drctest.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. // gcc drctest.c cpu/drc/cmn.c cpu/sh2/mame/sh2dasm.c platform/libpicofe/linux/host_dasm.c platform/libpicofe/linux/plat.c -I. -DDRC_SH2 -g -O -o drctest -lbfd-<ver>-multiarch -lopcodes-<ver>-multiarch -liberty -D<__platform__>
  2. #include <stdarg.h>
  3. #include <stdio.h>
  4. #include <cpu/sh2/compiler.c>
  5. struct Pico Pico;
  6. SH2 sh2s[2];
  7. struct Pico32xMem _Pico32xMem, *Pico32xMem = &_Pico32xMem;
  8. struct Pico32x Pico32x;
  9. char **g_argv;
  10. void memset32(void *dest_in, int c, int count) { memset(dest_in, c, 4*count); }
  11. void cache_flush_d_inval_i(void *start_addr, void *end_addr) { }
  12. void *plat_mem_get_for_drc(size_t size) { return NULL; }
  13. void *p32x_sh2_get_mem_ptr(u32 a, u32 *mask, SH2 *sh2) { return NULL; }
  14. void REGPARM(3) p32x_sh2_write8 (u32 a, u32 d, SH2 *s) { }
  15. void REGPARM(3) p32x_sh2_write16(u32 a, u32 d, SH2 *s) { }
  16. void REGPARM(3) p32x_sh2_write32(u32 a, u32 d, SH2 *s) { }
  17. u32 REGPARM(2) p32x_sh2_read8 (u32 a, SH2 *s) { }
  18. u32 REGPARM(2) p32x_sh2_read16(u32 a, SH2 *s) { }
  19. u32 REGPARM(2) p32x_sh2_read32(u32 a, SH2 *s) { }
  20. u32 REGPARM(3) p32x_sh2_poll_memory8 (u32 a, u32 d, SH2 *s) { }
  21. u32 REGPARM(3) p32x_sh2_poll_memory16(u32 a, u32 d, SH2 *s) { }
  22. u32 REGPARM(3) p32x_sh2_poll_memory32(u32 a, u32 d, SH2 *s) { }
  23. int main(int argc, char *argv[])
  24. {
  25. FILE *f;
  26. u32 (*testfunc)(u32), ret;
  27. int arg0, arg1, arg2, arg3, sr;
  28. host_arg2reg(arg0, 0);
  29. host_arg2reg(arg1, 1);
  30. host_arg2reg(arg2, 2);
  31. host_arg2reg(arg3, 3);
  32. g_argv = argv;
  33. sh2_drc_init(sh2s);
  34. f = fopen("utils.bin", "w");
  35. fwrite(tcache, 1, 4096, f);
  36. fclose(f);
  37. tcache_ptr = tcache_ring[0].base;
  38. u8 *p1 = tcache_ptr;
  39. emith_jump_patchable(0);
  40. u8 *p2 = tcache_ptr;
  41. emith_jump_cond_patchable(DCOND_GE, 0);
  42. emith_move_r_r(0, 1);
  43. emith_move_r_r(0, 2);
  44. u8 *p3 = tcache_ptr;
  45. emith_move_r_r(0, 3);
  46. emith_move_r_r(0, 4);
  47. emith_move_r_r(0, 5);
  48. u8 *p4 = tcache_ptr;
  49. emith_move_r_imm_s8_patchable(arg0, 0);
  50. emith_move_r_r(0, 6);
  51. emith_flush();
  52. emith_jump_patch(p1, tcache_ptr, NULL);
  53. emith_jump_patch(p2, tcache_ptr, NULL);
  54. emith_jump_at(p3, tcache_ptr);
  55. emith_move_r_imm_s8_patch(p4, 42);
  56. emith_read8_r_r_offs(arg0, arg1, 100);
  57. emith_read8_r_r_offs(arg0, arg1, 1000);
  58. emith_read8_r_r_offs(arg0, arg1, 10000);
  59. emith_read8_r_r_offs(arg0, arg1, -100);
  60. emith_read8_r_r_offs(arg0, arg1, -1000);
  61. emith_read8_r_r_offs(arg0, arg1, -10000);
  62. emith_read16_r_r_offs(arg0, arg1, 4);
  63. emith_read_r_r_offs(arg0, arg1, 4);
  64. emith_read8s_r_r_offs(arg0, arg1, 4);
  65. emith_read16s_r_r_offs(arg0, arg1, 4);
  66. emith_write_r_r_offs(arg0, arg1, 4);
  67. emith_add_r_r_r_lsl(arg0, arg1, arg2, 2);
  68. emith_move_r_r(0, 0);
  69. emith_mula_s64(arg0, arg1, arg2, arg3);
  70. emith_move_r_r(0, 0);
  71. emith_clear_msb(arg0, arg1, 8);
  72. emith_clear_msb(arg0, arg1, 16);
  73. emith_clear_msb(arg0, arg1, 24);
  74. emith_sext(arg0, arg1, 8);
  75. emith_sext(arg0, arg1, 16);
  76. emith_sext(arg0, arg1, 24);
  77. emith_move_r_r(0, 0);
  78. emith_lsl(arg0, arg1, 24);
  79. emith_lsr(arg0, arg1, 24);
  80. emith_asr(arg0, arg1, 24);
  81. emith_rol(arg0, arg1, 24);
  82. emith_move_r_r(0, 0);
  83. emith_lslf(arg0, arg1, 24);
  84. emith_lsrf(arg0, arg1, 24);
  85. emith_asrf(arg0, arg1, 24);
  86. emith_rolf(arg0, arg1, 24);
  87. emith_rorf(arg0, arg1, 24);
  88. emith_move_r_r(0, 0);
  89. emith_rolcf(arg0);
  90. emith_rorcf(arg0);
  91. emith_negcf_r_r(arg0, arg1);
  92. emith_move_r_r(0, 0);
  93. emith_eor_r_r_imm(arg0, arg1, 100);
  94. emith_eor_r_r_imm(arg0, arg1, 10000);
  95. emith_eor_r_r_imm(arg0, arg1, -100);
  96. emith_eor_r_r_imm(arg0, arg1, -10000);
  97. emith_move_r_r(0, 0);
  98. emith_move_r_imm(arg0, 100);
  99. emith_move_r_imm(arg0, 1000);
  100. emith_move_r_imm(arg0, 10000);
  101. emith_move_r_imm(arg0, -100);
  102. emith_move_r_imm(arg0, -1000);
  103. emith_move_r_imm(arg0, -10000);
  104. emith_move_r_r(0, 0);
  105. emith_move_r_ptr_imm(arg0, 0x1234567887654321ULL);
  106. emith_move_r_ptr_imm(arg1, 0x8765432112345678ULL);
  107. emith_move_r_ptr_imm(arg2, 0x0011223344556677ULL);
  108. emith_move_r_ptr_imm(arg3, 0x7766554433221100ULL);
  109. emith_move_r_r(0, 0);
  110. emith_tpop_carry(29, 0);
  111. emith_tpush_carry(29, 0);
  112. emith_move_r_r(0, 0);
  113. emith_carry_to_t(29, 0);
  114. emith_t_to_carry(29, 0);
  115. emith_move_r_r(0, 0);
  116. emith_write_sr(29, arg0);
  117. emith_move_r_r(0, 0);
  118. emith_sh2_delay_loop(11, arg0);
  119. emith_move_r_r(0, 0);
  120. emith_sh2_delay_loop(11, -1);
  121. emith_move_r_r(0, 0);
  122. emith_sh2_div1_step(arg0, arg1, 29);
  123. emith_move_r_r(0, 0);
  124. emith_sh2_macl(arg0, arg1, arg2, arg3, 29);
  125. emith_move_r_r(0, 0);
  126. emith_sh2_macw(arg0, arg1, arg2, arg3, 29);
  127. emith_move_r_r(0, 0);
  128. emith_flush();
  129. emith_pool_commit(1);
  130. emith_ret();
  131. f = fopen("test.bin", "w");
  132. fwrite(tcache_ring[0].base, 1, tcache_ptr - tcache_ring[0].base, f);
  133. fclose(f);
  134. do_host_disasm(0);
  135. #if 0
  136. testfunc = (void *)tcache_next[0];
  137. tcache_ptr = tcache_next[0];
  138. emith_move_r_r(RET_REG, arg0);
  139. emith_ret();
  140. host_instructions_updated(tcache_next[0], tcache_ptr);
  141. ret = testfunc(0x00000001);
  142. printf("ret %x\n",ret);
  143. #endif
  144. }