32x: drc: mmap dram+rom for direct dereference

git-svn-id: file:///home/notaz/opt/svn/PicoDrive@851 be3aeb3a-fb24-0410-a615-afba39da0efa
This commit is contained in:
notaz 2010-01-02 21:03:04 +00:00
parent f6c49d38cb
commit b081408f66
8 changed files with 200 additions and 71 deletions

View file

@ -169,7 +169,8 @@
#define EOP_C_AM3_REG(cond,u,l,rn,rd,s,h,rm) EOP_C_AM3(cond,u,0,l,rn,rd,s,h,rm) #define EOP_C_AM3_REG(cond,u,l,rn,rd,s,h,rm) EOP_C_AM3(cond,u,0,l,rn,rd,s,h,rm)
/* ldr and str */ /* ldr and str */
#define EOP_LDR_IMM2(cond,rd,rn,offset_12) EOP_C_AM2_IMM(cond,1,0,1,rn,rd,offset_12) #define EOP_LDR_IMM2(cond,rd,rn,offset_12) EOP_C_AM2_IMM(cond,1,0,1,rn,rd,offset_12)
#define EOP_LDRB_IMM2(cond,rd,rn,offset_12) EOP_C_AM2_IMM(cond,1,1,1,rn,rd,offset_12)
#define EOP_LDR_IMM( rd,rn,offset_12) EOP_C_AM2_IMM(A_COND_AL,1,0,1,rn,rd,offset_12) #define EOP_LDR_IMM( rd,rn,offset_12) EOP_C_AM2_IMM(A_COND_AL,1,0,1,rn,rd,offset_12)
#define EOP_LDR_NEGIMM(rd,rn,offset_12) EOP_C_AM2_IMM(A_COND_AL,0,0,1,rn,rd,offset_12) #define EOP_LDR_NEGIMM(rd,rn,offset_12) EOP_C_AM2_IMM(A_COND_AL,0,0,1,rn,rd,offset_12)
@ -179,6 +180,8 @@
#define EOP_LDR_REG_LSL(cond,rd,rn,rm,shift_imm) EOP_C_AM2_REG(cond,1,0,1,rn,rd,shift_imm,A_AM1_LSL,rm) #define EOP_LDR_REG_LSL(cond,rd,rn,rm,shift_imm) EOP_C_AM2_REG(cond,1,0,1,rn,rd,shift_imm,A_AM1_LSL,rm)
#define EOP_LDRH_IMM2(cond,rd,rn,offset_8) EOP_C_AM3_IMM(cond,1,1,rn,rd,0,1,offset_8)
#define EOP_LDRH_IMM( rd,rn,offset_8) EOP_C_AM3_IMM(A_COND_AL,1,1,rn,rd,0,1,offset_8) #define EOP_LDRH_IMM( rd,rn,offset_8) EOP_C_AM3_IMM(A_COND_AL,1,1,rn,rd,0,1,offset_8)
#define EOP_LDRH_SIMPLE(rd,rn) EOP_C_AM3_IMM(A_COND_AL,1,1,rn,rd,0,1,0) #define EOP_LDRH_SIMPLE(rd,rn) EOP_C_AM3_IMM(A_COND_AL,1,1,rn,rd,0,1,0)
#define EOP_LDRH_REG( rd,rn,rm) EOP_C_AM3_REG(A_COND_AL,1,1,rn,rd,0,1,rm) #define EOP_LDRH_REG( rd,rn,rm) EOP_C_AM3_REG(A_COND_AL,1,1,rn,rd,0,1,rm)
@ -327,11 +330,14 @@ static int emith_xbranch(int cond, void *target, int is_call)
} }
// fake "simple" or "short" jump - using cond insns instead // fake "simple" or "short" jump - using cond insns instead
#define EMITH_SJMP_START(cond) \ #define EMITH_NOTHING1(cond) \
(void)(cond) (void)(cond)
#define EMITH_SJMP_END(cond) \ #define EMITH_SJMP_START(cond) EMITH_NOTHING1(cond)
(void)(cond) #define EMITH_SJMP_END(cond) EMITH_NOTHING1(cond)
#define EMITH_SJMP3_START(cond) EMITH_NOTHING1(cond)
#define EMITH_SJMP3_MID(cond) EMITH_NOTHING1(cond)
#define EMITH_SJMP3_END()
#define emith_move_r_r(d, s) \ #define emith_move_r_r(d, s) \
EOP_MOV_REG_SIMPLE(d, s) EOP_MOV_REG_SIMPLE(d, s)
@ -485,8 +491,11 @@ static int emith_xbranch(int cond, void *target, int is_call)
#define emith_asr(d, s, cnt) \ #define emith_asr(d, s, cnt) \
EOP_MOV_REG(A_COND_AL,0,d,s,A_AM1_ASR,cnt) EOP_MOV_REG(A_COND_AL,0,d,s,A_AM1_ASR,cnt)
#define emith_ror_c(cond, d, s, cnt) \
EOP_MOV_REG(cond,0,d,s,A_AM1_ROR,cnt)
#define emith_ror(d, s, cnt) \ #define emith_ror(d, s, cnt) \
EOP_MOV_REG(A_COND_AL,0,d,s,A_AM1_ROR,cnt) emith_ror_c(A_COND_AL, d, s, cnt)
#define emith_rol(d, s, cnt) \ #define emith_rol(d, s, cnt) \
EOP_MOV_REG(A_COND_AL,0,d,s,A_AM1_ROR,32-(cnt)); \ EOP_MOV_REG(A_COND_AL,0,d,s,A_AM1_ROR,32-(cnt)); \
@ -536,8 +545,26 @@ static int emith_xbranch(int cond, void *target, int is_call)
EOP_C_SMLAL(A_COND_AL,0,dhi,dlo,s1,s2) EOP_C_SMLAL(A_COND_AL,0,dhi,dlo,s1,s2)
// misc // misc
#define emith_read_r_r_offs_c(cond, r, rs, offs) \
EOP_LDR_IMM2(cond, r, rs, offs)
#define emith_read8_r_r_offs_c(cond, r, rs, offs) \
EOP_LDRB_IMM2(cond, r, rs, offs)
#define emith_read16_r_r_offs_c(cond, r, rs, offs) \
EOP_LDRH_IMM2(cond, r, rs, offs)
#define emith_read_r_r_offs(r, rs, offs) \
emith_read_r_r_offs_c(A_COND_AL, r, rs, offs)
#define emith_read8_r_r_offs(r, rs, offs) \
emith_read8_r_r_offs_c(A_COND_AL, r, rs, offs)
#define emith_read16_r_r_offs(r, rs, offs) \
emith_read16_r_r_offs_c(A_COND_AL, r, rs, offs)
#define emith_ctx_read(r, offs) \ #define emith_ctx_read(r, offs) \
EOP_LDR_IMM(r, CONTEXT_REG, offs) emith_read_r_r_offs(r, CONTEXT_REG, offs)
#define emith_ctx_write(r, offs) \ #define emith_ctx_write(r, offs) \
EOP_STR_IMM(r, CONTEXT_REG, offs) EOP_STR_IMM(r, CONTEXT_REG, offs)

