Allocate a very small 4K stack for the other CPUs, increase count to 4
This commit is contained in:
parent
979d80a8c7
commit
b0797a5d8a
2
Makefile
2
Makefile
|
@ -10,7 +10,7 @@ bochs: build/harddrive.bin
|
||||||
bochs -f bochs.$(ARCH)
|
bochs -f bochs.$(ARCH)
|
||||||
|
|
||||||
qemu: build/harddrive.bin
|
qemu: build/harddrive.bin
|
||||||
qemu-system-$(ARCH) -enable-kvm -cpu host -smp 2 -machine q35 \
|
qemu-system-$(ARCH) -enable-kvm -cpu host -smp 4 -machine q35 \
|
||||||
-serial mon:stdio -drive file=$<,format=raw,index=0,media=disk \
|
-serial mon:stdio -drive file=$<,format=raw,index=0,media=disk \
|
||||||
-nographic -d guest_errors,int,pcall
|
-nographic -d guest_errors,int,pcall
|
||||||
#-device intel-iommu
|
#-device intel-iommu
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
use core::intrinsics::{atomic_load, atomic_store};
|
use core::intrinsics::{atomic_load, atomic_store};
|
||||||
|
|
||||||
use memory::Frame;
|
use memory::{allocate_frame, Frame};
|
||||||
use paging::{entry, ActivePageTable, Page, PhysicalAddress, VirtualAddress};
|
use paging::{entry, ActivePageTable, Page, PhysicalAddress, VirtualAddress};
|
||||||
use start::kstart_ap;
|
use start::kstart_ap;
|
||||||
|
|
||||||
|
@ -50,19 +50,9 @@ pub fn init_sdt(sdt: &'static Sdt, active_table: &mut ActivePageTable) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Map a stack
|
// Allocate a stack
|
||||||
/*
|
let stack_start = allocate_frame().expect("no more frames").start_address().get();
|
||||||
let stack_start = HEAP_START + HEAP_SIZE + 4096 + (asp_local_apic.id as usize * (1024 * 1024 + 4096));
|
let stack_end = stack_start + 4096;
|
||||||
let stack_end = stack_start + 1024 * 1024;
|
|
||||||
{
|
|
||||||
let start_page = Page::containing_address(VirtualAddress::new(stack_start));
|
|
||||||
let end_page = Page::containing_address(VirtualAddress::new(stack_end - 1));
|
|
||||||
|
|
||||||
for page in Page::range_inclusive(start_page, end_page) {
|
|
||||||
active_table.map(page, entry::WRITABLE | entry::NO_EXECUTE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
let ap_ready = TRAMPOLINE as *mut u64;
|
let ap_ready = TRAMPOLINE as *mut u64;
|
||||||
let ap_stack_start = unsafe { ap_ready.offset(1) };
|
let ap_stack_start = unsafe { ap_ready.offset(1) };
|
||||||
|
@ -71,8 +61,8 @@ pub fn init_sdt(sdt: &'static Sdt, active_table: &mut ActivePageTable) {
|
||||||
|
|
||||||
// Set the ap_ready to 0, volatile
|
// Set the ap_ready to 0, volatile
|
||||||
unsafe { atomic_store(ap_ready, 0) };
|
unsafe { atomic_store(ap_ready, 0) };
|
||||||
unsafe { atomic_store(ap_stack_start, 0x1000) };
|
unsafe { atomic_store(ap_stack_start, stack_start as u64) };
|
||||||
unsafe { atomic_store(ap_stack_end, 0x7000) };
|
unsafe { atomic_store(ap_stack_end, stack_end as u64) };
|
||||||
unsafe { atomic_store(ap_code, kstart_ap as u64) };
|
unsafe { atomic_store(ap_code, kstart_ap as u64) };
|
||||||
|
|
||||||
// Send INIT IPI
|
// Send INIT IPI
|
||||||
|
|
|
@ -83,7 +83,7 @@ macro_rules! interrupt_error {
|
||||||
$func
|
$func
|
||||||
}
|
}
|
||||||
|
|
||||||
// Push scratch registers, grab stack pointer
|
// Push scratch registers
|
||||||
asm!("push rax
|
asm!("push rax
|
||||||
push rcx
|
push rcx
|
||||||
push rdx
|
push rdx
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
/// It must create the IDT with the correct entries, those entries are
|
/// It must create the IDT with the correct entries, those entries are
|
||||||
/// defined in other files inside of the `arch` module
|
/// defined in other files inside of the `arch` module
|
||||||
|
|
||||||
|
use core::sync::atomic::{AtomicBool, ATOMIC_BOOL_INIT, Ordering};
|
||||||
|
|
||||||
use acpi;
|
use acpi;
|
||||||
use allocator::{HEAP_START, HEAP_SIZE};
|
use allocator::{HEAP_START, HEAP_SIZE};
|
||||||
use externs::memset;
|
use externs::memset;
|
||||||
|
@ -16,6 +18,8 @@ static BSS_TEST_ZERO: usize = 0;
|
||||||
/// Test of non-zero values in BSS.
|
/// Test of non-zero values in BSS.
|
||||||
static BSS_TEST_NONZERO: usize = 0xFFFFFFFFFFFFFFFF;
|
static BSS_TEST_NONZERO: usize = 0xFFFFFFFFFFFFFFFF;
|
||||||
|
|
||||||
|
static BSP_READY: AtomicBool = ATOMIC_BOOL_INIT;
|
||||||
|
|
||||||
extern {
|
extern {
|
||||||
/// Kernel main function
|
/// Kernel main function
|
||||||
fn kmain() -> !;
|
fn kmain() -> !;
|
||||||
|
@ -46,6 +50,8 @@ pub unsafe extern fn kstart() -> ! {
|
||||||
debug_assert_eq!(BSS_TEST_NONZERO, 0xFFFFFFFFFFFFFFFF);
|
debug_assert_eq!(BSS_TEST_NONZERO, 0xFFFFFFFFFFFFFFFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BSP_READY.store(false, Ordering::SeqCst);
|
||||||
|
|
||||||
// Set up GDT
|
// Set up GDT
|
||||||
gdt::init();
|
gdt::init();
|
||||||
|
|
||||||
|
@ -72,6 +78,13 @@ pub unsafe extern fn kstart() -> ! {
|
||||||
for page in Page::range_inclusive(heap_start_page, heap_end_page) {
|
for page in Page::range_inclusive(heap_start_page, heap_end_page) {
|
||||||
active_table.map(page, entry::WRITABLE | entry::NO_EXECUTE);
|
active_table.map(page, entry::WRITABLE | entry::NO_EXECUTE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BSP_READY.store(true, Ordering::SeqCst);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for _i in 0..10 {
|
||||||
|
print!("BSP\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
kmain();
|
kmain();
|
||||||
|
@ -98,6 +111,14 @@ pub unsafe extern fn kstart_ap(stack_start: usize, stack_end: usize) -> ! {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while ! BSP_READY.load(Ordering::SeqCst) {
|
||||||
|
asm!("pause" : : : : "intel", "volatile");
|
||||||
|
}
|
||||||
|
|
||||||
|
for _i in 0..10 {
|
||||||
|
print!("AP\n");
|
||||||
|
}
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
asm!("hlt");
|
asm!("hlt");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue