| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
#pragma once |
| 7 |
|
| 8 |
#include <array> |
| 9 |
#include <vector> |
| 10 |
|
| 11 |
#ifdef _MSC_VER |
| 12 |
# pragma warning(push, 0) |
| 13 |
# include <unicorn/unicorn.h> |
| 14 |
# pragma warning(pop) |
| 15 |
#else |
| 16 |
# include <unicorn/unicorn.h> |
| 17 |
#endif |
| 18 |
|
| 19 |
#include <mcl/stdint.hpp> |
| 20 |
|
| 21 |
#include "../A64/testenv.h" |
| 22 |
|
| 23 |
class A64Unicorn final { |
| 24 |
public: |
| 25 |
static constexpr size_t num_gprs = 31; |
| 26 |
using RegisterArray = std::array<u64, num_gprs>; |
| 27 |
using RegisterPtrArray = std::array<RegisterArray::pointer, num_gprs>; |
| 28 |
using RegisterConstPtrArray = std::array<RegisterArray::const_pointer, num_gprs>; |
| 29 |
|
| 30 |
static constexpr size_t num_vecs = 32; |
| 31 |
using VectorArray = std::array<Vector, num_vecs>; |
| 32 |
using VectorPtrArray = std::array<VectorArray::pointer, num_vecs>; |
| 33 |
using VectorConstPtrArray = std::array<VectorArray::const_pointer, num_vecs>; |
| 34 |
|
| 35 |
explicit A64Unicorn(A64TestEnv& testenv); |
| 36 |
~A64Unicorn(); |
| 37 |
|
| 38 |
void Run(); |
| 39 |
|
| 40 |
u64 GetSP() const; |
| 41 |
void SetSP(u64 value); |
| 42 |
|
| 43 |
u64 GetPC() const; |
| 44 |
void SetPC(u64 value); |
| 45 |
|
| 46 |
RegisterArray GetRegisters() const; |
| 47 |
void SetRegisters(const RegisterArray& value); |
| 48 |
|
| 49 |
VectorArray GetVectors() const; |
| 50 |
void SetVectors(const VectorArray& value); |
| 51 |
|
| 52 |
u32 GetFpcr() const; |
| 53 |
void SetFpcr(u32 value); |
| 54 |
|
| 55 |
u32 GetFpsr() const; |
| 56 |
void SetFpsr(u32 value); |
| 57 |
|
| 58 |
u32 GetPstate() const; |
| 59 |
void SetPstate(u32 value); |
| 60 |
|
| 61 |
void ClearPageCache(); |
| 62 |
|
| 63 |
void DumpMemoryInformation(); |
| 64 |
|
| 65 |
private: |
| 66 |
static void InterruptHook(uc_engine* uc, u32 interrupt, void* user_data); |
| 67 |
static bool UnmappedMemoryHook(uc_engine* uc, uc_mem_type type, u64 addr, int size, u64 value, void* user_data); |
| 68 |
static bool MemoryWriteHook(uc_engine* uc, uc_mem_type type, u64 addr, int size, u64 value, void* user_data); |
| 69 |
|
| 70 |
struct Page { |
| 71 |
u64 address; |
| 72 |
std::array<u8, 4096> data; |
| 73 |
}; |
| 74 |
|
| 75 |
A64TestEnv& testenv; |
| 76 |
uc_engine* uc{}; |
| 77 |
uc_hook intr_hook{}; |
| 78 |
uc_hook mem_invalid_hook{}; |
| 79 |
uc_hook mem_write_prot_hook{}; |
| 80 |
|
| 81 |
std::vector<std::unique_ptr<Page>> pages; |
| 82 |
}; |