Skip to content
This repository was archived by the owner on Jul 17, 2025. It is now read-only.

Commit 9e703ea

Browse files
committed
WIP do not merge -- bunch of debugging.
1 parent 3c47974 commit 9e703ea

File tree

6 files changed

+43
-21
lines changed

6 files changed

+43
-21
lines changed

Cargo.lock

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bootloader/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ pub extern "C" fn uefi_start(handle: uefi::Handle, mut st: SystemTable<Boot>) ->
387387

388388
// On big machines with the init stack tends to put big structures
389389
// on the stack so we reserve a fair amount of space:
390-
let stack_pages: usize = 768;
390+
let stack_pages: usize = 1024;
391391
let stack_region: PAddr = allocate_pages(&st, stack_pages, MemoryType(KERNEL_STACK));
392392
let stack_protector: PAddr = stack_region;
393393
let stack_base: PAddr = stack_region + BASE_PAGE_SIZE;

kernel/src/arch/x86_64/irq.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ pub unsafe fn setup_early_idt() {
272272
///
273273
/// # See also
274274
/// Described in Intel SDM 3a, Figure 6-8. IA-32e Mode Stack Usage After Privilege Level Change
275-
#[repr(C)]
275+
#[repr(C, packed)]
276276
pub struct ExceptionArguments {
277277
_reserved: u64,
278278
vector: u64,
@@ -286,10 +286,17 @@ pub struct ExceptionArguments {
286286

287287
impl fmt::Debug for ExceptionArguments {
288288
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
289+
let vector = self.vector;
290+
let exception = self.exception;
291+
let rip = self.rip;
292+
let cs = self.cs;
293+
let rflags = self.rflags;
294+
let rsp = self.rsp;
295+
let ss = self.ss;
289296
write!(
290297
f,
291298
"ExceptionArguments {{ vec = 0x{:x} exception = 0x{:x} rip = 0x{:x}, cs = 0x{:x} rflags = 0x{:x} rsp = 0x{:x} ss = 0x{:x} }}",
292-
self.vector, self.exception, self.rip, self.cs, self.rflags, self.rsp, self.ss
299+
vector, exception, rip, cs, rflags, rsp, ss
293300
)
294301
}
295302
}
@@ -304,7 +311,8 @@ unsafe fn unhandled_irq(a: &ExceptionArguments) {
304311
let desc = &EXCEPTIONS[a.vector as usize];
305312
sprintln!(" {}", desc);
306313
} else {
307-
sprintln!(" dev vector {}", a.vector);
314+
let vector = a.vector;
315+
sprintln!(" dev vector {}", vector);
308316
}
309317
sprintln!("{:?}", a);
310318
backtrace();
@@ -374,7 +382,8 @@ unsafe fn pf_handler(a: &ExceptionArguments) {
374382
// Print where the fault happend in the address-space:
375383
let faulting_address = x86::controlregs::cr2();
376384
sprint!("Faulting address: {:#x}", faulting_address);
377-
sprint!(" Instruction Pointer: {:#x}", a.rip);
385+
let rip = a.rip;
386+
sprint!(" Instruction Pointer: {:#x}", rip);
378387

379388
/*
380389
if !err.contains(PageFaultError::US) {
@@ -390,7 +399,7 @@ unsafe fn pf_handler(a: &ExceptionArguments) {
390399
*/
391400

392401
// Print the RIP that triggered the fault:
393-
sprint!("Instruction Pointer: {:#x}", a.rip);
402+
sprint!("Instruction Pointer: {:#x}", rip);
394403
if !err.contains(PageFaultError::US) {
395404
crate::KERNEL_ARGS
396405
.get()
@@ -596,7 +605,8 @@ unsafe fn gp_handler(a: &ExceptionArguments) {
596605

597606
// Print the RIP that triggered the fault:
598607
//use crate::arch::kcb;
599-
sprint!("Instruction Pointer: {:#x}", a.rip);
608+
let rip = a.rip;
609+
sprint!("Instruction Pointer: {:#x}", rip);
600610
/*kcb::try_get_kcb::<Arch86Kcb>().map(|k| {
601611
sprintln!(
602612
" (in ELF: {:#x})",

kernel/src/arch/x86_64/mod.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ fn _start(argc: isize, _argv: *const *const u8) -> isize {
294294
let mut dyn_mem = PerCoreMemory::new(emanager, 0);
295295
// Make `dyn_mem` a static reference:
296296
let static_dyn_mem =
297-
// Safety:
297+
// Safety:
298298
// - The initial stack of the core will never get deallocated (hence
299299
// 'static is fine)
300300
// - TODO(safety): aliasing rules is broken here (we have mut dyn_mem
@@ -305,7 +305,7 @@ fn _start(argc: isize, _argv: *const *const u8) -> isize {
305305
let mut arch = kcb::Arch86Kcb::new(static_dyn_mem);
306306
// Make `arch` a static reference:
307307
let static_kcb =
308-
// Safety:
308+
// Safety:
309309
// - The initial stack of the core will never get deallocated (hence
310310
// 'static is fine)
311311
// - TODO(safety): aliasing rules is broken here (we have mut dyn_mem
@@ -363,7 +363,7 @@ fn _start(argc: isize, _argv: *const *const u8) -> isize {
363363
// `global_memory` to every core) that's fine since it is allocated on our
364364
// BSP init stack (which isn't reclaimed):
365365
let global_memory_static =
366-
// Safety:
366+
// Safety:
367367
// -'static: Lives on init stack (not deallocated)
368368
// - No mut alias to it
369369
unsafe { core::mem::transmute::<&GlobalMemory, &'static GlobalMemory>(&global_memory) };
@@ -384,13 +384,15 @@ fn _start(argc: isize, _argv: *const *const u8) -> isize {
384384
crate::nr::NR_REPLICA.call_once(|| (bsp_replica.clone(), local_ridx));
385385

386386
// Starting to initialize file-system
387+
info!("before alloc logs");
387388
let fs_logs = crate::fs::cnrfs::allocate_logs();
389+
info!("after alloc logs {}", fs_logs.len());
390+
let fs_logs_cloned = fs_logs
391+
.try_clone()
392+
.expect("Not enough memory to initialize system");
393+
info!("after fs logs cloned");
388394
// Construct the first replica
389-
let fs_replica = MlnrReplica::<MlnrKernelNode>::new(
390-
fs_logs
391-
.try_clone()
392-
.expect("Not enough memory to initialize system"),
393-
);
395+
let fs_replica = MlnrReplica::<MlnrKernelNode>::new(fs_logs_cloned);
394396
crate::fs::cnrfs::init_cnrfs_on_thread(fs_replica.clone());
395397

396398
// Intialize PCI

kernel/src/arch/x86_64/process.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,7 @@ impl elfloader::ElfLoader for Ring3Process {
960960
.expect("Refill didn't work");
961961

962962
let pcm = crate::arch::kcb::per_core_mem();
963+
info!("1");
963964

964965
// TODO(correctness): Will this work (we round-up and map large-pages?)
965966
// TODO(efficiency): What about wasted memory
@@ -991,20 +992,22 @@ impl elfloader::ElfLoader for Ring3Process {
991992
.allocate_large_page()
992993
.expect("We refilled so allocation should work.")
993994
};
995+
info!("2");
994996

995997
trace!(
996998
"process load vspace from {:#x} with {:?}",
997999
self.offset + page_base + i * LARGE_PAGE_SIZE,
9981000
frame
9991001
);
1000-
1002+
info!("3");
10011003
self.vspace
10021004
.map_frame(
10031005
self.offset + page_base + i * LARGE_PAGE_SIZE,
10041006
frame,
10051007
map_action,
10061008
)
10071009
.expect("Can't map ELF region");
1010+
info!("4");
10081011
}
10091012
}
10101013

kernel/src/arch/x86_64/vspace/mod.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use fallible_collections::btree::BTreeMap;
88
use lazy_static::lazy_static;
99
use spin::Mutex;
1010
use x86::current::paging::{PDFlags, PDPTFlags, PTFlags};
11+
use log::info;
1112

1213
mod debug;
1314
pub mod page_table; /* TODO(encapsulation): This should be a private module but we break encapsulation in a few places */
@@ -90,6 +91,7 @@ pub(crate) struct VSpace {
9091

9192
impl AddressSpace for VSpace {
9293
fn map_frame(&mut self, base: VAddr, frame: Frame, action: MapAction) -> Result<(), KError> {
94+
info!("map_frame 1");
9395
if frame.size() == 0 {
9496
return Err(KError::InvalidFrame);
9597
}
@@ -101,6 +103,7 @@ impl AddressSpace for VSpace {
101103
// virtual addr should be aligned to page-size
102104
return Err(KError::InvalidBase);
103105
}
106+
info!("map_frame 2");
104107

105108
let tomap_range = base.as_usize()..base.as_usize() + frame.size;
106109

@@ -111,11 +114,13 @@ impl AddressSpace for VSpace {
111114
.range((Unbounded, Excluded(VAddr::from(tomap_range.end))))
112115
.rev()
113116
{
117+
info!("map_frame 3");
114118
let existing_map_range = existing_mapping.vrange(existing_base);
115119
if existing_map_range.end <= tomap_range.start {
116120
// We reached the end of relevant mappings
117121
break;
118122
}
123+
info!("map_frame 4");
119124

120125
if existing_base == base
121126
&& existing_mapping.frame.base == frame.base
@@ -129,10 +134,13 @@ impl AddressSpace for VSpace {
129134
});
130135
}
131136
}
132-
137+
info!("map_frame 5");
133138
self.mappings
134139
.try_insert(base, MappingInfo::new(frame, action))?;
135-
self.page_table.map_frame(base, frame, action)
140+
info!("map_frame 6");
141+
let r = self.page_table.map_frame(base, frame, action);
142+
info!("map_frame 6");
143+
r
136144
}
137145

138146
fn map_memory_requirements(_base: VAddr, _frames: &[Frame]) -> usize {

0 commit comments

Comments
 (0)