Skip to content

Commit 2215d00

Browse files
committed
Remove nop instructions and explain why we need inline asm to access protected mode
1 parent 2eed431 commit 2215d00

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

bios/stage-2/src/protected_mode.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,19 @@ pub fn enter_unreal_mode() {
9090
pub unsafe fn copy_to_protected_mode(target: *mut u8, bytes: &[u8]) {
9191
for (offset, byte) in bytes.iter().enumerate() {
9292
let dst = target.wrapping_add(offset);
93-
unsafe { asm!("nop", "nop", "mov [{}], {}", in(reg) dst, in(reg_byte) *byte) };
93+
// we need to do the write in inline assembly because the compiler
94+
// seems to truncate the address
95+
unsafe { asm!("mov [{}], {}", in(reg) dst, in(reg_byte) *byte) };
9496
assert_eq!(read_from_protected_mode(dst), *byte);
9597
}
9698
}
9799

98100
#[no_mangle]
99101
pub unsafe fn read_from_protected_mode(ptr: *mut u8) -> u8 {
100102
let res;
101-
unsafe { asm!("nop", "nop", "mov {}, [{}]", out(reg_byte) res, in(reg) ptr) };
103+
// we need to do the read in inline assembly because the compiler
104+
// seems to truncate the address
105+
unsafe { asm!("mov {}, [{}]", out(reg_byte) res, in(reg) ptr) };
102106
res
103107
}
104108

0 commit comments

Comments
 (0)