Set CPU num to 4. Init lapic for each. TODO: fix deadlock.

master
WangRunji 7 years ago
parent f6df3c412c
commit 2b813b2acc

@ -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

@ -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
}
}

@ -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();
}

@ -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 {}
}

Loading…
Cancel
Save