diff --git a/Cargo.toml b/Cargo.toml index 56e09c55d5766a1537aef4c30977d075dd83cf1b..e7e116a4b689200bbf6afec9ab449b06c733be45 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,8 @@ version = "0.7" default-features = false [features] -default = [] +default = ["acpi"] +acpi = [] doc = [] live = [] multi_core = [] diff --git a/src/arch/x86_64/device/mod.rs b/src/arch/x86_64/device/mod.rs index 1678e739c7e90aaac99efd5bffb909f70195c8f3..9a9e8937a30c571c92198946df9549fd948d8b3c 100644 --- a/src/arch/x86_64/device/mod.rs +++ b/src/arch/x86_64/device/mod.rs @@ -1,5 +1,4 @@ use paging::ActivePageTable; -use acpi::ACPI_TABLE; pub mod cpu; pub mod local_apic; @@ -7,6 +6,7 @@ pub mod pic; pub mod pit; pub mod rtc; pub mod serial; +#[cfg(feature = "acpi")] pub mod hpet; pub unsafe fn init(active_table: &mut ActivePageTable){ @@ -14,18 +14,26 @@ pub unsafe fn init(active_table: &mut ActivePageTable){ local_apic::init(active_table); } +#[cfg(feature = "acpi")] +unsafe fn init_hpet() -> bool { + use acpi::ACPI_TABLE; + if let Some(ref mut hpet) = *ACPI_TABLE.hpet.write() { + hpet::init(hpet) + } else { + false + } +} + +#[cfg(not(feature = "acpi"))] +unsafe fn init_hpet() -> bool { + false +} + pub unsafe fn init_noncore() { - { - let using_hpet = if let Some(ref mut hpet) = *ACPI_TABLE.hpet.write() { - hpet::init(hpet) - } else { - false - }; - if !using_hpet { - pit::init(); - } + if ! init_hpet() { + pit::init(); } - + rtc::init(); serial::init(); } diff --git a/src/arch/x86_64/macros.rs b/src/arch/x86_64/macros.rs index 29a3024b8a605c7f7295757360c58ac77aad72c1..1772c3d8e622c89cb6af1dd896e553f9aba2af30 100644 --- a/src/arch/x86_64/macros.rs +++ b/src/arch/x86_64/macros.rs @@ -31,25 +31,15 @@ pub struct ScratchRegisters { impl ScratchRegisters { pub fn dump(&self) { - let rax = self.rax; - let rcx = self.rcx; - let rdx = self.rdx; - let rdi = self.rdi; - let rsi = self.rsi; - let r8 = self.r8; - let r9 = self.r9; - let r10 = self.r10; - let r11 = self.r11; - - println!("RAX: {:>016X}", rax); - println!("RCX: {:>016X}", rcx); - println!("RDX: {:>016X}", rdx); - println!("RDI: {:>016X}", rdi); - println!("RSI: {:>016X}", rsi); - println!("R8: {:>016X}", r8); - println!("R9: {:>016X}", r9); - println!("R10: {:>016X}", r10); - println!("R11: {:>016X}", r11); + println!("RAX: {:>016X}", { self.rax }); + println!("RCX: {:>016X}", { self.rcx }); + println!("RDX: {:>016X}", { self.rdx }); + println!("RDI: {:>016X}", { self.rdi }); + println!("RSI: {:>016X}", { self.rsi }); + println!("R8: {:>016X}", { self.r8 }); + println!("R9: {:>016X}", { self.r9 }); + println!("R10: {:>016X}", { self.r10 }); + println!("R11: {:>016X}", { self.r11 }); } } @@ -96,19 +86,12 @@ pub struct PreservedRegisters { impl PreservedRegisters { pub fn dump(&self) { - let rbx = self.rbx; - let rbp = self.rbp; - let r12 = self.r12; - let r13 = self.r13; - let r14 = self.r14; - let r15 = self.r15; - - println!("RBX: {:>016X}", rbx); - println!("RBP: {:>016X}", rbp); - println!("R12: {:>016X}", r12); - println!("R13: {:>016X}", r13); - println!("R14: {:>016X}", r14); - println!("R15: {:>016X}", r15); + println!("RBX: {:>016X}", { self.rbx }); + println!("RBP: {:>016X}", { self.rbp }); + println!("R12: {:>016X}", { self.r12 }); + println!("R13: {:>016X}", { self.r13 }); + println!("R14: {:>016X}", { self.r14 }); + println!("R15: {:>016X}", { self.r15 }); } } @@ -162,13 +145,9 @@ pub struct IretRegisters { impl IretRegisters { pub fn dump(&self) { - let rflags = self.rflags; - let cs = self.cs; - let rip = self.rip; - - println!("RFLAG: {:>016X}", rflags); - println!("CS: {:>016X}", cs); - println!("RIP: {:>016X}", rip); + println!("RFLAG: {:>016X}", { self.rflags }); + println!("CS: {:>016X}", { self.cs }); + println!("RIP: {:>016X}", { self.rip }); } } @@ -223,7 +202,7 @@ impl InterruptStack { pub fn dump(&self) { self.iret.dump(); self.scratch.dump(); - println!("FS: {:>016X}", self.fs); + println!("FS: {:>016X}", { self.fs }); } } @@ -274,9 +253,9 @@ pub struct InterruptErrorStack { impl InterruptErrorStack { pub fn dump(&self) { self.iret.dump(); - println!("CODE: {:>016X}", self.code); + println!("CODE: {:>016X}", { self.code }); self.scratch.dump(); - println!("FS: {:>016X}", self.fs); + println!("FS: {:>016X}", { self.fs }); } } @@ -330,7 +309,7 @@ impl InterruptStackP { self.iret.dump(); self.scratch.dump(); self.preserved.dump(); - println!("FS: {:>016X}", self.fs); + println!("FS: {:>016X}", { self.fs }); } } @@ -384,10 +363,10 @@ pub struct InterruptErrorStackP { impl InterruptErrorStackP { pub fn dump(&self) { self.iret.dump(); - println!("CODE: {:>016X}", self.code); + println!("CODE: {:>016X}", { self.code }); self.scratch.dump(); self.preserved.dump(); - println!("FS: {:>016X}", self.fs); + println!("FS: {:>016X}", { self.fs }); } } diff --git a/src/arch/x86_64/start.rs b/src/arch/x86_64/start.rs index 96d245865a88fa5da1f7043849e12dd4eda6457c..1d92afc0bdcfce2f72d5ec1faf5c6ad6a2346df6 100644 --- a/src/arch/x86_64/start.rs +++ b/src/arch/x86_64/start.rs @@ -7,6 +7,7 @@ use core::slice; use core::sync::atomic::{AtomicBool, ATOMIC_BOOL_INIT, AtomicUsize, ATOMIC_USIZE_INIT, Ordering}; use allocator; +#[cfg(feature = "acpi")] use acpi; use arch::x86_64::pti; use device; @@ -103,6 +104,7 @@ pub unsafe extern fn kstart(args_ptr: *const KernelArgs) -> ! { device::init(&mut active_table); // Read ACPI tables, starts APs + #[cfg(feature = "acpi")] acpi::init(&mut active_table); // Initialize all of the non-core devices not otherwise needed to complete initialization diff --git a/src/arch/x86_64/stop.rs b/src/arch/x86_64/stop.rs index c65768cc104b7387f4e9b0b1cfb2e00740ab1019..ae084f00c47ae3ec7c2d6d80d88de416c0bd2724 100644 --- a/src/arch/x86_64/stop.rs +++ b/src/arch/x86_64/stop.rs @@ -1,3 +1,4 @@ +#[cfg(feature = "acpi")] use acpi; use syscall::io::{Io, Pio}; @@ -21,6 +22,8 @@ pub unsafe extern fn kreset() -> ! { #[no_mangle] pub unsafe extern fn kstop() -> ! { println!("kstop"); + + #[cfg(feature = "acpi")] acpi::set_global_s_state(5); // Magic shutdown code for bochs and qemu (older versions). diff --git a/src/lib.rs b/src/lib.rs index 7e5a6b9612ef7b1721149f46bea970628dffd3d0..cbbd38a9e97d971d0e8ea27983036bdc61cc88af 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -69,6 +69,7 @@ pub mod consts; pub mod allocator; /// ACPI table parsing +#[cfg(feature = "acpi")] mod acpi; /// Context management