From cb19bc5464c4f811be7c98fed0415687bfe1496b Mon Sep 17 00:00:00 2001 From: WangRunji Date: Wed, 18 Apr 2018 15:22:06 +0800 Subject: [PATCH] Start AP one by one. Fix deadlock. --- src/arch/x86_64/smp.rs | 9 ++++++++- src/io/mod.rs | 10 ++++++---- src/lib.rs | 3 ++- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/arch/x86_64/smp.rs b/src/arch/x86_64/smp.rs index 256c20f..3bc2af0 100644 --- a/src/arch/x86_64/smp.rs +++ b/src/arch/x86_64/smp.rs @@ -25,8 +25,8 @@ pub fn start_other_cores(acpi: &ACPI_Result, mc: &mut MemoryController) { stack: 0x8000, // just enough stack to get us to entry64mp }; start_ap(apic_id, ENTRYOTHER_ADDR); + while unsafe{ !STARTED[i as usize] } {} } - } fn copy_entryother() { @@ -44,4 +44,11 @@ struct EntryArgs { kstack: u64, page_table: u32, stack: u32, +} + +use consts::MAX_CPU_NUM; +static mut STARTED: [bool; MAX_CPU_NUM] = [false; MAX_CPU_NUM]; + +pub unsafe fn notify_started(cpu_id: u8) { + STARTED[cpu_id as usize] = true; } \ No newline at end of file diff --git a/src/io/mod.rs b/src/io/mod.rs index 45239e6..b4a037e 100644 --- a/src/io/mod.rs +++ b/src/io/mod.rs @@ -29,10 +29,12 @@ use arch::driver::vga::Color; fn print_in_color(args: fmt::Arguments, color: Color) { use core::fmt::Write; - use arch::driver::vga::*; - let mut writer = vga_writer::VGA_WRITER.lock(); - writer.set_color(color); - writer.write_fmt(args).unwrap(); + use arch::driver::vga::*; + { + let mut writer = vga_writer::VGA_WRITER.lock(); + writer.set_color(color); + writer.write_fmt(args).unwrap(); + } COM1.lock().write_fmt(args).unwrap(); } diff --git a/src/lib.rs b/src/lib.rs index 6d984c8..3affcd9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -86,8 +86,9 @@ pub extern "C" fn other_main() -> ! { arch::gdt::init(); arch::idt::init(); arch::driver::apic::other_init(); - // FIXME: deadlock! + let cpu_id = arch::driver::apic::lapic_id(); println!("Hello world! from CPU {}!", arch::driver::apic::lapic_id()); + unsafe{ arch::smp::notify_started(cpu_id); } unsafe{ let a = *(0xdeadbeaf as *const u8); } // Page fault loop {} }