ReXGlue SDK
Loading...
Searching...
No Matches
thread_state.h
1
11
12#pragma once
13
14#include <array>
15#include <atomic>
16#include <string>
17
18#include <rex/platform.h>
19#include <rex/types.h>
20#include <rex/kernel/heap.h>
21#include <rex/ppc/context.h>
22
23namespace rex {
24namespace kernel {
25class TitleRuntime;
26} // namespace kernel
27} // namespace rex
28
29namespace rex::kernel {
30
33 std::array<PPCRegister, 32> fpr{};
35 u32 csr = 0;
36 std::array<PPCVRegister, 128> vr{};
37 PPCVSCRRegister vscr;
38};
39
41 public:
50 ThreadState(u32 thread_id, u32 stack_base, u32 pcr_address, GuestAddressSpace* memory,
51 TitleRuntime* runtime);
54
55 GuestAddressSpace* GetAddressSpace() const { return memory_; }
56
58 void RequestStop() { stop_requested_.store(true, std::memory_order_release); }
59
60 bool IsStopRequested() const { return stop_requested_.load(std::memory_order_acquire); }
61
63 void ClearStop() { stop_requested_.store(false, std::memory_order_release); }
64 ::PPCContext* GetContext() const { return context_; }
65
66 u32 GetThreadID() const { return thread_id_; }
67
69 TitleRuntime* GetRuntime() const { return runtime_; }
70
71 DPCSaveArea& GetDPCSaveArea() { return dpc_save_area_; }
72
74 char*& GetStrtokContext() { return strtok_context_; }
75
81 static void Bind(ThreadState* state);
83 static ThreadState* Get();
87 static u32 GetBoundThreadID();
88
89 private:
90 GuestAddressSpace* memory_;
91 TitleRuntime* runtime_;
92
93 u32 thread_id_ = 0;
94
95 alignas(64)::PPCContext context_storage_{};
96 ::PPCContext* context_ = &context_storage_;
97 DPCSaveArea dpc_save_area_;
98 char* strtok_context_ = nullptr;
99 std::atomic<bool> stop_requested_{false};
100};
101
102namespace detail {
103
105[[noreturn]] REX_KERNEL_API void AbortNoRuntime();
106
107} // namespace detail
108
111 ThreadState* state = ThreadState::Get();
112 if (state == nullptr || state->GetRuntime() == nullptr) [[unlikely]] {
113 detail::AbortNoRuntime();
114 }
115 return *state->GetRuntime();
116}
117
118} // namespace rex::kernel
Definition heap.h:594
Definition thread_state.h:40
static void Bind(ThreadState *state)
ThreadState(u32 thread_id, u32 stack_base, u32 pcr_address, GuestAddressSpace *memory, TitleRuntime *runtime)
static u32 GetBoundThreadID()
TitleRuntime * GetRuntime() const
Definition thread_state.h:69
static ThreadState * Get()
void RequestStop()
Definition thread_state.h:58
char *& GetStrtokContext()
Definition thread_state.h:74
void ClearStop()
Definition thread_state.h:63
Definition title_runtime.h:85
Definition export.h:24
TitleRuntime & GetCurrent()
Definition thread_state.h:110
Definition endian.h:27
Definition app.h:36
Platform flags, packing macros and export markers.
#define REX_KERNEL_API
Definition platform.h:297
Definition context.h:387
Definition thread_state.h:32
u32 csr
Definition thread_state.h:35
Integer types, byte order wrappers and size literals.