Skip to content
This repository has been archived by the owner on Jul 10, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1790 from reicast/skmp/better-rec-cpp
Browse files Browse the repository at this point in the history
- Bios is at 3.6 on pc and 6.6 on emiscripten for me now
  • Loading branch information
skmp authored Feb 7, 2020
2 parents c0eaa4a + 708ff27 commit 31a0b73
Show file tree
Hide file tree
Showing 10 changed files with 468 additions and 527 deletions.
1 change: 1 addition & 0 deletions libswirl/gui/gui_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,7 @@ struct GUIRenderer_impl : GUIRenderer {
#else
while (keepRunning) {
UIFrame();
SleepMs(1); // don't sleep too much
}
#endif
DestroyContext();
Expand Down
107 changes: 0 additions & 107 deletions libswirl/hw/mem/_vmem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
#include "hw/aica/aica_mem.h"
#include "hw/sh4/dyna/blockmanager.h"

#define HANDLER_MAX 0x1F
#define HANDLER_COUNT (HANDLER_MAX+1)

//top registered handler
_vmem_handler _vmem_lrp;

Expand Down Expand Up @@ -145,110 +142,6 @@ void* _vmem_page_info(u32 addr,bool& ismem,u32 sz,u32& page_sz,bool rw)
return 0;
}

template<typename T,typename Trv>
INLINE Trv DYNACALL _vmem_readt(u32 addr)
{
const u32 sz=sizeof(T);

u32 page=addr>>24; //1 op, shift/extract
unat iirf=(unat)_vmem_MemInfo_ptr[page]; //2 ops, insert + read [vmem table will be on reg ]
void* ptr=(void*)(iirf&~HANDLER_MAX); //2 ops, and // 1 op insert

if (likely(ptr!=0))
{
addr<<=iirf;
addr>>=iirf;

T data=(*((T*)&(((u8*)ptr)[addr])));
return data;
}
else
{
const u32 id=iirf;
if (sz==1)
{
return (T)_vmem_RF8[id/4](_vmem_CTX[id/4], addr);
}
else if (sz==2)
{
return (T)_vmem_RF16[id/4](_vmem_CTX[id/4], addr);
}
else if (sz==4)
{
return _vmem_RF32[id/4](_vmem_CTX[id/4], addr);
}
else if (sz==8)
{
T rv=_vmem_RF32[id/4](_vmem_CTX[id/4], addr);
rv|=(T)((u64)_vmem_RF32[id/4](_vmem_CTX[id/4], addr+4)<<32);

return rv;
}
else
{
die("Invalid size");
}
}
}
template<typename T>
INLINE void DYNACALL _vmem_writet(u32 addr,T data)
{
const u32 sz=sizeof(T);

u32 page=addr>>24;
unat iirf=(unat)_vmem_MemInfo_ptr[page];
void* ptr=(void*)(iirf&~HANDLER_MAX);

if (likely(ptr!=0))
{
addr<<=iirf;
addr>>=iirf;

*((T*)&(((u8*)ptr)[addr]))=data;
}
else
{
const u32 id=iirf;
if (sz==1)
{
_vmem_WF8[id/4](_vmem_CTX[id/4], addr,data);
}
else if (sz==2)
{
_vmem_WF16[id/4](_vmem_CTX[id/4], addr,data);
}
else if (sz==4)
{
_vmem_WF32[id/4](_vmem_CTX[id/4], addr,data);
}
else if (sz==8)
{
_vmem_WF32[id/4](_vmem_CTX[id/4], addr,(u32)data);
_vmem_WF32[id/4](_vmem_CTX[id/4], addr+4,(u32)((u64)data>>32));
}
else
{
die("Invalid size");
}
}
}

//ReadMem/WriteMem functions
//ReadMem
u32 DYNACALL _vmem_ReadMem8SX32(u32 Address) { return _vmem_readt<s8,s32>(Address); }
u32 DYNACALL _vmem_ReadMem16SX32(u32 Address) { return _vmem_readt<s16,s32>(Address); }

u8 DYNACALL _vmem_ReadMem8(u32 Address) { return _vmem_readt<u8,u8>(Address); }
u16 DYNACALL _vmem_ReadMem16(u32 Address) { return _vmem_readt<u16,u16>(Address); }
u32 DYNACALL _vmem_ReadMem32(u32 Address) { return _vmem_readt<u32,u32>(Address); }
u64 DYNACALL _vmem_ReadMem64(u32 Address) { return _vmem_readt<u64,u64>(Address); }

//WriteMem
void DYNACALL _vmem_WriteMem8(u32 Address,u8 data) { _vmem_writet<u8>(Address,data); }
void DYNACALL _vmem_WriteMem16(u32 Address,u16 data) { _vmem_writet<u16>(Address,data); }
void DYNACALL _vmem_WriteMem32(u32 Address,u32 data) { _vmem_writet<u32>(Address,data); }
void DYNACALL _vmem_WriteMem64(u32 Address,u64 data) { _vmem_writet<u64>(Address,data); }

