diff --git a/src/rust/cpu2/cpu.rs b/src/rust/cpu2/cpu.rs index 0e8cb795..9ae64b75 100644 --- a/src/rust/cpu2/cpu.rs +++ b/src/rust/cpu2/cpu.rs @@ -2833,8 +2833,8 @@ pub unsafe fn get_reg_asize(reg: i32) -> i32 { }; } -pub unsafe fn set_ecx_asize(value: i32) { - if is_asize_32() { +pub unsafe fn set_ecx_asize(is_asize_32: bool, value: i32) { + if is_asize_32 { *reg32.offset(ECX as isize) = value } else { @@ -2842,9 +2842,9 @@ pub unsafe fn set_ecx_asize(value: i32) { }; } -pub unsafe fn add_reg_asize(reg: i32, value: i32) { +pub unsafe fn add_reg_asize(is_asize_32: bool, reg: i32, value: i32) { dbg_assert!(reg == ECX || reg == ESI || reg == EDI); - if is_asize_32() { + if is_asize_32 { *reg32.offset(reg as isize) += value; } else { @@ -2852,8 +2852,8 @@ pub unsafe fn add_reg_asize(reg: i32, value: i32) { }; } -pub unsafe fn decr_ecx_asize() -> i32 { - return if is_asize_32() { +pub unsafe fn decr_ecx_asize(is_asize_32: bool) -> i32 { + return if is_asize_32 { *reg32.offset(ECX as isize) -= 1; *reg32.offset(ECX as isize) } diff --git a/src/rust/cpu2/instructions.rs b/src/rust/cpu2/instructions.rs index e6d33614..6e2d9187 100644 --- a/src/rust/cpu2/instructions.rs +++ b/src/rust/cpu2/instructions.rs @@ -922,17 +922,17 @@ pub unsafe fn instr32_6B_reg(r1: i32, r: i32, imm: i32) { write_reg32(r, imul_reg32(read_reg32(r1), imm)); } #[no_mangle] -pub unsafe fn instr_6C() { insb_no_rep(); } +pub unsafe fn instr_6C() { insb_no_rep(is_asize_32()); } #[no_mangle] -pub unsafe fn instr16_6D() { insw_no_rep(); } +pub unsafe fn instr16_6D() { insw_no_rep(is_asize_32()); } #[no_mangle] -pub unsafe fn instr32_6D() { insd_no_rep(); } +pub unsafe fn instr32_6D() { insd_no_rep(is_asize_32()); } #[no_mangle] -pub unsafe fn instr_6E() { outsb_no_rep(); } +pub unsafe fn instr_6E() { outsb_no_rep(is_asize_32(), get_seg_prefix(DS)); } #[no_mangle] -pub unsafe fn instr16_6F() { outsw_no_rep(); } +pub unsafe fn instr16_6F() { outsw_no_rep(is_asize_32(), get_seg_prefix(DS)); } #[no_mangle] -pub unsafe fn instr32_6F() { outsd_no_rep(); } +pub unsafe fn instr32_6F() { outsd_no_rep(is_asize_32(), get_seg_prefix(DS)); } #[no_mangle] pub unsafe fn instr_80_0_mem(addr: i32, imm: i32) { SAFE_READ_WRITE8!(___, addr, add8(___, imm)); @@ -1613,17 +1613,17 @@ pub unsafe fn instr32_A3(moffs: i32) { )); } #[no_mangle] -pub unsafe fn instr_A4() { movsb_no_rep(); } +pub unsafe fn instr_A4() { movsb_no_rep(is_asize_32(), get_seg_prefix(DS)); } #[no_mangle] -pub unsafe fn instr16_A5() { movsw_no_rep(); } +pub unsafe fn instr16_A5() { movsw_no_rep(is_asize_32(), get_seg_prefix(DS)); } #[no_mangle] -pub unsafe fn instr32_A5() { movsd_no_rep(); } +pub unsafe fn instr32_A5() { movsd_no_rep(is_asize_32(), get_seg_prefix(DS)); } #[no_mangle] -pub unsafe fn instr_A6() { cmpsb_no_rep(); } +pub unsafe fn instr_A6() { cmpsb_no_rep(is_asize_32(), get_seg_prefix(DS)); } #[no_mangle] -pub unsafe fn instr16_A7() { cmpsw_no_rep(); } +pub unsafe fn instr16_A7() { cmpsw_no_rep(is_asize_32(), get_seg_prefix(DS)); } #[no_mangle] -pub unsafe fn instr32_A7() { cmpsd_no_rep(); } +pub unsafe fn instr32_A7() { cmpsd_no_rep(is_asize_32(), get_seg_prefix(DS)); } #[no_mangle] pub unsafe fn instr_A8(imm8: i32) { test8(*reg8.offset(AL as isize) as i32, imm8); } #[no_mangle] @@ -1631,23 +1631,23 @@ pub unsafe fn instr16_A9(imm16: i32) { test16(*reg16.offset(AX as isize) as i32, #[no_mangle] pub unsafe fn instr32_A9(imm32: i32) { test32(*reg32.offset(EAX as isize), imm32); } #[no_mangle] -pub unsafe fn instr_AA() { stosb_no_rep(); } +pub unsafe fn instr_AA() { stosb_no_rep(is_asize_32()); } #[no_mangle] -pub unsafe fn instr16_AB() { stosw_no_rep(); } +pub unsafe fn instr16_AB() { stosw_no_rep(is_asize_32()); } #[no_mangle] -pub unsafe fn instr32_AB() { stosd_no_rep(); } +pub unsafe fn instr32_AB() { stosd_no_rep(is_asize_32()); } #[no_mangle] -pub unsafe fn instr_AC() { lodsb_no_rep(); } +pub unsafe fn instr_AC() { lodsb_no_rep(is_asize_32(), get_seg_prefix(DS)); } #[no_mangle] -pub unsafe fn instr16_AD() { lodsw_no_rep(); } +pub unsafe fn instr16_AD() { lodsw_no_rep(is_asize_32(), get_seg_prefix(DS)); } #[no_mangle] -pub unsafe fn instr32_AD() { lodsd_no_rep(); } +pub unsafe fn instr32_AD() { lodsd_no_rep(is_asize_32(), get_seg_prefix(DS)); } #[no_mangle] -pub unsafe fn instr_AE() { scasb_no_rep(); } +pub unsafe fn instr_AE() { scasb_no_rep(is_asize_32()); } #[no_mangle] -pub unsafe fn instr16_AF() { scasw_no_rep(); } +pub unsafe fn instr16_AF() { scasw_no_rep(is_asize_32()); } #[no_mangle] -pub unsafe fn instr32_AF() { scasd_no_rep(); } +pub unsafe fn instr32_AF() { scasd_no_rep(is_asize_32()); } pub unsafe fn instr_B0(imm8: i32) { *reg8.offset(AL as isize) = imm8 as u8; } pub unsafe fn instr_B1(imm8: i32) { *reg8.offset(CL as isize) = imm8 as u8; } @@ -3028,29 +3028,29 @@ pub unsafe fn instr32_FF_6_reg(r1: i32) { return_on_pagefault!(push32(read_reg32(r1))); } #[no_mangle] -pub unsafe fn instr_F26C() { insb_rep(); } +pub unsafe fn instr_F26C() { insb_rep(is_asize_32()); } #[no_mangle] -pub unsafe fn instr_F36C() { insb_rep(); } +pub unsafe fn instr_F36C() { insb_rep(is_asize_32()); } #[no_mangle] -pub unsafe fn instr16_F26D() { insw_rep(); } +pub unsafe fn instr16_F26D() { insw_rep(is_asize_32()); } #[no_mangle] -pub unsafe fn instr16_F36D() { insw_rep(); } +pub unsafe fn instr16_F36D() { insw_rep(is_asize_32()); } #[no_mangle] -pub unsafe fn instr32_F26D() { insd_rep(); } +pub unsafe fn instr32_F26D() { insd_rep(is_asize_32()); } #[no_mangle] -pub unsafe fn instr32_F36D() { insd_rep(); } +pub unsafe fn instr32_F36D() { insd_rep(is_asize_32()); } #[no_mangle] -pub unsafe fn instr_F26E() { outsb_rep(); } +pub unsafe fn instr_F26E() { outsb_rep(is_asize_32(), get_seg_prefix(DS)); } #[no_mangle] -pub unsafe fn instr_F36E() { outsb_rep(); } +pub unsafe fn instr_F36E() { outsb_rep(is_asize_32(), get_seg_prefix(DS)); } #[no_mangle] -pub unsafe fn instr16_F26F() { outsw_rep(); } +pub unsafe fn instr16_F26F() { outsw_rep(is_asize_32(), get_seg_prefix(DS)); } #[no_mangle] -pub unsafe fn instr16_F36F() { outsw_rep(); } +pub unsafe fn instr16_F36F() { outsw_rep(is_asize_32(), get_seg_prefix(DS)); } #[no_mangle] -pub unsafe fn instr32_F26F() { outsd_rep(); } +pub unsafe fn instr32_F26F() { outsd_rep(is_asize_32(), get_seg_prefix(DS)); } #[no_mangle] -pub unsafe fn instr32_F36F() { outsd_rep(); } +pub unsafe fn instr32_F36F() { outsd_rep(is_asize_32(), get_seg_prefix(DS)); } #[no_mangle] pub unsafe fn instr16_70(imm8: i32) { jmpcc16(test_o(), imm8); } #[no_mangle] @@ -3116,65 +3116,65 @@ pub unsafe fn instr32_7E(imm8: i32) { jmpcc32(test_le(), imm8); } #[no_mangle] pub unsafe fn instr32_7F(imm8: i32) { jmpcc32(!test_le(), imm8); } #[no_mangle] -pub unsafe fn instr_F2A4() { movsb_rep(); } +pub unsafe fn instr_F2A4() { movsb_rep(is_asize_32(), get_seg_prefix(DS)); } #[no_mangle] -pub unsafe fn instr_F3A4() { movsb_rep(); } +pub unsafe fn instr_F3A4() { movsb_rep(is_asize_32(), get_seg_prefix(DS)); } #[no_mangle] -pub unsafe fn instr16_F2A5() { movsw_rep(); } +pub unsafe fn instr16_F2A5() { movsw_rep(is_asize_32(), get_seg_prefix(DS)); } #[no_mangle] -pub unsafe fn instr16_F3A5() { movsw_rep(); } +pub unsafe fn instr16_F3A5() { movsw_rep(is_asize_32(), get_seg_prefix(DS)); } #[no_mangle] -pub unsafe fn instr32_F2A5() { movsd_rep(); } +pub unsafe fn instr32_F2A5() { movsd_rep(is_asize_32(), get_seg_prefix(DS)); } #[no_mangle] -pub unsafe fn instr32_F3A5() { movsd_rep(); } +pub unsafe fn instr32_F3A5() { movsd_rep(is_asize_32(), get_seg_prefix(DS)); } #[no_mangle] -pub unsafe fn instr_F2A6() { cmpsb_rep(PREFIX_F2); } +pub unsafe fn instr_F2A6() { cmpsb_rep(PREFIX_F2, is_asize_32(), get_seg_prefix(DS)); } #[no_mangle] -pub unsafe fn instr_F3A6() { cmpsb_rep(PREFIX_F3); } +pub unsafe fn instr_F3A6() { cmpsb_rep(PREFIX_F3, is_asize_32(), get_seg_prefix(DS)); } #[no_mangle] -pub unsafe fn instr16_F2A7() { cmpsw_rep(PREFIX_F2); } +pub unsafe fn instr16_F2A7() { cmpsw_rep(PREFIX_F2, is_asize_32(), get_seg_prefix(DS)); } #[no_mangle] -pub unsafe fn instr16_F3A7() { cmpsw_rep(PREFIX_F3); } +pub unsafe fn instr16_F3A7() { cmpsw_rep(PREFIX_F3, is_asize_32(), get_seg_prefix(DS)); } #[no_mangle] -pub unsafe fn instr32_F2A7() { cmpsd_rep(PREFIX_F2); } +pub unsafe fn instr32_F2A7() { cmpsd_rep(PREFIX_F2, is_asize_32(), get_seg_prefix(DS)); } #[no_mangle] -pub unsafe fn instr32_F3A7() { cmpsd_rep(PREFIX_F3); } +pub unsafe fn instr32_F3A7() { cmpsd_rep(PREFIX_F3, is_asize_32(), get_seg_prefix(DS)); } #[no_mangle] -pub unsafe fn instr_F2AA() { stosb_rep(); } +pub unsafe fn instr_F2AA() { stosb_rep(is_asize_32()); } #[no_mangle] -pub unsafe fn instr_F3AA() { stosb_rep(); } +pub unsafe fn instr_F3AA() { stosb_rep(is_asize_32()); } #[no_mangle] -pub unsafe fn instr16_F2AB() { stosw_rep(); } +pub unsafe fn instr16_F2AB() { stosw_rep(is_asize_32()); } #[no_mangle] -pub unsafe fn instr16_F3AB() { stosw_rep(); } +pub unsafe fn instr16_F3AB() { stosw_rep(is_asize_32()); } #[no_mangle] -pub unsafe fn instr32_F2AB() { stosd_rep(); } +pub unsafe fn instr32_F2AB() { stosd_rep(is_asize_32()); } #[no_mangle] -pub unsafe fn instr32_F3AB() { stosd_rep(); } +pub unsafe fn instr32_F3AB() { stosd_rep(is_asize_32()); } #[no_mangle] -pub unsafe fn instr_F2AC() { lodsb_rep(); } +pub unsafe fn instr_F2AC() { lodsb_rep(is_asize_32(), get_seg_prefix(DS)); } #[no_mangle] -pub unsafe fn instr_F3AC() { lodsb_rep(); } +pub unsafe fn instr_F3AC() { lodsb_rep(is_asize_32(), get_seg_prefix(DS)); } #[no_mangle] -pub unsafe fn instr16_F2AD() { lodsw_rep(); } +pub unsafe fn instr16_F2AD() { lodsw_rep(is_asize_32(), get_seg_prefix(DS)); } #[no_mangle] -pub unsafe fn instr16_F3AD() { lodsw_rep(); } +pub unsafe fn instr16_F3AD() { lodsw_rep(is_asize_32(), get_seg_prefix(DS)); } #[no_mangle] -pub unsafe fn instr32_F2AD() { lodsd_rep(); } +pub unsafe fn instr32_F2AD() { lodsd_rep(is_asize_32(), get_seg_prefix(DS)); } #[no_mangle] -pub unsafe fn instr32_F3AD() { lodsd_rep(); } +pub unsafe fn instr32_F3AD() { lodsd_rep(is_asize_32(), get_seg_prefix(DS)); } #[no_mangle] -pub unsafe fn instr_F2AE() { scasb_rep(PREFIX_F2); } +pub unsafe fn instr_F2AE() { scasb_rep(PREFIX_F2, is_asize_32()); } #[no_mangle] -pub unsafe fn instr_F3AE() { scasb_rep(PREFIX_F3); } +pub unsafe fn instr_F3AE() { scasb_rep(PREFIX_F3, is_asize_32()); } #[no_mangle] -pub unsafe fn instr16_F2AF() { scasw_rep(PREFIX_F2); } +pub unsafe fn instr16_F2AF() { scasw_rep(PREFIX_F2, is_asize_32()); } #[no_mangle] -pub unsafe fn instr16_F3AF() { scasw_rep(PREFIX_F3); } +pub unsafe fn instr16_F3AF() { scasw_rep(PREFIX_F3, is_asize_32()); } #[no_mangle] -pub unsafe fn instr32_F2AF() { scasd_rep(PREFIX_F2); } +pub unsafe fn instr32_F2AF() { scasd_rep(PREFIX_F2, is_asize_32()); } #[no_mangle] -pub unsafe fn instr32_F3AF() { scasd_rep(PREFIX_F3); } +pub unsafe fn instr32_F3AF() { scasd_rep(PREFIX_F3, is_asize_32()); } #[no_mangle] pub unsafe fn instr_D8_0_mem(addr: i32) { fpu_fadd(0, return_on_pagefault!(fpu_load_m32(addr))); } diff --git a/src/rust/cpu2/misc_instr.rs b/src/rust/cpu2/misc_instr.rs index c552ae7e..b4df0f53 100644 --- a/src/rust/cpu2/misc_instr.rs +++ b/src/rust/cpu2/misc_instr.rs @@ -114,19 +114,23 @@ pub unsafe fn jmpcc32(condition: bool, imm32: i32) { }; } #[no_mangle] -pub unsafe fn loope16(imm8s: i32) { jmpcc16(0 != decr_ecx_asize() && getzf(), imm8s); } +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() && !getzf(), imm8s); } +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(), imm8s); } +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() && getzf(), imm8s); } +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() && !getzf(), imm8s); } +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(), imm8s); } +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); } diff --git a/src/rust/cpu2/string.rs b/src/rust/cpu2/string.rs index 7d9d3d01..7be15bb7 100644 --- a/src/rust/cpu2/string.rs +++ b/src/rust/cpu2/string.rs @@ -14,7 +14,7 @@ extern "C" { pub fn io_port_write32(port: i32, value: i32); } -use cpu2::arith::{cmp16, cmp32, cmp8}; +use cpu2::arith::{cmp8, cmp16, cmp32}; use cpu2::cpu::*; use cpu2::global_pointers::*; use cpu2::memory::{ @@ -23,6 +23,10 @@ use cpu2::memory::{ }; use page::Page; +const CX: i32 = ::regs::CX as i32; +const SI: i32 = ::regs::SI as i32; +const DI: i32 = ::regs::DI as i32; + const MAX_COUNT_PER_CYCLE: i32 = 4096; #[no_mangle] @@ -44,11 +48,11 @@ pub unsafe fn string_get_cycle_count2(size: i32, addr1: i32, addr2: i32) -> i32 return if c1 < c2 { c1 } else { c2 }; } #[no_mangle] -pub unsafe fn movsb_rep() { - let src = get_seg_prefix(DS) + get_reg_asize(ESI); - let dest = get_seg(ES) + get_reg_asize(EDI); +pub unsafe fn movsb_rep(is_asize_32: bool, ds: i32) { + let src = ds + if is_asize_32 { read_reg32(ESI) } else { read_reg16(SI) }; + let dest = get_seg(ES) + if is_asize_32 { read_reg32(EDI) } else { read_reg16(DI) }; let size = if 0 != *flags & FLAG_DIRECTION { -1 } else { 1 }; - let mut count: i32 = get_reg_asize(ECX); + let mut count: i32 = if is_asize_32 { read_reg32(ECX) } else { read_reg16(CX) }; if count == 0 { return; } @@ -90,9 +94,9 @@ pub unsafe fn movsb_rep() { } } let diff = size * (start_count - count); - add_reg_asize(EDI, diff); - add_reg_asize(ESI, diff); - set_ecx_asize(count); + add_reg_asize(is_asize_32, EDI, diff); + add_reg_asize(is_asize_32, ESI, diff); + set_ecx_asize(is_asize_32, count); *timestamp_counter = (*timestamp_counter as u32).wrapping_add((start_count - count) as u32) as u32 as u32; if 0 != cont { @@ -102,21 +106,21 @@ pub unsafe fn movsb_rep() { }; } #[no_mangle] -pub unsafe fn movsb_no_rep() { - let src = get_seg_prefix(DS) + get_reg_asize(ESI); - let dest = get_seg(ES) + get_reg_asize(EDI); +pub unsafe fn movsb_no_rep(is_asize_32: bool, ds: i32) { + let src = ds + if is_asize_32 { read_reg32(ESI) } else { read_reg16(SI) }; + let dest = get_seg(ES) + if is_asize_32 { read_reg32(EDI) } else { read_reg16(DI) }; let size = if 0 != *flags & FLAG_DIRECTION { -1 } else { 1 }; return_on_pagefault!(safe_write8(dest, return_on_pagefault!(safe_read8(src)))); - add_reg_asize(EDI, size); - add_reg_asize(ESI, size); + add_reg_asize(is_asize_32, EDI, size); + add_reg_asize(is_asize_32, ESI, size); } #[no_mangle] -pub unsafe fn movsw_rep() { +pub unsafe fn movsw_rep(is_asize_32: bool, ds: i32) { let diff; - let mut src: i32 = get_seg_prefix(DS) + get_reg_asize(ESI); - let mut dest: i32 = get_seg(ES) + get_reg_asize(EDI); + let mut src: i32 = ds + if is_asize_32 { read_reg32(ESI) } else { read_reg16(SI) }; + let mut dest: i32 = get_seg(ES) + if is_asize_32 { read_reg32(EDI) } else { read_reg16(DI) }; let size = if 0 != *flags & FLAG_DIRECTION { -2 } else { 2 }; - let mut count: i32 = get_reg_asize(ECX); + let mut count: i32 = if is_asize_32 { read_reg32(ECX) } else { read_reg16(CX) }; if count == 0 { return; } @@ -144,9 +148,9 @@ pub unsafe fn movsw_rep() { } } diff = size * (start_count - count); - add_reg_asize(EDI, diff); - add_reg_asize(ESI, diff); - set_ecx_asize(count); + add_reg_asize(is_asize_32, EDI, diff); + add_reg_asize(is_asize_32, ESI, diff); + set_ecx_asize(is_asize_32, count); *timestamp_counter = (*timestamp_counter as u32).wrapping_add((start_count - count) as u32) as u32 as u32 } @@ -154,10 +158,10 @@ pub unsafe fn movsw_rep() { loop { return_on_pagefault!(safe_write16(dest, return_on_pagefault!(safe_read16(src)))); dest += size; - add_reg_asize(EDI, size); + add_reg_asize(is_asize_32, EDI, size); src += size; - add_reg_asize(ESI, size); - cont = (decr_ecx_asize() != 0) as i32; + add_reg_asize(is_asize_32, ESI, size); + cont = (decr_ecx_asize(is_asize_32) != 0) as i32; if !(0 != cont && { cycle_counter -= 1; 0 != cycle_counter @@ -173,21 +177,21 @@ pub unsafe fn movsw_rep() { }; } #[no_mangle] -pub unsafe fn movsw_no_rep() { - let src = get_seg_prefix(DS) + get_reg_asize(ESI); - let dest = get_seg(ES) + get_reg_asize(EDI); +pub unsafe fn movsw_no_rep(is_asize_32: bool, ds: i32) { + let src = ds + if is_asize_32 { read_reg32(ESI) } else { read_reg16(SI) }; + let dest = get_seg(ES) + if is_asize_32 { read_reg32(EDI) } else { read_reg16(DI) }; let size = if 0 != *flags & FLAG_DIRECTION { -2 } else { 2 }; return_on_pagefault!(safe_write16(dest, return_on_pagefault!(safe_read16(src)))); - add_reg_asize(EDI, size); - add_reg_asize(ESI, size); + add_reg_asize(is_asize_32, EDI, size); + add_reg_asize(is_asize_32, ESI, size); } #[no_mangle] -pub unsafe fn movsd_rep() { +pub unsafe fn movsd_rep(is_asize_32: bool, ds: i32) { let diff; - let mut src: i32 = get_seg_prefix(DS) + get_reg_asize(ESI); - let mut dest: i32 = get_seg(ES) + get_reg_asize(EDI); + let mut src: i32 = ds + if is_asize_32 { read_reg32(ESI) } else { read_reg16(SI) }; + let mut dest: i32 = get_seg(ES) + if is_asize_32 { read_reg32(EDI) } else { read_reg16(DI) }; let size = if 0 != *flags & FLAG_DIRECTION { -4 } else { 4 }; - let mut count: i32 = get_reg_asize(ECX); + let mut count: i32 = if is_asize_32 { read_reg32(ECX) } else { read_reg16(CX) }; if count == 0 { return; } @@ -236,9 +240,9 @@ pub unsafe fn movsd_rep() { } } diff = size * (start_count - count); - add_reg_asize(EDI, diff); - add_reg_asize(ESI, diff); - set_ecx_asize(count); + add_reg_asize(is_asize_32, EDI, diff); + add_reg_asize(is_asize_32, ESI, diff); + set_ecx_asize(is_asize_32, count); *timestamp_counter = (*timestamp_counter as u32).wrapping_add((start_count - count) as u32) as u32 as u32 } @@ -246,10 +250,10 @@ pub unsafe fn movsd_rep() { loop { return_on_pagefault!(safe_write32(dest, return_on_pagefault!(safe_read32s(src)))); dest += size; - add_reg_asize(EDI, size); + add_reg_asize(is_asize_32, EDI, size); src += size; - add_reg_asize(ESI, size); - cont = (decr_ecx_asize() != 0) as i32; + add_reg_asize(is_asize_32, ESI, size); + cont = (decr_ecx_asize(is_asize_32) != 0) as i32; if !(0 != cont && { cycle_counter -= 1; 0 != cycle_counter @@ -265,22 +269,22 @@ pub unsafe fn movsd_rep() { }; } #[no_mangle] -pub unsafe fn movsd_no_rep() { - let src = get_seg_prefix(DS) + get_reg_asize(ESI); - let dest = get_seg(ES) + get_reg_asize(EDI); +pub unsafe fn movsd_no_rep(is_asize_32: bool, ds: i32) { + let src = ds + if is_asize_32 { read_reg32(ESI) } else { read_reg16(SI) }; + let dest = get_seg(ES) + if is_asize_32 { read_reg32(EDI) } else { read_reg16(DI) }; let size = if 0 != *flags & FLAG_DIRECTION { -4 } else { 4 }; return_on_pagefault!(safe_write32(dest, return_on_pagefault!(safe_read32s(src)))); - add_reg_asize(EDI, size); - add_reg_asize(ESI, size); + add_reg_asize(is_asize_32, EDI, size); + add_reg_asize(is_asize_32, ESI, size); } #[no_mangle] -pub unsafe fn cmpsb_rep(prefix_flag: i32) { - let src = get_seg_prefix(DS) + get_reg_asize(ESI); - let dest = get_seg(ES) + get_reg_asize(EDI); +pub unsafe fn cmpsb_rep(prefix_flag: i32, is_asize_32: bool, ds: i32) { + let src = ds + if is_asize_32 { read_reg32(ESI) } else { read_reg16(SI) }; + let dest = get_seg(ES) + if is_asize_32 { read_reg32(EDI) } else { read_reg16(DI) }; let mut data_src; let mut data_dest; let size = if 0 != *flags & FLAG_DIRECTION { -1 } else { 1 }; - let mut count: i32 = get_reg_asize(ECX); + let mut count: i32 = if is_asize_32 { read_reg32(ECX) } else { read_reg16(CX) }; if count == 0 { return; } @@ -306,9 +310,9 @@ pub unsafe fn cmpsb_rep(prefix_flag: i32) { } } let diff = size * (start_count - count); - add_reg_asize(EDI, diff); - add_reg_asize(ESI, diff); - set_ecx_asize(count); + add_reg_asize(is_asize_32, EDI, diff); + add_reg_asize(is_asize_32, ESI, diff); + set_ecx_asize(is_asize_32, count); *timestamp_counter = (*timestamp_counter as u32).wrapping_add((start_count - count) as u32) as u32 as u32; if 0 != cont { @@ -319,27 +323,27 @@ pub unsafe fn cmpsb_rep(prefix_flag: i32) { }; } #[no_mangle] -pub unsafe fn cmpsb_no_rep() { - let src = get_seg_prefix(DS) + get_reg_asize(ESI); - let dest = get_seg(ES) + get_reg_asize(EDI); +pub unsafe fn cmpsb_no_rep(is_asize_32: bool, ds: i32) { + let src = ds + if is_asize_32 { read_reg32(ESI) } else { read_reg16(SI) }; + let dest = get_seg(ES) + if is_asize_32 { read_reg32(EDI) } else { read_reg16(DI) }; let data_src; let data_dest; let size = if 0 != *flags & FLAG_DIRECTION { -1 } else { 1 }; data_src = return_on_pagefault!(safe_read8(src)); data_dest = return_on_pagefault!(safe_read8(dest)); - add_reg_asize(EDI, size); - add_reg_asize(ESI, size); + add_reg_asize(is_asize_32, EDI, size); + add_reg_asize(is_asize_32, ESI, size); cmp8(data_src, data_dest); } #[no_mangle] -pub unsafe fn cmpsw_rep(prefix_flag: i32) { +pub unsafe fn cmpsw_rep(prefix_flag: i32, is_asize_32: bool, ds: i32) { let diff; - let mut src: i32 = get_seg_prefix(DS) + get_reg_asize(ESI); - let mut dest: i32 = get_seg(ES) + get_reg_asize(EDI); + let mut src: i32 = ds + if is_asize_32 { read_reg32(ESI) } else { read_reg16(SI) }; + let mut dest: i32 = get_seg(ES) + if is_asize_32 { read_reg32(EDI) } else { read_reg16(DI) }; let mut data_src; let mut data_dest; let size = if 0 != *flags & FLAG_DIRECTION { -2 } else { 2 }; - let mut count: i32 = get_reg_asize(ECX); + let mut count: i32 = if is_asize_32 { read_reg32(ECX) } else { read_reg16(CX) }; if count == 0 { return; } @@ -369,9 +373,9 @@ pub unsafe fn cmpsw_rep(prefix_flag: i32) { } } diff = size * (start_count - count); - add_reg_asize(EDI, diff); - add_reg_asize(ESI, diff); - set_ecx_asize(count); + add_reg_asize(is_asize_32, EDI, diff); + add_reg_asize(is_asize_32, ESI, diff); + set_ecx_asize(is_asize_32, count); *timestamp_counter = (*timestamp_counter as u32).wrapping_add((start_count - count) as u32) as u32 as u32 } @@ -380,10 +384,11 @@ pub unsafe fn cmpsw_rep(prefix_flag: i32) { data_dest = return_on_pagefault!(safe_read16(dest)); data_src = return_on_pagefault!(safe_read16(src)); dest += size; - add_reg_asize(EDI, size); + add_reg_asize(is_asize_32, EDI, size); src += size; - add_reg_asize(ESI, size); - cont = (decr_ecx_asize() != 0 && (data_src == data_dest) as i32 == is_repz) as i32; + add_reg_asize(is_asize_32, ESI, size); + cont = (decr_ecx_asize(is_asize_32) != 0 + && (data_src == data_dest) as i32 == is_repz) as i32; if !(0 != cont && { cycle_counter -= 1; 0 != cycle_counter @@ -400,27 +405,27 @@ pub unsafe fn cmpsw_rep(prefix_flag: i32) { }; } #[no_mangle] -pub unsafe fn cmpsw_no_rep() { - let src = get_seg_prefix(DS) + get_reg_asize(ESI); - let dest = get_seg(ES) + get_reg_asize(EDI); +pub unsafe fn cmpsw_no_rep(is_asize_32: bool, ds: i32) { + let src = ds + if is_asize_32 { read_reg32(ESI) } else { read_reg16(SI) }; + let dest = get_seg(ES) + if is_asize_32 { read_reg32(EDI) } else { read_reg16(DI) }; let data_src; let data_dest; let size = if 0 != *flags & FLAG_DIRECTION { -2 } else { 2 }; data_dest = return_on_pagefault!(safe_read16(dest)); data_src = return_on_pagefault!(safe_read16(src)); - add_reg_asize(EDI, size); - add_reg_asize(ESI, size); + add_reg_asize(is_asize_32, EDI, size); + add_reg_asize(is_asize_32, ESI, size); cmp16(data_src, data_dest); } #[no_mangle] -pub unsafe fn cmpsd_rep(prefix_flag: i32) { +pub unsafe fn cmpsd_rep(prefix_flag: i32, is_asize_32: bool, ds: i32) { let diff; - let mut src: i32 = get_seg_prefix(DS) + get_reg_asize(ESI); - let mut dest: i32 = get_seg(ES) + get_reg_asize(EDI); + let mut src: i32 = ds + if is_asize_32 { read_reg32(ESI) } else { read_reg16(SI) }; + let mut dest: i32 = get_seg(ES) + if is_asize_32 { read_reg32(EDI) } else { read_reg16(DI) }; let mut data_src; let mut data_dest; let size = if 0 != *flags & FLAG_DIRECTION { -4 } else { 4 }; - let mut count: i32 = get_reg_asize(ECX); + let mut count: i32 = if is_asize_32 { read_reg32(ECX) } else { read_reg16(CX) }; if count == 0 { return; } @@ -450,9 +455,9 @@ pub unsafe fn cmpsd_rep(prefix_flag: i32) { } } diff = size * (start_count - count); - add_reg_asize(EDI, diff); - add_reg_asize(ESI, diff); - set_ecx_asize(count); + add_reg_asize(is_asize_32, EDI, diff); + add_reg_asize(is_asize_32, ESI, diff); + set_ecx_asize(is_asize_32, count); *timestamp_counter = (*timestamp_counter as u32).wrapping_add((start_count - count) as u32) as u32 as u32 } @@ -461,10 +466,11 @@ pub unsafe fn cmpsd_rep(prefix_flag: i32) { data_dest = return_on_pagefault!(safe_read32s(dest)); data_src = return_on_pagefault!(safe_read32s(src)); dest += size; - add_reg_asize(EDI, size); + add_reg_asize(is_asize_32, EDI, size); src += size; - add_reg_asize(ESI, size); - cont = (decr_ecx_asize() != 0 && (data_src == data_dest) as i32 == is_repz) as i32; + add_reg_asize(is_asize_32, ESI, size); + cont = (decr_ecx_asize(is_asize_32) != 0 + && (data_src == data_dest) as i32 == is_repz) as i32; if !(0 != cont && { cycle_counter -= 1; 0 != cycle_counter @@ -481,24 +487,24 @@ pub unsafe fn cmpsd_rep(prefix_flag: i32) { }; } #[no_mangle] -pub unsafe fn cmpsd_no_rep() { - let src = get_seg_prefix(DS) + get_reg_asize(ESI); - let dest = get_seg(ES) + get_reg_asize(EDI); +pub unsafe fn cmpsd_no_rep(is_asize_32: bool, ds: i32) { + let src = ds + if is_asize_32 { read_reg32(ESI) } else { read_reg16(SI) }; + let dest = get_seg(ES) + if is_asize_32 { read_reg32(EDI) } else { read_reg16(DI) }; let data_src; let data_dest; let size = if 0 != *flags & FLAG_DIRECTION { -4 } else { 4 }; data_dest = return_on_pagefault!(safe_read32s(dest)); data_src = return_on_pagefault!(safe_read32s(src)); - add_reg_asize(EDI, size); - add_reg_asize(ESI, size); + add_reg_asize(is_asize_32, EDI, size); + add_reg_asize(is_asize_32, ESI, size); cmp32(data_src, data_dest); } #[no_mangle] -pub unsafe fn stosb_rep() { +pub unsafe fn stosb_rep(is_asize_32: bool) { let data = *reg8.offset(AL as isize) as i32; - let dest = get_seg(ES) + get_reg_asize(EDI); + let dest = get_seg(ES) + if is_asize_32 { read_reg32(EDI) } else { read_reg16(DI) }; let size = if 0 != *flags & FLAG_DIRECTION { -1 } else { 1 }; - let mut count: i32 = get_reg_asize(ECX); + let mut count: i32 = if is_asize_32 { read_reg32(ECX) } else { read_reg16(CX) }; if count == 0 { return; } @@ -537,8 +543,8 @@ pub unsafe fn stosb_rep() { } } let diff = size * (start_count - count); - add_reg_asize(EDI, diff); - set_ecx_asize(count); + add_reg_asize(is_asize_32, EDI, diff); + set_ecx_asize(is_asize_32, count); *timestamp_counter = (*timestamp_counter as u32).wrapping_add((start_count - count) as u32) as u32 as u32; if 0 != cont { @@ -548,20 +554,20 @@ pub unsafe fn stosb_rep() { }; } #[no_mangle] -pub unsafe fn stosb_no_rep() { +pub unsafe fn stosb_no_rep(is_asize_32: bool) { let data = *reg8.offset(AL as isize) as i32; - let dest = get_seg(ES) + get_reg_asize(EDI); + let dest = get_seg(ES) + if is_asize_32 { read_reg32(EDI) } else { read_reg16(DI) }; let size = if 0 != *flags & FLAG_DIRECTION { -1 } else { 1 }; return_on_pagefault!(safe_write8(dest, data)); - add_reg_asize(EDI, size); + add_reg_asize(is_asize_32, EDI, size); } #[no_mangle] -pub unsafe fn stosw_rep() { +pub unsafe fn stosw_rep(is_asize_32: bool) { let diff; let data = *reg16.offset(AX as isize) as i32; - let mut dest: i32 = get_seg(ES) + get_reg_asize(EDI); + let mut dest: i32 = get_seg(ES) + if is_asize_32 { read_reg32(EDI) } else { read_reg16(DI) }; let size = if 0 != *flags & FLAG_DIRECTION { -2 } else { 2 }; - let mut count: i32 = get_reg_asize(ECX); + let mut count: i32 = if is_asize_32 { read_reg32(ECX) } else { read_reg16(CX) }; if count == 0 { return; } @@ -587,8 +593,8 @@ pub unsafe fn stosw_rep() { } } diff = size * (start_count - count); - add_reg_asize(EDI, diff); - set_ecx_asize(count); + add_reg_asize(is_asize_32, EDI, diff); + set_ecx_asize(is_asize_32, count); *timestamp_counter = (*timestamp_counter as u32).wrapping_add((start_count - count) as u32) as u32 as u32 } @@ -596,8 +602,8 @@ pub unsafe fn stosw_rep() { loop { return_on_pagefault!(safe_write16(dest, data)); dest += size; - add_reg_asize(EDI, size); - cont = (decr_ecx_asize() != 0) as i32; + add_reg_asize(is_asize_32, EDI, size); + cont = (decr_ecx_asize(is_asize_32) != 0) as i32; if !(0 != cont && { cycle_counter -= 1; 0 != cycle_counter @@ -613,20 +619,20 @@ pub unsafe fn stosw_rep() { }; } #[no_mangle] -pub unsafe fn stosw_no_rep() { +pub unsafe fn stosw_no_rep(is_asize_32: bool) { let data = *reg16.offset(AX as isize) as i32; - let dest = get_seg(ES) + get_reg_asize(EDI); + let dest = get_seg(ES) + if is_asize_32 { read_reg32(EDI) } else { read_reg16(DI) }; let size = if 0 != *flags & FLAG_DIRECTION { -2 } else { 2 }; return_on_pagefault!(safe_write16(dest, data)); - add_reg_asize(EDI, size); + add_reg_asize(is_asize_32, EDI, size); } #[no_mangle] -pub unsafe fn stosd_rep() { +pub unsafe fn stosd_rep(is_asize_32: bool) { let diff; let data = *reg32.offset(EAX as isize); - let mut dest: i32 = get_seg(ES) + get_reg_asize(EDI); + let mut dest: i32 = get_seg(ES) + if is_asize_32 { read_reg32(EDI) } else { read_reg16(DI) }; let size = if 0 != *flags & FLAG_DIRECTION { -4 } else { 4 }; - let mut count: i32 = get_reg_asize(ECX); + let mut count: i32 = if is_asize_32 { read_reg32(ECX) } else { read_reg16(CX) }; if count == 0 { return; } @@ -669,8 +675,8 @@ pub unsafe fn stosd_rep() { } } diff = size * (start_count - count); - add_reg_asize(EDI, diff); - set_ecx_asize(count); + add_reg_asize(is_asize_32, EDI, diff); + set_ecx_asize(is_asize_32, count); *timestamp_counter = (*timestamp_counter as u32).wrapping_add((start_count - count) as u32) as u32 as u32 } @@ -678,8 +684,8 @@ pub unsafe fn stosd_rep() { loop { return_on_pagefault!(safe_write32(dest, data)); dest += size; - add_reg_asize(EDI, size); - cont = (decr_ecx_asize() != 0) as i32; + add_reg_asize(is_asize_32, EDI, size); + cont = (decr_ecx_asize(is_asize_32) != 0) as i32; if !(0 != cont && { cycle_counter -= 1; 0 != cycle_counter @@ -695,18 +701,18 @@ pub unsafe fn stosd_rep() { }; } #[no_mangle] -pub unsafe fn stosd_no_rep() { +pub unsafe fn stosd_no_rep(is_asize_32: bool) { let data = *reg32.offset(EAX as isize); - let dest = get_seg(ES) + get_reg_asize(EDI); + let dest = get_seg(ES) + if is_asize_32 { read_reg32(EDI) } else { read_reg16(DI) }; let size = if 0 != *flags & FLAG_DIRECTION { -4 } else { 4 }; return_on_pagefault!(safe_write32(dest, data)); - add_reg_asize(EDI, size); + add_reg_asize(is_asize_32, EDI, size); } #[no_mangle] -pub unsafe fn lodsb_rep() { - let src = get_seg_prefix(DS) + get_reg_asize(ESI); +pub unsafe fn lodsb_rep(is_asize_32: bool, ds: i32) { + let src = ds + if is_asize_32 { read_reg32(ESI) } else { read_reg16(SI) }; let size = if 0 != *flags & FLAG_DIRECTION { -1 } else { 1 }; - let mut count: i32 = get_reg_asize(ECX); + let mut count: i32 = if is_asize_32 { read_reg32(ECX) } else { read_reg16(CX) }; if count == 0 { return; } @@ -728,8 +734,8 @@ pub unsafe fn lodsb_rep() { } } let diff = size * (start_count - count); - add_reg_asize(ESI, diff); - set_ecx_asize(count); + add_reg_asize(is_asize_32, ESI, diff); + set_ecx_asize(is_asize_32, count); *timestamp_counter = (*timestamp_counter as u32).wrapping_add((start_count - count) as u32) as u32 as u32; if 0 != cont { @@ -739,17 +745,17 @@ pub unsafe fn lodsb_rep() { }; } #[no_mangle] -pub unsafe fn lodsb_no_rep() { - let src = get_seg_prefix(DS) + get_reg_asize(ESI); +pub unsafe fn lodsb_no_rep(is_asize_32: bool, ds: i32) { + let src = ds + if is_asize_32 { read_reg32(ESI) } else { read_reg16(SI) }; let size = if 0 != *flags & FLAG_DIRECTION { -1 } else { 1 }; *reg8.offset(AL as isize) = return_on_pagefault!(safe_read8(src)) as u8; - add_reg_asize(ESI, size); + add_reg_asize(is_asize_32, ESI, size); } #[no_mangle] -pub unsafe fn lodsw_rep() { - let mut src: i32 = get_seg_prefix(DS) + get_reg_asize(ESI); +pub unsafe fn lodsw_rep(is_asize_32: bool, ds: i32) { + let mut src: i32 = ds + if is_asize_32 { read_reg32(ESI) } else { read_reg16(SI) }; let size = if 0 != *flags & FLAG_DIRECTION { -2 } else { 2 }; - let count = get_reg_asize(ECX) as u32; + let count = if is_asize_32 { read_reg32(ECX) } else { read_reg16(CX) } as u32; if count == 0 { return; } @@ -759,8 +765,8 @@ pub unsafe fn lodsw_rep() { loop { *reg16.offset(AX as isize) = return_on_pagefault!(safe_read16(src)) as u16; src += size; - add_reg_asize(ESI, size); - cont = decr_ecx_asize() != 0; + add_reg_asize(is_asize_32, ESI, size); + cont = decr_ecx_asize(is_asize_32) != 0; if !(0 != cont as i32 && { cycle_counter = cycle_counter.wrapping_sub(1); 0 != cycle_counter @@ -775,17 +781,17 @@ pub unsafe fn lodsw_rep() { }; } #[no_mangle] -pub unsafe fn lodsw_no_rep() { - let src = get_seg_prefix(DS) + get_reg_asize(ESI); +pub unsafe fn lodsw_no_rep(is_asize_32: bool, ds: i32) { + let src = ds + if is_asize_32 { read_reg32(ESI) } else { read_reg16(SI) }; let size = if 0 != *flags & FLAG_DIRECTION { -2 } else { 2 }; *reg16.offset(AX as isize) = return_on_pagefault!(safe_read16(src)) as u16; - add_reg_asize(ESI, size); + add_reg_asize(is_asize_32, ESI, size); } #[no_mangle] -pub unsafe fn lodsd_rep() { - let mut src: i32 = get_seg_prefix(DS) + get_reg_asize(ESI); +pub unsafe fn lodsd_rep(is_asize_32: bool, ds: i32) { + let mut src: i32 = ds + if is_asize_32 { read_reg32(ESI) } else { read_reg16(SI) }; let size = if 0 != *flags & FLAG_DIRECTION { -4 } else { 4 }; - let count = get_reg_asize(ECX); + let count = if is_asize_32 { read_reg32(ECX) } else { read_reg16(CX) }; if count == 0 { return; } @@ -795,8 +801,8 @@ pub unsafe fn lodsd_rep() { loop { *reg32.offset(EAX as isize) = return_on_pagefault!(safe_read32s(src)); src += size; - add_reg_asize(ESI, size); - cont = (decr_ecx_asize() != 0) as i32; + add_reg_asize(is_asize_32, ESI, size); + cont = (decr_ecx_asize(is_asize_32) != 0) as i32; if !(0 != cont && { cycle_counter -= 1; 0 != cycle_counter @@ -811,19 +817,19 @@ pub unsafe fn lodsd_rep() { }; } #[no_mangle] -pub unsafe fn lodsd_no_rep() { - let src = get_seg_prefix(DS) + get_reg_asize(ESI); +pub unsafe fn lodsd_no_rep(is_asize_32: bool, ds: i32) { + let src = ds + if is_asize_32 { read_reg32(ESI) } else { read_reg16(SI) }; let size = if 0 != *flags & FLAG_DIRECTION { -4 } else { 4 }; *reg32.offset(EAX as isize) = return_on_pagefault!(safe_read32s(src)); - add_reg_asize(ESI, size); + add_reg_asize(is_asize_32, ESI, size); } #[no_mangle] -pub unsafe fn scasb_rep(prefix_flag: i32) { - let dest = get_seg(ES) + get_reg_asize(EDI); +pub unsafe fn scasb_rep(prefix_flag: i32, is_asize_32: bool) { + let dest = get_seg(ES) + if is_asize_32 { read_reg32(EDI) } else { read_reg16(DI) }; let size = if 0 != *flags & FLAG_DIRECTION { -1 } else { 1 }; let mut data_dest; let data_src = *reg8.offset(AL as isize) as i32; - let mut count: i32 = get_reg_asize(ECX); + let mut count: i32 = if is_asize_32 { read_reg32(ECX) } else { read_reg16(CX) }; if count == 0 { return; } @@ -846,8 +852,8 @@ pub unsafe fn scasb_rep(prefix_flag: i32) { } } let diff = size * (start_count - count); - add_reg_asize(EDI, diff); - set_ecx_asize(count); + add_reg_asize(is_asize_32, EDI, diff); + set_ecx_asize(is_asize_32, count); *timestamp_counter = (*timestamp_counter as u32).wrapping_add((start_count - count) as u32) as u32 as u32; if 0 != cont { @@ -858,23 +864,23 @@ pub unsafe fn scasb_rep(prefix_flag: i32) { }; } #[no_mangle] -pub unsafe fn scasb_no_rep() { - let dest = get_seg(ES) + get_reg_asize(EDI); +pub unsafe fn scasb_no_rep(is_asize_32: bool) { + let dest = get_seg(ES) + if is_asize_32 { read_reg32(EDI) } else { read_reg16(DI) }; let size = if 0 != *flags & FLAG_DIRECTION { -1 } else { 1 }; let data_dest; let data_src = *reg8.offset(AL as isize) as i32; data_dest = return_on_pagefault!(safe_read8(dest)); - add_reg_asize(EDI, size); + add_reg_asize(is_asize_32, EDI, size); cmp8(data_src, data_dest); } #[no_mangle] -pub unsafe fn scasw_rep(prefix_flag: i32) { +pub unsafe fn scasw_rep(prefix_flag: i32, is_asize_32: bool) { let diff; - let mut dest: i32 = get_seg(ES) + get_reg_asize(EDI); + let mut dest: i32 = get_seg(ES) + if is_asize_32 { read_reg32(EDI) } else { read_reg16(DI) }; let size = if 0 != *flags & FLAG_DIRECTION { -2 } else { 2 }; let mut data_dest; let data_src = *reg16.offset(AL as isize) as i32; - let mut count: i32 = get_reg_asize(ECX); + let mut count: i32 = if is_asize_32 { read_reg32(ECX) } else { read_reg16(CX) }; if count == 0 { return; } @@ -901,8 +907,8 @@ pub unsafe fn scasw_rep(prefix_flag: i32) { } } diff = size * (start_count - count); - add_reg_asize(EDI, diff); - set_ecx_asize(count); + add_reg_asize(is_asize_32, EDI, diff); + set_ecx_asize(is_asize_32, count); *timestamp_counter = (*timestamp_counter as u32).wrapping_add((start_count - count) as u32) as u32 as u32 } @@ -910,8 +916,9 @@ pub unsafe fn scasw_rep(prefix_flag: i32) { loop { data_dest = return_on_pagefault!(safe_read16(dest)); dest += size; - add_reg_asize(EDI, size); - cont = (decr_ecx_asize() != 0 && (data_src == data_dest) as i32 == is_repz) as i32; + add_reg_asize(is_asize_32, EDI, size); + cont = (decr_ecx_asize(is_asize_32) != 0 + && (data_src == data_dest) as i32 == is_repz) as i32; if !(0 != cont && { cycle_counter -= 1; 0 != cycle_counter @@ -928,23 +935,23 @@ pub unsafe fn scasw_rep(prefix_flag: i32) { }; } #[no_mangle] -pub unsafe fn scasw_no_rep() { - let dest = get_seg(ES) + get_reg_asize(EDI); +pub unsafe fn scasw_no_rep(is_asize_32: bool) { + let dest = get_seg(ES) + if is_asize_32 { read_reg32(EDI) } else { read_reg16(DI) }; let size = if 0 != *flags & FLAG_DIRECTION { -2 } else { 2 }; let data_dest; let data_src = *reg16.offset(AL as isize) as i32; data_dest = return_on_pagefault!(safe_read16(dest)); - add_reg_asize(EDI, size); + add_reg_asize(is_asize_32, EDI, size); cmp16(data_src, data_dest); } #[no_mangle] -pub unsafe fn scasd_rep(prefix_flag: i32) { +pub unsafe fn scasd_rep(prefix_flag: i32, is_asize_32: bool) { let diff; - let mut dest: i32 = get_seg(ES) + get_reg_asize(EDI); + let mut dest: i32 = get_seg(ES) + if is_asize_32 { read_reg32(EDI) } else { read_reg16(DI) }; let size = if 0 != *flags & FLAG_DIRECTION { -4 } else { 4 }; let mut data_dest; let data_src = *reg32.offset(EAX as isize); - let mut count: i32 = get_reg_asize(ECX); + let mut count: i32 = if is_asize_32 { read_reg32(ECX) } else { read_reg16(CX) }; if count == 0 { return; } @@ -971,8 +978,8 @@ pub unsafe fn scasd_rep(prefix_flag: i32) { } } diff = size * (start_count - count); - add_reg_asize(EDI, diff); - set_ecx_asize(count); + add_reg_asize(is_asize_32, EDI, diff); + set_ecx_asize(is_asize_32, count); *timestamp_counter = (*timestamp_counter as u32).wrapping_add((start_count - count) as u32) as u32 as u32 } @@ -980,8 +987,9 @@ pub unsafe fn scasd_rep(prefix_flag: i32) { loop { data_dest = return_on_pagefault!(safe_read32s(dest)); dest += size; - add_reg_asize(EDI, size); - cont = (decr_ecx_asize() != 0 && (data_src == data_dest) as i32 == is_repz) as i32; + add_reg_asize(is_asize_32, EDI, size); + cont = (decr_ecx_asize(is_asize_32) != 0 + && (data_src == data_dest) as i32 == is_repz) as i32; if !(0 != cont && { cycle_counter -= 1; 0 != cycle_counter @@ -998,25 +1006,25 @@ pub unsafe fn scasd_rep(prefix_flag: i32) { }; } #[no_mangle] -pub unsafe fn scasd_no_rep() { - let dest = get_seg(ES) + get_reg_asize(EDI); +pub unsafe fn scasd_no_rep(is_asize_32: bool) { + let dest = get_seg(ES) + if is_asize_32 { read_reg32(EDI) } else { read_reg16(DI) }; let size = if 0 != *flags & FLAG_DIRECTION { -4 } else { 4 }; let data_dest; let data_src = *reg32.offset(EAX as isize); data_dest = return_on_pagefault!(safe_read32s(dest)); - add_reg_asize(EDI, size); + add_reg_asize(is_asize_32, EDI, size); cmp32(data_src, data_dest); } #[no_mangle] -pub unsafe fn insb_rep() { +pub unsafe fn insb_rep(is_asize_32: bool) { let port = *reg16.offset(DX as isize) as i32; if !test_privileges_for_io(port, 1) { return; } else { - let dest = get_seg(ES) + get_reg_asize(EDI); + let dest = get_seg(ES) + if is_asize_32 { read_reg32(EDI) } else { read_reg16(DI) }; let size = if 0 != *flags & FLAG_DIRECTION { -1 } else { 1 }; - let mut count: i32 = get_reg_asize(ECX); + let mut count: i32 = if is_asize_32 { read_reg32(ECX) } else { read_reg16(CX) }; if count == 0 { return; } @@ -1038,8 +1046,8 @@ pub unsafe fn insb_rep() { } } let diff = size * (start_count - count); - add_reg_asize(EDI, diff); - set_ecx_asize(count); + add_reg_asize(is_asize_32, EDI, diff); + set_ecx_asize(is_asize_32, count); *timestamp_counter = (*timestamp_counter as u32) .wrapping_add((start_count - count) as u32) as u32 as u32; @@ -1051,31 +1059,32 @@ pub unsafe fn insb_rep() { }; } #[no_mangle] -pub unsafe fn insb_no_rep() { +pub unsafe fn insb_no_rep(is_asize_32: bool) { let port = *reg16.offset(DX as isize) as i32; if !test_privileges_for_io(port, 1) { return; } else { - let dest = get_seg(ES) + get_reg_asize(EDI); + let dest = get_seg(ES) + if is_asize_32 { read_reg32(EDI) } else { read_reg16(DI) }; let size = if 0 != *flags & FLAG_DIRECTION { -1 } else { 1 }; return_on_pagefault!(writable_or_pagefault(dest, 1)); return_on_pagefault!(safe_write8(dest, io_port_read8(port))); - add_reg_asize(EDI, size); + add_reg_asize(is_asize_32, EDI, size); return; }; } #[no_mangle] -pub unsafe fn insw_rep() { +pub unsafe fn insw_rep(is_asize_32: bool) { let diff; let port = *reg16.offset(DX as isize) as i32; if !test_privileges_for_io(port, 2) { return; } else { - let mut dest: i32 = get_seg(ES) + get_reg_asize(EDI); + let mut dest: i32 = + get_seg(ES) + if is_asize_32 { read_reg32(EDI) } else { read_reg16(DI) }; let size = if 0 != *flags & FLAG_DIRECTION { -2 } else { 2 }; - let mut count: i32 = get_reg_asize(ECX); + let mut count: i32 = if is_asize_32 { read_reg32(ECX) } else { read_reg16(CX) }; if count == 0 { return; } @@ -1101,8 +1110,8 @@ pub unsafe fn insw_rep() { } } diff = size * (start_count - count); - add_reg_asize(EDI, diff); - set_ecx_asize(count); + add_reg_asize(is_asize_32, EDI, diff); + set_ecx_asize(is_asize_32, count); *timestamp_counter = (*timestamp_counter as u32) .wrapping_add((start_count - count) as u32) as u32 as u32 @@ -1112,8 +1121,8 @@ pub unsafe fn insw_rep() { return_on_pagefault!(writable_or_pagefault(dest, 2)); return_on_pagefault!(safe_write16(dest, io_port_read16(port))); dest += size; - add_reg_asize(EDI, size); - cont = (decr_ecx_asize() != 0) as i32; + add_reg_asize(is_asize_32, EDI, size); + cont = (decr_ecx_asize(is_asize_32) != 0) as i32; if !(0 != cont && { cycle_counter -= 1; 0 != cycle_counter @@ -1130,31 +1139,32 @@ pub unsafe fn insw_rep() { }; } #[no_mangle] -pub unsafe fn insw_no_rep() { +pub unsafe fn insw_no_rep(is_asize_32: bool) { let port = *reg16.offset(DX as isize) as i32; if !test_privileges_for_io(port, 2) { return; } else { - let dest = get_seg(ES) + get_reg_asize(EDI); + let dest = get_seg(ES) + if is_asize_32 { read_reg32(EDI) } else { read_reg16(DI) }; let size = if 0 != *flags & FLAG_DIRECTION { -2 } else { 2 }; return_on_pagefault!(writable_or_pagefault(dest, 2)); return_on_pagefault!(safe_write16(dest, io_port_read16(port))); - add_reg_asize(EDI, size); + add_reg_asize(is_asize_32, EDI, size); return; }; } #[no_mangle] -pub unsafe fn insd_rep() { +pub unsafe fn insd_rep(is_asize_32: bool) { let diff; let port = *reg16.offset(DX as isize) as i32; if !test_privileges_for_io(port, 4) { return; } else { - let mut dest: i32 = get_seg(ES) + get_reg_asize(EDI); + let mut dest: i32 = + get_seg(ES) + if is_asize_32 { read_reg32(EDI) } else { read_reg16(DI) }; let size = if 0 != *flags & FLAG_DIRECTION { -4 } else { 4 }; - let mut count: i32 = get_reg_asize(ECX); + let mut count: i32 = if is_asize_32 { read_reg32(ECX) } else { read_reg16(CX) }; if count == 0 { return; } @@ -1180,8 +1190,8 @@ pub unsafe fn insd_rep() { } } diff = size * (start_count - count); - add_reg_asize(EDI, diff); - set_ecx_asize(count); + add_reg_asize(is_asize_32, EDI, diff); + set_ecx_asize(is_asize_32, count); *timestamp_counter = (*timestamp_counter as u32) .wrapping_add((start_count - count) as u32) as u32 as u32 @@ -1191,8 +1201,8 @@ pub unsafe fn insd_rep() { return_on_pagefault!(writable_or_pagefault(dest, 4)); return_on_pagefault!(safe_write32(dest, io_port_read32(port))); dest += size; - add_reg_asize(EDI, size); - cont = (decr_ecx_asize() != 0) as i32; + add_reg_asize(is_asize_32, EDI, size); + cont = (decr_ecx_asize(is_asize_32) != 0) as i32; if !(0 != cont && { cycle_counter -= 1; 0 != cycle_counter @@ -1209,30 +1219,30 @@ pub unsafe fn insd_rep() { }; } #[no_mangle] -pub unsafe fn insd_no_rep() { +pub unsafe fn insd_no_rep(is_asize_32: bool) { let port = *reg16.offset(DX as isize) as i32; if !test_privileges_for_io(port, 4) { return; } else { - let dest = get_seg(ES) + get_reg_asize(EDI); + let dest = get_seg(ES) + if is_asize_32 { read_reg32(EDI) } else { read_reg16(DI) }; let size = if 0 != *flags & FLAG_DIRECTION { -4 } else { 4 }; return_on_pagefault!(writable_or_pagefault(dest, 4)); return_on_pagefault!(safe_write32(dest, io_port_read32(port))); - add_reg_asize(EDI, size); + add_reg_asize(is_asize_32, EDI, size); return; }; } #[no_mangle] -pub unsafe fn outsb_rep() { +pub unsafe fn outsb_rep(is_asize_32: bool, ds: i32) { let port = *reg16.offset(DX as isize) as i32; if !test_privileges_for_io(port, 1) { return; } else { - let src = get_seg_prefix(DS) + get_reg_asize(ESI); + let src = ds + if is_asize_32 { read_reg32(ESI) } else { read_reg16(SI) }; let size = if 0 != *flags & FLAG_DIRECTION { -1 } else { 1 }; - let mut count: i32 = get_reg_asize(ECX); + let mut count: i32 = if is_asize_32 { read_reg32(ECX) } else { read_reg16(CX) }; if count == 0 { return; } @@ -1254,8 +1264,8 @@ pub unsafe fn outsb_rep() { } } let diff = size * (start_count - count); - add_reg_asize(ESI, diff); - set_ecx_asize(count); + add_reg_asize(is_asize_32, ESI, diff); + set_ecx_asize(is_asize_32, count); *timestamp_counter = (*timestamp_counter as u32) .wrapping_add((start_count - count) as u32) as u32 as u32; @@ -1267,30 +1277,30 @@ pub unsafe fn outsb_rep() { }; } #[no_mangle] -pub unsafe fn outsb_no_rep() { +pub unsafe fn outsb_no_rep(is_asize_32: bool, ds: i32) { let port = *reg16.offset(DX as isize) as i32; if !test_privileges_for_io(port, 1) { return; } else { - let src = get_seg_prefix(DS) + get_reg_asize(ESI); + let src = ds + if is_asize_32 { read_reg32(ESI) } else { read_reg16(SI) }; let size = if 0 != *flags & FLAG_DIRECTION { -1 } else { 1 }; io_port_write8(port, return_on_pagefault!(safe_read8(src))); - add_reg_asize(ESI, size); + add_reg_asize(is_asize_32, ESI, size); return; }; } #[no_mangle] -pub unsafe fn outsw_rep() { +pub unsafe fn outsw_rep(is_asize_32: bool, ds: i32) { let diff; let port = *reg16.offset(DX as isize) as i32; if !test_privileges_for_io(port, 2) { return; } else { - let mut src: i32 = get_seg_prefix(DS) + get_reg_asize(ESI); + let mut src: i32 = ds + if is_asize_32 { read_reg32(ESI) } else { read_reg16(SI) }; let size = if 0 != *flags & FLAG_DIRECTION { -2 } else { 2 }; - let mut count: i32 = get_reg_asize(ECX); + let mut count: i32 = if is_asize_32 { read_reg32(ECX) } else { read_reg16(CX) }; if count == 0 { return; } @@ -1316,8 +1326,8 @@ pub unsafe fn outsw_rep() { } } diff = size * (start_count - count); - add_reg_asize(ESI, diff); - set_ecx_asize(count); + add_reg_asize(is_asize_32, ESI, diff); + set_ecx_asize(is_asize_32, count); *timestamp_counter = (*timestamp_counter as u32) .wrapping_add((start_count - count) as u32) as u32 as u32 @@ -1326,8 +1336,8 @@ pub unsafe fn outsw_rep() { loop { io_port_write16(port, return_on_pagefault!(safe_read16(src))); src += size; - add_reg_asize(ESI, size); - cont = (decr_ecx_asize() != 0) as i32; + add_reg_asize(is_asize_32, ESI, size); + cont = (decr_ecx_asize(is_asize_32) != 0) as i32; if !(0 != cont && { cycle_counter -= 1; 0 != cycle_counter @@ -1344,30 +1354,30 @@ pub unsafe fn outsw_rep() { }; } #[no_mangle] -pub unsafe fn outsw_no_rep() { +pub unsafe fn outsw_no_rep(is_asize_32: bool, ds: i32) { let port = *reg16.offset(DX as isize) as i32; if !test_privileges_for_io(port, 2) { return; } else { - let src = get_seg_prefix(DS) + get_reg_asize(ESI); + let src = ds + if is_asize_32 { read_reg32(ESI) } else { read_reg16(SI) }; let size = if 0 != *flags & FLAG_DIRECTION { -2 } else { 2 }; io_port_write16(port, return_on_pagefault!(safe_read16(src))); - add_reg_asize(ESI, size); + add_reg_asize(is_asize_32, ESI, size); return; }; } #[no_mangle] -pub unsafe fn outsd_rep() { +pub unsafe fn outsd_rep(is_asize_32: bool, ds: i32) { let diff; let port = *reg16.offset(DX as isize) as i32; if !test_privileges_for_io(port, 4) { return; } else { - let mut src: i32 = get_seg_prefix(DS) + get_reg_asize(ESI); + let mut src: i32 = ds + if is_asize_32 { read_reg32(ESI) } else { read_reg16(SI) }; let size = if 0 != *flags & FLAG_DIRECTION { -4 } else { 4 }; - let mut count: i32 = get_reg_asize(ECX); + let mut count: i32 = if is_asize_32 { read_reg32(ECX) } else { read_reg16(CX) }; if count == 0 { return; } @@ -1393,8 +1403,8 @@ pub unsafe fn outsd_rep() { } } diff = size * (start_count - count); - add_reg_asize(ESI, diff); - set_ecx_asize(count); + add_reg_asize(is_asize_32, ESI, diff); + set_ecx_asize(is_asize_32, count); *timestamp_counter = (*timestamp_counter as u32) .wrapping_add((start_count - count) as u32) as u32 as u32 @@ -1403,8 +1413,8 @@ pub unsafe fn outsd_rep() { loop { io_port_write32(port, return_on_pagefault!(safe_read32s(src))); src += size; - add_reg_asize(ESI, size); - cont = (decr_ecx_asize() != 0) as i32; + add_reg_asize(is_asize_32, ESI, size); + cont = (decr_ecx_asize(is_asize_32) != 0) as i32; if !(0 != cont && { cycle_counter -= 1; 0 != cycle_counter @@ -1421,16 +1431,16 @@ pub unsafe fn outsd_rep() { }; } #[no_mangle] -pub unsafe fn outsd_no_rep() { +pub unsafe fn outsd_no_rep(is_asize_32: bool, ds: i32) { let port = *reg16.offset(DX as isize) as i32; if !test_privileges_for_io(port, 4) { return; } else { - let src = get_seg_prefix(DS) + get_reg_asize(ESI); + let src = ds + if is_asize_32 { read_reg32(ESI) } else { read_reg16(SI) }; let size = if 0 != *flags & FLAG_DIRECTION { -4 } else { 4 }; io_port_write32(port, return_on_pagefault!(safe_read32s(src))); - add_reg_asize(ESI, size); + add_reg_asize(is_asize_32, ESI, size); return; }; }