Keep track of AP count, allocate bigger AP stack, stack trace function
This commit is contained in:
parent
26c86f8242
commit
0d995bfb5c
|
@ -51,8 +51,12 @@ pub fn init_sdt(sdt: &'static Sdt, active_table: &mut ActivePageTable) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allocate a stack
|
// Allocate a stack
|
||||||
|
// TODO: Allocate contiguous
|
||||||
let stack_start = allocate_frame().expect("no more frames").start_address().get();
|
let stack_start = allocate_frame().expect("no more frames").start_address().get();
|
||||||
let stack_end = stack_start + 4096;
|
for i in 0..62 {
|
||||||
|
allocate_frame().expect("no more frames");
|
||||||
|
}
|
||||||
|
let stack_end = allocate_frame().expect("no more frames").start_address().get() + 4096;
|
||||||
|
|
||||||
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) };
|
||||||
|
|
|
@ -2,22 +2,51 @@
|
||||||
|
|
||||||
/// Clear interrupts
|
/// Clear interrupts
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub unsafe fn disable_interrupts() {
|
pub unsafe fn disable() {
|
||||||
asm!("cli" : : : : "intel", "volatile");
|
asm!("cli" : : : : "intel", "volatile");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set interrupts
|
/// Set interrupts
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub unsafe fn enable_interrupts() {
|
pub unsafe fn enable() {
|
||||||
asm!("sti" : : : : "intel", "volatile");
|
asm!("sti" : : : : "intel", "volatile");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set interrupts and halt
|
||||||
|
#[inline(always)]
|
||||||
|
pub unsafe fn enable_and_halt() {
|
||||||
|
asm!("sti
|
||||||
|
hlt"
|
||||||
|
: : : : "intel", "volatile");
|
||||||
|
}
|
||||||
|
|
||||||
/// Halt instruction
|
/// Halt instruction
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub unsafe fn halt() {
|
pub unsafe fn halt() {
|
||||||
asm!("hlt" : : : : "intel", "volatile");
|
asm!("hlt" : : : : "intel", "volatile");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get a stack trace
|
||||||
|
//TODO: Check for stack being mapped before dereferencing
|
||||||
|
#[inline(never)]
|
||||||
|
pub unsafe fn stack_trace() {
|
||||||
|
let mut rbp: usize;
|
||||||
|
asm!("xchg bx, bx" : "={rbp}"(rbp) : : : "intel", "volatile");
|
||||||
|
|
||||||
|
println!("TRACE: {:>016X}", rbp);
|
||||||
|
//Maximum 64 frames
|
||||||
|
for _frame in 0..64 {
|
||||||
|
unsafe {
|
||||||
|
let rip = *(rbp as *const usize).offset(1);
|
||||||
|
println!(" {:>016X}: {:>016X}", rbp, rip);
|
||||||
|
if rip == 0 {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
rbp = *(rbp as *const usize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// x86 External Interrupts (1-16).
|
/// x86 External Interrupts (1-16).
|
||||||
pub static EXCEPTIONS: [Descriptor; 21] = [
|
pub static EXCEPTIONS: [Descriptor; 21] = [
|
||||||
Descriptor::new("Division error", Kind::Fault),
|
Descriptor::new("Division error", Kind::Fault),
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
//! Intrinsics for panic handling
|
//! Intrinsics for panic handling
|
||||||
|
|
||||||
use interrupt::halt;
|
use interrupt;
|
||||||
|
|
||||||
#[cfg(not(test))]
|
#[cfg(not(test))]
|
||||||
#[lang = "eh_personality"]
|
#[lang = "eh_personality"]
|
||||||
|
@ -10,28 +10,15 @@ extern "C" fn eh_personality() {}
|
||||||
/// Required to handle panics
|
/// Required to handle panics
|
||||||
#[lang = "panic_fmt"]
|
#[lang = "panic_fmt"]
|
||||||
extern "C" fn panic_fmt(fmt: ::core::fmt::Arguments, file: &str, line: u32) -> ! {
|
extern "C" fn panic_fmt(fmt: ::core::fmt::Arguments, file: &str, line: u32) -> ! {
|
||||||
let mut rbp: usize;
|
|
||||||
unsafe { asm!("xchg bx, bx" : "={rbp}"(rbp) : : : "intel", "volatile"); }
|
|
||||||
|
|
||||||
println!("PANIC: {}", fmt);
|
println!("PANIC: {}", fmt);
|
||||||
println!("FILE: {}", file);
|
println!("FILE: {}", file);
|
||||||
println!("LINE: {}", line);
|
println!("LINE: {}", line);
|
||||||
|
|
||||||
println!("TRACE: {:>016X}", rbp);
|
unsafe { interrupt::stack_trace(); }
|
||||||
for _frame in 0..16 { //Maximum 16 frames
|
|
||||||
unsafe {
|
|
||||||
let rip = *(rbp as *const usize).offset(1);
|
|
||||||
println!(" {:>016X}: {:>016X}", rbp, rip);
|
|
||||||
if rip == 0 {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
rbp = *(rbp as *const usize);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
println!("HALT");
|
println!("HALT");
|
||||||
loop {
|
loop {
|
||||||
unsafe { halt() };
|
unsafe { interrupt::halt(); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,6 +27,6 @@ extern "C" fn panic_fmt(fmt: ::core::fmt::Arguments, file: &str, line: u32) -> !
|
||||||
/// Required to handle panics
|
/// Required to handle panics
|
||||||
pub extern "C" fn _Unwind_Resume() -> ! {
|
pub extern "C" fn _Unwind_Resume() -> ! {
|
||||||
loop {
|
loop {
|
||||||
unsafe { halt() }
|
unsafe { interrupt::halt(); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ use allocator::{HEAP_START, HEAP_SIZE};
|
||||||
use externs::memset;
|
use externs::memset;
|
||||||
use gdt;
|
use gdt;
|
||||||
use idt;
|
use idt;
|
||||||
|
use interrupt;
|
||||||
use memory;
|
use memory;
|
||||||
use paging::{self, entry, Page, VirtualAddress};
|
use paging::{self, entry, Page, VirtualAddress};
|
||||||
|
|
||||||
|
@ -19,6 +20,7 @@ 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 AP_COUNT: AtomicUsize = ATOMIC_USIZE_INIT;
|
||||||
static BSP_READY: AtomicBool = ATOMIC_BOOL_INIT;
|
static BSP_READY: AtomicBool = ATOMIC_BOOL_INIT;
|
||||||
static BSP_PAGE_TABLE: AtomicUsize = ATOMIC_USIZE_INIT;
|
static BSP_PAGE_TABLE: AtomicUsize = ATOMIC_USIZE_INIT;
|
||||||
|
|
||||||
|
@ -52,8 +54,6 @@ 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();
|
||||||
|
|
||||||
|
@ -70,6 +70,9 @@ pub unsafe extern fn kstart() -> ! {
|
||||||
// Initialize paging
|
// Initialize paging
|
||||||
let mut active_table = paging::init(stack_start, stack_end);
|
let mut active_table = paging::init(stack_start, stack_end);
|
||||||
|
|
||||||
|
// Reset AP variables
|
||||||
|
AP_COUNT.store(1, Ordering::SeqCst);
|
||||||
|
BSP_READY.store(false, Ordering::SeqCst);
|
||||||
BSP_PAGE_TABLE.store(controlregs::cr3() as usize, Ordering::SeqCst);
|
BSP_PAGE_TABLE.store(controlregs::cr3() as usize, Ordering::SeqCst);
|
||||||
|
|
||||||
// Read ACPI tables, starts APs
|
// Read ACPI tables, starts APs
|
||||||
|
@ -84,6 +87,8 @@ pub unsafe extern fn kstart() -> ! {
|
||||||
}
|
}
|
||||||
|
|
||||||
BSP_READY.store(true, Ordering::SeqCst);
|
BSP_READY.store(true, Ordering::SeqCst);
|
||||||
|
|
||||||
|
print!("BSP\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
kmain();
|
kmain();
|
||||||
|
@ -103,11 +108,15 @@ pub unsafe extern fn kstart_ap(stack_start: usize, stack_end: usize) -> ! {
|
||||||
paging::init_ap(stack_start, stack_end, BSP_PAGE_TABLE.load(Ordering::SeqCst));
|
paging::init_ap(stack_start, stack_end, BSP_PAGE_TABLE.load(Ordering::SeqCst));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let ap_number = AP_COUNT.fetch_add(1, Ordering::SeqCst);
|
||||||
|
|
||||||
while ! BSP_READY.load(Ordering::SeqCst) {
|
while ! BSP_READY.load(Ordering::SeqCst) {
|
||||||
asm!("pause" : : : : "intel", "volatile");
|
asm!("pause" : : : : "intel", "volatile");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
print!("{}", ::core::str::from_utf8_unchecked(&[b'A', b'P', b' ', ap_number as u8 + b'0', b'\n']));
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
asm!("hlt");
|
interrupt::enable_and_halt();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,7 @@
|
||||||
#![feature(question_mark)]
|
#![feature(question_mark)]
|
||||||
#![no_std]
|
#![no_std]
|
||||||
|
|
||||||
use arch::interrupt::{enable_interrupts, halt};
|
use arch::interrupt;
|
||||||
|
|
||||||
/// Architecture specific items (test)
|
/// Architecture specific items (test)
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -107,17 +107,8 @@ pub mod tests;
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern fn kmain() {
|
pub extern fn kmain() {
|
||||||
println!("TEST");
|
|
||||||
|
|
||||||
println!("{:?}", syscall::open(b"debug:", 0));
|
|
||||||
println!("{:?}", syscall::open(b"debug:", 0));
|
|
||||||
println!("{:?}", syscall::open(b"debug:", 0));
|
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
unsafe {
|
unsafe { interrupt::enable_and_halt(); }
|
||||||
enable_interrupts();
|
print!("HALT\n");
|
||||||
halt();
|
|
||||||
}
|
|
||||||
println!("{:?}", syscall::write(1, b"HALT\n"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue