@@ -11,9 +11,10 @@ use crate::jit::op::Op;
1111use crate :: jit:: reg:: Reg ;
1212use crate :: jit:: reg:: { reg_reserve, RegReserve } ;
1313use crate :: logging:: debug_println;
14- use crate :: { get_jit_asm_ptr, DEBUG_LOG , DEBUG_LOG_BRANCH_OUT } ;
14+ use crate :: { get_jit_asm_ptr, DEBUG_LOG , IS_DEBUG } ;
1515use std:: arch:: asm;
1616use std:: cell:: UnsafeCell ;
17+ use std:: hint:: unreachable_unchecked;
1718use std:: intrinsics:: unlikely;
1819use std:: { mem, ptr} ;
1920
@@ -111,22 +112,22 @@ impl JitRuntimeData {
111112
112113pub extern "C" fn hle_bios_uninterrupt < const CPU : CpuType > ( store_host_sp : bool ) {
113114 let asm = unsafe { get_jit_asm_ptr :: < CPU > ( ) . as_mut ( ) . unwrap_unchecked ( ) } ;
114- bios:: uninterrupt :: < CPU > ( asm. emu ) ;
115+ if IS_DEBUG {
116+ asm. runtime_data . branch_out_pc = get_regs ! ( asm. emu, CPU ) . pc ;
117+ }
115118 asm. runtime_data . return_stack_ptr = 0 ;
116119 asm. runtime_data . accumulated_cycles += 3 ;
120+ bios:: uninterrupt :: < CPU > ( asm. emu ) ;
117121 if unlikely ( get_cpu_regs ! ( asm. emu, CPU ) . is_halted ( ) ) {
118- if DEBUG_LOG_BRANCH_OUT {
119- asm. runtime_data . branch_out_pc = get_regs ! ( asm. emu, CPU ) . pc ;
120- }
121122 if !store_host_sp {
122123 // r4-r12,pc since we need an even amount of registers for 8 byte alignment, in case the compiler decides to use neon instructions
123124 unsafe {
124125 asm ! (
125- "mov sp, {}" ,
126- "pop {{r4-r12,pc}}" ,
127- in( reg) asm. runtime_data. host_sp
126+ "mov sp, {}" ,
127+ "pop {{r4-r12,pc}}" ,
128+ in( reg) asm. runtime_data. host_sp
128129 ) ;
129- std :: hint :: unreachable_unchecked ( ) ;
130+ unreachable_unchecked ( ) ;
130131 }
131132 }
132133 } else {
@@ -154,36 +155,37 @@ fn emit_code_block_internal<const CPU: CpuType, const THUMB: bool>(store_host_sp
154155 let asm = unsafe { get_jit_asm_ptr :: < CPU > ( ) . as_mut ( ) . unwrap_unchecked ( ) } ;
155156
156157 {
157- let mut index = 0 ;
158+ let mut pc_offset = 0 ;
158159 loop {
159160 let inst_info = if THUMB {
160- let opcode = asm. emu . mem_read :: < CPU , u16 > ( guest_pc + index ) ;
161+ let opcode = asm. emu . mem_read :: < CPU , u16 > ( guest_pc + pc_offset ) ;
161162 let ( op, func) = lookup_thumb_opcode ( opcode) ;
162163 InstInfo :: from ( func ( opcode, * op) )
163164 } else {
164- let opcode = asm. emu . mem_read :: < CPU , u32 > ( guest_pc + index ) ;
165+ let opcode = asm. emu . mem_read :: < CPU , u32 > ( guest_pc + pc_offset ) ;
165166 let ( op, func) = lookup_opcode ( opcode) ;
166167 func ( opcode, * op)
167168 } ;
168169
170+ if inst_info. op == Op :: UnkArm || inst_info. op == Op :: UnkThumb {
171+ break ;
172+ }
173+
169174 if let Some ( last) = asm. jit_buf . insts_cycle_counts . last ( ) {
170- assert ! ( u16 :: MAX - last >= inst_info. cycle as u16 , "{CPU:?} {guest_pc:x} {inst_info:?}" ) ;
175+ debug_assert ! ( u16 :: MAX - last >= inst_info. cycle as u16 , "{CPU:?} {guest_pc:x} {inst_info:?}" ) ;
171176 asm. jit_buf . insts_cycle_counts . push ( last + inst_info. cycle as u16 ) ;
172177 } else {
173178 asm. jit_buf . insts_cycle_counts . push ( inst_info. cycle as u16 ) ;
174- assert ! ( asm. jit_buf. insts_cycle_counts. len( ) <= u16 :: MAX as usize , "{CPU:?} {guest_pc:x} {inst_info:?}" )
179+ debug_assert ! ( asm. jit_buf. insts_cycle_counts. len( ) <= u16 :: MAX as usize , "{CPU:?} {guest_pc:x} {inst_info:?}" )
175180 }
176181
177182 let is_unreturnable_branch = !inst_info. out_regs . is_reserved ( Reg :: LR ) && inst_info. is_uncond_branch ( ) ;
178- // let is_uncond_branch = inst_info.is_uncond_branch();
179- let is_unknown = inst_info. op == Op :: UnkArm || inst_info. op == Op :: UnkThumb ;
180-
181183 asm. jit_buf . insts . push ( inst_info) ;
182184
183- index += if THUMB { 2 } else { 4 } ;
184- if is_unreturnable_branch || is_unknown {
185+ if is_unreturnable_branch {
185186 break ;
186187 }
188+ pc_offset += if THUMB { 2 } else { 4 } ;
187189 }
188190 }
189191
@@ -198,7 +200,7 @@ fn emit_code_block_internal<const CPU: CpuType, const THUMB: bool>(store_host_sp
198200 block_asm. restore_reg ( Reg :: CPSR ) ;
199201 }
200202
201- // if guest_pc == 0x20b2688 {
203+ // if guest_pc == 0x2001b5e {
202204 // block_asm.bkpt(2);
203205 // }
204206
@@ -207,7 +209,7 @@ fn emit_code_block_internal<const CPU: CpuType, const THUMB: bool>(store_host_sp
207209 asm. jit_buf . current_pc = guest_pc + ( i << if THUMB { 1 } else { 2 } ) as u32 ;
208210 debug_println ! ( "{CPU:?} emitting {:?} at pc: {:x}" , asm. jit_buf. current_inst( ) , asm. jit_buf. current_pc) ;
209211
210- // if asm.jit_buf.current_pc == 0x20216e2 {
212+ // if asm.jit_buf.current_pc == 0x2001b5c {
211213 // block_asm.bkpt(1);
212214 // }
213215
@@ -217,11 +219,11 @@ fn emit_code_block_internal<const CPU: CpuType, const THUMB: bool>(store_host_sp
217219 asm. emit ( & mut block_asm) ;
218220 }
219221
220- // if DEBUG_LOG {
221- // block_asm.save_context();
222- // block_asm.call2(debug_after_exec_op::<CPU> as *const (), asm.jit_buf.current_pc, asm.jit_buf.current_inst().opcode);
223- // block_asm.restore_reg(Reg::CPSR);
224- // }
222+ if DEBUG_LOG {
223+ block_asm. save_context ( ) ;
224+ block_asm. call2 ( debug_after_exec_op :: < CPU > as * const ( ) , asm. jit_buf . current_pc , asm. jit_buf . current_inst ( ) . opcode ) ;
225+ block_asm. restore_reg ( Reg :: CPSR ) ;
226+ }
225227 }
226228
227229 let opcodes = block_asm. finalize ( guest_pc, THUMB ) ;
@@ -263,7 +265,7 @@ fn execute_internal<const CPU: CpuType>(guest_pc: u32) -> u16 {
263265
264266 debug_println ! ( "{CPU:?} Enter jit addr {:x}" , jit_entry as usize ) ;
265267
266- if DEBUG_LOG {
268+ if IS_DEBUG {
267269 asm. runtime_data . branch_out_pc = u32:: MAX ;
268270 }
269271 asm. runtime_data . pre_cycle_count_sum = 0 ;
@@ -274,11 +276,9 @@ fn execute_internal<const CPU: CpuType>(guest_pc: u32) -> u16 {
274276
275277 jit_entry ( true ) ;
276278
277- if DEBUG_LOG {
278- assert_ne ! ( asm. runtime_data. branch_out_pc, u32 :: MAX ) ;
279- }
279+ debug_assert_ne ! ( asm. runtime_data. branch_out_pc, u32 :: MAX ) ;
280280
281- if DEBUG_LOG && DEBUG_LOG_BRANCH_OUT {
281+ if DEBUG_LOG {
282282 println ! (
283283 "{:?} reading opcode of breakout at {:x} executed cycles {}" ,
284284 CPU , asm. runtime_data. branch_out_pc, asm. runtime_data. accumulated_cycles
0 commit comments