//0xDEADC0D3 or 0
#define MEM_ERROR_RETURN_VALUE 0xDEADC0D3

Expand Down
135 changes: 123 additions & 12 deletions libswirl/hw/mem/_vmem.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ void vmem_platform_flush_cache(void *icache_start, void *icache_end, void *dcach
// Note: if you want to disable vmem magic in any given platform, implement the
// above functions as empty functions and make vmem_platform_init return MemTypeError.


//Typedef's

//ReadMem
Expand All @@ -57,6 +58,113 @@ typedef void DYNACALL _vmem_WriteMem32FP(void* ctx, u32 Address, u32 data);
typedef u32 _vmem_handler;



//handler tables
#define HANDLER_MAX 0x1F
#define HANDLER_COUNT (HANDLER_MAX+1)

extern _vmem_ReadMem8FP* _vmem_RF8[HANDLER_COUNT];
extern _vmem_WriteMem8FP* _vmem_WF8[HANDLER_COUNT];

extern _vmem_ReadMem16FP* _vmem_RF16[HANDLER_COUNT];
extern _vmem_WriteMem16FP* _vmem_WF16[HANDLER_COUNT];

extern _vmem_ReadMem32FP* _vmem_RF32[HANDLER_COUNT];
extern _vmem_WriteMem32FP* _vmem_WF32[HANDLER_COUNT];

extern void* _vmem_CTX[HANDLER_COUNT];

extern void* _vmem_MemInfo_ptr[0x100];

template<typename T, typename Trv>
INLINE Trv DYNACALL _vmem_readt(u32 addr)
{
const u32 sz = sizeof(T);

u32 page = addr >> 24; //1 op, shift/extract
unat iirf = (unat)_vmem_MemInfo_ptr[page]; //2 ops, insert + read [vmem table will be on reg ]
void* ptr = (void*)(iirf & ~HANDLER_MAX); //2 ops, and // 1 op insert

if (likely(ptr != 0))
{
addr <<= iirf;
addr >>= iirf;

T data = (*((T*)&(((u8*)ptr)[addr])));
return data;
}
else
{
const u32 id = iirf;
if (sz == 1)
{
return (T)_vmem_RF8[id / 4](_vmem_CTX[id / 4], addr);
}
else if (sz == 2)
{
return (T)_vmem_RF16[id / 4](_vmem_CTX[id / 4], addr);
}
else if (sz == 4)
{
return _vmem_RF32[id / 4](_vmem_CTX[id / 4], addr);
}
else if (sz == 8)
{
T rv = _vmem_RF32[id / 4](_vmem_CTX[id / 4], addr);
rv |= (T)((u64)_vmem_RF32[id / 4](_vmem_CTX[id / 4], addr + 4) << 32);

return rv;
}
else
{
die("Invalid size");
}
}
}
template<typename T>
INLINE void DYNACALL _vmem_writet(u32 addr, T data)
{
const u32 sz = sizeof(T);

u32 page = addr >> 24;
unat iirf = (unat)_vmem_MemInfo_ptr[page];
void* ptr = (void*)(iirf & ~HANDLER_MAX);

if (likely(ptr != 0))
{
addr <<= iirf;
addr >>= iirf;

*((T*)&(((u8*)ptr)[addr])) = data;
}
else
{
const u32 id = iirf;
if (sz == 1)
{
_vmem_WF8[id / 4](_vmem_CTX[id / 4], addr, data);
}
else if (sz == 2)
{
_vmem_WF16[id / 4](_vmem_CTX[id / 4], addr, data);
}
else if (sz == 4)
{
_vmem_WF32[id / 4](_vmem_CTX[id / 4], addr, data);
}
else if (sz == 8)
{
_vmem_WF32[id / 4](_vmem_CTX[id / 4], addr, (u32)data);
_vmem_WF32[id / 4](_vmem_CTX[id / 4], addr + 4, (u32)((u64)data >> 32));
}
else
{
die("Invalid size");
}
}
}


//Functions

//init/reset/term
Expand Down Expand Up @@ -99,18 +207,21 @@ void DYNACALL Write##name(void* ctx, u32 addr, T data) { \
that->Write##name<sz, T>(addr, data); \
}

