Add GetInfo syscall

This commit is contained in:
rkx1209 2018-03-23 19:18:54 +09:00
parent a0d987e151
commit fbdf9fe643
9 changed files with 66 additions and 5 deletions

View file

@ -13,6 +13,7 @@ void Init() {
//PC = 0x30f0;
SP = 0x3100000;
SYSR.tpidrro_el[0] = (1 << 24) + 0x1000 * 1;
SYSR.tczid_el[0] = 0x4; //FIXME: calclulate at runtime
}
void RunLoop() {

View file

@ -407,6 +407,10 @@ static const A64SysRegInfo cp_reginfo[] = {
// name, state, opc0, opc1, opc2, crn, crm, offset
A64SysRegInfo("TPIDRRO_EL0", ARM_CP_STATE_AA64,
3, 3, 3, 13, 0, offsetof(ARMv8::ARMv8State::SysReg, tpidrro_el[0])),
A64SysRegInfo("DCZID_EL0", ARM_CP_STATE_AA64,
3, 3, 7, 0, 0, offsetof(ARMv8::ARMv8State::SysReg, tczid_el[0])),
A64SysRegInfo("DC_ZVA", ARM_CP_STATE_AA64,
1, 3, 1, 7, 4, -1),
A64SysRegInfo(ARM_CP_SENTINEL)
};
@ -464,6 +468,23 @@ const A64SysRegInfo* GetSysReg(uint32_t encoded_op) {
return it->second;
}
static void DisasHint(uint32_t insn, unsigned int op1, unsigned int op2, unsigned int crm, DisasCallback *cb) {
unsigned int selector = crm << 3 | op2;
if (op1 != 3) {
UnallocatedOp (insn);
return;
}
switch (selector) {
case 0: /* NOP */
return;
default:
UnsupportedOp ("HINT ops (except NOP)");
break;
}
}
static void DisasSystem(uint32_t insn, DisasCallback *cb) {
unsigned int l, op0, op1, crn, crm, op2, rt;
const A64SysRegInfo *ri;
@ -481,7 +502,7 @@ static void DisasSystem(uint32_t insn, DisasCallback *cb) {
}
switch (crn) {
case 2: /* HINT (including allocated hints like NOP, YIELD, etc) */
UnsupportedOp ("HINT");
DisasHint (insn, op1, op2, crm, cb);
break;
case 3: /* CLREX, DSB, DMB, ISB */
UnsupportedOp ("SYNC");
@ -514,7 +535,8 @@ static void DisasSystem(uint32_t insn, DisasCallback *cb) {
UnsupportedOp ("MSR/MRS Current EL");
return;
case ARM_CP_DC_ZVA:
UnsupportedOp ("MSR/MRS ZVA");
/* TODO: */
debug_print("DC ZVA (clear cache. future work...)\n");
return;
}
cb->ReadWriteSysReg(rt, ri->offset, isread);

View file

@ -32,6 +32,14 @@ static void WriteToRAM(const uint64_t gpa, T value) {
bindump (ptr, sizeof(T));
}
void ReadBytes(uint64_t gva, uint8_t *ptr, int size) {
uint64_t gpa = gva;
for (int i = 0; i < size; i++) {
uint8_t byte = ReadU8 (gpa + i);
ptr[i] = byte;
}
}
uint8_t ReadU8(const uint64_t gva) {
/* XXX: Implement Page translation */
uint64_t gpa = gva;

View file

@ -29,7 +29,7 @@ State GetState() {
}
void DumpMachine() {
//ARMv8::Dump ();
ARMv8::Dump ();
if (TraceOut)
ARMv8::DumpJson (TraceOut);
}

View file

@ -15,6 +15,9 @@ RAMBlock::RAMBlock (std::string _name, uint64_t _addr, size_t _length, int _perm
namespace Memory
{
uint64_t heap_base = 0x9000000;
//uint64_t heap_size = 0x2000000;
uint64_t heap_size = 0x0;
uint8_t *pRAM; // XXX: Replace raw pointer to View wrapper.
static RAMBlock mem_map[] =
{
@ -22,6 +25,7 @@ static RAMBlock mem_map[] =
RAMBlock (".rdata", 0x1000000, 0x1000000, PROT_READ | PROT_WRITE),
RAMBlock (".data", 0x2000000, 0x1000000, PROT_READ | PROT_WRITE),
RAMBlock ("[stack]", 0x3000000, 0x6000000, PROT_READ | PROT_WRITE),
//RAMBlock ("[heap]", heap_base, heap_size, PROT_READ | PROT_WRITE),
};
void InitMemmap(Nsemu *nsemu) {

25
Svc.cpp
View file

@ -259,11 +259,32 @@ uint64_t Break(uint64_t X0, uint64_t X1, uint64_t info) {
uint64_t OutputDebugString(uint64_t ptr, uint64_t size) {
ns_print("OutputDebugString addr=0x%lx, size=%llu\n", ptr, size);
unsigned char *str = new unsigned char[size + 1];
ARMv8::ReadBytes (ptr, str, size);
ns_print("String: %s\n", str);
delete[] str;
return 0;
}
#define matchone(a, v) do { if(id1 == (a)) return make_tuple(0, (v)); } while(0)
#define matchpair(a, b, v) do { if(id1 == (a) && id2 == (b)) return make_tuple(0, (v)); } while(0)
std::tuple<uint64_t, uint64_t> GetInfo(uint64_t id1, uint32_t handle, uint64_t id2) {
return make_tuple(0, 0);
ns_print("GetInfo id1: %llu, id2: %llu, handle: %u\n", id1, id2, handle);
matchpair(0, 0, 0xF);
matchpair(1, 0, 0xFFFFFFFF00000000);
matchpair(2, 0, 0xbb0000000); // map region
matchpair(3, 0, 0x1000000000); // size
matchpair(4, 0, Memory::heap_base); // heap region
matchpair(5, 0, Memory::heap_size); // size
matchpair(6, 0, 0x400000);
matchpair(7, 0, 0x10000);
matchpair(12, 0, 0x8000000);
matchpair(13, 0, 0x7ff8000000);
matchpair(14, 0, 0xbb0000000); // new map region
matchpair(15, 0, 0x1000000000); // size
matchpair(18, 0, 0x0100000000000036); // Title ID
matchone(11, 0);
ns_abort ("Unknown getinfo %llu, %llu\n", id1, id2);
}
std::tuple<uint64_t, uint64_t, uint64_t> CreateSession(uint32_t clientOut, uint32_t serverOut, uint64_t unk) {

View file

@ -34,6 +34,7 @@ struct ARMv8State {
uint64_t tpidr_el[4];
};
uint64_t tpidrro_el[1];
uint64_t tczid_el[1];
} sysr;
};

View file

@ -10,6 +10,7 @@ uint8_t ReadU8(const uint64_t gva);
uint16_t ReadU16(const uint64_t gva);
uint32_t ReadU32(const uint64_t gva);
uint64_t ReadU64(const uint64_t gva);
void ReadBytes(uint64_t gva, uint8_t *ptr, int size);
void WriteU8(const uint64_t gva, uint8_t value);
void WriteU16(const uint64_t gva, uint16_t value);

View file

@ -23,6 +23,9 @@ class Nsemu;
namespace Memory
{
extern uint8_t *pRAM; // XXX: Replace raw pointer to View wrapper.
extern uint64_t heap_base;
extern uint64_t heap_size;
void InitMemmap(Nsemu *nsemu);
RAMBlock *FindRAMBlock(Nsemu *nsemu, uint64_t addr, size_t len);
bool CopytoEmu(Nsemu *nsemu, void *data, uint64_t addr, size_t len);