From fe7def27970cc7c21373d3e73e776986e14e7bac Mon Sep 17 00:00:00 2001 From: Jeremy Soller <jackpot51@gmail.com> Date: Sat, 20 Aug 2022 13:16:23 -0600 Subject: [PATCH] Update to use TableKind on x86_64 --- src/arch/x86_64/rmm.rs | 4 +++- src/arch/x86_64/start.rs | 4 ++-- src/context/arch/x86_64.rs | 4 ++-- src/debugger.rs | 8 ++++---- src/syscall/mod.rs | 10 +++++----- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/arch/x86_64/rmm.rs b/src/arch/x86_64/rmm.rs index 380505e8..7827a7e8 100644 --- a/src/arch/x86_64/rmm.rs +++ b/src/arch/x86_64/rmm.rs @@ -17,6 +17,7 @@ use rmm::{ PageFlags, PageMapper, PhysicalAddress, + TableKind, VirtualAddress, }; use spin::Mutex; @@ -100,6 +101,7 @@ unsafe fn inner<A: Arch>( { let mut mapper = PageMapper::<A, _>::create( + TableKind::Kernel, &mut bump_allocator ).expect("failed to create Mapper"); @@ -298,7 +300,7 @@ impl KernelMapper { } } pub fn lock_manually(current_processor: usize) -> Self { - unsafe { Self::lock_for_manual_mapper(current_processor, PageMapper::new(RmmA::table(), FRAME_ALLOCATOR)) } + unsafe { Self::lock_for_manual_mapper(current_processor, PageMapper::current(TableKind::Kernel, FRAME_ALLOCATOR)) } } pub fn lock() -> Self { Self::lock_manually(crate::cpu_id()) diff --git a/src/arch/x86_64/start.rs b/src/arch/x86_64/start.rs index 08a6c919..24235cfc 100644 --- a/src/arch/x86_64/start.rs +++ b/src/arch/x86_64/start.rs @@ -18,7 +18,7 @@ use crate::gdt; use crate::idt; use crate::interrupt; use crate::log::{self, info}; -use crate::paging::{self, KernelMapper}; +use crate::paging::{self, KernelMapper, TableKind}; /// Test of zero values in BSS. static BSS_TEST_ZERO: usize = 0; @@ -234,7 +234,7 @@ pub unsafe extern fn kstart_ap(args_ptr: *const KernelArgsAp) -> ! { use crate::paging::{PageMapper, PhysicalAddress}; use crate::rmm::FRAME_ALLOCATOR; - let mut mapper = KernelMapper::lock_for_manual_mapper(cpu_id, PageMapper::new(PhysicalAddress::new(bsp_table), FRAME_ALLOCATOR)); + let mut mapper = KernelMapper::lock_for_manual_mapper(cpu_id, PageMapper::new(TableKind::Kernel, PhysicalAddress::new(bsp_table), FRAME_ALLOCATOR)); paging::init_ap(cpu_id, &mut mapper) }; diff --git a/src/context/arch/x86_64.rs b/src/context/arch/x86_64.rs index 97d14a94..9b3f366c 100644 --- a/src/context/arch/x86_64.rs +++ b/src/context/arch/x86_64.rs @@ -3,7 +3,7 @@ use core::sync::atomic::AtomicBool; use alloc::sync::Arc; -use crate::paging::{RmmA, RmmArch}; +use crate::paging::{RmmA, RmmArch, TableKind}; use crate::syscall::FloatRegisters; use memoffset::offset_of; @@ -175,7 +175,7 @@ pub unsafe fn switch_to(prev: &mut super::Context, next: &mut super::Context) { next_space.read().table.utable.make_current(); } None => { - RmmA::set_table(empty_cr3()); + RmmA::set_table(TableKind::User, empty_cr3()); } } switch_to_inner(&mut prev.arch, &mut next.arch) diff --git a/src/debugger.rs b/src/debugger.rs index 8309ee6e..c141ffa7 100644 --- a/src/debugger.rs +++ b/src/debugger.rs @@ -1,4 +1,4 @@ -use crate::paging::{RmmA, RmmArch}; +use crate::paging::{RmmA, RmmArch, TableKind}; #[cfg(not(target_arch = "x86_64"))] pub unsafe fn debugger(target_id: Option<crate::context::ContextId>) { @@ -12,7 +12,7 @@ pub unsafe fn debugger(target_id: Option<crate::context::ContextId>) { println!("DEBUGGER START"); println!(); - let old_table = RmmA::table(); + let old_table = RmmA::table(TableKind::User); for (id, context_lock) in crate::context::contexts().iter() { if target_id.map_or(false, |target_id| *id != target_id) { continue; } @@ -21,7 +21,7 @@ pub unsafe fn debugger(target_id: Option<crate::context::ContextId>) { // Switch to context page table to ensure syscall debug and stack dump will work if let Some(ref space) = context.addr_space { - RmmA::set_table(space.read().table.utable.table().phys()); + RmmA::set_table(TableKind::User, space.read().table.utable.table().phys()); check_consistency(&mut space.write()); } @@ -71,7 +71,7 @@ pub unsafe fn debugger(target_id: Option<crate::context::ContextId>) { } // Switch to original page table - RmmA::set_table(old_table); + RmmA::set_table(TableKind::User, old_table); println!(); } diff --git a/src/syscall/mod.rs b/src/syscall/mod.rs index 57dde0e7..e36bfd4f 100644 --- a/src/syscall/mod.rs +++ b/src/syscall/mod.rs @@ -170,12 +170,12 @@ pub fn syscall(a: usize, b: usize, c: usize, d: usize, e: usize, f: usize, stack } } - /*let debug = { + let debug = { let contexts = crate::context::contexts(); if let Some(context_lock) = contexts.current() { let context = context_lock.read(); let name = context.name.read(); - if name.contains("redoxfs") { + if name.contains("bootstrap") { if a == SYS_CLOCK_GETTIME || a == SYS_YIELD { false } else if (a == SYS_WRITE || a == SYS_FSYNC) && (b == 1 || b == 2) { @@ -199,7 +199,7 @@ pub fn syscall(a: usize, b: usize, c: usize, d: usize, e: usize, f: usize, stack } println!("{}", debug::format_call(a, b, c, d, e, f)); - }*/ + } // The next lines set the current syscall in the context struct, then once the inner() function // completes, we set the current syscall to none. @@ -224,7 +224,7 @@ pub fn syscall(a: usize, b: usize, c: usize, d: usize, e: usize, f: usize, stack } } - /*if debug { + if debug { let contexts = crate::context::contexts(); if let Some(context_lock) = contexts.current() { let context = context_lock.read(); @@ -241,7 +241,7 @@ pub fn syscall(a: usize, b: usize, c: usize, d: usize, e: usize, f: usize, stack println!("Err({} ({:#X}))", err, err.errno); } } - }*/ + } // errormux turns Result<usize> into -errno Error::mux(result) -- GitLab