diff --git a/kernel-rs/src/arch/x86/device/cpu.rs b/kernel-rs/src/arch/x86/device/cpu.rs index cf7e3fbb..83051d5d 100644 --- a/kernel-rs/src/arch/x86/device/cpu.rs +++ b/kernel-rs/src/arch/x86/device/cpu.rs @@ -28,7 +28,7 @@ pub fn cpu_info() -> Result { } if let Some(info) = cpuid.get_feature_info() { - print!("Features:"); + print!("CPU Features:"); if info.has_fpu() { print!(" fpu") }; if info.has_vme() { print!(", vme") }; if info.has_de() { print!(", de") }; diff --git a/kernel-rs/src/arch/x86/device/pic.rs b/kernel-rs/src/arch/x86/device/pic.rs index 48738772..c36e8ee8 100644 --- a/kernel-rs/src/arch/x86/device/pic.rs +++ b/kernel-rs/src/arch/x86/device/pic.rs @@ -36,13 +36,14 @@ pub unsafe fn init() { MASTER.data.write(master_mask); wait(); SLAVE.data.write(slave_mask); wait(); - println!("master={:#b}", MASTER.data.read()); - println!("slave ={:#b}", SLAVE.data.read()); + println!("master={:#x}", MASTER.data.read()); + println!("slave ={:#x}", SLAVE.data.read()); - unsafe { ::arch::x86::interrupt::irq::trigger(1); } + MASTER.mask_set(0); + MASTER.mask_clear(1); - println!("master={:#b}", MASTER.data.read()); - println!("slave ={:#b}", SLAVE.data.read()); + // asm!("sti"); + ::x86::instructions::interrupts::enable(); } pub struct Pic { diff --git a/kernel-rs/src/arch/x86/interrupt/exception.rs b/kernel-rs/src/arch/x86/interrupt/exception.rs index 489c4011..e6baaff8 100644 --- a/kernel-rs/src/arch/x86/interrupt/exception.rs +++ b/kernel-rs/src/arch/x86/interrupt/exception.rs @@ -1,24 +1,59 @@ // https://wiki.osdev.org/Exceptions +macro_rules! exception { + ($name:ident, $func:block) => { + pub extern "x86-interrupt" fn $name(stack_frame: &mut ExceptionStackFrame) + { + println!("Exception: {}", stringify!($name)); + println!("{:#?}", stack_frame); + flush!(); + + #[allow(unused_variables)] + fn inner(stack: &mut ExceptionStackFrame) { + $func + } + inner(stack_frame); + } + } +} + +macro_rules! exception_err { + ($name:ident, $func:block) => { + pub extern "x86-interrupt" fn $name( + stack_frame: &mut ExceptionStackFrame, _error_code: u32) + { + println!("Exception: {}", stringify!($name)); + println!("{:#?}", stack_frame); + flush!(); + + #[allow(unused_variables)] + fn inner(stack: &mut ExceptionStackFrame) { + $func + } + inner(stack_frame); + } + } +} + use x86::structures::idt::*; -interrupt!(divide_by_zero, {}); -interrupt!(debug, {}); -interrupt!(non_maskable, {}); -interrupt!(breakpoint, { +exception!(divide_by_zero, {}); +exception!(debug, {}); +exception!(non_maskable, {}); +exception!(breakpoint, { println!("testing here dont mind me"); flush!(); }); -interrupt!(overflow, {}); -interrupt!(bound_range, {}); -interrupt!(invalid_opcode, {}); -interrupt!(device_not_available, {}); -interrupt_err!(double_fault, {}); -interrupt!(coprocessor_segment_overrun, {}); -interrupt_err!(invalid_tss, {}); -interrupt_err!(segment_not_present, {}); -interrupt_err!(stack_segment, {}); -interrupt_err!(general_protection, {}); +exception!(overflow, {}); +exception!(bound_range, {}); +exception!(invalid_opcode, {}); +exception!(device_not_available, {}); +exception_err!(double_fault, {}); +exception!(coprocessor_segment_overrun, {}); +exception_err!(invalid_tss, {}); +exception_err!(segment_not_present, {}); +exception_err!(stack_segment, {}); +exception_err!(general_protection, {}); pub extern "x86-interrupt" fn page_fault( stack_frame: &mut ExceptionStackFrame, code: PageFaultErrorCode) @@ -29,9 +64,9 @@ pub extern "x86-interrupt" fn page_fault( flush!(); } -interrupt!(x87_fpu, {}); -interrupt_err!(alignment_check, {}); -interrupt!(machine_check, {}); -interrupt!(simd, {}); -interrupt!(virtualization, {}); -interrupt_err!(security, {}); +exception!(x87_fpu, {}); +exception_err!(alignment_check, {}); +exception!(machine_check, {}); +exception!(simd, {}); +exception!(virtualization, {}); +exception_err!(security, {}); diff --git a/kernel-rs/src/arch/x86/interrupt/irq.rs b/kernel-rs/src/arch/x86/interrupt/irq.rs index cb94f379..46d2d6e2 100644 --- a/kernel-rs/src/arch/x86/interrupt/irq.rs +++ b/kernel-rs/src/arch/x86/interrupt/irq.rs @@ -1,6 +1,22 @@ use x86::structures::idt::*; use arch::x86::device::pic; +#[macro_export] +macro_rules! interrupt { + ($i:expr, $name:ident, $func:block) => { + pub extern "x86-interrupt" fn $name(stack_frame: &mut ExceptionStackFrame) + { + unsafe { trigger(1); } + #[allow(unused_variables)] + fn inner(stack: &mut ExceptionStackFrame) { + $func + } + inner(stack_frame); + unsafe { acknowledge(1); } + } + } +} + pub unsafe fn trigger(irq: u8) { if irq < 16 { if irq >= 8 { @@ -18,34 +34,31 @@ pub unsafe fn acknowledge(irq: usize) { if irq < 16 { if irq >= 8 { pic::SLAVE.mask_clear(irq as u8 - 8); + pic::SLAVE.ack(); } else { pic::MASTER.mask_clear(irq as u8); + pic::MASTER.ack(); } } } -interrupt!(pit, {}); +interrupt!(0, pit, {}); -interrupt!(keyboard, { - unsafe { trigger(1); } - - println!("IT WOOOOOOOOOORKS WOUHOU!!!!!!"); - flush!(); - - unsafe { acknowledge(1); } +interrupt!(1, keyboard, { + ::keyboard::kbd_callback(); }); -interrupt!(cascade, {}); -interrupt!(com2, {}); -interrupt!(com1, {}); -interrupt!(lpt2, {}); -interrupt!(floppy, {}); -interrupt!(lpt1, {}); -interrupt!(rtc, {}); -interrupt!(pci1, {}); -interrupt!(pci2, {}); -interrupt!(pci3, {}); -interrupt!(mouse, {}); -interrupt!(fpu, {}); -interrupt!(ata1, {}); -interrupt!(ata2, {}); +interrupt!(2, cascade, {}); +interrupt!(3, com2, {}); +interrupt!(4, com1, {}); +interrupt!(5, lpt2, {}); +interrupt!(6, floppy, {}); +interrupt!(7, lpt1, {}); +interrupt!(8, rtc, {}); +interrupt!(9, pci1, {}); +interrupt!(10, pci2, {}); +interrupt!(11, pci3, {}); +interrupt!(12, mouse, {}); +interrupt!(13, fpu, {}); +interrupt!(14, ata1, {}); +interrupt!(15, ata2, {}); diff --git a/kernel-rs/src/arch/x86/macros.rs b/kernel-rs/src/arch/x86/macros.rs deleted file mode 100644 index 94b41202..00000000 --- a/kernel-rs/src/arch/x86/macros.rs +++ /dev/null @@ -1,36 +0,0 @@ -#[macro_export] -macro_rules! interrupt { - ($name:ident, $func:block) => { - pub extern "x86-interrupt" fn $name(stack_frame: &mut ExceptionStackFrame) - { - println!("Exception: {}", stringify!($name)); - println!("{:#?}", stack_frame); - flush!(); - - #[allow(unused_variables)] - fn inner(stack: &mut ExceptionStackFrame) { - $func - } - inner(stack_frame); - } - } -} - -#[macro_export] -macro_rules! interrupt_err { - ($name:ident, $func:block) => { - pub extern "x86-interrupt" fn $name( - stack_frame: &mut ExceptionStackFrame, _error_code: u32) - { - println!("Exception: {}", stringify!($name)); - println!("{:#?}", stack_frame); - flush!(); - - #[allow(unused_variables)] - fn inner(stack: &mut ExceptionStackFrame) { - $func - } - inner(stack_frame); - } - } -} diff --git a/kernel-rs/src/arch/x86/mod.rs b/kernel-rs/src/arch/x86/mod.rs index 1cb4f2c7..45f657b7 100644 --- a/kernel-rs/src/arch/x86/mod.rs +++ b/kernel-rs/src/arch/x86/mod.rs @@ -1,15 +1,14 @@ extern crate x86; #[macro_use] -pub mod macros; pub mod paging; pub mod interrupt; pub mod device; + pub mod idt; use multiboot2; use acpi; -use raw_cpuid::CpuId; #[no_mangle] pub unsafe extern fn x86_rust_start(multiboot_info_addr: usize) { diff --git a/kernel-rs/src/lib.rs b/kernel-rs/src/lib.rs index 4a63e890..1acdefc8 100644 --- a/kernel-rs/src/lib.rs +++ b/kernel-rs/src/lib.rs @@ -14,7 +14,8 @@ #![feature(abi_x86_interrupt)] extern crate rlibc; -#[macro_use] extern crate alloc; +// #[macro_use] +extern crate alloc; #[macro_use] extern crate lazy_static; extern crate spin; extern crate multiboot2; @@ -45,9 +46,7 @@ pub mod arch; /// kernel entry point. arch module is responsible for calling this pub fn kmain() -> ! { - // x86::instructions::interrupts::disable(); - x86::instructions::interrupts::int3(); - // x86::instructions::interrupts::enable(); + // x86::instructions::interrupts::int3(); // fn stack_overflow() { stack_overflow(); } // stack_overflow();