From 7b6d1d70d2840ee4abed24710e2a8cb63a0c0bb0 Mon Sep 17 00:00:00 2001 From: mrgian Date: Thu, 13 Jul 2023 10:44:15 +0200 Subject: [PATCH] Add comments --- bootloader/src/main.rs | 1 + bootloader/src/print.rs | 2 + bootloader/src/splash.rs | 3 +- kernel/src/main.rs | 74 ++++++++++----------------------- kernel/src/multitasking/task.rs | 7 +++- 5 files changed, 32 insertions(+), 55 deletions(-) diff --git a/bootloader/src/main.rs b/bootloader/src/main.rs index a47297d..ff39b3a 100644 --- a/bootloader/src/main.rs +++ b/bootloader/src/main.rs @@ -141,6 +141,7 @@ fn unreal_mode() { } } +#[allow(dead_code)] fn wait_for_key() { unsafe { asm!("int 0x16", in("ah") 0x00 as u8); diff --git a/bootloader/src/print.rs b/bootloader/src/print.rs index 2f098da..d2a070a 100644 --- a/bootloader/src/print.rs +++ b/bootloader/src/print.rs @@ -45,6 +45,7 @@ impl Printer { } //set bios video mode to clear the screen + #[allow(dead_code)] pub fn clear(&self) { unsafe { asm!( @@ -83,6 +84,7 @@ pub fn _print(args: fmt::Arguments) { } } +#[allow(dead_code)] pub fn _clear() { unsafe { PRINTER.clear(); diff --git a/bootloader/src/splash.rs b/bootloader/src/splash.rs index 9ba60bb..9729426 100644 --- a/bootloader/src/splash.rs +++ b/bootloader/src/splash.rs @@ -23,7 +23,8 @@ pub const SPLASH: &'static str = ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▀▀▀▀▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ Press any key to start..."; - + +#[allow(dead_code)] pub fn splash() { for c in SPLASH.chars() { match c { diff --git a/kernel/src/main.rs b/kernel/src/main.rs index d396682..5fd7090 100644 --- a/kernel/src/main.rs +++ b/kernel/src/main.rs @@ -21,7 +21,6 @@ use filesystem::fat::FAT; use interrupts::idt::IDT; use memory::allocator::Allocator; use memory::paging::PAGING; -use memory::paging::TABLES; use shell::shell::SHELL; use syscalls::print::PRINTER; @@ -45,94 +44,63 @@ const VERSION: &str = env!("CARGO_PKG_VERSION"); #[no_mangle] #[link_section = ".start"] pub extern "C" fn _start() -> ! { - //setup stack unsafe { + //setup stack asm!("mov esp, {}", in(reg) STACK_START); - } - //setup paging - unsafe { + //setup paging PAGING.identity(); - PAGING.enable(); - } - unsafe { + //bochs magic breakpoint asm!("xchg bx, bx"); - } - - unsafe { - //init idt - IDT.init(); - - //add CPU exceptions to idt - IDT.add_exceptions(); - //add timer interrupt to idt + //setup idt + IDT.init(); //init idt + IDT.add_exceptions(); //add CPU exceptions to idt IDT.add( interrupts::timer::TIMER_INT as usize, interrupts::timer::timer as u32, - ); - - //add system call handler interrupt + ); //add timer interrupt to idt IDT.add( syscalls::handler::SYSCALL_INT as usize, syscalls::handler::syscall as u32, - ); - - //add keyboard interrupt to idt + ); //add system call handler interrupt IDT.add( drivers::keyboard::KEYBOARD_INT as usize, drivers::keyboard::keyboard as u32, - ); + ); //add keyboard interrupt to idt + IDT.load(); //load idt - //load idt - IDT.load(); - } - - //init programmable interrupt controllers - PICS.init(); + //init programmable interrupt controllers + PICS.init(); - unsafe { - //check if ata drive is working + //enable ata disk if present DISK.check(); - } - - print_info(); - unsafe { + //init filesystem if DISK.enabled { - //init filesystem FAT.load_header(); FAT.load_entries(); FAT.load_table(); } - } - unsafe { + //print name, version and copyright + print_info(); + //init felix shell SHELL.init(); - } - unsafe { + //init multitasking TASK_MANAGER.init(); - } - //bochs magic breakpoint - unsafe { + //bochs magic breakpoint asm!("xchg bx, bx"); - } - //enable hardware interrupts - unsafe { + //enable hardware interrupts asm!("sti"); - } - //halt cpu while waiting for interrupts - loop { - unsafe { - asm!("hlt"); - } + loop {} } } diff --git a/kernel/src/multitasking/task.rs b/kernel/src/multitasking/task.rs index 97b9d11..7a264a4 100644 --- a/kernel/src/multitasking/task.rs +++ b/kernel/src/multitasking/task.rs @@ -1,4 +1,5 @@ //TASK MANAGER +use core::arch::asm; const STACK_SIZE: usize = 4096; const MAX_TASKS: i8 = 32; @@ -191,7 +192,11 @@ impl TaskManager { } fn idle() { - loop {} + loop { + unsafe { + asm!("hlt"); + } + } } //EXAMPLE TASKS