Skip to content

Commit

Permalink
refactor(gdt): migrate CR3 access to x86_64 crate
Browse files Browse the repository at this point in the history
  • Loading branch information
mkroening committed Dec 20, 2024
1 parent 270af2e commit ee3fa55
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/arch/x86_64/kernel/gdt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,21 @@ pub fn add_current_core() {

pub extern "C" fn set_current_kernel_stack() {
#[cfg(feature = "common-os")]
unsafe {
{
use x86_64::registers::control::Cr3;
use x86_64::structures::paging::PhysFrame;
use x86_64::PhysAddr;

let root = crate::scheduler::get_root_page_table();
if root != x86::controlregs::cr3().try_into().unwrap() {
x86::controlregs::cr3_write(root.try_into().unwrap());
let new_frame =
PhysFrame::from_start_address(PhysAddr::new(root.try_into().unwrap())).unwrap();

let (current_frame, val) = Cr3::read_raw();

if current_frame != new_frame {
unsafe {
Cr3::write_raw(new_frame, val);
}
}
}

Expand Down

0 comments on commit ee3fa55

Please sign in to comment.