From b7855ae56cca9ae2f475faf9c49a50abfebf00e8 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Thu, 5 Apr 2018 19:04:05 +0200 Subject: [PATCH] @gz merged rust-cpuid PR so i can get rid of my fork --- kernel-rs/.gitmodules | 3 --- kernel-rs/Cargo.toml | 8 +++++--- kernel-rs/rust-cpuid | 1 - kernel-rs/src/arch/mod.rs | 2 ++ kernel-rs/src/arch/x86/interrupt/exception.rs | 16 +++++++++++----- kernel-rs/src/arch/x86/mod.rs | 1 + kernel-rs/src/console.rs | 15 ++++++++------- kernel-rs/src/keyboard.rs | 5 ----- kernel-rs/src/lib.rs | 10 ++++++---- 9 files changed, 33 insertions(+), 28 deletions(-) delete mode 160000 kernel-rs/rust-cpuid diff --git a/kernel-rs/.gitmodules b/kernel-rs/.gitmodules index 782f58ec..820f6043 100644 --- a/kernel-rs/.gitmodules +++ b/kernel-rs/.gitmodules @@ -4,6 +4,3 @@ [submodule "x86"] path = x86 url = https://github.com/jzck/x86.git -[submodule "rust-cpuid"] - path = rust-cpuid - url = https://github.com/jzck/rust-cpuid diff --git a/kernel-rs/Cargo.toml b/kernel-rs/Cargo.toml index 1c8920b7..217b03ac 100644 --- a/kernel-rs/Cargo.toml +++ b/kernel-rs/Cargo.toml @@ -13,10 +13,12 @@ spin = "0.4" slab_allocator = "0.3.1" multiboot2 = { path = "multiboot2-elf64" } # added rsdp tag x86 = { path = "x86" } # forked for IA32 -raw-cpuid = { path = "rust-cpuid" } # forked for IA32 + +[dependencies.raw-cpuid] +# need to use github/master because of features not yet on crates.io +git = "https://github.com/gz/rust-cpuid" +features = ["nightly"] [dependencies.lazy_static] version = "1.0.0" features = ["spin_no_std"] - - diff --git a/kernel-rs/rust-cpuid b/kernel-rs/rust-cpuid deleted file mode 160000 index 07299b93..00000000 --- a/kernel-rs/rust-cpuid +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 07299b93df57fcee2b6aec61502a5135b99967f8 diff --git a/kernel-rs/src/arch/mod.rs b/kernel-rs/src/arch/mod.rs index aebe1682..06b8ef64 100644 --- a/kernel-rs/src/arch/mod.rs +++ b/kernel-rs/src/arch/mod.rs @@ -1 +1,3 @@ +// we only support a single architecture at the moment +// more specifically IA-32 (aka i386) but we name it x86 here. pub mod x86; diff --git a/kernel-rs/src/arch/x86/interrupt/exception.rs b/kernel-rs/src/arch/x86/interrupt/exception.rs index e6baaff8..9a75ef24 100644 --- a/kernel-rs/src/arch/x86/interrupt/exception.rs +++ b/kernel-rs/src/arch/x86/interrupt/exception.rs @@ -1,9 +1,13 @@ // https://wiki.osdev.org/Exceptions +use ::arch::x86::pti; + macro_rules! exception { ($name:ident, $func:block) => { pub extern "x86-interrupt" fn $name(stack_frame: &mut ExceptionStackFrame) { + // unsafe { pti::map(); } + println!("Exception: {}", stringify!($name)); println!("{:#?}", stack_frame); flush!(); @@ -13,6 +17,8 @@ macro_rules! exception { $func } inner(stack_frame); + + // unsafe { pti::unmap(); } } } } @@ -37,13 +43,13 @@ macro_rules! exception_err { use x86::structures::idt::*; -exception!(divide_by_zero, {}); +exception!(divide_by_zero, { + panic!("CPU exception: division by zero"); +}); + exception!(debug, {}); exception!(non_maskable, {}); -exception!(breakpoint, { - println!("testing here dont mind me"); - flush!(); -}); +exception!(breakpoint, {}); exception!(overflow, {}); exception!(bound_range, {}); exception!(invalid_opcode, {}); diff --git a/kernel-rs/src/arch/x86/mod.rs b/kernel-rs/src/arch/x86/mod.rs index ddf17a1c..f00125a2 100644 --- a/kernel-rs/src/arch/x86/mod.rs +++ b/kernel-rs/src/arch/x86/mod.rs @@ -4,6 +4,7 @@ extern crate x86; pub mod paging; pub mod interrupt; pub mod device; +pub mod pti; pub mod idt; diff --git a/kernel-rs/src/console.rs b/kernel-rs/src/console.rs index 6dc8f781..29a8f583 100644 --- a/kernel-rs/src/console.rs +++ b/kernel-rs/src/console.rs @@ -20,7 +20,7 @@ fn dispatch(command: &str) -> Result <(), &'static str> { "reboot" => self::reboot(), "shutdown" | "halt" | "q" => self::shutdown(), - // others + // x86 specific "stack" => self::print_stack(), "regs" => self::regs(), "cpu" => self::cpu(), @@ -117,7 +117,6 @@ fn print_line(line: &[u8], address: usize) { } /// Print the kernel stack -/// fn print_stack() -> Result <(), &'static str> { let esp: usize; let ebp: usize; @@ -130,7 +129,7 @@ fn print_stack() -> Result <(), &'static str> { } // fn mb2_memory() -> Result <(), &'static str> { -// let boot_info = context::boot_info(); +// let boot_info = ::multiboot2::boot_info(); // let memory_map_tag = boot_info.memory_map_tag() // .expect("Memory map tag required"); @@ -144,7 +143,7 @@ fn print_stack() -> Result <(), &'static str> { // } // fn mb2_sections() -> Result <(), &'static str> { -// let boot_info = context::boot_info(); +// let boot_info = ::multiboot2::boot_info(); // let elf_sections_tag = boot_info.elf_sections_tag() // .expect("Elf-sections tag required"); @@ -178,15 +177,17 @@ pub fn acpi_info() -> Result <(), &'static str> { Ok(()) } +/// Dump control registers pub fn regs() -> Result <(), &'static str> { use ::x86::registers::control::*; - println!("cr0={:#b}", Cr0::read()); - println!("cr3={:?}", Cr3::read()); - println!("cr4={:?}", Cr4::read()); + println!("cr0 = {:?}", Cr0::read()); + println!("cr3 = {:?}", Cr3::read()); + println!("cr4 = {:?}", Cr4::read()); flush!(); Ok(()) } +/// Dump cpu info, should add power management info pub fn cpu() -> Result <(), &'static str> { use ::arch::x86::device::cpu; cpu::cpu_info().expect("cpu info not available"); diff --git a/kernel-rs/src/keyboard.rs b/kernel-rs/src/keyboard.rs index c29217a8..c456d45f 100644 --- a/kernel-rs/src/keyboard.rs +++ b/kernel-rs/src/keyboard.rs @@ -91,11 +91,6 @@ pub fn kbd_callback() { 0x2A | 0x36 => {SHIFT = !is_release}, 0x38 => {ALT = !is_release}, 0x1D => {CTRL = !is_release}, - // terminal switching - // 0x0F if !is_release => { - // context::switch_term(); - // context::current_term().flush(); - // }, 0x0E if !is_release => { vga::VGA.backspace(); } diff --git a/kernel-rs/src/lib.rs b/kernel-rs/src/lib.rs index 1acdefc8..509d3d71 100644 --- a/kernel-rs/src/lib.rs +++ b/kernel-rs/src/lib.rs @@ -1,23 +1,25 @@ //! project hosted on [github](https://github.com/jzck/kernel) -//! exclusively x86 -//! + +// nightly stuff we need #![no_std] #![feature(lang_items)] #![feature(const_fn)] #![feature(ptr_internals)] #![feature(asm)] +#![feature(thread_local)] +// home made heap #![feature(alloc)] #![feature(allocator_api)] #![feature(global_allocator)] +// x86 specific #![feature(abi_x86_interrupt)] extern crate rlibc; -// #[macro_use] extern crate alloc; -#[macro_use] extern crate lazy_static; extern crate spin; +#[macro_use] extern crate lazy_static; extern crate multiboot2; extern crate slab_allocator; extern crate raw_cpuid;