From 0509307d8fb3e066bd554a3d26823945d9e7e6fe Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Fri, 26 Apr 2019 12:20:29 +0200 Subject: [PATCH] Mention test_main and blog_os::init in later posts --- .../posts/05-cpu-exceptions/index.md | 4 +++ .../posts/06-double-faults/index.md | 7 +++-- .../posts/08-paging-introduction/index.md | 7 +++-- .../posts/09-paging-implementation/index.md | 30 ++++++++++--------- 4 files changed, 30 insertions(+), 18 deletions(-) diff --git a/blog/content/second-edition/posts/05-cpu-exceptions/index.md b/blog/content/second-edition/posts/05-cpu-exceptions/index.md index 9ab22c7b..e62a499f 100644 --- a/blog/content/second-edition/posts/05-cpu-exceptions/index.md +++ b/blog/content/second-edition/posts/05-cpu-exceptions/index.md @@ -399,6 +399,10 @@ pub extern "C" fn _start() -> ! { // invoke a breakpoint exception x86_64::instructions::interrupts::int3(); // new + // as before + #[cfg(test)] + test_main(); + println!("It did not crash!"); loop {} } diff --git a/blog/content/second-edition/posts/06-double-faults/index.md b/blog/content/second-edition/posts/06-double-faults/index.md index c9d3ccdc..797ceab5 100644 --- a/blog/content/second-edition/posts/06-double-faults/index.md +++ b/blog/content/second-edition/posts/06-double-faults/index.md @@ -42,6 +42,10 @@ pub extern "C" fn _start() -> ! { *(0xdeadbeef as *mut u64) = 42; }; + // as before + #[cfg(test)] + test_main(); + println!("It did not crash!"); loop {} } @@ -171,8 +175,7 @@ pub extern "C" fn _start() -> ! { // trigger a stack overflow stack_overflow(); - println!("It did not crash!"); - loop {} + […] // test_main(), println(…), and loop {} } ``` diff --git a/blog/content/second-edition/posts/08-paging-introduction/index.md b/blog/content/second-edition/posts/08-paging-introduction/index.md index 6f5b0315..60753e2c 100644 --- a/blog/content/second-edition/posts/08-paging-introduction/index.md +++ b/blog/content/second-edition/posts/08-paging-introduction/index.md @@ -312,6 +312,10 @@ pub extern "C" fn _start() -> ! { let ptr = 0xdeadbeaf as *mut u32; unsafe { *ptr = 42; } + // as before + #[cfg(test)] + test_main(); + println!("It did not crash!"); blog_os::hlt_loop(); } @@ -355,8 +359,7 @@ pub extern "C" fn _start() -> ! { let (level_4_page_table, _) = Cr3::read(); println!("Level 4 page table at: {:?}", level_4_page_table.start_address()); - println!("It did not crash!"); - blog_os::hlt_loop(); + […] // test_main(), println(…), and hlt_loop() } ``` diff --git a/blog/content/second-edition/posts/09-paging-implementation/index.md b/blog/content/second-edition/posts/09-paging-implementation/index.md index 6305f7b4..9c7ab521 100644 --- a/blog/content/second-edition/posts/09-paging-implementation/index.md +++ b/blog/content/second-edition/posts/09-paging-implementation/index.md @@ -436,10 +436,11 @@ We can now use this function to print the entries of the level 4 table: // in src/main.rs fn kernel_main(boot_info: &'static BootInfo) -> ! { - […] // initialize GDT, IDT, PICS - use blog_os::memory::active_level_4_table; + println!("Hello World{}", "!"); + blog_os::init(); + let l4_table = unsafe { active_level_4_table(boot_info.physical_memory_offset) }; @@ -449,6 +450,10 @@ fn kernel_main(boot_info: &'static BootInfo) -> ! { } } + // as before + #[cfg(test)] + test_main(); + println!("It did not crash!"); blog_os::hlt_loop(); } @@ -576,11 +581,11 @@ Let's test our translation function by translating some addresses: // in src/main.rs fn kernel_main(boot_info: &'static BootInfo) -> ! { - […] // initialize GDT, IDT, PICS - use blog_os::memory::translate_addr; use x86_64::VirtAddr; + […] // hello world and blog_os::init + let addresses = [ // the identity-mapped vga buffer page 0xb8000, @@ -600,8 +605,7 @@ fn kernel_main(boot_info: &'static BootInfo) -> ! { println!("{:?} -> {:?}", virt, phys); } - println!("It did not crash!"); - blog_os::hlt_loop(); + […] // test_main(), "it did not crash" printing, and hlt_loop() } ``` @@ -676,12 +680,12 @@ To use the `MapperAllSizes::translate_addr` method instead of our own `memory::t // in src/main.rs fn kernel_main(boot_info: &'static BootInfo) -> ! { - […] // initialize GDT, IDT, PICS - // new: different imports use blog_os::memory; use x86_64::{structures::paging::MapperAllSizes, VirtAddr}; + […] // hello world and blog_os::init + // new: initialize a mapper let mapper = unsafe { memory::init(boot_info.physical_memory_offset) }; @@ -694,8 +698,7 @@ fn kernel_main(boot_info: &'static BootInfo) -> ! { println!("{:?} -> {:?}", virt, phys); } - println!("It did not crash!"); - blog_os::hlt_loop(); + […] // test_main(), "it did not crash" printing, and hlt_loop() } ``` @@ -787,11 +790,11 @@ To test our mapping function, we first map page `0x1000` and then try to write t // in src/main.rs fn kernel_main(boot_info: &'static BootInfo) -> ! { - […] // initialize GDT, IDT, PICS - use blog_os::memory; use x86_64::{structures::paging::Page, VirtAddr}; + […] // hello world and blog_os::init + let mut mapper = unsafe { memory::init(boot_info.physical_memory_offset) }; let mut frame_allocator = memory::EmptyFrameAllocator; @@ -803,8 +806,7 @@ fn kernel_main(boot_info: &'static BootInfo) -> ! { let page_ptr: *mut u64 = page.start_address().as_mut_ptr(); unsafe { page_ptr.offset(400).write_volatile(0x_f021_f077_f065_f04e)}; - println!("It did not crash!"); - blog_os::hlt_loop(); + […] // test_main(), "it did not crash" printing, and hlt_loop() } ```