some drc debug patches
[pcsx_rearmed.git] / libpcsxcore / new_dynarec / patches / trace_drc_chk
1 diff --git a/libpcsxcore/new_dynarec/linkage_arm.S b/libpcsxcore/new_dynarec/linkage_arm.S
2 index d32dc0b..e52dde8 100644
3 --- a/libpcsxcore/new_dynarec/linkage_arm.S
4 +++ b/libpcsxcore/new_dynarec/linkage_arm.S
5 @@ -442,7 +442,7 @@ FUNCTION(cc_interrupt):
6         str     r1, [fp, #LO_pending_exception]
7         and     r2, r2, r10, lsr #17
8         add     r3, fp, #LO_restore_candidate
9 -       str     r10, [fp, #LO_cycle]            /* PCSX cycles */
10 +@@@    str     r10, [fp, #LO_cycle]            /* PCSX cycles */
11  @@     str     r10, [fp, #LO_reg_cop0+36]      /* Count */
12         ldr     r4, [r2, r3]
13         mov     r10, lr
14 @@ -530,7 +530,7 @@ FUNCTION(jump_syscall_hle):
15         mov     r1, #0    /* in delay slot */
16         add     r2, r2, r10
17         mov     r0, #0x20 /* cause */
18 -       str     r2, [fp, #LO_cycle] /* PCSX cycle counter */
19 +@@@    str     r2, [fp, #LO_cycle] /* PCSX cycle counter */
20         bl      psxException
21  
22         /* note: psxException might do recursive recompiler call from it's HLE code,
23 @@ -551,7 +551,7 @@ FUNCTION(jump_hlecall):
24         str     r0, [fp, #LO_pcaddr]
25         add     r2, r2, r10
26         adr     lr, pcsx_return
27 -       str     r2, [fp, #LO_cycle] /* PCSX cycle counter */
28 +@@@    str     r2, [fp, #LO_cycle] /* PCSX cycle counter */
29         bx      r1
30         .size   jump_hlecall, .-jump_hlecall
31  
32 @@ -561,7 +561,7 @@ FUNCTION(jump_intcall):
33         str     r0, [fp, #LO_pcaddr]
34         add     r2, r2, r10
35         adr     lr, pcsx_return
36 -       str     r2, [fp, #LO_cycle] /* PCSX cycle counter */
37 +@@@    str     r2, [fp, #LO_cycle] /* PCSX cycle counter */
38         b       execI
39         .size   jump_hlecall, .-jump_hlecall
40  
41 @@ -570,7 +570,7 @@ FUNCTION(new_dyna_leave):
42         ldr     r0, [fp, #LO_last_count]
43         add     r12, fp, #28
44         add     r10, r0, r10
45 -       str     r10, [fp, #LO_cycle]
46 +@@@    str     r10, [fp, #LO_cycle]
47         ldmfd   sp!, {r4, r5, r6, r7, r8, r9, sl, fp, ip, pc}
48         .size   new_dyna_leave, .-new_dyna_leave
49  
50 @@ -687,7 +687,7 @@ FUNCTION(new_dyna_start):
51         \readop r0, [r1, r3, lsl #\tab_shift]
52  .endif
53         movcc   pc, lr
54 -       str     r2, [fp, #LO_cycle]
55 +@@@    str     r2, [fp, #LO_cycle]
56         bx      r1
57  .endm
58  
59 @@ -722,7 +722,7 @@ FUNCTION(jump_handler_read32):
60         mov     r0, r1
61         add     r2, r2, r12
62         push    {r2, lr}
63 -       str     r2, [fp, #LO_cycle]
64 +@@@    str     r2, [fp, #LO_cycle]
65         blx     r3
66  
67         ldr     r0, [fp, #LO_next_interupt]
68 @@ -750,7 +750,7 @@ FUNCTION(jump_handler_write_h):
69         add     r2, r2, r12
70         mov     r0, r1
71         push    {r2, lr}
72 -       str     r2, [fp, #LO_cycle]
73 +@@@    str     r2, [fp, #LO_cycle]
74         blx     r3
75  
76         ldr     r0, [fp, #LO_next_interupt]
77 diff --git a/libpcsxcore/new_dynarec/new_dynarec.c b/libpcsxcore/new_dynarec/new_dynarec.c
78 index 6d7069d..586a6db 100644
79 --- a/libpcsxcore/new_dynarec/new_dynarec.c
80 +++ b/libpcsxcore/new_dynarec/new_dynarec.c
81 @@ -38,10 +38,10 @@ static int sceBlock;
82  #include "../psxhle.h" //emulator interface
83  #include "emu_if.h" //emulator interface
84  
85 -//#define DISASM
86 -//#define assem_debug printf
87 +#define DISASM
88 +#define assem_debug printf
89  //#define inv_debug printf
90 -#define assem_debug(...)
91 +//#define assem_debug(...)
92  #define inv_debug(...)
93  
94  #ifdef __i386__
95 @@ -362,6 +362,9 @@ static u_int get_vpage(u_int vaddr)
96  // This is called from the recompiled JR/JALR instructions
97  void *get_addr(u_int vaddr)
98  {
99 +#ifdef DRC_DBG
100 +printf("get_addr %08x, pc=%08x\n", vaddr, psxRegs.pc);
101 +#endif
102    u_int page=get_page(vaddr);
103    u_int vpage=get_vpage(vaddr);
104    struct ll_entry *head;
105 @@ -4403,13 +4406,15 @@ void do_cc(int i,signed char i_regmap[],int *adj,int addr,int taken,int invert)
106      }
107      emit_addimm_and_set_flags(cycles,HOST_CCREG);
108      jaddr=(int)out;
109 -    emit_jns(0);
110 +//    emit_jns(0);
111 +emit_jmp(0);
112    }
113    else
114    {
115      emit_cmpimm(HOST_CCREG,-CLOCK_ADJUST(count+2));
116      jaddr=(int)out;
117 -    emit_jns(0);
118 +//    emit_jns(0);
119 +emit_jmp(0);
120    }
121    add_stub(CC_STUB,jaddr,idle?idle:(int)out,(*adj==0||invert||idle)?0:(count+2),i,addr,taken,0);
122  }
123 @@ -4884,7 +4889,8 @@ void rjump_assemble(int i,struct regstat *i_regs)
124      // special case for RFE
125      emit_jmp(0);
126    else
127 -    emit_jns(0);
128 +    //emit_jns(0);
129 +    emit_jmp(0);
130    //load_regs_bt(branch_regs[i].regmap,branch_regs[i].is32,branch_regs[i].dirty,-1);
131    #ifdef USE_MINI_HT
132    if(rs1[i]==31) {
133 @@ -5034,7 +5040,8 @@ void cjump_assemble(int i,struct regstat *i_regs)
134      else if(nop) {
135        emit_addimm_and_set_flags(CLOCK_ADJUST(ccadj[i]+2),cc);
136        int jaddr=(int)out;
137 -      emit_jns(0);
138 +//      emit_jns(0);
139 +emit_jmp(0);
140        add_stub(CC_STUB,jaddr,(int)out,0,i,start+i*4+8,NOTTAKEN,0);
141      }
142      else {
143 @@ -5300,7 +5307,8 @@ void cjump_assemble(int i,struct regstat *i_regs)
144          emit_loadreg(CCREG,HOST_CCREG);
145          emit_addimm_and_set_flags(CLOCK_ADJUST(ccadj[i]+2),HOST_CCREG);
146          int jaddr=(int)out;
147 -        emit_jns(0);
148 +//        emit_jns(0);
149 +emit_jmp(0);
150          add_stub(CC_STUB,jaddr,(int)out,0,i,start+i*4+8,NOTTAKEN,0);
151          emit_storereg(CCREG,HOST_CCREG);
152        }
153 @@ -5309,7 +5317,8 @@ void cjump_assemble(int i,struct regstat *i_regs)
154          assert(cc==HOST_CCREG);
155          emit_addimm_and_set_flags(CLOCK_ADJUST(ccadj[i]+2),cc);
156          int jaddr=(int)out;
157 -        emit_jns(0);
158 +//        emit_jns(0);
159 +emit_jmp(0);
160          add_stub(CC_STUB,jaddr,(int)out,0,i,start+i*4+8,likely[i]?NULLDS:NOTTAKEN,0);
161        }
162      }
163 @@ -5419,7 +5428,8 @@ void sjump_assemble(int i,struct regstat *i_regs)
164      else if(nevertaken) {
165        emit_addimm_and_set_flags(CLOCK_ADJUST(ccadj[i]+2),cc);
166        int jaddr=(int)out;
167 -      emit_jns(0);
168 +//      emit_jns(0);
169 +emit_jmp(0);
170        add_stub(CC_STUB,jaddr,(int)out,0,i,start+i*4+8,NOTTAKEN,0);
171      }
172      else {
173 @@ -5628,7 +5638,8 @@ void sjump_assemble(int i,struct regstat *i_regs)
174          emit_loadreg(CCREG,HOST_CCREG);
175          emit_addimm_and_set_flags(CLOCK_ADJUST(ccadj[i]+2),HOST_CCREG);
176          int jaddr=(int)out;
177 -        emit_jns(0);
178 +//        emit_jns(0);
179 +emit_jmp(0);
180          add_stub(CC_STUB,jaddr,(int)out,0,i,start+i*4+8,NOTTAKEN,0);
181          emit_storereg(CCREG,HOST_CCREG);
182        }
183 @@ -5637,7 +5648,8 @@ void sjump_assemble(int i,struct regstat *i_regs)
184          assert(cc==HOST_CCREG);
185          emit_addimm_and_set_flags(CLOCK_ADJUST(ccadj[i]+2),cc);
186          int jaddr=(int)out;
187 -        emit_jns(0);
188 +//        emit_jns(0);
189 +emit_jmp(0);
190          add_stub(CC_STUB,jaddr,(int)out,0,i,start+i*4+8,likely[i]?NULLDS:NOTTAKEN,0);
191        }
192      }
193 @@ -5833,7 +5845,8 @@ void fjump_assemble(int i,struct regstat *i_regs)
194          emit_loadreg(CCREG,HOST_CCREG);
195          emit_addimm_and_set_flags(CLOCK_ADJUST(ccadj[i]+2),HOST_CCREG);
196          int jaddr=(int)out;
197 -        emit_jns(0);
198 +//        emit_jns(0);
199 +emit_jmp(0);
200          add_stub(CC_STUB,jaddr,(int)out,0,i,start+i*4+8,NOTTAKEN,0);
201          emit_storereg(CCREG,HOST_CCREG);
202        }
203 @@ -5842,7 +5855,8 @@ void fjump_assemble(int i,struct regstat *i_regs)
204          assert(cc==HOST_CCREG);
205          emit_addimm_and_set_flags(CLOCK_ADJUST(ccadj[i]+2),cc);
206          int jaddr=(int)out;
207 -        emit_jns(0);
208 +//        emit_jns(0);
209 +emit_jmp(0);
210          add_stub(CC_STUB,jaddr,(int)out,0,i,start+i*4+8,likely[i]?NULLDS:NOTTAKEN,0);
211        }
212      }
213 @@ -6463,7 +6477,7 @@ void unneeded_registers(int istart,int iend,int r)
214      // R0 is always unneeded
215      u|=1;uu|=1;
216      // Save it
217 -    unneeded_reg[i]=u;
218 +    unneeded_reg[i]=1;//u;
219      unneeded_reg_upper[i]=uu;
220      gte_unneeded[i]=gte_u;
221      /*
222 @@ -9676,6 +9690,7 @@ int new_recompile_block(int addr)
223  
224    // This allocates registers (if possible) one instruction prior
225    // to use, which can avoid a load-use penalty on certain CPUs.
226 +#if 0
227    for(i=0;i<slen-1;i++)
228    {
229      if(!i||(itype[i-1]!=UJUMP&&itype[i-1]!=CJUMP&&itype[i-1]!=SJUMP&&itype[i-1]!=RJUMP&&itype[i-1]!=FJUMP))
230 @@ -9832,6 +9847,7 @@ int new_recompile_block(int addr)
231        }
232      }
233    }
234 +#endif
235  
236    /* Pass 6 - Optimize clean/dirty state */
237    clean_registers(0,slen-1,1);
238 @@ -10149,6 +10165,11 @@ int new_recompile_block(int addr)
239          case SPAN:
240            pagespan_assemble(i,&regs[i]);break;
241        }
242 +
243 +#ifdef DRC_DBG
244 +      if(itype[i]!=UJUMP&&itype[i]!=CJUMP&&itype[i]!=SJUMP&&itype[i]!=RJUMP)
245 +        wb_dirtys(regs[i].regmap,regs[i].is32,regs[i].dirty);
246 +#endif
247        if(itype[i]==UJUMP||itype[i]==RJUMP||(source[i]>>16)==0x1000)
248          literal_pool(1024);
249        else
250 @@ -10256,7 +10277,7 @@ int new_recompile_block(int addr)
251      }
252    }
253    // External Branch Targets (jump_in)
254 -  if(copy+slen*4>(void *)shadow+sizeof(shadow)) copy=shadow;
255 +  if(copy+slen*4>(void *)shadow+sizeof(shadow)) {copy=shadow;printf("shadow overflow\n");}
256    for(i=0;i<slen;i++)
257    {
258      if(bt[i]||i==0)
259 @@ -10370,6 +10391,10 @@ int new_recompile_block(int addr)
260      }
261      expirep=(expirep+1)&65535;
262    }
263 +#ifdef DRC_DBG
264 +printf("new_recompile_block done\n");
265 +fflush(stdout);
266 +#endif
267    return 0;
268  }
269