Fix C++ entry and tiny cleanup

This commit is contained in:
◱ PixelyIon 2019-08-18 18:31:32 +05:30
parent 113bfd059e
commit 342fee841f
4 changed files with 17 additions and 26 deletions

View File

@ -35,8 +35,8 @@ void thread_main(std::string rom_path, std::string pref_path, std::string log_pa
extern "C"
JNIEXPORT void JNICALL
Java_emu_lightswitch_lightswitch_MainActivity_loadFile(JNIEnv *env, jobject instance, jstring rom_path_,
jstring pref_path_, jstring log_path_) {
Java_emu_lightswitch_MainActivity_loadFile(JNIEnv *env, jobject instance, jstring rom_path_,
jstring pref_path_, jstring log_path_) {
const char *rom_path = env->GetStringUTFChars(rom_path_, 0);
const char *pref_path = env->GetStringUTFChars(pref_path_, 0);
const char *log_path = env->GetStringUTFChars(log_path_, 0);

View File

@ -34,28 +34,19 @@ namespace lightSwitch::hw {
if (status == -1) throw std::runtime_error("Cannot resume process");
}
void bin(unsigned n) {
unsigned i;
std::string s;
for (i = 1 << 31; i > 0; i = i / 2)
(n & i) ? s += "1" : s += "0";
s = s.substr(16);
syslog(LOG_WARNING, "%s", s.c_str());
}
void Cpu::WriteBreakpoint(uint64_t &address_, uint64_t &size) {
void Cpu::WriteBreakpoint(uint64_t address_, uint64_t size) {
auto address = (uint32_t *) address_;
for (uint64_t iter = 0; iter < size; iter++) {
auto instr_svc = reinterpret_cast<instr::svc *>(address + iter);
auto instr_mrs = reinterpret_cast<instr::mrs *>(address + iter);
if (instr_svc->verify()) {
// syslog(LOG_WARNING, "Found SVC call: 0x%X, At location 0x%X", instr_svc->value, ((uint64_t)address)+iter);
instr::brk brk((uint16_t) instr_svc->value);
address[iter] = *(uint32_t *) (&brk);
instr::brk brk(reinterpret_cast<uint16_t>(instr_svc->value));
address[iter] = *reinterpret_cast<uint32_t *>(&brk);
} else if (instr_mrs->verify() && instr_mrs->Sreg == constant::tpidrro_el0) {
// syslog(LOG_WARNING, "Found MRS call: 0x%X, At location 0x%X", instr_mrs->Xt, ((uint64_t)address)+iter);
instr::brk brk((uint16_t) (constant::svc_last + 1 + instr_mrs->Xt));
address[iter] = *(uint32_t *) (&brk);
instr::brk brk(reinterpret_cast<uint16_t>(constant::svc_last + 1 + instr_mrs->Xt));
address[iter] = *reinterpret_cast<uint32_t *>(&brk);
}
}
}
@ -75,7 +66,7 @@ namespace lightSwitch::hw {
auto instr = reinterpret_cast<instr::brk *>(ReadMemory(regs.pc));
if (instr->verify()) {
if (instr->value <= constant::svc_last) {
svc_handler((uint16_t) instr->value, device);
svc_handler(reinterpret_cast<uint16_t>(instr->value), device);
syslog(LOG_ERR, "SVC has been called 0x%X", instr->value);
if (stop) break;
} else if (instr->value > constant::svc_last && instr->value <= constant::svc_last + constant::num_regs) {
@ -116,10 +107,10 @@ namespace lightSwitch::hw {
}
uint64_t Cpu::GetRegister(wreg reg_id) {
return ((uint32_t *) regs.regs)[wreg_lut[reg_id]];
return (reinterpret_cast<uint32_t *>(regs.regs))[wreg_lut[reg_id]];
}
void Cpu::SetRegister(wreg reg_id, uint32_t value) {
((uint32_t *) regs.regs)[wreg_lut[reg_id]] = value;
(reinterpret_cast<uint32_t *>(regs.regs))[wreg_lut[reg_id]] = value;
}
}

View File

@ -32,7 +32,7 @@ namespace lightSwitch::hw {
void ResumeProcess();
void WriteBreakpoint(uint64_t &address, uint64_t &size);
void WriteBreakpoint(uint64_t address, uint64_t size);
uint8_t wreg_lut[31] = {1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61};

View File

@ -12,27 +12,27 @@ namespace lightSwitch::hw {
void Memory::Map(uint64_t address, size_t size, Region region) {
void *ptr = mmap((void *) address, size, PROT_EXEC | PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON | MAP_FIXED, 0, 0);
if (ptr == MAP_FAILED)
throw exception("An occurred while mapping region at " + std::to_string(address));
throw exception("An occurred while mapping region: " + std::string(strerror(errno)));
region_map.insert(std::pair<Region, RegionData>(region, {address, size}));
}
void Memory::Remap(Region region, size_t size) {
RegionData region_data = region_map.at(region);
void *ptr = mremap((void *) region_data.address, region_data.size, size, 0);
void *ptr = mremap(reinterpret_cast<void *>(region_data.address), region_data.size, size, 0);
if (ptr == MAP_FAILED)
throw exception("An occurred while unmapping region: " + std::string(strerror(errno)));
throw exception("An occurred while remapping region: " + std::string(strerror(errno)));
region_map[region].size = size;
}
void Memory::Unmap(Region region) {
RegionData region_data = region_map.at(region);
int err = munmap((void *) region_data.address, region_data.size);
int err = munmap(reinterpret_cast<void *>(region_data.address), region_data.size);
if (err == -1)
throw exception("An occurred while unmapping region: " + std::string(strerror(errno)));
}
void Memory::Write(void *data, uint64_t offset, size_t size) {
std::memcpy((void *) offset, data, size);
std::memcpy(reinterpret_cast<void *>(offset), data, size);
}
template<typename T>
@ -41,7 +41,7 @@ namespace lightSwitch::hw {
}
void Memory::Read(void *destination, uint64_t offset, size_t size) {
std::memcpy(destination, (void *) (offset), size);
std::memcpy(destination, reinterpret_cast<void *>(offset), size);
}
template<typename T>