Skip to content

Commit b1780e1

Browse files
committed
add internal write fn that writes the 63rd bit
1 parent a20e690 commit b1780e1

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/registers/control.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ mod x86_64 {
308308
#[inline]
309309
pub unsafe fn write(frame: PhysFrame, flags: Cr3Flags) {
310310
unsafe {
311-
Cr3::write_raw(frame, flags.bits() as u16);
311+
Cr3::write_raw_impl(false, frame, flags.bits() as u16);
312312
}
313313
}
314314

@@ -322,7 +322,7 @@ mod x86_64 {
322322
#[inline]
323323
pub unsafe fn write_pcid(frame: PhysFrame, pcid: Pcid) {
324324
unsafe {
325-
Cr3::write_raw(frame, pcid.value());
325+
Cr3::write_raw_impl(false, frame, pcid.value());
326326
}
327327
}
328328

@@ -334,8 +334,13 @@ mod x86_64 {
334334
/// changing the page mapping.
335335
#[inline]
336336
pub unsafe fn write_raw(frame: PhysFrame, val: u16) {
337+
unsafe { Self::write_raw_impl(false, frame, val) }
338+
}
339+
340+
#[inline]
341+
unsafe fn write_raw_impl(top_bit: bool, frame: PhysFrame, val: u16) {
337342
let addr = frame.start_address();
338-
let value = addr.as_u64() | val as u64;
343+
let value = ((top_bit as u64) << 63) | addr.as_u64() | val as u64;
339344

340345
unsafe {
341346
asm!("mov cr3, {}", in(reg) value, options(nostack, preserves_flags));

0 commit comments

Comments
 (0)