From e45b16f8dd4161c48c4ec13fd38164fb876dd8f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Mei=C3=9Fner?= Date: Fri, 29 Sep 2023 18:36:29 +0200 Subject: [PATCH] Swap REGISTER_PTR_TO_VM, REGISTER_INSTRUCTION_METER and registers[10]. --- src/jit.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/jit.rs b/src/jit.rs index 0ee363d7..b9dc648f 100644 --- a/src/jit.rs +++ b/src/jit.rs @@ -110,7 +110,7 @@ impl JitProgram { "push rbp", "mov [{host_stack_pointer}], rsp", "add QWORD PTR [{host_stack_pointer}], -8", // We will push RIP in "call r10" later - "mov rbp, {rbp}", + "mov rbx, rax", "mov rax, [r11 + 0x00]", "mov rsi, [r11 + 0x08]", "mov rdx, [r11 + 0x10]", @@ -121,17 +121,18 @@ impl JitProgram { "mov r13, [r11 + 0x38]", "mov r14, [r11 + 0x40]", "mov r15, [r11 + 0x48]", - "mov rbx, [r11 + 0x50]", + "mov rbp, [r11 + 0x50]", "mov r11, [r11 + 0x58]", "call r10", + "mov rax, rbx", "pop rbp", "pop rbx", host_stack_pointer = in(reg) &mut vm.host_stack_pointer, - rbp = in(reg) (vm as *mut _ as *mut u64).offset(*RUNTIME_ENVIRONMENT_KEY.get().unwrap() as isize), - inlateout("rdi") instruction_meter, + inlateout("rax") instruction_meter, + inlateout("rdi") (vm as *mut _ as *mut u64).offset(*RUNTIME_ENVIRONMENT_KEY.get().unwrap() as isize) => _, inlateout("r10") self.pc_section[registers[11] as usize] => _, inlateout("r11") ®isters => _, - lateout("rax") _, lateout("rsi") _, lateout("rdx") _, lateout("rcx") _, lateout("r8") _, + lateout("rsi") _, lateout("rdx") _, lateout("rcx") _, lateout("r8") _, lateout("r9") _, lateout("r12") _, lateout("r13") _, lateout("r14") _, lateout("r15") _, // lateout("rbp") _, lateout("rbx") _, ); @@ -207,13 +208,13 @@ const REGISTER_MAP: [u8; 11] = [ CALLEE_SAVED_REGISTERS[3], // R13 CALLEE_SAVED_REGISTERS[4], // R14 CALLEE_SAVED_REGISTERS[5], // R15 - CALLEE_SAVED_REGISTERS[1], // RBX + CALLEE_SAVED_REGISTERS[0], // RBP ]; -/// RDI: Program counter limit -const REGISTER_INSTRUCTION_METER: u8 = ARGUMENT_REGISTERS[0]; -/// RBP: Used together with slot_in_vm() -const REGISTER_PTR_TO_VM: u8 = CALLEE_SAVED_REGISTERS[0]; +/// RDI: Used together with slot_in_vm() +const REGISTER_PTR_TO_VM: u8 = ARGUMENT_REGISTERS[0]; +/// RBX: Program counter limit +const REGISTER_INSTRUCTION_METER: u8 = CALLEE_SAVED_REGISTERS[1]; /// R10: Other scratch register const REGISTER_OTHER_SCRATCH: u8 = CALLER_SAVED_REGISTERS[7]; /// R11: Scratch register