Skip to content

Commit

Permalink
Update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
mrgian committed Mar 30, 2023
1 parent af06203 commit b69dd4c
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 17 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)).
53 changes: 45 additions & 8 deletions kernel/src/idt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
Expand All @@ -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)
);
}
}
}
10 changes: 1 addition & 9 deletions kernel/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand All @@ -55,5 +49,3 @@ fn panic(info: &PanicInfo) -> ! {

loop {}
}


0 comments on commit b69dd4c

Please sign in to comment.