nn_save: Refactor and modernize code

This commit is contained in:
Exzap 2024-05-29 00:07:37 +02:00
parent 1ee9d5c78c
commit da8fd5b7c7
5 changed files with 323 additions and 887 deletions

View File

@ -90,7 +90,7 @@ uint8* PPCInterpreterGetStackPointer()
return memory_getPointerFromVirtualOffset(PPCInterpreter_getCurrentInstance()->gpr[1]);
}
uint8* PPCInterpreterGetAndModifyStackPointer(sint32 offset)
uint8* PPCInterpreter_PushAndReturnStackPointer(sint32 offset)
{
PPCInterpreter_t* hCPU = PPCInterpreter_getCurrentInstance();
uint8* result = memory_getPointerFromVirtualOffset(hCPU->gpr[1] - offset);

View File

@ -213,7 +213,7 @@ void PPCTimer_start();
// core info and control
extern uint32 ppcThreadQuantum;
uint8* PPCInterpreterGetAndModifyStackPointer(sint32 offset);
uint8* PPCInterpreter_PushAndReturnStackPointer(sint32 offset);
uint8* PPCInterpreterGetStackPointer();
void PPCInterpreterModifyStackPointer(sint32 offset);

File diff suppressed because it is too large Load Diff

View File

@ -11,7 +11,7 @@ using PAddr = uint32; // physical address
extern uint8* memory_base;
extern uint8* PPCInterpreterGetStackPointer();
extern uint8* PPCInterpreterGetAndModifyStackPointer(sint32 offset);
extern uint8* PPCInterpreter_PushAndReturnStackPointer(sint32 offset);
extern void PPCInterpreterModifyStackPointer(sint32 offset);
class MEMPTRBase {};

View File

@ -10,14 +10,16 @@ public:
explicit StackAllocator(const uint32 items)
{
m_items = items;
m_modified_size = count * sizeof(T) * items + kStaticMemOffset * 2;
auto tmp = PPCInterpreterGetStackPointer();
m_ptr = (T*)(PPCInterpreterGetAndModifyStackPointer(m_modified_size) + kStaticMemOffset);
m_modified_size = (m_modified_size/8+7) * 8; // pad to 8 bytes
m_ptr = new(PPCInterpreter_PushAndReturnStackPointer(m_modified_size) + kStaticMemOffset) T[count * items]();
}
~StackAllocator()
{
for (size_t i = 0; i < count * m_items; ++i)
m_ptr[i].~T();
PPCInterpreterModifyStackPointer(-m_modified_size);
}
@ -64,4 +66,5 @@ private:
T* m_ptr;
sint32 m_modified_size;
uint32 m_items;
};