View file

@ -219,29 +219,38 @@ enum { xAX = 0, xCX, xDX, xBX, xSP, xBP, xSI, xDI };
emith_add_r_imm(r, imm); \ emith_add_r_imm(r, imm); \
} }
#define emith_or_r_imm_c(cond, r, imm) { \
(void)(cond); \
emith_or_r_imm(r, imm); \
}
#define emith_eor_r_imm_c(cond, r, imm) { \
(void)(cond); \
emith_eor_r_imm(r, imm); \
}
#define emith_sub_r_imm_c(cond, r, imm) { \ #define emith_sub_r_imm_c(cond, r, imm) { \
(void)(cond); \ (void)(cond); \
emith_sub_r_imm(r, imm); \ emith_sub_r_imm(r, imm); \
} }
#define emith_bic_r_imm_c(cond, r, imm) { \ #define emith_or_r_imm_c(cond, r, imm) \
(void)(cond); \ emith_or_r_imm(r, imm)
emith_bic_r_imm(r, imm); \ #define emith_eor_r_imm_c(cond, r, imm) \
} emith_eor_r_imm(r, imm)
#define emith_bic_r_imm_c(cond, r, imm) \
emith_bic_r_imm(r, imm)
#define emith_ror_c(cond, d, s, cnt) \
emith_ror(d, s, cnt)
#define emith_jump_reg_c(cond, r) emith_jump_reg(r) #define emith_read_r_r_offs_c(cond, r, rs, offs) \
#define emith_jump_ctx_c(cond, offs) emith_jump_ctx(offs) emith_read_r_r_offs(r, rs, offs)
#define emith_ret_c(cond) emith_ret() #define emith_write_r_r_offs_c(cond, r, rs, offs) \
emith_write_r_r_offs(r, rs, offs)
#define emith_read8_r_r_offs_c(cond, r, rs, offs) \
emith_read8_r_r_offs(r, rs, offs)
#define emith_write8_r_r_offs_c(cond, r, rs, offs) \
emith_write8_r_r_offs(r, rs, offs)
#define emith_read16_r_r_offs_c(cond, r, rs, offs) \
emith_read16_r_r_offs(r, rs, offs)
#define emith_write16_r_r_offs_c(cond, r, rs, offs) \
emith_write16_r_r_offs(r, rs, offs)
#define emith_jump_reg_c(cond, r) \
emith_jump_reg(r)
#define emith_jump_ctx_c(cond, offs) \
emith_jump_ctx(offs)
#define emith_ret_c(cond) \
emith_ret()
// _r_r_imm // _r_r_imm
#define emith_add_r_r_imm(d, s, imm) { \ #define emith_add_r_r_imm(d, s, imm) { \
@ -391,22 +400,44 @@ enum { xAX = 0, xCX, xDX, xBX, xSP, xBP, xSI, xDI };
#define emith_rolcf emith_rolc #define emith_rolcf emith_rolc
#define emith_rorcf emith_rorc #define emith_rorcf emith_rorc
#define emith_ctx_op(op, r, offs) do { \ #define emith_deref_op(op, r, rs, offs) do { \
/* mov r <-> [ebp+#offs] */ \ /* mov r <-> [ebp+#offs] */ \
if ((offs) >= 0x80) { \ if ((offs) >= 0x80) { \
EMIT_OP_MODRM(op, 2, r, xBP); \ EMIT_OP_MODRM(op, 2, r, rs); \
EMIT(offs, u32); \ EMIT(offs, u32); \
} else { \ } else { \
EMIT_OP_MODRM(op, 1, r, xBP); \ EMIT_OP_MODRM(op, 1, r, rs); \
EMIT(offs, u8); \ EMIT(offs, u8); \
} \ } \
} while (0) } while (0)
#define emith_read_r_r_offs(r, rs, offs) \
emith_deref_op(0x8b, r, rs, offs)
#define emith_write_r_r_offs(r, rs, offs) \
emith_deref_op(0x89, r, rs, offs)
#define emith_read8_r_r_offs(r, rs, offs) \
emith_deref_op(0x8a, r, rs, offs)
#define emith_write8_r_r_offs(r, rs, offs) \
emith_deref_op(0x88, r, rs, offs)
#define emith_read16_r_r_offs(r, rs, offs) { \
EMIT(0x66, u8); /* operand override */ \
emith_read_r_r_offs(r, rs, offs); \
}
#define emith_write16_r_r_offs(r, rs, offs) { \
EMIT(0x66, u8); \
emith_write16_r_r_offs(r, rs, offs) \
}
#define emith_ctx_read(r, offs) \ #define emith_ctx_read(r, offs) \
emith_ctx_op(0x8b, r, offs) emith_read_r_r_offs(r, CONTEXT_REG, offs)
#define emith_ctx_write(r, offs) \ #define emith_ctx_write(r, offs) \
emith_ctx_op(0x89, r, offs) emith_write_r_r_offs(r, CONTEXT_REG, offs)
#define emith_ctx_read_multiple(r, offs, cnt, tmpr) do { \ #define emith_ctx_read_multiple(r, offs, cnt, tmpr) do { \
int r_ = r, offs_ = offs, cnt_ = cnt; \ int r_ = r, offs_ = offs, cnt_ = cnt; \
@ -460,7 +491,7 @@ enum { xAX = 0, xCX, xDX, xBX, xSP, xBP, xSI, xDI };
EMIT_OP_MODRM(0xff, 3, 2, r) EMIT_OP_MODRM(0xff, 3, 2, r)
#define emith_call_ctx(offs) { \ #define emith_call_ctx(offs) { \
EMIT_OP_MODRM(0xff, 2, 2, xBP); \ EMIT_OP_MODRM(0xff, 2, 2, CONTEXT_REG); \
EMIT(offs, u32); \ EMIT(offs, u32); \
} }
@ -471,7 +502,7 @@ enum { xAX = 0, xCX, xDX, xBX, xSP, xBP, xSI, xDI };
EMIT_OP_MODRM(0xff, 3, 4, r) EMIT_OP_MODRM(0xff, 3, 4, r)
#define emith_jump_ctx(offs) { \ #define emith_jump_ctx(offs) { \
EMIT_OP_MODRM(0xff, 2, 4, xBP); \ EMIT_OP_MODRM(0xff, 2, 4, CONTEXT_REG); \
EMIT(offs, u32); \ EMIT(offs, u32); \
} }
@ -483,10 +514,27 @@ enum { xAX = 0, xCX, xDX, xBX, xSP, xBP, xSI, xDI };
JMP8_EMIT(cond, cond_ptr); \ JMP8_EMIT(cond, cond_ptr); \
} }
#define EMITH_JMP3_START(cond) { \
u8 *cond_ptr, *else_ptr; \
JMP8_POS(cond_ptr)
#define EMITH_JMP3_MID(cond) \
JMP8_POS(else_ptr); \
JMP8_EMIT(cond, cond_ptr);
#define EMITH_JMP3_END() \
JMP8_EMIT_NC(else_ptr); \
}
// "simple" jump (no more then a few insns) // "simple" jump (no more then a few insns)
// ARM will use conditional instructions here
#define EMITH_SJMP_START EMITH_JMP_START #define EMITH_SJMP_START EMITH_JMP_START
#define EMITH_SJMP_END EMITH_JMP_END #define EMITH_SJMP_END EMITH_JMP_END
#define EMITH_SJMP3_START EMITH_JMP3_START
#define EMITH_SJMP3_MID EMITH_JMP3_MID
#define EMITH_SJMP3_END EMITH_JMP3_END
#define host_arg2reg(rd, arg) \ #define host_arg2reg(rd, arg) \
switch (arg) { \ switch (arg) { \
case 0: rd = xAX; break; \ case 0: rd = xAX; break; \

View file

@ -496,24 +496,60 @@ static void emit_or_t_if_eq(int srr)
// reg cache must be clean before call // reg cache must be clean before call
static int emit_memhandler_read(int size) static int emit_memhandler_read(int size)
{ {
int ctxr; int arg0, arg1;
host_arg2reg(ctxr, 1); host_arg2reg(arg0, 0);
emith_move_r_r(ctxr, CONTEXT_REG);
switch (size) { // must writeback cycles for poll detection stuff
case 0: // 8 if (reg_map_g2h[SHR_SR] != -1)
// must writeback cycles for poll detection stuff emith_ctx_write(reg_map_g2h[SHR_SR], SHR_SR * 4);
if (reg_map_g2h[SHR_SR] != -1) arg1 = rcache_get_tmp_arg(1);
emith_ctx_write(reg_map_g2h[SHR_SR], SHR_SR * 4); emith_move_r_r(arg1, CONTEXT_REG);
emith_call(p32x_sh2_read8);
break; #if 1
case 1: // 16 if (Pico.rom == (void *)0x02000000 && Pico32xMem->sdram == (void *)0x06000000) {
if (reg_map_g2h[SHR_SR] != -1) int tmp = rcache_get_tmp();
emith_ctx_write(reg_map_g2h[SHR_SR], SHR_SR * 4); emith_and_r_r_imm(tmp, arg0, 0xfb000000);
emith_call(p32x_sh2_read16); emith_cmp_r_imm(tmp, 0x02000000);
break; switch (size) {
case 2: // 32 case 0: // 8
emith_call(p32x_sh2_read32); EMITH_SJMP3_START(DCOND_NE);
break; emith_eor_r_imm_c(DCOND_EQ, arg0, 1);
emith_read8_r_r_offs_c(DCOND_EQ, arg0, arg0, 0);
EMITH_SJMP3_MID(DCOND_NE);
emith_call_cond(DCOND_NE, p32x_sh2_read8);
EMITH_SJMP3_END();
break;
case 1: // 16
EMITH_SJMP3_START(DCOND_NE);
emith_read16_r_r_offs_c(DCOND_EQ, arg0, arg0, 0);
EMITH_SJMP3_MID(DCOND_NE);
emith_call_cond(DCOND_NE, p32x_sh2_read16);
EMITH_SJMP3_END();
break;
case 2: // 32
EMITH_SJMP3_START(DCOND_NE);
emith_read_r_r_offs_c(DCOND_EQ, arg0, arg0, 0);
emith_ror_c(DCOND_EQ, arg0, arg0, 16);
EMITH_SJMP3_MID(DCOND_NE);
emith_call_cond(DCOND_NE, p32x_sh2_read32);
EMITH_SJMP3_END();
break;
}
}
else
#endif
{
switch (size) {
case 0: // 8
emith_call(p32x_sh2_read8);
break;
case 1: // 16
emith_call(p32x_sh2_read16);
break;
case 2: // 32
emith_call(p32x_sh2_read32);
break;
}
} }
rcache_invalidate(); rcache_invalidate();
// assuming arg0 and retval reg matches // assuming arg0 and retval reg matches

View file

@ -129,7 +129,7 @@ void PicoPower32x(void)
void PicoUnload32x(void) void PicoUnload32x(void)
{ {
if (Pico32xMem != NULL) if (Pico32xMem != NULL)
free(Pico32xMem); plat_munmap(Pico32xMem, sizeof(*Pico32xMem));
Pico32xMem = NULL; Pico32xMem = NULL;
sh2_finish(&msh2); sh2_finish(&msh2);
sh2_finish(&ssh2); sh2_finish(&ssh2);

View file

@ -1419,7 +1419,7 @@ void PicoMemSetup32x(void)
unsigned int rs; unsigned int rs;
int i; int i;
Pico32xMem = calloc(1, sizeof(*Pico32xMem)); Pico32xMem = plat_mmap(0x06000000, sizeof(*Pico32xMem));
if (Pico32xMem == NULL) { if (Pico32xMem == NULL) {
elprintf(EL_STATUS, "OOM"); elprintf(EL_STATUS, "OOM");
return; return;

View file

@ -13,6 +13,7 @@
#include "../unzip/unzip_stream.h" #include "../unzip/unzip_stream.h"
static int rom_alloc_size;
static const char *rom_exts[] = { "bin", "gen", "smd", "iso", "sms", "gg", "sg" }; static const char *rom_exts[] = { "bin", "gen", "smd", "iso", "sms", "gg", "sg" };
void (*PicoCartUnloadHook)(void); void (*PicoCartUnloadHook)(void);
@ -425,22 +426,10 @@ static int DecodeSmd(unsigned char *data,int len)
return 0; return 0;
} }
static unsigned char *cd_realloc(void *old, int filesize)
{
unsigned char *rom;
rom=realloc(old, sizeof(mcd_state));
if (rom) memset(rom+0x20000, 0, sizeof(mcd_state)-0x20000);
return rom;
}
static unsigned char *PicoCartAlloc(int filesize, int is_sms) static unsigned char *PicoCartAlloc(int filesize, int is_sms)
{ {
int alloc_size;
unsigned char *rom; unsigned char *rom;
if (PicoAHW & PAHW_MCD)
return cd_realloc(NULL, filesize);
if (is_sms) { if (is_sms) {
// make size power of 2 for easier banking handling // make size power of 2 for easier banking handling
int s = 0, tmp = filesize; int s = 0, tmp = filesize;
@ -448,18 +437,24 @@ static unsigned char *PicoCartAlloc(int filesize, int is_sms)
s++; s++;
if (filesize > (1 << s)) if (filesize > (1 << s))
s++; s++;
alloc_size = 1 << s; rom_alloc_size = 1 << s;
} }
else { else {
// make alloc size at least sizeof(mcd_state),
// in case we want to switch to CD mode
if (filesize < sizeof(mcd_state))
filesize = sizeof(mcd_state);
// align to 512K for memhandlers // align to 512K for memhandlers
alloc_size = (filesize + 0x7ffff) & ~0x7ffff; rom_alloc_size = (filesize + 0x7ffff) & ~0x7ffff;
} }
if (alloc_size - filesize < 4) if (rom_alloc_size - filesize < 4)
alloc_size += 4; // padding for out-of-bound exec protection rom_alloc_size += 4; // padding for out-of-bound exec protection
// Allocate space for the rom plus padding // Allocate space for the rom plus padding
rom = calloc(alloc_size, 1); // use special address for 32x dynarec
rom = plat_mmap(0x02000000, rom_alloc_size);
return rom; return rom;
} }
@ -513,7 +508,6 @@ int PicoCartLoad(pm_file *f,unsigned char **prom,unsigned int *psize,int is_sms)
if (!(PicoAHW & PAHW_MCD) && size == 0x20000 && (!strncmp((char *)rom+0x124, "BOOT", 4) || if (!(PicoAHW & PAHW_MCD) && size == 0x20000 && (!strncmp((char *)rom+0x124, "BOOT", 4) ||
!strncmp((char *)rom+0x128, "BOOT", 4))) { !strncmp((char *)rom+0x128, "BOOT", 4))) {
PicoAHW |= PAHW_MCD; PicoAHW |= PAHW_MCD;
rom = cd_realloc(rom, size);
} }
// Check for SMD: // Check for SMD:
@ -608,8 +602,8 @@ void PicoCartUnload(void)
if (Pico.rom != NULL) { if (Pico.rom != NULL) {
SekFinishIdleDet(); SekFinishIdleDet();
free(Pico.rom); plat_munmap(Pico.rom, rom_alloc_size);
Pico.rom=NULL; Pico.rom = NULL;
} }
} }

View file

@ -28,9 +28,14 @@ extern void mp3_update(int *buffer, int length, int stereo);
// this function should write-back d-cache and invalidate i-cache // this function should write-back d-cache and invalidate i-cache
// on a mem region [start_addr, end_addr) // on a mem region [start_addr, end_addr)
// used by SVP dynarec // used by dynarecs
extern void cache_flush_d_inval_i(const void *start_addr, const void *end_addr); extern void cache_flush_d_inval_i(const void *start_addr, const void *end_addr);
// attempt to alloc mem at specified address.
// alloc anywhere else if that fails (callers should handle that)
extern void *plat_mmap(unsigned long addr, size_t size);
extern void plat_munmap(void *ptr, size_t size);
// this one should handle display mode changes // this one should handle display mode changes
extern void emu_video_mode_change(int start_line, int line_count, int is_32cols); extern void emu_video_mode_change(int start_line, int line_count, int is_32cols);

View file

@ -4,6 +4,7 @@
#include <sys/time.h> #include <sys/time.h>
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
#include <sys/mman.h>
#include "../common/plat.h" #include "../common/plat.h"
@ -108,3 +109,21 @@ int plat_wait_event(int *fds_hnds, int count, int timeout_ms)
return ret; return ret;
} }
void *plat_mmap(unsigned long addr, size_t size)
{
void *req, *ret;
req = (void *)addr;
ret = mmap(req, size, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS, -1, 0);
if (ret == MAP_FAILED)
return NULL;
if (ret != req)
printf("warning: mmaped to %p, requested %p\n", ret, req);
return ret;
}
void plat_munmap(void *ptr, size_t size)
{
munmap(ptr, size);
}