Files
LibretroAdmin 4dedef028b Memory: convert to C89, with the memory map and handler APIs it faces
Memory.c and VirtualMemory.c replace their C++ originals: the memory
managers, bump allocator and reserves are plain structs and functions,
SysMainMemory is a struct, the host memory map is HOSTMEM_ constants,
and the GS JIT's code reserve is GSCodeReserve.c. The vtlb, GS, DEV9,
CDVD NVRAM, IOP and MTVU entry points Memory.c calls carry C linkage;
the EE hardware handler sets are registered from Dmac.cpp, so Hw.cpp's
handlers stay as they are.

memBindConditionalHandlers takes the INTC_STAT hack and MTVU setting
and binds VU1's memory handlers for them, so no handler tests the
configuration per access, and MTVU writes store straight into their
ring slot. The main and code maps are placed together by
near_place_pair: the shared-memory backing is created once, a taken
address fails with one MAP_FIXED_NOREPLACE call, the bases next to the
image are tried before the address space is read, and it is read at
most once.
2026-10-27 11:41:24 +01:00

67 lines
1.6 KiB
C++

/* The software renderer's code-generator map over the real GSCodeReserve,
* with a stand-in generator, for main.c. A key's low 32 bits name the
* function and its high 32 bits the bytes it takes; the generator writes
* the name's low byte over them, and like the real generator's emitter
* stops writing at the end of the room it is given. */
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include "GS/Renderers/Common/GSFunctionMap.h"
static void gsjit_log(enum retro_log_level level, const char* fmt, ...)
{
va_list ap;
(void)level;
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
}
extern "C" retro_log_printf_t log_cb = gsjit_log;
typedef const u8* FakeFn;
struct FakeCG
{
u8* m_code;
size_t m_size;
FakeCG(u64 key, void* code, size_t room)
: m_code(static_cast<u8*>(code))
{
const size_t want = (size_t)(key >> 32);
m_size = want < room ? want : room;
memset(m_code, (int)(key & 0xff), m_size);
}
size_t getSize() const { return m_size; }
const u8* getCode() const { return m_code; }
};
static GSCodeGeneratorFunctionMap<FakeCG, u64, FakeFn> s_map;
extern "C" void gsjit_assign(unsigned char* base, size_t size)
{
g_gs_code_reserve.reserve.baseptr = base;
g_gs_code_reserve.reserve.size = size;
g_gs_code_reserve.reserve.allocator = NULL;
gs_code_reserve_reset();
}
extern "C" const unsigned char* gsjit_get(unsigned long long key)
{
return s_map[key];
}
/* What GSDrawScanline::ResetCodeCache does. */
extern "C" void gsjit_reset(void)
{
s_map.Clear();
gs_code_reserve_reset();
}
extern "C" void gsjit_release(void)
{
s_map.Clear();
code_reserve_init(&g_gs_code_reserve.reserve);
}