From a6905b4de17f4d772c7742065f2863b77ddf0b31 Mon Sep 17 00:00:00 2001 From: notaz Date: Sun, 16 Jun 2013 19:48:40 +0300 Subject: [PATCH] tests and tools from PicoDrive --- tests/crash_cyclone.bin | Bin 0 -> 524 bytes tests/test_abcd.bin | Bin 0 -> 570 bytes tests/test_cmpm.bin | Bin 0 -> 618 bytes tests/test_div.bin | Bin 0 -> 604 bytes tests/test_misc2_gen.c | 119 +++++++++++++++++++++++++++ tests/test_negx.bin | Bin 0 -> 542 bytes tests/test_rol.bin | Bin 0 -> 578 bytes tests/test_shift.bin | Bin 0 -> 582 bytes tests/test_trace.bin | Bin 0 -> 558 bytes tests/test_trace.s | 140 ++++++++++++++++++++++++++++++++ tools/idle.h | 3 + tools/idle.s | 176 ++++++++++++++++++++++++++++++++++++++++ 12 files changed, 438 insertions(+) create mode 100644 tests/crash_cyclone.bin create mode 100644 tests/test_abcd.bin create mode 100644 tests/test_cmpm.bin create mode 100644 tests/test_div.bin create mode 100644 tests/test_misc2_gen.c create mode 100644 tests/test_negx.bin create mode 100644 tests/test_rol.bin create mode 100644 tests/test_shift.bin create mode 100644 tests/test_trace.bin create mode 100644 tests/test_trace.s create mode 100644 tools/idle.h create mode 100644 tools/idle.s diff --git a/tests/crash_cyclone.bin b/tests/crash_cyclone.bin new file mode 100644 index 0000000000000000000000000000000000000000..dfa0276ad88bc70f5f4a9953056f7eab2435b3d4 GIT binary patch literal 524 zcmZQz00AZ@1_qXUKs*7+2JuP2ApQ6NA+zx5rM;ZOpaPwWUTE$Chk*S5{|x_utpET2 g2RUv~U{GLSWKgjGkEWC;ZYY{6zvBP@{R$xv07N`3q5uE@ literal 0 HcmV?d00001 diff --git a/tests/test_abcd.bin b/tests/test_abcd.bin new file mode 100644 index 0000000000000000000000000000000000000000..fe2504002e8085aa741cf157a6806ab897852f8d GIT binary patch literal 570 zcmZQz00AZ@1_qXUKs*76R{{AzF)$w}hRlYEkxH|AFfhRJBq)0dkPZUc6T`qDZUMwH zKpX@e0P{EdT%e6+$2YZ!K)D literal 0 HcmV?d00001 diff --git a/tests/test_cmpm.bin b/tests/test_cmpm.bin new file mode 100644 index 0000000000000000000000000000000000000000..e76185787596b4933339a51030d87212fbf10a78 GIT binary patch literal 618 zcmZQz00AZ@1_qXUKs*76R{{AzF)$w}hRlYEkxH|AFfhRJBq)0dkPZUc6T`qDZUMwH zKpX +#include +#include + + +static FILE *f; + +#define bswap16(x) (x=(unsigned short)((x<<8)|(x>>8))) +#define bswap32(x) (x=((x<<24)|((x<<8)&0xff0000)|((x>>8)&0x00ff00)|((unsigned)x>>24))) + +static void write_op(unsigned short op, unsigned short word0, unsigned short word1, unsigned short word2) +{ + bswap16(op); + bswap16(word0); + bswap16(word1); + bswap16(word2); + + fwrite(&op, 1, sizeof(op), f); + fwrite(&word0, 1, sizeof(word0), f); + fwrite(&word1, 1, sizeof(word1), f); + fwrite(&word2, 1, sizeof(word2), f); +} + +static void write32(unsigned int a) +{ + bswap32(a); + fwrite(&a, 1, sizeof(a), f); +} + +static int op_check(unsigned short op) +{ + if ((op&0xf000) == 0x6000) return 0; // Bxx + if ((op&0xf0f8) == 0x50c8) return 0; // DBxx + if ((op&0xff80) == 0x4e80) return 0; // Jsr + if ((op&0xf000) == 0xa000) return 0; // a-line + if ((op&0xf000) == 0xf000) return 0; // f-line + if ((op&0xfff8)==0x4e70&&op!=0x4e71&&op!=0x4e76) return 0; // reset, rte, rts + + if ((op&0x3f) >= 0x28) op = (op&~0x3f) | (rand() % 0x28); + return 1; +} + +static unsigned short safe_rand(void) +{ + unsigned short op; + + /* avoid branch opcodes */ + do + { + op = rand(); + } + while (!op_check(op)); + + return op; +} + +int main() +{ + int i, op; + + srand(time(0)); + + f = fopen("test_misc2.bin", "wb"); + if (!f) return 1; + + write32(0x00ff8000); // stack + write32(0x300); // IP + + for (i=0x100/4-2; i; i--) + { + write32(0x200+i*4); // exception vectors + } + + for (i=0x100/4; i; i--) + { + write32(0); // pad + } + + for (i=0x100/4; i; i--) + { + write32(0x4e734e73); // fill with rte instructions + } + + for (op = 0; op < 0x10000; op++) + { + if ((op&0xf000) == 0x6000) // Bxx + { + if ((op&0x00ff) == 0) + write_op(op, 6, 0, 0); + } + else if ((op&0xf0f8)==0x50c8) // DBxx + { + write_op(op, 6, 0, 0); + } + else if ((op&0xff80)==0x4e80) // Jsr + { + int addr = 0x300 + op*8 + 8; + if ((op&0x3f) == 0x39) + write_op(op, addr >> 16, addr & 0xffff, 0); + } + else if ((op&0xf000)==0xa000 || (op&0xf000)==0xf000) // a-line, f-line + { + if (op != 0xa000 && op != 0xf000) continue; + } + else if ((op&0xfff8)==0x4e70&&op!=0x4e71&&op!=0x4e76); // rte, rts, stop, reset + else + { + write_op(op, safe_rand(), safe_rand(), safe_rand()); + } + } + + // jump to the beginning + write_op(0x4ef8, 0x300, 0x4ef8, 0x300); + write_op(0x4ef8, 0x300, 0x4ef8, 0x300); + + fclose(f); + return 0; +} + diff --git a/tests/test_negx.bin b/tests/test_negx.bin new file mode 100644 index 0000000000000000000000000000000000000000..1f6e6cf696d2ce5adc111b6feffc80d209f7542b GIT binary patch literal 542 zcmZQz00AZ-X1NE%6M%RX5Fdf^L1I+EtR4&ua6Adho&uzUfab?AFo;_Ku?!H005Q-l ztYJW01yu*s%YF{QhMNO5lQQ=OySh6nxV!qf273l80D*?HCRoVO($YlFE7ZrOG`Ao% zMZu|3AtcxZq<{bj_VD!c^mA8m^AB=%RWKr;T0z0xSHag?*U;F|R6*Ckpi|KcO$R7; z807!|XZR1K|Ns9V;p=hcK{uli(VN|nWU}#`)XmDtBU~+K& J|KG0=0s)GBWj+7^ literal 0 HcmV?d00001 diff --git a/tests/test_rol.bin b/tests/test_rol.bin new file mode 100644 index 0000000000000000000000000000000000000000..0cb0a412cd64c087b84bcb2d16456525618108cb GIT binary patch literal 578 zcmZQz00AZ@1_qXUKs*76R{{AzF)$w}hRlYEkxH|AFfhRJBq)0dkPZUc6T`qDZUMwH zKpX34rV0>iZ ra2(3!e_Y{k49aGBRN-*6fLX}~Xn*759S%ndn2Q)5@A&`UuMh$OHxz9b literal 0 HcmV?d00001 diff --git a/tests/test_shift.bin b/tests/test_shift.bin new file mode 100644 index 0000000000000000000000000000000000000000..c364f218c817a76856e3d9afb111e5cf041558fb GIT binary patch literal 582 zcmZQz00AZ@1_qXUKs*76R{{AzF)$w}hRlYEkxH|AFfhRJBq)0dkPZUc6T`qDZUMwH zKpX34rV0@(D va2(2JaQmbF|M3ckV^BW-;{=DJ3N}C&G!!ub)g38dE|Pz|;{SiYLI?x^3es-$ literal 0 HcmV?d00001 diff --git a/tests/test_trace.bin b/tests/test_trace.bin new file mode 100644 index 0000000000000000000000000000000000000000..e9ca5fa9d3c0b901da110c53bda826347b9c8d4f GIT binary patch literal 558 zcmZQzU|?uqU}9rnV7Ujx6M%RX5Fdf^L1OoS@<3H!c`%=JHme5%0~}9+vZny)AfQ<> z3=HBHKr92qAwUeYi!}_0tDx$DdfCq**l=^8W>VrVmV3dj?v4uXu70k;p1}%0py8|u z7BaN7G|}@4^>Hc9El5pKaH>=Y33dS~AOM0rJpDZV+!fsXgPdIzj0mV!P;mEE@b%U; zG&VF<&^0jVRP;jA0SpWV2KoR08U6$5|Ns97Ic`v3P+(wWP_X}xrj#gdD4Ht2LLe+I n_+Rwj?ay+-5=J!}P" "<0><1><0>" ?"<0xFF> | Modem_Infos + .ascii " " + .byte 0x20 | + .byte 0x20 | + .byte 0x20 | + .byte 0x20 | + .byte 0x20 | + .byte 0x20 | + .byte 0x20 | + .byte 0x20 | + .byte 0x20 | + .byte 0x20 | + .byte 0x20 | + .byte 0x20 | +aU: .ascii "U " | Countries + .byte 0x20 | + .byte 0x20 | + .byte 0x20 | + .byte 0x20 | + .byte 0x20 | + .byte 0x20 | + .byte 0x20 | + .byte 0x20 | + .byte 0x20 | + .byte 0x20 | + .byte 0x20 | + .byte 0x20 | + .byte 0x20 | +_trace: + nop + nop + rte + +.globl _start +_start: + move.l #0xFFFFFFFF, %d0 + move.l #0xFFFFFFFF, %d1 + move.w #0xa711, %sr + move.l #0x1, %d2 + move.l #0x8000, %d3 + negx.l %d0 + negx.l %d1 + move.w #0x270f, %sr + negx.b %d2 + negx.w %d3 +_loop: + bra _loop + + nop + nop + nop + nop diff --git a/tools/idle.h b/tools/idle.h new file mode 100644 index 0000000..254cc57 --- /dev/null +++ b/tools/idle.h @@ -0,0 +1,3 @@ + +void CycloneInitIdle(void); +void CycloneFinishIdle(void); diff --git a/tools/idle.s b/tools/idle.s new file mode 100644 index 0000000..a8b7cca --- /dev/null +++ b/tools/idle.s @@ -0,0 +1,176 @@ +@ vim:filetype=armasm + +@ ranges/opcodes (idle, normal): +@ 71xx, 73xx - bne.s (8bit offset) +@ 75xx, 77xx - beq.s (8bit offset) +@ 7dxx, 7fxx - bra.s (8bit offset) + +.data +.align 2 + +have_patches: + .word 0 + +.equ patch_desc_table_size, 10 + +patch_desc_table: + .word (0x71fa<<16) | 0x66fa, idle_detector_bcc8, idle_bne, Op6601 @ bne.s + .word (0x71f8<<16) | 0x66f8, idle_detector_bcc8, idle_bne, Op6601 @ bne.s + .word (0x71f6<<16) | 0x66f6, idle_detector_bcc8, idle_bne, Op6601 @ bne.s + .word (0x71f2<<16) | 0x66f2, idle_detector_bcc8, idle_bne, Op6601 @ bne.s + .word (0x75fa<<16) | 0x67fa, idle_detector_bcc8, idle_beq, Op6701 @ beq.s + .word (0x75f8<<16) | 0x67f8, idle_detector_bcc8, idle_beq, Op6701 @ beq.s + .word (0x75f6<<16) | 0x67f6, idle_detector_bcc8, idle_beq, Op6701 @ beq.s + .word (0x75f2<<16) | 0x67f2, idle_detector_bcc8, idle_beq, Op6701 @ beq.s + .word (0x7dfe<<16) | 0x60fe, idle_detector_bcc8, idle_bra, Op6001 @ bra.s + .word (0x7dfc<<16) | 0x60fc, idle_detector_bcc8, idle_bra, Op6001 @ bra.s + + +.text +.align 2 + + +.global CycloneInitIdle + +CycloneInitIdle: + ldr r3, =CycloneJumpTab + ldr r2, =patch_desc_table + mov r12,#patch_desc_table_size + +cii_loop: + ldrh r0, [r2] + ldr r1, [r2, #4] @ detector + str r1, [r3, r0, lsl #2] + ldrh r0, [r2, #2] + ldr r1, [r2, #8] @ idle + add r0, r3, r0, lsl #2 + str r1, [r0] + ldr r1, [r2, #12] @ normal + str r1, [r0, #0x800] + add r2, r2, #16 + subs r12,r12,#1 + bgt cii_loop + + ldr r0, =have_patches + mov r1, #1 + str r1, [r0] + bx lr + + +.global CycloneFinishIdle + +CycloneFinishIdle: + ldr r0, =have_patches + ldr r0, [r0] + tst r0, r0 + bxeq lr + + ldr r3, =CycloneJumpTab + ldr r2, =patch_desc_table + mov r12,#patch_desc_table_size + +cfi_loop: + ldrh r0, [r2] + ldr r1, [r2, #12] @ normal + str r1, [r3, r0, lsl #2] + ldrh r0, [r2, #2] + ldr r1, =Op____ + add r0, r3, r0, lsl #2 + str r1, [r0] + str r1, [r0, #0x800] + add r2, r2, #16 + subs r12,r12,#1 + bgt cfi_loop + + ldr r0, =have_patches + mov r1, #0 + str r1, [r0] + bx lr + + + +.macro inc_counter cond +@ ldr\cond r0, [r7, #0x60] +@ mov r11,lr +@ sub r0, r4, r0 +@ sub r0, r0, #2 +@ bl\cond SekRegisterIdleHit +@ mov lr, r11 +.endm + +idle_bra: + mov r5, #2 + inc_counter + b Op6001 + +idle_bne: + msr cpsr_flg, r10 + movne r5, #2 @ 2 is intentional due to strange timing issues + inc_counter ne + b Op6601 + +idle_beq: + msr cpsr_flg, r10 ;@ ARM flags = 68000 flags + moveq r5, #2 + inc_counter eq + b Op6701 + + +@ @@@ @ + +idle_detector_bcc8: + ldr r0, =(Pico+0x22208) @ Pico.m + ldr r1, =idledet_start_frame + ldr r0, [r0, #0x1c] @ ..frame_count + ldr r1, [r1] + cmp r0, r1 + blt exit_detector @ not yet + + mov r0, r8, asl #24 @ Shift 8-bit signed offset up... + add r0, r4, r0, asr #24 @ jump dest + bic r0, r0, #1 + + mov r1, #0 + sub r1, r1, r8, lsl #24 + mov r1, r1, lsr #24 + sub r1, r1, #2 + bic r1, r1, #1 + + bl SekIsIdleCode + tst r0, r0 + and r2, r8, #0x00ff + orr r2, r2, #0x7100 + orreq r2, r2, #0x0200 + mov r0, r8, lsr #8 + cmp r0, #0x66 + orrgt r2, r2, #0x0400 @ 67xx (beq) + orrlt r2, r2, #0x0c00 @ 60xx (bra) + + @ r2 = patch_opcode + sub r0, r4, #2 + ldrh r1, [r0] + mov r11,r2 + mov r3, r7 + bl SekRegisterIdlePatch + cmp r0, #1 @ 0 - ok to patch, 1 - no patch, 2 - remove detector + strlth r11,[r4, #-2] + ble exit_detector + + @ remove detector from Cyclone + mov r0, r8, lsr #8 + cmp r0, #0x66 + ldrlt r1, =Op6001 + ldreq r1, =Op6601 + ldrgt r1, =Op6701 + + ldr r3, =CycloneJumpTab + str r1, [r3, r8, lsl #2] + bx r1 + +exit_detector: + mov r0, r8, lsr #8 + cmp r0, #0x66 + blt Op6001 + beq Op6601 + b Op6701 + -- 2.39.5