From a6c0ab7d99b9d015b0d75a4455b1bf4acb9c9d6d Mon Sep 17 00:00:00 2001 From: kub Date: Sat, 12 Oct 2019 00:26:11 +0200 Subject: [PATCH] sh2 drc bugfix for aarch64/mips --- Makefile | 2 +- cpu/drc/emit_arm64.c | 2 +- cpu/drc/emit_mips.c | 4 ++-- cpu/drc/emit_x86.c | 2 +- pico/32x/memory.c | 20 ++++++++++---------- tools/mkoffsets.sh | 9 +++++---- 6 files changed, 20 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index 15549dca..a79c054b 100644 --- a/Makefile +++ b/Makefile @@ -225,7 +225,7 @@ endif pprof: platform/linux/pprof.c $(CC) $(CFLAGS) -O2 -ggdb -DPPROF -DPPROF_TOOL -I../../ -I. $^ -o $@ $(LDFLAGS) $(LDLIBS) -pico/pico_int_offs.h:: tools/mkoffsets.sh +pico/pico_int_offs.h: tools/mkoffsets.sh make -C tools/ XCC="$(CC)" XCFLAGS="$(CFLAGS)" .s.o: diff --git a/cpu/drc/emit_arm64.c b/cpu/drc/emit_arm64.c index 3ef402b4..4bad6469 100644 --- a/cpu/drc/emit_arm64.c +++ b/cpu/drc/emit_arm64.c @@ -979,7 +979,7 @@ static void emith_ldst_offs(int sz, int rd, int rn, int o9, int ld, int mode) #define emith_save_caller_regs(mask) do { \ int _c, _r1, _r2; u32 _m = mask & 0x3ffff; \ if (__builtin_parity(_m) == 1) _m |= 0x40000; /* hardware align */ \ - for (_c = HOST_REGS, _r1 = -1; _m && _c >= 0; _m &= ~(1 << _c), _c--) \ + for (_c = HOST_REGS-1, _r1 = -1; _m && _c >= 0; _m &= ~(1 << _c), _c--)\ if (_m & (1 << _c)) { \ _r2 = _r1, _r1 = _c; \ if (_r2 != -1) { \ diff --git a/cpu/drc/emit_mips.c b/cpu/drc/emit_mips.c index 4a452a68..38d68f40 100644 --- a/cpu/drc/emit_mips.c +++ b/cpu/drc/emit_mips.c @@ -1065,7 +1065,7 @@ static void emith_lohi_nops(void) if (__builtin_parity(_m) == 1) _m |= 0x1; /* ABI align */ \ int _s = count_bits(_m) * 4, _o = _s; \ if (_s) emith_sub_r_imm(SP, _s); \ - for (_c = HOST_REGS; _m && _c >= 0; _m &= ~(1 << _c), _c--) \ + for (_c = HOST_REGS-1; _m && _c >= 0; _m &= ~(1 << _c), _c--) \ if (_m & (1 << _c)) \ { _o -= 4; if (_c) emith_write_r_r_offs(_c, SP, _o); } \ } while (0) @@ -1279,7 +1279,7 @@ static int emith_cond_check(int cond, int *r) if (__builtin_parity(_m) == 1) _m |= 0x1; /* ABI align for SP is 8 */ \ int _s = count_bits(_m) * 4 + 16, _o = _s; /* 16 byte arg save area */ \ if (_s) emith_sub_r_imm(SP, _s); \ - for (_c = HOST_REGS; _m && _c >= 0; _m &= ~(1 << _c), _c--) \ + for (_c = HOST_REGS-1; _m && _c >= 0; _m &= ~(1 << _c), _c--) \ if (_m & (1 << _c)) \ { _o -= 4; if (_c) emith_write_r_r_offs(_c, SP, _o); } \ } while (0) diff --git a/cpu/drc/emit_x86.c b/cpu/drc/emit_x86.c index 44e10ecf..212a12c5 100644 --- a/cpu/drc/emit_x86.c +++ b/cpu/drc/emit_x86.c @@ -1115,7 +1115,7 @@ enum { xAX = 0, xCX, xDX, xBX, xSP, xBP, xSI, xDI, // x86-64,i386 common #define emith_save_caller_regs(mask) do { \ int _c; u32 _m = mask & 0xfc7; /* AX, CX, DX, SI, DI, 8, 9, 10, 11 */ \ if (__builtin_parity(_m) == 1) _m |= 0x8; /* BX for ABI align */ \ - for (_c = HOST_REGS; _m && _c >= 0; _m &= ~(1 << _c), _c--) \ + for (_c = HOST_REGS-1; _m && _c >= 0; _m &= ~(1 << _c), _c--) \ if (_m & (1 << _c)) emith_push(_c); \ } while (0) diff --git a/pico/32x/memory.c b/pico/32x/memory.c index e139910a..60820e1a 100644 --- a/pico/32x/memory.c +++ b/pico/32x/memory.c @@ -347,7 +347,7 @@ static u32 p32x_reg_read16(u32 a) if ((a & 0x30) == 0x20) { unsigned int cycles = SekCyclesDone(); - if (cycles - msh2.m68krcycles_done > 244) + if (CYCLES_GT(cycles - msh2.m68krcycles_done, 244)) p32x_sync_sh2s(cycles); if (m68k_poll_detect(a, cycles, P32XF_68KCPOLL)) { @@ -360,7 +360,7 @@ static u32 p32x_reg_read16(u32 a) if (a == 2) { // INTM, INTS unsigned int cycles = SekCyclesDone(); - if (cycles - msh2.m68krcycles_done > 64) + if (CYCLES_GT(cycles - msh2.m68krcycles_done, 64)) p32x_sync_sh2s(cycles); goto out; } @@ -420,7 +420,7 @@ static void p32x_reg_write8(u32 a, u32 d) return; case 0x03: // irq ctl if ((d ^ r[0x02 / 2]) & 3) { - int cycles = SekCyclesDone(); + unsigned int cycles = SekCyclesDone(); p32x_sync_sh2s(cycles); r[0x02 / 2] = d & 3; p32x_update_cmd_irq(NULL, cycles); @@ -610,9 +610,9 @@ static void p32x_reg_write16(u32 a, u32 d) case 0x2c/2: case 0x2e/2: if (r[a / 2] != d) { - int cycles = SekCyclesDone(); + unsigned int cycles = SekCyclesDone(); - if (cycles - (int)msh2.m68krcycles_done > 30) + if (CYCLES_GT(cycles - msh2.m68krcycles_done, 64)) p32x_sync_sh2s(cycles); r[a / 2] = d; @@ -712,7 +712,7 @@ static void p32x_vdp_write16(u32 a, u32 d, SH2 *sh2) } Pico32x.vdp_regs[0x06 / 2] = a; Pico32x.vdp_regs[0x08 / 2] = d; - if (sh2 != NULL && len > 4) { + if (sh2 != NULL && len > 8) { Pico32x.vdp_regs[0x0a / 2] |= P32XV_nFEN; // supposedly takes 3 bus/6 sh2 cycles? or 3 sh2 cycles? p32x_event_schedule_sh2(sh2, P32X_EVENT_FILLEND, 3 + len); @@ -824,8 +824,8 @@ static void p32x_sh2reg_write8(u32 a, u32 d, SH2 *sh2) if (Pico32x.sh2_regs[4 / 2] != d) { unsigned int cycles = sh2_cycles_done_m68k(sh2); Pico32x.sh2_regs[4 / 2] = d; - sh2_end_run(sh2, 4); p32x_sh2_poll_event(sh2->other_sh2, SH2_STATE_CPOLL, cycles); + sh2_end_run(sh2, 4); sh2_poll_write(a & ~1, d, cycles, sh2); } return; @@ -849,9 +849,9 @@ static void p32x_sh2reg_write8(u32 a, u32 d, SH2 *sh2) unsigned int cycles = sh2_cycles_done_m68k(sh2); REG8IN16(r, a) = d; - sh2_end_run(sh2, 1); p32x_m68k_poll_event(P32XF_68KCPOLL); p32x_sh2_poll_event(sh2->other_sh2, SH2_STATE_CPOLL, cycles); + sh2_end_run(sh2, 1); sh2_poll_write(a & ~1, r[a / 2], cycles, sh2); } return; @@ -941,9 +941,9 @@ static void p32x_sh2reg_write16(u32 a, u32 d, SH2 *sh2) unsigned int cycles = sh2_cycles_done_m68k(sh2); Pico32x.regs[a / 2] = d; - sh2_end_run(sh2, 1); p32x_m68k_poll_event(P32XF_68KCPOLL); p32x_sh2_poll_event(sh2->other_sh2, SH2_STATE_CPOLL, cycles); + sh2_end_run(sh2, 1); sh2_poll_write(a, d, cycles, sh2); } return; @@ -1574,10 +1574,10 @@ static void NOINLINE sh2_sdram_poll(u32 a, u32 d, SH2 *sh2) unsigned cycles; DRC_SAVE_SR(sh2); - sh2_end_run(sh2, 1); cycles = sh2_cycles_done_m68k(sh2); sh2_poll_write(a, d, cycles, sh2); p32x_sh2_poll_event(sh2->other_sh2, SH2_STATE_RPOLL, cycles); + sh2_end_run(sh2, 1); DRC_RESTORE_SR(sh2); } diff --git a/tools/mkoffsets.sh b/tools/mkoffsets.sh index 8f2d888c..2223b804 100755 --- a/tools/mkoffsets.sh +++ b/tools/mkoffsets.sh @@ -11,10 +11,10 @@ ENDIAN= # compile with target C compiler and extract value from .rodata section compile_rodata () { - # $CC $CFLAGS -I .. -shared /tmp/getoffs.c -o /tmp/getoffs.o || exit 1 - echo 'void dummy(void) { asm(""::"r" (&val)); }' >> /tmp/getoffs.c - $CC $CFLAGS -I .. -nostdlib -Wl,-edummy /tmp/getoffs.c \ - -o /tmp/getoffs.o || exit 1 + $CC $CFLAGS -I .. -c /tmp/getoffs.c -o /tmp/getoffs.o || exit 1 + # echo 'void dummy(void) { asm(""::"r" (&val)); }' >> /tmp/getoffs.c + # $CC $CFLAGS -I .. -nostdlib -Wl,-edummy /tmp/getoffs.c \ + # -o /tmp/getoffs.o || exit 1 # find the name of the .rodata section (in case -fdata-sections is used) rosect=$(readelf -S /tmp/getoffs.o | grep '\.rodata' | sed 's/^[^.]*././;s/ .*//') @@ -48,6 +48,7 @@ get_define () # prefix struct member member... line=$(printf "#define %-20s 0x%04x" $prefix$name $rodata) } +CFLAGS="$CFLAGS -fno-lto" # determine endianess echo "const int val = 1;" >/tmp/getoffs.c compile_rodata -- 2.39.5