diff options
| author | 2014-04-04 22:26:06 -0400 | |
|---|---|---|
| committer | 2014-04-04 22:26:06 -0400 | |
| commit | 69223d007ef70cbcbe4b0db47c00b2f4837f5d23 (patch) | |
| tree | c2ec7aceaae8a70a938bd419e31d78ac632907c9 | |
| parent | renamed ARM disassembler class from "Arm" to "ARM_Disasm" (diff) | |
| download | yuzu-69223d007ef70cbcbe4b0db47c00b2f4837f5d23.tar.gz yuzu-69223d007ef70cbcbe4b0db47c00b2f4837f5d23.tar.xz yuzu-69223d007ef70cbcbe4b0db47c00b2f4837f5d23.zip | |
- added an interface layer for ARM cores
- cleaned up core.cpp a bit
| -rw-r--r-- | src/core/core.vcxproj | 3 | ||||
| -rw-r--r-- | src/core/core.vcxproj.filters | 9 | ||||
| -rw-r--r-- | src/core/src/arm/arm_interface.h | 47 | ||||
| -rw-r--r-- | src/core/src/arm/interpreter/arm_interpreter.cpp | 86 | ||||
| -rw-r--r-- | src/core/src/arm/interpreter/arm_interpreter.h | 50 | ||||
| -rw-r--r-- | src/core/src/core.cpp | 87 | ||||
| -rw-r--r-- | src/core/src/core.h | 8 |
7 files changed, 213 insertions, 77 deletions
diff --git a/src/core/core.vcxproj b/src/core/core.vcxproj index 4cd55c575..bee9f3046 100644 --- a/src/core/core.vcxproj +++ b/src/core/core.vcxproj | |||
| @@ -144,6 +144,7 @@ | |||
| 144 | <ClCompile Include="src\arm\interpreter\armos.cpp" /> | 144 | <ClCompile Include="src\arm\interpreter\armos.cpp" /> |
| 145 | <ClCompile Include="src\arm\interpreter\armsupp.cpp" /> | 145 | <ClCompile Include="src\arm\interpreter\armsupp.cpp" /> |
| 146 | <ClCompile Include="src\arm\interpreter\armvirt.cpp" /> | 146 | <ClCompile Include="src\arm\interpreter\armvirt.cpp" /> |
| 147 | <ClCompile Include="src\arm\interpreter\arm_interpreter.cpp" /> | ||
| 147 | <ClCompile Include="src\arm\interpreter\thumbemu.cpp" /> | 148 | <ClCompile Include="src\arm\interpreter\thumbemu.cpp" /> |
| 148 | <ClCompile Include="src\arm\mmu\arm1176jzf_s_mmu.cpp" /> | 149 | <ClCompile Include="src\arm\mmu\arm1176jzf_s_mmu.cpp" /> |
| 149 | <ClCompile Include="src\core.cpp" /> | 150 | <ClCompile Include="src\core.cpp" /> |
| @@ -157,12 +158,14 @@ | |||
| 157 | <ClCompile Include="src\system.cpp" /> | 158 | <ClCompile Include="src\system.cpp" /> |
| 158 | </ItemGroup> | 159 | </ItemGroup> |
| 159 | <ItemGroup> | 160 | <ItemGroup> |
| 161 | <ClInclude Include="src\arm\arm_interface.h" /> | ||
| 160 | <ClInclude Include="src\arm\disassembler\arm_disasm.h" /> | 162 | <ClInclude Include="src\arm\disassembler\arm_disasm.h" /> |
| 161 | <ClInclude Include="src\arm\interpreter\armcpu.h" /> | 163 | <ClInclude Include="src\arm\interpreter\armcpu.h" /> |
| 162 | <ClInclude Include="src\arm\interpreter\armdefs.h" /> | 164 | <ClInclude Include="src\arm\interpreter\armdefs.h" /> |
| 163 | <ClInclude Include="src\arm\interpreter\armemu.h" /> | 165 | <ClInclude Include="src\arm\interpreter\armemu.h" /> |
| 164 | <ClInclude Include="src\arm\interpreter\armmmu.h" /> | 166 | <ClInclude Include="src\arm\interpreter\armmmu.h" /> |
| 165 | <ClInclude Include="src\arm\interpreter\armos.h" /> | 167 | <ClInclude Include="src\arm\interpreter\armos.h" /> |
| 168 | <ClInclude Include="src\arm\interpreter\arm_interpreter.h" /> | ||
| 166 | <ClInclude Include="src\arm\interpreter\arm_regformat.h" /> | 169 | <ClInclude Include="src\arm\interpreter\arm_regformat.h" /> |
| 167 | <ClInclude Include="src\arm\interpreter\skyeye_defs.h" /> | 170 | <ClInclude Include="src\arm\interpreter\skyeye_defs.h" /> |
| 168 | <ClInclude Include="src\arm\mmu\arm1176jzf_s_mmu.h" /> | 171 | <ClInclude Include="src\arm\mmu\arm1176jzf_s_mmu.h" /> |
diff --git a/src/core/core.vcxproj.filters b/src/core/core.vcxproj.filters index fe583127a..45ddf8cf6 100644 --- a/src/core/core.vcxproj.filters +++ b/src/core/core.vcxproj.filters | |||
| @@ -43,6 +43,9 @@ | |||
| 43 | <ClCompile Include="src\arm\interpreter\thumbemu.cpp"> | 43 | <ClCompile Include="src\arm\interpreter\thumbemu.cpp"> |
| 44 | <Filter>arm\interpreter</Filter> | 44 | <Filter>arm\interpreter</Filter> |
| 45 | </ClCompile> | 45 | </ClCompile> |
| 46 | <ClCompile Include="src\arm\interpreter\arm_interpreter.cpp"> | ||
| 47 | <Filter>arm\interpreter</Filter> | ||
| 48 | </ClCompile> | ||
| 46 | </ItemGroup> | 49 | </ItemGroup> |
| 47 | <ItemGroup> | 50 | <ItemGroup> |
| 48 | <Filter Include="arm"> | 51 | <Filter Include="arm"> |
| @@ -127,6 +130,12 @@ | |||
| 127 | <ClInclude Include="src\arm\interpreter\skyeye_defs.h"> | 130 | <ClInclude Include="src\arm\interpreter\skyeye_defs.h"> |
| 128 | <Filter>arm\interpreter</Filter> | 131 | <Filter>arm\interpreter</Filter> |
| 129 | </ClInclude> | 132 | </ClInclude> |
| 133 | <ClInclude Include="src\arm\arm_interface.h"> | ||
| 134 | <Filter>arm</Filter> | ||
| 135 | </ClInclude> | ||
| 136 | <ClInclude Include="src\arm\interpreter\arm_interpreter.h"> | ||
| 137 | <Filter>arm\interpreter</Filter> | ||
| 138 | </ClInclude> | ||
| 130 | </ItemGroup> | 139 | </ItemGroup> |
| 131 | <ItemGroup> | 140 | <ItemGroup> |
| 132 | <None Include="CMakeLists.txt" /> | 141 | <None Include="CMakeLists.txt" /> |
diff --git a/src/core/src/arm/arm_interface.h b/src/core/src/arm/arm_interface.h new file mode 100644 index 000000000..785234396 --- /dev/null +++ b/src/core/src/arm/arm_interface.h | |||
| @@ -0,0 +1,47 @@ | |||
| 1 | /** | ||
| 2 | * Copyright (C) 2013 Citrus Emulator | ||
| 3 | * | ||
| 4 | * @file arm_interface.h | ||
| 5 | * @author bunnei | ||
| 6 | * @date 2014-04-04 | ||
| 7 | * @brief Generic ARM CPU core interface | ||
| 8 | * | ||
| 9 | * @section LICENSE | ||
| 10 | * This program is free software; you can redistribute it and/or | ||
| 11 | * modify it under the terms of the GNU General Public License as | ||
| 12 | * published by the Free Software Foundation; either version 2 of | ||
| 13 | * the License, or (at your option) any later version. | ||
| 14 | * | ||
| 15 | * This program is distributed in the hope that it will be useful, but | ||
| 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 18 | * General Public License for more details at | ||
| 19 | * http://www.gnu.org/copyleft/gpl.html | ||
| 20 | * | ||
| 21 | * Official project repository can be found at: | ||
| 22 | * http://code.google.com/p/gekko-gc-emu/ | ||
| 23 | */ | ||
| 24 | |||
| 25 | #pragma once | ||
| 26 | |||
| 27 | #include "common_types.h" | ||
| 28 | |||
| 29 | /// Generic ARM11 CPU interface | ||
| 30 | class ARM_Interface { | ||
| 31 | public: | ||
| 32 | ARM_Interface() { | ||
| 33 | } | ||
| 34 | |||
| 35 | ~ARM_Interface() { | ||
| 36 | } | ||
| 37 | |||
| 38 | virtual void ExecuteInstruction() = 0; | ||
| 39 | |||
| 40 | virtual void SetPC(u32 pc) = 0; | ||
| 41 | |||
| 42 | virtual u32 PC() = 0; | ||
| 43 | |||
| 44 | virtual u32 Reg(int index) = 0; | ||
| 45 | |||
| 46 | virtual u32 CPSR() = 0; | ||
| 47 | }; | ||
diff --git a/src/core/src/arm/interpreter/arm_interpreter.cpp b/src/core/src/arm/interpreter/arm_interpreter.cpp new file mode 100644 index 000000000..930506963 --- /dev/null +++ b/src/core/src/arm/interpreter/arm_interpreter.cpp | |||
| @@ -0,0 +1,86 @@ | |||
| 1 | /** | ||
| 2 | * Copyright (C) 2013 Citrus Emulator | ||
| 3 | * | ||
| 4 | * @file arm_interpreter.h | ||
| 5 | * @author bunnei | ||
| 6 | * @date 2014-04-04 | ||
| 7 | * @brief ARM interface instance for SkyEye interprerer | ||
| 8 | * | ||
| 9 | * @section LICENSE | ||
| 10 | * This program is free software; you can redistribute it and/or | ||
| 11 | * modify it under the terms of the GNU General Public License as | ||
| 12 | * published by the Free Software Foundation; either version 2 of | ||
| 13 | * the License, or (at your option) any later version. | ||
| 14 | * | ||
| 15 | * This program is distributed in the hope that it will be useful, but | ||
| 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 18 | * General Public License for more details at | ||
| 19 | * http://www.gnu.org/copyleft/gpl.html | ||
| 20 | * | ||
| 21 | * Official project repository can be found at: | ||
| 22 | * http://code.google.com/p/gekko-gc-emu/ | ||
| 23 | */ | ||
| 24 | |||
| 25 | #include "arm_interpreter.h" | ||
| 26 | |||
| 27 | const static cpu_config_t s_arm11_cpu_info = { | ||
| 28 | "armv6", "arm11", 0x0007b000, 0x0007f000, NONCACHE | ||
| 29 | }; | ||
| 30 | |||
| 31 | ARM_Interpreter::ARM_Interpreter() { | ||
| 32 | |||
| 33 | state = new ARMul_State; | ||
| 34 | |||
| 35 | ARMul_EmulateInit(); | ||
| 36 | ARMul_NewState(state); | ||
| 37 | |||
| 38 | state->abort_model = 0; | ||
| 39 | state->cpu = (cpu_config_t*)&s_arm11_cpu_info; | ||
| 40 | state->bigendSig = LOW; | ||
| 41 | |||
| 42 | ARMul_SelectProcessor(state, ARM_v6_Prop | ARM_v5_Prop | ARM_v5e_Prop); | ||
| 43 | state->lateabtSig = LOW; | ||
| 44 | mmu_init(state); | ||
| 45 | |||
| 46 | // Reset the core to initial state | ||
| 47 | ARMul_Reset(state); | ||
| 48 | state->NextInstr = 0; | ||
| 49 | state->Emulate = 3; | ||
| 50 | |||
| 51 | state->pc = state->Reg[15] = 0x00000000; | ||
| 52 | state->Reg[13] = 0x10000000; // Set stack pointer to the top of the stack | ||
| 53 | } | ||
| 54 | |||
| 55 | void ARM_Interpreter::SetPC(u32 pc) { | ||
| 56 | state->pc = state->Reg[15] = pc; | ||
| 57 | } | ||
| 58 | |||
| 59 | u32 ARM_Interpreter::PC() { | ||
| 60 | return state->pc; | ||
| 61 | } | ||
| 62 | |||
| 63 | u32 ARM_Interpreter::Reg(int index){ | ||
| 64 | return state->Reg[index]; | ||
| 65 | } | ||
| 66 | |||
| 67 | u32 ARM_Interpreter::CPSR() { | ||
| 68 | return state->Cpsr; | ||
| 69 | } | ||
| 70 | |||
| 71 | ARM_Interpreter::~ARM_Interpreter() { | ||
| 72 | delete state; | ||
| 73 | } | ||
| 74 | |||
| 75 | void ARM_Interpreter::ExecuteInstruction() { | ||
| 76 | state->step++; | ||
| 77 | state->cycle++; | ||
| 78 | state->EndCondition = 0; | ||
| 79 | state->stop_simulator = 0; | ||
| 80 | state->NextInstr = RESUME; | ||
| 81 | state->last_pc = state->Reg[15]; | ||
| 82 | state->Reg[15] = ARMul_DoInstr(state); | ||
| 83 | state->Cpsr = ((state->Cpsr & 0x0fffffdf) | (state->NFlag << 31) | (state->ZFlag << 30) | | ||
| 84 | (state->CFlag << 29) | (state->VFlag << 28) | (state->TFlag << 5)); | ||
| 85 | FLUSHPIPE; | ||
| 86 | } | ||
diff --git a/src/core/src/arm/interpreter/arm_interpreter.h b/src/core/src/arm/interpreter/arm_interpreter.h new file mode 100644 index 000000000..89f871fa9 --- /dev/null +++ b/src/core/src/arm/interpreter/arm_interpreter.h | |||
| @@ -0,0 +1,50 @@ | |||
| 1 | /** | ||
| 2 | * Copyright (C) 2013 Citrus Emulator | ||
| 3 | * | ||
| 4 | * @file arm_interpreter.h | ||
| 5 | * @author bunnei | ||
| 6 | * @date 2014-04-04 | ||
| 7 | * @brief ARM interface instance for SkyEye interprerer | ||
| 8 | * | ||
| 9 | * @section LICENSE | ||
| 10 | * This program is free software; you can redistribute it and/or | ||
| 11 | * modify it under the terms of the GNU General Public License as | ||
| 12 | * published by the Free Software Foundation; either version 2 of | ||
| 13 | * the License, or (at your option) any later version. | ||
| 14 | * | ||
| 15 | * This program is distributed in the hope that it will be useful, but | ||
| 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 18 | * General Public License for more details at | ||
| 19 | * http://www.gnu.org/copyleft/gpl.html | ||
| 20 | * | ||
| 21 | * Official project repository can be found at: | ||
| 22 | * http://code.google.com/p/gekko-gc-emu/ | ||
| 23 | */ | ||
| 24 | |||
| 25 | #pragma once | ||
| 26 | |||
| 27 | #include "common_types.h" | ||
| 28 | #include "arm/arm_interface.h" | ||
| 29 | |||
| 30 | #include "arm/interpreter/armdefs.h" | ||
| 31 | #include "arm/interpreter/armemu.h" | ||
| 32 | |||
| 33 | class ARM_Interpreter : virtual public ARM_Interface { | ||
| 34 | public: | ||
| 35 | ARM_Interpreter(); | ||
| 36 | ~ARM_Interpreter(); | ||
| 37 | |||
| 38 | void ExecuteInstruction(); | ||
| 39 | |||
| 40 | void SetPC(u32 pc); | ||
| 41 | |||
| 42 | u32 PC(); | ||
| 43 | |||
| 44 | u32 Reg(int index); | ||
| 45 | |||
| 46 | u32 CPSR(); | ||
| 47 | |||
| 48 | private: | ||
| 49 | ARMul_State* state; | ||
| 50 | }; | ||
diff --git a/src/core/src/core.cpp b/src/core/src/core.cpp index edae66b9f..592805134 100644 --- a/src/core/src/core.cpp +++ b/src/core/src/core.cpp | |||
| @@ -25,28 +25,14 @@ | |||
| 25 | #include "log.h" | 25 | #include "log.h" |
| 26 | #include "core.h" | 26 | #include "core.h" |
| 27 | #include "mem_map.h" | 27 | #include "mem_map.h" |
| 28 | #include "arm/armdefs.h" | ||
| 29 | #include "arm/armemu.h" | ||
| 30 | #include "arm/disassembler/arm_disasm.h" | 28 | #include "arm/disassembler/arm_disasm.h" |
| 29 | #include "arm/interpreter/arm_interpreter.h" | ||
| 31 | 30 | ||
| 32 | namespace Core { | 31 | namespace Core { |
| 33 | 32 | ||
| 34 | typedef struct arm11_core{ | 33 | ARM_Disasm* g_disasm = NULL; ///< ARM disassembler |
| 35 | conf_object_t* obj; | 34 | ARM_Interface* g_app_core = NULL; ///< ARM11 application core |
| 36 | ARMul_State* state; | 35 | ARM_Interface* g_sys_core = NULL; ///< ARM11 system (OS) core |
| 37 | memory_space_intf* space; | ||
| 38 | }arm11_core_t; | ||
| 39 | |||
| 40 | arm11_core* core = NULL; | ||
| 41 | |||
| 42 | Arm* disasm = NULL; | ||
| 43 | |||
| 44 | //ARMul_State* g_arm_state = NULL; | ||
| 45 | |||
| 46 | /// Start the core | ||
| 47 | void Start() { | ||
| 48 | // TODO(ShizZy): ImplementMe | ||
| 49 | } | ||
| 50 | 36 | ||
| 51 | /// Run the core CPU loop | 37 | /// Run the core CPU loop |
| 52 | void RunLoop() { | 38 | void RunLoop() { |
| @@ -55,23 +41,7 @@ void RunLoop() { | |||
| 55 | 41 | ||
| 56 | /// Step the CPU one instruction | 42 | /// Step the CPU one instruction |
| 57 | void SingleStep() { | 43 | void SingleStep() { |
| 58 | ARMul_State *state = core->state; | 44 | g_app_core->ExecuteInstruction(); |
| 59 | |||
| 60 | state->step++; | ||
| 61 | state->cycle++; | ||
| 62 | state->EndCondition = 0; | ||
| 63 | state->stop_simulator = 0; | ||
| 64 | state->NextInstr = RESUME; /* treat as PC change */ | ||
| 65 | state->last_pc = state->Reg[15]; | ||
| 66 | state->Reg[15] = ARMul_DoInstr(state); | ||
| 67 | state->Cpsr = (state->Cpsr & 0x0fffffdf) | \ | ||
| 68 | (state->NFlag << 31) | \ | ||
| 69 | (state->ZFlag << 30) | \ | ||
| 70 | (state->CFlag << 29) | \ | ||
| 71 | (state->VFlag << 28);// | \ | ||
| 72 | //(state->TFlag << 5); | ||
| 73 | |||
| 74 | FLUSHPIPE; | ||
| 75 | } | 45 | } |
| 76 | 46 | ||
| 77 | /// Halt the core | 47 | /// Halt the core |
| @@ -85,55 +55,20 @@ void Stop() { | |||
| 85 | } | 55 | } |
| 86 | 56 | ||
| 87 | /// Initialize the core | 57 | /// Initialize the core |
| 88 | const static cpu_config_t arm11_cpu_info = { "armv6", "arm11", 0x0007b000, 0x0007f000, NONCACHE }; | ||
| 89 | int Init() { | 58 | int Init() { |
| 90 | NOTICE_LOG(MASTER_LOG, "Core initialized OK"); | 59 | NOTICE_LOG(MASTER_LOG, "Core initialized OK"); |
| 91 | 60 | ||
| 92 | disasm = new Arm(); | 61 | g_disasm = new ARM_Disasm(); |
| 93 | core = (arm11_core_t*)malloc(sizeof(arm11_core_t)); | 62 | g_app_core = new ARM_Interpreter(); |
| 94 | //core->obj = new_conf_object(obj_name, core); | 63 | g_sys_core = new ARM_Interpreter(); |
| 95 | ARMul_EmulateInit(); | ||
| 96 | ARMul_State* state = new ARMul_State; | ||
| 97 | ARMul_NewState(state); | ||
| 98 | state->abort_model = 0; | ||
| 99 | state->cpu = (cpu_config_t*)&arm11_cpu_info; | ||
| 100 | state->bigendSig = LOW; | ||
| 101 | |||
| 102 | ARMul_SelectProcessor(state, ARM_v6_Prop | ARM_v5_Prop | ARM_v5e_Prop); | ||
| 103 | state->lateabtSig = LOW; | ||
| 104 | mmu_init(state); | ||
| 105 | /* reset the core to initial state */ | ||
| 106 | ARMul_Reset(state); | ||
| 107 | state->NextInstr = 0; | ||
| 108 | state->Emulate = 3; | ||
| 109 | #if 0 | ||
| 110 | state->mmu.ops.read_byte = arm11_read_byte; | ||
| 111 | state->mmu.ops.read_halfword = arm11_read_halfword; | ||
| 112 | state->mmu.ops.read_word = arm11_read_word; | ||
| 113 | state->mmu.ops.write_byte = arm11_write_byte; | ||
| 114 | state->mmu.ops.write_halfword = arm11_write_halfword; | ||
| 115 | state->mmu.ops.write_word = arm11_write_word; | ||
| 116 | #endif | ||
| 117 | core->state = state; | ||
| 118 | |||
| 119 | state->pc = state->Reg[15] = 0x080c3ee0; // Hardcoded set PC to start address of a homebrew ROM | ||
| 120 | // this is where most launcher.dat code loads /bunnei | ||
| 121 | 64 | ||
| 122 | state->Reg[13] = 0x10000000; // Set stack pointer to the top of the stack, not sure if this is | ||
| 123 | // right? /bunnei | ||
| 124 | |||
| 125 | //state->s | ||
| 126 | return 0; | 65 | return 0; |
| 127 | } | 66 | } |
| 128 | 67 | ||
| 129 | ARMul_State* GetState() | ||
| 130 | { | ||
| 131 | return core->state; | ||
| 132 | } | ||
| 133 | |||
| 134 | void Shutdown() { | 68 | void Shutdown() { |
| 135 | //delete g_arm_state; | 69 | delete g_disasm; |
| 136 | //g_arm_state = NULL; | 70 | delete g_app_core; |
| 71 | delete g_sys_core; | ||
| 137 | } | 72 | } |
| 138 | 73 | ||
| 139 | } // namespace | 74 | } // namespace |
diff --git a/src/core/src/core.h b/src/core/src/core.h index f4a3ca05d..f41daca6a 100644 --- a/src/core/src/core.h +++ b/src/core/src/core.h | |||
| @@ -25,12 +25,18 @@ | |||
| 25 | #ifndef CORE_CORE_H_ | 25 | #ifndef CORE_CORE_H_ |
| 26 | #define CORE_CORE_H_ | 26 | #define CORE_CORE_H_ |
| 27 | 27 | ||
| 28 | #include "arm/armdefs.h" | 28 | #include "arm/arm_interface.h" |
| 29 | #include "arm/interpreter/armdefs.h" | ||
| 29 | 30 | ||
| 30 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 31 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 31 | 32 | ||
| 32 | namespace Core { | 33 | namespace Core { |
| 33 | 34 | ||
| 35 | extern ARM_Interface* g_app_core; ///< ARM11 application core | ||
| 36 | extern ARM_Interface* g_sys_core; ///< ARM11 system (OS) core | ||
| 37 | |||
| 38 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 39 | |||
| 34 | /// Start the core | 40 | /// Start the core |
| 35 | void Start(); | 41 | void Start(); |
| 36 | 42 | ||