@@ -3,7 +3,7 @@ use crate::jit::assembler::arm::branch_assembler::Bx;
33use crate :: jit:: assembler:: arm:: transfer_assembler:: { LdmStm , LdrStrImm , LdrStrImmSBHD , LdrStrReg , LdrStrRegSBHD , Mrs , Msr } ;
44use crate :: jit:: assembler:: arm:: Bkpt ;
55use crate :: jit:: assembler:: block_reg_set:: { block_reg_set, BlockRegSet } ;
6- use crate :: jit:: assembler:: { BlockLabel , BlockOperand , BlockOperandShift , BlockReg , BlockShift } ;
6+ use crate :: jit:: assembler:: { block_reg_allocator , BlockLabel , BlockOperand , BlockOperandShift , BlockReg , BlockShift } ;
77use crate :: jit:: inst_info:: { InstInfo , Operand , Shift , ShiftValue } ;
88use crate :: jit:: reg:: { Reg , RegReserve } ;
99use crate :: jit:: { Cond , MemoryAmount , ShiftType } ;
@@ -194,6 +194,16 @@ impl BlockInst {
194194 }
195195 ( inputs, outputs)
196196 }
197+
198+ BlockInst :: Prologue => (
199+ block_reg_set ! ( Some ( BlockReg :: Fixed ( Reg :: SP ) ) , Some ( BlockReg :: Fixed ( Reg :: LR ) ) ) ,
200+ block_reg_set ! ( Some ( BlockReg :: Fixed ( Reg :: SP ) ) ) ,
201+ ) ,
202+ BlockInst :: Epilogue => (
203+ block_reg_set ! ( Some ( BlockReg :: Fixed ( Reg :: SP ) ) ) ,
204+ block_reg_set ! ( Some ( BlockReg :: Fixed ( Reg :: SP ) ) , Some ( BlockReg :: Fixed ( Reg :: PC ) ) ) ,
205+ ) ,
206+
197207 BlockInst :: Label { .. } | BlockInst :: Branch { .. } | BlockInst :: GuestPc ( _) | BlockInst :: Bkpt ( _) => ( block_reg_set ! ( ) , block_reg_set ! ( ) ) ,
198208 }
199209 }
@@ -261,7 +271,7 @@ impl BlockInst {
261271 Self :: replace_reg ( & mut regs_mapping[ reg as usize ] , old, new) ;
262272 }
263273 }
264- BlockInst :: Label { .. } | BlockInst :: Branch { .. } | BlockInst :: GuestPc ( _) | BlockInst :: Bkpt ( _) => { }
274+ BlockInst :: Label { .. } | BlockInst :: Branch { .. } | BlockInst :: GuestPc ( _) | BlockInst :: Bkpt ( _) | BlockInst :: Prologue | BlockInst :: Epilogue => { }
265275 }
266276 }
267277
@@ -315,7 +325,7 @@ impl BlockInst {
315325 Self :: replace_reg ( & mut regs_mapping[ reg as usize ] , old, new) ;
316326 }
317327 }
318- BlockInst :: Label { .. } | BlockInst :: Branch { .. } | BlockInst :: GuestPc ( _) | BlockInst :: Bkpt ( _) => { }
328+ BlockInst :: Label { .. } | BlockInst :: Branch { .. } | BlockInst :: GuestPc ( _) | BlockInst :: Bkpt ( _) | BlockInst :: Prologue | BlockInst :: Epilogue => { }
319329 }
320330 }
321331
@@ -355,7 +365,7 @@ impl BlockInst {
355365 Self :: replace_reg ( reg_mapping, old, new) ;
356366 }
357367 }
358- BlockInst :: Label { .. } | BlockInst :: Branch { .. } | BlockInst :: GuestPc ( _) | BlockInst :: Bkpt ( _) => { }
368+ BlockInst :: Label { .. } | BlockInst :: Branch { .. } | BlockInst :: GuestPc ( _) | BlockInst :: Bkpt ( _) | BlockInst :: Prologue | BlockInst :: Epilogue => { }
359369 }
360370 }
361371
@@ -381,7 +391,7 @@ impl BlockInst {
381391 opcodes. push ( LdrStrImm :: str_offset_al ( guest_reg, thread_regs_addr_reg, Reg :: CPSR as u16 * 4 ) ) ;
382392 }
383393
384- pub fn emit_opcode ( & mut self , opcodes : & mut Vec < u32 > , opcode_index : usize , branch_placeholders : & mut Vec < usize > , opcodes_offset : usize ) {
394+ pub fn emit_opcode ( & mut self , opcodes : & mut Vec < u32 > , opcode_index : usize , branch_placeholders : & mut Vec < usize > , opcodes_offset : usize , used_host_regs : RegReserve ) {
385395 let alu_reg = |op : BlockAluOp , op0 : BlockReg , op1 : BlockReg , op2 : BlockReg , shift : BlockShift , set_cond : bool | match shift. value {
386396 BlockOperand :: Reg ( shift_reg) => AluReg :: generic ( op as u8 , op0. as_fixed ( ) , op1. as_fixed ( ) , op2. as_fixed ( ) , shift. shift_type , shift_reg. as_fixed ( ) , set_cond, Cond :: AL ) ,
387397 BlockOperand :: Imm ( shift_imm) => {
@@ -590,6 +600,11 @@ impl BlockInst {
590600 opcodes. push ( inst_info. assemble ( ) ) ;
591601 }
592602
603+ // BlockInst::Prologue => opcodes.push(LdmStm::generic(Reg::SP, used_host_regs + Reg::LR, false, true, false, true, Cond::AL)),
604+ // BlockInst::Epilogue => opcodes.push(LdmStm::generic(Reg::SP, used_host_regs + Reg::PC, true, true, true, false, Cond::AL)),
605+ BlockInst :: Prologue => opcodes. push ( LdmStm :: generic ( Reg :: SP , block_reg_allocator:: ALLOCATION_REGS + Reg :: LR , false , true , false , true , Cond :: AL ) ) ,
606+ BlockInst :: Epilogue => opcodes. push ( LdmStm :: generic ( Reg :: SP , block_reg_allocator:: ALLOCATION_REGS + Reg :: PC , true , true , true , false , Cond :: AL ) ) ,
607+
593608 BlockInst :: Label { .. } | BlockInst :: GuestPc ( _) => { }
594609 }
595610 }
@@ -713,6 +728,9 @@ pub enum BlockInst {
713728 inst : GuestInstInfo ,
714729 regs_mapping : [ BlockReg ; Reg :: None as usize ] ,
715730 } ,
731+
732+ Prologue ,
733+ Epilogue ,
716734}
717735
718736impl Debug for BlockInst {
@@ -783,6 +801,8 @@ impl Debug for BlockInst {
783801 BlockInst :: Bkpt ( id) => write ! ( f, "Bkpt {id}" ) ,
784802 BlockInst :: GuestPc ( pc) => write ! ( f, "GuestPc {pc:x}" ) ,
785803 BlockInst :: GenericGuestInst { inst, .. } => write ! ( f, "{inst:?}" ) ,
804+ BlockInst :: Prologue => write ! ( f, "Prologue" ) ,
805+ BlockInst :: Epilogue => write ! ( f, "Epilogue" ) ,
786806 }
787807 }
788808}
0 commit comments