vm::stackvar (experimental)

Should be convenient for small allocations which would be done on stack
on real console
This commit is contained in:
Nekotekina 2015-01-07 05:14:00 +03:00
parent 5ffc6ffca5
commit 3f44e07b7c
9 changed files with 272 additions and 44 deletions

View file

@ -1,5 +1,7 @@
#include "stdafx.h"
#include "Memory.h"
#include "Emu/CPU/CPUThread.h"
#include "Emu/Cell/PPUThread.h"
namespace vm
{
@ -143,4 +145,84 @@ namespace vm
{
Memory.Close();
}
u32 stack_push(CPUThread& CPU, u32 size, u32 align_v, u32& old_pos)
{
switch (CPU.GetType())
{
case CPU_THREAD_PPU:
{
PPUThread& PPU = static_cast<PPUThread&>(CPU);
assert(align_v);
old_pos = (u32)PPU.GPR[1];
PPU.GPR[1] -= align(size, 8); // room minimal possible size
PPU.GPR[1] &= ~(align_v - 1); // fix stack alignment
if (PPU.GPR[1] < CPU.GetStackAddr())
{
// stack overflow
PPU.GPR[1] = old_pos;
return 0;
}
else
{
return (u32)PPU.GPR[1];
}
}
case CPU_THREAD_SPU:
case CPU_THREAD_RAW_SPU:
{
assert(!"stack_push(): SPU not supported");
return 0;
}
case CPU_THREAD_ARMv7:
{
assert(!"stack_push(): ARMv7 not supported");
return 0;
}
default:
{
assert(!"stack_push(): invalid thread type");
return 0;
}
}
}
void stack_pop(CPUThread& CPU, u32 addr, u32 old_pos)
{
switch (CPU.GetType())
{
case CPU_THREAD_PPU:
{
PPUThread& PPU = static_cast<PPUThread&>(CPU);
assert(PPU.GPR[1] == addr);
PPU.GPR[1] = old_pos;
return;
}
case CPU_THREAD_SPU:
case CPU_THREAD_RAW_SPU:
{
assert(!"stack_pop(): SPU not supported");
return;
}
case CPU_THREAD_ARMv7:
{
assert(!"stack_pop(): ARMv7 not supported");
return;
}
default:
{
assert(!"stack_pop(): invalid thread type");
return;
}
}
}
}