Rename wasm functions loading from fixed address

This commit is contained in:
Fabian 2020-12-31 19:14:31 -06:00
parent bf661f0829
commit a3dbd9ad5f
5 changed files with 32 additions and 36 deletions

View file

@ -13,12 +13,12 @@ use wasmgen::wasm_builder::{FunctionType, WasmBuilder, WasmLocal, WasmLocalI64};
pub fn gen_add_cs_offset(ctx: &mut JitContext) {
ctx.builder
.load_aligned_i32(global_pointers::get_seg_offset(regs::CS));
.load_fixed_i32(global_pointers::get_seg_offset(regs::CS));
ctx.builder.add_i32();
}
fn gen_get_eip(builder: &mut WasmBuilder) {
builder.load_aligned_i32(global_pointers::INSTRUCTION_POINTER);
builder.load_fixed_i32(global_pointers::INSTRUCTION_POINTER);
}
pub fn gen_set_previous_eip_offset_from_eip(builder: &mut WasmBuilder, n: u32) {
@ -81,7 +81,7 @@ pub fn gen_absolute_indirect_jump(ctx: &mut JitContext, new_eip: WasmLocal) {
ctx.builder.store_aligned_i32(0);
ctx.builder.get_local(&new_eip);
ctx.builder.load_aligned_i32(global_pointers::PREVIOUS_IP);
ctx.builder.load_fixed_i32(global_pointers::PREVIOUS_IP);
ctx.builder.xor_i32();
ctx.builder.const_i32(!0xFFF);
ctx.builder.and_i32();
@ -110,7 +110,7 @@ pub fn gen_absolute_indirect_jump(ctx: &mut JitContext, new_eip: WasmLocal) {
}
pub fn gen_increment_timestamp_counter(builder: &mut WasmBuilder, n: i32) {
builder.increment_mem32(global_pointers::TIMESTAMP_COUNTER, n)
builder.increment_fixed_i32(global_pointers::TIMESTAMP_COUNTER, n)
}
pub fn gen_get_reg8(ctx: &mut JitContext, r: u32) {
@ -234,32 +234,30 @@ pub fn decr_exc_asize(ctx: &mut JitContext) {
pub fn gen_get_sreg(ctx: &mut JitContext, r: u32) {
ctx.builder
.load_aligned_u16(global_pointers::get_sreg_offset(r));
.load_fixed_u16(global_pointers::get_sreg_offset(r))
}
pub fn gen_get_ss_offset(ctx: &mut JitContext) {
ctx.builder
.load_aligned_i32(global_pointers::get_seg_offset(regs::SS));
.load_fixed_i32(global_pointers::get_seg_offset(regs::SS));
}
pub fn gen_get_flags(builder: &mut WasmBuilder) {
builder.load_aligned_i32(global_pointers::FLAGS);
}
pub fn gen_get_flags(builder: &mut WasmBuilder) { builder.load_fixed_i32(global_pointers::FLAGS); }
pub fn gen_get_flags_changed(builder: &mut WasmBuilder) {
builder.load_aligned_i32(global_pointers::FLAGS_CHANGED);
builder.load_fixed_i32(global_pointers::FLAGS_CHANGED);
}
pub fn gen_get_last_result(builder: &mut WasmBuilder) {
builder.load_aligned_i32(global_pointers::LAST_RESULT);
builder.load_fixed_i32(global_pointers::LAST_RESULT);
}
pub fn gen_get_last_op_size(builder: &mut WasmBuilder) {
builder.load_aligned_i32(global_pointers::LAST_OP_SIZE);
builder.load_fixed_i32(global_pointers::LAST_OP_SIZE);
}
pub fn gen_get_last_op1(builder: &mut WasmBuilder) {
builder.load_aligned_i32(global_pointers::LAST_OP1);
builder.load_fixed_i32(global_pointers::LAST_OP1);
}
pub fn gen_get_page_fault(builder: &mut WasmBuilder) {
builder.load_u8(global_pointers::PAGE_FAULT);
builder.load_fixed_u8(global_pointers::PAGE_FAULT);
}
/// sign-extend a byte value on the stack and leave it on the stack
@ -1040,7 +1038,7 @@ pub fn bug_gen_safe_read_write_page_fault(bits: i32, addr: u32) {
pub fn gen_jmp_rel16(builder: &mut WasmBuilder, rel16: u16) {
let cs_offset_addr = global_pointers::get_seg_offset(regs::CS);
builder.load_aligned_i32(cs_offset_addr);
builder.load_fixed_i32(cs_offset_addr);
let local = builder.set_new_local();
// generate:
@ -1242,7 +1240,7 @@ pub fn gen_task_switch_test(ctx: &mut JitContext) {
let cr0_offset = global_pointers::get_creg_offset(0);
dbg_assert!(regs::CR0_EM | regs::CR0_TS <= 0xFF);
ctx.builder.load_u8(cr0_offset);
ctx.builder.load_fixed_u8(cr0_offset);
ctx.builder.const_i32((regs::CR0_EM | regs::CR0_TS) as i32);
ctx.builder.and_i32();
@ -1268,7 +1266,7 @@ pub fn gen_task_switch_test_mmx(ctx: &mut JitContext) {
let cr0_offset = global_pointers::get_creg_offset(0);
dbg_assert!(regs::CR0_EM | regs::CR0_TS <= 0xFF);
ctx.builder.load_u8(cr0_offset);
ctx.builder.load_fixed_u8(cr0_offset);
ctx.builder.const_i32((regs::CR0_EM | regs::CR0_TS) as i32);
ctx.builder.and_i32();
@ -1385,7 +1383,7 @@ pub fn gen_push32(ctx: &mut JitContext, value_local: &WasmLocal) {
pub fn gen_get_real_eip(ctx: &mut JitContext) {
gen_get_eip(ctx.builder);
ctx.builder
.load_aligned_i32(global_pointers::get_seg_offset(regs::CS));
.load_fixed_i32(global_pointers::get_seg_offset(regs::CS));
ctx.builder.sub_i32();
}
@ -1773,7 +1771,7 @@ pub fn gen_profiler_stat_increment(builder: &mut WasmBuilder, stat: profiler::st
return;
}
let addr = unsafe { profiler::stat_array.as_mut_ptr().offset(stat as isize) } as u32;
builder.increment_mem32(addr, 1)
builder.increment_fixed_i32(addr, 1)
}
pub fn gen_debug_track_jit_exit(builder: &mut WasmBuilder, address: u32) {

View file

@ -4465,7 +4465,7 @@ pub fn instr_660F7E_mem_jit(ctx: &mut JitContext, modrm_byte: u8, r: u32) {
codegen::gen_modrm_resolve(ctx, modrm_byte);
let address_local = ctx.builder.set_new_local();
ctx.builder
.load_aligned_i32(global_pointers::get_reg_xmm_low_offset(r));
.load_fixed_i32(global_pointers::get_reg_xmm_low_offset(r));
let value_local = ctx.builder.set_new_local();
codegen::gen_safe_write32(ctx, &address_local, &value_local);
ctx.builder.free_local(address_local);
@ -4473,7 +4473,7 @@ pub fn instr_660F7E_mem_jit(ctx: &mut JitContext, modrm_byte: u8, r: u32) {
}
pub fn instr_660F7E_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {
ctx.builder
.load_aligned_i32(global_pointers::get_reg_xmm_low_offset(r2));
.load_fixed_i32(global_pointers::get_reg_xmm_low_offset(r2));
codegen::gen_set_reg32(ctx, r1);
}

View file

@ -347,6 +347,6 @@ pub fn jit_add_seg_offset(ctx: &mut JitContext, default_segment: u32) {
}
ctx.builder
.load_aligned_i32(global_pointers::get_seg_offset(seg));
.load_fixed_i32(global_pointers::get_seg_offset(seg));
ctx.builder.add_i32();
}

View file

@ -134,7 +134,7 @@ pub fn gen_opstats(builder: &mut WasmBuilder, opcode: u32) {
for prefix in instruction.prefixes {
let index = (prefix as u32) << 4;
builder.increment_mem32(global_pointers::OPSTATS_BUFFER + 4 * index, 1);
builder.increment_fixed_i32(global_pointers::OPSTATS_BUFFER + 4 * index, 1);
}
let index = (instruction.is_0f as u32) << 12
@ -142,7 +142,7 @@ pub fn gen_opstats(builder: &mut WasmBuilder, opcode: u32) {
| (instruction.is_mem as u32) << 3
| instruction.fixed_g as u32;
builder.increment_mem32(global_pointers::OPSTATS_BUFFER + 4 * index, 1);
builder.increment_fixed_i32(global_pointers::OPSTATS_BUFFER + 4 * index, 1);
}
pub fn record_opstat_compiled(opcode: u32) {
@ -216,7 +216,7 @@ pub fn gen_opstat_unguarded_register(builder: &mut WasmBuilder, opcode: u32) {
for prefix in instruction.prefixes {
let index = (prefix as u32) << 4;
builder.increment_mem32(
builder.increment_fixed_i32(
global_pointers::OPSTATS_UNGUARDED_REGISTER_BUFFER + 4 * index,
1,
);
@ -227,7 +227,7 @@ pub fn gen_opstat_unguarded_register(builder: &mut WasmBuilder, opcode: u32) {
| (instruction.is_mem as u32) << 3
| instruction.fixed_g as u32;
builder.increment_mem32(
builder.increment_fixed_i32(
global_pointers::OPSTATS_UNGUARDED_REGISTER_BUFFER + 4 * index,
1,
);

View file

@ -570,7 +570,11 @@ impl WasmBuilder {
write_leb_i64(&mut self.instruction_body, v);
}
pub fn load_aligned_u16(&mut self, addr: u32) {
pub fn load_fixed_u8(&mut self, addr: u32) {
self.const_i32(addr as i32);
self.load_u8_from_stack(0);
}
pub fn load_fixed_u16(&mut self, addr: u32) {
// doesn't cause a failure in the generated code, but it will be much slower
dbg_assert!((addr & 1) == 0);
@ -580,8 +584,7 @@ impl WasmBuilder {
self.instruction_body.push(op::MEM_ALIGN16);
self.instruction_body.push(0); // immediate offset
}
pub fn load_aligned_i32(&mut self, addr: u32) {
pub fn load_fixed_i32(&mut self, addr: u32) {
// doesn't cause a failure in the generated code, but it will be much slower
dbg_assert!((addr & 3) == 0);
@ -595,11 +598,6 @@ impl WasmBuilder {
write_leb_u32(&mut self.instruction_body, byte_offset);
}
pub fn load_u8(&mut self, addr: u32) {
self.const_i32(addr as i32);
self.load_u8_from_stack(0);
}
pub fn load_unaligned_i64_from_stack(&mut self, byte_offset: u32) {
self.instruction_body.push(op::OP_I64LOAD);
self.instruction_body.push(op::MEM_NO_ALIGN);
@ -678,9 +676,9 @@ impl WasmBuilder {
write_leb_u32(&mut self.instruction_body, byte_offset);
}
pub fn increment_mem32(&mut self, byte_offset: u32, n: i32) {
pub fn increment_fixed_i32(&mut self, byte_offset: u32, n: i32) {
self.const_i32(byte_offset as i32);
self.load_aligned_i32(byte_offset);
self.load_fixed_i32(byte_offset);
self.const_i32(n);
self.add_i32();
self.store_aligned_i32(0);