//ReadMem(s)
u32 DYNACALL _vmem_ReadMem8SX32(u32 Address);
u32 DYNACALL _vmem_ReadMem16SX32(u32 Address);
u8 DYNACALL _vmem_ReadMem8(u32 Address);
u16 DYNACALL _vmem_ReadMem16(u32 Address);
u32 DYNACALL _vmem_ReadMem32(u32 Address);
u64 DYNACALL _vmem_ReadMem64(u32 Address);
//WriteMem(s)
void DYNACALL _vmem_WriteMem8(u32 Address,u8 data);
void DYNACALL _vmem_WriteMem16(u32 Address,u16 data);
void DYNACALL _vmem_WriteMem32(u32 Address,u32 data);
void DYNACALL _vmem_WriteMem64(u32 Address,u64 data);
//ReadMem/WriteMem functions
//ReadMem
INLINE u32 DYNACALL _vmem_ReadMem8SX32(u32 Address) { return _vmem_readt<s8, s32>(Address); }
INLINE u32 DYNACALL _vmem_ReadMem16SX32(u32 Address) { return _vmem_readt<s16, s32>(Address); }

INLINE u8 DYNACALL _vmem_ReadMem8(u32 Address) { return _vmem_readt<u8, u8>(Address); }
INLINE u16 DYNACALL _vmem_ReadMem16(u32 Address) { return _vmem_readt<u16, u16>(Address); }
INLINE u32 DYNACALL _vmem_ReadMem32(u32 Address) { return _vmem_readt<u32, u32>(Address); }
INLINE u64 DYNACALL _vmem_ReadMem64(u32 Address) { return _vmem_readt<u64, u64>(Address); }

//WriteMem
INLINE void DYNACALL _vmem_WriteMem8(u32 Address, u8 data) { _vmem_writet<u8>(Address, data); }
INLINE void DYNACALL _vmem_WriteMem16(u32 Address, u16 data) { _vmem_writet<u16>(Address, data); }
INLINE void DYNACALL _vmem_WriteMem32(u32 Address, u32 data) { _vmem_writet<u32>(Address, data); }
INLINE void DYNACALL _vmem_WriteMem64(u32 Address, u64 data) { _vmem_writet<u64>(Address, data); }

//should be called at start up to ensure it will succeed :)
bool _vmem_reserve(VLockedMemory* mram, VLockedMemory* vram, VLockedMemory* aica_ram, u32 aram_size);
Expand Down
7 changes: 7 additions & 0 deletions libswirl/hw/sh4/dyna/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ u32 emit_FreeSpace()

SmcCheckEnum DoCheck(u32 pc, u32 len)
{

// is on bios or such
if (!GetMemPtr(pc, len))
{
return NoCheck;
}

// no need for checks if fault based discard is used for this block
if (!bm_RamPageHasData(pc, len))
{
Expand Down
4 changes: 2 additions & 2 deletions libswirl/hw/sh4/dyna/shil_canonical.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ extern "C" f32 fipr_asm(float* fn, float* fm);
#define shil_opc(name) struct shil_opcl_##name {
#define shil_opc_end() };

#define shil_canonical(rv,name,args,code) struct name { static rv impl args { code } };
#define shil_canonical(rv,name,args,code) struct name { static INLINE rv impl args { code } };

#define shil_cf_arg_u32(x) rdv_ngen->CC_Param(op,&op->x,CPT_u32);
#define shil_cf_arg_f32(x) rdv_ngen->CC_Param(op,&op->x,CPT_f32);
Expand All @@ -69,7 +69,7 @@ extern "C" f32 fipr_asm(float* fn, float* fm);
#define shil_opc(name) struct shil_opcl_##name {
#define shil_opc_end() };

#define shil_canonical(rv,name,args,code) struct name { static rv impl args; };
#define shil_canonical(rv,name,args,code) struct name { static INLINE rv impl args; };
#define shil_compile(code) static void compile(shil_opcode* op);
#elif SHIL_MODE==3
//generate struct list ...
Expand Down
6 changes: 4 additions & 2 deletions libswirl/hw/sh4/sh4_core_regs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,10 @@ void SetFloatStatusReg()
: "r"(off_mask), "r"(on_mask)
);
#else
printf("SetFloatStatusReg: Unsupported platform\n");
#endif
#if !defined(TARGET_EMSCRIPTEN)
printf("SetFloatStatusReg: Unsupported platform\n");
#endif
#endif
#endif

}
Expand Down
2 changes: 1 addition & 1 deletion libswirl/jit/backend/arm64/rec_arm64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <unistd.h>
#include <sys/mman.h>
#include <map>
#include "hw/sh4/sh4_mem.h"

#include "deps/vixl/aarch64/macro-assembler-aarch64.h"
using namespace vixl::aarch64;
Expand All @@ -25,7 +26,6 @@ using namespace vixl::aarch64;
#include "hw/sh4/sh4_interrupts.h"
#include "hw/sh4/sh4_core.h"
#include "hw/sh4/dyna/ngen.h"
#include "hw/sh4/sh4_mem.h"
#include "hw/sh4/sh4_rom.h"
#include "arm64_regalloc.h"

Expand Down
Loading

0 comments on commit 31a0b73

Please sign in to comment.