diff options
Diffstat (limited to '')
31 files changed, 234 insertions, 124 deletions
diff --git a/src/core/arm/dyncom/arm_dyncom.cpp b/src/core/arm/dyncom/arm_dyncom.cpp index bc1e969e4..128413262 100644 --- a/src/core/arm/dyncom/arm_dyncom.cpp +++ b/src/core/arm/dyncom/arm_dyncom.cpp @@ -2,6 +2,8 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include "common/make_unique.h" + #include "core/arm/skyeye_common/armemu.h" #include "core/arm/skyeye_common/vfp/vfp.h" @@ -17,7 +19,7 @@ const static cpu_config_t s_arm11_cpu_info = { }; ARM_DynCom::ARM_DynCom(PrivilegeMode initial_mode) { - state = std::unique_ptr<ARMul_State>(new ARMul_State); + state = Common::make_unique<ARMul_State>(); ARMul_NewState(state.get()); ARMul_SelectProcessor(state.get(), ARM_v6_Prop | ARM_v5_Prop | ARM_v5e_Prop); diff --git a/src/core/arm/dyncom/arm_dyncom_interpreter.cpp b/src/core/arm/dyncom/arm_dyncom_interpreter.cpp index fde11e4ff..991da740b 100644 --- a/src/core/arm/dyncom/arm_dyncom_interpreter.cpp +++ b/src/core/arm/dyncom/arm_dyncom_interpreter.cpp @@ -6,7 +6,6 @@ #include <algorithm> #include <cstdio> -#include <unordered_map> #include "common/logging/log.h" #include "common/profiler.h" @@ -3533,25 +3532,6 @@ const transop_fp_t arm_instruction_trans[] = { INTERPRETER_TRANSLATE(blx_1_thumb) }; -typedef std::unordered_map<u32, int> bb_map; -static bb_map CreamCache; - -static void insert_bb(unsigned int addr, int start) { - CreamCache[addr] = start; -} - -static int find_bb(unsigned int addr, int& start) { - int ret = -1; - bb_map::const_iterator it = CreamCache.find(addr); - if (it != CreamCache.end()) { - start = static_cast<int>(it->second); - ret = 0; - } else { - ret = -1; - } - return ret; -} - enum { FETCH_SUCCESS, FETCH_FAILURE @@ -3674,7 +3654,9 @@ translated: } ret = inst_base->br; }; - insert_bb(pc_start, bb_start); + + cpu->instruction_cache[pc_start] = bb_start; + return KEEP_GOING; } @@ -4001,9 +3983,14 @@ unsigned InterpreterMainLoop(ARMul_State* state) { phys_addr = cpu->Reg[15]; - if (find_bb(cpu->Reg[15], ptr) == -1) + // Find the cached instruction cream, otherwise translate it... + auto itr = cpu->instruction_cache.find(cpu->Reg[15]); + if (itr != cpu->instruction_cache.end()) { + ptr = itr->second; + } else { if (InterpreterTranslate(cpu, ptr, cpu->Reg[15]) == FETCH_EXCEPTION) goto END; + } inst_base = (arm_inst *)&inst_buf[ptr]; GOTO_NEXT_INST; diff --git a/src/core/arm/interpreter/arminit.cpp b/src/core/arm/interpreter/arminit.cpp index 6ac45c396..31b2bab06 100644 --- a/src/core/arm/interpreter/arminit.cpp +++ b/src/core/arm/interpreter/arminit.cpp @@ -26,8 +26,6 @@ \***************************************************************************/ ARMul_State* ARMul_NewState(ARMul_State* state) { - memset(state, 0, sizeof(ARMul_State)); - state->Emulate = RUN; state->Mode = USER32MODE; diff --git a/src/core/arm/skyeye_common/armdefs.h b/src/core/arm/skyeye_common/armdefs.h index 08da6d9eb..85d523bc2 100644 --- a/src/core/arm/skyeye_common/armdefs.h +++ b/src/core/arm/skyeye_common/armdefs.h @@ -17,6 +17,8 @@ #pragma once +#include <unordered_map> + #include "common/common_types.h" #include "core/arm/skyeye_common/arm_regformat.h" #include "core/arm/skyeye_common/skyeye_defs.h" @@ -152,6 +154,10 @@ So, if lateabtSig=1, then it means Late Abort Model(Base Updated Abort Model) // Added by ksh in 2005-10-1 cpu_config_t* cpu; + + // TODO(bunnei): Move this cache to a better place - it should be per codeset (likely per + // process for our purposes), not per ARMul_State (which tracks CPU core state). + std::unordered_map<u32, int> instruction_cache; }; /***************************************************************************\ diff --git a/src/core/core_timing.cpp b/src/core/core_timing.cpp index 6f716b1ca..f70c84c3d 100644 --- a/src/core/core_timing.cpp +++ b/src/core/core_timing.cpp @@ -160,6 +160,16 @@ void Init() { last_global_time_us = 0; has_ts_events = 0; mhz_change_callbacks.clear(); + + first = nullptr; + ts_first = nullptr; + ts_last = nullptr; + + event_pool = nullptr; + event_ts_pool = nullptr; + allocated_ts_events = 0; + + advance_callback = nullptr; } void Shutdown() { diff --git a/src/core/hle/config_mem.cpp b/src/core/hle/config_mem.cpp index 40bae9346..9fcfcc285 100644 --- a/src/core/hle/config_mem.cpp +++ b/src/core/hle/config_mem.cpp @@ -61,12 +61,13 @@ template void Read<u16>(u16 &var, const u32 addr); template void Read<u8>(u8 &var, const u32 addr); void Init() { + memset(&config_mem, 0, sizeof(config_mem)); + config_mem.update_flag = 0; // No update config_mem.sys_core_ver = 0x2; config_mem.unit_info = 0x1; // Bit 0 set for Retail config_mem.prev_firm = 0; config_mem.app_mem_type = 0x2; // Default app mem type is 0 - config_mem.unit_info = 0x1; // Bit 0 set for Retail config_mem.app_mem_alloc = 0x06000000; // Set to 96MB, since some games use more than the default (64MB) config_mem.base_mem_alloc = 0x01400000; // Default base memory is 20MB config_mem.sys_mem_alloc = Memory::FCRAM_SIZE - (config_mem.app_mem_alloc + config_mem.base_mem_alloc); @@ -77,4 +78,7 @@ void Init() { config_mem.firm_sys_core_ver = 0x2; } +void Shutdown() { +} + } // namespace diff --git a/src/core/hle/config_mem.h b/src/core/hle/config_mem.h index 94853901a..cbb478fb3 100644 --- a/src/core/hle/config_mem.h +++ b/src/core/hle/config_mem.h @@ -20,4 +20,6 @@ void Read(T &var, const u32 addr); void Init(); +void Shutdown(); + } // namespace diff --git a/src/core/hle/hle.cpp b/src/core/hle/hle.cpp index c645d6563..191d0411e 100644 --- a/src/core/hle/hle.cpp +++ b/src/core/hle/hle.cpp @@ -23,7 +23,7 @@ Common::Profiling::TimingCategory profiler_svc("SVC Calls"); static std::vector<ModuleDef> g_module_db; -bool g_reschedule = false; ///< If true, immediately reschedules the CPU to a new thread +bool g_reschedule; ///< If true, immediately reschedules the CPU to a new thread static const FunctionDef* GetSVCInfo(u32 opcode) { u32 func_num = opcode & 0xFFFFFF; // 8 bits @@ -73,17 +73,20 @@ static void RegisterAllModules() { } void Init() { - Service::Init(); - RegisterAllModules(); + Service::Init(); ConfigMem::Init(); SharedPage::Init(); + g_reschedule = false; + LOG_DEBUG(Kernel, "initialized OK"); } void Shutdown() { + ConfigMem::Shutdown(); + SharedPage::Shutdown(); Service::Shutdown(); g_module_db.clear(); diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp index 6261b82b6..fca582bbe 100644 --- a/src/core/hle/kernel/kernel.cpp +++ b/src/core/hle/kernel/kernel.cpp @@ -14,11 +14,10 @@ namespace Kernel { -unsigned int Object::next_object_id = 0; - -SharedPtr<Thread> g_main_thread = nullptr; +unsigned int Object::next_object_id; +SharedPtr<Thread> g_main_thread; HandleTable g_handle_table; -u64 g_program_id = 0; +u64 g_program_id; void WaitObject::AddWaitingThread(SharedPtr<Thread> thread) { auto itr = std::find(waiting_threads.begin(), waiting_threads.end(), thread); @@ -138,6 +137,10 @@ void HandleTable::Clear() { void Init() { Kernel::ThreadingInit(); Kernel::TimersInit(); + + Object::next_object_id = 0; + g_program_id = 0; + g_main_thread = nullptr; } /// Shutdown the kernel diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h index 2d295ea00..ab06fa025 100644 --- a/src/core/hle/kernel/kernel.h +++ b/src/core/hle/kernel/kernel.h @@ -95,12 +95,13 @@ public: return false; } +public: + static unsigned int next_object_id; + private: friend void intrusive_ptr_add_ref(Object*); friend void intrusive_ptr_release(Object*); - static unsigned int next_object_id; - unsigned int ref_count = 0; unsigned int object_id = next_object_id++; }; diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index 33d66b986..d678f5f6f 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp @@ -23,7 +23,7 @@ namespace Kernel { /// Event type for the thread wake up event -static int ThreadWakeupEventType = -1; +static int ThreadWakeupEventType; bool Thread::ShouldWait() { return status != THREADSTATUS_DEAD; @@ -42,7 +42,7 @@ static Common::ThreadQueueList<Thread*, THREADPRIO_LOWEST+1> ready_queue; static Thread* current_thread; // The first available thread id at startup -static u32 next_thread_id = 1; +static u32 next_thread_id; /** * Creates a new thread ID @@ -497,6 +497,12 @@ void Thread::SetWaitSynchronizationOutput(s32 output) { void ThreadingInit() { ThreadWakeupEventType = CoreTiming::RegisterEvent("ThreadWakeupCallback", ThreadWakeupCallback); + current_thread = nullptr; + next_thread_id = 1; + + thread_list.clear(); + ready_queue.clear(); + // Setup the idle thread SetupIdleThread(); } diff --git a/src/core/hle/kernel/timer.cpp b/src/core/hle/kernel/timer.cpp index 1ec2a4b10..36979248d 100644 --- a/src/core/hle/kernel/timer.cpp +++ b/src/core/hle/kernel/timer.cpp @@ -12,7 +12,7 @@ namespace Kernel { /// The event type of the generic timer callback event -static int timer_callback_event_type = -1; +static int timer_callback_event_type; // TODO(yuriks): This can be removed if Timer objects are explicitly pooled in the future, allowing // us to simply use a pool index or similar. static Kernel::HandleTable timer_callback_handle_table; @@ -89,6 +89,7 @@ static void TimerCallback(u64 timer_handle, int cycles_late) { } void TimersInit() { + timer_callback_handle_table.Clear(); timer_callback_event_type = CoreTiming::RegisterEvent("TimerCallback", TimerCallback); } diff --git a/src/core/hle/service/apt/apt.cpp b/src/core/hle/service/apt/apt.cpp index 190c5df7a..98ae80b3a 100644 --- a/src/core/hle/service/apt/apt.cpp +++ b/src/core/hle/service/apt/apt.cpp @@ -28,15 +28,15 @@ namespace APT { static const VAddr SHARED_FONT_VADDR = 0x18000000; /// Handle to shared memory region designated to for shared system font -static Kernel::SharedPtr<Kernel::SharedMemory> shared_font_mem = nullptr; +static Kernel::SharedPtr<Kernel::SharedMemory> shared_font_mem; -static Kernel::SharedPtr<Kernel::Mutex> lock = nullptr; -static Kernel::SharedPtr<Kernel::Event> notification_event = nullptr; ///< APT notification event -static Kernel::SharedPtr<Kernel::Event> start_event = nullptr; ///< APT start event +static Kernel::SharedPtr<Kernel::Mutex> lock; +static Kernel::SharedPtr<Kernel::Event> notification_event; ///< APT notification event +static Kernel::SharedPtr<Kernel::Event> start_event; ///< APT start event static std::vector<u8> shared_font; -static u32 cpu_percent = 0; ///< CPU time available to the running application +static u32 cpu_percent; ///< CPU time available to the running application void Initialize(Service::Interface* self) { u32* cmd_buff = Kernel::GetCommandBuffer(); @@ -309,6 +309,7 @@ void Init() { } lock = Kernel::Mutex::Create(false, "APT_U:Lock"); + cpu_percent = 0; // TODO(bunnei): Check if these are created in Initialize or on APT process startup. @@ -317,7 +318,11 @@ void Init() { } void Shutdown() { - + shared_font.clear(); + shared_font_mem = nullptr; + lock = nullptr; + notification_event = nullptr; + start_event = nullptr; } } // namespace APT diff --git a/src/core/hle/service/cfg/cfg.cpp b/src/core/hle/service/cfg/cfg.cpp index fe1245fe8..5eccdecf7 100644 --- a/src/core/hle/service/cfg/cfg.cpp +++ b/src/core/hle/service/cfg/cfg.cpp @@ -53,12 +53,12 @@ ResultCode GetConfigInfoBlock(u32 block_id, u32 size, u32 flag, u8* output) { }); if (itr == std::end(config->block_entries)) { - LOG_ERROR(Service_CFG, "Config block %u with flags %u was not found", block_id, flag); + LOG_ERROR(Service_CFG, "Config block 0x%X with flags %u and size %u was not found", block_id, flag, size); return ResultCode(ErrorDescription::NotFound, ErrorModule::Config, ErrorSummary::WrongArgument, ErrorLevel::Permanent); } if (itr->size != size) { - LOG_ERROR(Service_CFG, "Invalid size %u for config block %u with flags %u", size, block_id, flag); + LOG_ERROR(Service_CFG, "Invalid size %u for config block 0x%X with flags %u", size, block_id, flag); return ResultCode(ErrorDescription::InvalidSize, ErrorModule::Config, ErrorSummary::WrongArgument, ErrorLevel::Permanent); } @@ -207,6 +207,7 @@ void Init() { // Initialize the Username block // TODO(Subv): Initialize this directly in the variable when MSVC supports char16_t string literals + memset(&CONSOLE_USERNAME_BLOCK, 0, sizeof(CONSOLE_USERNAME_BLOCK)); CONSOLE_USERNAME_BLOCK.ng_word = 0; CONSOLE_USERNAME_BLOCK.zero = 0; @@ -219,7 +220,6 @@ void Init() { } void Shutdown() { - } } // namespace CFG diff --git a/src/core/hle/service/dsp_dsp.cpp b/src/core/hle/service/dsp_dsp.cpp index f16f84e67..2e759a3e3 100644 --- a/src/core/hle/service/dsp_dsp.cpp +++ b/src/core/hle/service/dsp_dsp.cpp @@ -11,7 +11,7 @@ namespace DSP_DSP { -static u32 read_pipe_count = 0; +static u32 read_pipe_count; static Kernel::SharedPtr<Kernel::Event> semaphore_event; static Kernel::SharedPtr<Kernel::Event> interrupt_event; @@ -42,7 +42,7 @@ static void ConvertProcessAddressFromDspDram(Service::Interface* self) { cmd_buff[1] = 0; // No error cmd_buff[2] = (addr << 1) + (Memory::DSP_MEMORY_VADDR + 0x40000); - LOG_WARNING(Service_DSP, "(STUBBED) called with address %u", addr); + LOG_WARNING(Service_DSP, "(STUBBED) called with address 0x%08X", addr); } /** @@ -60,12 +60,19 @@ static void ConvertProcessAddressFromDspDram(Service::Interface* self) { static void LoadComponent(Service::Interface* self) { u32* cmd_buff = Kernel::GetCommandBuffer(); + u32 size = cmd_buff[1]; + u32 unk1 = cmd_buff[2]; + u32 unk2 = cmd_buff[3]; + u32 new_size = cmd_buff[4]; + u32 buffer = cmd_buff[5]; + cmd_buff[1] = 0; // No error cmd_buff[2] = 1; // Pretend that we actually loaded the DSP firmware // TODO(bunnei): Implement real DSP firmware loading - LOG_WARNING(Service_DSP, "(STUBBED) called"); + LOG_WARNING(Service_DSP, "(STUBBED) called size=0x%X, unk1=0x%08X, unk2=0x%08X, new_size=0x%X, buffer=0x%08X", + size, unk1, unk2, new_size, buffer); } /** @@ -106,7 +113,7 @@ static void FlushDataCache(Service::Interface* self) { cmd_buff[1] = RESULT_SUCCESS.raw; // No error - LOG_DEBUG(Service_DSP, "(STUBBED) called address=0x%08X, size=0x%08X, process=0x%08X", + LOG_DEBUG(Service_DSP, "(STUBBED) called address=0x%08X, size=0x%X, process=0x%08X", address, size, process); } @@ -122,6 +129,10 @@ static void FlushDataCache(Service::Interface* self) { static void RegisterInterruptEvents(Service::Interface* self) { u32* cmd_buff = Kernel::GetCommandBuffer(); + u32 param0 = cmd_buff[1]; + u32 param1 = cmd_buff[2]; + u32 event_handle = cmd_buff[4]; + auto evt = Kernel::g_handle_table.Get<Kernel::Event>(cmd_buff[4]); if (evt != nullptr) { interrupt_event = evt; @@ -133,7 +144,7 @@ static void RegisterInterruptEvents(Service::Interface* self) { cmd_buff[1] = -1; } - LOG_WARNING(Service_DSP, "(STUBBED) called"); + LOG_WARNING(Service_DSP, "(STUBBED) called param0=%u, param1=%u, event_handle=0x%08X", param0, param1, event_handle); } /** @@ -174,7 +185,7 @@ static void WriteProcessPipe(Service::Interface* self) { cmd_buff[1] = RESULT_SUCCESS.raw; // No error - LOG_WARNING(Service_DSP, "(STUBBED) called number=%u, size=0x%08X, new_size=0x%08X, buffer=0x%08X", + LOG_WARNING(Service_DSP, "(STUBBED) called number=%u, size=0x%X, new_size=0x%X, buffer=0x%08X", number, size, new_size, buffer); } @@ -192,6 +203,8 @@ static void WriteProcessPipe(Service::Interface* self) { static void ReadPipeIfPossible(Service::Interface* self) { u32* cmd_buff = Kernel::GetCommandBuffer(); + u32 unk1 = cmd_buff[1]; + u32 unk2 = cmd_buff[2]; u32 size = cmd_buff[3] & 0xFFFF;// Lower 16 bits are size VAddr addr = cmd_buff[0x41]; @@ -217,7 +230,8 @@ static void ReadPipeIfPossible(Service::Interface* self) { cmd_buff[1] = 0; // No error cmd_buff[2] = (read_pipe_count - initial_size) * sizeof(u16); - LOG_WARNING(Service_DSP, "(STUBBED) called size=0x%08X, buffer=0x%08X", size, addr); + LOG_WARNING(Service_DSP, "(STUBBED) called unk1=0x%08X, unk2=0x%08X, size=0x%X, buffer=0x%08X", + unk1, unk2, size, addr); } /** diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp index 9ca5d13d4..0f30f743a 100644 --- a/src/core/hle/service/hid/hid.cpp +++ b/src/core/hle/service/hid/hid.cpp @@ -20,17 +20,17 @@ namespace HID { static const int MAX_CIRCLEPAD_POS = 0x9C; ///< Max value for a circle pad position // Handle to shared memory region designated to HID_User service -static Kernel::SharedPtr<Kernel::SharedMemory> shared_mem = nullptr; +static Kernel::SharedPtr<Kernel::SharedMemory> shared_mem; // Event handles -static Kernel::SharedPtr<Kernel::Event> event_pad_or_touch_1 = nullptr; -static Kernel::SharedPtr<Kernel::Event> event_pad_or_touch_2 = nullptr; -static Kernel::SharedPtr<Kernel::Event> event_accelerometer = nullptr; -static Kernel::SharedPtr<Kernel::Event> event_gyroscope = nullptr; -static Kernel::SharedPtr<Kernel::Event> event_debug_pad = nullptr; +static Kernel::SharedPtr<Kernel::Event> event_pad_or_touch_1; +static Kernel::SharedPtr<Kernel::Event> event_pad_or_touch_2; +static Kernel::SharedPtr<Kernel::Event> event_accelerometer; +static Kernel::SharedPtr<Kernel::Event> event_gyroscope; +static Kernel::SharedPtr<Kernel::Event> event_debug_pad; -static u32 next_pad_index = 0; -static u32 next_touch_index = 0; +static u32 next_pad_index; +static u32 next_touch_index; // TODO(peachum): // Add a method for setting analog input from joystick device for the circle Pad. @@ -175,6 +175,12 @@ void Init() { } void Shutdown() { + shared_mem = nullptr; + event_pad_or_touch_1 = nullptr; + event_pad_or_touch_2 = nullptr; + event_accelerometer = nullptr; + event_gyroscope = nullptr; + event_debug_pad = nullptr; } } // namespace HID diff --git a/src/core/hle/service/ir/ir.cpp b/src/core/hle/service/ir/ir.cpp index 58dfd8e1a..15ac477ef 100644 --- a/src/core/hle/service/ir/ir.cpp +++ b/src/core/hle/service/ir/ir.cpp @@ -15,8 +15,8 @@ namespace Service { namespace IR { -static Kernel::SharedPtr<Kernel::Event> handle_event = nullptr; -static Kernel::SharedPtr<Kernel::SharedMemory> shared_memory = nullptr; +static Kernel::SharedPtr<Kernel::Event> handle_event; +static Kernel::SharedPtr<Kernel::SharedMemory> shared_memory; void GetHandles(Service::Interface* self) { u32* cmd_buff = Kernel::GetCommandBuffer(); @@ -41,6 +41,8 @@ void Init() { } void Shutdown() { + shared_memory = nullptr; + handle_event = nullptr; } } // namespace IR diff --git a/src/core/hle/service/nwm_uds.cpp b/src/core/hle/service/nwm_uds.cpp index 1cee81ab2..4b06efc3a 100644 --- a/src/core/hle/service/nwm_uds.cpp +++ b/src/core/hle/service/nwm_uds.cpp @@ -11,7 +11,7 @@ namespace NWM_UDS { -static Kernel::SharedPtr<Kernel::Event> handle_event = nullptr; +static Kernel::SharedPtr<Kernel::Event> handle_event; /** * NWM_UDS::Shutdown service function diff --git a/src/core/hle/service/ptm/ptm.cpp b/src/core/hle/service/ptm/ptm.cpp index 57a301bec..d44510c1b 100644 --- a/src/core/hle/service/ptm/ptm.cpp +++ b/src/core/hle/service/ptm/ptm.cpp @@ -18,9 +18,9 @@ static const GameCoin default_game_coin = { 0x4F00, 42, 0, 0, 0, 2014, 12, 29 }; /// Id of the SharedExtData archive used by the PTM process static const std::vector<u8> ptm_shared_extdata_id = {0, 0, 0, 0, 0x0B, 0, 0, 0xF0, 0, 0, 0, 0}; -static bool shell_open = true; +static bool shell_open; -static bool battery_is_charging = true; +static bool battery_is_charging; u32 GetAdapterState() { // TODO(purpasmart96): This function is only a stub, @@ -43,6 +43,9 @@ void Init() { AddService(new PTM_Sysm_Interface); AddService(new PTM_U_Interface); + shell_open = true; + battery_is_charging = true; + // Open the SharedExtSaveData archive 0xF000000B and create the gamecoin.dat file if it doesn't exist FileSys::Path archive_path(ptm_shared_extdata_id); auto archive_result = Service::FS::OpenArchive(Service::FS::ArchiveIdCode::SharedExtSaveData, archive_path); diff --git a/src/core/hle/service/ptm/ptm_sysm.cpp b/src/core/hle/service/ptm/ptm_sysm.cpp index 2d841f69c..13322bdbb 100644 --- a/src/core/hle/service/ptm/ptm_sysm.cpp +++ b/src/core/hle/service/ptm/ptm_sysm.cpp @@ -16,7 +16,7 @@ namespace PTM { * 1: Result code, 0 on success, otherwise error code * 2: Whether the system is going through a power off */ -void IsLegacyPowerOff(Service::Interface* self) { +static void IsLegacyPowerOff(Service::Interface* self) { u32* cmd_buff = Kernel::GetCommandBuffer(); cmd_buff[1] = RESULT_SUCCESS.raw; cmd_buff[2] = 0; diff --git a/src/core/hle/service/y2r_u.cpp b/src/core/hle/service/y2r_u.cpp index 6607965e1..33ecf64a2 100644 --- a/src/core/hle/service/y2r_u.cpp +++ b/src/core/hle/service/y2r_u.cpp @@ -11,7 +11,7 @@ namespace Y2R_U { -static Kernel::SharedPtr<Kernel::Event> completion_event = 0; +static Kernel::SharedPtr<Kernel::Event> completion_event; /** * Y2R_U::IsBusyConversion service function diff --git a/src/core/hle/shared_page.cpp b/src/core/hle/shared_page.cpp index 568dad684..94fae2551 100644 --- a/src/core/hle/shared_page.cpp +++ b/src/core/hle/shared_page.cpp @@ -62,6 +62,8 @@ template void Read<u16>(u16 &var, const u32 addr); template void Read<u8>(u8 &var, const u32 addr); void Set3DSlider(float amount) { + memset(&shared_page, 0, sizeof(shared_page)); + shared_page.sliderstate_3d = amount; shared_page.ledstate_3d = (amount == 0.0f); // off when non-zero } @@ -71,4 +73,7 @@ void Init() { Set3DSlider(0.0f); } +void Shutdown() { +} + } // namespace diff --git a/src/core/hle/shared_page.h b/src/core/hle/shared_page.h index 8f93545ec..1b6e4e581 100644 --- a/src/core/hle/shared_page.h +++ b/src/core/hle/shared_page.h @@ -23,4 +23,6 @@ void Set3DSlider(float amount); void Init(); +void Shutdown(); + } // namespace diff --git a/src/core/hw/gpu.cpp b/src/core/hw/gpu.cpp index 308ea2035..0ad7e2963 100644 --- a/src/core/hw/gpu.cpp +++ b/src/core/hw/gpu.cpp @@ -29,8 +29,7 @@ namespace GPU { Regs g_regs; /// True if the current frame was skipped -bool g_skip_frame = false; - +bool g_skip_frame; /// 268MHz / gpu_refresh_rate frames per second static u64 frame_ticks; /// Event id for CoreTiming @@ -38,7 +37,7 @@ static int vblank_event; /// Total number of frames drawn static u64 frame_count; /// True if the last frame was skipped -static bool last_skip_frame = false; +static bool last_skip_frame; template <typename T> inline void Read(T &var, const u32 raw_addr) { @@ -320,6 +319,8 @@ static void VBlankCallback(u64 userdata, int cycles_late) { /// Initialize hardware void Init() { + memset(&g_regs, 0, sizeof(g_regs)); + auto& framebuffer_top = g_regs.framebuffer_config[0]; auto& framebuffer_sub = g_regs.framebuffer_config[1]; @@ -349,6 +350,7 @@ void Init() { frame_ticks = 268123480 / Settings::values.gpu_refresh_rate; last_skip_frame = false; g_skip_frame = false; + frame_count = 0; vblank_event = CoreTiming::RegisterEvent("GPU::VBlankCallback", VBlankCallback); CoreTiming::ScheduleEvent(frame_ticks, vblank_event); diff --git a/src/core/hw/hw.cpp b/src/core/hw/hw.cpp index bed50af50..236958139 100644 --- a/src/core/hw/hw.cpp +++ b/src/core/hw/hw.cpp @@ -63,6 +63,8 @@ void Init() { /// Shutdown hardware void Shutdown() { + GPU::Shutdown(); + LCD::Shutdown(); LOG_DEBUG(HW, "shutdown OK"); } diff --git a/src/core/hw/lcd.cpp b/src/core/hw/lcd.cpp index 7986f3ddb..8a09c3bc0 100644 --- a/src/core/hw/lcd.cpp +++ b/src/core/hw/lcd.cpp @@ -55,6 +55,7 @@ template void Write<u8>(u32 addr, const u8 data); /// Initialize hardware void Init() { + memset(&g_regs, 0, sizeof(g_regs)); LOG_DEBUG(HW_LCD, "initialized OK"); } diff --git a/src/core/loader/ncch.cpp b/src/core/loader/ncch.cpp index aaaa4d650..4efed78bf 100644 --- a/src/core/loader/ncch.cpp +++ b/src/core/loader/ncch.cpp @@ -198,20 +198,33 @@ ResultStatus AppLoader_NCCH::Load() { if (file->ReadBytes(&exheader_header, sizeof(ExHeader_Header)) != sizeof(ExHeader_Header)) return ResultStatus::Error; - is_compressed = (exheader_header.codeset_info.flags.flag & 1) == 1; - entry_point = exheader_header.codeset_info.text.address; - - LOG_INFO(Loader, "Name: %s", exheader_header.codeset_info.name); - LOG_DEBUG(Loader, "Code compressed: %s", is_compressed ? "yes" : "no"); - LOG_DEBUG(Loader, "Entry point: 0x%08X", entry_point); + is_compressed = (exheader_header.codeset_info.flags.flag & 1) == 1; + entry_point = exheader_header.codeset_info.text.address; + code_size = exheader_header.codeset_info.text.code_size; + stack_size = exheader_header.codeset_info.stack_size; + bss_size = exheader_header.codeset_info.bss_size; + core_version = exheader_header.arm11_system_local_caps.core_version; + priority = exheader_header.arm11_system_local_caps.priority; + resource_limit_category = exheader_header.arm11_system_local_caps.resource_limit_category; + + LOG_INFO(Loader, "Name: %s" , exheader_header.codeset_info.name); + LOG_DEBUG(Loader, "Code compressed: %s" , is_compressed ? "yes" : "no"); + LOG_DEBUG(Loader, "Entry point: 0x%08X", entry_point); + LOG_DEBUG(Loader, "Code size: 0x%08X", code_size); + LOG_DEBUG(Loader, "Stack size: 0x%08X", stack_size); + LOG_DEBUG(Loader, "Bss size: 0x%08X", bss_size); + LOG_DEBUG(Loader, "Core version: %d" , core_version); + LOG_DEBUG(Loader, "Thread priority: 0x%X" , priority); + LOG_DEBUG(Loader, "Resource limit descriptor: 0x%08X", exheader_header.arm11_system_local_caps.resource_limit_descriptor); + LOG_DEBUG(Loader, "Resource limit category: %d" , resource_limit_category); // Read ExeFS... exefs_offset = ncch_header.exefs_offset * kBlockSize; u32 exefs_size = ncch_header.exefs_size * kBlockSize; - LOG_DEBUG(Loader, "ExeFS offset: 0x%08X", exefs_offset); - LOG_DEBUG(Loader, "ExeFS size: 0x%08X", exefs_size); + LOG_DEBUG(Loader, "ExeFS offset: 0x%08X", exefs_offset); + LOG_DEBUG(Loader, "ExeFS size: 0x%08X", exefs_size); file->Seek(exefs_offset + ncch_offset, SEEK_SET); if (file->ReadBytes(&exefs_header, sizeof(ExeFs_Header)) != sizeof(ExeFs_Header)) @@ -247,8 +260,8 @@ ResultStatus AppLoader_NCCH::ReadRomFS(std::vector<u8>& buffer) const { u32 romfs_offset = ncch_offset + (ncch_header.romfs_offset * kBlockSize) + 0x1000; u32 romfs_size = (ncch_header.romfs_size * kBlockSize) - 0x1000; - LOG_DEBUG(Loader, "RomFS offset: 0x%08X", romfs_offset); - LOG_DEBUG(Loader, "RomFS size: 0x%08X", romfs_size); + LOG_DEBUG(Loader, "RomFS offset: 0x%08X", romfs_offset); + LOG_DEBUG(Loader, "RomFS size: 0x%08X", romfs_size); buffer.resize(romfs_size); diff --git a/src/core/loader/ncch.h b/src/core/loader/ncch.h index f6f670060..3dd151dbd 100644 --- a/src/core/loader/ncch.h +++ b/src/core/loader/ncch.h @@ -43,6 +43,8 @@ struct NCCH_Header { u8 romfs_super_block_hash[0x20]; }; +static_assert(sizeof(NCCH_Header) == 0x200, "NCCH header structure size is wrong"); + //////////////////////////////////////////////////////////////////////////////////////////////////// // ExeFS (executable file system) headers @@ -77,11 +79,11 @@ struct ExHeader_CodeSetInfo { u8 name[8]; ExHeader_SystemInfoFlags flags; ExHeader_CodeSegmentInfo text; - u8 stacksize[4]; + u32 stack_size; ExHeader_CodeSegmentInfo ro; u8 reserved[4]; ExHeader_CodeSegmentInfo data; - u8 bsssize[4]; + u32 bss_size; }; struct ExHeader_DependencyList{ @@ -107,9 +109,9 @@ struct ExHeader_ARM11_SystemLocalCaps{ u32 core_version; u8 flags[3]; u8 priority; - u8 resource_limit_descriptor[0x16][2]; + u8 resource_limit_descriptor[0x10][2]; ExHeader_StorageInfo storage_info; - u8 service_access_control[0x32][8]; + u8 service_access_control[0x20][8]; u8 ex_service_access_control[0x2][8]; u8 reserved[0xf]; u8 resource_limit_category; @@ -141,6 +143,8 @@ struct ExHeader_Header{ } access_desc; }; +static_assert(sizeof(ExHeader_Header) == 0x800, "ExHeader structure size is wrong"); + //////////////////////////////////////////////////////////////////////////////////////////////////// // Loader namespace @@ -224,6 +228,12 @@ private: bool is_compressed = false; u32 entry_point = 0; + u32 code_size = 0; + u32 stack_size = 0; + u32 bss_size = 0; + u32 core_version = 0; + u8 priority = 0; + u8 resource_limit_category = 0; u32 ncch_offset = 0; // Offset to NCCH header, can be 0 or after NCSD header u32 exefs_offset = 0; diff --git a/src/core/mem_map.cpp b/src/core/mem_map.cpp index a14e8303e..22e359b3e 100644 --- a/src/core/mem_map.cpp +++ b/src/core/mem_map.cpp @@ -11,30 +11,30 @@ namespace Memory { -u8* g_base = nullptr; ///< The base pointer to the auto-mirrored arena. - -static MemArena arena; ///< The MemArena class - -u8* g_exefs_code = nullptr; ///< ExeFS:/.code is loaded here -u8* g_system_mem = nullptr; ///< System memory -u8* g_heap = nullptr; ///< Application heap (main memory) -u8* g_heap_linear = nullptr; ///< Linear heap -u8* g_vram = nullptr; ///< Video memory (VRAM) pointer -u8* g_shared_mem = nullptr; ///< Shared memory -u8* g_dsp_mem = nullptr; ///< DSP memory -u8* g_kernel_mem; ///< Kernel memory - -static u8* physical_bootrom = nullptr; ///< Bootrom physical memory -static u8* uncached_bootrom = nullptr; - -static u8* physical_exefs_code = nullptr; ///< Phsical ExeFS:/.code is loaded here -static u8* physical_system_mem = nullptr; ///< System physical memory -static u8* physical_fcram = nullptr; ///< Main physical memory (FCRAM) -static u8* physical_heap_gsp = nullptr; ///< GSP heap physical memory -static u8* physical_vram = nullptr; ///< Video physical memory (VRAM) -static u8* physical_shared_mem = nullptr; ///< Physical shared memory -static u8* physical_dsp_mem = nullptr; ///< Physical DSP memory -static u8* physical_kernel_mem; ///< Kernel memory +u8* g_base; ///< The base pointer to the auto-mirrored arena. + +static MemArena arena; ///< The MemArena class + +u8* g_exefs_code; ///< ExeFS:/.code is loaded here +u8* g_system_mem; ///< System memory +u8* g_heap; ///< Application heap (main memory) +u8* g_heap_linear; ///< Linear heap +u8* g_vram; ///< Video memory (VRAM) pointer +u8* g_shared_mem; ///< Shared memory +u8* g_dsp_mem; ///< DSP memory +u8* g_kernel_mem; ///< Kernel memory + +static u8* physical_bootrom; ///< Bootrom physical memory +static u8* uncached_bootrom; + +static u8* physical_exefs_code; ///< Phsical ExeFS:/.code is loaded here +static u8* physical_system_mem; ///< System physical memory +static u8* physical_fcram; ///< Main physical memory (FCRAM) +static u8* physical_heap_gsp; ///< GSP heap physical memory +static u8* physical_vram; ///< Video physical memory (VRAM) +static u8* physical_shared_mem; ///< Physical shared memory +static u8* physical_dsp_mem; ///< Physical DSP memory +static u8* physical_kernel_mem; ///< Kernel memory // We don't declare the IO region in here since its handled by other means. static MemoryView g_views[] = { @@ -73,6 +73,7 @@ void Init() { } g_base = MemoryMap_Setup(g_views, kNumMemViews, flags, &arena); + MemBlock_Init(); LOG_DEBUG(HW_Memory, "initialized OK, RAM at %p (mirror at 0 @ %p)", g_heap, physical_fcram); @@ -81,9 +82,29 @@ void Init() { void Shutdown() { u32 flags = 0; MemoryMap_Shutdown(g_views, kNumMemViews, flags, &arena); - arena.ReleaseSpace(); + MemBlock_Shutdown(); + g_base = nullptr; + g_exefs_code = nullptr; + g_system_mem = nullptr; + g_heap = nullptr; + g_heap_linear = nullptr; + g_vram = nullptr; + g_shared_mem = nullptr; + g_dsp_mem = nullptr; + g_kernel_mem = nullptr; + + physical_bootrom = nullptr; + uncached_bootrom = nullptr; + physical_exefs_code = nullptr; + physical_system_mem = nullptr; + physical_fcram = nullptr; + physical_heap_gsp = nullptr; + physical_vram = nullptr; + physical_shared_mem = nullptr; + physical_dsp_mem = nullptr; + physical_kernel_mem = nullptr; LOG_DEBUG(HW_Memory, "shutdown OK"); } diff --git a/src/core/mem_map.h b/src/core/mem_map.h index ff730593e..1af02973b 100644 --- a/src/core/mem_map.h +++ b/src/core/mem_map.h @@ -171,6 +171,12 @@ u32 MapBlock_Heap(u32 size, u32 operation, u32 permissions); */ u32 MapBlock_HeapLinear(u32 size, u32 operation, u32 permissions); +/// Initialize mapped memory blocks +void MemBlock_Init(); + +/// Shutdown mapped memory blocks +void MemBlock_Shutdown(); + inline const char* GetCharPointer(const VAddr address) { return (const char *)GetPointer(address); } diff --git a/src/core/mem_map_funcs.cpp b/src/core/mem_map_funcs.cpp index 5878b99dc..8759ebdfb 100644 --- a/src/core/mem_map_funcs.cpp +++ b/src/core/mem_map_funcs.cpp @@ -15,7 +15,6 @@ namespace Memory { static std::map<u32, MemoryBlock> heap_map; static std::map<u32, MemoryBlock> heap_linear_map; -static std::map<u32, MemoryBlock> shared_map; /// Convert a physical address to virtual address VAddr PhysicalToVirtualAddress(const PAddr addr) { @@ -185,12 +184,6 @@ u8 *GetPointer(const VAddr vaddr) { } } -/** - * Maps a block of memory on the heap - * @param size Size of block in bytes - * @param operation Memory map operation type - * @param flags Memory allocation flags - */ u32 MapBlock_Heap(u32 size, u32 operation, u32 permissions) { MemoryBlock block; @@ -208,12 +201,6 @@ u32 MapBlock_Heap(u32 size, u32 operation, u32 permissions) { return block.GetVirtualAddress(); } -/** - * Maps a block of memory on the linear heap - * @param size Size of block in bytes - * @param operation Memory map operation type - * @param flags Memory allocation flags - */ u32 MapBlock_HeapLinear(u32 size, u32 operation, u32 permissions) { MemoryBlock block; @@ -231,6 +218,14 @@ u32 MapBlock_HeapLinear(u32 size, u32 operation, u32 permissions) { return block.GetVirtualAddress(); } +void MemBlock_Init() { +} + +void MemBlock_Shutdown() { + heap_map.clear(); + heap_linear_map.clear(); +} + u8 Read8(const VAddr addr) { u8 data = 0; Read<u8>(data, addr); |