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 13eab547..f07d9612 100644 --- a/blog/content/second-edition/posts/06-double-faults/index.md +++ b/blog/content/second-edition/posts/06-double-faults/index.md @@ -35,7 +35,7 @@ Let's provoke a double fault by triggering an exception for that we didn't defin pub extern "C" fn _start() -> ! { println!("Hello World{}", "!"); - blog_os::interrupts::init_idt(); + blog_os::init(); // trigger a page fault unsafe { @@ -162,7 +162,7 @@ Let's try it ourselves! We can easily provoke a kernel stack overflow by calling pub extern "C" fn _start() -> ! { println!("Hello World{}", "!"); - blog_os::interrupts::init_idt(); + blog_os::init(); fn stack_overflow() { stack_overflow(); // for each recursion, the return address is pushed @@ -298,7 +298,7 @@ We use `lazy_static` again, because Rust's const evaluator is not powerful enoug #### Loading the GDT -To load our GDT we create a new `gdt::init` function, that we call from our `_start` function: +To load our GDT we create a new `gdt::init` function, that we call from our `init` function: ```rust // in src/gdt.rs @@ -307,22 +307,15 @@ pub fn init() { GDT.load(); } -// in src/main.rs +// in src/lib.rs -#[cfg(not(test))] -#[no_mangle] -pub extern "C" fn _start() -> ! { - println!("Hello World{}", "!"); - - blog_os::gdt::init(); - blog_os::interrupts::init_idt(); - - […] +pub fn init() { + gdt::init(); + interrupts::init_idt(); } - ``` -Now our GDT is loaded, but we still see the boot loop on stack overflow. +Now our GDT is loaded (since the `_start` function calls `init`), but we still see the boot loop on stack overflow. ### The final Steps diff --git a/blog/content/second-edition/posts/07-hardware-interrupts/index.md b/blog/content/second-edition/posts/07-hardware-interrupts/index.md index 5e9ad6fd..e285a097 100644 --- a/blog/content/second-edition/posts/07-hardware-interrupts/index.md +++ b/blog/content/second-edition/posts/07-hardware-interrupts/index.md @@ -109,24 +109,15 @@ We're setting the offsets for the pics to the range 32–47 as we noted above. B [spin mutex lock]: https://docs.rs/spin/0.4.8/spin/struct.Mutex.html#method.lock -We can now initialize the 8259 PIC from our `_start` function: +We can now initialize the 8259 PIC in our `init` function: ```rust -// in src/main.rs +// in src/lib.rs -#[cfg(not(test))] -#[no_mangle] -pub extern "C" fn _start() -> ! { - use blog_os::interrupts::PICS; // new - - println!("Hello World{}", "!"); - - blog_os::gdt::init(); - blog_os::interrupts::init_idt(); - unsafe { PICS.lock().initialize() }; // new - - println!("It did not crash!"); - loop {} +pub fn init() { + gdt::init(); + interrupts::init_idt(); + unsafe { interrupts::PICS.lock().initialize() }; // new } ``` @@ -141,22 +132,13 @@ If all goes well we should continue to see the "It did not crash" message when e Until now nothing happened because interrupts are still disabled in the CPU configuration. This means that the CPU does not listen to the interrupt controller at all, so no interrupts can reach the CPU. Let's change that: ```rust -// in src/main.rs +// in src/lib.rs -#[cfg(not(test))] -#[no_mangle] -pub extern "C" fn _start() -> ! { - use blog_os::interrupts::PICS; - - println!("Hello World{}", "!"); - - blog_os::gdt::init(); - blog_os::interrupts::init_idt(); - unsafe { PICS.lock().initialize() }; +pub fn init() { + gdt::init(); + interrupts::init_idt(); + unsafe { interrupts::PICS.lock().initialize() }; x86_64::instructions::interrupts::enable(); // new - - println!("It did not crash!"); - 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 8aed2beb..5c2edc2c 100644 --- a/blog/content/second-edition/posts/08-paging-introduction/index.md +++ b/blog/content/second-edition/posts/08-paging-introduction/index.md @@ -305,16 +305,9 @@ Now we can try to access some memory outside our kernel: #[no_mangle] pub extern "C" fn _start() -> ! { - use blog_os::interrupts::PICS; - println!("Hello World{}", "!"); - // set up the IDT first, otherwise we would enter a boot loop instead of - // invoking our page fault handler - blog_os::gdt::init(); - blog_os::interrupts::init_idt(); - unsafe { PICS.lock().initialize() }; - x86_64::instructions::interrupts::enable(); + blog_os::init(); // new let ptr = 0xdeadbeaf as *mut u32; @@ -354,7 +347,9 @@ Let's try to take a look at the page tables that our kernel runs on: #[no_mangle] pub extern "C" fn _start() -> ! { - […] // initialize GDT, IDT, PICS + println!("Hello World{}", "!"); + + blog_os::init(); use x86_64::registers::control::Cr3;