@@ -45,13 +45,21 @@ impl JitBuf {
4545 }
4646}
4747
48+ #[ derive( Copy , Clone , Default ) ]
49+ pub struct JitBlockLinkData {
50+ pub desired_lr : u32 ,
51+ pub return_pre_cycle_count_sum : u16 ,
52+ }
53+
4854#[ repr( C ) ]
4955pub struct JitRuntimeData {
5056 pub branch_out_pc : u32 ,
5157 pub branch_out_total_cycles : u16 ,
5258 pub pre_cycle_count_sum : u16 ,
5359 pub accumulated_cycles : u16 ,
5460 pub idle_loop : bool ,
61+ pub block_link_ptr : u8 ,
62+ pub block_link_stack : [ JitBlockLinkData ; 32 ] ,
5563}
5664
5765impl JitRuntimeData {
@@ -62,16 +70,22 @@ impl JitRuntimeData {
6270 pre_cycle_count_sum : 0 ,
6371 accumulated_cycles : 0 ,
6472 idle_loop : false ,
73+ block_link_ptr : 0 ,
74+ block_link_stack : [ JitBlockLinkData :: default ( ) ; 32 ] ,
6575 } ;
76+
6677 let branch_out_pc_ptr = ptr:: addr_of!( instance. branch_out_pc) as usize ;
6778 let branch_out_total_cycles_ptr = ptr:: addr_of!( instance. branch_out_total_cycles) as usize ;
6879 let pre_cycle_count_sum_ptr = ptr:: addr_of!( instance. pre_cycle_count_sum) as usize ;
6980 let accumulated_cycles_ptr = ptr:: addr_of!( instance. accumulated_cycles) as usize ;
7081 let idle_loop_ptr = ptr:: addr_of!( instance. idle_loop) as usize ;
82+ let block_link_ptr_ptr = ptr:: addr_of!( instance. block_link_ptr) as usize ;
83+
7184 assert_eq ! ( branch_out_total_cycles_ptr - branch_out_pc_ptr, Self :: get_out_total_cycles_offset( ) as usize ) ;
7285 assert_eq ! ( pre_cycle_count_sum_ptr - branch_out_pc_ptr, Self :: get_pre_cycle_count_sum_offset( ) as usize ) ;
7386 assert_eq ! ( accumulated_cycles_ptr - branch_out_pc_ptr, Self :: get_accumulated_cycles_offset( ) as usize ) ;
7487 assert_eq ! ( idle_loop_ptr - branch_out_pc_ptr, Self :: get_idle_loop_offset( ) as usize ) ;
88+ assert_eq ! ( block_link_ptr_ptr - branch_out_pc_ptr, Self :: get_block_link_ptr_offset( ) as usize ) ;
7589 instance
7690 }
7791
@@ -98,6 +112,10 @@ impl JitRuntimeData {
98112 pub const fn get_idle_loop_offset ( ) -> u8 {
99113 Self :: get_accumulated_cycles_offset ( ) + 2
100114 }
115+
116+ pub const fn get_block_link_ptr_offset ( ) -> u8 {
117+ Self :: get_idle_loop_offset ( ) + 1
118+ }
101119}
102120
103121pub extern "C" fn emit_code_block < const CPU : CpuType > ( ) {
@@ -136,20 +154,20 @@ fn emit_code_block_internal<const CPU: CpuType, const THUMB: bool>(guest_pc: u32
136154 assert ! ( asm. jit_buf. insts_cycle_counts. len( ) <= u16 :: MAX as usize , "{CPU:?} {guest_pc:x} {inst_info:?}" )
137155 }
138156
139- // let is_unreturnable_branch = !inst_info.out_regs.is_reserved(Reg::LR) && inst_info.is_uncond_branch() && !inst_info.op.is_labelled_branch();
140- let is_uncond_branch = inst_info. is_uncond_branch ( ) ;
157+ let is_unreturnable_branch = !inst_info. out_regs . is_reserved ( Reg :: LR ) && inst_info. is_uncond_branch ( ) && !inst_info. op . is_labelled_branch ( ) ;
158+ // let is_uncond_branch = inst_info.is_uncond_branch();
141159 let is_unknown = inst_info. op == Op :: UnkArm || inst_info. op == Op :: UnkThumb ;
142160
143161 asm. jit_buf . insts . push ( inst_info) ;
144162
145163 index += if THUMB { 2 } else { 4 } ;
146- if is_uncond_branch || is_unknown {
164+ if is_unreturnable_branch || is_unknown {
147165 break ;
148166 }
149167 }
150168 }
151169
152- // unsafe { BLOCK_LOG = true };
170+ unsafe { BLOCK_LOG = true } ;
153171
154172 let thread_regs = get_regs ! ( asm. emu, CPU ) ;
155173 let mut block_asm = unsafe { ( * asm. block_asm_buf . get ( ) ) . new_asm ( thread_regs, ptr:: addr_of_mut!( asm. host_sp) as _ ) } ;
@@ -177,6 +195,7 @@ fn emit_code_block_internal<const CPU: CpuType, const THUMB: bool>(guest_pc: u32
177195 for & opcode in & opcodes {
178196 println ! ( "0x{opcode:x}," ) ;
179197 }
198+ todo ! ( )
180199 }
181200 let insert_entry = get_jit_mut ! ( asm. emu) . insert_block :: < CPU > ( & opcodes, guest_pc) ;
182201 let jit_entry: extern "C" fn ( ) = unsafe { mem:: transmute ( insert_entry) } ;
@@ -210,6 +229,7 @@ fn execute_internal<const CPU: CpuType>(guest_pc: u32) -> u16 {
210229 }
211230 asm. runtime_data . pre_cycle_count_sum = 0 ;
212231 asm. runtime_data . accumulated_cycles = 0 ;
232+ asm. runtime_data . block_link_ptr = 0 ;
213233 get_regs_mut ! ( asm. emu, CPU ) . cycle_correction = 0 ;
214234
215235 jit_entry ( ) ;
0 commit comments