diff --git a/Makefile b/Makefile index 1cd3409..1adc097 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 mon:stdio +qemu_opts := -cdrom $(iso) -smp 4 -serial mon:stdio features := use_apic ifdef travis diff --git a/src/arch/x86_64/driver/apic/lapic.rs b/src/arch/x86_64/driver/apic/lapic.rs index 4331028..51f1d46 100644 --- a/src/arch/x86_64/driver/apic/lapic.rs +++ b/src/arch/x86_64/driver/apic/lapic.rs @@ -5,10 +5,15 @@ extern { fn lapicstartap(apicid: u8, addr: u32); } -pub fn init(lapic_addr: *const ()) { - debug!("WARNING: lapic::init use C lib"); +pub fn set_addr(lapic_addr: *const ()) { unsafe { lapic = lapic_addr; + } +} + +pub fn init() { + debug!("WARNING: lapic::init use C lib"); + unsafe { lapicinit(); } debug!("lapic: init end"); @@ -25,4 +30,10 @@ pub fn start_ap(apicid: u8, addr: u32) { unsafe { lapicstartap(apicid, addr); } +} + +pub fn lapic_id() -> u8 { + unsafe{ + (*(lapic as *const u32).offset(0x0020/4) >> 24) as u8 + } } \ 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 c03d30d..2ab9c5f 100644 --- a/src/arch/x86_64/driver/apic/mod.rs +++ b/src/arch/x86_64/driver/apic/mod.rs @@ -1,11 +1,16 @@ pub use self::ioapic::IOAPIC; -pub use self::lapic::{ack, start_ap}; +pub use self::lapic::{ack, start_ap, lapic_id}; mod lapic; mod ioapic; 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::lapic::set_addr(lapic_addr); + self::lapic::init(); self::ioapic::init(ioapic_id); +} + +pub fn other_init() { + self::lapic::init(); } \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 82594d6..6d984c8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -85,7 +85,9 @@ pub extern "C" fn other_main() -> ! { arch::cpu::init(); arch::gdt::init(); arch::idt::init(); - println!("Hello world! from AP!"); + arch::driver::apic::other_init(); + // FIXME: deadlock! + println!("Hello world! from CPU {}!", arch::driver::apic::lapic_id()); unsafe{ let a = *(0xdeadbeaf as *const u8); } // Page fault loop {} }