diff --git a/README.md b/README.md index 1c426a9..cb166a0 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,22 @@ You can run it in QEMU using this command: `qemu-system-i386 -drive id=disk,file Or you can run it on a real x86 computer by copying the disk image to a USB drive using this command: `sudo dd if=build/disk.img of=/dev/sdX status=progress` and then booting from USB. +## Features + +### Bootloader + - boots (you don't say!) + - BIOS compatible (also works on UEFI with CSM enabled) + - loads a basic Global Descriptor Table + - switches to Unreal Mode (to use 32bit addresses in 16bit Real Mode) + - copies kernel from disk to protected memory + - switches to 32bit Protected Mode + - jumps to kernel + + ### Kernel + - prints formatted text to screen by writing to VGA text buffer + - loads a basic Interrupt Descriptor Table + - has a basic handler for CPU exceptions + ## Progress - *22/10/22* - Project start - *27/01/23* - Bootloader can print to screen @@ -60,6 +76,7 @@ Or you can run it on a real x86 computer by copying the disk image to a USB driv - *01/03/23* - Rewritten kernel loading code in Rust - *08/03/23* - Implemented println macro - *20/03/23* - Switch to 32bit protected mode +- *30/03/23* - Basic CPU exception handler ## Credits This project is entirely developed by **Gianmatteo Palmieri** ([mrgian](https://github.com/mrgian)). diff --git a/kernel/src/idt.rs b/kernel/src/idt.rs index 789a0cd..a830965 100644 --- a/kernel/src/idt.rs +++ b/kernel/src/idt.rs @@ -98,7 +98,7 @@ impl IdtEntry { //handle excpetion based on interrupt number #[no_mangle] -pub extern "C" fn exception_handler(int: u32) { +pub extern "C" fn exception_handler(int: u32, eip: u32, cs: u32, eflags: u32) { match int { 0x00 => { println!("DIVISION ERROR!"); @@ -122,46 +122,83 @@ pub extern "C" fn exception_handler(int: u32) { println!("EXCEPTION!"); } } + println!("EIP: {:X}, CS: {:X}, EFLAGS: {:b}", eip, cs, eflags); } #[naked] pub extern "C" fn div_error() { unsafe { - asm!("push 0x00", "call exception_handler","add esp, 4","iretd", options(noreturn)); + asm!( + "push 0x00", + "call exception_handler", + "add esp, 4", + "iretd", + options(noreturn) + ); } } #[naked] pub extern "C" fn invalid_opcode() { unsafe { - asm!("push 0x06", "call exception_handler", "add esp, 4","iretd", options(noreturn)); + asm!( + "push 0x06", + "call exception_handler", + "add esp, 4", + "iretd", + options(noreturn) + ); } } #[naked] pub extern "C" fn double_fault() { unsafe { - asm!("push 0x08", "call exception_handler", options(noreturn)); + asm!( + "push 0x08", + "call exception_handler", + "add esp, 4", + "iretd", + options(noreturn) + ); } } #[naked] pub extern "C" fn general_protection_fault() { unsafe { - asm!("push 0x0d", "call exception_handler", options(noreturn)); + asm!( + "push 0x0d", + "call exception_handler", + "add esp, 4", + "iretd", + options(noreturn) + ); } } #[naked] pub extern "C" fn page_fault() { unsafe { - asm!("push 0x0e", "call exception_handler", options(noreturn)); + asm!( + "push 0x0e", + "call exception_handler", + "add esp, 4", + "iretd", + options(noreturn) + ); } } #[naked] pub extern "C" fn generic_handler() { unsafe { - asm!("push 0xff", "call exception_handler", options(noreturn)); + asm!( + "push 0xff", + "call exception_handler", + "add esp, 4", + "iretd", + options(noreturn) + ); } -} \ No newline at end of file +} diff --git a/kernel/src/main.rs b/kernel/src/main.rs index c61151e..4908397 100644 --- a/kernel/src/main.rs +++ b/kernel/src/main.rs @@ -34,16 +34,10 @@ pub extern "C" fn _start() -> ! { idt.add_exceptions(); idt.load(); - //generates invalid opcode exception unsafe { - asm!("int 0x0"); + asm!("int 0xff"); } - //generates division error exception - /*unsafe { - asm!("div bl", in("al") 0x00 as u8, in("bl") 0x00 as u8); - }*/ - println!("Not crashed!"); loop {} @@ -55,5 +49,3 @@ fn panic(info: &PanicInfo) -> ! { loop {} } - -