Fix stack trace, WIP usermode
This commit is contained in:
parent
eab03299be
commit
f45958f449
|
@ -1,7 +1,8 @@
|
|||
use super::halt;
|
||||
use super::{halt, stack_trace};
|
||||
|
||||
interrupt!(divide_by_zero, {
|
||||
print!("Divide by zero fault\n");
|
||||
stack_trace();
|
||||
loop { halt(); }
|
||||
});
|
||||
|
||||
|
@ -23,75 +24,90 @@ interrupt!(overflow, {
|
|||
|
||||
interrupt!(bound_range, {
|
||||
print!("Bound range exceeded fault\n");
|
||||
stack_trace();
|
||||
loop { halt(); }
|
||||
});
|
||||
|
||||
interrupt!(invalid_opcode, {
|
||||
print!("Invalid opcode fault\n");
|
||||
stack_trace();
|
||||
loop { halt(); }
|
||||
});
|
||||
|
||||
interrupt!(device_not_available, {
|
||||
print!("Device not available fault\n");
|
||||
stack_trace();
|
||||
loop { halt(); }
|
||||
});
|
||||
|
||||
interrupt_error!(double_fault, {
|
||||
print!("Double fault\n");
|
||||
stack_trace();
|
||||
loop { halt(); }
|
||||
});
|
||||
|
||||
interrupt_error!(invalid_tss, {
|
||||
print!("Invalid TSS fault\n");
|
||||
stack_trace();
|
||||
loop { halt(); }
|
||||
});
|
||||
|
||||
interrupt_error!(segment_not_present, {
|
||||
print!("Segment not present fault\n");
|
||||
stack_trace();
|
||||
loop { halt(); }
|
||||
});
|
||||
|
||||
interrupt_error!(stack_segment, {
|
||||
print!("Stack segment fault\n");
|
||||
stack_trace();
|
||||
loop { halt(); }
|
||||
});
|
||||
|
||||
interrupt_error!(protection, {
|
||||
print!("Protection fault\n");
|
||||
stack_trace();
|
||||
loop { halt(); }
|
||||
});
|
||||
|
||||
interrupt_error!(page, {
|
||||
print!("Page fault\n");
|
||||
stack_trace();
|
||||
loop { halt(); }
|
||||
});
|
||||
|
||||
interrupt!(fpu, {
|
||||
print!("FPU floating point fault\n");
|
||||
stack_trace();
|
||||
loop { halt(); }
|
||||
});
|
||||
|
||||
interrupt_error!(alignment_check, {
|
||||
print!("Alignment check fault\n");
|
||||
stack_trace();
|
||||
loop { halt(); }
|
||||
});
|
||||
|
||||
interrupt!(machine_check, {
|
||||
print!("Machine check fault\n");
|
||||
stack_trace();
|
||||
loop { halt(); }
|
||||
});
|
||||
|
||||
interrupt!(simd, {
|
||||
print!("SIMD floating point fault\n");
|
||||
stack_trace();
|
||||
loop { halt(); }
|
||||
});
|
||||
|
||||
interrupt!(virtualization, {
|
||||
print!("Virtualization fault\n");
|
||||
stack_trace();
|
||||
loop { halt(); }
|
||||
});
|
||||
|
||||
interrupt_error!(security, {
|
||||
print!("Security exception\n");
|
||||
stack_trace();
|
||||
loop { halt(); }
|
||||
});
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
//! Interrupt instructions
|
||||
|
||||
use core::mem;
|
||||
|
||||
use paging::{ActivePageTable, VirtualAddress};
|
||||
|
||||
pub mod exception;
|
||||
pub mod irq;
|
||||
pub mod syscall;
|
||||
|
@ -46,12 +50,15 @@ pub unsafe fn stack_trace() {
|
|||
|
||||
println!("TRACE: {:>016X}", rbp);
|
||||
//Maximum 64 frames
|
||||
let active_table = ActivePageTable::new();
|
||||
for _frame in 0..64 {
|
||||
if active_table.translate(VirtualAddress::new(rbp)).is_some() && active_table.translate(VirtualAddress::new(rbp + mem::size_of::<usize>())).is_some() {
|
||||
let rip = *(rbp as *const usize).offset(1);
|
||||
println!(" {:>016X}: {:>016X}", rbp, rip);
|
||||
if rip == 0 {
|
||||
rbp = *(rbp as *const usize);
|
||||
} else {
|
||||
println!(" {:>016X}: GUARD PAGE", rbp);
|
||||
break;
|
||||
}
|
||||
rbp = *(rbp as *const usize);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,7 +48,8 @@ macro_rules! interrupt {
|
|||
}
|
||||
|
||||
// Push scratch registers
|
||||
asm!("push rax
|
||||
asm!("xchg bx, bx
|
||||
push rax
|
||||
push rcx
|
||||
push rdx
|
||||
push rdi
|
||||
|
@ -63,7 +64,8 @@ macro_rules! interrupt {
|
|||
inner();
|
||||
|
||||
// Pop scratch registers and return
|
||||
asm!("pop r11
|
||||
asm!("xchg bx,bx
|
||||
pop r11
|
||||
pop r10
|
||||
pop r9
|
||||
pop r8
|
||||
|
@ -89,7 +91,8 @@ macro_rules! interrupt_error {
|
|||
}
|
||||
|
||||
// Push scratch registers
|
||||
asm!("push rax
|
||||
asm!("xchg bx, bx
|
||||
push rax
|
||||
push rcx
|
||||
push rdx
|
||||
push rdi
|
||||
|
@ -104,7 +107,8 @@ macro_rules! interrupt_error {
|
|||
inner();
|
||||
|
||||
// Pop scratch registers, error code, and return
|
||||
asm!("pop r11
|
||||
asm!("xchg bx, bx
|
||||
pop r11
|
||||
pop r10
|
||||
pop r9
|
||||
pop r8
|
||||
|
|
|
@ -180,7 +180,7 @@ impl DerefMut for ActivePageTable {
|
|||
}
|
||||
|
||||
impl ActivePageTable {
|
||||
unsafe fn new() -> ActivePageTable {
|
||||
pub unsafe fn new() -> ActivePageTable {
|
||||
ActivePageTable {
|
||||
mapper: Mapper::new(),
|
||||
}
|
||||
|
|
|
@ -137,6 +137,28 @@ pub unsafe extern fn kstart() -> ! {
|
|||
kmain();
|
||||
}
|
||||
|
||||
unsafe fn usermode(ip: usize, sp: usize) {
|
||||
// Test usermode
|
||||
asm!("xchg bx, bx
|
||||
mov rax, 0x2B
|
||||
mov ds, ax
|
||||
mov es, ax
|
||||
mov fs, ax
|
||||
mov gs, ax
|
||||
|
||||
push rax
|
||||
push rbx
|
||||
pushfq
|
||||
mov rax, 0x23
|
||||
push rax
|
||||
push rcx
|
||||
iretq"
|
||||
:
|
||||
: "{rbx}"(sp), "{rcx}"(ip)
|
||||
: "rax", "rbx", "rcx", "sp"
|
||||
: "intel", "volatile");
|
||||
}
|
||||
|
||||
/// Entry to rust for an AP
|
||||
pub unsafe extern fn kstart_ap(stack_start: usize, stack_end: usize) -> ! {
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue