diff options
| author | 2015-01-25 22:56:17 -0800 | |
|---|---|---|
| committer | 2015-02-09 21:47:12 -0800 | |
| commit | 5fcbfc06eb247c0a4c1db201ac9050d80d4e4020 (patch) | |
| tree | 4cdac59449b025c7a07e8655f29eda2fbcb423fe /src/core/arm | |
| parent | Merge pull request #551 from bunnei/mutex-fixes (diff) | |
| download | yuzu-5fcbfc06eb247c0a4c1db201ac9050d80d4e4020.tar.gz yuzu-5fcbfc06eb247c0a4c1db201ac9050d80d4e4020.tar.xz yuzu-5fcbfc06eb247c0a4c1db201ac9050d80d4e4020.zip | |
Scheduler refactor Pt. 1
* Simplifies scheduling logic, specifically regarding thread status. It should be much clearer which statuses are valid
for a thread at any given point in the system.
* Removes dead code from thread.cpp.
* Moves the implementation of resetting a ThreadContext to the corresponding core's implementation.
Other changes:
* Fixed comments in arm interfaces.
* Updated comments in thread.cpp
* Removed confusing, useless, functions like MakeReady() and ChangeStatus() from thread.cpp.
* Removed stack_size from Thread. In the CTR kernel, the thread's stack would be allocated before thread creation.
Diffstat (limited to 'src/core/arm')
| -rw-r--r-- | src/core/arm/arm_interface.h | 9 | ||||
| -rw-r--r-- | src/core/arm/dyncom/arm_dyncom.cpp | 10 | ||||
| -rw-r--r-- | src/core/arm/dyncom/arm_dyncom.h | 57 |
3 files changed, 20 insertions, 56 deletions
diff --git a/src/core/arm/arm_interface.h b/src/core/arm/arm_interface.h index e612f7439..ef37ee055 100644 --- a/src/core/arm/arm_interface.h +++ b/src/core/arm/arm_interface.h | |||
| @@ -86,6 +86,15 @@ public: | |||
| 86 | virtual void AddTicks(u64 ticks) = 0; | 86 | virtual void AddTicks(u64 ticks) = 0; |
| 87 | 87 | ||
| 88 | /** | 88 | /** |
| 89 | * Initializes a CPU context for use on this CPU | ||
| 90 | * @param context Thread context to reset | ||
| 91 | * @param stack_top Pointer to the top of the stack | ||
| 92 | * @param entry_point Entry point for execution | ||
| 93 | * @param arg User argument for thread | ||
| 94 | */ | ||
| 95 | virtual void ResetContext(Core::ThreadContext& context, u32 stack_top, u32 entry_point, u32 arg) = 0; | ||
| 96 | |||
| 97 | /** | ||
| 89 | * Saves the current CPU context | 98 | * Saves the current CPU context |
| 90 | * @param ctx Thread context to save | 99 | * @param ctx Thread context to save |
| 91 | */ | 100 | */ |
diff --git a/src/core/arm/dyncom/arm_dyncom.cpp b/src/core/arm/dyncom/arm_dyncom.cpp index f6628ca33..68fddc94f 100644 --- a/src/core/arm/dyncom/arm_dyncom.cpp +++ b/src/core/arm/dyncom/arm_dyncom.cpp | |||
| @@ -93,6 +93,16 @@ void ARM_DynCom::ExecuteInstructions(int num_instructions) { | |||
| 93 | AddTicks(ticks_executed); | 93 | AddTicks(ticks_executed); |
| 94 | } | 94 | } |
| 95 | 95 | ||
| 96 | void ARM_DynCom::ResetContext(Core::ThreadContext& context, u32 stack_top, u32 entry_point, u32 arg) { | ||
| 97 | memset(&context, 0, sizeof(Core::ThreadContext)); | ||
| 98 | |||
| 99 | context.cpu_registers[0] = arg; | ||
| 100 | context.pc = entry_point; | ||
| 101 | context.sp = stack_top; | ||
| 102 | context.cpsr = 0x1F; // Usermode | ||
| 103 | context.mode = 8; // Instructs dyncom CPU core to start execution as if it's "resuming" a thread. | ||
| 104 | } | ||
| 105 | |||
| 96 | void ARM_DynCom::SaveContext(Core::ThreadContext& ctx) { | 106 | void ARM_DynCom::SaveContext(Core::ThreadContext& ctx) { |
| 97 | memcpy(ctx.cpu_registers, state->Reg, sizeof(ctx.cpu_registers)); | 107 | memcpy(ctx.cpu_registers, state->Reg, sizeof(ctx.cpu_registers)); |
| 98 | memcpy(ctx.fpu_registers, state->ExtReg, sizeof(ctx.fpu_registers)); | 108 | memcpy(ctx.fpu_registers, state->ExtReg, sizeof(ctx.fpu_registers)); |
diff --git a/src/core/arm/dyncom/arm_dyncom.h b/src/core/arm/dyncom/arm_dyncom.h index f16fb070c..9e2dda843 100644 --- a/src/core/arm/dyncom/arm_dyncom.h +++ b/src/core/arm/dyncom/arm_dyncom.h | |||
| @@ -13,79 +13,24 @@ | |||
| 13 | 13 | ||
| 14 | class ARM_DynCom final : virtual public ARM_Interface { | 14 | class ARM_DynCom final : virtual public ARM_Interface { |
| 15 | public: | 15 | public: |
| 16 | |||
| 17 | ARM_DynCom(); | 16 | ARM_DynCom(); |
| 18 | ~ARM_DynCom(); | 17 | ~ARM_DynCom(); |
| 19 | 18 | ||
| 20 | /** | ||
| 21 | * Set the Program Counter to an address | ||
| 22 | * @param pc Address to set PC to | ||
| 23 | */ | ||
| 24 | void SetPC(u32 pc) override; | 19 | void SetPC(u32 pc) override; |
| 25 | |||
| 26 | /* | ||
| 27 | * Get the current Program Counter | ||
| 28 | * @return Returns current PC | ||
| 29 | */ | ||
| 30 | u32 GetPC() const override; | 20 | u32 GetPC() const override; |
| 31 | |||
| 32 | /** | ||
| 33 | * Get an ARM register | ||
| 34 | * @param index Register index (0-15) | ||
| 35 | * @return Returns the value in the register | ||
| 36 | */ | ||
| 37 | u32 GetReg(int index) const override; | 21 | u32 GetReg(int index) const override; |
| 38 | |||
| 39 | /** | ||
| 40 | * Set an ARM register | ||
| 41 | * @param index Register index (0-15) | ||
| 42 | * @param value Value to set register to | ||
| 43 | */ | ||
| 44 | void SetReg(int index, u32 value) override; | 22 | void SetReg(int index, u32 value) override; |
| 45 | |||
| 46 | /** | ||
| 47 | * Get the current CPSR register | ||
| 48 | * @return Returns the value of the CPSR register | ||
| 49 | */ | ||
| 50 | u32 GetCPSR() const override; | 23 | u32 GetCPSR() const override; |
| 51 | |||
| 52 | /** | ||
| 53 | * Set the current CPSR register | ||
| 54 | * @param cpsr Value to set CPSR to | ||
| 55 | */ | ||
| 56 | void SetCPSR(u32 cpsr) override; | 24 | void SetCPSR(u32 cpsr) override; |
| 57 | 25 | ||
| 58 | /** | ||
| 59 | * Returns the number of clock ticks since the last reset | ||
| 60 | * @return Returns number of clock ticks | ||
| 61 | */ | ||
| 62 | u64 GetTicks() const override; | 26 | u64 GetTicks() const override; |
| 63 | |||
| 64 | /** | ||
| 65 | * Advance the CPU core by the specified number of ticks (e.g. to simulate CPU execution time) | ||
| 66 | * @param ticks Number of ticks to advance the CPU core | ||
| 67 | */ | ||
| 68 | void AddTicks(u64 ticks) override; | 27 | void AddTicks(u64 ticks) override; |
| 69 | 28 | ||
| 70 | /** | 29 | void ResetContext(Core::ThreadContext& context, u32 stack_top, u32 entry_point, u32 arg); |
| 71 | * Saves the current CPU context | ||
| 72 | * @param ctx Thread context to save | ||
| 73 | */ | ||
| 74 | void SaveContext(Core::ThreadContext& ctx) override; | 30 | void SaveContext(Core::ThreadContext& ctx) override; |
| 75 | |||
| 76 | /** | ||
| 77 | * Loads a CPU context | ||
| 78 | * @param ctx Thread context to load | ||
| 79 | */ | ||
| 80 | void LoadContext(const Core::ThreadContext& ctx) override; | 31 | void LoadContext(const Core::ThreadContext& ctx) override; |
| 81 | 32 | ||
| 82 | /// Prepare core for thread reschedule (if needed to correctly handle state) | ||
| 83 | void PrepareReschedule() override; | 33 | void PrepareReschedule() override; |
| 84 | |||
| 85 | /** | ||
| 86 | * Executes the given number of instructions | ||
| 87 | * @param num_instructions Number of instructions to executes | ||
| 88 | */ | ||
| 89 | void ExecuteInstructions(int num_instructions) override; | 34 | void ExecuteInstructions(int num_instructions) override; |
| 90 | 35 | ||
| 91 | private: | 36 | private: |