Skip to content

Commit d2fdb33

Browse files
committed
WIP
1 parent 8bd4f89 commit d2fdb33

File tree

4 files changed

+28
-10
lines changed

4 files changed

+28
-10
lines changed

src/jit/emitter/emit.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ impl<'a, const CPU: CpuType> JitAsm<'a, CPU> {
1818
block_asm.start_cond_block(cond);
1919
match op {
2020
Op::B | Op::Bl => self.emit_branch_label(block_asm),
21-
Op::Bx | Op::BlxReg => self.emit_branch_reg(block_asm),
21+
Op::Bx => self.emit_bx(block_asm),
22+
Op::BlxReg => self.emit_blx(block_asm),
2223
Op::Blx => self.emit_blx_label(block_asm),
2324
Op::Mcr | Op::Mrc => self.emit_cp15(block_asm),
2425
Op::MsrRc | Op::MsrIc | Op::MsrRs | Op::MsrIs => self.emit_msr(block_asm),

src/jit/emitter/emit_branch.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,19 +113,35 @@ impl<'a, const CPU: CpuType> JitAsm<'a, CPU> {
113113
block_asm.epilogue();
114114
}
115115

116-
pub fn emit_branch_reg(&mut self, block_asm: &mut BlockAsm) {
116+
pub fn emit_bx(&mut self, block_asm: &mut BlockAsm) {
117117
let inst_info = self.jit_buf.current_inst();
118118
let branch_to = *inst_info.operands()[0].as_reg_no_shift().unwrap();
119119

120-
if inst_info.op == Op::BlxReg {
121-
block_asm.mov(Reg::LR, self.jit_buf.current_pc + 4);
122-
}
123120
block_asm.mov(Reg::PC, branch_to);
124121
block_asm.save_context();
125122
self.emit_branch_out_metadata(block_asm);
126123
block_asm.epilogue();
127124
}
128125

126+
pub fn emit_blx(&mut self, block_asm: &mut BlockAsm) {
127+
let inst_info = self.jit_buf.current_inst();
128+
let branch_to = *inst_info.operands()[0].as_reg_no_shift().unwrap();
129+
130+
self.emit_flush_cycles(
131+
block_asm,
132+
0,
133+
|asm, block_asm| {
134+
135+
},
136+
|asm, block_asm| {
137+
block_asm.mov(Reg::PC, branch_to);
138+
block_asm.save_context();
139+
asm.emit_branch_out_metadata(block_asm);
140+
block_asm.epilogue();
141+
},
142+
);
143+
}
144+
129145
pub fn emit_blx_label(&mut self, block_asm: &mut BlockAsm) {
130146
if CPU != ARM9 {
131147
return;

src/jit/jit_asm.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,20 +136,20 @@ fn emit_code_block_internal<const CPU: CpuType, const THUMB: bool>(guest_pc: u32
136136
assert!(asm.jit_buf.insts_cycle_counts.len() <= u16::MAX as usize, "{CPU:?} {guest_pc:x} {inst_info:?}")
137137
}
138138

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();
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();
141141
let is_unknown = inst_info.op == Op::UnkArm || inst_info.op == Op::UnkThumb;
142142

143143
asm.jit_buf.insts.push(inst_info);
144144

145145
index += if THUMB { 2 } else { 4 };
146-
if is_uncond_branch || is_unknown {
146+
if is_unreturnable_branch || is_unknown {
147147
break;
148148
}
149149
}
150150
}
151151

152-
// unsafe { BLOCK_LOG = true };
152+
unsafe { BLOCK_LOG = true };
153153

154154
let thread_regs = get_regs!(asm.emu, CPU);
155155
let mut block_asm = unsafe { (*asm.block_asm_buf.get()).new_asm(thread_regs, ptr::addr_of_mut!(asm.host_sp) as _) };
@@ -177,6 +177,7 @@ fn emit_code_block_internal<const CPU: CpuType, const THUMB: bool>(guest_pc: u32
177177
for &opcode in &opcodes {
178178
println!("0x{opcode:x},");
179179
}
180+
todo!()
180181
}
181182
let insert_entry = get_jit_mut!(asm.emu).insert_block::<CPU>(&opcodes, guest_pc);
182183
let jit_entry: extern "C" fn() = unsafe { mem::transmute(insert_entry) };

src/jit/jit_memory.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ impl JitMemory {
154154
}
155155

156156
fn insert(&mut self, opcodes: &[u32]) -> (usize, usize) {
157-
let aligned_size = utils::align_up(opcodes.len() * size_of::<u32>(), *PAGE_SIZE);
157+
let aligned_size = utils::align_up(size_of_val(opcodes), *PAGE_SIZE);
158158
let allocated_offset_addr = self.allocate_block(aligned_size);
159159

160160
utils::write_to_mem_slice(&mut self.mem, allocated_offset_addr, opcodes);

0 commit comments

Comments
 (0)