Skip to content

Commit

Permalink
sys: Fix PVALIDATE carry flag detection
Browse files Browse the repository at this point in the history
The assembler code for PVALIDATE performs an XOR immediately after the
PVALIDATE instruction, which clears the carry-flag, causing the carry-flag
result of the PVALIDATE instruction to be lost.

Move the XOR before the PVALIDATE instruction and switch to using the R8
register since the RCX register is used as input to PVALIDATE

Signed-off-by: Tom Lendacky <[email protected]>
  • Loading branch information
tlendacky committed Jan 10, 2024
1 parent 1801cf2 commit 4b2cab1
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/cpu/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ pub fn pvalidate(va: u64, page_size: u32, validation: u32) -> u32 {
let mut carry: u32;

unsafe {
asm!(".byte 0xf2,0x0f,0x01,0xff",
"xor rcx, rcx",
asm!("xor r8, r8",
".byte 0xf2,0x0f,0x01,0xff",
"jnc 1f",
"inc rcx",
"inc r8",
"1:",
in("rax") va, in("rcx") page_size, in("rdx") validation,
lateout("rax") ret, lateout("rcx") carry,
lateout("rax") ret, lateout("r8") carry,
options(nostack));
}

Expand Down

0 comments on commit 4b2cab1

Please sign in to comment.