From 95e5436f41a3cffaace7c48be72373bebcaf91e4 Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 10 Apr 2014 19:55:59 -0400 Subject: [PATCH 01/49] cleaned up arm_interface, added a setter to set registers for use with HLE return values --- src/core/arm/interpreter/arm_interpreter.cpp | 71 ++++++++++++++------ src/core/arm/interpreter/arm_interpreter.h | 37 +++++++++- 2 files changed, 86 insertions(+), 22 deletions(-) diff --git a/src/core/arm/interpreter/arm_interpreter.cpp b/src/core/arm/interpreter/arm_interpreter.cpp index 81f38f016..4045779d7 100644 --- a/src/core/arm/interpreter/arm_interpreter.cpp +++ b/src/core/arm/interpreter/arm_interpreter.cpp @@ -31,30 +31,61 @@ ARM_Interpreter::ARM_Interpreter() { m_state->Reg[13] = 0x10000000; // Set stack pointer to the top of the stack } -void ARM_Interpreter::SetPC(u32 pc) { - m_state->pc = m_state->Reg[15] = pc; -} - -u32 ARM_Interpreter::GetPC() const { - return m_state->pc; -} - -u32 ARM_Interpreter::GetReg(int index) const { - return m_state->Reg[index]; -} - -u32 ARM_Interpreter::GetCPSR() const { - return m_state->Cpsr; -} - -u64 ARM_Interpreter::GetTicks() const { - return ARMul_Time(m_state); -} - ARM_Interpreter::~ARM_Interpreter() { delete m_state; } +/** + * Set the Program Counter to an address + * @param addr Address to set PC to + */ +void ARM_Interpreter::SetPC(u32 pc) { + m_state->pc = m_state->Reg[15] = pc; +} + +/* + * Get the current Program Counter + * @return Returns current PC + */ +u32 ARM_Interpreter::GetPC() const { + return m_state->pc; +} + +/** + * Get an ARM register + * @param index Register index (0-15) + * @return Returns the value in the register + */ +u32 ARM_Interpreter::GetReg(int index) const { + return m_state->Reg[index]; +} + +/** + * Set an ARM register + * @param index Register index (0-15) + * @param value Value to set register to + */ +void ARM_Interpreter::SetReg(int index, u32 value) { + m_state->Reg[index] = value; +} + +/** + * Get the current CPSR register + * @return Returns the value of the CPSR register + */ +u32 ARM_Interpreter::GetCPSR() const { + return m_state->Cpsr; +} + +/** + * Returns the number of clock ticks since the last reset + * @return Returns number of clock ticks + */ +u64 ARM_Interpreter::GetTicks() const { + return ARMul_Time(m_state); +} + +/// Execture next instruction void ARM_Interpreter::ExecuteInstruction() { m_state->step++; m_state->cycle++; diff --git a/src/core/arm/interpreter/arm_interpreter.h b/src/core/arm/interpreter/arm_interpreter.h index 932046d9a..f3c86f8dd 100644 --- a/src/core/arm/interpreter/arm_interpreter.h +++ b/src/core/arm/interpreter/arm_interpreter.h @@ -12,22 +12,55 @@ class ARM_Interpreter : virtual public ARM_Interface { public: + ARM_Interpreter(); ~ARM_Interpreter(); - void ExecuteInstruction(); - + /** + * Set the Program Counter to an address + * @param addr Address to set PC to + */ void SetPC(u32 pc); + /* + * Get the current Program Counter + * @return Returns current PC + */ u32 GetPC() const; + /** + * Get an ARM register + * @param index Register index (0-15) + * @return Returns the value in the register + */ u32 GetReg(int index) const; + /** + * Set an ARM register + * @param index Register index (0-15) + * @param value Value to set register to + */ + void SetReg(int index, u32 value); + + /** + * Get the current CPSR register + * @return Returns the value of the CPSR register + */ u32 GetCPSR() const; + /** + * Returns the number of clock ticks since the last reset + * @return Returns number of clock ticks + */ u64 GetTicks() const; +protected: + + /// Execture next instruction + void ExecuteInstruction(); + private: + ARMul_State* m_state; DISALLOW_COPY_AND_ASSIGN(ARM_Interpreter); From d9bb4f11c61503bd2e40d2ea9fc9795c55e48c2e Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 10 Apr 2014 19:56:30 -0400 Subject: [PATCH 02/49] added Memory::GetCharPointer to read strings from HLE functions --- src/core/mem_map.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/core/mem_map.h b/src/core/mem_map.h index 1a3bd7234..94469ec8c 100644 --- a/src/core/mem_map.h +++ b/src/core/mem_map.h @@ -70,4 +70,8 @@ void Write32(const u32 addr, const u32 data); u8* GetPointer(const u32 Address); +inline const char* GetCharPointer(const u32 address) { + return (const char *)GetPointer(address); +} + } // namespace From fccbfc208c53ef6c3424531d8f4a42d3d23b200a Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 10 Apr 2014 19:57:56 -0400 Subject: [PATCH 03/49] missed this file with commit 95e5436f --- src/core/arm/arm_interface.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/core/arm/arm_interface.h b/src/core/arm/arm_interface.h index dafde8368..eee4726db 100644 --- a/src/core/arm/arm_interface.h +++ b/src/core/arm/arm_interface.h @@ -42,6 +42,13 @@ public: */ virtual u32 GetReg(int index) const = 0; + /** + * Set an ARM register + * @param index Register index (0-15) + * @param value Value to set register to + */ + virtual void SetReg(int index, u32 value) = 0; + /** * Get the current CPSR register * @return Returns the value of the CPSR register @@ -59,11 +66,13 @@ public: return m_num_instructions; } -private: +protected: /// Execture next instruction virtual void ExecuteInstruction() = 0; +private: + u64 m_num_instructions; ///< Number of instructions executed DISALLOW_COPY_AND_ASSIGN(ARM_Interface); From f68de21ad1cd267029b60ee3767d219c46f5fba0 Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 10 Apr 2014 19:58:28 -0400 Subject: [PATCH 04/49] added initial modules for setting up SysCall HLE --- src/core/core.cpp | 18 + src/core/core.vcxproj | 4 + src/core/core.vcxproj.filters | 15 + src/core/hle/function_wrappers.h | 726 +++++++++++++++++++++++++++++++ src/core/hle/hle.h | 35 ++ src/core/hle/hle_syscall.cpp | 22 + src/core/hle/hle_syscall.h | 42 ++ 7 files changed, 862 insertions(+) create mode 100644 src/core/hle/function_wrappers.h create mode 100644 src/core/hle/hle.h create mode 100644 src/core/hle/hle_syscall.cpp create mode 100644 src/core/hle/hle_syscall.h diff --git a/src/core/core.cpp b/src/core/core.cpp index 28f6b6c58..acb0a6e82 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -24,6 +24,24 @@ void RunLoop() { /// Step the CPU one instruction void SingleStep() { + + char current_instr[512]; + + if (g_app_core->GetPC() == 0x080D1534) { + g_disasm->disasm(g_app_core->GetPC(), Memory::Read32(g_app_core->GetPC()), current_instr); + + + NOTICE_LOG(ARM11, "0x%08X 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X", + g_app_core->GetReg(0), + g_app_core->GetReg(1), + g_app_core->GetReg(2), + g_app_core->GetReg(3), Memory::Read32(g_app_core->GetReg(0)), Memory::Read32(g_app_core->GetReg(1))); + + + NOTICE_LOG(ARM11, "0x%08X\t%s", g_app_core->GetPC(), current_instr); + } + + g_app_core->Step(); HW::Update(); } diff --git a/src/core/core.vcxproj b/src/core/core.vcxproj index 1800b5512..55ce508a6 100644 --- a/src/core/core.vcxproj +++ b/src/core/core.vcxproj @@ -152,6 +152,7 @@ + @@ -182,6 +183,9 @@ + + + diff --git a/src/core/core.vcxproj.filters b/src/core/core.vcxproj.filters index 2efac8127..7bac04a2d 100644 --- a/src/core/core.vcxproj.filters +++ b/src/core/core.vcxproj.filters @@ -22,6 +22,9 @@ {7ae34319-6d72-4d12-bc62-9b438ba9241f} + + {8b62769e-3e2a-4a57-a7bc-b3b2933c2bc7} + @@ -75,6 +78,9 @@ + + hle + @@ -148,6 +154,15 @@ + + hle + + + hle + + + hle + diff --git a/src/core/hle/function_wrappers.h b/src/core/hle/function_wrappers.h new file mode 100644 index 000000000..22588d95d --- /dev/null +++ b/src/core/hle/function_wrappers.h @@ -0,0 +1,726 @@ +// Copyright (c) 2012- PPSSPP Project. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 2.0 or later versions. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License 2.0 for more details. + +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ + +// Official git repository and contact information can be found at +// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. + +#pragma once + +#include "common/common_types.h" +#include "core/mem_map.h" +#include "core/hle/hle.h" + +// For easy parameter parsing and return value processing. + +//32bit wrappers +template void WrapV_V() { + func(); +} + +template void WrapU_V() { + RETURN(func()); +} + +template void WrapI_VC() { + u32 retval = func(Memory::GetPointer(PARAM(0)), Memory::GetCharPointer(PARAM(1))); + RETURN(retval); +} + +template void WrapU_IVI() { + u32 retval = func(PARAM(0), Memory::GetPointer(PARAM(1)), PARAM(2)); + RETURN(retval); +} + +template void WrapI_CIIU() { + u32 retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2), PARAM(3)); + RETURN(retval); +} + +template void WrapI_ICUVVUI() { + u32 retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1)), PARAM(2), Memory::GetPointer(PARAM(3)),Memory::GetPointer(PARAM(4)), PARAM(5), PARAM(6) ); + RETURN(retval); +} + +// Hm, do so many params get passed in registers? +template void WrapI_CICIIIII() { + u32 retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), Memory::GetCharPointer(PARAM(2)), + PARAM(3), PARAM(4), PARAM(5), PARAM(6), PARAM(7)); + RETURN(retval); +} + +// Hm, do so many params get passed in registers? +template void WrapI_CIIIIII() { + u32 retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2), + PARAM(3), PARAM(4), PARAM(5), PARAM(6)); + RETURN(retval); +} + +// Hm, do so many params get passed in registers? +template void WrapI_IIIIIIU() { + u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4), PARAM(5), PARAM(6)); + RETURN(retval); +} + +// Hm, do so many params get passed in registers? +template void WrapI_IIIIIIIIU() { + u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4), PARAM(5), PARAM(6), PARAM(7), PARAM(8)); + RETURN(retval); +} + +template void WrapU_IV() { + u32 retval = func(PARAM(0), Memory::GetPointer(PARAM(1))); + RETURN(retval); +} + +template void WrapF_V() { + RETURNF(func()); +} + +// TODO: Not sure about the floating point parameter passing +template void WrapF_IFU() { + RETURNF(func(PARAM(0), PARAMF(0), PARAM(1))); +} + +template void WrapU_U() { + u32 retval = func(PARAM(0)); + RETURN(retval); +} + +template void WrapU_UI() { + u32 retval = func(PARAM(0), PARAM(1)); + RETURN(retval); +} + +template void WrapI_U() { + int retval = func(PARAM(0)); + RETURN(retval); +} + +template void WrapI_UI() { + int retval = func(PARAM(0), PARAM(1)); + RETURN(retval); +} + +template void WrapI_UIIU() { + int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); + RETURN(retval); +} + +template void WrapU_IUI() { + u32 retval = func(PARAM(0), PARAM(1), PARAM(2)); + RETURN(retval); +} + +template void WrapI_UU() { + int retval = func(PARAM(0), PARAM(1)); + RETURN(retval); +} + +template void WrapI_UFF() { + // Not sure about the float arguments. + int retval = func(PARAM(0), PARAMF(0), PARAMF(1)); + RETURN(retval); +} + +template void WrapI_UUU() { + int retval = func(PARAM(0), PARAM(1), PARAM(2)); + RETURN(retval); +} + +template void WrapI_UUUI() { + int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); + RETURN(retval); +} + +template void WrapI_UUUIIII() { + int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4), PARAM(5), PARAM(6)); + RETURN(retval); +} + +template void WrapI_UUUU() { + int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); + RETURN(retval); +} + +template void WrapI_UUUUU() { + int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)); + RETURN(retval); +} + +template void WrapI_V() { + int retval = func(); + RETURN(retval); +} + +template void WrapU_I() { + u32 retval = func(PARAM(0)); + RETURN(retval); +} + +template void WrapU_IIU() { + u32 retval = func(PARAM(0), PARAM(1), PARAM(2)); + RETURN(retval); +} + +template void WrapI_I() { + int retval = func(PARAM(0)); + RETURN(retval); +} + +template void WrapV_U() { + func(PARAM(0)); +} + +template void WrapV_I() { + func(PARAM(0)); +} + +template void WrapV_UU() { + func(PARAM(0), PARAM(1)); +} + +template void WrapV_II() { + func(PARAM(0), PARAM(1)); +} + +template void WrapV_UC() { + func(PARAM(0), Memory::GetCharPointer(PARAM(1))); +} + +template void WrapI_UC() { + int retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1))); + RETURN(retval); +} + +template void WrapI_UCI() { + int retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1)), PARAM(2)); + RETURN(retval); +} + +template void WrapU_UIIIII() { + u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4), PARAM(5)); + RETURN(retval); +} + +template void WrapU_UIIIU() { + u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)); + RETURN(retval); +} + +template void WrapU_UIIIIII() { + u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4), PARAM(5), PARAM(6)); + RETURN(retval); +} + +template void WrapU_UU() { + u32 retval = func(PARAM(0), PARAM(1)); + RETURN(retval); +} + +template void WrapU_UUI() { + u32 retval = func(PARAM(0), PARAM(1), PARAM(2)); + RETURN(retval); +} + +template void WrapU_UUII() { + u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); + RETURN(retval); +} + +template void WrapU_CUUU() { + u32 retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2), PARAM(3)); + RETURN(retval); +} + +template void WrapV_UIUII() { + func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)); +} + +template void WrapU_UIUII() { + u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)); + RETURN(retval); +} + +template void WrapI_UIUII() { + int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)); + RETURN(retval); +} + +template void WrapU_UIUI() { + u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); + RETURN(retval); +} + +template void WrapI_UIUI() { + u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); + RETURN(retval); +} + +template void WrapU_UIU() { + u32 retval = func(PARAM(0), PARAM(1), PARAM(2)); + RETURN(retval); +} + +template void WrapU_UIUU() { + u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); + RETURN(retval); +} + +template void WrapU_UII() { + u32 retval = func(PARAM(0), PARAM(1), PARAM(2)); + RETURN(retval); +} + +template void WrapU_UIIU() { + u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); + RETURN(retval); +} + +template void WrapI_UIIUU() { + u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)); + RETURN(retval); +} + +template void WrapI_UUII() { + int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); + RETURN(retval); +} + +template void WrapI_UUIII() { + int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)); + RETURN(retval); +} + +template void WrapV_UIII() { + func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); +} + +template void WrapV_UIIIII() { + func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4), PARAM(5)); +} + +template void WrapV_UII() { + func(PARAM(0), PARAM(1), PARAM(2)); +} + +template void WrapU_IU() { + int retval = func(PARAM(0), PARAM(1)); + RETURN(retval); +} + +template void WrapI_IU() { + int retval = func(PARAM(0), PARAM(1)); + RETURN(retval); +} + +template void WrapI_UUI() { + int retval = func(PARAM(0), PARAM(1), PARAM(2)); + RETURN(retval); +} + +template void WrapI_UUIU() { + int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); + RETURN(retval); +} + +template void WrapI_II() { + int retval = func(PARAM(0), PARAM(1)); + RETURN(retval); +} + +template void WrapI_III() { + int retval = func(PARAM(0), PARAM(1), PARAM(2)); + RETURN(retval); +} + +template void WrapI_IUI() { + int retval = func(PARAM(0), PARAM(1), PARAM(2)); + RETURN(retval); +} + +template void WrapI_IIII() { + int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); + RETURN(retval); +} + +template void WrapI_UIII() { + int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); + RETURN(retval); +} + +template void WrapI_IIIUI() { + int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)); + RETURN(retval); +} + +template void WrapI_IUUII() { + int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)); + RETURN(retval); +} + +template void WrapI_ICIUU() { + int retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1)), PARAM(2), PARAM(3), PARAM(4)); + RETURN(retval); +} + +template void WrapI_IIU() { + int retval = func(PARAM(0), PARAM(1), PARAM(2)); + RETURN(retval); +} + +template void WrapV_IU() { + func(PARAM(0), PARAM(1)); +} + +template void WrapV_UI() { + func(PARAM(0), PARAM(1)); +} + +template void WrapU_C() { + u32 retval = func(Memory::GetCharPointer(PARAM(0))); + RETURN(retval); +} + +template void WrapU_CCCU() { + u32 retval = func(Memory::GetCharPointer(PARAM(0)), + Memory::GetCharPointer(PARAM(1)), Memory::GetCharPointer(PARAM(2)), + PARAM(3)); + RETURN(retval); +} + +template void WrapI_C() { + int retval = func(Memory::GetCharPointer(PARAM(0))); + RETURN(retval); +} + +template void WrapI_CU() { + int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1)); + RETURN(retval); +} + +template void WrapI_CUI() { + int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2)); + RETURN(retval); +} + +template void WrapI_ICIU() { + int retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1)), PARAM(2), PARAM(3)); + RETURN(retval); +} + +template void WrapI_CIU() { + int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2)); + RETURN(retval); +} + +template void WrapI_CUU() { + int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2)); + RETURN(retval); +} + +template void WrapI_CUUU() { + int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2), + PARAM(3)); + RETURN(retval); +} + +template void WrapI_CCII() { + int retval = func(Memory::GetCharPointer(PARAM(0)), Memory::GetCharPointer(PARAM(1)), PARAM(2), PARAM(3)); + RETURN(retval); +} + +template void WrapI_CUUIUU() { + int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2), + PARAM(3), PARAM(4), PARAM(5)); + RETURN(retval); +} + +template void WrapI_CIIUII() { + int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2), + PARAM(3), PARAM(4), PARAM(5)); + RETURN(retval); +} + +template void WrapI_CIUUU() { + int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2), + PARAM(3), PARAM(4)); + RETURN(retval); +} + +template void WrapI_CUUUUU() { + int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2), + PARAM(3), PARAM(4), PARAM(5)); + RETURN(retval); +} + +template void WrapU_CU() { + u32 retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1)); + RETURN((u32) retval); +} + +template void WrapU_UC() { + u32 retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1))); + RETURN(retval); +} + +template void WrapU_CUU() { + u32 retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2)); + RETURN((u32) retval); +} + +template void WrapU_III() { + u32 retval = func(PARAM(0), PARAM(1), PARAM(2)); + RETURN(retval); +} + +template void WrapU_II() { + u32 retval = func(PARAM(0), PARAM(1)); + RETURN(retval); +} + +template void WrapU_IIII() { + u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); + RETURN(retval); +} + +template void WrapU_IUU() { + u32 retval = func(PARAM(0), PARAM(1), PARAM(2)); + RETURN(retval); +} + +template void WrapU_IUUU() { + u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); + RETURN(retval); +} + +template void WrapU_IUUUU() { + u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)); + RETURN(retval); +} + +template void WrapU_UUU() { + u32 retval = func(PARAM(0), PARAM(1), PARAM(2)); + RETURN(retval); +} + +template void WrapV_IUU() { + func(PARAM(0), PARAM(1), PARAM(2)); +} + +template void WrapV_IIU() { + func(PARAM(0), PARAM(1), PARAM(2)); +} + +template void WrapV_UIU() { + func(PARAM(0), PARAM(1), PARAM(2)); +} + +template void WrapI_UIU() { + int retval = func(PARAM(0), PARAM(1), PARAM(2)); + RETURN(retval); +} + +template void WrapV_IUUUU() { + func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)); +} + +template void WrapV_UUU() { + func(PARAM(0), PARAM(1), PARAM(2)); +} + +template void WrapV_UUUU() { + func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); +} + +template void WrapV_CUIU() { + func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2), PARAM(3)); +} + +template void WrapI_CUIU() { + int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2), PARAM(3)); + RETURN(retval); +} + +template void WrapV_UCUIU() { + func(PARAM(0), Memory::GetCharPointer(PARAM(1)), PARAM(2), PARAM(3), + PARAM(4)); +} + +template void WrapI_UCUIU() { + int retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1)), PARAM(2), + PARAM(3), PARAM(4)); + RETURN(retval); +} + +template void WrapV_CUIIU() { + func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2), PARAM(3), + PARAM(4)); +} + +template void WrapI_CUIIU() { + int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2), + PARAM(3), PARAM(4)); + RETURN(retval); +} + +template void WrapU_UUUU() { + u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); + RETURN(retval); +} + +template void WrapU_UCUU() { + u32 retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1)), PARAM(2), PARAM(3)); + RETURN(retval); +} + +template void WrapU_UUUI() { + u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); + RETURN(retval); +} + +template void WrapU_UUUIU() { + u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)); + RETURN(retval); +} + +template void WrapU_UUUIUI() { + u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4), PARAM(5)); + RETURN(retval); +} + +template void WrapU_UUIU() { + u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); + RETURN(retval); +} + +template void WrapU_UIII() { + u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); + RETURN(retval); +} + +template void WrapI_IUUUU() { + int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)); + RETURN(retval); +} + +template void WrapI_IUUUUU() { + int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4), PARAM(5)); + RETURN(retval); +} + +template void WrapI_IUII() { + int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); + RETURN(retval); +} +template void WrapU_UUUUU() { + u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)); + RETURN(retval); +} + +template void WrapV_UUUUU() { + func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)); +} + +template void WrapU_CC() { + int retval = func(Memory::GetCharPointer(PARAM(0)), + Memory::GetCharPointer(PARAM(1))); + RETURN(retval); +} + +template void WrapV_CI() { + func(Memory::GetCharPointer(PARAM(0)), PARAM(1)); +} + +template void WrapU_CI() { + int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1)); + RETURN(retval); +} + +template void WrapU_CII() { + int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2)); + RETURN(retval); +} + +template void WrapU_CIUIU() { + int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2), + PARAM(3), PARAM(4)); + RETURN(retval); +} + +template void WrapU_CIUIUI() { + u32 retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2), + PARAM(3), PARAM(4), PARAM(5)); + RETURN(retval); +} + +template void WrapU_UUUUUU() { + u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4), + PARAM(5)); + RETURN(retval); +} + +template void WrapI_IUUU() { + int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); + RETURN(retval); +} + +template void WrapI_IUU() { + int retval = func(PARAM(0), PARAM(1), PARAM(2)); + RETURN(retval); +} + +template void WrapU_UUUUUUU() { + u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4), PARAM(5), PARAM(6)); + RETURN(retval); +} + +template void WrapI_UIUU() { + u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); + RETURN(retval); +} + +template void WrapI_IC() { + int retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1))); + RETURN(retval); +} + +template void WrapI_ICCUI() { + int retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1)), Memory::GetCharPointer(PARAM(2)), PARAM(3), PARAM(4)); + RETURN(retval); +} + +template void WrapI_ICCI() { + int retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1)), Memory::GetCharPointer(PARAM(2)), PARAM(3)); + RETURN(retval); +} + +template void WrapI_CII() { + int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2)); + RETURN(retval); +} + +template void WrapI_ICI() { + int retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1)), PARAM(2)); + RETURN(retval); +} + +template void WrapI_IVVVVUI(){ + u32 retval = func(PARAM(0), Memory::GetPointer(PARAM(1)), Memory::GetPointer(PARAM(2)), Memory::GetPointer(PARAM(3)), Memory::GetPointer(PARAM(4)), PARAM(5), PARAM(6) ); + RETURN(retval); +} + +template void WrapI_ICUVIII(){ + u32 retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1)), PARAM(2), Memory::GetPointer(PARAM(3)), PARAM(4), PARAM(5), PARAM(6)); + RETURN(retval); +} diff --git a/src/core/hle/hle.h b/src/core/hle/hle.h new file mode 100644 index 000000000..6780b52c4 --- /dev/null +++ b/src/core/hle/hle.h @@ -0,0 +1,35 @@ +// Copyright 2014 Citra Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#pragma once + +#include "common/common_types.h" +#include "core/core.h" + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +typedef void (*HLEFunc)(); +typedef void (*SysCallFunc)(); + +struct HLEFunction { + u32 id; + HLEFunc func; + const char* name; + u32 flags; +}; + +struct HLEModule { + const char* name; + int num_funcs; + const HLEFunction* func_table; +}; + +struct SysCall { + u8 id; + SysCallFunc func; + const char* name; +}; + +#define PARAM(n) Core::g_app_core->GetReg(n) +#define RETURN(n) Core::g_app_core->SetReg(0, n) diff --git a/src/core/hle/hle_syscall.cpp b/src/core/hle/hle_syscall.cpp new file mode 100644 index 000000000..c8a516848 --- /dev/null +++ b/src/core/hle/hle_syscall.cpp @@ -0,0 +1,22 @@ +// Copyright 2014 Citra Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#include "core/hle/function_wrappers.h" +#include "core/hle/hle_syscall.h" + +//////////////////////////////////////////////////////////////////////////////////////////////////// + + + +Result SVC_ConnectToPort(void* out, const char* port_name) { + NOTICE_LOG(OSHLE, "SVC_ConnectToPort called, port_name: %s", port_name); + return 0; +} + +const SysCall SysCallTable[] = { + {0x2D, WrapI_VC, "svcConnectToPort"}, +}; + +void Register_SysCalls() { +} diff --git a/src/core/hle/hle_syscall.h b/src/core/hle/hle_syscall.h new file mode 100644 index 000000000..506dcfc78 --- /dev/null +++ b/src/core/hle/hle_syscall.h @@ -0,0 +1,42 @@ +// Copyright 2014 Citra Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#pragma once + +#include "common/common_types.h" + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +//template +//class KernelObject { +//public: +// virtual ~KernelObject() {} +// +// T GetNative() const { +// return m_native; +// } +// +// void SetNative(const T& native) { +// m_native = native; +// } +// +// virtual const char *GetTypeName() {return "[BAD KERNEL OBJECT TYPE]";} +// virtual const char *GetName() {return "[UNKNOWN KERNEL OBJECT]";} +// +//private: +// T m_native; +//}; + +//class Handle : public KernelObject { +// const char* GetTypeName() { +// return "Handle"; +// } +//}; + + +typedef u32 Handle; +typedef s32 Result; + + +Result ConnectToPort(Handle* out, const char* port_name); From 2a7d7ce55d51a1cf893d14e893b87941df4a2f03 Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 10 Apr 2014 21:30:00 -0400 Subject: [PATCH 05/49] - removed syscall classes (will just use HLEFunction) - added hle.cpp and module registration - removed unused code --- src/core/core.vcxproj | 1 + src/core/core.vcxproj.filters | 3 +++ src/core/hle.cpp | 33 +++++++++++++++++++++++++++++++++ src/core/hle/hle.h | 18 ++++++++++-------- src/core/hle/hle_syscall.cpp | 10 ++++++---- src/core/hle/hle_syscall.h | 4 +--- 6 files changed, 54 insertions(+), 15 deletions(-) create mode 100644 src/core/hle.cpp diff --git a/src/core/core.vcxproj b/src/core/core.vcxproj index 55ce508a6..8097a47d3 100644 --- a/src/core/core.vcxproj +++ b/src/core/core.vcxproj @@ -152,6 +152,7 @@ + diff --git a/src/core/core.vcxproj.filters b/src/core/core.vcxproj.filters index 7bac04a2d..79bddf09a 100644 --- a/src/core/core.vcxproj.filters +++ b/src/core/core.vcxproj.filters @@ -81,6 +81,9 @@ hle + + hle + diff --git a/src/core/hle.cpp b/src/core/hle.cpp new file mode 100644 index 000000000..f0c7d2178 --- /dev/null +++ b/src/core/hle.cpp @@ -0,0 +1,33 @@ +// Copyright 2014 Citra Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#include + +#include "core/hle/hle.h" +#include "core/hle/hle_syscall.h" + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +namespace HLE { + +static std::vector g_module_db; + +void RegisterModule(const char *name, int num_functions, const HLEFunction *func_table) { + HLEModule module = {name, num_functions, func_table}; + g_module_db.push_back(module); +} + +void RegisterAllModules() { + Register_SysCall(); +} + +void Init() { + RegisterAllModules(); +} + +void Shutdown() { + g_module_db.clear(); +} + +} // namespace diff --git a/src/core/hle/hle.h b/src/core/hle/hle.h index 6780b52c4..6648c787f 100644 --- a/src/core/hle/hle.h +++ b/src/core/hle/hle.h @@ -10,13 +10,11 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// typedef void (*HLEFunc)(); -typedef void (*SysCallFunc)(); struct HLEFunction { u32 id; HLEFunc func; const char* name; - u32 flags; }; struct HLEModule { @@ -25,11 +23,15 @@ struct HLEModule { const HLEFunction* func_table; }; -struct SysCall { - u8 id; - SysCallFunc func; - const char* name; -}; - #define PARAM(n) Core::g_app_core->GetReg(n) #define RETURN(n) Core::g_app_core->SetReg(0, n) + +namespace HLE { + +void Init(); + +void Shutdown(); + +void RegisterModule(const char *name, int num_functions, const HLEFunction *func_table); + +} // namespace diff --git a/src/core/hle/hle_syscall.cpp b/src/core/hle/hle_syscall.cpp index c8a516848..b17a2e220 100644 --- a/src/core/hle/hle_syscall.cpp +++ b/src/core/hle/hle_syscall.cpp @@ -7,16 +7,18 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// - +typedef u32 Handle; +typedef s32 Result; Result SVC_ConnectToPort(void* out, const char* port_name) { - NOTICE_LOG(OSHLE, "SVC_ConnectToPort called, port_name: %s", port_name); + NOTICE_LOG(OSHLE, "svcConnectToPort called, port_name: %s", port_name); return 0; } -const SysCall SysCallTable[] = { +const HLEFunction SysCallTable[] = { {0x2D, WrapI_VC, "svcConnectToPort"}, }; -void Register_SysCalls() { +void Register_SysCall() { + HLE::RegisterModule("SysCallTable", ARRAY_SIZE(SysCallTable), SysCallTable); } diff --git a/src/core/hle/hle_syscall.h b/src/core/hle/hle_syscall.h index 506dcfc78..643af0bf4 100644 --- a/src/core/hle/hle_syscall.h +++ b/src/core/hle/hle_syscall.h @@ -35,8 +35,6 @@ //}; -typedef u32 Handle; -typedef s32 Result; -Result ConnectToPort(Handle* out, const char* port_name); +void Register_SysCall(); From 3bd041f5b0cd481ded892594d569462492679e39 Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 10 Apr 2014 22:15:07 -0400 Subject: [PATCH 06/49] changed some naming/misc cleanups --- src/core/hle.cpp | 6 +++--- src/core/hle/hle.h | 32 +++++++++++++++++--------------- src/core/hle/hle_syscall.cpp | 4 ++-- src/core/hle/hle_syscall.h | 3 --- 4 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/core/hle.cpp b/src/core/hle.cpp index f0c7d2178..8dad7695b 100644 --- a/src/core/hle.cpp +++ b/src/core/hle.cpp @@ -11,10 +11,10 @@ namespace HLE { -static std::vector g_module_db; +static std::vector g_module_db; -void RegisterModule(const char *name, int num_functions, const HLEFunction *func_table) { - HLEModule module = {name, num_functions, func_table}; +void RegisterModule(std::string name, int num_functions, const FunctionDef* func_table) { + ModuleDef module = {name, num_functions, func_table}; g_module_db.push_back(module); } diff --git a/src/core/hle/hle.h b/src/core/hle/hle.h index 6648c787f..35c8a4621 100644 --- a/src/core/hle/hle.h +++ b/src/core/hle/hle.h @@ -9,29 +9,31 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// -typedef void (*HLEFunc)(); - -struct HLEFunction { - u32 id; - HLEFunc func; - const char* name; -}; - -struct HLEModule { - const char* name; - int num_funcs; - const HLEFunction* func_table; -}; - #define PARAM(n) Core::g_app_core->GetReg(n) #define RETURN(n) Core::g_app_core->SetReg(0, n) +//////////////////////////////////////////////////////////////////////////////////////////////////// + namespace HLE { +typedef void (*Func)(); + +struct FunctionDef { + u32 id; + Func func; + std::string name; +}; + +struct ModuleDef { + std::string name; + int num_funcs; + const FunctionDef* func_table; +}; + void Init(); void Shutdown(); -void RegisterModule(const char *name, int num_functions, const HLEFunction *func_table); +void RegisterModule(std::string name, int num_functions, const FunctionDef *func_table); } // namespace diff --git a/src/core/hle/hle_syscall.cpp b/src/core/hle/hle_syscall.cpp index b17a2e220..fdcaa914f 100644 --- a/src/core/hle/hle_syscall.cpp +++ b/src/core/hle/hle_syscall.cpp @@ -15,10 +15,10 @@ Result SVC_ConnectToPort(void* out, const char* port_name) { return 0; } -const HLEFunction SysCallTable[] = { +const HLE::FunctionDef SysCall_Table[] = { {0x2D, WrapI_VC, "svcConnectToPort"}, }; void Register_SysCall() { - HLE::RegisterModule("SysCallTable", ARRAY_SIZE(SysCallTable), SysCallTable); + HLE::RegisterModule("SysCallTable", ARRAY_SIZE(SysCall_Table), SysCall_Table); } diff --git a/src/core/hle/hle_syscall.h b/src/core/hle/hle_syscall.h index 643af0bf4..4faa14535 100644 --- a/src/core/hle/hle_syscall.h +++ b/src/core/hle/hle_syscall.h @@ -34,7 +34,4 @@ // } //}; - - - void Register_SysCall(); From d4cb2aab63d4739db6b09a821a9e715985e615be Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 10 Apr 2014 22:43:48 -0400 Subject: [PATCH 07/49] added logger for generic HLE --- src/common/log.h | 2 +- src/common/log_manager.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/common/log.h b/src/common/log.h index 432a307f0..2eacf05f2 100644 --- a/src/common/log.h +++ b/src/common/log.h @@ -56,7 +56,7 @@ enum LOG_TYPE { WII_IPC_HLE, WII_IPC_NET, WII_IPC_WC24, - WII_IPC_SSL, + HLE, RENDER, LCD, HW, diff --git a/src/common/log_manager.cpp b/src/common/log_manager.cpp index 245760d0d..b2dbbbdac 100644 --- a/src/common/log_manager.cpp +++ b/src/common/log_manager.cpp @@ -68,8 +68,8 @@ LogManager::LogManager() m_Log[LogTypes::LCD] = new LogContainer("LCD", "LCD"); m_Log[LogTypes::WII_IPC_NET] = new LogContainer("WII_IPC_NET", "WII IPC NET"); m_Log[LogTypes::WII_IPC_WC24] = new LogContainer("WII_IPC_WC24", "WII IPC WC24"); - m_Log[LogTypes::WII_IPC_SSL] = new LogContainer("WII_IPC_SSL", "WII IPC SSL"); - m_Log[LogTypes::HW] = new LogContainer("HARDWARE", "HARDWARE"); + m_Log[LogTypes::HLE] = new LogContainer("HLE", "High Level Emulation"); + m_Log[LogTypes::HW] = new LogContainer("HW", "Hardware"); m_Log[LogTypes::ACTIONREPLAY] = new LogContainer("ActionReplay", "ActionReplay"); m_Log[LogTypes::MEMCARD_MANAGER] = new LogContainer("MemCard Manager", "MemCard Manager"); m_Log[LogTypes::NETPLAY] = new LogContainer("NETPLAY", "Netplay"); From 5d95bb98434b8e7cd67010f6064ccdb69c1222bb Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 10 Apr 2014 22:45:40 -0400 Subject: [PATCH 08/49] cleaned up some logging messages --- src/core/core.cpp | 22 ++-------------------- src/core/hw/hw.cpp | 8 ++++---- src/core/mem_map.cpp | 4 ++-- src/core/mem_map_funcs.cpp | 2 +- src/core/system.cpp | 15 ++++++++++----- src/video_core/video_core.cpp | 3 ++- 6 files changed, 21 insertions(+), 33 deletions(-) diff --git a/src/core/core.cpp b/src/core/core.cpp index acb0a6e82..859a62c78 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -24,24 +24,6 @@ void RunLoop() { /// Step the CPU one instruction void SingleStep() { - - char current_instr[512]; - - if (g_app_core->GetPC() == 0x080D1534) { - g_disasm->disasm(g_app_core->GetPC(), Memory::Read32(g_app_core->GetPC()), current_instr); - - - NOTICE_LOG(ARM11, "0x%08X 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X", - g_app_core->GetReg(0), - g_app_core->GetReg(1), - g_app_core->GetReg(2), - g_app_core->GetReg(3), Memory::Read32(g_app_core->GetReg(0)), Memory::Read32(g_app_core->GetReg(1))); - - - NOTICE_LOG(ARM11, "0x%08X\t%s", g_app_core->GetPC(), current_instr); - } - - g_app_core->Step(); HW::Update(); } @@ -58,7 +40,7 @@ void Stop() { /// Initialize the core int Init() { - NOTICE_LOG(MASTER_LOG, "Core initialized OK"); + NOTICE_LOG(MASTER_LOG, "initialized OK"); g_disasm = new ARM_Disasm(); g_app_core = new ARM_Interpreter(); @@ -72,7 +54,7 @@ void Shutdown() { delete g_app_core; delete g_sys_core; - NOTICE_LOG(MASTER_LOG, "Core shutdown OK"); + NOTICE_LOG(MASTER_LOG, "shutdown OK"); } } // namespace diff --git a/src/core/hw/hw.cpp b/src/core/hw/hw.cpp index 44625e3af..7191d7c60 100644 --- a/src/core/hw/hw.cpp +++ b/src/core/hw/hw.cpp @@ -12,12 +12,12 @@ namespace HW { template inline void Read(T &var, const u32 addr) { - NOTICE_LOG(HW, "Hardware read from address %08X", addr); + NOTICE_LOG(HW, "read from address %08X", addr); } template inline void Write(u32 addr, const T data) { - NOTICE_LOG(HW, "Hardware write to address %08X", addr); + NOTICE_LOG(HW, "write to address %08X", addr); } // Explicitly instantiate template functions because we aren't defining this in the header: @@ -40,12 +40,12 @@ void Update() { /// Initialize hardware void Init() { LCD::Init(); - NOTICE_LOG(HW, "Hardware initialized OK"); + NOTICE_LOG(HW, "initialized OK"); } /// Shutdown hardware void Shutdown() { - NOTICE_LOG(HW, "Hardware shutdown OK"); + NOTICE_LOG(HW, "shutdown OK"); } } \ No newline at end of file diff --git a/src/core/mem_map.cpp b/src/core/mem_map.cpp index 96f8d0440..a5865d785 100644 --- a/src/core/mem_map.cpp +++ b/src/core/mem_map.cpp @@ -63,7 +63,7 @@ void Init() { g_scratchpad = new u8[MEM_SCRATCHPAD_SIZE]; - NOTICE_LOG(MEMMAP, "Memory system initialized. RAM at %p (mirror at 0 @ %p)", g_fcram, + NOTICE_LOG(MEMMAP, "initialized OK, RAM at %p (mirror at 0 @ %p)", g_fcram, g_physical_fcram); } @@ -77,7 +77,7 @@ void Shutdown() { g_base = NULL; g_scratchpad = NULL; - NOTICE_LOG(MEMMAP, "Memory system shut down."); + NOTICE_LOG(MEMMAP, "shutdown OK"); } } // namespace diff --git a/src/core/mem_map_funcs.cpp b/src/core/mem_map_funcs.cpp index 4c0e08b3f..00719445f 100644 --- a/src/core/mem_map_funcs.cpp +++ b/src/core/mem_map_funcs.cpp @@ -40,7 +40,7 @@ inline void _Read(T &var, const u32 addr) { var = *((const T*)&g_fcram[addr & MEM_FCRAM_MASK]); } else { - _assert_msg_(MEMMAP, false, "unknown memory read"); + _assert_msg_(MEMMAP, false, "unknown memory read @ 0x%08X", addr); } } diff --git a/src/core/system.cpp b/src/core/system.cpp index edb07fef5..c77092327 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -7,6 +7,7 @@ #include "core/mem_map.h" #include "core/system.h" #include "core/hw/hw.h" +#include "core/hle/hle.h" #include "video_core/video_core.h" @@ -19,15 +20,16 @@ void UpdateState(State state) { } void Init(EmuWindow* emu_window) { - Core::Init(); - Memory::Init(); + Core::Init(); + Memory::Init(); HW::Init(); - CoreTiming::Init(); + HLE::Init(); + CoreTiming::Init(); VideoCore::Init(emu_window); } void RunLoopFor(int cycles) { - RunLoopUntil(CoreTiming::GetTicks() + cycles); + RunLoopUntil(CoreTiming::GetTicks() + cycles); } void RunLoopUntil(u64 global_cycles) { @@ -35,9 +37,12 @@ void RunLoopUntil(u64 global_cycles) { void Shutdown() { Core::Shutdown(); + Memory::Shutdown(); HW::Shutdown(); + HLE::Shutdown(); + CoreTiming::Shutdown(); VideoCore::Shutdown(); - g_ctr_file_system.Shutdown(); + g_ctr_file_system.Shutdown(); } } // namespace diff --git a/src/video_core/video_core.cpp b/src/video_core/video_core.cpp index e227b6795..f2e17f9f9 100644 --- a/src/video_core/video_core.cpp +++ b/src/video_core/video_core.cpp @@ -38,12 +38,13 @@ void Init(EmuWindow* emu_window) { g_current_frame = 0; - NOTICE_LOG(VIDEO, "initialized ok"); + NOTICE_LOG(VIDEO, "initialized OK"); } /// Shutdown the video core void Shutdown() { delete g_renderer; + NOTICE_LOG(VIDEO, "shutdown OK"); } } // namespace From 01bedbf956a261fb339eba6901716510cc8c9ca2 Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 10 Apr 2014 22:49:12 -0400 Subject: [PATCH 09/49] updated logging message --- src/core/hw/hw_lcd.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/hw/hw_lcd.cpp b/src/core/hw/hw_lcd.cpp index fd783a84a..9fb485bac 100644 --- a/src/core/hw/hw_lcd.cpp +++ b/src/core/hw/hw_lcd.cpp @@ -37,12 +37,12 @@ void Update() { /// Initialize hardware void Init() { g_last_ticks = Core::g_app_core->GetTicks(); - NOTICE_LOG(LCD, "LCD initialized OK"); + NOTICE_LOG(LCD, "initialized OK"); } /// Shutdown hardware void Shutdown() { - NOTICE_LOG(LCD, "LCD shutdown OK"); + NOTICE_LOG(LCD, "shutdown OK"); } } // namespace From 2bde8f28561ea9436d13d990f6b129a0e80a325e Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 10 Apr 2014 23:26:12 -0400 Subject: [PATCH 10/49] base code to call a syscall from ARM11 appcore --- src/core/arm/interpreter/armemu.cpp | 3 ++ src/core/hle.cpp | 28 +++++++++++++-- src/core/hle/hle.h | 6 ++-- src/core/hle/hle_syscall.cpp | 55 ++++++++++++++++++++++++++--- src/core/hle/hle_syscall.h | 2 +- 5 files changed, 85 insertions(+), 9 deletions(-) diff --git a/src/core/arm/interpreter/armemu.cpp b/src/core/arm/interpreter/armemu.cpp index 46c51fbe8..6074ff480 100644 --- a/src/core/arm/interpreter/armemu.cpp +++ b/src/core/arm/interpreter/armemu.cpp @@ -16,6 +16,8 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include "core/hle/hle.h" + #include "arm_regformat.h" #include "armdefs.h" #include "armemu.h" @@ -4558,6 +4560,7 @@ ARMul_Emulate26 (ARMul_State * state) // ARMul_OSHandleSWI (state, BITS (0, 23)); // break; //} + HLE::CallSyscall(instr); ARMul_Abort (state, ARMul_SWIV); break; } diff --git a/src/core/hle.cpp b/src/core/hle.cpp index 8dad7695b..d62d2d0ce 100644 --- a/src/core/hle.cpp +++ b/src/core/hle.cpp @@ -13,21 +13,45 @@ namespace HLE { static std::vector g_module_db; +const FunctionDef* GetSyscallInfo(u32 opcode) { + u32 func_num = opcode & 0xFFFFFF; // 8 bits + if (func_num > 0xFF) { + ERROR_LOG(HLE,"Unknown syscall: 0x%02X", func_num); + return NULL; + } + return &g_module_db[0].func_table[func_num]; +} + +void CallSyscall(u32 opcode) { + const FunctionDef *info = GetSyscallInfo(opcode); + + if (!info) { + return; + } + if (info->func) { + info->func(); + } else { + ERROR_LOG(HLE, "Unimplemented HLE function %s", info->name); + } +} + void RegisterModule(std::string name, int num_functions, const FunctionDef* func_table) { ModuleDef module = {name, num_functions, func_table}; g_module_db.push_back(module); } void RegisterAllModules() { - Register_SysCall(); + Register_Syscall(); } void Init() { RegisterAllModules(); + NOTICE_LOG(HLE, "initialized OK"); } void Shutdown() { - g_module_db.clear(); + g_module_db.clear(); + NOTICE_LOG(HLE, "shutdown OK"); } } // namespace diff --git a/src/core/hle/hle.h b/src/core/hle/hle.h index 35c8a4621..e3b8d483a 100644 --- a/src/core/hle/hle.h +++ b/src/core/hle/hle.h @@ -30,10 +30,12 @@ struct ModuleDef { const FunctionDef* func_table; }; +void RegisterModule(std::string name, int num_functions, const FunctionDef *func_table); + +void CallSyscall(u32 opcode); + void Init(); void Shutdown(); -void RegisterModule(std::string name, int num_functions, const FunctionDef *func_table); - } // namespace diff --git a/src/core/hle/hle_syscall.cpp b/src/core/hle/hle_syscall.cpp index fdcaa914f..53d721275 100644 --- a/src/core/hle/hle_syscall.cpp +++ b/src/core/hle/hle_syscall.cpp @@ -10,15 +10,62 @@ typedef u32 Handle; typedef s32 Result; +//////////////////////////////////////////////////////////////////////////////////////////////////// + Result SVC_ConnectToPort(void* out, const char* port_name) { NOTICE_LOG(OSHLE, "svcConnectToPort called, port_name: %s", port_name); return 0; } -const HLE::FunctionDef SysCall_Table[] = { - {0x2D, WrapI_VC, "svcConnectToPort"}, +const HLE::FunctionDef Syscall_Table[] = { + {0x00, NULL, "Unknown"}, + {0x01, NULL, "svcControlMemory"}, + {0x02, NULL, "svcQueryMemory"}, + {0x03, NULL, "svcExitProcess"}, + {0x04, NULL, "svcGetProcessAffinityMask"}, + {0x05, NULL, "svcSetProcessAffinityMask"}, + {0x06, NULL, "svcGetProcessIdealProcessor"}, + {0x07, NULL, "svcSetProcessIdealProcessor"}, + {0x08, NULL, "svcCreateThread"}, + {0x09, NULL, "svcExitThread"}, + {0x0A, NULL, "svcSleepThread"}, + {0x0B, NULL, "svcGetThreadPriority"}, + {0x0C, NULL, "svcSetThreadPriority"}, + {0x0D, NULL, "svcGetThreadAffinityMask"}, + {0x0E, NULL, "svcSetThreadAffinityMask"}, + {0x0F, NULL, "svcGetThreadIdealProcessor"}, + {0x10, NULL, "svcSetThreadIdealProcessor"}, + {0x11, NULL, "svcGetCurrentProcessorNumber"}, + {0x12, NULL, "svcRun"}, + {0x13, NULL, "svcCreateMutex"}, + {0x14, NULL, "svcReleaseMutex"}, + {0x15, NULL, "svcCreateSemaphore"}, + {0x16, NULL, "svcReleaseSemaphore"}, + {0x17, NULL, "svcCreateEvent"}, + {0x18, NULL, "svcSignalEvent"}, + {0x19, NULL, "svcClearEvent"}, + {0x1A, NULL, "svcCreateTimer"}, + {0x1B, NULL, "svcSetTimer"}, + {0x1C, NULL, "svcCancelTimer"}, + {0x1D, NULL, "svcClearTimer"}, + {0x1E, NULL, "svcCreateMemoryBlock"}, + {0x1F, NULL, "svcMapMemoryBlock"}, + {0x20, NULL, "svcUnmapMemoryBlock"}, + {0x21, NULL, "svcCreateAddressArbiter"}, + {0x22, NULL, "svcArbitrateAddress"}, + {0x23, NULL, "svcCloseHandle"}, + {0x24, NULL, "svcWaitSynchronization1"}, + {0x25, NULL, "svcWaitSynchronizationN"}, + {0x26, NULL, "svcSignalAndWait"}, + {0x27, NULL, "svcDuplicateHandle"}, + {0x28, NULL, "svcGetSystemTick"}, + {0x29, NULL, "svcGetHandleInfo"}, + {0x2A, NULL, "svcGetSystemInfo"}, + {0x2B, NULL, "svcGetProcessInfo"}, + {0x2C, NULL, "svcGetThreadInfo"}, + {0x2D, WrapI_VC, "svcConnectToPort"}, }; -void Register_SysCall() { - HLE::RegisterModule("SysCallTable", ARRAY_SIZE(SysCall_Table), SysCall_Table); +void Register_Syscall() { + HLE::RegisterModule("SyscallTable", ARRAY_SIZE(Syscall_Table), Syscall_Table); } diff --git a/src/core/hle/hle_syscall.h b/src/core/hle/hle_syscall.h index 4faa14535..80b20c358 100644 --- a/src/core/hle/hle_syscall.h +++ b/src/core/hle/hle_syscall.h @@ -34,4 +34,4 @@ // } //}; -void Register_SysCall(); +void Register_Syscall(); From e9f0e4967d410fb25081a232b5c3d899dd7a80ed Mon Sep 17 00:00:00 2001 From: bunnei Date: Fri, 11 Apr 2014 14:19:40 -0400 Subject: [PATCH 11/49] added remaining known syscall functions to Syscall_Table --- src/core/hle/hle_syscall.cpp | 80 ++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/src/core/hle/hle_syscall.cpp b/src/core/hle/hle_syscall.cpp index 53d721275..92d9b0c85 100644 --- a/src/core/hle/hle_syscall.cpp +++ b/src/core/hle/hle_syscall.cpp @@ -64,6 +64,86 @@ const HLE::FunctionDef Syscall_Table[] = { {0x2B, NULL, "svcGetProcessInfo"}, {0x2C, NULL, "svcGetThreadInfo"}, {0x2D, WrapI_VC, "svcConnectToPort"}, + {0x2E NULL, "svcSendSyncRequest1"}, + {0x2F NULL, "svcSendSyncRequest2"}, + {0x30 NULL, "svcSendSyncRequest3"}, + {0x31 NULL, "svcSendSyncRequest4"}, + {0x32 NULL, "svcSendSyncRequest"}, + {0x33 NULL, "svcOpenProcess"}, + {0x34 NULL, "svcOpenThread"}, + {0x35 NULL, "svcGetProcessId"}, + {0x36 NULL, "svcGetProcessIdOfThread"}, + {0x37 NULL, "svcGetThreadId"}, + {0x38 NULL, "svcGetResourceLimit"}, + {0x39 NULL, "svcGetResourceLimitLimitValues"}, + {0x3A NULL, "svcGetResourceLimitCurrentValues"}, + {0x3B NULL, "svcGetThreadContext"}, + {0x3C NULL, "svcBreak"}, + {0x3D NULL, "svcOutputDebugString"}, + {0x3E NULL, "svcControlPerformanceCounter"}, + {0x3F, NULL, "Unknown"}, + {0x40, NULL, "Unknown"}, + {0x41, NULL, "Unknown"}, + {0x42, NULL, "Unknown"}, + {0x43, NULL, "Unknown"}, + {0x44, NULL, "Unknown"}, + {0x45, NULL, "Unknown"}, + {0x46, NULL, "Unknown"}, + {0x47 NULL, "svcCreatePort"}, + {0x48 NULL, "svcCreateSessionToPort"}, + {0x49 NULL, "svcCreateSession"}, + {0x4A NULL, "svcAcceptSession"}, + {0x4B NULL, "svcReplyAndReceive1"}, + {0x4C NULL, "svcReplyAndReceive2"}, + {0x4D NULL, "svcReplyAndReceive3"}, + {0x4E NULL, "svcReplyAndReceive4"}, + {0x4F NULL, "svcReplyAndReceive"}, + {0x50 NULL, "svcBindInterrupt"}, + {0x51 NULL, "svcUnbindInterrupt"}, + {0x52 NULL, "svcInvalidateProcessDataCache"}, + {0x53 NULL, "svcStoreProcessDataCache"}, + {0x54 NULL, "svcFlushProcessDataCache"}, + {0x55 NULL, "svcStartInterProcessDma"}, + {0x56 NULL, "svcStopDma"}, + {0x57 NULL, "svcGetDmaState"}, + {0x58 NULL, "svcRestartDma"}, + {0x59, NULL, "Unknown"}, + {0x5A, NULL, "Unknown"}, + {0x5B, NULL, "Unknown"}, + {0x5C, NULL, "Unknown"}, + {0x5D, NULL, "Unknown"}, + {0x5E, NULL, "Unknown"}, + {0x5F, NULL, "Unknown"}, + {0x60 NULL, "svcDebugActiveProcess"}, + {0x61 NULL, "svcBreakDebugProcess"}, + {0x62 NULL, "svcTerminateDebugProcess"}, + {0x63 NULL, "svcGetProcessDebugEvent"}, + {0x64 NULL, "svcContinueDebugEvent"}, + {0x65 NULL, "svcGetProcessList"}, + {0x66 NULL, "svcGetThreadList"}, + {0x67 NULL, "svcGetDebugThreadContext"}, + {0x68 NULL, "svcSetDebugThreadContext"}, + {0x69 NULL, "svcQueryDebugProcessMemory"}, + {0x6A NULL, "svcReadProcessMemory"}, + {0x6B NULL, "svcWriteProcessMemory"}, + {0x6C NULL, "svcSetHardwareBreakPoint"}, + {0x6D NULL, "svcGetDebugThreadParam"}, + {0x6E, NULL, "Unknown"}, + {0x6F, NULL, "Unknown"}, + {0x70 NULL, "svcControlProcessMemory"}, + {0x71 NULL, "svcMapProcessMemory"}, + {0x72 NULL, "svcUnmapProcessMemory"}, + {0x73, NULL, "Unknown"}, + {0x74, NULL, "Unknown"}, + {0x75, NULL, "Unknown"}, + {0x76 NULL, "svcTerminateProcess"}, + {0x77, NULL, "Unknown"}, + {0x78 NULL, "svcCreateResourceLimit"}, + {0x79, NULL, "Unknown"}, + {0x7A, NULL, "Unknown"}, + {0x7B, NULL, "Unknown"}, + {0x7C NULL, "svcKernelSetState"}, + {0x7D NULL, "svcQueryProcessMemory"}, }; void Register_Syscall() { From f6c328cf37fe6e0250c20fcbf128f301b3d71d36 Mon Sep 17 00:00:00 2001 From: bunnei Date: Fri, 11 Apr 2014 18:07:49 -0400 Subject: [PATCH 12/49] moved hle.cpp into hle folder (due to mistake earlier) --- src/core/core.vcxproj | 2 +- src/core/core.vcxproj.filters | 2 +- src/core/{ => hle}/hle.cpp | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename src/core/{ => hle}/hle.cpp (100%) diff --git a/src/core/core.vcxproj b/src/core/core.vcxproj index 8097a47d3..89795ce63 100644 --- a/src/core/core.vcxproj +++ b/src/core/core.vcxproj @@ -152,7 +152,7 @@ - + diff --git a/src/core/core.vcxproj.filters b/src/core/core.vcxproj.filters index 79bddf09a..eece5d486 100644 --- a/src/core/core.vcxproj.filters +++ b/src/core/core.vcxproj.filters @@ -81,7 +81,7 @@ hle - + hle diff --git a/src/core/hle.cpp b/src/core/hle/hle.cpp similarity index 100% rename from src/core/hle.cpp rename to src/core/hle/hle.cpp From 7ea75858984e23ed22ad1dfa8ad0315aaeded538 Mon Sep 17 00:00:00 2001 From: bunnei Date: Fri, 11 Apr 2014 18:09:23 -0400 Subject: [PATCH 13/49] replace tabs with spaces --- src/core/hle/hle.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/core/hle/hle.h b/src/core/hle/hle.h index e3b8d483a..9466be540 100644 --- a/src/core/hle/hle.h +++ b/src/core/hle/hle.h @@ -19,15 +19,15 @@ namespace HLE { typedef void (*Func)(); struct FunctionDef { - u32 id; - Func func; - std::string name; + u32 id; + Func func; + std::string name; }; struct ModuleDef { - std::string name; - int num_funcs; - const FunctionDef* func_table; + std::string name; + int num_funcs; + const FunctionDef* func_table; }; void RegisterModule(std::string name, int num_functions, const FunctionDef *func_table); From 02fbd42e7f006236199698c61ca917092afa1f7d Mon Sep 17 00:00:00 2001 From: bunnei Date: Fri, 11 Apr 2014 18:44:21 -0400 Subject: [PATCH 14/49] - renamed hle_syscall to just syscall - added service.h as an initial service interface --- src/core/core.vcxproj | 5 +- src/core/core.vcxproj.filters | 12 +- src/core/hle/hle.cpp | 4 +- src/core/hle/hle_syscall.h | 37 ----- src/core/hle/service/service.h | 60 +++++++++ src/core/hle/{hle_syscall.cpp => syscall.cpp} | 126 +++++++++--------- src/core/hle/syscall.h | 19 +++ 7 files changed, 157 insertions(+), 106 deletions(-) delete mode 100644 src/core/hle/hle_syscall.h create mode 100644 src/core/hle/service/service.h rename src/core/hle/{hle_syscall.cpp => syscall.cpp} (58%) create mode 100644 src/core/hle/syscall.h diff --git a/src/core/core.vcxproj b/src/core/core.vcxproj index 89795ce63..10ecca596 100644 --- a/src/core/core.vcxproj +++ b/src/core/core.vcxproj @@ -153,7 +153,7 @@ - + @@ -186,7 +186,8 @@ - + + diff --git a/src/core/core.vcxproj.filters b/src/core/core.vcxproj.filters index eece5d486..d450224a4 100644 --- a/src/core/core.vcxproj.filters +++ b/src/core/core.vcxproj.filters @@ -25,6 +25,9 @@ {8b62769e-3e2a-4a57-a7bc-b3b2933c2bc7} + + {812c5189-ca49-4704-b842-3ffad09092d3} + @@ -78,10 +81,10 @@ - + hle - + hle @@ -163,7 +166,10 @@ hle - + + hle\service + + hle diff --git a/src/core/hle/hle.cpp b/src/core/hle/hle.cpp index d62d2d0ce..32aff0eb5 100644 --- a/src/core/hle/hle.cpp +++ b/src/core/hle/hle.cpp @@ -5,7 +5,7 @@ #include #include "core/hle/hle.h" -#include "core/hle/hle_syscall.h" +#include "core/hle/syscall.h" //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -41,7 +41,7 @@ void RegisterModule(std::string name, int num_functions, const FunctionDef* func } void RegisterAllModules() { - Register_Syscall(); + Syscall::Register(); } void Init() { diff --git a/src/core/hle/hle_syscall.h b/src/core/hle/hle_syscall.h deleted file mode 100644 index 80b20c358..000000000 --- a/src/core/hle/hle_syscall.h +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2014 Citra Emulator Project -// Licensed under GPLv2 -// Refer to the license.txt file included. - -#pragma once - -#include "common/common_types.h" - -//////////////////////////////////////////////////////////////////////////////////////////////////// - -//template -//class KernelObject { -//public: -// virtual ~KernelObject() {} -// -// T GetNative() const { -// return m_native; -// } -// -// void SetNative(const T& native) { -// m_native = native; -// } -// -// virtual const char *GetTypeName() {return "[BAD KERNEL OBJECT TYPE]";} -// virtual const char *GetName() {return "[UNKNOWN KERNEL OBJECT]";} -// -//private: -// T m_native; -//}; - -//class Handle : public KernelObject { -// const char* GetTypeName() { -// return "Handle"; -// } -//}; - -void Register_Syscall(); diff --git a/src/core/hle/service/service.h b/src/core/hle/service/service.h new file mode 100644 index 000000000..f15099982 --- /dev/null +++ b/src/core/hle/service/service.h @@ -0,0 +1,60 @@ +// Copyright 2014 Citra Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#pragma once + +#include + +#include "common/common_types.h" +#include "core/hle/syscall.h" + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// Namespace Service + +namespace Service { + +typedef s32 NativeUID; + +/// Interface to a CTROS service +class Interface { +public: + + virtual ~Interface() { + } + + /** + * Gets the UID for the serice + * @return UID of service in native format + */ + NativeUID GetUID() const { + return (NativeUID)m_uid; + } + + /** + * Gets the string name used by CTROS for a service + * @return String name of service + */ + virtual std::string GetName() { + return "[UNKNOWN SERVICE NAME]"; + } + + /** + * Gets the string name used by CTROS for a service + * @return Port name of service + */ + virtual std::string GetPort() { + return "[UNKNOWN SERVICE PORT]"; + } + + /** + * Called when svcSendSyncRequest is called, loads command buffer and executes comand + * @return Return result of svcSendSyncRequest passed back to user app + */ + virtual Syscall::Result Sync() = 0; + +private: + u32 m_uid; +}; + +} // namespace diff --git a/src/core/hle/hle_syscall.cpp b/src/core/hle/syscall.cpp similarity index 58% rename from src/core/hle/hle_syscall.cpp rename to src/core/hle/syscall.cpp index 92d9b0c85..98155dc8e 100644 --- a/src/core/hle/hle_syscall.cpp +++ b/src/core/hle/syscall.cpp @@ -2,15 +2,15 @@ // Licensed under GPLv2 // Refer to the license.txt file included. +#include + #include "core/hle/function_wrappers.h" -#include "core/hle/hle_syscall.h" +#include "core/hle/syscall.h" //////////////////////////////////////////////////////////////////////////////////////////////////// +// Namespace Syscall -typedef u32 Handle; -typedef s32 Result; - -//////////////////////////////////////////////////////////////////////////////////////////////////// +namespace Syscall { Result SVC_ConnectToPort(void* out, const char* port_name) { NOTICE_LOG(OSHLE, "svcConnectToPort called, port_name: %s", port_name); @@ -64,23 +64,23 @@ const HLE::FunctionDef Syscall_Table[] = { {0x2B, NULL, "svcGetProcessInfo"}, {0x2C, NULL, "svcGetThreadInfo"}, {0x2D, WrapI_VC, "svcConnectToPort"}, - {0x2E NULL, "svcSendSyncRequest1"}, - {0x2F NULL, "svcSendSyncRequest2"}, - {0x30 NULL, "svcSendSyncRequest3"}, - {0x31 NULL, "svcSendSyncRequest4"}, - {0x32 NULL, "svcSendSyncRequest"}, - {0x33 NULL, "svcOpenProcess"}, - {0x34 NULL, "svcOpenThread"}, - {0x35 NULL, "svcGetProcessId"}, - {0x36 NULL, "svcGetProcessIdOfThread"}, - {0x37 NULL, "svcGetThreadId"}, - {0x38 NULL, "svcGetResourceLimit"}, - {0x39 NULL, "svcGetResourceLimitLimitValues"}, - {0x3A NULL, "svcGetResourceLimitCurrentValues"}, - {0x3B NULL, "svcGetThreadContext"}, - {0x3C NULL, "svcBreak"}, - {0x3D NULL, "svcOutputDebugString"}, - {0x3E NULL, "svcControlPerformanceCounter"}, + {0x2E, NULL, "svcSendSyncRequest1"}, + {0x2F, NULL, "svcSendSyncRequest2"}, + {0x30, NULL, "svcSendSyncRequest3"}, + {0x31, NULL, "svcSendSyncRequest4"}, + {0x32, NULL, "svcSendSyncRequest"}, + {0x33, NULL, "svcOpenProcess"}, + {0x34, NULL, "svcOpenThread"}, + {0x35, NULL, "svcGetProcessId"}, + {0x36, NULL, "svcGetProcessIdOfThread"}, + {0x37, NULL, "svcGetThreadId"}, + {0x38, NULL, "svcGetResourceLimit"}, + {0x39, NULL, "svcGetResourceLimitLimitValues"}, + {0x3A, NULL, "svcGetResourceLimitCurrentValues"}, + {0x3B, NULL, "svcGetThreadContext"}, + {0x3C, NULL, "svcBreak"}, + {0x3D, NULL, "svcOutputDebugString"}, + {0x3E, NULL, "svcControlPerformanceCounter"}, {0x3F, NULL, "Unknown"}, {0x40, NULL, "Unknown"}, {0x41, NULL, "Unknown"}, @@ -89,24 +89,24 @@ const HLE::FunctionDef Syscall_Table[] = { {0x44, NULL, "Unknown"}, {0x45, NULL, "Unknown"}, {0x46, NULL, "Unknown"}, - {0x47 NULL, "svcCreatePort"}, - {0x48 NULL, "svcCreateSessionToPort"}, - {0x49 NULL, "svcCreateSession"}, - {0x4A NULL, "svcAcceptSession"}, - {0x4B NULL, "svcReplyAndReceive1"}, - {0x4C NULL, "svcReplyAndReceive2"}, - {0x4D NULL, "svcReplyAndReceive3"}, - {0x4E NULL, "svcReplyAndReceive4"}, - {0x4F NULL, "svcReplyAndReceive"}, - {0x50 NULL, "svcBindInterrupt"}, - {0x51 NULL, "svcUnbindInterrupt"}, - {0x52 NULL, "svcInvalidateProcessDataCache"}, - {0x53 NULL, "svcStoreProcessDataCache"}, - {0x54 NULL, "svcFlushProcessDataCache"}, - {0x55 NULL, "svcStartInterProcessDma"}, - {0x56 NULL, "svcStopDma"}, - {0x57 NULL, "svcGetDmaState"}, - {0x58 NULL, "svcRestartDma"}, + {0x47, NULL, "svcCreatePort"}, + {0x48, NULL, "svcCreateSessionToPort"}, + {0x49, NULL, "svcCreateSession"}, + {0x4A, NULL, "svcAcceptSession"}, + {0x4B, NULL, "svcReplyAndReceive1"}, + {0x4C, NULL, "svcReplyAndReceive2"}, + {0x4D, NULL, "svcReplyAndReceive3"}, + {0x4E, NULL, "svcReplyAndReceive4"}, + {0x4F, NULL, "svcReplyAndReceive"}, + {0x50, NULL, "svcBindInterrupt"}, + {0x51, NULL, "svcUnbindInterrupt"}, + {0x52, NULL, "svcInvalidateProcessDataCache"}, + {0x53, NULL, "svcStoreProcessDataCache"}, + {0x54, NULL, "svcFlushProcessDataCache"}, + {0x55, NULL, "svcStartInterProcessDma"}, + {0x56, NULL, "svcStopDma"}, + {0x57, NULL, "svcGetDmaState"}, + {0x58, NULL, "svcRestartDma"}, {0x59, NULL, "Unknown"}, {0x5A, NULL, "Unknown"}, {0x5B, NULL, "Unknown"}, @@ -114,38 +114,40 @@ const HLE::FunctionDef Syscall_Table[] = { {0x5D, NULL, "Unknown"}, {0x5E, NULL, "Unknown"}, {0x5F, NULL, "Unknown"}, - {0x60 NULL, "svcDebugActiveProcess"}, - {0x61 NULL, "svcBreakDebugProcess"}, - {0x62 NULL, "svcTerminateDebugProcess"}, - {0x63 NULL, "svcGetProcessDebugEvent"}, - {0x64 NULL, "svcContinueDebugEvent"}, - {0x65 NULL, "svcGetProcessList"}, - {0x66 NULL, "svcGetThreadList"}, - {0x67 NULL, "svcGetDebugThreadContext"}, - {0x68 NULL, "svcSetDebugThreadContext"}, - {0x69 NULL, "svcQueryDebugProcessMemory"}, - {0x6A NULL, "svcReadProcessMemory"}, - {0x6B NULL, "svcWriteProcessMemory"}, - {0x6C NULL, "svcSetHardwareBreakPoint"}, - {0x6D NULL, "svcGetDebugThreadParam"}, + {0x60, NULL, "svcDebugActiveProcess"}, + {0x61, NULL, "svcBreakDebugProcess"}, + {0x62, NULL, "svcTerminateDebugProcess"}, + {0x63, NULL, "svcGetProcessDebugEvent"}, + {0x64, NULL, "svcContinueDebugEvent"}, + {0x65, NULL, "svcGetProcessList"}, + {0x66, NULL, "svcGetThreadList"}, + {0x67, NULL, "svcGetDebugThreadContext"}, + {0x68, NULL, "svcSetDebugThreadContext"}, + {0x69, NULL, "svcQueryDebugProcessMemory"}, + {0x6A, NULL, "svcReadProcessMemory"}, + {0x6B, NULL, "svcWriteProcessMemory"}, + {0x6C, NULL, "svcSetHardwareBreakPoint"}, + {0x6D, NULL, "svcGetDebugThreadParam"}, {0x6E, NULL, "Unknown"}, {0x6F, NULL, "Unknown"}, - {0x70 NULL, "svcControlProcessMemory"}, - {0x71 NULL, "svcMapProcessMemory"}, - {0x72 NULL, "svcUnmapProcessMemory"}, + {0x70, NULL, "svcControlProcessMemory"}, + {0x71, NULL, "svcMapProcessMemory"}, + {0x72, NULL, "svcUnmapProcessMemory"}, {0x73, NULL, "Unknown"}, {0x74, NULL, "Unknown"}, {0x75, NULL, "Unknown"}, - {0x76 NULL, "svcTerminateProcess"}, + {0x76, NULL, "svcTerminateProcess"}, {0x77, NULL, "Unknown"}, - {0x78 NULL, "svcCreateResourceLimit"}, + {0x78, NULL, "svcCreateResourceLimit"}, {0x79, NULL, "Unknown"}, {0x7A, NULL, "Unknown"}, {0x7B, NULL, "Unknown"}, - {0x7C NULL, "svcKernelSetState"}, - {0x7D NULL, "svcQueryProcessMemory"}, + {0x7C, NULL, "svcKernelSetState"}, + {0x7D, NULL, "svcQueryProcessMemory"}, }; -void Register_Syscall() { +void Register() { HLE::RegisterModule("SyscallTable", ARRAY_SIZE(Syscall_Table), Syscall_Table); } + +} // namespace diff --git a/src/core/hle/syscall.h b/src/core/hle/syscall.h new file mode 100644 index 000000000..7a94e0136 --- /dev/null +++ b/src/core/hle/syscall.h @@ -0,0 +1,19 @@ +// Copyright 2014 Citra Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#pragma once + +#include "common/common_types.h" + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// Namespace Syscall + +namespace Syscall { + +typedef u32 Handle; +typedef s32 Result; + +void Register(); + +} // namespace From 9a9b7b289ab87e22b9896c0345d42b61c47a304f Mon Sep 17 00:00:00 2001 From: bunnei Date: Sat, 12 Apr 2014 01:33:13 -0400 Subject: [PATCH 15/49] added a memory mapped option for HLE --- src/core/mem_map.h | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/core/mem_map.h b/src/core/mem_map.h index 94469ec8c..29f2dce86 100644 --- a/src/core/mem_map.h +++ b/src/core/mem_map.h @@ -19,19 +19,22 @@ enum { MEM_AXI_WRAM_SIZE = 0x00080000, ///< AXI WRAM size MEM_FCRAM_SIZE = 0x08000000, ///< FCRAM size... Really 0x07E00000, but power of 2 // works much better - MEM_SCRATCHPAD_SIZE = 0x00004000, ///< Typical stack size - TODO: Read from exheader + MEM_SCRATCHPAD_SIZE = 0x00004000, ///< Typical stack size - TODO: Read from exheader MEM_VRAM_MASK = 0x007FFFFF, MEM_FCRAM_MASK = (MEM_FCRAM_SIZE - 1), ///< FCRAM mask MEM_SCRATCHPAD_MASK = (MEM_SCRATCHPAD_SIZE - 1), ///< Scratchpad memory mask - MEM_FCRAM_PADDR = 0x20000000, ///< FCRAM physical address - MEM_FCRAM_PADDR_END = (MEM_FCRAM_PADDR + MEM_FCRAM_SIZE), ///< FCRAM end of physical space - MEM_FCRAM_VADDR = 0x08000000, ///< FCRAM virtual address - MEM_FCRAM_VADDR_END = (MEM_FCRAM_VADDR + MEM_FCRAM_SIZE), ///< FCRAM end of virtual space + MEM_FCRAM_PADDR = 0x20000000, ///< FCRAM physical address + MEM_FCRAM_PADDR_END = (MEM_FCRAM_PADDR + MEM_FCRAM_SIZE), ///< FCRAM end of physical space + MEM_FCRAM_VADDR = 0x08000000, ///< FCRAM virtual address + MEM_FCRAM_VADDR_END = (MEM_FCRAM_VADDR + MEM_FCRAM_SIZE), ///< FCRAM end of virtual space MEM_VRAM_VADDR = 0x1F000000, MEM_SCRATCHPAD_VADDR = (0x10000000 - MEM_SCRATCHPAD_SIZE), ///< Scratchpad virtual address + + MEM_OSHLE_VADDR = 0xC0000000, ///< Memory for use by OSHLE accessible by appcore CPU + MEM_OSHLE_SIZE = 0x08000000, ///< ...Same size as FCRAM for now }; //////////////////////////////////////////////////////////////////////////////////////////////////// From cd7de52fea8359da3c37f661b0da0c145b9b3f7e Mon Sep 17 00:00:00 2001 From: bunnei Date: Sat, 12 Apr 2014 01:35:45 -0400 Subject: [PATCH 16/49] added a SETABORT method that does not update LR (for HLE'd SVC that does not jump appcore CPU to an IRQ vector) --- src/core/arm/interpreter/armemu.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/core/arm/interpreter/armemu.h b/src/core/arm/interpreter/armemu.h index 7391dea7f..7c118948a 100644 --- a/src/core/arm/interpreter/armemu.h +++ b/src/core/arm/interpreter/armemu.h @@ -229,6 +229,17 @@ extern ARMword isize; } \ while (0) +#define SETABORT_SKIPBRANCH(i, m, d) \ + do \ + { \ + int SETABORT_mode = (m); \ + \ + ARMul_SetSPSR (state, SETABORT_mode, ARMul_GetCPSR (state)); \ + ARMul_SetCPSR (state, ((ARMul_GetCPSR (state) & ~(EMODE | TBIT)) \ + | (i) | SETABORT_mode)); \ + } \ + while (0) + //#ifndef MODE32 #define VECTORS 0x20 #define LEGALADDR 0x03ffffff From 4d8831890321c11e2e29ed9bc87c8a48841b702e Mon Sep 17 00:00:00 2001 From: bunnei Date: Sat, 12 Apr 2014 01:36:39 -0400 Subject: [PATCH 17/49] hacked CPU interpreter to ignore branch on SVC instruction (as we are HLEing this...) --- src/core/arm/interpreter/arminit.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/core/arm/interpreter/arminit.cpp b/src/core/arm/interpreter/arminit.cpp index cdbd02f3c..a8aeecdea 100644 --- a/src/core/arm/interpreter/arminit.cpp +++ b/src/core/arm/interpreter/arminit.cpp @@ -530,9 +530,13 @@ ARMul_Abort (ARMul_State * state, ARMword vector) isize); break; case ARMul_SWIV: /* Software Interrupt */ - SETABORT (IBIT, state->prog32Sig ? SVC32MODE : SVC26MODE, + // Modified SETABORT that doesn't branch to a SVC vector as we are implementing this in HLE + // Instead of doing normal routine, backup R15 by one instruction (this is what PC will get + // set to, making it the next instruction after the SVC call), and skip setting the LR. + SETABORT_SKIPBRANCH (IBIT, state->prog32Sig ? SVC32MODE : SVC26MODE, isize); - break; + state->Reg[15] -= 4; + return; case ARMul_PrefetchAbortV: /* Prefetch Abort */ state->AbortAddr = 1; SETABORT (IBIT, state->prog32Sig ? ABORT32MODE : SVC26MODE, From 68e198476f17a026fed88f3c9a271aa768694354 Mon Sep 17 00:00:00 2001 From: bunnei Date: Sat, 12 Apr 2014 21:55:36 -0400 Subject: [PATCH 18/49] - added HLE to connect to "srv:" service - added a manager for keeping track of services/ports - added a memory mapped region for memory accessed by HLE - added HLE for GetThreadCommandBuffer function --- src/core/arm/interpreter/armsupp.cpp | 64 +++---- src/core/core.vcxproj | 1 + src/core/core.vcxproj.filters | 3 + src/core/hle/hle.cpp | 13 ++ src/core/hle/hle.h | 7 + src/core/hle/service/service.cpp | 115 ++++++++++++ src/core/hle/service/service.h | 57 +++++- src/core/hle/syscall.cpp | 266 ++++++++++++++------------- src/core/mem_map.cpp | 3 +- src/core/mem_map.h | 3 +- src/core/mem_map_funcs.cpp | 18 +- 11 files changed, 384 insertions(+), 166 deletions(-) create mode 100644 src/core/hle/service/service.cpp diff --git a/src/core/arm/interpreter/armsupp.cpp b/src/core/arm/interpreter/armsupp.cpp index a0c866c15..101b9807a 100644 --- a/src/core/arm/interpreter/armsupp.cpp +++ b/src/core/arm/interpreter/armsupp.cpp @@ -19,6 +19,8 @@ #include "armemu.h" //#include "ansidecl.h" #include "skyeye_defs.h" +#include "core/hle/hle.h" + unsigned xscale_cp15_cp_access_allowed (ARMul_State * state, unsigned reg, unsigned cpnum); //extern int skyeye_instr_debug; @@ -734,39 +736,39 @@ ARMword ARMul_MRC (ARMul_State * state, ARMword instr) { unsigned cpab; - ARMword result = 0; + ARMword result = HLE::CallGetThreadCommandBuffer(); - //printf("SKYEYE ARMul_MRC, CPnum is %x, instr %x\n",CPNum, instr); - if (!CP_ACCESS_ALLOWED (state, CPNum)) { - //chy 2004-07-19 should fix in the future????!!!! - //printf("SKYEYE ARMul_MRC,NOT ALLOWed UndefInstr CPnum is %x, instr %x\n",CPNum, instr); - ARMul_UndefInstr (state, instr); - return -1; - } + ////printf("SKYEYE ARMul_MRC, CPnum is %x, instr %x\n",CPNum, instr); + //if (!CP_ACCESS_ALLOWED (state, CPNum)) { + // //chy 2004-07-19 should fix in the future????!!!! + // //printf("SKYEYE ARMul_MRC,NOT ALLOWed UndefInstr CPnum is %x, instr %x\n",CPNum, instr); + // ARMul_UndefInstr (state, instr); + // return -1; + //} - cpab = (state->MRC[CPNum]) (state, ARMul_FIRST, instr, &result); - while (cpab == ARMul_BUSY) { - ARMul_Icycles (state, 1, 0); - if (IntPending (state)) { - cpab = (state->MRC[CPNum]) (state, ARMul_INTERRUPT, - instr, 0); - return (0); - } - else - cpab = (state->MRC[CPNum]) (state, ARMul_BUSY, instr, - &result); - } - if (cpab == ARMul_CANT) { - printf ("SKYEYE ARMul_MRC,CANT UndefInstr CPnum is %x, instr %x\n", CPNum, instr); - ARMul_Abort (state, ARMul_UndefinedInstrV); - /* Parent will destroy the flags otherwise. */ - result = ECC; - } - else { - BUSUSEDINCPCN; - ARMul_Ccycles (state, 1, 0); - ARMul_Icycles (state, 1, 0); - } + //cpab = (state->MRC[CPNum]) (state, ARMul_FIRST, instr, &result); + //while (cpab == ARMul_BUSY) { + // ARMul_Icycles (state, 1, 0); + // if (IntPending (state)) { + // cpab = (state->MRC[CPNum]) (state, ARMul_INTERRUPT, + // instr, 0); + // return (0); + // } + // else + // cpab = (state->MRC[CPNum]) (state, ARMul_BUSY, instr, + // &result); + //} + //if (cpab == ARMul_CANT) { + // printf ("SKYEYE ARMul_MRC,CANT UndefInstr CPnum is %x, instr %x\n", CPNum, instr); + // ARMul_Abort (state, ARMul_UndefinedInstrV); + // /* Parent will destroy the flags otherwise. */ + // result = ECC; + //} + //else { + // BUSUSEDINCPCN; + // ARMul_Ccycles (state, 1, 0); + // ARMul_Icycles (state, 1, 0); + //} return result; } diff --git a/src/core/core.vcxproj b/src/core/core.vcxproj index 10ecca596..b10ae8684 100644 --- a/src/core/core.vcxproj +++ b/src/core/core.vcxproj @@ -153,6 +153,7 @@ + diff --git a/src/core/core.vcxproj.filters b/src/core/core.vcxproj.filters index d450224a4..4844e78b8 100644 --- a/src/core/core.vcxproj.filters +++ b/src/core/core.vcxproj.filters @@ -87,6 +87,9 @@ hle + + hle\service + diff --git a/src/core/hle/hle.cpp b/src/core/hle/hle.cpp index 32aff0eb5..3d2c53954 100644 --- a/src/core/hle/hle.cpp +++ b/src/core/hle/hle.cpp @@ -4,8 +4,10 @@ #include +#include "core/mem_map.h" #include "core/hle/hle.h" #include "core/hle/syscall.h" +#include "core/hle/service/service.h" //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -35,6 +37,14 @@ void CallSyscall(u32 opcode) { } } +/// Returns the coprocessor (in this case, syscore) command buffer pointer +Addr CallGetThreadCommandBuffer() { + // Called on insruction: mrc p15, 0, r0, c13, c0, 3 + // Returns an address in OSHLE memory for the CPU to read/write to + RETURN(OS_THREAD_COMMAND_BUFFER_ADDR); + return OS_THREAD_COMMAND_BUFFER_ADDR; +} + void RegisterModule(std::string name, int num_functions, const FunctionDef* func_table) { ModuleDef module = {name, num_functions, func_table}; g_module_db.push_back(module); @@ -45,7 +55,10 @@ void RegisterAllModules() { } void Init() { + Service::Init(); + RegisterAllModules(); + NOTICE_LOG(HLE, "initialized OK"); } diff --git a/src/core/hle/hle.h b/src/core/hle/hle.h index 9466be540..2bd1f99a2 100644 --- a/src/core/hle/hle.h +++ b/src/core/hle/hle.h @@ -16,6 +16,11 @@ namespace HLE { +enum { + OS_THREAD_COMMAND_BUFFER_ADDR = 0xA0004000, +}; + +typedef u32 Addr; typedef void (*Func)(); struct FunctionDef { @@ -34,6 +39,8 @@ void RegisterModule(std::string name, int num_functions, const FunctionDef *func void CallSyscall(u32 opcode); +Addr CallGetThreadCommandBuffer(); + void Init(); void Shutdown(); diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp new file mode 100644 index 000000000..4bc96cc18 --- /dev/null +++ b/src/core/hle/service/service.cpp @@ -0,0 +1,115 @@ +// Copyright 2014 Citra Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#include "common/common.h" +#include "common/log.h" + +#include "core/hle/service/service.h" + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// Namespace Service + +namespace Service { + +Manager* g_manager = NULL; ///< Service manager + +Manager::Manager() { +} + +Manager::~Manager() { + for(Interface* service : m_services) { + DeleteService(service->GetPortName()); + } +} + +/// Add a service to the manager (does not create it though) +void Manager::AddService(Interface* service) { + int index = m_services.size(); + u32 new_uid = GetUIDFromIndex(index); + + m_services.push_back(service); + + m_port_map[service->GetPortName()] = new_uid; + service->m_uid = new_uid; +} + +/// Removes a service from the manager, also frees memory +void Manager::DeleteService(std::string port_name) { + auto service = FetchFromPortName(port_name); + + m_services.erase(m_services.begin() + GetIndexFromUID(service->m_uid)); + m_port_map.erase(port_name); + + delete service; +} + +/// Get a Service Interface from its UID +Interface* Manager::FetchFromUID(u32 uid) { + int index = GetIndexFromUID(uid); + if (index < (int)m_services.size()) { + return m_services[index]; + } + return NULL; +} + +/// Get a Service Interface from its port +Interface* Manager::FetchFromPortName(std::string port_name) { + auto itr = m_port_map.find(port_name); + if (itr == m_port_map.end()) { + return NULL; + } + return FetchFromUID(itr->second); +} + +class Interface_SRV : public Interface { +public: + + Interface_SRV() { + } + + ~Interface_SRV() { + } + + /** + * Gets the string name used by CTROS for a service + * @return String name of service + */ + std::string GetName() { + return "ServiceManager"; + } + + /** + * Gets the string name used by CTROS for a service + * @return Port name of service + */ + std::string GetPortName() { + return "srv:"; + } + + /** + * Called when svcSendSyncRequest is called, loads command buffer and executes comand + * @return Return result of svcSendSyncRequest passed back to user app + */ + Syscall::Result Sync() { + ERROR_LOG(HLE, "Unimplemented function ServiceManager::Sync"); + return -1; + } + +}; + +/// Initialize ServiceManager +void Init() { + g_manager = new Manager; + g_manager->AddService(new Interface_SRV); + NOTICE_LOG(HLE, "ServiceManager initialized OK"); +} + +/// Shutdown ServiceManager +void Shutdown() { + delete g_manager; + NOTICE_LOG(HLE, "ServiceManager shutdown OK"); +} + + +} diff --git a/src/core/hle/service/service.h b/src/core/hle/service/service.h index f15099982..3fd855dee 100644 --- a/src/core/hle/service/service.h +++ b/src/core/hle/service/service.h @@ -4,6 +4,8 @@ #pragma once +#include +#include #include #include "common/common_types.h" @@ -14,10 +16,13 @@ namespace Service { -typedef s32 NativeUID; +typedef s32 NativeUID; ///< Native handle for a service + +class Manager; /// Interface to a CTROS service class Interface { + friend class Manager; public: virtual ~Interface() { @@ -43,7 +48,7 @@ public: * Gets the string name used by CTROS for a service * @return Port name of service */ - virtual std::string GetPort() { + virtual std::string GetPortName() { return "[UNKNOWN SERVICE PORT]"; } @@ -57,4 +62,52 @@ private: u32 m_uid; }; +/// Simple class to manage accessing services from ports and UID handles +class Manager { + +public: + Manager(); + + ~Manager(); + + /// Add a service to the manager (does not create it though) + void AddService(Interface* service); + + /// Removes a service from the manager (does not delete it though) + void DeleteService(std::string port_name); + + /// Get a Service Interface from its UID + Interface* FetchFromUID(u32 uid); + + /// Get a Service Interface from its port + Interface* FetchFromPortName(std::string port_name); + +private: + + /// Convert an index into m_services vector into a UID + static u32 GetUIDFromIndex(const int index) { + return index | 0x10000000; + } + + /// Convert a UID into an index into m_services + static int GetIndexFromUID(const u32 uid) { + return uid & 0x0FFFFFFF; + } + + std::vector m_services; + std::map m_port_map; + + DISALLOW_COPY_AND_ASSIGN(Manager); +}; + +/// Initialize ServiceManager +void Init(); + +/// Shutdown ServiceManager +void Shutdown(); + + +extern Manager* g_manager; ///< Service manager + + } // namespace diff --git a/src/core/hle/syscall.cpp b/src/core/hle/syscall.cpp index 98155dc8e..8225f168b 100644 --- a/src/core/hle/syscall.cpp +++ b/src/core/hle/syscall.cpp @@ -6,144 +6,154 @@ #include "core/hle/function_wrappers.h" #include "core/hle/syscall.h" +#include "core/hle/service/service.h" //////////////////////////////////////////////////////////////////////////////////////////////////// // Namespace Syscall namespace Syscall { -Result SVC_ConnectToPort(void* out, const char* port_name) { - NOTICE_LOG(OSHLE, "svcConnectToPort called, port_name: %s", port_name); +/// Connect to an OS service given the port name, returns the handle to the port to out +Result ConnectToPort(void* out, const char* port_name) { + Service::Interface* service = Service::g_manager->FetchFromPortName(port_name); + Core::g_app_core->SetReg(1, service->GetUID()); + return 0; +} + +/// Synchronize to an OS service +Result SendSyncRequest(Handle session) { + Service::Interface* service = Service::g_manager->FetchFromUID(session); + service->Sync(); return 0; } const HLE::FunctionDef Syscall_Table[] = { - {0x00, NULL, "Unknown"}, - {0x01, NULL, "svcControlMemory"}, - {0x02, NULL, "svcQueryMemory"}, - {0x03, NULL, "svcExitProcess"}, - {0x04, NULL, "svcGetProcessAffinityMask"}, - {0x05, NULL, "svcSetProcessAffinityMask"}, - {0x06, NULL, "svcGetProcessIdealProcessor"}, - {0x07, NULL, "svcSetProcessIdealProcessor"}, - {0x08, NULL, "svcCreateThread"}, - {0x09, NULL, "svcExitThread"}, - {0x0A, NULL, "svcSleepThread"}, - {0x0B, NULL, "svcGetThreadPriority"}, - {0x0C, NULL, "svcSetThreadPriority"}, - {0x0D, NULL, "svcGetThreadAffinityMask"}, - {0x0E, NULL, "svcSetThreadAffinityMask"}, - {0x0F, NULL, "svcGetThreadIdealProcessor"}, - {0x10, NULL, "svcSetThreadIdealProcessor"}, - {0x11, NULL, "svcGetCurrentProcessorNumber"}, - {0x12, NULL, "svcRun"}, - {0x13, NULL, "svcCreateMutex"}, - {0x14, NULL, "svcReleaseMutex"}, - {0x15, NULL, "svcCreateSemaphore"}, - {0x16, NULL, "svcReleaseSemaphore"}, - {0x17, NULL, "svcCreateEvent"}, - {0x18, NULL, "svcSignalEvent"}, - {0x19, NULL, "svcClearEvent"}, - {0x1A, NULL, "svcCreateTimer"}, - {0x1B, NULL, "svcSetTimer"}, - {0x1C, NULL, "svcCancelTimer"}, - {0x1D, NULL, "svcClearTimer"}, - {0x1E, NULL, "svcCreateMemoryBlock"}, - {0x1F, NULL, "svcMapMemoryBlock"}, - {0x20, NULL, "svcUnmapMemoryBlock"}, - {0x21, NULL, "svcCreateAddressArbiter"}, - {0x22, NULL, "svcArbitrateAddress"}, - {0x23, NULL, "svcCloseHandle"}, - {0x24, NULL, "svcWaitSynchronization1"}, - {0x25, NULL, "svcWaitSynchronizationN"}, - {0x26, NULL, "svcSignalAndWait"}, - {0x27, NULL, "svcDuplicateHandle"}, - {0x28, NULL, "svcGetSystemTick"}, - {0x29, NULL, "svcGetHandleInfo"}, - {0x2A, NULL, "svcGetSystemInfo"}, - {0x2B, NULL, "svcGetProcessInfo"}, - {0x2C, NULL, "svcGetThreadInfo"}, - {0x2D, WrapI_VC, "svcConnectToPort"}, - {0x2E, NULL, "svcSendSyncRequest1"}, - {0x2F, NULL, "svcSendSyncRequest2"}, - {0x30, NULL, "svcSendSyncRequest3"}, - {0x31, NULL, "svcSendSyncRequest4"}, - {0x32, NULL, "svcSendSyncRequest"}, - {0x33, NULL, "svcOpenProcess"}, - {0x34, NULL, "svcOpenThread"}, - {0x35, NULL, "svcGetProcessId"}, - {0x36, NULL, "svcGetProcessIdOfThread"}, - {0x37, NULL, "svcGetThreadId"}, - {0x38, NULL, "svcGetResourceLimit"}, - {0x39, NULL, "svcGetResourceLimitLimitValues"}, - {0x3A, NULL, "svcGetResourceLimitCurrentValues"}, - {0x3B, NULL, "svcGetThreadContext"}, - {0x3C, NULL, "svcBreak"}, - {0x3D, NULL, "svcOutputDebugString"}, - {0x3E, NULL, "svcControlPerformanceCounter"}, - {0x3F, NULL, "Unknown"}, - {0x40, NULL, "Unknown"}, - {0x41, NULL, "Unknown"}, - {0x42, NULL, "Unknown"}, - {0x43, NULL, "Unknown"}, - {0x44, NULL, "Unknown"}, - {0x45, NULL, "Unknown"}, - {0x46, NULL, "Unknown"}, - {0x47, NULL, "svcCreatePort"}, - {0x48, NULL, "svcCreateSessionToPort"}, - {0x49, NULL, "svcCreateSession"}, - {0x4A, NULL, "svcAcceptSession"}, - {0x4B, NULL, "svcReplyAndReceive1"}, - {0x4C, NULL, "svcReplyAndReceive2"}, - {0x4D, NULL, "svcReplyAndReceive3"}, - {0x4E, NULL, "svcReplyAndReceive4"}, - {0x4F, NULL, "svcReplyAndReceive"}, - {0x50, NULL, "svcBindInterrupt"}, - {0x51, NULL, "svcUnbindInterrupt"}, - {0x52, NULL, "svcInvalidateProcessDataCache"}, - {0x53, NULL, "svcStoreProcessDataCache"}, - {0x54, NULL, "svcFlushProcessDataCache"}, - {0x55, NULL, "svcStartInterProcessDma"}, - {0x56, NULL, "svcStopDma"}, - {0x57, NULL, "svcGetDmaState"}, - {0x58, NULL, "svcRestartDma"}, - {0x59, NULL, "Unknown"}, - {0x5A, NULL, "Unknown"}, - {0x5B, NULL, "Unknown"}, - {0x5C, NULL, "Unknown"}, - {0x5D, NULL, "Unknown"}, - {0x5E, NULL, "Unknown"}, - {0x5F, NULL, "Unknown"}, - {0x60, NULL, "svcDebugActiveProcess"}, - {0x61, NULL, "svcBreakDebugProcess"}, - {0x62, NULL, "svcTerminateDebugProcess"}, - {0x63, NULL, "svcGetProcessDebugEvent"}, - {0x64, NULL, "svcContinueDebugEvent"}, - {0x65, NULL, "svcGetProcessList"}, - {0x66, NULL, "svcGetThreadList"}, - {0x67, NULL, "svcGetDebugThreadContext"}, - {0x68, NULL, "svcSetDebugThreadContext"}, - {0x69, NULL, "svcQueryDebugProcessMemory"}, - {0x6A, NULL, "svcReadProcessMemory"}, - {0x6B, NULL, "svcWriteProcessMemory"}, - {0x6C, NULL, "svcSetHardwareBreakPoint"}, - {0x6D, NULL, "svcGetDebugThreadParam"}, - {0x6E, NULL, "Unknown"}, - {0x6F, NULL, "Unknown"}, - {0x70, NULL, "svcControlProcessMemory"}, - {0x71, NULL, "svcMapProcessMemory"}, - {0x72, NULL, "svcUnmapProcessMemory"}, - {0x73, NULL, "Unknown"}, - {0x74, NULL, "Unknown"}, - {0x75, NULL, "Unknown"}, - {0x76, NULL, "svcTerminateProcess"}, - {0x77, NULL, "Unknown"}, - {0x78, NULL, "svcCreateResourceLimit"}, - {0x79, NULL, "Unknown"}, - {0x7A, NULL, "Unknown"}, - {0x7B, NULL, "Unknown"}, - {0x7C, NULL, "svcKernelSetState"}, - {0x7D, NULL, "svcQueryProcessMemory"}, + {0x00, NULL, "Unknown"}, + {0x01, NULL, "ControlMemory"}, + {0x02, NULL, "QueryMemory"}, + {0x03, NULL, "ExitProcess"}, + {0x04, NULL, "GetProcessAffinityMask"}, + {0x05, NULL, "SetProcessAffinityMask"}, + {0x06, NULL, "GetProcessIdealProcessor"}, + {0x07, NULL, "SetProcessIdealProcessor"}, + {0x08, NULL, "CreateThread"}, + {0x09, NULL, "ExitThread"}, + {0x0A, NULL, "SleepThread"}, + {0x0B, NULL, "GetThreadPriority"}, + {0x0C, NULL, "SetThreadPriority"}, + {0x0D, NULL, "GetThreadAffinityMask"}, + {0x0E, NULL, "SetThreadAffinityMask"}, + {0x0F, NULL, "GetThreadIdealProcessor"}, + {0x10, NULL, "SetThreadIdealProcessor"}, + {0x11, NULL, "GetCurrentProcessorNumber"}, + {0x12, NULL, "Run"}, + {0x13, NULL, "CreateMutex"}, + {0x14, NULL, "ReleaseMutex"}, + {0x15, NULL, "CreateSemaphore"}, + {0x16, NULL, "ReleaseSemaphore"}, + {0x17, NULL, "CreateEvent"}, + {0x18, NULL, "SignalEvent"}, + {0x19, NULL, "ClearEvent"}, + {0x1A, NULL, "CreateTimer"}, + {0x1B, NULL, "SetTimer"}, + {0x1C, NULL, "CancelTimer"}, + {0x1D, NULL, "ClearTimer"}, + {0x1E, NULL, "CreateMemoryBlock"}, + {0x1F, NULL, "MapMemoryBlock"}, + {0x20, NULL, "UnmapMemoryBlock"}, + {0x21, NULL, "CreateAddressArbiter"}, + {0x22, NULL, "ArbitrateAddress"}, + {0x23, NULL, "CloseHandle"}, + {0x24, NULL, "WaitSynchronization1"}, + {0x25, NULL, "WaitSynchronizationN"}, + {0x26, NULL, "SignalAndWait"}, + {0x27, NULL, "DuplicateHandle"}, + {0x28, NULL, "GetSystemTick"}, + {0x29, NULL, "GetHandleInfo"}, + {0x2A, NULL, "GetSystemInfo"}, + {0x2B, NULL, "GetProcessInfo"}, + {0x2C, NULL, "GetThreadInfo"}, + {0x2D, WrapI_VC, "ConnectToPort"}, + {0x2E, NULL, "SendSyncRequest1"}, + {0x2F, NULL, "SendSyncRequest2"}, + {0x30, NULL, "SendSyncRequest3"}, + {0x31, NULL, "SendSyncRequest4"}, + {0x32, WrapI_U, "SendSyncRequest"}, + {0x33, NULL, "OpenProcess"}, + {0x34, NULL, "OpenThread"}, + {0x35, NULL, "GetProcessId"}, + {0x36, NULL, "GetProcessIdOfThread"}, + {0x37, NULL, "GetThreadId"}, + {0x38, NULL, "GetResourceLimit"}, + {0x39, NULL, "GetResourceLimitLimitValues"}, + {0x3A, NULL, "GetResourceLimitCurrentValues"}, + {0x3B, NULL, "GetThreadContext"}, + {0x3C, NULL, "Break"}, + {0x3D, NULL, "OutputDebugString"}, + {0x3E, NULL, "ControlPerformanceCounter"}, + {0x3F, NULL, "Unknown"}, + {0x40, NULL, "Unknown"}, + {0x41, NULL, "Unknown"}, + {0x42, NULL, "Unknown"}, + {0x43, NULL, "Unknown"}, + {0x44, NULL, "Unknown"}, + {0x45, NULL, "Unknown"}, + {0x46, NULL, "Unknown"}, + {0x47, NULL, "CreatePort"}, + {0x48, NULL, "CreateSessionToPort"}, + {0x49, NULL, "CreateSession"}, + {0x4A, NULL, "AcceptSession"}, + {0x4B, NULL, "ReplyAndReceive1"}, + {0x4C, NULL, "ReplyAndReceive2"}, + {0x4D, NULL, "ReplyAndReceive3"}, + {0x4E, NULL, "ReplyAndReceive4"}, + {0x4F, NULL, "ReplyAndReceive"}, + {0x50, NULL, "BindInterrupt"}, + {0x51, NULL, "UnbindInterrupt"}, + {0x52, NULL, "InvalidateProcessDataCache"}, + {0x53, NULL, "StoreProcessDataCache"}, + {0x54, NULL, "FlushProcessDataCache"}, + {0x55, NULL, "StartInterProcessDma"}, + {0x56, NULL, "StopDma"}, + {0x57, NULL, "GetDmaState"}, + {0x58, NULL, "RestartDma"}, + {0x59, NULL, "Unknown"}, + {0x5A, NULL, "Unknown"}, + {0x5B, NULL, "Unknown"}, + {0x5C, NULL, "Unknown"}, + {0x5D, NULL, "Unknown"}, + {0x5E, NULL, "Unknown"}, + {0x5F, NULL, "Unknown"}, + {0x60, NULL, "DebugActiveProcess"}, + {0x61, NULL, "BreakDebugProcess"}, + {0x62, NULL, "TerminateDebugProcess"}, + {0x63, NULL, "GetProcessDebugEvent"}, + {0x64, NULL, "ContinueDebugEvent"}, + {0x65, NULL, "GetProcessList"}, + {0x66, NULL, "GetThreadList"}, + {0x67, NULL, "GetDebugThreadContext"}, + {0x68, NULL, "SetDebugThreadContext"}, + {0x69, NULL, "QueryDebugProcessMemory"}, + {0x6A, NULL, "ReadProcessMemory"}, + {0x6B, NULL, "WriteProcessMemory"}, + {0x6C, NULL, "SetHardwareBreakPoint"}, + {0x6D, NULL, "GetDebugThreadParam"}, + {0x6E, NULL, "Unknown"}, + {0x6F, NULL, "Unknown"}, + {0x70, NULL, "ControlProcessMemory"}, + {0x71, NULL, "MapProcessMemory"}, + {0x72, NULL, "UnmapProcessMemory"}, + {0x73, NULL, "Unknown"}, + {0x74, NULL, "Unknown"}, + {0x75, NULL, "Unknown"}, + {0x76, NULL, "TerminateProcess"}, + {0x77, NULL, "Unknown"}, + {0x78, NULL, "CreateResourceLimit"}, + {0x79, NULL, "Unknown"}, + {0x7A, NULL, "Unknown"}, + {0x7B, NULL, "Unknown"}, + {0x7C, NULL, "KernelSetState"}, + {0x7D, NULL, "QueryProcessMemory"}, }; void Register() { diff --git a/src/core/mem_map.cpp b/src/core/mem_map.cpp index a5865d785..5b5c57fca 100644 --- a/src/core/mem_map.cpp +++ b/src/core/mem_map.cpp @@ -1,4 +1,4 @@ -// Copyright 2014 Citra Emulator Project + // Copyright 2014 Citra Emulator Project // Licensed under GPLv2 // Refer to the license.txt file included. @@ -12,7 +12,6 @@ namespace Memory { - u8* g_base = NULL; ///< The base pointer to the auto-mirrored arena. MemArena g_arena; ///< The MemArena class diff --git a/src/core/mem_map.h b/src/core/mem_map.h index 29f2dce86..2596ba925 100644 --- a/src/core/mem_map.h +++ b/src/core/mem_map.h @@ -33,8 +33,9 @@ enum { MEM_VRAM_VADDR = 0x1F000000, MEM_SCRATCHPAD_VADDR = (0x10000000 - MEM_SCRATCHPAD_SIZE), ///< Scratchpad virtual address - MEM_OSHLE_VADDR = 0xC0000000, ///< Memory for use by OSHLE accessible by appcore CPU MEM_OSHLE_SIZE = 0x08000000, ///< ...Same size as FCRAM for now + MEM_OSHLE_VADDR = 0xA0000000, ///< Memory for use by OSHLE accessible by appcore CPU + MEM_OSHLE_VADDR_END = (MEM_OSHLE_VADDR + MEM_OSHLE_SIZE), }; //////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/core/mem_map_funcs.cpp b/src/core/mem_map_funcs.cpp index 00719445f..f35e25caf 100644 --- a/src/core/mem_map_funcs.cpp +++ b/src/core/mem_map_funcs.cpp @@ -6,6 +6,7 @@ #include "core/mem_map.h" #include "core/hw/hw.h" +#include "hle/hle.h" namespace Memory { @@ -15,9 +16,16 @@ inline void _Read(T &var, const u32 addr) { // TODO: Make sure this represents the mirrors in a correct way. // Could just do a base-relative read, too.... TODO + + // Memory allocated for HLE use that can be addressed from the emulated application + // The primary use of this is sharing a commandbuffer between the HLE OS (syscore) and the LLE + // core running the user application (appcore) + if (addr >= MEM_OSHLE_VADDR && addr < MEM_OSHLE_VADDR_END) { + NOTICE_LOG(MEMMAP, "OSHLE read @ 0x%08X", addr); + // Hardware I/O register reads // 0x10XXXXXX- is physical address space, 0x1EXXXXXX is virtual address space - if ((addr & 0xFF000000) == 0x10000000 || (addr & 0xFF000000) == 0x1E000000) { + } else if ((addr & 0xFF000000) == 0x10000000 || (addr & 0xFF000000) == 0x1E000000) { HW::Read(var, addr); // FCRAM virtual address reads @@ -47,9 +55,15 @@ inline void _Read(T &var, const u32 addr) { template inline void _Write(u32 addr, const T data) { + // Memory allocated for HLE use that can be addressed from the emulated application + // The primary use of this is sharing a commandbuffer between the HLE OS (syscore) and the LLE + // core running the user application (appcore) + if (addr >= MEM_OSHLE_VADDR && addr < MEM_OSHLE_VADDR_END) { + NOTICE_LOG(MEMMAP, "OSHLE write @ 0x%08X", addr); + // Hardware I/O register writes // 0x10XXXXXX- is physical address space, 0x1EXXXXXX is virtual address space - if ((addr & 0xFF000000) == 0x10000000 || (addr & 0xFF000000) == 0x1E000000) { + } else if ((addr & 0xFF000000) == 0x10000000 || (addr & 0xFF000000) == 0x1E000000) { HW::Write(addr, data); // ExeFS:/.code is loaded here: From b24e6f2b609e1a75f05124a6246801dd0e56183a Mon Sep 17 00:00:00 2001 From: bunnei Date: Sat, 12 Apr 2014 22:08:48 -0400 Subject: [PATCH 19/49] cleanups to service HLE --- src/core/hle/service/service.cpp | 12 ++++++------ src/core/hle/service/service.h | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp index 4bc96cc18..3434b6dbf 100644 --- a/src/core/hle/service/service.cpp +++ b/src/core/hle/service/service.cpp @@ -75,7 +75,7 @@ public: * Gets the string name used by CTROS for a service * @return String name of service */ - std::string GetName() { + std::string GetName() const { return "ServiceManager"; } @@ -83,7 +83,7 @@ public: * Gets the string name used by CTROS for a service * @return Port name of service */ - std::string GetPortName() { + std::string GetPortName() const { return "srv:"; } @@ -92,8 +92,8 @@ public: * @return Return result of svcSendSyncRequest passed back to user app */ Syscall::Result Sync() { - ERROR_LOG(HLE, "Unimplemented function ServiceManager::Sync"); - return -1; + ERROR_LOG(HLE, "Unimplemented function Interface_SRV::Sync"); + return 0; } }; @@ -102,13 +102,13 @@ public: void Init() { g_manager = new Manager; g_manager->AddService(new Interface_SRV); - NOTICE_LOG(HLE, "ServiceManager initialized OK"); + NOTICE_LOG(HLE, "Services initialized OK"); } /// Shutdown ServiceManager void Shutdown() { delete g_manager; - NOTICE_LOG(HLE, "ServiceManager shutdown OK"); + NOTICE_LOG(HLE, "Services shutdown OK"); } diff --git a/src/core/hle/service/service.h b/src/core/hle/service/service.h index 3fd855dee..3cad6c642 100644 --- a/src/core/hle/service/service.h +++ b/src/core/hle/service/service.h @@ -40,7 +40,7 @@ public: * Gets the string name used by CTROS for a service * @return String name of service */ - virtual std::string GetName() { + virtual std::string GetName() const { return "[UNKNOWN SERVICE NAME]"; } @@ -48,7 +48,7 @@ public: * Gets the string name used by CTROS for a service * @return Port name of service */ - virtual std::string GetPortName() { + virtual std::string GetPortName() const { return "[UNKNOWN SERVICE PORT]"; } From 6f6d5158de18a7ca134406d55446c27f6db48a1a Mon Sep 17 00:00:00 2001 From: bunnei Date: Sat, 12 Apr 2014 23:31:39 -0400 Subject: [PATCH 20/49] added OS memory read/write for thread command buffer --- src/core/hle/hle.cpp | 45 ++++++++++++++++++++++++++++++++++++-- src/core/hle/hle.h | 13 ++++++++++- src/core/mem_map.h | 4 ---- src/core/mem_map_funcs.cpp | 10 ++++----- 4 files changed, 60 insertions(+), 12 deletions(-) diff --git a/src/core/hle/hle.cpp b/src/core/hle/hle.cpp index 3d2c53954..51432dc87 100644 --- a/src/core/hle/hle.cpp +++ b/src/core/hle/hle.cpp @@ -15,6 +15,40 @@ namespace HLE { static std::vector g_module_db; +u8* g_command_buffer = NULL; ///< Command buffer used for sharing between appcore and syscore + +// Read from memory used by CTROS HLE functions +template +inline void Read(T &var, const u32 addr) { + if (addr >= HLE::CMD_BUFFER_ADDR && addr < HLE::CMD_BUFFER_ADDR_END) { + var = *((const T*)&g_command_buffer[addr & CMD_BUFFER_MASK]); + } else { + ERROR_LOG(HLE, "unknown read from address %08X", addr); + } +} + +// Write to memory used by CTROS HLE functions +template +inline void Write(u32 addr, const T data) { + if (addr >= HLE::CMD_BUFFER_ADDR && addr < HLE::CMD_BUFFER_ADDR_END) { + *(T*)&g_command_buffer[addr & CMD_BUFFER_MASK] = data; + } else { + ERROR_LOG(HLE, "unknown write to address %08X", addr); + } +} + +// Explicitly instantiate template functions because we aren't defining this in the header: + +template void Read(u64 &var, const u32 addr); +template void Read(u32 &var, const u32 addr); +template void Read(u16 &var, const u32 addr); +template void Read(u8 &var, const u32 addr); + +template void Write(u32 addr, const u64 data); +template void Write(u32 addr, const u32 data); +template void Write(u32 addr, const u16 data); +template void Write(u32 addr, const u8 data); + const FunctionDef* GetSyscallInfo(u32 opcode) { u32 func_num = opcode & 0xFFFFFF; // 8 bits if (func_num > 0xFF) { @@ -41,8 +75,8 @@ void CallSyscall(u32 opcode) { Addr CallGetThreadCommandBuffer() { // Called on insruction: mrc p15, 0, r0, c13, c0, 3 // Returns an address in OSHLE memory for the CPU to read/write to - RETURN(OS_THREAD_COMMAND_BUFFER_ADDR); - return OS_THREAD_COMMAND_BUFFER_ADDR; + RETURN(CMD_BUFFER_ADDR); + return CMD_BUFFER_ADDR; } void RegisterModule(std::string name, int num_functions, const FunctionDef* func_table) { @@ -56,6 +90,8 @@ void RegisterAllModules() { void Init() { Service::Init(); + + g_command_buffer = new u8[CMD_BUFFER_SIZE]; RegisterAllModules(); @@ -63,7 +99,12 @@ void Init() { } void Shutdown() { + Service::Shutdown(); + + delete g_command_buffer; + g_module_db.clear(); + NOTICE_LOG(HLE, "shutdown OK"); } diff --git a/src/core/hle/hle.h b/src/core/hle/hle.h index 2bd1f99a2..5ee90bcdc 100644 --- a/src/core/hle/hle.h +++ b/src/core/hle/hle.h @@ -17,7 +17,10 @@ namespace HLE { enum { - OS_THREAD_COMMAND_BUFFER_ADDR = 0xA0004000, + CMD_BUFFER_ADDR = 0xA0010000, ///< Totally arbitrary unused address space + CMD_BUFFER_SIZE = 0x10000, + CMD_BUFFER_MASK = (CMD_BUFFER_SIZE - 1), + CMD_BUFFER_ADDR_END = (CMD_BUFFER_ADDR + CMD_BUFFER_SIZE), }; typedef u32 Addr; @@ -35,6 +38,14 @@ struct ModuleDef { const FunctionDef* func_table; }; +// Read from memory used by CTROS HLE functions +template +inline void Read(T &var, const u32 addr); + +// Write to memory used by CTROS HLE functions +template +inline void Write(u32 addr, const T data); + void RegisterModule(std::string name, int num_functions, const FunctionDef *func_table); void CallSyscall(u32 opcode); diff --git a/src/core/mem_map.h b/src/core/mem_map.h index 2596ba925..ab2c2d4ec 100644 --- a/src/core/mem_map.h +++ b/src/core/mem_map.h @@ -32,10 +32,6 @@ enum { MEM_VRAM_VADDR = 0x1F000000, MEM_SCRATCHPAD_VADDR = (0x10000000 - MEM_SCRATCHPAD_SIZE), ///< Scratchpad virtual address - - MEM_OSHLE_SIZE = 0x08000000, ///< ...Same size as FCRAM for now - MEM_OSHLE_VADDR = 0xA0000000, ///< Memory for use by OSHLE accessible by appcore CPU - MEM_OSHLE_VADDR_END = (MEM_OSHLE_VADDR + MEM_OSHLE_SIZE), }; //////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/core/mem_map_funcs.cpp b/src/core/mem_map_funcs.cpp index f35e25caf..184296287 100644 --- a/src/core/mem_map_funcs.cpp +++ b/src/core/mem_map_funcs.cpp @@ -20,8 +20,8 @@ inline void _Read(T &var, const u32 addr) { // Memory allocated for HLE use that can be addressed from the emulated application // The primary use of this is sharing a commandbuffer between the HLE OS (syscore) and the LLE // core running the user application (appcore) - if (addr >= MEM_OSHLE_VADDR && addr < MEM_OSHLE_VADDR_END) { - NOTICE_LOG(MEMMAP, "OSHLE read @ 0x%08X", addr); + if (addr >= HLE::CMD_BUFFER_ADDR && addr < HLE::CMD_BUFFER_ADDR_END) { + HLE::Read(var, addr); // Hardware I/O register reads // 0x10XXXXXX- is physical address space, 0x1EXXXXXX is virtual address space @@ -58,13 +58,13 @@ inline void _Write(u32 addr, const T data) { // Memory allocated for HLE use that can be addressed from the emulated application // The primary use of this is sharing a commandbuffer between the HLE OS (syscore) and the LLE // core running the user application (appcore) - if (addr >= MEM_OSHLE_VADDR && addr < MEM_OSHLE_VADDR_END) { - NOTICE_LOG(MEMMAP, "OSHLE write @ 0x%08X", addr); + if (addr >= HLE::CMD_BUFFER_ADDR && addr < HLE::CMD_BUFFER_ADDR_END) { + HLE::Write(addr, data); // Hardware I/O register writes // 0x10XXXXXX- is physical address space, 0x1EXXXXXX is virtual address space } else if ((addr & 0xFF000000) == 0x10000000 || (addr & 0xFF000000) == 0x1E000000) { - HW::Write(addr, data); + HW::Write(addr, data); // ExeFS:/.code is loaded here: } else if ((addr & 0xFFF00000) == 0x00100000) { From f2f63a0f0583d672342d300f3c8b099f56a13c7d Mon Sep 17 00:00:00 2001 From: bunnei Date: Sat, 12 Apr 2014 23:32:04 -0400 Subject: [PATCH 21/49] fixed hw write declarations to not be const --- src/core/hw/hw.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/core/hw/hw.cpp b/src/core/hw/hw.cpp index 7191d7c60..59c348ca9 100644 --- a/src/core/hw/hw.cpp +++ b/src/core/hw/hw.cpp @@ -27,10 +27,10 @@ template void Read(u32 &var, const u32 addr); template void Read(u16 &var, const u32 addr); template void Read(u8 &var, const u32 addr); -template void Write(u32 addr, const u64 data); -template void Write(u32 addr, const u32 data); -template void Write(u32 addr, const u16 data); -template void Write(u32 addr, const u8 data); +template void Write(u32 addr, const u64 data); +template void Write(u32 addr, const u32 data); +template void Write(u32 addr, const u16 data); +template void Write(u32 addr, const u8 data); /// Update hardware void Update() { From 67f6e414702cbb83a53392e1cca229875a186cea Mon Sep 17 00:00:00 2001 From: bunnei Date: Sun, 13 Apr 2014 00:37:10 -0400 Subject: [PATCH 22/49] added a GetPointer function for reading from HLE command buffer --- src/core/hle/hle.cpp | 8 ++++++++ src/core/hle/hle.h | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/src/core/hle/hle.cpp b/src/core/hle/hle.cpp index 51432dc87..a4ab61c0c 100644 --- a/src/core/hle/hle.cpp +++ b/src/core/hle/hle.cpp @@ -37,6 +37,14 @@ inline void Write(u32 addr, const T data) { } } +u8 *GetPointer(const u32 addr) { + if (addr >= HLE::CMD_BUFFER_ADDR && addr < HLE::CMD_BUFFER_ADDR_END) { + return g_command_buffer + (addr & CMD_BUFFER_MASK); + } else { + ERROR_LOG(HLE, "unknown pointer from address %08X", addr); + } +} + // Explicitly instantiate template functions because we aren't defining this in the header: template void Read(u64 &var, const u32 addr); diff --git a/src/core/hle/hle.h b/src/core/hle/hle.h index 5ee90bcdc..d02948be3 100644 --- a/src/core/hle/hle.h +++ b/src/core/hle/hle.h @@ -46,6 +46,12 @@ inline void Read(T &var, const u32 addr); template inline void Write(u32 addr, const T data); +u8* GetPointer(const u32 Address); + +inline const char* GetCharPointer(const u32 address) { + return (const char *)GetPointer(address); +} + void RegisterModule(std::string name, int num_functions, const FunctionDef *func_table); void CallSyscall(u32 opcode); From 5ea4679630d6776837114252476dd445f377322d Mon Sep 17 00:00:00 2001 From: bunnei Date: Sun, 13 Apr 2014 00:38:48 -0400 Subject: [PATCH 23/49] added some very initial command parsing for SRV Sync --- src/core/hle/service/service.cpp | 36 +++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp index 3434b6dbf..556dfc8a2 100644 --- a/src/core/hle/service/service.cpp +++ b/src/core/hle/service/service.cpp @@ -5,15 +5,16 @@ #include "common/common.h" #include "common/log.h" +#include "core/hle/hle.h" #include "core/hle/service/service.h" -//////////////////////////////////////////////////////////////////////////////////////////////////// -// Namespace Service - namespace Service { Manager* g_manager = NULL; ///< Service manager +//////////////////////////////////////////////////////////////////////////////////////////////////// +// Service Manager class + Manager::Manager() { } @@ -62,7 +63,11 @@ Interface* Manager::FetchFromPortName(std::string port_name) { return FetchFromUID(itr->second); } +//////////////////////////////////////////////////////////////////////////////////////////////////// +// Interface to "SRV" service + class Interface_SRV : public Interface { + public: Interface_SRV() { @@ -71,6 +76,12 @@ public: ~Interface_SRV() { } + enum { + CMD_OFFSET = 0x80, + CMD_HEADER_INIT = 0x10002, ///< Command header to initialize SRV service + CMD_HEADER_GET_HANDLE = 0x50100, ///< Command header to get handle of other services + }; + /** * Gets the string name used by CTROS for a service * @return String name of service @@ -92,12 +103,27 @@ public: * @return Return result of svcSendSyncRequest passed back to user app */ Syscall::Result Sync() { - ERROR_LOG(HLE, "Unimplemented function Interface_SRV::Sync"); + u32 header = 0; + HLE::Read(header, (HLE::CMD_BUFFER_ADDR + CMD_OFFSET)); + + switch (header) { + case CMD_HEADER_INIT: + NOTICE_LOG(HLE, "Interface_SRV::Sync - Initialize"); + break; + + case CMD_HEADER_GET_HANDLE: + NOTICE_LOG(HLE, "Interface_SRV::Sync - GetHandle, port: %s", HLE::GetCharPointer(HLE::CMD_BUFFER_ADDR + CMD_OFFSET + 4)); + break; + } + return 0; } - + }; +//////////////////////////////////////////////////////////////////////////////////////////////////// +// Module interface + /// Initialize ServiceManager void Init() { g_manager = new Manager; From ce822b68152fe2a35c30fd38d0e98d92db2e8d04 Mon Sep 17 00:00:00 2001 From: bunnei Date: Sun, 13 Apr 2014 00:39:05 -0400 Subject: [PATCH 24/49] replace tabs with spaces --- src/core/mem_map.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/mem_map.h b/src/core/mem_map.h index ab2c2d4ec..d0308fa5c 100644 --- a/src/core/mem_map.h +++ b/src/core/mem_map.h @@ -50,8 +50,8 @@ extern u8 *g_base; // These are guaranteed to point to "low memory" addresses (sub-32-bit). // 64-bit: Pointers to low-mem (sub-0x10000000) mirror // 32-bit: Same as the corresponding physical/virtual pointers. -extern u8* g_fcram; ///< Main memory -extern u8* g_vram; ///< Video memory (VRAM) +extern u8* g_fcram; ///< Main memory +extern u8* g_vram; ///< Video memory (VRAM) extern u8* g_scratchpad; ///< Stack memory void Init(); @@ -71,7 +71,7 @@ void Write32(const u32 addr, const u32 data); u8* GetPointer(const u32 Address); inline const char* GetCharPointer(const u32 address) { - return (const char *)GetPointer(address); + return (const char *)GetPointer(address); } } // namespace From 524e78ece8139ad1adf4c6cf08ff1f705e7af823 Mon Sep 17 00:00:00 2001 From: bunnei Date: Sun, 13 Apr 2014 01:22:05 -0400 Subject: [PATCH 25/49] renamed class Interface_SRV to SRV --- src/core/hle/service/service.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp index 556dfc8a2..b0b2b7b35 100644 --- a/src/core/hle/service/service.cpp +++ b/src/core/hle/service/service.cpp @@ -66,14 +66,14 @@ Interface* Manager::FetchFromPortName(std::string port_name) { //////////////////////////////////////////////////////////////////////////////////////////////////// // Interface to "SRV" service -class Interface_SRV : public Interface { +class SRV : public Interface { public: - Interface_SRV() { + SRV() { } - ~Interface_SRV() { + ~SRV() { } enum { @@ -108,11 +108,11 @@ public: switch (header) { case CMD_HEADER_INIT: - NOTICE_LOG(HLE, "Interface_SRV::Sync - Initialize"); + NOTICE_LOG(HLE, "SRV::Sync - Initialize"); break; case CMD_HEADER_GET_HANDLE: - NOTICE_LOG(HLE, "Interface_SRV::Sync - GetHandle, port: %s", HLE::GetCharPointer(HLE::CMD_BUFFER_ADDR + CMD_OFFSET + 4)); + NOTICE_LOG(HLE, "SRV::Sync - GetHandle, port: %s", HLE::GetCharPointer(HLE::CMD_BUFFER_ADDR + CMD_OFFSET + 4)); break; } @@ -127,7 +127,7 @@ public: /// Initialize ServiceManager void Init() { g_manager = new Manager; - g_manager->AddService(new Interface_SRV); + g_manager->AddService(new SRV); NOTICE_LOG(HLE, "Services initialized OK"); } From 9f4d677cdf1fcc937d2e68cae3f52f53c24582f8 Mon Sep 17 00:00:00 2001 From: bunnei Date: Sun, 13 Apr 2014 16:33:45 -0400 Subject: [PATCH 26/49] added framework for APT service (application and title launching service) --- src/core/core.vcxproj | 2 + src/core/core.vcxproj.filters | 6 +++ src/core/hle/hle.cpp | 1 + src/core/hle/service/apt.cpp | 21 ++++++++++ src/core/hle/service/apt.h | 71 ++++++++++++++++++++++++++++++++ src/core/hle/service/service.cpp | 29 ++++++++++--- src/core/hle/service/service.h | 1 + 7 files changed, 126 insertions(+), 5 deletions(-) create mode 100644 src/core/hle/service/apt.cpp create mode 100644 src/core/hle/service/apt.h diff --git a/src/core/core.vcxproj b/src/core/core.vcxproj index b10ae8684..be750b24f 100644 --- a/src/core/core.vcxproj +++ b/src/core/core.vcxproj @@ -153,6 +153,7 @@ + @@ -187,6 +188,7 @@ + diff --git a/src/core/core.vcxproj.filters b/src/core/core.vcxproj.filters index 4844e78b8..29d680935 100644 --- a/src/core/core.vcxproj.filters +++ b/src/core/core.vcxproj.filters @@ -90,6 +90,9 @@ hle\service + + hle\service + @@ -175,6 +178,9 @@ hle + + hle\service + diff --git a/src/core/hle/hle.cpp b/src/core/hle/hle.cpp index a4ab61c0c..c173b82de 100644 --- a/src/core/hle/hle.cpp +++ b/src/core/hle/hle.cpp @@ -42,6 +42,7 @@ u8 *GetPointer(const u32 addr) { return g_command_buffer + (addr & CMD_BUFFER_MASK); } else { ERROR_LOG(HLE, "unknown pointer from address %08X", addr); + return 0; } } diff --git a/src/core/hle/service/apt.cpp b/src/core/hle/service/apt.cpp new file mode 100644 index 000000000..9ab5a361c --- /dev/null +++ b/src/core/hle/service/apt.cpp @@ -0,0 +1,21 @@ +// Copyright 2014 Citra Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + + +#include "common/log.h" +#include "core/hle/service/apt.h" + + + + +namespace Service { + + +Syscall::Result APT::Sync() { + NOTICE_LOG(HLE, "APT::Sync - Initialize"); + return 0; +} + + +} diff --git a/src/core/hle/service/apt.h b/src/core/hle/service/apt.h new file mode 100644 index 000000000..05c544378 --- /dev/null +++ b/src/core/hle/service/apt.h @@ -0,0 +1,71 @@ +// Copyright 2014 Citra Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#pragma once + +#include "core/hle/service/service.h" + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// Namespace Service + +namespace Service { + +// Application and title launching service. These services handle signaling for home/power button as +// well. Only one session for either APT service can be open at a time, normally processes close the +// service handle immediately once finished using the service. The commands for APT:U and APT:S are +// exactly the same, however certain commands are only accessible with APT:S(NS module will call +// svcBreak when the command isn't accessible). See http://3dbrew.org/wiki/NS#APT_Services. + +class APT : public Interface { +public: + + APT() { + } + + ~APT() { + } + + enum { + CMD_OFFSET = 0x00000080, + + CMD_HEADER_INIT = 0x00020080, ///< Initialize service + CMD_HEADER_GET_LOCK_HANDLE = 0x00010040, ///< Get service Mutex + CMD_HEADER_ENABLE = 0x00030040, ///< Enable service + CMD_HEADER_INQUIRE_NOTIFICATION = 0x000B0040, ///< Inquire notification + CMD_HEADER_PREPARE_TO_JUMP_TO_HOME_MENU = 0x002B0000, ///< Prepare to jump to home menu + CMD_HEADER_JUMP_TO_HOME_MENU = 0x002C0044, ///< Jump to home menu + CMD_HEADER_NOTIFY_TO_WAIT = 0x00430040, ///< Notify to wait + CMD_HEADER_APPLET_UTILITY = 0x004B00C2, ///< Applet utility + CMD_HEADER_GLANCE_PARAMETER = 0x000E0080, ///< Glance parameter + CMD_HEADER_RECEIVE_PARAMETER = 0x000D0080, ///< Receive parameter + CMD_HEADER_REPLY_SLEEP_QUERY = 0x003E0080, ///< Reply sleep query + CMD_HEADER_PREPARE_TO_CLOSE_APP = 0x00220040, ///< Prepare to close application + CMD_HEADER_CLOSE_APP = 0x00270044, ///< Close application + }; + + /** + * Gets the string name used by CTROS for the APT service + * @return String name of service + */ + std::string GetName() const { + return "APT"; + } + + /** + * Gets the string port name used by CTROS for the APT service + * @return Port name of service + */ + std::string GetPortName() const { + return "APT:U"; + } + + /** + * Called when svcSendSyncRequest is called, loads command buffer and executes comand + * @return Return result of svcSendSyncRequest passed back to user app + */ + virtual Syscall::Result Sync(); + +}; + +} // namespace diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp index b0b2b7b35..b2470d814 100644 --- a/src/core/hle/service/service.cpp +++ b/src/core/hle/service/service.cpp @@ -7,6 +7,7 @@ #include "core/hle/hle.h" #include "core/hle/service/service.h" +#include "core/hle/service/apt.h" namespace Service { @@ -104,19 +105,36 @@ public: */ Syscall::Result Sync() { u32 header = 0; - HLE::Read(header, (HLE::CMD_BUFFER_ADDR + CMD_OFFSET)); + Syscall::Result res = 0; + + u32* cmd_buff = (u32*)HLE::GetPointer(HLE::CMD_BUFFER_ADDR + CMD_OFFSET); + + switch (cmd_buff[0]) { - switch (header) { case CMD_HEADER_INIT: - NOTICE_LOG(HLE, "SRV::Sync - Initialize"); + NOTICE_LOG(OSHLE, "SRV::Sync - Initialize"); break; case CMD_HEADER_GET_HANDLE: - NOTICE_LOG(HLE, "SRV::Sync - GetHandle, port: %s", HLE::GetCharPointer(HLE::CMD_BUFFER_ADDR + CMD_OFFSET + 4)); + const char* port_name = (const char*)&cmd_buff[1]; + Interface* service = g_manager->FetchFromPortName(port_name); + + NOTICE_LOG(OSHLE, "SRV::Sync - GetHandle - port: %s, handle: 0x%08X", port_name, + service->GetUID()); + + if (NULL != service) { + cmd_buff[3] = service->GetUID(); + } else { + ERROR_LOG(OSHLE, "Service %s does not exist", port_name); + res = -1; + } + break; } - return 0; + cmd_buff[1] = res; + + return res; } }; @@ -128,6 +146,7 @@ public: void Init() { g_manager = new Manager; g_manager->AddService(new SRV); + g_manager->AddService(new APT); NOTICE_LOG(HLE, "Services initialized OK"); } diff --git a/src/core/hle/service/service.h b/src/core/hle/service/service.h index 3cad6c642..365583ed2 100644 --- a/src/core/hle/service/service.h +++ b/src/core/hle/service/service.h @@ -8,6 +8,7 @@ #include #include +#include "common/common.h" #include "common/common_types.h" #include "core/hle/syscall.h" From 18766b9e69bf822764eba98237325d07b3c4ef0f Mon Sep 17 00:00:00 2001 From: bunnei Date: Sun, 13 Apr 2014 22:59:16 -0400 Subject: [PATCH 27/49] added a stub for GetLockHandle --- src/core/hle/service/apt.cpp | 35 +++++++++++++++++++++++++++----- src/core/hle/service/apt.h | 8 +++++++- src/core/hle/service/service.cpp | 10 ++++++--- 3 files changed, 44 insertions(+), 9 deletions(-) diff --git a/src/core/hle/service/apt.cpp b/src/core/hle/service/apt.cpp index 9ab5a361c..5e37b838a 100644 --- a/src/core/hle/service/apt.cpp +++ b/src/core/hle/service/apt.cpp @@ -4,17 +4,42 @@ #include "common/log.h" + +#include "core/hle/hle.h" #include "core/hle/service/apt.h" - - - namespace Service { +// Returns handle to APT Mutex. Not imlemented. +Syscall::Result APT::GetLockHandle() { + return 0x00000000; +} +/** + * Called when svcSendSyncRequest is called, loads command buffer and executes comand + * @return Return result of svcSendSyncRequest passed back to user app + */ Syscall::Result APT::Sync() { - NOTICE_LOG(HLE, "APT::Sync - Initialize"); - return 0; + Syscall::Result res = 0; + u32* cmd_buff = (u32*)HLE::GetPointer(HLE::CMD_BUFFER_ADDR + CMD_OFFSET); + + switch(cmd_buff[0]) { + case CMD_HEADER_INIT: + NOTICE_LOG(OSHLE, "APT::Sync - Initialize"); + break; + + case CMD_HEADER_GET_LOCK_HANDLE: + NOTICE_LOG(OSHLE, "APT::Sync - GetLockHandle"); + cmd_buff[5] = GetLockHandle(); + break; + + default: + ERROR_LOG(OSHLE, "APT::Sync - Unknown command 0x%08X", cmd_buff[0]); + res = -1; + break; + } + + return res; } diff --git a/src/core/hle/service/apt.h b/src/core/hle/service/apt.h index 05c544378..3730bc30e 100644 --- a/src/core/hle/service/apt.h +++ b/src/core/hle/service/apt.h @@ -64,7 +64,13 @@ public: * Called when svcSendSyncRequest is called, loads command buffer and executes comand * @return Return result of svcSendSyncRequest passed back to user app */ - virtual Syscall::Result Sync(); + Syscall::Result Sync(); + +private: + + + Syscall::Result GetLockHandle(); + }; diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp index b2470d814..44c7c8627 100644 --- a/src/core/hle/service/service.cpp +++ b/src/core/hle/service/service.cpp @@ -104,9 +104,7 @@ public: * @return Return result of svcSendSyncRequest passed back to user app */ Syscall::Result Sync() { - u32 header = 0; Syscall::Result res = 0; - u32* cmd_buff = (u32*)HLE::GetPointer(HLE::CMD_BUFFER_ADDR + CMD_OFFSET); switch (cmd_buff[0]) { @@ -116,6 +114,7 @@ public: break; case CMD_HEADER_GET_HANDLE: + { const char* port_name = (const char*)&cmd_buff[1]; Interface* service = g_manager->FetchFromPortName(port_name); @@ -128,7 +127,12 @@ public: ERROR_LOG(OSHLE, "Service %s does not exist", port_name); res = -1; } - + break; + } + + default: + ERROR_LOG(OSHLE, "SRV::Sync - Unknown command 0x%08X", cmd_buff[0]); + res = -1; break; } From cb504e236bb21816b5794a14c4dc57d93766e5a8 Mon Sep 17 00:00:00 2001 From: bunnei Date: Mon, 14 Apr 2014 21:25:46 -0400 Subject: [PATCH 28/49] added helper functions for upper/lowercase strings --- src/common/string_util.cpp | 16 ++++++++++++++++ src/common/string_util.h | 6 ++++++ 2 files changed, 22 insertions(+) diff --git a/src/common/string_util.cpp b/src/common/string_util.cpp index a99644f11..e5a9ba322 100644 --- a/src/common/string_util.cpp +++ b/src/common/string_util.cpp @@ -17,6 +17,22 @@ #include #endif +/// Make a string lowercase +void LowerStr(char* str) { + for (int i = 0; str[i]; i++) { + str[i] = tolower(str[ i ]); + } +} + +/// Make a string uppercase +void UpperStr(char* str) { + for (int i=0; i < strlen(str); i++) { + if(str[i] >= 'a' && str[i] <= 'z') { + str[i] &= 0xDF; + } + } +} + // faster than sscanf bool AsciiToHex(const char* _szValue, u32& result) { diff --git a/src/common/string_util.h b/src/common/string_util.h index 6b7e84797..b3c99a807 100644 --- a/src/common/string_util.h +++ b/src/common/string_util.h @@ -14,6 +14,12 @@ #include "common/common.h" +/// Make a string lowercase +void LowerStr(char* str); + +/// Make a string uppercase +void UpperStr(char* str); + std::string StringFromFormat(const char* format, ...); // Cheap! bool CharArrayFromFormatV(char* out, int outsize, const char* format, va_list args); From 7ec5950bc4c8e4a786df1f4c3392d7b5332d1613 Mon Sep 17 00:00:00 2001 From: bunnei Date: Tue, 15 Apr 2014 22:40:19 -0400 Subject: [PATCH 29/49] - extracted srv: calls from service.cpp and put in its own module - added function tables for service calls - lots of refactoring --- src/core/core.vcxproj | 2 + src/core/core.vcxproj.filters | 6 +++ src/core/hle/service/apt.cpp | 91 ++++++++++++++++++++++++++++++-- src/core/hle/service/apt.h | 17 ++---- src/core/hle/service/service.cpp | 84 ++--------------------------- src/core/hle/service/service.h | 19 ++++--- 6 files changed, 113 insertions(+), 106 deletions(-) diff --git a/src/core/core.vcxproj b/src/core/core.vcxproj index be750b24f..da3cc7a26 100644 --- a/src/core/core.vcxproj +++ b/src/core/core.vcxproj @@ -155,6 +155,7 @@ + @@ -190,6 +191,7 @@ + diff --git a/src/core/core.vcxproj.filters b/src/core/core.vcxproj.filters index 29d680935..fa20ab686 100644 --- a/src/core/core.vcxproj.filters +++ b/src/core/core.vcxproj.filters @@ -93,6 +93,9 @@ hle\service + + hle\service + @@ -181,6 +184,9 @@ hle\service + + hle\service + diff --git a/src/core/hle/service/apt.cpp b/src/core/hle/service/apt.cpp index 5e37b838a..b1e49db97 100644 --- a/src/core/hle/service/apt.cpp +++ b/src/core/hle/service/apt.cpp @@ -10,8 +10,89 @@ namespace Service { +const HLE::FunctionDef APT_U_Table[] = { + {0x00010040, NULL, "GetLockHandle"}, + {0x00020080, NULL, "Initialize"}, + {0x00030040, NULL, "Enable"}, + {0x00040040, NULL, "Finalize"}, + {0x00050040, NULL, "GetAppletManInfo"}, + {0x00060040, NULL, "GetAppletInfo"}, + {0x00070000, NULL, "GetLastSignaledAppletId"}, + {0x00080000, NULL, "CountRegisteredApplet"}, + {0x00090040, NULL, "IsRegistered"}, + {0x000A0040, NULL, "GetAttribute"}, + {0x000B0040, NULL, "InquireNotification"}, + {0x000C0104, NULL, "SendParameter"}, + {0x000D0080, NULL, "ReceiveParameter"}, + {0x000E0080, NULL, "GlanceParameter"}, + {0x000F0100, NULL, "CancelParameter"}, + {0x001000C2, NULL, "DebugFunc"}, + {0x001100C0, NULL, "MapProgramIdForDebug"}, + {0x00120040, NULL, "SetHomeMenuAppletIdForDebug"}, + {0x00130000, NULL, "GetPreparationState"}, + {0x00140040, NULL, "SetPreparationState"}, + {0x00150140, NULL, "PrepareToStartApplication"}, + {0x00160040, NULL, "PreloadLibraryApplet"}, + {0x00170040, NULL, "FinishPreloadingLibraryApplet"}, + {0x00180040, NULL, "PrepareToStartLibraryApplet"}, + {0x00190040, NULL, "PrepareToStartSystemApplet"}, + {0x001A0000, NULL, "PrepareToStartNewestHomeMenu"}, + {0x001B00C4, NULL, "StartApplication"}, + {0x001C0000, NULL, "WakeupApplication"}, + {0x001D0000, NULL, "CancelApplication"}, + {0x001E0084, NULL, "StartLibraryApplet"}, + {0x001F0084, NULL, "StartSystemApplet"}, + {0x00200044, NULL, "StartNewestHomeMenu"}, + {0x00210000, NULL, "OrderToCloseApplication"}, + {0x00220040, NULL, "PrepareToCloseApplication"}, + {0x00230040, NULL, "PrepareToJumpToApplication"}, + {0x00240044, NULL, "JumpToApplication"}, + {0x002500C0, NULL, "PrepareToCloseLibraryApplet"}, + {0x00260000, NULL, "PrepareToCloseSystemApplet"}, + {0x00270044, NULL, "CloseApplication"}, + {0x00280044, NULL, "CloseLibraryApplet"}, + {0x00290044, NULL, "CloseSystemApplet"}, + {0x002A0000, NULL, "OrderToCloseSystemApplet"}, + {0x002B0000, NULL, "PrepareToJumpToHomeMenu"}, + {0x002C0044, NULL, "JumpToHomeMenu"}, + {0x002D0000, NULL, "PrepareToLeaveHomeMenu"}, + {0x002E0044, NULL, "LeaveHomeMenu"}, + {0x002F0040, NULL, "PrepareToLeaveResidentApplet"}, + {0x00300044, NULL, "LeaveResidentApplet"}, + {0x00310100, NULL, "PrepareToDoApplicationJump"}, + {0x00320084, NULL, "DoApplicationJump"}, + {0x00330000, NULL, "GetProgramIdOnApplicationJump"}, + {0x00340084, NULL, "SendDeliverArg"}, + {0x00350080, NULL, "ReceiveDeliverArg"}, + {0x00360040, NULL, "LoadSysMenuArg"}, + {0x00370042, NULL, "StoreSysMenuArg"}, + {0x00380040, NULL, "PreloadResidentApplet"}, + {0x00390040, NULL, "PrepareToStartResidentApplet"}, + {0x003A0044, NULL, "StartResidentApplet"}, + {0x003B0040, NULL, "CancelLibraryApplet"}, + {0x003C0042, NULL, "SendDspSleep"}, + {0x003D0042, NULL, "SendDspWakeUp"}, + {0x003E0080, NULL, "ReplySleepQuery"}, + {0x003F0040, NULL, "ReplySleepNotificationComplete"}, + {0x00400042, NULL, "SendCaptureBufferInfo"}, + {0x00410040, NULL, "ReceiveCaptureBufferInfo"}, + {0x00420080, NULL, "SleepSystem"}, + {0x00430040, NULL, "NotifyToWait"}, + {0x00440000, NULL, "GetSharedFont"}, + {0x00450040, NULL, "GetWirelessRebootInfo"}, + {0x00460104, NULL, "Wrap"}, + {0x00470104, NULL, "Unwrap"}, + {0x00480100, NULL, "GetProgramInfo"}, + {0x00490180, NULL, "Reboot"}, + {0x004A0040, NULL, "GetCaptureInfo"}, + {0x004B00C2, NULL, "AppletUtility"}, + {0x004C0000, NULL, "SetFatalErrDispMode"}, + {0x004D0080, NULL, "GetAppletProgramInfo"}, + {0x004E0000, NULL, "HardwareResetAsync"}, +}; + // Returns handle to APT Mutex. Not imlemented. -Syscall::Result APT::GetLockHandle() { +Syscall::Result APT_U::GetLockHandle() { return 0x00000000; } @@ -19,22 +100,22 @@ Syscall::Result APT::GetLockHandle() { * Called when svcSendSyncRequest is called, loads command buffer and executes comand * @return Return result of svcSendSyncRequest passed back to user app */ -Syscall::Result APT::Sync() { +Syscall::Result APT_U::Sync() { Syscall::Result res = 0; u32* cmd_buff = (u32*)HLE::GetPointer(HLE::CMD_BUFFER_ADDR + CMD_OFFSET); switch(cmd_buff[0]) { case CMD_HEADER_INIT: - NOTICE_LOG(OSHLE, "APT::Sync - Initialize"); + NOTICE_LOG(OSHLE, "APT_U::Sync - Initialize"); break; case CMD_HEADER_GET_LOCK_HANDLE: - NOTICE_LOG(OSHLE, "APT::Sync - GetLockHandle"); + NOTICE_LOG(OSHLE, "APT_U::Sync - GetLockHandle"); cmd_buff[5] = GetLockHandle(); break; default: - ERROR_LOG(OSHLE, "APT::Sync - Unknown command 0x%08X", cmd_buff[0]); + ERROR_LOG(OSHLE, "APT_U::Sync - Unknown command 0x%08X", cmd_buff[0]); res = -1; break; } diff --git a/src/core/hle/service/apt.h b/src/core/hle/service/apt.h index 3730bc30e..0e1f205c7 100644 --- a/src/core/hle/service/apt.h +++ b/src/core/hle/service/apt.h @@ -17,13 +17,13 @@ namespace Service { // exactly the same, however certain commands are only accessible with APT:S(NS module will call // svcBreak when the command isn't accessible). See http://3dbrew.org/wiki/NS#APT_Services. -class APT : public Interface { +class APT_U : public Interface { public: - APT() { + APT_U() { } - ~APT() { + ~APT_U() { } enum { @@ -44,14 +44,6 @@ public: CMD_HEADER_CLOSE_APP = 0x00270044, ///< Close application }; - /** - * Gets the string name used by CTROS for the APT service - * @return String name of service - */ - std::string GetName() const { - return "APT"; - } - /** * Gets the string port name used by CTROS for the APT service * @return Port name of service @@ -68,10 +60,9 @@ public: private: - Syscall::Result GetLockHandle(); - + DISALLOW_COPY_AND_ASSIGN(APT_U); }; } // namespace diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp index 44c7c8627..799dbe90e 100644 --- a/src/core/hle/service/service.cpp +++ b/src/core/hle/service/service.cpp @@ -4,10 +4,12 @@ #include "common/common.h" #include "common/log.h" +#include "common/string_util.h" #include "core/hle/hle.h" #include "core/hle/service/service.h" #include "core/hle/service/apt.h" +#include "core/hle/service/srv.h" namespace Service { @@ -64,84 +66,6 @@ Interface* Manager::FetchFromPortName(std::string port_name) { return FetchFromUID(itr->second); } -//////////////////////////////////////////////////////////////////////////////////////////////////// -// Interface to "SRV" service - -class SRV : public Interface { - -public: - - SRV() { - } - - ~SRV() { - } - - enum { - CMD_OFFSET = 0x80, - CMD_HEADER_INIT = 0x10002, ///< Command header to initialize SRV service - CMD_HEADER_GET_HANDLE = 0x50100, ///< Command header to get handle of other services - }; - - /** - * Gets the string name used by CTROS for a service - * @return String name of service - */ - std::string GetName() const { - return "ServiceManager"; - } - - /** - * Gets the string name used by CTROS for a service - * @return Port name of service - */ - std::string GetPortName() const { - return "srv:"; - } - - /** - * Called when svcSendSyncRequest is called, loads command buffer and executes comand - * @return Return result of svcSendSyncRequest passed back to user app - */ - Syscall::Result Sync() { - Syscall::Result res = 0; - u32* cmd_buff = (u32*)HLE::GetPointer(HLE::CMD_BUFFER_ADDR + CMD_OFFSET); - - switch (cmd_buff[0]) { - - case CMD_HEADER_INIT: - NOTICE_LOG(OSHLE, "SRV::Sync - Initialize"); - break; - - case CMD_HEADER_GET_HANDLE: - { - const char* port_name = (const char*)&cmd_buff[1]; - Interface* service = g_manager->FetchFromPortName(port_name); - - NOTICE_LOG(OSHLE, "SRV::Sync - GetHandle - port: %s, handle: 0x%08X", port_name, - service->GetUID()); - - if (NULL != service) { - cmd_buff[3] = service->GetUID(); - } else { - ERROR_LOG(OSHLE, "Service %s does not exist", port_name); - res = -1; - } - break; - } - - default: - ERROR_LOG(OSHLE, "SRV::Sync - Unknown command 0x%08X", cmd_buff[0]); - res = -1; - break; - } - - cmd_buff[1] = res; - - return res; - } - -}; //////////////////////////////////////////////////////////////////////////////////////////////////// // Module interface @@ -149,8 +73,8 @@ public: /// Initialize ServiceManager void Init() { g_manager = new Manager; - g_manager->AddService(new SRV); - g_manager->AddService(new APT); + g_manager->AddService(new SRV::Interface); + g_manager->AddService(new APT_U); NOTICE_LOG(HLE, "Services initialized OK"); } diff --git a/src/core/hle/service/service.h b/src/core/hle/service/service.h index 365583ed2..9368a9f0f 100644 --- a/src/core/hle/service/service.h +++ b/src/core/hle/service/service.h @@ -37,14 +37,6 @@ public: return (NativeUID)m_uid; } - /** - * Gets the string name used by CTROS for a service - * @return String name of service - */ - virtual std::string GetName() const { - return "[UNKNOWN SERVICE NAME]"; - } - /** * Gets the string name used by CTROS for a service * @return Port name of service @@ -59,8 +51,19 @@ public: */ virtual Syscall::Result Sync() = 0; +protected: + /** + * Registers the functions in the service + */ + void Register(const HLE::FunctionDef* functions, int len) { + for (int i = 0; i < len; i++) { + m_functions[functions[i].id] = functions[i]; + } + } + private: u32 m_uid; + std::map m_functions; }; /// Simple class to manage accessing services from ports and UID handles From 386dd722e7a2463eadefd3b1fd82681e8edcb5b7 Mon Sep 17 00:00:00 2001 From: bunnei Date: Tue, 15 Apr 2014 22:42:35 -0400 Subject: [PATCH 30/49] fixed naming for APT_U --- src/core/hle/service/apt.cpp | 6 +++--- src/core/hle/service/apt.h | 10 +++++----- src/core/hle/service/service.cpp | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/core/hle/service/apt.cpp b/src/core/hle/service/apt.cpp index b1e49db97..288a68a86 100644 --- a/src/core/hle/service/apt.cpp +++ b/src/core/hle/service/apt.cpp @@ -8,7 +8,7 @@ #include "core/hle/hle.h" #include "core/hle/service/apt.h" -namespace Service { +namespace APT_U { const HLE::FunctionDef APT_U_Table[] = { {0x00010040, NULL, "GetLockHandle"}, @@ -92,7 +92,7 @@ const HLE::FunctionDef APT_U_Table[] = { }; // Returns handle to APT Mutex. Not imlemented. -Syscall::Result APT_U::GetLockHandle() { +Syscall::Result Interface::GetLockHandle() { return 0x00000000; } @@ -100,7 +100,7 @@ Syscall::Result APT_U::GetLockHandle() { * Called when svcSendSyncRequest is called, loads command buffer and executes comand * @return Return result of svcSendSyncRequest passed back to user app */ -Syscall::Result APT_U::Sync() { +Syscall::Result Interface::Sync() { Syscall::Result res = 0; u32* cmd_buff = (u32*)HLE::GetPointer(HLE::CMD_BUFFER_ADDR + CMD_OFFSET); diff --git a/src/core/hle/service/apt.h b/src/core/hle/service/apt.h index 0e1f205c7..2be5a7e15 100644 --- a/src/core/hle/service/apt.h +++ b/src/core/hle/service/apt.h @@ -9,7 +9,7 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// // Namespace Service -namespace Service { +namespace APT_U { // Application and title launching service. These services handle signaling for home/power button as // well. Only one session for either APT service can be open at a time, normally processes close the @@ -17,13 +17,13 @@ namespace Service { // exactly the same, however certain commands are only accessible with APT:S(NS module will call // svcBreak when the command isn't accessible). See http://3dbrew.org/wiki/NS#APT_Services. -class APT_U : public Interface { +class Interface : public Service::Interface { public: - APT_U() { + Interface() { } - ~APT_U() { + ~Interface() { } enum { @@ -62,7 +62,7 @@ private: Syscall::Result GetLockHandle(); - DISALLOW_COPY_AND_ASSIGN(APT_U); + DISALLOW_COPY_AND_ASSIGN(Interface); }; } // namespace diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp index 799dbe90e..81a34ed06 100644 --- a/src/core/hle/service/service.cpp +++ b/src/core/hle/service/service.cpp @@ -74,7 +74,7 @@ Interface* Manager::FetchFromPortName(std::string port_name) { void Init() { g_manager = new Manager; g_manager->AddService(new SRV::Interface); - g_manager->AddService(new APT_U); + g_manager->AddService(new APT_U::Interface); NOTICE_LOG(HLE, "Services initialized OK"); } From ffabed8c25490be0e61409cebd1615eedb223c3d Mon Sep 17 00:00:00 2001 From: bunnei Date: Tue, 15 Apr 2014 23:28:03 -0400 Subject: [PATCH 31/49] restructured hle:services completely to use function lookup tables --- src/core/hle/service/apt.cpp | 204 +++++++++++++++------------------ src/core/hle/service/apt.h | 30 +---- src/core/hle/service/service.h | 28 ++++- src/core/hle/service/srv.cpp | 55 +++++++++ src/core/hle/service/srv.h | 39 +++++++ 5 files changed, 217 insertions(+), 139 deletions(-) create mode 100644 src/core/hle/service/srv.cpp create mode 100644 src/core/hle/service/srv.h diff --git a/src/core/hle/service/apt.cpp b/src/core/hle/service/apt.cpp index 288a68a86..e5c9dd873 100644 --- a/src/core/hle/service/apt.cpp +++ b/src/core/hle/service/apt.cpp @@ -10,118 +10,104 @@ namespace APT_U { -const HLE::FunctionDef APT_U_Table[] = { - {0x00010040, NULL, "GetLockHandle"}, - {0x00020080, NULL, "Initialize"}, - {0x00030040, NULL, "Enable"}, - {0x00040040, NULL, "Finalize"}, - {0x00050040, NULL, "GetAppletManInfo"}, - {0x00060040, NULL, "GetAppletInfo"}, - {0x00070000, NULL, "GetLastSignaledAppletId"}, - {0x00080000, NULL, "CountRegisteredApplet"}, - {0x00090040, NULL, "IsRegistered"}, - {0x000A0040, NULL, "GetAttribute"}, - {0x000B0040, NULL, "InquireNotification"}, - {0x000C0104, NULL, "SendParameter"}, - {0x000D0080, NULL, "ReceiveParameter"}, - {0x000E0080, NULL, "GlanceParameter"}, - {0x000F0100, NULL, "CancelParameter"}, - {0x001000C2, NULL, "DebugFunc"}, - {0x001100C0, NULL, "MapProgramIdForDebug"}, - {0x00120040, NULL, "SetHomeMenuAppletIdForDebug"}, - {0x00130000, NULL, "GetPreparationState"}, - {0x00140040, NULL, "SetPreparationState"}, - {0x00150140, NULL, "PrepareToStartApplication"}, - {0x00160040, NULL, "PreloadLibraryApplet"}, - {0x00170040, NULL, "FinishPreloadingLibraryApplet"}, - {0x00180040, NULL, "PrepareToStartLibraryApplet"}, - {0x00190040, NULL, "PrepareToStartSystemApplet"}, - {0x001A0000, NULL, "PrepareToStartNewestHomeMenu"}, - {0x001B00C4, NULL, "StartApplication"}, - {0x001C0000, NULL, "WakeupApplication"}, - {0x001D0000, NULL, "CancelApplication"}, - {0x001E0084, NULL, "StartLibraryApplet"}, - {0x001F0084, NULL, "StartSystemApplet"}, - {0x00200044, NULL, "StartNewestHomeMenu"}, - {0x00210000, NULL, "OrderToCloseApplication"}, - {0x00220040, NULL, "PrepareToCloseApplication"}, - {0x00230040, NULL, "PrepareToJumpToApplication"}, - {0x00240044, NULL, "JumpToApplication"}, - {0x002500C0, NULL, "PrepareToCloseLibraryApplet"}, - {0x00260000, NULL, "PrepareToCloseSystemApplet"}, - {0x00270044, NULL, "CloseApplication"}, - {0x00280044, NULL, "CloseLibraryApplet"}, - {0x00290044, NULL, "CloseSystemApplet"}, - {0x002A0000, NULL, "OrderToCloseSystemApplet"}, - {0x002B0000, NULL, "PrepareToJumpToHomeMenu"}, - {0x002C0044, NULL, "JumpToHomeMenu"}, - {0x002D0000, NULL, "PrepareToLeaveHomeMenu"}, - {0x002E0044, NULL, "LeaveHomeMenu"}, - {0x002F0040, NULL, "PrepareToLeaveResidentApplet"}, - {0x00300044, NULL, "LeaveResidentApplet"}, - {0x00310100, NULL, "PrepareToDoApplicationJump"}, - {0x00320084, NULL, "DoApplicationJump"}, - {0x00330000, NULL, "GetProgramIdOnApplicationJump"}, - {0x00340084, NULL, "SendDeliverArg"}, - {0x00350080, NULL, "ReceiveDeliverArg"}, - {0x00360040, NULL, "LoadSysMenuArg"}, - {0x00370042, NULL, "StoreSysMenuArg"}, - {0x00380040, NULL, "PreloadResidentApplet"}, - {0x00390040, NULL, "PrepareToStartResidentApplet"}, - {0x003A0044, NULL, "StartResidentApplet"}, - {0x003B0040, NULL, "CancelLibraryApplet"}, - {0x003C0042, NULL, "SendDspSleep"}, - {0x003D0042, NULL, "SendDspWakeUp"}, - {0x003E0080, NULL, "ReplySleepQuery"}, - {0x003F0040, NULL, "ReplySleepNotificationComplete"}, - {0x00400042, NULL, "SendCaptureBufferInfo"}, - {0x00410040, NULL, "ReceiveCaptureBufferInfo"}, - {0x00420080, NULL, "SleepSystem"}, - {0x00430040, NULL, "NotifyToWait"}, - {0x00440000, NULL, "GetSharedFont"}, - {0x00450040, NULL, "GetWirelessRebootInfo"}, - {0x00460104, NULL, "Wrap"}, - {0x00470104, NULL, "Unwrap"}, - {0x00480100, NULL, "GetProgramInfo"}, - {0x00490180, NULL, "Reboot"}, - {0x004A0040, NULL, "GetCaptureInfo"}, - {0x004B00C2, NULL, "AppletUtility"}, - {0x004C0000, NULL, "SetFatalErrDispMode"}, - {0x004D0080, NULL, "GetAppletProgramInfo"}, - {0x004E0000, NULL, "HardwareResetAsync"}, +void Initialize() { + NOTICE_LOG(OSHLE, "APT_U::Sync - Initialize"); +} + +void GetLockHandle() { + u32* cmd_buff = (u32*)HLE::GetPointer(HLE::CMD_BUFFER_ADDR + Service::kCommandHeaderOffset); + cmd_buff[5] = 0x00000000; // TODO: This should be an actual mutex handle +} + +const HLE::FunctionDef FunctionTable[] = { + {0x00010040, GetLockHandle, "GetLockHandle"}, + {0x00020080, Initialize, "Initialize"}, + {0x00030040, NULL, "Enable"}, + {0x00040040, NULL, "Finalize"}, + {0x00050040, NULL, "GetAppletManInfo"}, + {0x00060040, NULL, "GetAppletInfo"}, + {0x00070000, NULL, "GetLastSignaledAppletId"}, + {0x00080000, NULL, "CountRegisteredApplet"}, + {0x00090040, NULL, "IsRegistered"}, + {0x000A0040, NULL, "GetAttribute"}, + {0x000B0040, NULL, "InquireNotification"}, + {0x000C0104, NULL, "SendParameter"}, + {0x000D0080, NULL, "ReceiveParameter"}, + {0x000E0080, NULL, "GlanceParameter"}, + {0x000F0100, NULL, "CancelParameter"}, + {0x001000C2, NULL, "DebugFunc"}, + {0x001100C0, NULL, "MapProgramIdForDebug"}, + {0x00120040, NULL, "SetHomeMenuAppletIdForDebug"}, + {0x00130000, NULL, "GetPreparationState"}, + {0x00140040, NULL, "SetPreparationState"}, + {0x00150140, NULL, "PrepareToStartApplication"}, + {0x00160040, NULL, "PreloadLibraryApplet"}, + {0x00170040, NULL, "FinishPreloadingLibraryApplet"}, + {0x00180040, NULL, "PrepareToStartLibraryApplet"}, + {0x00190040, NULL, "PrepareToStartSystemApplet"}, + {0x001A0000, NULL, "PrepareToStartNewestHomeMenu"}, + {0x001B00C4, NULL, "StartApplication"}, + {0x001C0000, NULL, "WakeupApplication"}, + {0x001D0000, NULL, "CancelApplication"}, + {0x001E0084, NULL, "StartLibraryApplet"}, + {0x001F0084, NULL, "StartSystemApplet"}, + {0x00200044, NULL, "StartNewestHomeMenu"}, + {0x00210000, NULL, "OrderToCloseApplication"}, + {0x00220040, NULL, "PrepareToCloseApplication"}, + {0x00230040, NULL, "PrepareToJumpToApplication"}, + {0x00240044, NULL, "JumpToApplication"}, + {0x002500C0, NULL, "PrepareToCloseLibraryApplet"}, + {0x00260000, NULL, "PrepareToCloseSystemApplet"}, + {0x00270044, NULL, "CloseApplication"}, + {0x00280044, NULL, "CloseLibraryApplet"}, + {0x00290044, NULL, "CloseSystemApplet"}, + {0x002A0000, NULL, "OrderToCloseSystemApplet"}, + {0x002B0000, NULL, "PrepareToJumpToHomeMenu"}, + {0x002C0044, NULL, "JumpToHomeMenu"}, + {0x002D0000, NULL, "PrepareToLeaveHomeMenu"}, + {0x002E0044, NULL, "LeaveHomeMenu"}, + {0x002F0040, NULL, "PrepareToLeaveResidentApplet"}, + {0x00300044, NULL, "LeaveResidentApplet"}, + {0x00310100, NULL, "PrepareToDoApplicationJump"}, + {0x00320084, NULL, "DoApplicationJump"}, + {0x00330000, NULL, "GetProgramIdOnApplicationJump"}, + {0x00340084, NULL, "SendDeliverArg"}, + {0x00350080, NULL, "ReceiveDeliverArg"}, + {0x00360040, NULL, "LoadSysMenuArg"}, + {0x00370042, NULL, "StoreSysMenuArg"}, + {0x00380040, NULL, "PreloadResidentApplet"}, + {0x00390040, NULL, "PrepareToStartResidentApplet"}, + {0x003A0044, NULL, "StartResidentApplet"}, + {0x003B0040, NULL, "CancelLibraryApplet"}, + {0x003C0042, NULL, "SendDspSleep"}, + {0x003D0042, NULL, "SendDspWakeUp"}, + {0x003E0080, NULL, "ReplySleepQuery"}, + {0x003F0040, NULL, "ReplySleepNotificationComplete"}, + {0x00400042, NULL, "SendCaptureBufferInfo"}, + {0x00410040, NULL, "ReceiveCaptureBufferInfo"}, + {0x00420080, NULL, "SleepSystem"}, + {0x00430040, NULL, "NotifyToWait"}, + {0x00440000, NULL, "GetSharedFont"}, + {0x00450040, NULL, "GetWirelessRebootInfo"}, + {0x00460104, NULL, "Wrap"}, + {0x00470104, NULL, "Unwrap"}, + {0x00480100, NULL, "GetProgramInfo"}, + {0x00490180, NULL, "Reboot"}, + {0x004A0040, NULL, "GetCaptureInfo"}, + {0x004B00C2, NULL, "AppletUtility"}, + {0x004C0000, NULL, "SetFatalErrDispMode"}, + {0x004D0080, NULL, "GetAppletProgramInfo"}, + {0x004E0000, NULL, "HardwareResetAsync"}, }; -// Returns handle to APT Mutex. Not imlemented. -Syscall::Result Interface::GetLockHandle() { - return 0x00000000; +//////////////////////////////////////////////////////////////////////////////////////////////////// +// Interface class + +Interface::Interface() { + Register(FunctionTable, ARRAY_SIZE(FunctionTable)); } -/** - * Called when svcSendSyncRequest is called, loads command buffer and executes comand - * @return Return result of svcSendSyncRequest passed back to user app - */ -Syscall::Result Interface::Sync() { - Syscall::Result res = 0; - u32* cmd_buff = (u32*)HLE::GetPointer(HLE::CMD_BUFFER_ADDR + CMD_OFFSET); - - switch(cmd_buff[0]) { - case CMD_HEADER_INIT: - NOTICE_LOG(OSHLE, "APT_U::Sync - Initialize"); - break; - - case CMD_HEADER_GET_LOCK_HANDLE: - NOTICE_LOG(OSHLE, "APT_U::Sync - GetLockHandle"); - cmd_buff[5] = GetLockHandle(); - break; - - default: - ERROR_LOG(OSHLE, "APT_U::Sync - Unknown command 0x%08X", cmd_buff[0]); - res = -1; - break; - } - - return res; +Interface::~Interface() { } - -} +} // namespace diff --git a/src/core/hle/service/apt.h b/src/core/hle/service/apt.h index 2be5a7e15..9f0245cc8 100644 --- a/src/core/hle/service/apt.h +++ b/src/core/hle/service/apt.h @@ -20,29 +20,9 @@ namespace APT_U { class Interface : public Service::Interface { public: - Interface() { - } + Interface(); - ~Interface() { - } - - enum { - CMD_OFFSET = 0x00000080, - - CMD_HEADER_INIT = 0x00020080, ///< Initialize service - CMD_HEADER_GET_LOCK_HANDLE = 0x00010040, ///< Get service Mutex - CMD_HEADER_ENABLE = 0x00030040, ///< Enable service - CMD_HEADER_INQUIRE_NOTIFICATION = 0x000B0040, ///< Inquire notification - CMD_HEADER_PREPARE_TO_JUMP_TO_HOME_MENU = 0x002B0000, ///< Prepare to jump to home menu - CMD_HEADER_JUMP_TO_HOME_MENU = 0x002C0044, ///< Jump to home menu - CMD_HEADER_NOTIFY_TO_WAIT = 0x00430040, ///< Notify to wait - CMD_HEADER_APPLET_UTILITY = 0x004B00C2, ///< Applet utility - CMD_HEADER_GLANCE_PARAMETER = 0x000E0080, ///< Glance parameter - CMD_HEADER_RECEIVE_PARAMETER = 0x000D0080, ///< Receive parameter - CMD_HEADER_REPLY_SLEEP_QUERY = 0x003E0080, ///< Reply sleep query - CMD_HEADER_PREPARE_TO_CLOSE_APP = 0x00220040, ///< Prepare to close application - CMD_HEADER_CLOSE_APP = 0x00270044, ///< Close application - }; + ~Interface(); /** * Gets the string port name used by CTROS for the APT service @@ -52,12 +32,6 @@ public: return "APT:U"; } - /** - * Called when svcSendSyncRequest is called, loads command buffer and executes comand - * @return Return result of svcSendSyncRequest passed back to user app - */ - Syscall::Result Sync(); - private: Syscall::Result GetLockHandle(); diff --git a/src/core/hle/service/service.h b/src/core/hle/service/service.h index 9368a9f0f..3b256aa3e 100644 --- a/src/core/hle/service/service.h +++ b/src/core/hle/service/service.h @@ -17,7 +17,9 @@ namespace Service { -typedef s32 NativeUID; ///< Native handle for a service +typedef s32 NativeUID; ///< Native handle for a service + +static const int kCommandHeaderOffset = 0x80; ///< Offset into command buffer of header class Manager; @@ -26,6 +28,9 @@ class Interface { friend class Manager; public: + Interface() { + } + virtual ~Interface() { } @@ -49,7 +54,24 @@ public: * Called when svcSendSyncRequest is called, loads command buffer and executes comand * @return Return result of svcSendSyncRequest passed back to user app */ - virtual Syscall::Result Sync() = 0; + Syscall::Result Sync() { + u32* cmd_buff = (u32*)HLE::GetPointer(HLE::CMD_BUFFER_ADDR + kCommandHeaderOffset); + auto itr = m_functions.find(cmd_buff[0]); + + if (itr == m_functions.end()) { + ERROR_LOG(OSHLE, "Unknown/unimplemented function: port=%s, command=0x%08X!", + GetPortName().c_str(), cmd_buff[0]); + return -1; + } + if (itr->second.func == NULL) { + ERROR_LOG(OSHLE, "Unimplemented function: port=%s, name=%s!", + GetPortName().c_str(), itr->second.name.c_str()); + } + + itr->second.func(); + + return 0; // TODO: Implement return from actual function + } protected: /** @@ -64,6 +86,8 @@ protected: private: u32 m_uid; std::map m_functions; + + DISALLOW_COPY_AND_ASSIGN(Interface); }; /// Simple class to manage accessing services from ports and UID handles diff --git a/src/core/hle/service/srv.cpp b/src/core/hle/service/srv.cpp new file mode 100644 index 000000000..bb6c08b78 --- /dev/null +++ b/src/core/hle/service/srv.cpp @@ -0,0 +1,55 @@ +// Copyright 2014 Citra Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#include "core/hle/hle.h" +#include "core/hle/service/srv.h" +#include "core/hle/service/service.h" + + +namespace SRV { + +void Initialize() { + NOTICE_LOG(OSHLE, "SRV::Sync - Initialize"); +} + +void GetServiceHandle() { + Syscall::Result res = 0; + u32* cmd_buff = (u32*)HLE::GetPointer(HLE::CMD_BUFFER_ADDR + Service::kCommandHeaderOffset); + + const char* port_name = (const char*)&cmd_buff[1]; + Service::Interface* service = Service::g_manager->FetchFromPortName(port_name); + + NOTICE_LOG(OSHLE, "SRV::Sync - GetHandle - port: %s, handle: 0x%08X", port_name, + service->GetUID()); + + if (NULL != service) { + cmd_buff[3] = service->GetUID(); + } else { + ERROR_LOG(OSHLE, "Service %s does not exist", port_name); + res = -1; + } + cmd_buff[1] = res; + + //return res; +} + +const HLE::FunctionDef FunctionTable[] = { + {0x00010002, Initialize, "Initialize"}, + {0x00020000, NULL, "GetProcSemaphore"}, + {0x00030100, NULL, "RegisterService"}, + {0x000400C0, NULL, "UnregisterService"}, + {0x00050100, GetServiceHandle, "GetServiceHandle"}, +}; + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// Interface class + +Interface::Interface() { + Register(FunctionTable, ARRAY_SIZE(FunctionTable)); +} + +Interface::~Interface() { +} + +} // namespace diff --git a/src/core/hle/service/srv.h b/src/core/hle/service/srv.h new file mode 100644 index 000000000..b4c5a0c17 --- /dev/null +++ b/src/core/hle/service/srv.h @@ -0,0 +1,39 @@ +// Copyright 2014 Citra Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#include "core/hle/service/service.h" + +namespace SRV { + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// Interface to "SRV" service + +class Interface : public Service::Interface { + +public: + + Interface(); + + ~Interface(); + + /** + * Gets the string name used by CTROS for a service + * @return Port name of service + */ + std::string GetPortName() const { + return "srv:"; + } + + /** + * Called when svcSendSyncRequest is called, loads command buffer and executes comand + * @return Return result of svcSendSyncRequest passed back to user app + */ + Syscall::Result Sync(); + +private: + + DISALLOW_COPY_AND_ASSIGN(Interface); +}; + +} // namespace From acef5e0b17e85bd25a5994d83b22d0ba02f589ba Mon Sep 17 00:00:00 2001 From: bunnei Date: Tue, 15 Apr 2014 23:41:52 -0400 Subject: [PATCH 32/49] removed no longer used function header --- src/core/hle/service/apt.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/core/hle/service/apt.h b/src/core/hle/service/apt.h index 9f0245cc8..889b12711 100644 --- a/src/core/hle/service/apt.h +++ b/src/core/hle/service/apt.h @@ -34,8 +34,6 @@ public: private: - Syscall::Result GetLockHandle(); - DISALLOW_COPY_AND_ASSIGN(Interface); }; From 32c3462047d814eada8f3b80ee5ea2cd03936ae0 Mon Sep 17 00:00:00 2001 From: bunnei Date: Wed, 16 Apr 2014 00:03:41 -0400 Subject: [PATCH 33/49] - added stubbed out GSP::Gpu service interface - various cleanups/refactors to HLE services --- src/core/core.vcxproj | 2 ++ src/core/core.vcxproj.filters | 6 ++++ src/core/hle/service/apt.h | 2 +- src/core/hle/service/gsp.cpp | 56 ++++++++++++++++++++++++++++++++ src/core/hle/service/gsp.h | 34 +++++++++++++++++++ src/core/hle/service/service.cpp | 4 +++ src/core/hle/service/service.h | 10 +++--- src/core/hle/service/srv.cpp | 2 +- src/core/hle/service/srv.h | 2 +- 9 files changed, 111 insertions(+), 7 deletions(-) create mode 100644 src/core/hle/service/gsp.cpp create mode 100644 src/core/hle/service/gsp.h diff --git a/src/core/core.vcxproj b/src/core/core.vcxproj index da3cc7a26..931345441 100644 --- a/src/core/core.vcxproj +++ b/src/core/core.vcxproj @@ -154,6 +154,7 @@ + @@ -190,6 +191,7 @@ + diff --git a/src/core/core.vcxproj.filters b/src/core/core.vcxproj.filters index fa20ab686..e022785ad 100644 --- a/src/core/core.vcxproj.filters +++ b/src/core/core.vcxproj.filters @@ -96,6 +96,9 @@ hle\service + + hle\service + @@ -187,6 +190,9 @@ hle\service + + hle\service + diff --git a/src/core/hle/service/apt.h b/src/core/hle/service/apt.h index 889b12711..9345eabc3 100644 --- a/src/core/hle/service/apt.h +++ b/src/core/hle/service/apt.h @@ -25,7 +25,7 @@ public: ~Interface(); /** - * Gets the string port name used by CTROS for the APT service + * Gets the string port name used by CTROS for the service * @return Port name of service */ std::string GetPortName() const { diff --git a/src/core/hle/service/gsp.cpp b/src/core/hle/service/gsp.cpp new file mode 100644 index 000000000..6dfd76de3 --- /dev/null +++ b/src/core/hle/service/gsp.cpp @@ -0,0 +1,56 @@ +// Copyright 2014 Citra Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + + +#include "common/log.h" + +#include "core/hle/hle.h" +#include "core/hle/service/gsp.h" + +namespace GSP_GPU { + +const HLE::FunctionDef FunctionTable[] = { + {0x00010082, NULL, "WriteHWRegs"}, + {0x00020084, NULL, "WriteHWRegsWithMask"}, + {0x00030082, NULL, "WriteHWRegRepeat"}, + {0x00040080, NULL, "ReadHWRegs"}, + {0x00050200, NULL, "SetBufferSwap"}, + {0x00060082, NULL, "SetCommandList"}, + {0x000700C2, NULL, "RequestDma"}, + {0x00080082, NULL, "FlushDataCache"}, + {0x00090082, NULL, "InvalidateDataCache"}, + {0x000A0044, NULL, "RegisterInterruptEvents"}, + {0x000B0040, NULL, "SetLcdForceBlack"}, + {0x000C0000, NULL, "TriggerCmdReqQueue"}, + {0x000D0140, NULL, "SetDisplayTransfer"}, + {0x000E0180, NULL, "SetTextureCopy"}, + {0x000F0200, NULL, "SetMemoryFill"}, + {0x00100040, NULL, "SetAxiConfigQoSMode"}, + {0x00110040, NULL, "SetPerfLogMode"}, + {0x00120000, NULL, "GetPerfLog"}, + {0x00130042, NULL, "RegisterInterruptRelayQueue"}, + {0x00140000, NULL, "UnregisterInterruptRelayQueue"}, + {0x00150002, NULL, "TryAcquireRight"}, + {0x00160042, NULL, "AcquireRight"}, + {0x00170000, NULL, "ReleaseRight"}, + {0x00180000, NULL, "ImportDisplayCaptureInfo"}, + {0x00190000, NULL, "SaveVramSysArea"}, + {0x001A0000, NULL, "RestoreVramSysArea"}, + {0x001B0000, NULL, "ResetGpuCore"}, + {0x001C0040, NULL, "SetLedForceOff"}, + {0x001D0040, NULL, "SetTestCommand"}, + {0x001E0080, NULL, "SetInternalPriorities"}, +}; + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// Interface class + +Interface::Interface() { + Register(FunctionTable, ARRAY_SIZE(FunctionTable)); +} + +Interface::~Interface() { +} + +} // namespace diff --git a/src/core/hle/service/gsp.h b/src/core/hle/service/gsp.h new file mode 100644 index 000000000..0a9d452f6 --- /dev/null +++ b/src/core/hle/service/gsp.h @@ -0,0 +1,34 @@ +// Copyright 2014 Citra Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#pragma once + +#include "core/hle/service/service.h" + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// Namespace Service + +namespace GSP_GPU { + +class Interface : public Service::Interface { +public: + + Interface(); + + ~Interface(); + + /** + * Gets the string port name used by CTROS for the service + * @return Port name of service + */ + std::string GetPortName() const { + return "gsp::Gpu"; + } + +private: + + DISALLOW_COPY_AND_ASSIGN(Interface); +}; + +} // namespace diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp index 81a34ed06..f612ff830 100644 --- a/src/core/hle/service/service.cpp +++ b/src/core/hle/service/service.cpp @@ -9,6 +9,7 @@ #include "core/hle/hle.h" #include "core/hle/service/service.h" #include "core/hle/service/apt.h" +#include "core/hle/service/gsp.h" #include "core/hle/service/srv.h" namespace Service { @@ -73,8 +74,11 @@ Interface* Manager::FetchFromPortName(std::string port_name) { /// Initialize ServiceManager void Init() { g_manager = new Manager; + g_manager->AddService(new SRV::Interface); g_manager->AddService(new APT_U::Interface); + g_manager->AddService(new GSP_GPU::Interface); + NOTICE_LOG(HLE, "Services initialized OK"); } diff --git a/src/core/hle/service/service.h b/src/core/hle/service/service.h index 3b256aa3e..9cbf8b6fa 100644 --- a/src/core/hle/service/service.h +++ b/src/core/hle/service/service.h @@ -19,7 +19,8 @@ namespace Service { typedef s32 NativeUID; ///< Native handle for a service -static const int kCommandHeaderOffset = 0x80; ///< Offset into command buffer of header +static const int kMaxPortSize = 0x08; ///< Maximum size of a port name (8 characters) +static const int kCommandHeaderOffset = 0x80; ///< Offset into command buffer of header class Manager; @@ -59,14 +60,15 @@ public: auto itr = m_functions.find(cmd_buff[0]); if (itr == m_functions.end()) { - ERROR_LOG(OSHLE, "Unknown/unimplemented function: port=%s, command=0x%08X!", + ERROR_LOG(OSHLE, "Unknown/unimplemented function: port = %s, command = 0x%08X!", GetPortName().c_str(), cmd_buff[0]); return -1; } if (itr->second.func == NULL) { - ERROR_LOG(OSHLE, "Unimplemented function: port=%s, name=%s!", + ERROR_LOG(OSHLE, "Unimplemented function: port = %s, name = %s!", GetPortName().c_str(), itr->second.name.c_str()); - } + return -1; + } itr->second.func(); diff --git a/src/core/hle/service/srv.cpp b/src/core/hle/service/srv.cpp index bb6c08b78..ad7448461 100644 --- a/src/core/hle/service/srv.cpp +++ b/src/core/hle/service/srv.cpp @@ -17,7 +17,7 @@ void GetServiceHandle() { Syscall::Result res = 0; u32* cmd_buff = (u32*)HLE::GetPointer(HLE::CMD_BUFFER_ADDR + Service::kCommandHeaderOffset); - const char* port_name = (const char*)&cmd_buff[1]; + std::string port_name = std::string((const char*)&cmd_buff[1], 0, Service::kMaxPortSize); Service::Interface* service = Service::g_manager->FetchFromPortName(port_name); NOTICE_LOG(OSHLE, "SRV::Sync - GetHandle - port: %s, handle: 0x%08X", port_name, diff --git a/src/core/hle/service/srv.h b/src/core/hle/service/srv.h index b4c5a0c17..a1d26a34d 100644 --- a/src/core/hle/service/srv.h +++ b/src/core/hle/service/srv.h @@ -18,7 +18,7 @@ public: ~Interface(); /** - * Gets the string name used by CTROS for a service + * Gets the string name used by CTROS for the service * @return Port name of service */ std::string GetPortName() const { From de3dcd38f6572da88a67e625e6aa98c2a2f786d7 Mon Sep 17 00:00:00 2001 From: bunnei Date: Wed, 16 Apr 2014 20:41:33 -0400 Subject: [PATCH 34/49] - fixed tabs in function_wrappers.h - fixed log message wording in hle.cpp - added syscall stubs for CloseHandle and WaitSynchronization1 --- src/core/hle/function_wrappers.h | 541 ++++++++++++++++--------------- src/core/hle/hle.cpp | 2 +- src/core/hle/hle.h | 1 + src/core/hle/syscall.cpp | 264 ++++++++------- 4 files changed, 413 insertions(+), 395 deletions(-) diff --git a/src/core/hle/function_wrappers.h b/src/core/hle/function_wrappers.h index 22588d95d..7d9389769 100644 --- a/src/core/hle/function_wrappers.h +++ b/src/core/hle/function_wrappers.h @@ -25,659 +25,659 @@ //32bit wrappers template void WrapV_V() { - func(); + func(); } template void WrapU_V() { - RETURN(func()); + RETURN(func()); } template void WrapI_VC() { - u32 retval = func(Memory::GetPointer(PARAM(0)), Memory::GetCharPointer(PARAM(1))); - RETURN(retval); + u32 retval = func(Memory::GetPointer(PARAM(0)), Memory::GetCharPointer(PARAM(1))); + RETURN(retval); } template void WrapU_IVI() { - u32 retval = func(PARAM(0), Memory::GetPointer(PARAM(1)), PARAM(2)); - RETURN(retval); + u32 retval = func(PARAM(0), Memory::GetPointer(PARAM(1)), PARAM(2)); + RETURN(retval); } template void WrapI_CIIU() { - u32 retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2), PARAM(3)); - RETURN(retval); + u32 retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2), PARAM(3)); + RETURN(retval); } template void WrapI_ICUVVUI() { - u32 retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1)), PARAM(2), Memory::GetPointer(PARAM(3)),Memory::GetPointer(PARAM(4)), PARAM(5), PARAM(6) ); - RETURN(retval); + u32 retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1)), PARAM(2), Memory::GetPointer(PARAM(3)),Memory::GetPointer(PARAM(4)), PARAM(5), PARAM(6) ); + RETURN(retval); } // Hm, do so many params get passed in registers? template void WrapI_CICIIIII() { - u32 retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), Memory::GetCharPointer(PARAM(2)), - PARAM(3), PARAM(4), PARAM(5), PARAM(6), PARAM(7)); - RETURN(retval); + u32 retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), Memory::GetCharPointer(PARAM(2)), + PARAM(3), PARAM(4), PARAM(5), PARAM(6), PARAM(7)); + RETURN(retval); } // Hm, do so many params get passed in registers? template void WrapI_CIIIIII() { - u32 retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2), - PARAM(3), PARAM(4), PARAM(5), PARAM(6)); - RETURN(retval); + u32 retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2), + PARAM(3), PARAM(4), PARAM(5), PARAM(6)); + RETURN(retval); } // Hm, do so many params get passed in registers? template void WrapI_IIIIIIU() { - u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4), PARAM(5), PARAM(6)); - RETURN(retval); + u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4), PARAM(5), PARAM(6)); + RETURN(retval); } // Hm, do so many params get passed in registers? template void WrapI_IIIIIIIIU() { - u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4), PARAM(5), PARAM(6), PARAM(7), PARAM(8)); - RETURN(retval); + u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4), PARAM(5), PARAM(6), PARAM(7), PARAM(8)); + RETURN(retval); } template void WrapU_IV() { - u32 retval = func(PARAM(0), Memory::GetPointer(PARAM(1))); - RETURN(retval); + u32 retval = func(PARAM(0), Memory::GetPointer(PARAM(1))); + RETURN(retval); } template void WrapF_V() { - RETURNF(func()); + RETURNF(func()); } // TODO: Not sure about the floating point parameter passing template void WrapF_IFU() { - RETURNF(func(PARAM(0), PARAMF(0), PARAM(1))); + RETURNF(func(PARAM(0), PARAMF(0), PARAM(1))); } template void WrapU_U() { - u32 retval = func(PARAM(0)); - RETURN(retval); + u32 retval = func(PARAM(0)); + RETURN(retval); } template void WrapU_UI() { - u32 retval = func(PARAM(0), PARAM(1)); - RETURN(retval); + u32 retval = func(PARAM(0), PARAM(1)); + RETURN(retval); } template void WrapI_U() { - int retval = func(PARAM(0)); - RETURN(retval); + int retval = func(PARAM(0)); + RETURN(retval); } template void WrapI_UI() { - int retval = func(PARAM(0), PARAM(1)); - RETURN(retval); + int retval = func(PARAM(0), PARAM(1)); + RETURN(retval); } template void WrapI_UIIU() { - int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); - RETURN(retval); + int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); + RETURN(retval); } template void WrapU_IUI() { - u32 retval = func(PARAM(0), PARAM(1), PARAM(2)); - RETURN(retval); + u32 retval = func(PARAM(0), PARAM(1), PARAM(2)); + RETURN(retval); } template void WrapI_UU() { - int retval = func(PARAM(0), PARAM(1)); - RETURN(retval); + int retval = func(PARAM(0), PARAM(1)); + RETURN(retval); } template void WrapI_UFF() { - // Not sure about the float arguments. - int retval = func(PARAM(0), PARAMF(0), PARAMF(1)); - RETURN(retval); + // Not sure about the float arguments. + int retval = func(PARAM(0), PARAMF(0), PARAMF(1)); + RETURN(retval); } template void WrapI_UUU() { - int retval = func(PARAM(0), PARAM(1), PARAM(2)); - RETURN(retval); + int retval = func(PARAM(0), PARAM(1), PARAM(2)); + RETURN(retval); } template void WrapI_UUUI() { - int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); - RETURN(retval); + int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); + RETURN(retval); } template void WrapI_UUUIIII() { - int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4), PARAM(5), PARAM(6)); - RETURN(retval); + int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4), PARAM(5), PARAM(6)); + RETURN(retval); } template void WrapI_UUUU() { - int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); - RETURN(retval); + int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); + RETURN(retval); } template void WrapI_UUUUU() { - int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)); - RETURN(retval); + int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)); + RETURN(retval); } template void WrapI_V() { - int retval = func(); - RETURN(retval); + int retval = func(); + RETURN(retval); } template void WrapU_I() { - u32 retval = func(PARAM(0)); - RETURN(retval); + u32 retval = func(PARAM(0)); + RETURN(retval); } template void WrapU_IIU() { - u32 retval = func(PARAM(0), PARAM(1), PARAM(2)); - RETURN(retval); + u32 retval = func(PARAM(0), PARAM(1), PARAM(2)); + RETURN(retval); } template void WrapI_I() { - int retval = func(PARAM(0)); - RETURN(retval); + int retval = func(PARAM(0)); + RETURN(retval); } template void WrapV_U() { - func(PARAM(0)); + func(PARAM(0)); } template void WrapV_I() { - func(PARAM(0)); + func(PARAM(0)); } template void WrapV_UU() { - func(PARAM(0), PARAM(1)); + func(PARAM(0), PARAM(1)); } template void WrapV_II() { - func(PARAM(0), PARAM(1)); + func(PARAM(0), PARAM(1)); } template void WrapV_UC() { - func(PARAM(0), Memory::GetCharPointer(PARAM(1))); + func(PARAM(0), Memory::GetCharPointer(PARAM(1))); } template void WrapI_UC() { - int retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1))); - RETURN(retval); + int retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1))); + RETURN(retval); } template void WrapI_UCI() { - int retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1)), PARAM(2)); - RETURN(retval); + int retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1)), PARAM(2)); + RETURN(retval); } template void WrapU_UIIIII() { - u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4), PARAM(5)); - RETURN(retval); + u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4), PARAM(5)); + RETURN(retval); } template void WrapU_UIIIU() { - u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)); - RETURN(retval); + u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)); + RETURN(retval); } template void WrapU_UIIIIII() { - u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4), PARAM(5), PARAM(6)); - RETURN(retval); + u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4), PARAM(5), PARAM(6)); + RETURN(retval); } template void WrapU_UU() { - u32 retval = func(PARAM(0), PARAM(1)); - RETURN(retval); + u32 retval = func(PARAM(0), PARAM(1)); + RETURN(retval); } template void WrapU_UUI() { - u32 retval = func(PARAM(0), PARAM(1), PARAM(2)); - RETURN(retval); + u32 retval = func(PARAM(0), PARAM(1), PARAM(2)); + RETURN(retval); } template void WrapU_UUII() { - u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); - RETURN(retval); + u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); + RETURN(retval); } template void WrapU_CUUU() { - u32 retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2), PARAM(3)); - RETURN(retval); + u32 retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2), PARAM(3)); + RETURN(retval); } template void WrapV_UIUII() { - func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)); + func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)); } template void WrapU_UIUII() { - u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)); - RETURN(retval); + u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)); + RETURN(retval); } template void WrapI_UIUII() { - int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)); - RETURN(retval); + int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)); + RETURN(retval); } template void WrapU_UIUI() { - u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); - RETURN(retval); + u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); + RETURN(retval); } template void WrapI_UIUI() { - u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); - RETURN(retval); + u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); + RETURN(retval); } template void WrapU_UIU() { - u32 retval = func(PARAM(0), PARAM(1), PARAM(2)); - RETURN(retval); + u32 retval = func(PARAM(0), PARAM(1), PARAM(2)); + RETURN(retval); } template void WrapU_UIUU() { - u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); - RETURN(retval); + u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); + RETURN(retval); } template void WrapU_UII() { - u32 retval = func(PARAM(0), PARAM(1), PARAM(2)); - RETURN(retval); + u32 retval = func(PARAM(0), PARAM(1), PARAM(2)); + RETURN(retval); } template void WrapU_UIIU() { - u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); - RETURN(retval); + u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); + RETURN(retval); } template void WrapI_UIIUU() { - u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)); - RETURN(retval); + u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)); + RETURN(retval); } template void WrapI_UUII() { - int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); - RETURN(retval); + int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); + RETURN(retval); } template void WrapI_UUIII() { - int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)); - RETURN(retval); + int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)); + RETURN(retval); } template void WrapV_UIII() { - func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); + func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); } template void WrapV_UIIIII() { - func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4), PARAM(5)); + func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4), PARAM(5)); } template void WrapV_UII() { - func(PARAM(0), PARAM(1), PARAM(2)); + func(PARAM(0), PARAM(1), PARAM(2)); } template void WrapU_IU() { - int retval = func(PARAM(0), PARAM(1)); - RETURN(retval); + int retval = func(PARAM(0), PARAM(1)); + RETURN(retval); } template void WrapI_IU() { - int retval = func(PARAM(0), PARAM(1)); - RETURN(retval); + int retval = func(PARAM(0), PARAM(1)); + RETURN(retval); } template void WrapI_UUI() { - int retval = func(PARAM(0), PARAM(1), PARAM(2)); - RETURN(retval); + int retval = func(PARAM(0), PARAM(1), PARAM(2)); + RETURN(retval); } template void WrapI_UUIU() { - int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); - RETURN(retval); + int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); + RETURN(retval); } template void WrapI_II() { - int retval = func(PARAM(0), PARAM(1)); - RETURN(retval); + int retval = func(PARAM(0), PARAM(1)); + RETURN(retval); } template void WrapI_III() { - int retval = func(PARAM(0), PARAM(1), PARAM(2)); - RETURN(retval); + int retval = func(PARAM(0), PARAM(1), PARAM(2)); + RETURN(retval); } template void WrapI_IUI() { - int retval = func(PARAM(0), PARAM(1), PARAM(2)); - RETURN(retval); + int retval = func(PARAM(0), PARAM(1), PARAM(2)); + RETURN(retval); } template void WrapI_IIII() { - int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); - RETURN(retval); + int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); + RETURN(retval); } template void WrapI_UIII() { - int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); - RETURN(retval); + int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); + RETURN(retval); } template void WrapI_IIIUI() { - int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)); - RETURN(retval); + int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)); + RETURN(retval); } template void WrapI_IUUII() { - int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)); - RETURN(retval); + int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)); + RETURN(retval); } template void WrapI_ICIUU() { - int retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1)), PARAM(2), PARAM(3), PARAM(4)); - RETURN(retval); + int retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1)), PARAM(2), PARAM(3), PARAM(4)); + RETURN(retval); } template void WrapI_IIU() { - int retval = func(PARAM(0), PARAM(1), PARAM(2)); - RETURN(retval); + int retval = func(PARAM(0), PARAM(1), PARAM(2)); + RETURN(retval); } template void WrapV_IU() { - func(PARAM(0), PARAM(1)); + func(PARAM(0), PARAM(1)); } template void WrapV_UI() { - func(PARAM(0), PARAM(1)); + func(PARAM(0), PARAM(1)); } template void WrapU_C() { - u32 retval = func(Memory::GetCharPointer(PARAM(0))); - RETURN(retval); + u32 retval = func(Memory::GetCharPointer(PARAM(0))); + RETURN(retval); } template void WrapU_CCCU() { - u32 retval = func(Memory::GetCharPointer(PARAM(0)), - Memory::GetCharPointer(PARAM(1)), Memory::GetCharPointer(PARAM(2)), - PARAM(3)); - RETURN(retval); + u32 retval = func(Memory::GetCharPointer(PARAM(0)), + Memory::GetCharPointer(PARAM(1)), Memory::GetCharPointer(PARAM(2)), + PARAM(3)); + RETURN(retval); } template void WrapI_C() { - int retval = func(Memory::GetCharPointer(PARAM(0))); - RETURN(retval); + int retval = func(Memory::GetCharPointer(PARAM(0))); + RETURN(retval); } template void WrapI_CU() { - int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1)); - RETURN(retval); + int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1)); + RETURN(retval); } template void WrapI_CUI() { - int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2)); - RETURN(retval); + int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2)); + RETURN(retval); } template void WrapI_ICIU() { - int retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1)), PARAM(2), PARAM(3)); - RETURN(retval); + int retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1)), PARAM(2), PARAM(3)); + RETURN(retval); } template void WrapI_CIU() { - int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2)); - RETURN(retval); + int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2)); + RETURN(retval); } template void WrapI_CUU() { - int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2)); - RETURN(retval); + int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2)); + RETURN(retval); } template void WrapI_CUUU() { - int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2), - PARAM(3)); - RETURN(retval); + int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2), + PARAM(3)); + RETURN(retval); } template void WrapI_CCII() { - int retval = func(Memory::GetCharPointer(PARAM(0)), Memory::GetCharPointer(PARAM(1)), PARAM(2), PARAM(3)); - RETURN(retval); + int retval = func(Memory::GetCharPointer(PARAM(0)), Memory::GetCharPointer(PARAM(1)), PARAM(2), PARAM(3)); + RETURN(retval); } template void WrapI_CUUIUU() { - int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2), - PARAM(3), PARAM(4), PARAM(5)); - RETURN(retval); + int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2), + PARAM(3), PARAM(4), PARAM(5)); + RETURN(retval); } template void WrapI_CIIUII() { - int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2), - PARAM(3), PARAM(4), PARAM(5)); - RETURN(retval); + int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2), + PARAM(3), PARAM(4), PARAM(5)); + RETURN(retval); } template void WrapI_CIUUU() { - int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2), - PARAM(3), PARAM(4)); - RETURN(retval); + int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2), + PARAM(3), PARAM(4)); + RETURN(retval); } template void WrapI_CUUUUU() { - int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2), - PARAM(3), PARAM(4), PARAM(5)); - RETURN(retval); + int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2), + PARAM(3), PARAM(4), PARAM(5)); + RETURN(retval); } template void WrapU_CU() { - u32 retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1)); - RETURN((u32) retval); + u32 retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1)); + RETURN((u32) retval); } template void WrapU_UC() { - u32 retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1))); - RETURN(retval); + u32 retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1))); + RETURN(retval); } template void WrapU_CUU() { - u32 retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2)); - RETURN((u32) retval); + u32 retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2)); + RETURN((u32) retval); } template void WrapU_III() { - u32 retval = func(PARAM(0), PARAM(1), PARAM(2)); - RETURN(retval); + u32 retval = func(PARAM(0), PARAM(1), PARAM(2)); + RETURN(retval); } template void WrapU_II() { - u32 retval = func(PARAM(0), PARAM(1)); - RETURN(retval); + u32 retval = func(PARAM(0), PARAM(1)); + RETURN(retval); } template void WrapU_IIII() { - u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); - RETURN(retval); + u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); + RETURN(retval); } template void WrapU_IUU() { - u32 retval = func(PARAM(0), PARAM(1), PARAM(2)); - RETURN(retval); + u32 retval = func(PARAM(0), PARAM(1), PARAM(2)); + RETURN(retval); } template void WrapU_IUUU() { - u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); - RETURN(retval); + u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); + RETURN(retval); } template void WrapU_IUUUU() { - u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)); - RETURN(retval); + u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)); + RETURN(retval); } template void WrapU_UUU() { - u32 retval = func(PARAM(0), PARAM(1), PARAM(2)); - RETURN(retval); + u32 retval = func(PARAM(0), PARAM(1), PARAM(2)); + RETURN(retval); } template void WrapV_IUU() { - func(PARAM(0), PARAM(1), PARAM(2)); + func(PARAM(0), PARAM(1), PARAM(2)); } template void WrapV_IIU() { - func(PARAM(0), PARAM(1), PARAM(2)); + func(PARAM(0), PARAM(1), PARAM(2)); } template void WrapV_UIU() { - func(PARAM(0), PARAM(1), PARAM(2)); + func(PARAM(0), PARAM(1), PARAM(2)); } template void WrapI_UIU() { - int retval = func(PARAM(0), PARAM(1), PARAM(2)); - RETURN(retval); + int retval = func(PARAM(0), PARAM(1), PARAM(2)); + RETURN(retval); } template void WrapV_IUUUU() { - func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)); + func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)); } template void WrapV_UUU() { - func(PARAM(0), PARAM(1), PARAM(2)); + func(PARAM(0), PARAM(1), PARAM(2)); } template void WrapV_UUUU() { - func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); + func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); } template void WrapV_CUIU() { - func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2), PARAM(3)); + func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2), PARAM(3)); } template void WrapI_CUIU() { - int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2), PARAM(3)); - RETURN(retval); + int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2), PARAM(3)); + RETURN(retval); } template void WrapV_UCUIU() { - func(PARAM(0), Memory::GetCharPointer(PARAM(1)), PARAM(2), PARAM(3), - PARAM(4)); + func(PARAM(0), Memory::GetCharPointer(PARAM(1)), PARAM(2), PARAM(3), + PARAM(4)); } template void WrapI_UCUIU() { - int retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1)), PARAM(2), - PARAM(3), PARAM(4)); - RETURN(retval); + int retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1)), PARAM(2), + PARAM(3), PARAM(4)); + RETURN(retval); } template void WrapV_CUIIU() { - func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2), PARAM(3), - PARAM(4)); + func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2), PARAM(3), + PARAM(4)); } template void WrapI_CUIIU() { - int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2), - PARAM(3), PARAM(4)); - RETURN(retval); + int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2), + PARAM(3), PARAM(4)); + RETURN(retval); } template void WrapU_UUUU() { - u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); - RETURN(retval); + u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); + RETURN(retval); } template void WrapU_UCUU() { - u32 retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1)), PARAM(2), PARAM(3)); - RETURN(retval); + u32 retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1)), PARAM(2), PARAM(3)); + RETURN(retval); } template void WrapU_UUUI() { - u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); - RETURN(retval); + u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); + RETURN(retval); } template void WrapU_UUUIU() { - u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)); - RETURN(retval); + u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)); + RETURN(retval); } template void WrapU_UUUIUI() { - u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4), PARAM(5)); - RETURN(retval); + u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4), PARAM(5)); + RETURN(retval); } template void WrapU_UUIU() { - u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); - RETURN(retval); + u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); + RETURN(retval); } template void WrapU_UIII() { - u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); - RETURN(retval); + u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); + RETURN(retval); } template void WrapI_IUUUU() { - int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)); - RETURN(retval); + int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)); + RETURN(retval); } template void WrapI_IUUUUU() { - int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4), PARAM(5)); - RETURN(retval); + int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4), PARAM(5)); + RETURN(retval); } template void WrapI_IUII() { - int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); - RETURN(retval); + int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); + RETURN(retval); } template void WrapU_UUUUU() { - u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)); - RETURN(retval); + u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)); + RETURN(retval); } template void WrapV_UUUUU() { - func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)); + func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)); } template void WrapU_CC() { - int retval = func(Memory::GetCharPointer(PARAM(0)), - Memory::GetCharPointer(PARAM(1))); - RETURN(retval); + int retval = func(Memory::GetCharPointer(PARAM(0)), + Memory::GetCharPointer(PARAM(1))); + RETURN(retval); } template void WrapV_CI() { - func(Memory::GetCharPointer(PARAM(0)), PARAM(1)); + func(Memory::GetCharPointer(PARAM(0)), PARAM(1)); } template void WrapU_CI() { - int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1)); - RETURN(retval); + int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1)); + RETURN(retval); } template void WrapU_CII() { - int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2)); - RETURN(retval); + int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2)); + RETURN(retval); } template void WrapU_CIUIU() { - int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2), - PARAM(3), PARAM(4)); - RETURN(retval); + int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2), + PARAM(3), PARAM(4)); + RETURN(retval); } template void WrapU_CIUIUI() { - u32 retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2), - PARAM(3), PARAM(4), PARAM(5)); - RETURN(retval); + u32 retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2), + PARAM(3), PARAM(4), PARAM(5)); + RETURN(retval); } template void WrapU_UUUUUU() { - u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4), - PARAM(5)); - RETURN(retval); + u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4), + PARAM(5)); + RETURN(retval); } template void WrapI_IUUU() { - int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); - RETURN(retval); + int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); + RETURN(retval); } template void WrapI_IUU() { - int retval = func(PARAM(0), PARAM(1), PARAM(2)); - RETURN(retval); + int retval = func(PARAM(0), PARAM(1), PARAM(2)); + RETURN(retval); } template void WrapU_UUUUUUU() { @@ -686,33 +686,33 @@ template void WrapU_UUUUUUU() { } template void WrapI_UIUU() { - u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); - RETURN(retval); + u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); + RETURN(retval); } template void WrapI_IC() { - int retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1))); - RETURN(retval); + int retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1))); + RETURN(retval); } template void WrapI_ICCUI() { - int retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1)), Memory::GetCharPointer(PARAM(2)), PARAM(3), PARAM(4)); - RETURN(retval); + int retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1)), Memory::GetCharPointer(PARAM(2)), PARAM(3), PARAM(4)); + RETURN(retval); } template void WrapI_ICCI() { - int retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1)), Memory::GetCharPointer(PARAM(2)), PARAM(3)); - RETURN(retval); + int retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1)), Memory::GetCharPointer(PARAM(2)), PARAM(3)); + RETURN(retval); } template void WrapI_CII() { - int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2)); - RETURN(retval); + int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2)); + RETURN(retval); } template void WrapI_ICI() { - int retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1)), PARAM(2)); - RETURN(retval); + int retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1)), PARAM(2)); + RETURN(retval); } template void WrapI_IVVVVUI(){ @@ -724,3 +724,8 @@ template void WrapI_ICU u32 retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1)), PARAM(2), Memory::GetPointer(PARAM(3)), PARAM(4), PARAM(5), PARAM(6)); RETURN(retval); } + +template void WrapI_US64() { + int retval = func(PARAM(0), PARAM64(2)); + RETURN(retval); +} diff --git a/src/core/hle/hle.cpp b/src/core/hle/hle.cpp index c173b82de..5672a659f 100644 --- a/src/core/hle/hle.cpp +++ b/src/core/hle/hle.cpp @@ -76,7 +76,7 @@ void CallSyscall(u32 opcode) { if (info->func) { info->func(); } else { - ERROR_LOG(HLE, "Unimplemented HLE function %s", info->name); + ERROR_LOG(HLE, "Unimplemented SysCall function %s(..)", info->name.c_str()); } } diff --git a/src/core/hle/hle.h b/src/core/hle/hle.h index d02948be3..628a1da89 100644 --- a/src/core/hle/hle.h +++ b/src/core/hle/hle.h @@ -10,6 +10,7 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// #define PARAM(n) Core::g_app_core->GetReg(n) +#define PARAM64(n) (Core::g_app_core->GetReg(n) | ((u64)Core::g_app_core->GetReg(n + 1) << 32)) #define RETURN(n) Core::g_app_core->SetReg(0, n) //////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/core/hle/syscall.cpp b/src/core/hle/syscall.cpp index 8225f168b..c5b887795 100644 --- a/src/core/hle/syscall.cpp +++ b/src/core/hle/syscall.cpp @@ -27,133 +27,145 @@ Result SendSyncRequest(Handle session) { return 0; } +/// Close a handle +Result CloseHandle(Handle handle) { + // ImplementMe + return 0; +} + +/// Wait for a handle to synchronize, timeout after the specified nanoseconds +Result WaitSynchronization1(Handle handle, s64 nanoseconds) { + // ImplementMe + return 0; +} + const HLE::FunctionDef Syscall_Table[] = { - {0x00, NULL, "Unknown"}, - {0x01, NULL, "ControlMemory"}, - {0x02, NULL, "QueryMemory"}, - {0x03, NULL, "ExitProcess"}, - {0x04, NULL, "GetProcessAffinityMask"}, - {0x05, NULL, "SetProcessAffinityMask"}, - {0x06, NULL, "GetProcessIdealProcessor"}, - {0x07, NULL, "SetProcessIdealProcessor"}, - {0x08, NULL, "CreateThread"}, - {0x09, NULL, "ExitThread"}, - {0x0A, NULL, "SleepThread"}, - {0x0B, NULL, "GetThreadPriority"}, - {0x0C, NULL, "SetThreadPriority"}, - {0x0D, NULL, "GetThreadAffinityMask"}, - {0x0E, NULL, "SetThreadAffinityMask"}, - {0x0F, NULL, "GetThreadIdealProcessor"}, - {0x10, NULL, "SetThreadIdealProcessor"}, - {0x11, NULL, "GetCurrentProcessorNumber"}, - {0x12, NULL, "Run"}, - {0x13, NULL, "CreateMutex"}, - {0x14, NULL, "ReleaseMutex"}, - {0x15, NULL, "CreateSemaphore"}, - {0x16, NULL, "ReleaseSemaphore"}, - {0x17, NULL, "CreateEvent"}, - {0x18, NULL, "SignalEvent"}, - {0x19, NULL, "ClearEvent"}, - {0x1A, NULL, "CreateTimer"}, - {0x1B, NULL, "SetTimer"}, - {0x1C, NULL, "CancelTimer"}, - {0x1D, NULL, "ClearTimer"}, - {0x1E, NULL, "CreateMemoryBlock"}, - {0x1F, NULL, "MapMemoryBlock"}, - {0x20, NULL, "UnmapMemoryBlock"}, - {0x21, NULL, "CreateAddressArbiter"}, - {0x22, NULL, "ArbitrateAddress"}, - {0x23, NULL, "CloseHandle"}, - {0x24, NULL, "WaitSynchronization1"}, - {0x25, NULL, "WaitSynchronizationN"}, - {0x26, NULL, "SignalAndWait"}, - {0x27, NULL, "DuplicateHandle"}, - {0x28, NULL, "GetSystemTick"}, - {0x29, NULL, "GetHandleInfo"}, - {0x2A, NULL, "GetSystemInfo"}, - {0x2B, NULL, "GetProcessInfo"}, - {0x2C, NULL, "GetThreadInfo"}, - {0x2D, WrapI_VC, "ConnectToPort"}, - {0x2E, NULL, "SendSyncRequest1"}, - {0x2F, NULL, "SendSyncRequest2"}, - {0x30, NULL, "SendSyncRequest3"}, - {0x31, NULL, "SendSyncRequest4"}, - {0x32, WrapI_U, "SendSyncRequest"}, - {0x33, NULL, "OpenProcess"}, - {0x34, NULL, "OpenThread"}, - {0x35, NULL, "GetProcessId"}, - {0x36, NULL, "GetProcessIdOfThread"}, - {0x37, NULL, "GetThreadId"}, - {0x38, NULL, "GetResourceLimit"}, - {0x39, NULL, "GetResourceLimitLimitValues"}, - {0x3A, NULL, "GetResourceLimitCurrentValues"}, - {0x3B, NULL, "GetThreadContext"}, - {0x3C, NULL, "Break"}, - {0x3D, NULL, "OutputDebugString"}, - {0x3E, NULL, "ControlPerformanceCounter"}, - {0x3F, NULL, "Unknown"}, - {0x40, NULL, "Unknown"}, - {0x41, NULL, "Unknown"}, - {0x42, NULL, "Unknown"}, - {0x43, NULL, "Unknown"}, - {0x44, NULL, "Unknown"}, - {0x45, NULL, "Unknown"}, - {0x46, NULL, "Unknown"}, - {0x47, NULL, "CreatePort"}, - {0x48, NULL, "CreateSessionToPort"}, - {0x49, NULL, "CreateSession"}, - {0x4A, NULL, "AcceptSession"}, - {0x4B, NULL, "ReplyAndReceive1"}, - {0x4C, NULL, "ReplyAndReceive2"}, - {0x4D, NULL, "ReplyAndReceive3"}, - {0x4E, NULL, "ReplyAndReceive4"}, - {0x4F, NULL, "ReplyAndReceive"}, - {0x50, NULL, "BindInterrupt"}, - {0x51, NULL, "UnbindInterrupt"}, - {0x52, NULL, "InvalidateProcessDataCache"}, - {0x53, NULL, "StoreProcessDataCache"}, - {0x54, NULL, "FlushProcessDataCache"}, - {0x55, NULL, "StartInterProcessDma"}, - {0x56, NULL, "StopDma"}, - {0x57, NULL, "GetDmaState"}, - {0x58, NULL, "RestartDma"}, - {0x59, NULL, "Unknown"}, - {0x5A, NULL, "Unknown"}, - {0x5B, NULL, "Unknown"}, - {0x5C, NULL, "Unknown"}, - {0x5D, NULL, "Unknown"}, - {0x5E, NULL, "Unknown"}, - {0x5F, NULL, "Unknown"}, - {0x60, NULL, "DebugActiveProcess"}, - {0x61, NULL, "BreakDebugProcess"}, - {0x62, NULL, "TerminateDebugProcess"}, - {0x63, NULL, "GetProcessDebugEvent"}, - {0x64, NULL, "ContinueDebugEvent"}, - {0x65, NULL, "GetProcessList"}, - {0x66, NULL, "GetThreadList"}, - {0x67, NULL, "GetDebugThreadContext"}, - {0x68, NULL, "SetDebugThreadContext"}, - {0x69, NULL, "QueryDebugProcessMemory"}, - {0x6A, NULL, "ReadProcessMemory"}, - {0x6B, NULL, "WriteProcessMemory"}, - {0x6C, NULL, "SetHardwareBreakPoint"}, - {0x6D, NULL, "GetDebugThreadParam"}, - {0x6E, NULL, "Unknown"}, - {0x6F, NULL, "Unknown"}, - {0x70, NULL, "ControlProcessMemory"}, - {0x71, NULL, "MapProcessMemory"}, - {0x72, NULL, "UnmapProcessMemory"}, - {0x73, NULL, "Unknown"}, - {0x74, NULL, "Unknown"}, - {0x75, NULL, "Unknown"}, - {0x76, NULL, "TerminateProcess"}, - {0x77, NULL, "Unknown"}, - {0x78, NULL, "CreateResourceLimit"}, - {0x79, NULL, "Unknown"}, - {0x7A, NULL, "Unknown"}, - {0x7B, NULL, "Unknown"}, - {0x7C, NULL, "KernelSetState"}, - {0x7D, NULL, "QueryProcessMemory"}, + {0x00, NULL, "Unknown"}, + {0x01, NULL, "ControlMemory"}, + {0x02, NULL, "QueryMemory"}, + {0x03, NULL, "ExitProcess"}, + {0x04, NULL, "GetProcessAffinityMask"}, + {0x05, NULL, "SetProcessAffinityMask"}, + {0x06, NULL, "GetProcessIdealProcessor"}, + {0x07, NULL, "SetProcessIdealProcessor"}, + {0x08, NULL, "CreateThread"}, + {0x09, NULL, "ExitThread"}, + {0x0A, NULL, "SleepThread"}, + {0x0B, NULL, "GetThreadPriority"}, + {0x0C, NULL, "SetThreadPriority"}, + {0x0D, NULL, "GetThreadAffinityMask"}, + {0x0E, NULL, "SetThreadAffinityMask"}, + {0x0F, NULL, "GetThreadIdealProcessor"}, + {0x10, NULL, "SetThreadIdealProcessor"}, + {0x11, NULL, "GetCurrentProcessorNumber"}, + {0x12, NULL, "Run"}, + {0x13, NULL, "CreateMutex"}, + {0x14, NULL, "ReleaseMutex"}, + {0x15, NULL, "CreateSemaphore"}, + {0x16, NULL, "ReleaseSemaphore"}, + {0x17, NULL, "CreateEvent"}, + {0x18, NULL, "SignalEvent"}, + {0x19, NULL, "ClearEvent"}, + {0x1A, NULL, "CreateTimer"}, + {0x1B, NULL, "SetTimer"}, + {0x1C, NULL, "CancelTimer"}, + {0x1D, NULL, "ClearTimer"}, + {0x1E, NULL, "CreateMemoryBlock"}, + {0x1F, NULL, "MapMemoryBlock"}, + {0x20, NULL, "UnmapMemoryBlock"}, + {0x21, NULL, "CreateAddressArbiter"}, + {0x22, NULL, "ArbitrateAddress"}, + {0x23, WrapI_U, "CloseHandle"}, + {0x24, WrapI_US64, "WaitSynchronization1"}, + {0x25, NULL, "WaitSynchronizationN"}, + {0x26, NULL, "SignalAndWait"}, + {0x27, NULL, "DuplicateHandle"}, + {0x28, NULL, "GetSystemTick"}, + {0x29, NULL, "GetHandleInfo"}, + {0x2A, NULL, "GetSystemInfo"}, + {0x2B, NULL, "GetProcessInfo"}, + {0x2C, NULL, "GetThreadInfo"}, + {0x2D, WrapI_VC, "ConnectToPort"}, + {0x2E, NULL, "SendSyncRequest1"}, + {0x2F, NULL, "SendSyncRequest2"}, + {0x30, NULL, "SendSyncRequest3"}, + {0x31, NULL, "SendSyncRequest4"}, + {0x32, WrapI_U, "SendSyncRequest"}, + {0x33, NULL, "OpenProcess"}, + {0x34, NULL, "OpenThread"}, + {0x35, NULL, "GetProcessId"}, + {0x36, NULL, "GetProcessIdOfThread"}, + {0x37, NULL, "GetThreadId"}, + {0x38, NULL, "GetResourceLimit"}, + {0x39, NULL, "GetResourceLimitLimitValues"}, + {0x3A, NULL, "GetResourceLimitCurrentValues"}, + {0x3B, NULL, "GetThreadContext"}, + {0x3C, NULL, "Break"}, + {0x3D, NULL, "OutputDebugString"}, + {0x3E, NULL, "ControlPerformanceCounter"}, + {0x3F, NULL, "Unknown"}, + {0x40, NULL, "Unknown"}, + {0x41, NULL, "Unknown"}, + {0x42, NULL, "Unknown"}, + {0x43, NULL, "Unknown"}, + {0x44, NULL, "Unknown"}, + {0x45, NULL, "Unknown"}, + {0x46, NULL, "Unknown"}, + {0x47, NULL, "CreatePort"}, + {0x48, NULL, "CreateSessionToPort"}, + {0x49, NULL, "CreateSession"}, + {0x4A, NULL, "AcceptSession"}, + {0x4B, NULL, "ReplyAndReceive1"}, + {0x4C, NULL, "ReplyAndReceive2"}, + {0x4D, NULL, "ReplyAndReceive3"}, + {0x4E, NULL, "ReplyAndReceive4"}, + {0x4F, NULL, "ReplyAndReceive"}, + {0x50, NULL, "BindInterrupt"}, + {0x51, NULL, "UnbindInterrupt"}, + {0x52, NULL, "InvalidateProcessDataCache"}, + {0x53, NULL, "StoreProcessDataCache"}, + {0x54, NULL, "FlushProcessDataCache"}, + {0x55, NULL, "StartInterProcessDma"}, + {0x56, NULL, "StopDma"}, + {0x57, NULL, "GetDmaState"}, + {0x58, NULL, "RestartDma"}, + {0x59, NULL, "Unknown"}, + {0x5A, NULL, "Unknown"}, + {0x5B, NULL, "Unknown"}, + {0x5C, NULL, "Unknown"}, + {0x5D, NULL, "Unknown"}, + {0x5E, NULL, "Unknown"}, + {0x5F, NULL, "Unknown"}, + {0x60, NULL, "DebugActiveProcess"}, + {0x61, NULL, "BreakDebugProcess"}, + {0x62, NULL, "TerminateDebugProcess"}, + {0x63, NULL, "GetProcessDebugEvent"}, + {0x64, NULL, "ContinueDebugEvent"}, + {0x65, NULL, "GetProcessList"}, + {0x66, NULL, "GetThreadList"}, + {0x67, NULL, "GetDebugThreadContext"}, + {0x68, NULL, "SetDebugThreadContext"}, + {0x69, NULL, "QueryDebugProcessMemory"}, + {0x6A, NULL, "ReadProcessMemory"}, + {0x6B, NULL, "WriteProcessMemory"}, + {0x6C, NULL, "SetHardwareBreakPoint"}, + {0x6D, NULL, "GetDebugThreadParam"}, + {0x6E, NULL, "Unknown"}, + {0x6F, NULL, "Unknown"}, + {0x70, NULL, "ControlProcessMemory"}, + {0x71, NULL, "MapProcessMemory"}, + {0x72, NULL, "UnmapProcessMemory"}, + {0x73, NULL, "Unknown"}, + {0x74, NULL, "Unknown"}, + {0x75, NULL, "Unknown"}, + {0x76, NULL, "TerminateProcess"}, + {0x77, NULL, "Unknown"}, + {0x78, NULL, "CreateResourceLimit"}, + {0x79, NULL, "Unknown"}, + {0x7A, NULL, "Unknown"}, + {0x7B, NULL, "Unknown"}, + {0x7C, NULL, "KernelSetState"}, + {0x7D, NULL, "QueryProcessMemory"}, }; void Register() { From b8851305bd9840c55a50ca386630f59166ae9578 Mon Sep 17 00:00:00 2001 From: bunnei Date: Wed, 16 Apr 2014 20:46:05 -0400 Subject: [PATCH 35/49] updated service comments --- src/core/hle/service/apt.cpp | 3 +++ src/core/hle/service/apt.h | 3 ++- src/core/hle/service/gsp.cpp | 3 +++ src/core/hle/service/gsp.h | 3 ++- src/core/hle/service/srv.cpp | 3 +++ src/core/hle/service/srv.h | 7 ++++--- 6 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/core/hle/service/apt.cpp b/src/core/hle/service/apt.cpp index e5c9dd873..4f8d7248d 100644 --- a/src/core/hle/service/apt.cpp +++ b/src/core/hle/service/apt.cpp @@ -8,6 +8,9 @@ #include "core/hle/hle.h" #include "core/hle/service/apt.h" +//////////////////////////////////////////////////////////////////////////////////////////////////// +// Namespace APT_U + namespace APT_U { void Initialize() { diff --git a/src/core/hle/service/apt.h b/src/core/hle/service/apt.h index 9345eabc3..e74baac0c 100644 --- a/src/core/hle/service/apt.h +++ b/src/core/hle/service/apt.h @@ -7,7 +7,7 @@ #include "core/hle/service/service.h" //////////////////////////////////////////////////////////////////////////////////////////////////// -// Namespace Service +// Namespace APT_U namespace APT_U { @@ -17,6 +17,7 @@ namespace APT_U { // exactly the same, however certain commands are only accessible with APT:S(NS module will call // svcBreak when the command isn't accessible). See http://3dbrew.org/wiki/NS#APT_Services. +/// Interface to "APT:U" service class Interface : public Service::Interface { public: diff --git a/src/core/hle/service/gsp.cpp b/src/core/hle/service/gsp.cpp index 6dfd76de3..7c80ab8b5 100644 --- a/src/core/hle/service/gsp.cpp +++ b/src/core/hle/service/gsp.cpp @@ -8,6 +8,9 @@ #include "core/hle/hle.h" #include "core/hle/service/gsp.h" +//////////////////////////////////////////////////////////////////////////////////////////////////// +// Namespace GSP_GPU + namespace GSP_GPU { const HLE::FunctionDef FunctionTable[] = { diff --git a/src/core/hle/service/gsp.h b/src/core/hle/service/gsp.h index 0a9d452f6..3b1846082 100644 --- a/src/core/hle/service/gsp.h +++ b/src/core/hle/service/gsp.h @@ -7,10 +7,11 @@ #include "core/hle/service/service.h" //////////////////////////////////////////////////////////////////////////////////////////////////// -// Namespace Service +// Namespace GSP_GPU namespace GSP_GPU { +/// Interface to "srv:" service class Interface : public Service::Interface { public: diff --git a/src/core/hle/service/srv.cpp b/src/core/hle/service/srv.cpp index ad7448461..1ec78dd15 100644 --- a/src/core/hle/service/srv.cpp +++ b/src/core/hle/service/srv.cpp @@ -7,6 +7,9 @@ #include "core/hle/service/service.h" +//////////////////////////////////////////////////////////////////////////////////////////////////// +// Namespace SRV + namespace SRV { void Initialize() { diff --git a/src/core/hle/service/srv.h b/src/core/hle/service/srv.h index a1d26a34d..d9ac8fc88 100644 --- a/src/core/hle/service/srv.h +++ b/src/core/hle/service/srv.h @@ -4,11 +4,12 @@ #include "core/hle/service/service.h" +//////////////////////////////////////////////////////////////////////////////////////////////////// +// Namespace SRV + namespace SRV { -//////////////////////////////////////////////////////////////////////////////////////////////////// -// Interface to "SRV" service - +/// Interface to "srv:" service class Interface : public Service::Interface { public: From bb5bc2df257330561c886ed768ce2191e2641a6c Mon Sep 17 00:00:00 2001 From: bunnei Date: Wed, 16 Apr 2014 20:58:36 -0400 Subject: [PATCH 36/49] added class stub for HID:User service --- src/core/core.vcxproj | 2 ++ src/core/core.vcxproj.filters | 6 ++++++ src/core/hle/service/hid.cpp | 33 ++++++++++++++++++++++++++++ src/core/hle/service/hid.h | 37 ++++++++++++++++++++++++++++++++ src/core/hle/service/service.cpp | 2 ++ 5 files changed, 80 insertions(+) create mode 100644 src/core/hle/service/hid.cpp create mode 100644 src/core/hle/service/hid.h diff --git a/src/core/core.vcxproj b/src/core/core.vcxproj index 931345441..caf827be4 100644 --- a/src/core/core.vcxproj +++ b/src/core/core.vcxproj @@ -155,6 +155,7 @@ + @@ -192,6 +193,7 @@ + diff --git a/src/core/core.vcxproj.filters b/src/core/core.vcxproj.filters index e022785ad..0a5b5a188 100644 --- a/src/core/core.vcxproj.filters +++ b/src/core/core.vcxproj.filters @@ -99,6 +99,9 @@ hle\service + + hle\service + @@ -193,6 +196,9 @@ hle\service + + hle\service + diff --git a/src/core/hle/service/hid.cpp b/src/core/hle/service/hid.cpp new file mode 100644 index 000000000..2d823dd16 --- /dev/null +++ b/src/core/hle/service/hid.cpp @@ -0,0 +1,33 @@ +// Copyright 2014 Citra Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#include "common/log.h" + +#include "core/hle/hle.h" +#include "core/hle/service/hid.h" + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// Namespace HID_User + +namespace HID_User { + +const HLE::FunctionDef FunctionTable[] = { + {0x000A0000, NULL, "GetIPCHandles"}, + {0x00110000, NULL, "EnableAccelerometer"}, + {0x00130000, NULL, "EnableGyroscopeLow"}, + {0x00150000, NULL, "GetGyroscopeLowRawToDpsCoefficient"}, + {0x00160000, NULL, "GetGyroscopeLowCalibrateParam"}, +}; + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// Interface class + +Interface::Interface() { + Register(FunctionTable, ARRAY_SIZE(FunctionTable)); +} + +Interface::~Interface() { +} + +} // namespace diff --git a/src/core/hle/service/hid.h b/src/core/hle/service/hid.h new file mode 100644 index 000000000..746c1b1fc --- /dev/null +++ b/src/core/hle/service/hid.h @@ -0,0 +1,37 @@ +// Copyright 2014 Citra Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#pragma once + +#include "core/hle/service/service.h" + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// Namespace HID_User + +// This service is used for interfacing to physical user controls... perhaps "Human Interface +// Devices"? Uses include game pad controls, accelerometers, gyroscopes, etc. + +namespace HID_User { + +class Interface : public Service::Interface { +public: + + Interface(); + + ~Interface(); + + /** + * Gets the string port name used by CTROS for the service + * @return Port name of service + */ + std::string GetPortName() const { + return "hid:USER"; + } + +private: + + DISALLOW_COPY_AND_ASSIGN(Interface); +}; + +} // namespace diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp index f612ff830..e6605a398 100644 --- a/src/core/hle/service/service.cpp +++ b/src/core/hle/service/service.cpp @@ -10,6 +10,7 @@ #include "core/hle/service/service.h" #include "core/hle/service/apt.h" #include "core/hle/service/gsp.h" +#include "core/hle/service/hid.h" #include "core/hle/service/srv.h" namespace Service { @@ -78,6 +79,7 @@ void Init() { g_manager->AddService(new SRV::Interface); g_manager->AddService(new APT_U::Interface); g_manager->AddService(new GSP_GPU::Interface); + g_manager->AddService(new HID_User::Interface); NOTICE_LOG(HLE, "Services initialized OK"); } From 795d6bf5b7cd822f70213a9024c67efedde8d6a1 Mon Sep 17 00:00:00 2001 From: bunnei Date: Wed, 16 Apr 2014 21:21:53 -0400 Subject: [PATCH 37/49] changed unknown memory read/write to report the size --- src/core/mem_map_funcs.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/core/mem_map_funcs.cpp b/src/core/mem_map_funcs.cpp index 184296287..3e85a119f 100644 --- a/src/core/mem_map_funcs.cpp +++ b/src/core/mem_map_funcs.cpp @@ -48,7 +48,7 @@ inline void _Read(T &var, const u32 addr) { var = *((const T*)&g_fcram[addr & MEM_FCRAM_MASK]); } else { - _assert_msg_(MEMMAP, false, "unknown memory read @ 0x%08X", addr); + _assert_msg_(MEMMAP, false, "unknown Read%d @ 0x%08X", sizeof(var) * 8, addr); } } @@ -109,7 +109,8 @@ inline void _Write(u32 addr, const T data) { // Error out... } else { - _assert_msg_(MEMMAP, false, "unknown memory write"); + _assert_msg_(MEMMAP, false, "unknown Write%d 0x%08X @ 0x%08X", sizeof(data) * 8, + data, addr); } } From 9d1a17ca88ee05cacb6e0f87d9a80b50d3acf69b Mon Sep 17 00:00:00 2001 From: bunnei Date: Wed, 16 Apr 2014 21:22:15 -0400 Subject: [PATCH 38/49] fixed bug with printing std::string in log messages --- src/core/hle/service/srv.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/hle/service/srv.cpp b/src/core/hle/service/srv.cpp index 1ec78dd15..579ea4a34 100644 --- a/src/core/hle/service/srv.cpp +++ b/src/core/hle/service/srv.cpp @@ -23,13 +23,13 @@ void GetServiceHandle() { std::string port_name = std::string((const char*)&cmd_buff[1], 0, Service::kMaxPortSize); Service::Interface* service = Service::g_manager->FetchFromPortName(port_name); - NOTICE_LOG(OSHLE, "SRV::Sync - GetHandle - port: %s, handle: 0x%08X", port_name, + NOTICE_LOG(OSHLE, "SRV::Sync - GetHandle - port: %s, handle: 0x%08X", port_name.c_str(), service->GetUID()); if (NULL != service) { cmd_buff[3] = service->GetUID(); } else { - ERROR_LOG(OSHLE, "Service %s does not exist", port_name); + ERROR_LOG(OSHLE, "Service %s does not exist", port_name.c_str()); res = -1; } cmd_buff[1] = res; From d4411acfd04a5c585e7cb8aebcc2e3260f9ee17f Mon Sep 17 00:00:00 2001 From: bunnei Date: Wed, 16 Apr 2014 21:30:10 -0400 Subject: [PATCH 39/49] removed hard-coded framebuffer addresses from renderer_opengl.cpp --- src/video_core/renderer_opengl/renderer_opengl.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/video_core/renderer_opengl/renderer_opengl.cpp b/src/video_core/renderer_opengl/renderer_opengl.cpp index 97f84c248..6cac968ed 100644 --- a/src/video_core/renderer_opengl/renderer_opengl.cpp +++ b/src/video_core/renderer_opengl/renderer_opengl.cpp @@ -2,6 +2,8 @@ // Licensed under GPLv2 // Refer to the license.txt file included. +#include "core/hw/hw_lcd.h" + #include "video_core/video_core.h" #include "video_core/renderer_opengl/renderer_opengl.h" @@ -75,8 +77,8 @@ void RendererOpenGL::FlipFramebuffer(u32 addr, u8* out) { */ void RendererOpenGL::RenderXFB(const Rect& src_rect, const Rect& dst_rect) { - FlipFramebuffer(0x20282160, m_xfb_top_flipped); - FlipFramebuffer(0x202118E0, m_xfb_bottom_flipped); + FlipFramebuffer(LCD::TOP_RIGHT_FRAME1, m_xfb_top_flipped); + FlipFramebuffer(LCD::SUB_FRAME1, m_xfb_bottom_flipped); // Blit the top framebuffer // ------------------------ From f0797dcf1ff954c357ebf4aa7eb234ebadae333d Mon Sep 17 00:00:00 2001 From: bunnei Date: Wed, 16 Apr 2014 22:19:23 -0400 Subject: [PATCH 40/49] added a new function wrapper --- src/core/hle/function_wrappers.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/core/hle/function_wrappers.h b/src/core/hle/function_wrappers.h index 7d9389769..4897d3f28 100644 --- a/src/core/hle/function_wrappers.h +++ b/src/core/hle/function_wrappers.h @@ -725,6 +725,11 @@ template void WrapI_ICU RETURN(retval); } +template void WrapI_VUUUUU(){ + u32 retval = func(Memory::GetPointer(PARAM(0)), PARAM(1), PARAM(2), PARAM(3), PARAM(4), PARAM(5)); + RETURN(retval); +} + template void WrapI_US64() { int retval = func(PARAM(0), PARAM64(2)); RETURN(retval); From 9d5a561c1b611bf5e501e8b67f0e9670c42adb19 Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 17 Apr 2014 17:47:34 -0400 Subject: [PATCH 41/49] fixed framebuffer color order --- src/video_core/renderer_opengl/renderer_opengl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/video_core/renderer_opengl/renderer_opengl.cpp b/src/video_core/renderer_opengl/renderer_opengl.cpp index 6cac968ed..168de9253 100644 --- a/src/video_core/renderer_opengl/renderer_opengl.cpp +++ b/src/video_core/renderer_opengl/renderer_opengl.cpp @@ -86,7 +86,7 @@ void RendererOpenGL::RenderXFB(const Rect& src_rect, const Rect& dst_rect) { // Update textures with contents of XFB in RAM - top glBindTexture(GL_TEXTURE_2D, m_xfb_texture_top); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, VideoCore::kScreenTopWidth, VideoCore::kScreenTopHeight, - GL_RGB, GL_UNSIGNED_BYTE, m_xfb_top_flipped); + GL_BGR, GL_UNSIGNED_BYTE, m_xfb_top_flipped); glBindTexture(GL_TEXTURE_2D, 0); // Render target is destination framebuffer From ae99574b6dd2f21960bd42e0bb9a1978e18413d4 Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 17 Apr 2014 18:40:42 -0400 Subject: [PATCH 42/49] cleaned up memory interfaces a lot, removed some hackish stuff --- src/core/mem_map.cpp | 8 +-- src/core/mem_map.h | 4 +- src/core/mem_map_funcs.cpp | 136 ++++++++++++------------------------- 3 files changed, 46 insertions(+), 102 deletions(-) diff --git a/src/core/mem_map.cpp b/src/core/mem_map.cpp index 5b5c57fca..8fc8388ec 100644 --- a/src/core/mem_map.cpp +++ b/src/core/mem_map.cpp @@ -19,7 +19,6 @@ MemArena g_arena; ///< The MemArena class u8* g_bootrom = NULL; ///< Bootrom physical memory u8* g_fcram = NULL; ///< Main memory (FCRAM) pointer u8* g_vram = NULL; ///< Video memory (VRAM) pointer -u8* g_scratchpad = NULL; ///< Scratchpad memory - Used for main thread stack u8* g_physical_bootrom = NULL; ///< Bootrom physical memory u8* g_uncached_bootrom = NULL; @@ -60,8 +59,6 @@ void Init() { g_base = MemoryMap_Setup(g_views, kNumMemViews, flags, &g_arena); - g_scratchpad = new u8[MEM_SCRATCHPAD_SIZE]; - NOTICE_LOG(MEMMAP, "initialized OK, RAM at %p (mirror at 0 @ %p)", g_fcram, g_physical_fcram); } @@ -71,10 +68,7 @@ void Shutdown() { MemoryMap_Shutdown(g_views, kNumMemViews, flags, &g_arena); g_arena.ReleaseSpace(); - delete[] g_scratchpad; - - g_base = NULL; - g_scratchpad = NULL; + g_base = NULL; NOTICE_LOG(MEMMAP, "shutdown OK"); } diff --git a/src/core/mem_map.h b/src/core/mem_map.h index d0308fa5c..82cfdece5 100644 --- a/src/core/mem_map.h +++ b/src/core/mem_map.h @@ -17,8 +17,7 @@ enum { MEM_VRAM_SIZE = 0x00600000, ///< VRAM size MEM_DSP_SIZE = 0x00080000, ///< DSP memory size MEM_AXI_WRAM_SIZE = 0x00080000, ///< AXI WRAM size - MEM_FCRAM_SIZE = 0x08000000, ///< FCRAM size... Really 0x07E00000, but power of 2 - // works much better + MEM_FCRAM_SIZE = 0x08000000, ///< FCRAM size MEM_SCRATCHPAD_SIZE = 0x00004000, ///< Typical stack size - TODO: Read from exheader MEM_VRAM_MASK = 0x007FFFFF, @@ -52,7 +51,6 @@ extern u8 *g_base; // 32-bit: Same as the corresponding physical/virtual pointers. extern u8* g_fcram; ///< Main memory extern u8* g_vram; ///< Video memory (VRAM) -extern u8* g_scratchpad; ///< Stack memory void Init(); void Shutdown(); diff --git a/src/core/mem_map_funcs.cpp b/src/core/mem_map_funcs.cpp index 3e85a119f..bb83855fe 100644 --- a/src/core/mem_map_funcs.cpp +++ b/src/core/mem_map_funcs.cpp @@ -10,154 +10,106 @@ namespace Memory { +/// Convert a physical address to virtual address +u32 _AddressPhysicalToVirtual(const u32 addr) { + // Our memory interface read/write functions assume virtual addresses. Put any physical address + // to virtual address translations here. This is obviously quite hacky... But we're not doing + // any MMU emulation yet or anything + if (((addr & 0xF0000000) == MEM_FCRAM_PADDR) && (addr < (MEM_FCRAM_PADDR_END))) { + return (addr & MEM_FCRAM_MASK) | MEM_FCRAM_VADDR; + } + return addr; +} + template inline void _Read(T &var, const u32 addr) { // TODO: Figure out the fastest order of tests for both read and write (they are probably different). // TODO: Make sure this represents the mirrors in a correct way. // Could just do a base-relative read, too.... TODO + const u32 vaddr = _AddressPhysicalToVirtual(addr); // Memory allocated for HLE use that can be addressed from the emulated application // The primary use of this is sharing a commandbuffer between the HLE OS (syscore) and the LLE // core running the user application (appcore) - if (addr >= HLE::CMD_BUFFER_ADDR && addr < HLE::CMD_BUFFER_ADDR_END) { - HLE::Read(var, addr); + if (vaddr >= HLE::CMD_BUFFER_ADDR && vaddr < HLE::CMD_BUFFER_ADDR_END) { + HLE::Read(var, vaddr); // Hardware I/O register reads // 0x10XXXXXX- is physical address space, 0x1EXXXXXX is virtual address space - } else if ((addr & 0xFF000000) == 0x10000000 || (addr & 0xFF000000) == 0x1E000000) { - HW::Read(var, addr); + } else if ((vaddr & 0xFF000000) == 0x10000000 || (vaddr & 0xFF000000) == 0x1E000000) { + HW::Read(var, vaddr); - // FCRAM virtual address reads - } else if ((addr & 0x3E000000) == 0x08000000) { - var = *((const T*)&g_fcram[addr & MEM_FCRAM_MASK]); + // FCRAM + } else if ((vaddr > MEM_FCRAM_VADDR) && (vaddr < MEM_FCRAM_VADDR_END)) { + var = *((const T*)&g_fcram[vaddr & MEM_FCRAM_MASK]); - // Scratchpad memory - } else if (addr > MEM_SCRATCHPAD_VADDR && addr <= (MEM_SCRATCHPAD_VADDR + MEM_SCRATCHPAD_SIZE)) { - var = *((const T*)&g_scratchpad[addr & MEM_SCRATCHPAD_MASK]); - - /*else if ((addr & 0x3F800000) == 0x04000000) { - var = *((const T*)&m_pVRAM[addr & VRAM_MASK]); - }*/ - - // HACK(bunnei): There is no layer yet to translate virtual addresses to physical addresses. - // Until we progress far enough along, we'll accept all physical address reads here. I think - // that this is typically a corner-case from usermode software unless they are trying to do - // bare-metal things (e.g. early 3DS homebrew writes directly to the FB @ 0x20184E60, etc. - } else if (((addr & 0xF0000000) == MEM_FCRAM_PADDR) && (addr < (MEM_FCRAM_PADDR_END))) { - var = *((const T*)&g_fcram[addr & MEM_FCRAM_MASK]); + /*else if ((vaddr & 0x3F800000) == 0x04000000) { + var = *((const T*)&m_pVRAM[vaddr & VRAM_MASK]);*/ } else { - _assert_msg_(MEMMAP, false, "unknown Read%d @ 0x%08X", sizeof(var) * 8, addr); + _assert_msg_(MEMMAP, false, "unknown Read%d @ 0x%08X", sizeof(var) * 8, vaddr); } } template inline void _Write(u32 addr, const T data) { + u32 vaddr = _AddressPhysicalToVirtual(addr); // Memory allocated for HLE use that can be addressed from the emulated application // The primary use of this is sharing a commandbuffer between the HLE OS (syscore) and the LLE // core running the user application (appcore) - if (addr >= HLE::CMD_BUFFER_ADDR && addr < HLE::CMD_BUFFER_ADDR_END) { - HLE::Write(addr, data); + if (vaddr >= HLE::CMD_BUFFER_ADDR && vaddr < HLE::CMD_BUFFER_ADDR_END) { + HLE::Write(vaddr, data); // Hardware I/O register writes // 0x10XXXXXX- is physical address space, 0x1EXXXXXX is virtual address space - } else if ((addr & 0xFF000000) == 0x10000000 || (addr & 0xFF000000) == 0x1E000000) { - HW::Write(addr, data); + } else if ((vaddr & 0xFF000000) == 0x10000000 || (vaddr & 0xFF000000) == 0x1E000000) { + HW::Write(vaddr, data); // ExeFS:/.code is loaded here: - } else if ((addr & 0xFFF00000) == 0x00100000) { + } else if ((vaddr & 0xFFF00000) == 0x00100000) { // TODO(ShizZy): This is dumb... handle correctly. From 3DBrew: // http://3dbrew.org/wiki/Memory_layout#ARM11_User-land_memory_regions // The ExeFS:/.code is loaded here, executables must be loaded to the 0x00100000 region when // the exheader "special memory" flag is clear. The 0x03F00000-byte size restriction only // applies when this flag is clear. Executables are usually loaded to 0x14000000 when the // exheader "special memory" flag is set, however this address can be arbitrary. - *(T*)&g_fcram[addr & MEM_FCRAM_MASK] = data; + *(T*)&g_fcram[vaddr & MEM_FCRAM_MASK] = data; - // Scratchpad memory - } else if (addr > MEM_SCRATCHPAD_VADDR && addr <= (MEM_SCRATCHPAD_VADDR + MEM_SCRATCHPAD_SIZE)) { - *(T*)&g_scratchpad[addr & MEM_SCRATCHPAD_MASK] = data; + // FCRAM + } else if ((vaddr > MEM_FCRAM_VADDR) && (vaddr < MEM_FCRAM_VADDR_END)) { + *(T*)&g_fcram[vaddr & MEM_FCRAM_MASK] = data; - // Heap mapped by ControlMemory: - } else if ((addr & 0x3E000000) == 0x08000000) { - // TODO(ShizZy): Writes to this virtual address should be put in physical memory at FCRAM + GSP - // heap size... the following is writing to FCRAM + 0, which is actually supposed to be the - // application's GSP heap - *(T*)&g_fcram[addr & MEM_FCRAM_MASK] = data; - - } else if ((addr & 0xFF000000) == 0x14000000) { + } else if ((vaddr & 0xFF000000) == 0x14000000) { _assert_msg_(MEMMAP, false, "umimplemented write to GSP heap"); - } else if ((addr & 0xFFF00000) == 0x1EC00000) { + } else if ((vaddr & 0xFFF00000) == 0x1EC00000) { _assert_msg_(MEMMAP, false, "umimplemented write to IO registers"); - } else if ((addr & 0xFF000000) == 0x1F000000) { + } else if ((vaddr & 0xFF000000) == 0x1F000000) { _assert_msg_(MEMMAP, false, "umimplemented write to VRAM"); - } else if ((addr & 0xFFF00000) == 0x1FF00000) { + } else if ((vaddr & 0xFFF00000) == 0x1FF00000) { _assert_msg_(MEMMAP, false, "umimplemented write to DSP memory"); - } else if ((addr & 0xFFFF0000) == 0x1FF80000) { + } else if ((vaddr & 0xFFFF0000) == 0x1FF80000) { _assert_msg_(MEMMAP, false, "umimplemented write to Configuration Memory"); - } else if ((addr & 0xFFFFF000) == 0x1FF81000) { + } else if ((vaddr & 0xFFFFF000) == 0x1FF81000) { _assert_msg_(MEMMAP, false, "umimplemented write to shared page"); - // HACK(bunnei): There is no layer yet to translate virtual addresses to physical addresses. - // Until we progress far enough along, we'll accept all physical address writes here. I think - // that this is typically a corner-case from usermode software unless they are trying to do - // bare-metal things (e.g. early 3DS homebrew writes directly to the FB @ 0x20184E60, etc. - } else if (((addr & 0xF0000000) == MEM_FCRAM_PADDR) && (addr < (MEM_FCRAM_PADDR_END))) { - *(T*)&g_fcram[addr & MEM_FCRAM_MASK] = data; - // Error out... } else { _assert_msg_(MEMMAP, false, "unknown Write%d 0x%08X @ 0x%08X", sizeof(data) * 8, - data, addr); - } -} - -bool IsValidAddress(const u32 addr) { - if ((addr & 0x3E000000) == 0x08000000) { - return true; - } else if ((addr & 0x3F800000) == 0x04000000) { - return true; - } else if ((addr & 0xBFFF0000) == 0x00010000) { - return true; - } else if ((addr & 0x3F000000) >= 0x08000000 && (addr & 0x3F000000) < 0x08000000 + MEM_FCRAM_MASK) { - return true; - } else { - return false; + data, vaddr); } } u8 *GetPointer(const u32 addr) { - // TODO(bunnei): Just a stub for now... ImplementMe! - if ((addr & 0x3E000000) == 0x08000000) { - return g_fcram + (addr & MEM_FCRAM_MASK); + const u32 vaddr = _AddressPhysicalToVirtual(addr); - // HACK(bunnei): There is no layer yet to translate virtual addresses to physical addresses. - // Until we progress far enough along, we'll accept all physical address reads here. I think - // that this is typically a corner-case from usermode software unless they are trying to do - // bare-metal things (e.g. early 3DS homebrew writes directly to the FB @ 0x20184E60, etc. - } else if (((addr & 0xF0000000) == MEM_FCRAM_PADDR) && (addr < (MEM_FCRAM_PADDR_END))) { - return g_fcram + (addr & MEM_FCRAM_MASK); + // FCRAM + if ((vaddr > MEM_FCRAM_VADDR) && (vaddr < MEM_FCRAM_VADDR_END)) { + return g_fcram + (vaddr & MEM_FCRAM_MASK); - //else if ((addr & 0x3F800000) == 0x04000000) { - // return g_vram + (addr & MEM_VRAM_MASK); - //} - //else if ((addr & 0x3F000000) >= 0x08000000 && (addr & 0x3F000000) < 0x08000000 + g_MemorySize) { - // return m_pRAM + (addr & g_MemoryMask); - //} } else { - //ERROR_LOG(MEMMAP, "Unknown GetPointer %08x PC %08x LR %08x", addr, currentMIPS->pc, currentMIPS->r[MIPS_REG_RA]); - ERROR_LOG(MEMMAP, "Unknown GetPointer %08x", addr); - static bool reported = false; - //if (!reported) { - // Reporting::ReportMessage("Unknown GetPointer %08x PC %08x LR %08x", addr, currentMIPS->pc, currentMIPS->r[MIPS_REG_RA]); - // reported = true; - //} - //if (!g_Config.bIgnoreBadMemAccess) { - // Core_EnableStepping(true); - // host->SetDebugMode(true); - //} + ERROR_LOG(MEMMAP, "Unknown GetPointer @ 0x%08x", vaddr); return 0; } } From 09ffe87360f39a76b084fe1c9bac2330d6f6f790 Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 17 Apr 2014 21:05:34 -0400 Subject: [PATCH 43/49] more various refactors to memory interface --- src/core/mem_map.cpp | 13 ++++++---- src/core/mem_map.h | 51 ++++++++++++++++++++++++-------------- src/core/mem_map_funcs.cpp | 38 ++++++++++++---------------- 3 files changed, 56 insertions(+), 46 deletions(-) diff --git a/src/core/mem_map.cpp b/src/core/mem_map.cpp index 8fc8388ec..44b4b07b7 100644 --- a/src/core/mem_map.cpp +++ b/src/core/mem_map.cpp @@ -17,20 +17,23 @@ u8* g_base = NULL; ///< The base pointer to the aut MemArena g_arena; ///< The MemArena class u8* g_bootrom = NULL; ///< Bootrom physical memory -u8* g_fcram = NULL; ///< Main memory (FCRAM) pointer +u8* g_heap_gsp = NULL; +u8* g_heap = NULL; u8* g_vram = NULL; ///< Video memory (VRAM) pointer u8* g_physical_bootrom = NULL; ///< Bootrom physical memory u8* g_uncached_bootrom = NULL; u8* g_physical_fcram = NULL; ///< Main physical memory (FCRAM) +u8* g_physical_heap_gsp = NULL; u8* g_physical_vram = NULL; ///< Video physical memory (VRAM) u8* g_physical_scratchpad = NULL; ///< Scratchpad memory used for main thread stack // We don't declare the IO region in here since its handled by other means. static MemoryView g_views[] = { - { &g_vram, &g_physical_vram, MEM_VRAM_VADDR, MEM_VRAM_SIZE, 0 }, - { &g_fcram, &g_physical_fcram, MEM_FCRAM_VADDR, MEM_FCRAM_SIZE, MV_IS_PRIMARY_RAM }, + {&g_vram, &g_physical_vram, VRAM_VADDR, VRAM_SIZE, 0}, + {&g_heap_gsp, &g_physical_heap_gsp, HEAP_GSP_VADDR, HEAP_GSP_SIZE, 0}, + {&g_heap, &g_physical_fcram, HEAP_VADDR, HEAP_SIZE, MV_IS_PRIMARY_RAM}, }; /*static MemoryView views[] = @@ -54,12 +57,12 @@ void Init() { for (size_t i = 0; i < ARRAY_SIZE(g_views); i++) { if (g_views[i].flags & MV_IS_PRIMARY_RAM) - g_views[i].size = MEM_FCRAM_SIZE; + g_views[i].size = FCRAM_SIZE; } g_base = MemoryMap_Setup(g_views, kNumMemViews, flags, &g_arena); - NOTICE_LOG(MEMMAP, "initialized OK, RAM at %p (mirror at 0 @ %p)", g_fcram, + NOTICE_LOG(MEMMAP, "initialized OK, RAM at %p (mirror at 0 @ %p)", g_heap, g_physical_fcram); } diff --git a/src/core/mem_map.h b/src/core/mem_map.h index 82cfdece5..a1fa90f3e 100644 --- a/src/core/mem_map.h +++ b/src/core/mem_map.h @@ -12,25 +12,38 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// enum { - MEM_BOOTROM_SIZE = 0x00010000, ///< Bootrom (super secret code/data @ 0x8000) size - MEM_MPCORE_PRIV_SIZE = 0x00002000, ///< MPCore private memory region size - MEM_VRAM_SIZE = 0x00600000, ///< VRAM size - MEM_DSP_SIZE = 0x00080000, ///< DSP memory size - MEM_AXI_WRAM_SIZE = 0x00080000, ///< AXI WRAM size - MEM_FCRAM_SIZE = 0x08000000, ///< FCRAM size - MEM_SCRATCHPAD_SIZE = 0x00004000, ///< Typical stack size - TODO: Read from exheader - - MEM_VRAM_MASK = 0x007FFFFF, - MEM_FCRAM_MASK = (MEM_FCRAM_SIZE - 1), ///< FCRAM mask - MEM_SCRATCHPAD_MASK = (MEM_SCRATCHPAD_SIZE - 1), ///< Scratchpad memory mask - - MEM_FCRAM_PADDR = 0x20000000, ///< FCRAM physical address - MEM_FCRAM_PADDR_END = (MEM_FCRAM_PADDR + MEM_FCRAM_SIZE), ///< FCRAM end of physical space - MEM_FCRAM_VADDR = 0x08000000, ///< FCRAM virtual address - MEM_FCRAM_VADDR_END = (MEM_FCRAM_VADDR + MEM_FCRAM_SIZE), ///< FCRAM end of virtual space + BOOTROM_SIZE = 0x00010000, ///< Bootrom (super secret code/data @ 0x8000) size + MPCORE_PRIV_SIZE = 0x00002000, ///< MPCore private memory region size + VRAM_SIZE = 0x00600000, ///< VRAM size + DSP_SIZE = 0x00080000, ///< DSP memory size + AXI_WRAM_SIZE = 0x00080000, ///< AXI WRAM size + FCRAM_SIZE = 0x08000000, ///< FCRAM size + SCRATCHPAD_SIZE = 0x00004000, ///< Typical stack size - TODO: Read from exheader + HEAP_GSP_SIZE = 0x02000000, ///< GSP heap size... TODO: Define correctly? + HEAP_SIZE = FCRAM_SIZE, ///< Application heap size - MEM_VRAM_VADDR = 0x1F000000, - MEM_SCRATCHPAD_VADDR = (0x10000000 - MEM_SCRATCHPAD_SIZE), ///< Scratchpad virtual address + HEAP_PADDR = HEAP_GSP_SIZE, + HEAP_PADDR_END = (HEAP_PADDR + HEAP_SIZE), + HEAP_VADDR = 0x08000000, + HEAP_VADDR_END = (HEAP_VADDR + HEAP_SIZE), + HEAP_GSP_VADDR = 0x14000000, + HEAP_GSP_VADDR_END = (HEAP_GSP_VADDR + HEAP_GSP_SIZE), + HEAP_GSP_PADDR = 0x00000000, + HEAP_GSP_PADDR_END = (HEAP_GSP_PADDR + HEAP_GSP_SIZE), + + VRAM_MASK = 0x007FFFFF, + FCRAM_MASK = (FCRAM_SIZE - 1), ///< FCRAM mask + SCRATCHPAD_MASK = (SCRATCHPAD_SIZE - 1), ///< Scratchpad memory mask + HEAP_MASK = (HEAP_SIZE - 1), + + FCRAM_PADDR = 0x20000000, ///< FCRAM physical address + FCRAM_PADDR_END = (FCRAM_PADDR + FCRAM_SIZE), ///< FCRAM end of physical space + FCRAM_VADDR = 0x08000000, ///< FCRAM virtual address + FCRAM_VADDR_END = (FCRAM_VADDR + FCRAM_SIZE), ///< FCRAM end of virtual space + + VRAM_VADDR = 0x1F000000, + SCRATCHPAD_VADDR_END = 0x10000000, + SCRATCHPAD_VADDR = (SCRATCHPAD_VADDR_END - SCRATCHPAD_SIZE), ///< Stack space }; //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -49,7 +62,7 @@ extern u8 *g_base; // These are guaranteed to point to "low memory" addresses (sub-32-bit). // 64-bit: Pointers to low-mem (sub-0x10000000) mirror // 32-bit: Same as the corresponding physical/virtual pointers. -extern u8* g_fcram; ///< Main memory +extern u8* g_heap; ///< Main memory extern u8* g_vram; ///< Video memory (VRAM) void Init(); diff --git a/src/core/mem_map_funcs.cpp b/src/core/mem_map_funcs.cpp index bb83855fe..40d9dab3a 100644 --- a/src/core/mem_map_funcs.cpp +++ b/src/core/mem_map_funcs.cpp @@ -15,8 +15,8 @@ u32 _AddressPhysicalToVirtual(const u32 addr) { // Our memory interface read/write functions assume virtual addresses. Put any physical address // to virtual address translations here. This is obviously quite hacky... But we're not doing // any MMU emulation yet or anything - if (((addr & 0xF0000000) == MEM_FCRAM_PADDR) && (addr < (MEM_FCRAM_PADDR_END))) { - return (addr & MEM_FCRAM_MASK) | MEM_FCRAM_VADDR; + if ((addr >= FCRAM_PADDR) && (addr < (FCRAM_PADDR_END))) { + return (addr & FCRAM_MASK) | FCRAM_VADDR; } return addr; } @@ -40,15 +40,15 @@ inline void _Read(T &var, const u32 addr) { } else if ((vaddr & 0xFF000000) == 0x10000000 || (vaddr & 0xFF000000) == 0x1E000000) { HW::Read(var, vaddr); - // FCRAM - } else if ((vaddr > MEM_FCRAM_VADDR) && (vaddr < MEM_FCRAM_VADDR_END)) { - var = *((const T*)&g_fcram[vaddr & MEM_FCRAM_MASK]); + // FCRAM - application heap + } else if ((vaddr > HEAP_VADDR) && (vaddr < HEAP_VADDR_END)) { + var = *((const T*)&g_heap[vaddr & HEAP_MASK]); /*else if ((vaddr & 0x3F800000) == 0x04000000) { var = *((const T*)&m_pVRAM[vaddr & VRAM_MASK]);*/ } else { - _assert_msg_(MEMMAP, false, "unknown Read%d @ 0x%08X", sizeof(var) * 8, vaddr); + //_assert_msg_(MEMMAP, false, "unknown Read%d @ 0x%08X", sizeof(var) * 8, vaddr); } } @@ -66,20 +66,14 @@ inline void _Write(u32 addr, const T data) { // 0x10XXXXXX- is physical address space, 0x1EXXXXXX is virtual address space } else if ((vaddr & 0xFF000000) == 0x10000000 || (vaddr & 0xFF000000) == 0x1E000000) { HW::Write(vaddr, data); - - // ExeFS:/.code is loaded here: - } else if ((vaddr & 0xFFF00000) == 0x00100000) { - // TODO(ShizZy): This is dumb... handle correctly. From 3DBrew: - // http://3dbrew.org/wiki/Memory_layout#ARM11_User-land_memory_regions - // The ExeFS:/.code is loaded here, executables must be loaded to the 0x00100000 region when - // the exheader "special memory" flag is clear. The 0x03F00000-byte size restriction only - // applies when this flag is clear. Executables are usually loaded to 0x14000000 when the - // exheader "special memory" flag is set, however this address can be arbitrary. - *(T*)&g_fcram[vaddr & MEM_FCRAM_MASK] = data; - // FCRAM - } else if ((vaddr > MEM_FCRAM_VADDR) && (vaddr < MEM_FCRAM_VADDR_END)) { - *(T*)&g_fcram[vaddr & MEM_FCRAM_MASK] = data; + // FCRAM - GSP heap + //} else if ((vaddr > HEAP_GSP_VADDR) && (vaddr < HEAP_VADDR_GSP_END)) { + // *(T*)&g_heap_gsp[vaddr & FCRAM_MASK] = data; + + // FCRAM - application heap + } else if ((vaddr > HEAP_VADDR) && (vaddr < HEAP_VADDR_END)) { + *(T*)&g_heap[vaddr & HEAP_MASK] = data; } else if ((vaddr & 0xFF000000) == 0x14000000) { _assert_msg_(MEMMAP, false, "umimplemented write to GSP heap"); @@ -104,9 +98,9 @@ inline void _Write(u32 addr, const T data) { u8 *GetPointer(const u32 addr) { const u32 vaddr = _AddressPhysicalToVirtual(addr); - // FCRAM - if ((vaddr > MEM_FCRAM_VADDR) && (vaddr < MEM_FCRAM_VADDR_END)) { - return g_fcram + (vaddr & MEM_FCRAM_MASK); + // FCRAM - application heap + if ((vaddr > HEAP_VADDR) && (vaddr < HEAP_VADDR_END)) { + return g_heap + (vaddr & HEAP_MASK); } else { ERROR_LOG(MEMMAP, "Unknown GetPointer @ 0x%08x", vaddr); From a9dba388eba586691724187fe53b385cc0bf23aa Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 17 Apr 2014 21:15:40 -0400 Subject: [PATCH 44/49] added memory read/write to GSP heap --- src/core/mem_map.cpp | 5 ++--- src/core/mem_map.h | 4 +++- src/core/mem_map_funcs.cpp | 14 +++++++++++--- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/core/mem_map.cpp b/src/core/mem_map.cpp index 44b4b07b7..180829239 100644 --- a/src/core/mem_map.cpp +++ b/src/core/mem_map.cpp @@ -16,9 +16,8 @@ u8* g_base = NULL; ///< The base pointer to the aut MemArena g_arena; ///< The MemArena class -u8* g_bootrom = NULL; ///< Bootrom physical memory -u8* g_heap_gsp = NULL; -u8* g_heap = NULL; +u8* g_heap_gsp = NULL; ///< GSP heap (main memory) +u8* g_heap = NULL; ///< Application heap (main memory) u8* g_vram = NULL; ///< Video memory (VRAM) pointer u8* g_physical_bootrom = NULL; ///< Bootrom physical memory diff --git a/src/core/mem_map.h b/src/core/mem_map.h index a1fa90f3e..9ca05cc4e 100644 --- a/src/core/mem_map.h +++ b/src/core/mem_map.h @@ -34,6 +34,7 @@ enum { VRAM_MASK = 0x007FFFFF, FCRAM_MASK = (FCRAM_SIZE - 1), ///< FCRAM mask SCRATCHPAD_MASK = (SCRATCHPAD_SIZE - 1), ///< Scratchpad memory mask + HEAP_GSP_MASK = (HEAP_GSP_SIZE - 1), HEAP_MASK = (HEAP_SIZE - 1), FCRAM_PADDR = 0x20000000, ///< FCRAM physical address @@ -62,7 +63,8 @@ extern u8 *g_base; // These are guaranteed to point to "low memory" addresses (sub-32-bit). // 64-bit: Pointers to low-mem (sub-0x10000000) mirror // 32-bit: Same as the corresponding physical/virtual pointers. -extern u8* g_heap; ///< Main memory +extern u8* g_heap_gsp; ///< GSP heap (main memory) +extern u8* g_heap; ///< Application heap (main memory) extern u8* g_vram; ///< Video memory (VRAM) void Init(); diff --git a/src/core/mem_map_funcs.cpp b/src/core/mem_map_funcs.cpp index 40d9dab3a..5ab1b6e92 100644 --- a/src/core/mem_map_funcs.cpp +++ b/src/core/mem_map_funcs.cpp @@ -40,6 +40,10 @@ inline void _Read(T &var, const u32 addr) { } else if ((vaddr & 0xFF000000) == 0x10000000 || (vaddr & 0xFF000000) == 0x1E000000) { HW::Read(var, vaddr); + // FCRAM - GSP heap + } else if ((vaddr > HEAP_GSP_VADDR) && (vaddr < HEAP_GSP_VADDR_END)) { + var = *((const T*)&g_heap_gsp[vaddr & HEAP_GSP_MASK]); + // FCRAM - application heap } else if ((vaddr > HEAP_VADDR) && (vaddr < HEAP_VADDR_END)) { var = *((const T*)&g_heap[vaddr & HEAP_MASK]); @@ -68,8 +72,8 @@ inline void _Write(u32 addr, const T data) { HW::Write(vaddr, data); // FCRAM - GSP heap - //} else if ((vaddr > HEAP_GSP_VADDR) && (vaddr < HEAP_VADDR_GSP_END)) { - // *(T*)&g_heap_gsp[vaddr & FCRAM_MASK] = data; + } else if ((vaddr > HEAP_GSP_VADDR) && (vaddr < HEAP_GSP_VADDR_END)) { + *(T*)&g_heap_gsp[vaddr & HEAP_GSP_MASK] = data; // FCRAM - application heap } else if ((vaddr > HEAP_VADDR) && (vaddr < HEAP_VADDR_END)) { @@ -98,8 +102,12 @@ inline void _Write(u32 addr, const T data) { u8 *GetPointer(const u32 addr) { const u32 vaddr = _AddressPhysicalToVirtual(addr); + // FCRAM - GSP heap + if ((vaddr > HEAP_GSP_VADDR) && (vaddr < HEAP_GSP_VADDR_END)) { + return g_heap_gsp + (vaddr & HEAP_GSP_MASK); + // FCRAM - application heap - if ((vaddr > HEAP_VADDR) && (vaddr < HEAP_VADDR_END)) { + } else if ((vaddr > HEAP_VADDR) && (vaddr < HEAP_VADDR_END)) { return g_heap + (vaddr & HEAP_MASK); } else { From fb026f6b46210d9e8cd24458c11c2d3845583a03 Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 17 Apr 2014 21:19:32 -0400 Subject: [PATCH 45/49] moved enums into Memory:: namespace --- src/core/mem_map.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/core/mem_map.h b/src/core/mem_map.h index 9ca05cc4e..9931daece 100644 --- a/src/core/mem_map.h +++ b/src/core/mem_map.h @@ -4,11 +4,11 @@ #pragma once -//////////////////////////////////////////////////////////////////////////////////////////////////// - #include "common/common.h" #include "common/common_types.h" +namespace Memory { + //////////////////////////////////////////////////////////////////////////////////////////////////// enum { @@ -49,8 +49,6 @@ enum { //////////////////////////////////////////////////////////////////////////////////////////////////// -namespace Memory { - // Base is a pointer to the base of the memory map. Yes, some MMU tricks // are used to set up a full GC or Wii memory map in process memory. on // 32-bit, you have to mask your offsets with 0x3FFFFFFF. This means that From 33e7d97d462b95a781a507fc9e3c59c6de063d91 Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 17 Apr 2014 21:40:42 -0400 Subject: [PATCH 46/49] fixed bug in Memory::GetPointer --- src/core/mem_map_funcs.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/mem_map_funcs.cpp b/src/core/mem_map_funcs.cpp index 5ab1b6e92..8e97ef111 100644 --- a/src/core/mem_map_funcs.cpp +++ b/src/core/mem_map_funcs.cpp @@ -103,11 +103,11 @@ u8 *GetPointer(const u32 addr) { const u32 vaddr = _AddressPhysicalToVirtual(addr); // FCRAM - GSP heap - if ((vaddr > HEAP_GSP_VADDR) && (vaddr < HEAP_GSP_VADDR_END)) { + if ((vaddr >= HEAP_GSP_VADDR) && (vaddr < HEAP_GSP_VADDR_END)) { return g_heap_gsp + (vaddr & HEAP_GSP_MASK); // FCRAM - application heap - } else if ((vaddr > HEAP_VADDR) && (vaddr < HEAP_VADDR_END)) { + } else if ((vaddr >= HEAP_VADDR) && (vaddr < HEAP_VADDR_END)) { return g_heap + (vaddr & HEAP_MASK); } else { From b2baafaf8ba760ce2b975391fd04db52ad386e29 Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 17 Apr 2014 23:05:31 -0400 Subject: [PATCH 47/49] added GSP heap memory allocation --- src/core/hle/syscall.cpp | 26 +++++++++++++++++++++++++- src/core/mem_map.h | 25 +++++++++++++++++++++++++ src/core/mem_map_funcs.cpp | 26 ++++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 1 deletion(-) diff --git a/src/core/hle/syscall.cpp b/src/core/hle/syscall.cpp index c5b887795..0cb563955 100644 --- a/src/core/hle/syscall.cpp +++ b/src/core/hle/syscall.cpp @@ -4,6 +4,10 @@ #include +#include "core/mem_map.h" + +#include "core/hw/hw_lcd.h" + #include "core/hle/function_wrappers.h" #include "core/hle/syscall.h" #include "core/hle/service/service.h" @@ -13,6 +17,26 @@ namespace Syscall { +/// Map application or GSP heap memory +Result ControlMemory(void* outaddr, u32 addr0, u32 addr1, u32 size, u32 operation, u32 permissions) { + u32 virtual_address = 0x00000000; + + switch (operation) { + + // Map GSP heap memory? + case 0x00010003: + virtual_address = Memory::MapBlock_HeapGSP(size, operation, permissions); + break; + + // Unknown ControlMemory operation + default: + ERROR_LOG(OSHLE, "Unknown ControlMemory operation %08X", operation); + } + + Core::g_app_core->SetReg(1, Memory::MapBlock_HeapGSP(size, operation, permissions)); + return 0; +} + /// Connect to an OS service given the port name, returns the handle to the port to out Result ConnectToPort(void* out, const char* port_name) { Service::Interface* service = Service::g_manager->FetchFromPortName(port_name); @@ -41,7 +65,7 @@ Result WaitSynchronization1(Handle handle, s64 nanoseconds) { const HLE::FunctionDef Syscall_Table[] = { {0x00, NULL, "Unknown"}, - {0x01, NULL, "ControlMemory"}, + {0x01, WrapI_VUUUUU, "ControlMemory"}, {0x02, NULL, "QueryMemory"}, {0x03, NULL, "ExitProcess"}, {0x04, NULL, "GetProcessAffinityMask"}, diff --git a/src/core/mem_map.h b/src/core/mem_map.h index 9931daece..ab1eb2606 100644 --- a/src/core/mem_map.h +++ b/src/core/mem_map.h @@ -49,6 +49,23 @@ enum { //////////////////////////////////////////////////////////////////////////////////////////////////// +/// Represents a block of heap memory mapped by ControlMemory +struct HeapBlock { + HeapBlock() : base_address(0), address(0), size(0), operation(0), permissions(0) { + } + u32 base_address; + u32 address; + u32 size; + u32 operation; + u32 permissions; + + const u32 GetVirtualAddress() const{ + return base_address + address; + } +}; + +//////////////////////////////////////////////////////////////////////////////////////////////////// + // Base is a pointer to the base of the memory map. Yes, some MMU tricks // are used to set up a full GC or Wii memory map in process memory. on // 32-bit, you have to mask your offsets with 0x3FFFFFFF. This means that @@ -81,6 +98,14 @@ void Write32(const u32 addr, const u32 data); u8* GetPointer(const u32 Address); +/** + * Maps a block of memory on the GSP heap + * @param size Size of block in bytes + * @param operation Control memory operation + * @param permissions Control memory permissions + */ +u32 MapBlock_HeapGSP(u32 size, u32 operation, u32 permissions); + inline const char* GetCharPointer(const u32 address) { return (const char *)GetPointer(address); } diff --git a/src/core/mem_map_funcs.cpp b/src/core/mem_map_funcs.cpp index 8e97ef111..af4cfacbd 100644 --- a/src/core/mem_map_funcs.cpp +++ b/src/core/mem_map_funcs.cpp @@ -2,6 +2,8 @@ // Licensed under GPLv2 // Refer to the license.txt file included. +#include + #include "common/common.h" #include "core/mem_map.h" @@ -10,6 +12,8 @@ namespace Memory { +std::map g_heap_gsp_map; + /// Convert a physical address to virtual address u32 _AddressPhysicalToVirtual(const u32 addr) { // Our memory interface read/write functions assume virtual addresses. Put any physical address @@ -116,6 +120,28 @@ u8 *GetPointer(const u32 addr) { } } +/** + * Maps a block of memory on the GSP heap + * @param size Size of block in bytes + * @param flags Memory allocation flags + */ +u32 MapBlock_HeapGSP(u32 size, u32 operation, u32 permissions) { + HeapBlock block; + + block.base_address = HEAP_GSP_VADDR; + block.size = size; + block.operation = operation; + block.permissions = permissions; + + if (g_heap_gsp_map.size() > 0) { + const HeapBlock last_block = g_heap_gsp_map.rbegin()->second; + block.address = last_block.address + last_block.size; + } + g_heap_gsp_map[block.GetVirtualAddress()] = block; + + return block.GetVirtualAddress(); +} + u8 Read8(const u32 addr) { u8 _var = 0; _Read(_var, addr); From c3a4b4bfca154f3f27830fe747c0fd74f8459d84 Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 17 Apr 2014 23:43:55 -0400 Subject: [PATCH 48/49] added NDMA hardware interface --- src/common/log.h | 2 +- src/common/log_manager.cpp | 2 +- src/core/core.vcxproj | 2 ++ src/core/core.vcxproj.filters | 6 ++++ src/core/hw/hw.cpp | 61 +++++++++++++++++++++++++++++++++-- src/core/hw/ndma.cpp | 48 +++++++++++++++++++++++++++ src/core/hw/ndma.h | 26 +++++++++++++++ 7 files changed, 143 insertions(+), 4 deletions(-) create mode 100644 src/core/hw/ndma.cpp create mode 100644 src/core/hw/ndma.h diff --git a/src/common/log.h b/src/common/log.h index 2eacf05f2..02db8bd55 100644 --- a/src/common/log.h +++ b/src/common/log.h @@ -55,7 +55,7 @@ enum LOG_TYPE { WII_IPC_HID, WII_IPC_HLE, WII_IPC_NET, - WII_IPC_WC24, + NDMA, HLE, RENDER, LCD, diff --git a/src/common/log_manager.cpp b/src/common/log_manager.cpp index b2dbbbdac..8e56deb8f 100644 --- a/src/common/log_manager.cpp +++ b/src/common/log_manager.cpp @@ -67,7 +67,7 @@ LogManager::LogManager() m_Log[LogTypes::RENDER] = new LogContainer("RENDER", "RENDER"); m_Log[LogTypes::LCD] = new LogContainer("LCD", "LCD"); m_Log[LogTypes::WII_IPC_NET] = new LogContainer("WII_IPC_NET", "WII IPC NET"); - m_Log[LogTypes::WII_IPC_WC24] = new LogContainer("WII_IPC_WC24", "WII IPC WC24"); + m_Log[LogTypes::NDMA] = new LogContainer("NDMA", "NDMA"); m_Log[LogTypes::HLE] = new LogContainer("HLE", "High Level Emulation"); m_Log[LogTypes::HW] = new LogContainer("HW", "Hardware"); m_Log[LogTypes::ACTIONREPLAY] = new LogContainer("ActionReplay", "ActionReplay"); diff --git a/src/core/core.vcxproj b/src/core/core.vcxproj index caf827be4..80bd75eeb 100644 --- a/src/core/core.vcxproj +++ b/src/core/core.vcxproj @@ -161,6 +161,7 @@ + @@ -199,6 +200,7 @@ + diff --git a/src/core/core.vcxproj.filters b/src/core/core.vcxproj.filters index 0a5b5a188..61cb6e405 100644 --- a/src/core/core.vcxproj.filters +++ b/src/core/core.vcxproj.filters @@ -102,6 +102,9 @@ hle\service + + hw + @@ -199,6 +202,9 @@ hle\service + + hw + diff --git a/src/core/hw/hw.cpp b/src/core/hw/hw.cpp index 59c348ca9..1f240f09c 100644 --- a/src/core/hw/hw.cpp +++ b/src/core/hw/hw.cpp @@ -7,17 +7,72 @@ #include "core/hw/hw.h" #include "core/hw/hw_lcd.h" +#include "core/hw/ndma.h" namespace HW { +enum { + ADDRESS_CONFIG = 0x10000000, + ADDRESS_IRQ = 0x10001000, + ADDRESS_NDMA = 0x10002000, + ADDRESS_TIMER = 0x10003000, + ADDRESS_CTRCARD = 0x10004000, + ADDRESS_CTRCARD_2 = 0x10005000, + ADDRESS_SDMC_NAND = 0x10006000, + ADDRESS_SDMC_NAND_2 = 0x10007000, // Apparently not used on retail + ADDRESS_PXI = 0x10008000, + ADDRESS_AES = 0x10009000, + ADDRESS_SHA = 0x1000A000, + ADDRESS_RSA = 0x1000B000, + ADDRESS_XDMA = 0x1000C000, + ADDRESS_SPICARD = 0x1000D800, + ADDRESS_CONFIG_2 = 0x10010000, + ADDRESS_HASH = 0x10101000, + ADDRESS_CSND = 0x10103000, + ADDRESS_DSP = 0x10140000, + ADDRESS_PDN = 0x10141000, + ADDRESS_CODEC = 0x10141000, + ADDRESS_SPI = 0x10142000, + ADDRESS_SPI_2 = 0x10143000, + ADDRESS_I2C = 0x10144000, + ADDRESS_CODEC_2 = 0x10145000, + ADDRESS_HID = 0x10146000, + ADDRESS_PAD = 0x10146000, + ADDRESS_PTM = 0x10146000, + ADDRESS_I2C_2 = 0x10148000, + ADDRESS_SPI_3 = 0x10160000, + ADDRESS_I2C_3 = 0x10161000, + ADDRESS_MIC = 0x10162000, + ADDRESS_PXI_2 = 0x10163000, + ADDRESS_NTRCARD = 0x10164000, + ADDRESS_DSP_2 = 0x10203000, + ADDRESS_HASH_2 = 0x10301000, +}; + template inline void Read(T &var, const u32 addr) { - NOTICE_LOG(HW, "read from address %08X", addr); + switch (addr & 0xFFFFF000) { + + case ADDRESS_NDMA: + NDMA::Read(var, addr); + break; + + default: + ERROR_LOG(HW, "unknown Read%d @ 0x%08X", sizeof(var) * 8, addr); + } } template inline void Write(u32 addr, const T data) { - NOTICE_LOG(HW, "write to address %08X", addr); + switch (addr & 0xFFFFF000) { + + case ADDRESS_NDMA: + NDMA::Write(addr, data); + break; + + default: + ERROR_LOG(HW, "unknown Write%d 0x%08X @ 0x%08X", sizeof(data) * 8, data, addr); + } } // Explicitly instantiate template functions because we aren't defining this in the header: @@ -35,11 +90,13 @@ template void Write(u32 addr, const u8 data); /// Update hardware void Update() { LCD::Update(); + NDMA::Update(); } /// Initialize hardware void Init() { LCD::Init(); + NDMA::Init(); NOTICE_LOG(HW, "initialized OK"); } diff --git a/src/core/hw/ndma.cpp b/src/core/hw/ndma.cpp new file mode 100644 index 000000000..52e459ebd --- /dev/null +++ b/src/core/hw/ndma.cpp @@ -0,0 +1,48 @@ +// Copyright 2014 Citra Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#include "common/common_types.h" +#include "common/log.h" + +#include "core/hw/ndma.h" + +namespace NDMA { + +template +inline void Read(T &var, const u32 addr) { + ERROR_LOG(NDMA, "unknown Read%d @ 0x%08X", sizeof(var) * 8, addr); +} + +template +inline void Write(u32 addr, const T data) { + ERROR_LOG(NDMA, "unknown Write%d 0x%08X @ 0x%08X", sizeof(data) * 8, data, addr); +} + +// Explicitly instantiate template functions because we aren't defining this in the header: + +template void Read(u64 &var, const u32 addr); +template void Read(u32 &var, const u32 addr); +template void Read(u16 &var, const u32 addr); +template void Read(u8 &var, const u32 addr); + +template void Write(u32 addr, const u64 data); +template void Write(u32 addr, const u32 data); +template void Write(u32 addr, const u16 data); +template void Write(u32 addr, const u8 data); + +/// Update hardware +void Update() { +} + +/// Initialize hardware +void Init() { + NOTICE_LOG(LCD, "initialized OK"); +} + +/// Shutdown hardware +void Shutdown() { + NOTICE_LOG(LCD, "shutdown OK"); +} + +} // namespace diff --git a/src/core/hw/ndma.h b/src/core/hw/ndma.h new file mode 100644 index 000000000..d8fa3d40b --- /dev/null +++ b/src/core/hw/ndma.h @@ -0,0 +1,26 @@ +// Copyright 2014 Citra Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#pragma once + +#include "common/common_types.h" + +namespace NDMA { + +template +inline void Read(T &var, const u32 addr); + +template +inline void Write(u32 addr, const T data); + +/// Update hardware +void Update(); + +/// Initialize hardware +void Init(); + +/// Shutdown hardware +void Shutdown(); + +} // namespace From 70c2cce963264678b5ba5b6aa17c2653bf459e61 Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 17 Apr 2014 23:48:23 -0400 Subject: [PATCH 49/49] renamed hw_lcd module to just lcd --- src/core/core.vcxproj | 4 ++-- src/core/core.vcxproj.filters | 12 ++++++------ src/core/hle/syscall.cpp | 2 -- src/core/hw/hw.cpp | 2 +- src/core/hw/{hw_lcd.cpp => lcd.cpp} | 2 +- src/core/hw/{hw_lcd.h => lcd.h} | 0 src/video_core/renderer_opengl/renderer_opengl.cpp | 2 +- 7 files changed, 11 insertions(+), 13 deletions(-) rename src/core/hw/{hw_lcd.cpp => lcd.cpp} (97%) rename src/core/hw/{hw_lcd.h => lcd.h} (100%) diff --git a/src/core/core.vcxproj b/src/core/core.vcxproj index 80bd75eeb..b6fc604c6 100644 --- a/src/core/core.vcxproj +++ b/src/core/core.vcxproj @@ -160,7 +160,7 @@ - + @@ -199,7 +199,7 @@ - + diff --git a/src/core/core.vcxproj.filters b/src/core/core.vcxproj.filters index 61cb6e405..ff7877feb 100644 --- a/src/core/core.vcxproj.filters +++ b/src/core/core.vcxproj.filters @@ -69,9 +69,6 @@ hw - - hw - elf @@ -105,6 +102,9 @@ hw + + hw + @@ -161,9 +161,6 @@ hw - - hw - elf @@ -205,6 +202,9 @@ hw + + hw + diff --git a/src/core/hle/syscall.cpp b/src/core/hle/syscall.cpp index 0cb563955..e5533a741 100644 --- a/src/core/hle/syscall.cpp +++ b/src/core/hle/syscall.cpp @@ -6,8 +6,6 @@ #include "core/mem_map.h" -#include "core/hw/hw_lcd.h" - #include "core/hle/function_wrappers.h" #include "core/hle/syscall.h" #include "core/hle/service/service.h" diff --git a/src/core/hw/hw.cpp b/src/core/hw/hw.cpp index 1f240f09c..16bd70125 100644 --- a/src/core/hw/hw.cpp +++ b/src/core/hw/hw.cpp @@ -6,7 +6,7 @@ #include "common/log.h" #include "core/hw/hw.h" -#include "core/hw/hw_lcd.h" +#include "core/hw/lcd.h" #include "core/hw/ndma.h" namespace HW { diff --git a/src/core/hw/hw_lcd.cpp b/src/core/hw/lcd.cpp similarity index 97% rename from src/core/hw/hw_lcd.cpp rename to src/core/hw/lcd.cpp index 9fb485bac..3013673f8 100644 --- a/src/core/hw/hw_lcd.cpp +++ b/src/core/hw/lcd.cpp @@ -6,7 +6,7 @@ #include "common/log.h" #include "core/core.h" -#include "core/hw/hw_lcd.h" +#include "core/hw/lcd.h" #include "video_core/video_core.h" diff --git a/src/core/hw/hw_lcd.h b/src/core/hw/lcd.h similarity index 100% rename from src/core/hw/hw_lcd.h rename to src/core/hw/lcd.h diff --git a/src/video_core/renderer_opengl/renderer_opengl.cpp b/src/video_core/renderer_opengl/renderer_opengl.cpp index 168de9253..35804aee1 100644 --- a/src/video_core/renderer_opengl/renderer_opengl.cpp +++ b/src/video_core/renderer_opengl/renderer_opengl.cpp @@ -2,7 +2,7 @@ // Licensed under GPLv2 // Refer to the license.txt file included. -#include "core/hw/hw_lcd.h" +#include "core/hw/lcd.h" #include "video_core/video_core.h" #include "video_core/renderer_opengl/renderer_opengl.h"