diff --git a/app/src/main/cpp/lightswitch.cpp b/app/src/main/cpp/lightswitch.cpp index d3bbf0ae..3a502abd 100644 --- a/app/src/main/cpp/lightswitch.cpp +++ b/app/src/main/cpp/lightswitch.cpp @@ -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); diff --git a/app/src/main/cpp/switch/hw/cpu.cpp b/app/src/main/cpp/switch/hw/cpu.cpp index 2fef2d5b..d5fce411 100644 --- a/app/src/main/cpp/switch/hw/cpu.cpp +++ b/app/src/main/cpp/switch/hw/cpu.cpp @@ -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(address + iter); auto instr_mrs = reinterpret_cast(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(instr_svc->value)); + address[iter] = *reinterpret_cast(&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(constant::svc_last + 1 + instr_mrs->Xt)); + address[iter] = *reinterpret_cast(&brk); } } } @@ -75,7 +66,7 @@ namespace lightSwitch::hw { auto instr = reinterpret_cast(ReadMemory(regs.pc)); if (instr->verify()) { if (instr->value <= constant::svc_last) { - svc_handler((uint16_t) instr->value, device); + svc_handler(reinterpret_cast(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(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(regs.regs))[wreg_lut[reg_id]] = value; } } \ No newline at end of file diff --git a/app/src/main/cpp/switch/hw/cpu.h b/app/src/main/cpp/switch/hw/cpu.h index 90a658dd..ba7f17b5 100644 --- a/app/src/main/cpp/switch/hw/cpu.h +++ b/app/src/main/cpp/switch/hw/cpu.h @@ -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}; diff --git a/app/src/main/cpp/switch/hw/memory.cpp b/app/src/main/cpp/switch/hw/memory.cpp index 59d4948b..4b3e9182 100644 --- a/app/src/main/cpp/switch/hw/memory.cpp +++ b/app/src/main/cpp/switch/hw/memory.cpp @@ -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, {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(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(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(offset), data, size); } template @@ -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(offset), size); } template