diff --git a/Makefile b/Makefile index b3163d4..559e148 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ grub_cfg := $(boot_src)/grub.cfg assembly_source_files := $(wildcard $(boot_src)/*.asm) assembly_object_files := $(patsubst $(boot_src)/%.asm, \ build/arch/$(arch)/boot/%.o, $(assembly_source_files)) -qemu_opts := -cdrom $(iso) -smp 2 -serial stdio +qemu_opts := -cdrom $(iso) -smp 2 -serial mon:stdio ifdef travis test := 1 diff --git a/src/arch/x86_64/driver/apic/ioapic.rs b/src/arch/x86_64/driver/apic/ioapic.rs index 0231ecd..e9ddc2d 100644 --- a/src/arch/x86_64/driver/apic/ioapic.rs +++ b/src/arch/x86_64/driver/apic/ioapic.rs @@ -12,13 +12,14 @@ use spin::Mutex; pub fn init(ioapic_id: u8) { let mut ioapic = IOAPIC.lock(); - assert!(ioapic.id() == ioapic_id, "ioapicinit: id isn't equal to ioapicid; not a MP"); + assert!(ioapic.id() == ioapic_id, "ioapic.init: id isn't equal to ioapicid; not a MP"); // Mark all interrupts edge-triggered, active high, disabled, // and not routed to any CPUs. for i in 0.. ioapic.maxintr() + 1 { ioapic.write_irq(i, DISABLED, 0); } + debug!("ioapic: init end"); } const IOAPIC_ADDRESS : u32 = 0xFEC00000; // Default physical address of IO APIC @@ -80,6 +81,7 @@ impl IoApic { } pub fn enable(&mut self, irq: u8, cpunum: u8) { + debug!("ioapic: enable irq {} @ cpu{}", irq, cpunum); // Mark interrupt edge-triggered, active high, // enabled, and routed to the given cpunum, // which happens to be that cpu's APIC ID. diff --git a/src/arch/x86_64/driver/apic/lapic.rs b/src/arch/x86_64/driver/apic/lapic.rs index c4537db..0e05a68 100644 --- a/src/arch/x86_64/driver/apic/lapic.rs +++ b/src/arch/x86_64/driver/apic/lapic.rs @@ -3,8 +3,11 @@ extern { fn lapicinit(); // must set `lapic` first } -pub unsafe fn init(lapic_addr: *const ()) { - debug!("WARNING: lapic::init use C lib"); - lapic = lapic_addr; - lapicinit(); +pub fn init(lapic_addr: *const ()) { + debug!("WARNING: lapic::init use C lib"); + unsafe { + lapic = lapic_addr; + lapicinit(); + } + debug!("lapic: init end"); } \ No newline at end of file diff --git a/src/arch/x86_64/driver/apic/mod.rs b/src/arch/x86_64/driver/apic/mod.rs index 64ac839..a6c9ff3 100644 --- a/src/arch/x86_64/driver/apic/mod.rs +++ b/src/arch/x86_64/driver/apic/mod.rs @@ -3,7 +3,8 @@ pub use self::ioapic::IOAPIC; mod lapic; mod ioapic; -pub unsafe fn init(lapic_addr: *const (), ioapic_id: u8) { +pub fn init(lapic_addr: *const (), ioapic_id: u8) { + assert_has_not_been_called!("apic::init must be called only once"); self::lapic::init(lapic_addr); self::ioapic::init(ioapic_id); } \ No newline at end of file diff --git a/src/arch/x86_64/driver/pic.rs b/src/arch/x86_64/driver/pic.rs index 4674db5..5da828e 100644 --- a/src/arch/x86_64/driver/pic.rs +++ b/src/arch/x86_64/driver/pic.rs @@ -5,6 +5,8 @@ static MASTER: Mutex = Mutex::new(Pic::new(0x20)); static SLAVE: Mutex = Mutex::new(Pic::new(0xA0)); pub fn init() { + assert_has_not_been_called!("pic::init must be called only once"); + let mut master = MASTER.lock(); let mut slave = SLAVE.lock(); diff --git a/src/lib.rs b/src/lib.rs index 452c1a4..6c4971c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -78,9 +78,9 @@ pub extern "C" fn rust_main(multiboot_information_address: usize) { memory_controller.map_page_identity(acpi.lapic_addr as usize); // LAPIC memory_controller.map_page_identity(0xFEC00000); // IOAPIC - unsafe{ arch::driver::apic::init(acpi.lapic_addr, acpi.ioapic_id); } + arch::driver::apic::init(acpi.lapic_addr, acpi.ioapic_id); - unsafe{ arch::driver::pic::init(); } + arch::driver::pic::init(); test_end!(); }