Remove some unnecessary no_mangle

This commit is contained in:
Fabian 2020-12-31 19:14:34 -06:00
parent 416b4b4b82
commit b27285cb7b
5 changed files with 1 additions and 152 deletions

View file

@ -5,7 +5,6 @@ use cpu::misc_instr::{getaf, getcf, getzf};
pub fn int_log2(x: i32) -> i32 { 31 - x.leading_zeros() as i32 }
#[no_mangle]
pub unsafe fn add(dest_operand: i32, source_operand: i32, op_size: i32) -> i32 {
let res = dest_operand + source_operand;
*last_op1 = dest_operand;
@ -14,7 +13,6 @@ pub unsafe fn add(dest_operand: i32, source_operand: i32, op_size: i32) -> i32 {
*flags_changed = FLAGS_ALL;
return res;
}
#[no_mangle]
pub unsafe fn adc(dest_operand: i32, source_operand: i32, op_size: i32) -> i32 {
let cf = getcf() as i32;
let res = dest_operand + source_operand + cf;
@ -29,7 +27,6 @@ pub unsafe fn adc(dest_operand: i32, source_operand: i32, op_size: i32) -> i32 {
| ((source_operand ^ res) & (dest_operand ^ res)) >> op_size << 11 & FLAG_OVERFLOW;
return res;
}
#[no_mangle]
pub unsafe fn sub(dest_operand: i32, source_operand: i32, op_size: i32) -> i32 {
let res = dest_operand - source_operand;
*last_op1 = dest_operand;
@ -38,7 +35,6 @@ pub unsafe fn sub(dest_operand: i32, source_operand: i32, op_size: i32) -> i32 {
*flags_changed = FLAGS_ALL | FLAG_SUB;
return res;
}
#[no_mangle]
pub unsafe fn sbb(dest_operand: i32, source_operand: i32, op_size: i32) -> i32 {
let cf = getcf() as i32;
let res = dest_operand - source_operand - cf;
@ -57,13 +53,11 @@ pub unsafe fn sbb(dest_operand: i32, source_operand: i32, op_size: i32) -> i32 {
pub unsafe fn add8(x: i32, y: i32) -> i32 { return add(x, y, OPSIZE_8); }
#[no_mangle]
pub unsafe fn add16(x: i32, y: i32) -> i32 { return add(x, y, OPSIZE_16); }
#[no_mangle]
pub unsafe fn add32(x: i32, y: i32) -> i32 { return add(x, y, OPSIZE_32); }
#[no_mangle]
pub unsafe fn sub8(x: i32, y: i32) -> i32 { return sub(x, y, OPSIZE_8); }
#[no_mangle]
pub unsafe fn sub16(x: i32, y: i32) -> i32 { return sub(x, y, OPSIZE_16); }
#[no_mangle]
pub unsafe fn sub32(x: i32, y: i32) -> i32 { return sub(x, y, OPSIZE_32); }
#[no_mangle]
pub unsafe fn adc8(x: i32, y: i32) -> i32 { return adc(x, y, OPSIZE_8); }
@ -77,13 +71,9 @@ pub unsafe fn sbb8(x: i32, y: i32) -> i32 { return sbb(x, y, OPSIZE_8); }
pub unsafe fn sbb16(x: i32, y: i32) -> i32 { return sbb(x, y, OPSIZE_16); }
#[no_mangle]
pub unsafe fn sbb32(x: i32, y: i32) -> i32 { return sbb(x, y, OPSIZE_32); }
#[no_mangle]
pub unsafe fn cmp8(x: i32, y: i32) { sub(x, y, OPSIZE_8); }
#[no_mangle]
pub unsafe fn cmp16(x: i32, y: i32) { sub(x, y, OPSIZE_16); }
#[no_mangle]
pub unsafe fn cmp32(x: i32, y: i32) { sub(x, y, OPSIZE_32); }
#[no_mangle]
pub unsafe fn inc(dest_operand: i32, op_size: i32) -> i32 {
*flags = *flags & !1 | getcf() as i32;
let res = dest_operand + 1;
@ -93,7 +83,6 @@ pub unsafe fn inc(dest_operand: i32, op_size: i32) -> i32 {
*flags_changed = FLAGS_ALL & !1;
return res;
}
#[no_mangle]
pub unsafe fn dec(dest_operand: i32, op_size: i32) -> i32 {
*flags = *flags & !1 | getcf() as i32;
let res = dest_operand - 1;
@ -105,31 +94,18 @@ pub unsafe fn dec(dest_operand: i32, op_size: i32) -> i32 {
}
#[no_mangle]
pub unsafe fn inc8(x: i32) -> i32 { return inc(x, OPSIZE_8); }
#[no_mangle]
pub unsafe fn inc16(x: i32) -> i32 { return inc(x, OPSIZE_16); }
#[no_mangle]
pub unsafe fn inc32(x: i32) -> i32 { return inc(x, OPSIZE_32); }
#[no_mangle]
pub unsafe fn dec8(x: i32) -> i32 { return dec(x, OPSIZE_8); }
#[no_mangle]
pub unsafe fn dec16(x: i32) -> i32 { return dec(x, OPSIZE_16); }
#[no_mangle]
pub unsafe fn dec32(x: i32) -> i32 { return dec(x, OPSIZE_32); }
#[no_mangle]
pub unsafe fn not8(x: i32) -> i32 { return !x; }
#[no_mangle]
pub unsafe fn not16(x: i32) -> i32 { return !x; }
#[no_mangle]
pub unsafe fn not32(x: i32) -> i32 { return !x; }
#[no_mangle]
pub unsafe fn neg(dest_operand: i32, op_size: i32) -> i32 { sub(0, dest_operand, op_size) }
#[no_mangle]
pub unsafe fn neg8(x: i32) -> i32 { return neg(x, OPSIZE_8); }
#[no_mangle]
pub unsafe fn neg16(x: i32) -> i32 { return neg(x, OPSIZE_16); }
#[no_mangle]
pub unsafe fn neg32(x: i32) -> i32 { return neg(x, OPSIZE_32); }
#[no_mangle]
@ -225,7 +201,6 @@ pub unsafe fn mul32(source_operand: i32) {
}
*flags_changed = FLAGS_ALL & !1 & !FLAG_OVERFLOW;
}
#[no_mangle]
pub unsafe fn imul32(source_operand: i32) {
let dest_operand = read_reg32(EAX);
let result = dest_operand as i64 * source_operand as i64;
@ -243,7 +218,6 @@ pub unsafe fn imul32(source_operand: i32) {
}
*flags_changed = FLAGS_ALL & !1 & !FLAG_OVERFLOW;
}
#[no_mangle]
pub unsafe fn imul_reg32(operand1: i32, operand2: i32) -> i32 {
let result = operand1 as i64 * operand2 as i64;
let result_low = result as i32;
@ -272,7 +246,6 @@ pub unsafe fn xadd16(source_operand: i32, reg: i32) -> i32 {
write_reg16(reg, source_operand);
return add(source_operand, tmp, OPSIZE_16);
}
#[no_mangle]
pub unsafe fn xadd32(source_operand: i32, reg: i32) -> i32 {
let tmp = read_reg32(reg);
write_reg32(reg, source_operand);
@ -301,7 +274,6 @@ pub unsafe fn cmpxchg16(data: i32, r: i32) -> i32 {
data
}
}
#[no_mangle]
pub unsafe fn cmpxchg32(data: i32, r: i32) -> i32 {
cmp32(read_reg32(EAX), data);
if getzf() {
@ -405,7 +377,6 @@ pub unsafe fn bcd_aas() {
write_reg8(AL, read_reg8(AL) & 15);
*flags_changed &= !FLAG_ADJUST & !1;
}
#[no_mangle]
pub unsafe fn and(dest_operand: i32, source_operand: i32, op_size: i32) -> i32 {
let result = dest_operand & source_operand;
*last_result = result;
@ -414,7 +385,6 @@ pub unsafe fn and(dest_operand: i32, source_operand: i32, op_size: i32) -> i32 {
*flags_changed = FLAGS_ALL & !1 & !FLAG_OVERFLOW & !FLAG_ADJUST;
return result;
}
#[no_mangle]
pub unsafe fn or(dest_operand: i32, source_operand: i32, op_size: i32) -> i32 {
let result = dest_operand | source_operand;
*last_result = result;
@ -423,7 +393,6 @@ pub unsafe fn or(dest_operand: i32, source_operand: i32, op_size: i32) -> i32 {
*flags_changed = FLAGS_ALL & !1 & !FLAG_OVERFLOW & !FLAG_ADJUST;
return result;
}
#[no_mangle]
pub unsafe fn xor(dest_operand: i32, source_operand: i32, op_size: i32) -> i32 {
let result = dest_operand ^ source_operand;
*last_result = result;
@ -436,25 +405,19 @@ pub unsafe fn xor(dest_operand: i32, source_operand: i32, op_size: i32) -> i32 {
pub unsafe fn and8(x: i32, y: i32) -> i32 { return and(x, y, OPSIZE_8); }
#[no_mangle]
pub unsafe fn and16(x: i32, y: i32) -> i32 { return and(x, y, OPSIZE_16); }
#[no_mangle]
pub unsafe fn and32(x: i32, y: i32) -> i32 { return and(x, y, OPSIZE_32); }
#[no_mangle]
pub unsafe fn test8(x: i32, y: i32) { and(x, y, OPSIZE_8); }
#[no_mangle]
pub unsafe fn test16(x: i32, y: i32) { and(x, y, OPSIZE_16); }
#[no_mangle]
pub unsafe fn test32(x: i32, y: i32) { and(x, y, OPSIZE_32); }
#[no_mangle]
pub unsafe fn or8(x: i32, y: i32) -> i32 { return or(x, y, OPSIZE_8); }
#[no_mangle]
pub unsafe fn or16(x: i32, y: i32) -> i32 { return or(x, y, OPSIZE_16); }
#[no_mangle]
pub unsafe fn or32(x: i32, y: i32) -> i32 { return or(x, y, OPSIZE_32); }
#[no_mangle]
pub unsafe fn xor8(x: i32, y: i32) -> i32 { return xor(x, y, OPSIZE_8); }
#[no_mangle]
pub unsafe fn xor16(x: i32, y: i32) -> i32 { return xor(x, y, OPSIZE_16); }
#[no_mangle]
pub unsafe fn xor32(x: i32, y: i32) -> i32 { return xor(x, y, OPSIZE_32); }
#[no_mangle]
@ -819,7 +782,6 @@ pub unsafe fn shl16(dest_operand: i32, count: i32) -> i32 {
return result;
};
}
#[no_mangle]
pub unsafe fn shl32(dest_operand: i32, count: i32) -> i32 {
dbg_assert!(count >= 0 && count < 32);
if count == 0 {
@ -869,7 +831,6 @@ pub unsafe fn shr16(dest_operand: i32, count: i32) -> i32 {
return result;
};
}
#[no_mangle]
pub unsafe fn shr32(dest_operand: i32, count: i32) -> i32 {
dbg_assert!(count >= 0 && count < 32);
if count == 0 {
@ -931,7 +892,6 @@ pub unsafe fn sar16(dest_operand: i32, count: i32) -> i32 {
return result;
};
}
#[no_mangle]
pub unsafe fn sar32(dest_operand: i32, count: i32) -> i32 {
dbg_assert!(count >= 0 && count < 32);
if count == 0 {
@ -1031,38 +991,32 @@ pub unsafe fn shld32(dest_operand: i32, source_operand: i32, count: i32) -> i32
};
}
#[no_mangle]
pub unsafe fn bt_reg(bit_base: i32, bit_offset: i32) {
*flags = *flags & !1 | bit_base >> bit_offset & 1;
*flags_changed &= !1;
}
#[no_mangle]
pub unsafe fn btc_reg(bit_base: i32, bit_offset: i32) -> i32 {
*flags = *flags & !1 | bit_base >> bit_offset & 1;
*flags_changed &= !1;
return bit_base ^ 1 << bit_offset;
}
#[no_mangle]
pub unsafe fn bts_reg(bit_base: i32, bit_offset: i32) -> i32 {
*flags = *flags & !1 | bit_base >> bit_offset & 1;
*flags_changed &= !1;
return bit_base | 1 << bit_offset;
}
#[no_mangle]
pub unsafe fn btr_reg(bit_base: i32, bit_offset: i32) -> i32 {
*flags = *flags & !1 | bit_base >> bit_offset & 1;
*flags_changed &= !1;
return bit_base & !(1 << bit_offset);
}
#[no_mangle]
pub unsafe fn bt_mem(virt_addr: i32, mut bit_offset: i32) {
let bit_base = return_on_pagefault!(safe_read8(virt_addr + (bit_offset >> 3)));
bit_offset &= 7;
*flags = *flags & !1 | bit_base >> bit_offset & 1;
*flags_changed &= !1;
}
#[no_mangle]
pub unsafe fn btc_mem(virt_addr: i32, mut bit_offset: i32) {
let phys_addr = return_on_pagefault!(translate_address_write(virt_addr + (bit_offset >> 3)));
let bit_base = read8(phys_addr);
@ -1071,7 +1025,6 @@ pub unsafe fn btc_mem(virt_addr: i32, mut bit_offset: i32) {
*flags_changed &= !1;
write8(phys_addr, bit_base ^ 1 << bit_offset);
}
#[no_mangle]
pub unsafe fn btr_mem(virt_addr: i32, mut bit_offset: i32) {
let phys_addr = return_on_pagefault!(translate_address_write(virt_addr + (bit_offset >> 3)));
let bit_base = read8(phys_addr);
@ -1080,7 +1033,6 @@ pub unsafe fn btr_mem(virt_addr: i32, mut bit_offset: i32) {
*flags_changed &= !1;
write8(phys_addr, bit_base & !(1 << bit_offset));
}
#[no_mangle]
pub unsafe fn bts_mem(virt_addr: i32, mut bit_offset: i32) {
let phys_addr = return_on_pagefault!(translate_address_write(virt_addr + (bit_offset >> 3)));
let bit_base = read8(phys_addr);
@ -1168,7 +1120,6 @@ pub unsafe fn popcnt(v: i32) -> i32 {
};
}
#[no_mangle]
pub unsafe fn saturate_sw_to_ub(v: u16) -> u8 {
let mut ret = v;
if ret >= 32768 {
@ -1179,7 +1130,6 @@ pub unsafe fn saturate_sw_to_ub(v: u16) -> u8 {
}
return ret as u8;
}
#[no_mangle]
pub unsafe fn saturate_sw_to_sb(v: i32) -> u8 {
dbg_assert!(v as u32 & 0xFFFF_0000 == 0);
let mut ret: i32 = v;
@ -1195,7 +1145,6 @@ pub unsafe fn saturate_sw_to_sb(v: i32) -> u8 {
dbg_assert!(ret as u32 & 0xFFFF_FF00 == 0);
return ret as u8;
}
#[no_mangle]
pub unsafe fn saturate_sd_to_sw(v: u32) -> u16 {
let mut ret: u32 = v;
if ret > 4294934528 {
@ -1210,7 +1159,6 @@ pub unsafe fn saturate_sd_to_sw(v: u32) -> u16 {
dbg_assert!(ret & 0xFFFF_0000 == 0);
return ret as u16;
}
#[no_mangle]
pub unsafe fn saturate_sd_to_sb(v: u32) -> i8 {
let mut ret: u32 = v;
if ret > 0xFFFFFF80 {
@ -1225,7 +1173,6 @@ pub unsafe fn saturate_sd_to_sb(v: u32) -> i8 {
dbg_assert!(ret & 0xFFFF_FF00 == 0);
return ret as i8;
}
#[no_mangle]
pub unsafe fn saturate_sd_to_ub(v: i32) -> i32 {
let mut ret: i32 = v;
if ret < 0 {
@ -1234,7 +1181,6 @@ pub unsafe fn saturate_sd_to_ub(v: i32) -> i32 {
dbg_assert!(ret as u32 & 0xFFFF_FF00 == 0);
return ret;
}
#[no_mangle]
pub unsafe fn saturate_ud_to_ub(v: u32) -> u8 {
let mut ret: u32 = v;
if ret > 255 {
@ -1243,7 +1189,6 @@ pub unsafe fn saturate_ud_to_ub(v: u32) -> u8 {
dbg_assert!(ret & 0xFFFF_FF00 == 0);
return ret as u8;
}
#[no_mangle]
pub unsafe fn saturate_uw(v: u32) -> u16 {
let mut ret: u32 = v;
if ret > 0x7FFFFFFF {

View file

@ -2580,6 +2580,7 @@ pub unsafe fn instr_DC_6_reg(r: i32) { fpu_fdiv(r, fpu_get_sti(r)); }
pub unsafe fn instr_DC_7_reg(r: i32) { fpu_fdivr(r, fpu_get_sti(r)); }
pub unsafe fn instr16_DD_0_mem(addr: i32) { fpu_fldm64(addr); }
#[no_mangle]
pub unsafe fn instr16_DD_1_mem(_addr: i32) {
dbg_log!("fisttp");
fpu_unimpl();

View file

@ -75,7 +75,6 @@ pub fn read32_no_mmap_check(addr: u32) -> i32 {
unsafe { *(mem8.offset(addr as isize) as *mut i32) }
}
#[no_mangle]
pub unsafe fn read64s(addr: u32) -> i64 {
if in_mapped_range(addr) {
return mmap_read32(addr) as i64 | (mmap_read32(addr.wrapping_add(4 as u32)) as i64) << 32;
@ -85,7 +84,6 @@ pub unsafe fn read64s(addr: u32) -> i64 {
};
}
#[no_mangle]
pub unsafe fn read_aligned32(addr: u32) -> i32 {
dbg_assert!(addr < 0x40000000 as u32);
if in_mapped_range(addr << 2) {
@ -96,7 +94,6 @@ pub unsafe fn read_aligned32(addr: u32) -> i32 {
};
}
#[no_mangle]
pub unsafe fn read128(addr: u32) -> reg128 {
let mut value: reg128 = reg128 {
i8_0: [0 as i8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
@ -162,7 +159,6 @@ pub unsafe fn write_aligned32_no_mmap_or_dirty_check(addr: u32, value: i32) {
*(mem8 as *mut i32).offset(addr as isize) = value
}
#[no_mangle]
pub unsafe fn write_aligned32(addr: u32, value: i32) {
dbg_assert!(addr < 0x40000000 as u32);
let phys_addr = addr << 2;
@ -175,36 +171,10 @@ pub unsafe fn write_aligned32(addr: u32, value: i32) {
};
}
#[no_mangle]
pub unsafe fn write64(addr: u32, value: u64) {
if in_mapped_range(addr) {
mmap_write64(addr, value as i32, (value >> 32) as i32);
}
else {
::jit::jit_dirty_cache_small(addr, addr.wrapping_add(8 as u32));
write64_no_mmap_or_dirty_check(addr, value);
};
}
pub unsafe fn write64_no_mmap_or_dirty_check(addr: u32, value: u64) {
*(mem8.offset(addr as isize) as *mut u64) = value
}
#[no_mangle]
pub unsafe fn write128(addr: u32, value: reg128) {
if in_mapped_range(addr) {
mmap_write128(
addr,
value.i32_0[0],
value.i32_0[1],
value.i32_0[2],
value.i32_0[3],
);
}
else {
::jit::jit_dirty_cache_small(addr, addr.wrapping_add(16 as u32));
write128_no_mmap_or_dirty_check(addr, value);
};
}
pub unsafe fn write128_no_mmap_or_dirty_check(addr: u32, value: reg128) {
*(mem8.offset(addr as isize) as *mut reg128) = value
}

View file

@ -91,43 +91,32 @@ pub unsafe fn test_nbe() -> bool { return !test_be(); }
pub unsafe fn test_nl() -> bool { return !test_l(); }
pub unsafe fn test_nle() -> bool { return !test_le(); }
#[no_mangle]
pub unsafe fn jmp_rel16(rel16: i32) {
let cs_offset = get_seg_cs();
// limit ip to 16 bit
*instruction_pointer = cs_offset + (*instruction_pointer - cs_offset + rel16 & 0xFFFF);
}
#[no_mangle]
pub unsafe fn jmpcc16(condition: bool, imm16: i32) {
if condition {
jmp_rel16(imm16);
};
}
#[no_mangle]
pub unsafe fn jmpcc32(condition: bool, imm32: i32) {
if condition {
*instruction_pointer += imm32
};
}
#[no_mangle]
pub unsafe fn loope16(imm8s: i32) { jmpcc16(0 != decr_ecx_asize(is_asize_32()) && getzf(), imm8s); }
#[no_mangle]
pub unsafe fn loopne16(imm8s: i32) {
jmpcc16(0 != decr_ecx_asize(is_asize_32()) && !getzf(), imm8s);
}
#[no_mangle]
pub unsafe fn loop16(imm8s: i32) { jmpcc16(0 != decr_ecx_asize(is_asize_32()), imm8s); }
#[no_mangle]
pub unsafe fn jcxz16(imm8s: i32) { jmpcc16(get_reg_asize(ECX) == 0, imm8s); }
#[no_mangle]
pub unsafe fn loope32(imm8s: i32) { jmpcc32(0 != decr_ecx_asize(is_asize_32()) && getzf(), imm8s); }
#[no_mangle]
pub unsafe fn loopne32(imm8s: i32) {
jmpcc32(0 != decr_ecx_asize(is_asize_32()) && !getzf(), imm8s);
}
#[no_mangle]
pub unsafe fn loop32(imm8s: i32) { jmpcc32(0 != decr_ecx_asize(is_asize_32()), imm8s); }
#[no_mangle]
pub unsafe fn jcxz32(imm8s: i32) { jmpcc32(get_reg_asize(ECX) == 0, imm8s); }
pub unsafe fn cmovcc16(condition: bool, value: i32, r: i32) {
@ -160,14 +149,12 @@ pub unsafe fn adjust_stack_reg(adjustment: i32) {
};
}
#[no_mangle]
pub unsafe fn push16_ss16(imm16: i32) -> OrPageFault<()> {
let sp = get_seg_ss() + (read_reg16(SP) - 2 & 0xFFFF);
safe_write16(sp, imm16)?;
write_reg16(SP, read_reg16(SP) - 2);
Ok(())
}
#[no_mangle]
pub unsafe fn push16_ss32(imm16: i32) -> OrPageFault<()> {
let sp = get_seg_ss() + read_reg32(ESP) - 2;
safe_write16(sp, imm16)?;
@ -175,24 +162,19 @@ pub unsafe fn push16_ss32(imm16: i32) -> OrPageFault<()> {
Ok(())
}
#[no_mangle]
pub unsafe fn push16_ss16_mem(addr: i32) -> OrPageFault<()> { push16_ss16(safe_read16(addr)?) }
#[no_mangle]
pub unsafe fn push16_ss32_mem(addr: i32) -> OrPageFault<()> { push16_ss32(safe_read16(addr)?) }
#[no_mangle]
pub unsafe fn push16(imm16: i32) -> OrPageFault<()> {
if *stack_size_32 { push16_ss32(imm16) } else { push16_ss16(imm16) }
}
#[no_mangle]
pub unsafe fn push32_ss16(imm32: i32) -> OrPageFault<()> {
let new_sp = read_reg16(SP) - 4 & 0xFFFF;
safe_write32(get_seg_ss() + new_sp, imm32)?;
write_reg16(SP, new_sp);
Ok(())
}
#[no_mangle]
pub unsafe fn push32_ss32(imm32: i32) -> OrPageFault<()> {
let new_esp = read_reg32(ESP) - 4;
safe_write32(get_seg_ss() + new_esp, imm32)?;
@ -200,52 +182,42 @@ pub unsafe fn push32_ss32(imm32: i32) -> OrPageFault<()> {
Ok(())
}
#[no_mangle]
pub unsafe fn push32_ss16_mem(addr: i32) -> OrPageFault<()> { push32_ss16(safe_read32s(addr)?) }
#[no_mangle]
pub unsafe fn push32_ss32_mem(addr: i32) -> OrPageFault<()> { push32_ss32(safe_read32s(addr)?) }
#[no_mangle]
pub unsafe fn push32(imm32: i32) -> OrPageFault<()> {
if *stack_size_32 { push32_ss32(imm32) } else { push32_ss16(imm32) }
}
#[no_mangle]
pub unsafe fn pop16() -> OrPageFault<i32> {
if *stack_size_32 { pop16_ss32() } else { pop16_ss16() }
}
#[no_mangle]
pub unsafe fn pop16_ss16() -> OrPageFault<i32> {
let sp = get_seg_ss() + read_reg16(SP);
let result = safe_read16(sp)?;
write_reg16(SP, read_reg16(SP) + 2);
Ok(result)
}
#[no_mangle]
pub unsafe fn pop16_ss32() -> OrPageFault<i32> {
let esp = get_seg_ss() + read_reg32(ESP);
let result = safe_read16(esp)?;
write_reg32(ESP, read_reg32(ESP) + 2);
Ok(result)
}
#[no_mangle]
pub unsafe fn pop32s() -> OrPageFault<i32> {
if *stack_size_32 { pop32s_ss32() } else { pop32s_ss16() }
}
#[no_mangle]
pub unsafe fn pop32s_ss16() -> OrPageFault<i32> {
let sp = read_reg16(SP);
let result = safe_read32s(get_seg_ss() + sp)?;
write_reg16(SP, sp + 4);
Ok(result)
}
#[no_mangle]
pub unsafe fn pop32s_ss32() -> OrPageFault<i32> {
let esp = read_reg32(ESP);
let result = safe_read32s(get_seg_ss() + esp)?;
write_reg32(ESP, read_reg32(ESP) + 4);
Ok(result)
}
#[no_mangle]
pub unsafe fn pusha16() {
let temp = read_reg16(SP);
// make sure we don't get a pagefault after having
@ -260,7 +232,6 @@ pub unsafe fn pusha16() {
push16(read_reg16(SI)).unwrap();
push16(read_reg16(DI)).unwrap();
}
#[no_mangle]
pub unsafe fn pusha32() {
let temp = read_reg32(ESP);
return_on_pagefault!(writable_or_pagefault(get_stack_pointer(-32), 32));
@ -356,9 +327,7 @@ pub unsafe fn enter32(size: i32, mut nesting_level: i32) {
adjust_stack_reg(-size - 4);
}
#[no_mangle]
pub unsafe fn setcc_reg(condition: bool, r: i32) { write_reg8(r, condition as i32); }
#[no_mangle]
pub unsafe fn setcc_mem(condition: bool, addr: i32) {
return_on_pagefault!(safe_write8(addr, condition as i32));
}
@ -426,38 +395,32 @@ pub unsafe fn fxrstor(addr: i32) {
}
}
#[no_mangle]
pub unsafe fn xchg8(data: i32, r8: i32) -> i32 {
let tmp = read_reg8(r8);
write_reg8(r8, data);
return tmp;
}
#[no_mangle]
pub unsafe fn xchg16(data: i32, r16: i32) -> i32 {
let tmp = read_reg16(r16);
write_reg16(r16, data);
return tmp;
}
#[no_mangle]
pub unsafe fn xchg16r(r16: i32) {
let tmp = read_reg16(AX);
write_reg16(AX, read_reg16(r16));
write_reg16(r16, tmp);
}
#[no_mangle]
pub unsafe fn xchg32(data: i32, r32: i32) -> i32 {
let tmp = read_reg32(r32);
write_reg32(r32, data);
return tmp;
}
#[no_mangle]
pub unsafe fn xchg32r(r32: i32) {
let tmp = read_reg32(EAX);
write_reg32(EAX, read_reg32(r32));
write_reg32(r32, tmp);
}
#[no_mangle]
pub unsafe fn bswap(r: i32) { write_reg32(r, read_reg32(r).swap_bytes()) }
pub unsafe fn lar(selector: i32, original: i32) -> i32 {

View file

@ -1,37 +1,31 @@
use cpu::cpu::*;
use cpu::global_pointers::mxcsr;
#[no_mangle]
pub unsafe fn mov_r_m64(addr: i32, r: i32) {
// mov* m64, mm
let data = read_mmx64s(r);
return_on_pagefault!(safe_write64(addr, data));
transition_fpu_to_mmx();
}
#[no_mangle]
pub unsafe fn movl_r128_m64(addr: i32, r: i32) {
// mov* m64, xmm
let data = read_xmm64s(r);
return_on_pagefault!(safe_write64(addr, data));
}
#[no_mangle]
pub unsafe fn mov_r_r128(r1: i32, r2: i32) {
// mov* xmm, xmm
let data = read_xmm128s(r2);
write_xmm_reg128(r1, data);
}
#[no_mangle]
pub unsafe fn mov_r_m128(addr: i32, r: i32) {
// mov* m128, xmm
let data = read_xmm128s(r);
return_on_pagefault!(safe_write128(addr, data));
}
#[no_mangle]
pub unsafe fn mov_rm_r128(source: reg128, r: i32) {
// mov* xmm, xmm/m128
write_xmm_reg128(r, source);
}
#[no_mangle]
pub unsafe fn movh_m64_r128(addr: i32, r: i32) {
// movhp* xmm, m64
let data = return_on_pagefault!(safe_read64s(addr));
@ -44,14 +38,12 @@ pub unsafe fn movh_m64_r128(addr: i32, r: i32) {
(data >> 32) as i32,
);
}
#[no_mangle]
pub unsafe fn movh_r128_m64(addr: i32, r: i32) {
// movhp* m64, xmm
let data = read_xmm128s(r);
return_on_pagefault!(safe_write64(addr, data.u64_0[1]));
}
#[no_mangle]
pub unsafe fn pand_r128(source: reg128, r: i32) {
// pand xmm, xmm/m128
// XXX: Aligned access or #gp
@ -61,7 +53,6 @@ pub unsafe fn pand_r128(source: reg128, r: i32) {
result.u64_0[1] = source.u64_0[1] & destination.u64_0[1];
write_xmm_reg128(r, result);
}
#[no_mangle]
pub unsafe fn pandn_r128(source: reg128, r: i32) {
// pandn xmm, xmm/m128
// XXX: Aligned access or #gp
@ -71,7 +62,6 @@ pub unsafe fn pandn_r128(source: reg128, r: i32) {
result.u64_0[1] = source.u64_0[1] & !destination.u64_0[1];
write_xmm_reg128(r, result);
}
#[no_mangle]
pub unsafe fn pxor_r128(source: reg128, r: i32) {
// pxor xmm, xmm/m128
// XXX: Aligned access or #gp
@ -81,7 +71,6 @@ pub unsafe fn pxor_r128(source: reg128, r: i32) {
result.u64_0[1] = source.u64_0[1] ^ destination.u64_0[1];
write_xmm_reg128(r, result);
}
#[no_mangle]
pub unsafe fn por_r128(source: reg128, r: i32) {
// por xmm, xmm/m128
// XXX: Aligned access or #gp
@ -92,7 +81,6 @@ pub unsafe fn por_r128(source: reg128, r: i32) {
write_xmm_reg128(r, result);
}
#[no_mangle]
pub unsafe fn psrlw_r64(r: i32, shift: u64) {
// psrlw mm, {shift}
let destination: [u16; 4] = std::mem::transmute(read_mmx64s(r));
@ -104,7 +92,6 @@ pub unsafe fn psrlw_r64(r: i32, shift: u64) {
write_mmx_reg64(r, std::mem::transmute(result));
transition_fpu_to_mmx();
}
#[no_mangle]
pub unsafe fn psraw_r64(r: i32, shift: u64) {
// psraw mm, {shift}
let destination: [i16; 4] = std::mem::transmute(read_mmx64s(r));
@ -116,7 +103,6 @@ pub unsafe fn psraw_r64(r: i32, shift: u64) {
write_mmx_reg64(r, std::mem::transmute(result));
transition_fpu_to_mmx();
}
#[no_mangle]
pub unsafe fn psllw_r64(r: i32, shift: u64) {
// psllw mm, {shift}
let destination: [i16; 4] = std::mem::transmute(read_mmx64s(r));
@ -129,7 +115,6 @@ pub unsafe fn psllw_r64(r: i32, shift: u64) {
write_mmx_reg64(r, std::mem::transmute(result));
transition_fpu_to_mmx();
}
#[no_mangle]
pub unsafe fn psrld_r64(r: i32, shift: u64) {
// psrld mm, {shift}
let destination: [u32; 2] = std::mem::transmute(read_mmx64s(r));
@ -142,7 +127,6 @@ pub unsafe fn psrld_r64(r: i32, shift: u64) {
write_mmx_reg64(r, std::mem::transmute(result));
transition_fpu_to_mmx();
}
#[no_mangle]
pub unsafe fn psrad_r64(r: i32, shift: u64) {
// psrad mm, {shift}
let destination: [i32; 2] = std::mem::transmute(read_mmx64s(r));
@ -154,7 +138,6 @@ pub unsafe fn psrad_r64(r: i32, shift: u64) {
write_mmx_reg64(r, std::mem::transmute(result));
transition_fpu_to_mmx();
}
#[no_mangle]
pub unsafe fn pslld_r64(r: i32, shift: u64) {
// pslld mm, {shift}
let destination: [i32; 2] = std::mem::transmute(read_mmx64s(r));
@ -167,7 +150,6 @@ pub unsafe fn pslld_r64(r: i32, shift: u64) {
write_mmx_reg64(r, std::mem::transmute(result));
transition_fpu_to_mmx();
}
#[no_mangle]
pub unsafe fn psrlq_r64(r: i32, shift: u64) {
// psrlq mm, {shift}
let destination = read_mmx64s(r);
@ -178,7 +160,6 @@ pub unsafe fn psrlq_r64(r: i32, shift: u64) {
write_mmx_reg64(r, result);
transition_fpu_to_mmx();
}
#[no_mangle]
pub unsafe fn psllq_r64(r: i32, shift: u64) {
// psllq mm, {shift}
let destination = read_mmx64s(r);
@ -189,7 +170,6 @@ pub unsafe fn psllq_r64(r: i32, shift: u64) {
write_mmx_reg64(r, result);
transition_fpu_to_mmx();
}
#[no_mangle]
pub unsafe fn psrlw_r128(r: i32, shift: u64) {
// psrlw xmm, {shift}
let destination = read_xmm128s(r);
@ -205,7 +185,6 @@ pub unsafe fn psrlw_r128(r: i32, shift: u64) {
}
write_xmm128(r, dword0, dword1, dword2, dword3);
}
#[no_mangle]
pub unsafe fn psraw_r128(r: i32, shift: u64) {
// psraw xmm, {shift}
let destination = read_xmm128s(r);
@ -220,7 +199,6 @@ pub unsafe fn psraw_r128(r: i32, shift: u64) {
| destination.i16_0[7] as i32 >> shift_clamped << 16;
write_xmm128(r, dword0, dword1, dword2, dword3);
}
#[no_mangle]
pub unsafe fn psllw_r128(r: i32, shift: u64) {
// psllw xmm, {shift}
let destination = read_xmm128s(r);
@ -240,7 +218,6 @@ pub unsafe fn psllw_r128(r: i32, shift: u64) {
}
write_xmm128(r, dword0, dword1, dword2, dword3);
}
#[no_mangle]
pub unsafe fn psrld_r128(r: i32, shift: u64) {
// psrld xmm, {shift}
let destination = read_xmm128s(r);
@ -256,7 +233,6 @@ pub unsafe fn psrld_r128(r: i32, shift: u64) {
}
write_xmm128(r, dword0, dword1, dword2, dword3);
}
#[no_mangle]
pub unsafe fn psrad_r128(r: i32, shift: u64) {
// psrad xmm, {shift}
let destination = read_xmm128s(r);
@ -267,7 +243,6 @@ pub unsafe fn psrad_r128(r: i32, shift: u64) {
let dword3 = destination.i32_0[3] >> shift_clamped;
write_xmm128(r, dword0, dword1, dword2, dword3);
}
#[no_mangle]
pub unsafe fn pslld_r128(r: i32, shift: u64) {
// pslld xmm, {shift}
let destination = read_xmm128s(r);
@ -283,7 +258,6 @@ pub unsafe fn pslld_r128(r: i32, shift: u64) {
}
write_xmm128(r, dword0, dword1, dword2, dword3);
}
#[no_mangle]
pub unsafe fn psrlq_r128(r: i32, shift: u64) {
// psrlq xmm, {shift}
let destination = read_xmm128s(r);
@ -294,7 +268,6 @@ pub unsafe fn psrlq_r128(r: i32, shift: u64) {
}
write_xmm_reg128(r, result);
}
#[no_mangle]
pub unsafe fn psllq_r128(r: i32, shift: u64) {
// psllq xmm, {shift}
let destination = read_xmm128s(r);
@ -306,7 +279,6 @@ pub unsafe fn psllq_r128(r: i32, shift: u64) {
write_xmm_reg128(r, result);
}
#[no_mangle]
pub unsafe fn sse_comparison(op: i32, x: f64, y: f64) -> bool {
// TODO: Signaling
match op & 7 {
@ -324,12 +296,10 @@ pub unsafe fn sse_comparison(op: i32, x: f64, y: f64) -> bool {
},
};
}
#[no_mangle]
pub unsafe fn sse_min(x: f64, y: f64) -> f64 {
// if both x and y are 0 or x is nan, y is returned
return if x < y { x } else { y };
}
#[no_mangle]
pub unsafe fn sse_max(x: f64, y: f64) -> f64 {
// if both x and y are 0 or x is nan, y is returned
return if x > y { x } else { y };