cleanup up for handing in
This commit is contained in:
parent
7e150e081b
commit
203ddd9780
4 changed files with 14 additions and 49 deletions
|
|
@ -5,7 +5,6 @@ use x86::instructions::tables::load_tss;
|
|||
use x86::registers::control;
|
||||
use arch::x86::paging::ActivePageTable;
|
||||
use spin::Once;
|
||||
// use io;
|
||||
|
||||
static GDT: Once<gdt::Gdt> = Once::new();
|
||||
static TSS_MAIN: Once<tss::TaskStateSegment> = Once::new();
|
||||
|
|
@ -15,44 +14,19 @@ pub fn init(mut active_table: &mut ActivePageTable) {
|
|||
let tss_main = TSS_MAIN.call_once(|| {
|
||||
let mut tss = tss::TaskStateSegment::new();
|
||||
// tss.esp0 = stack.top;
|
||||
tss.ss0 = 0x8;
|
||||
tss.cr3 = control::Cr3::read_u32();
|
||||
tss.reserved_iopb = 1; //T debug bit
|
||||
tss
|
||||
});
|
||||
|
||||
let tss_int = TSS_INT.call_once(|| {
|
||||
let mut tss = tss::TaskStateSegment::new();
|
||||
match ::memory::allocate_stack(&mut active_table) {
|
||||
Some(stack) => {
|
||||
println!("int tss stack at {:#x}", stack.top);
|
||||
tss.esp0 = stack.top;
|
||||
tss.ss0 = 0x8;
|
||||
tss.cr3 = control::Cr3::read_u32();
|
||||
// tss.esp = stack.top;
|
||||
// tss.es = 0x8;
|
||||
// tss.cs = 0x8;
|
||||
// tss.ss = 0x8;
|
||||
// tss.ds = 0x8;
|
||||
// tss.fs = 0x8;
|
||||
// tss.gs = 0x8;
|
||||
// tss.link = 0x10; //main tss
|
||||
tss.cr3 = control::Cr3::read_u32();
|
||||
tss.reserved_iopb = 1; //T debug bit
|
||||
}
|
||||
_ => panic!("There is no stack available for tss"),
|
||||
};
|
||||
tss
|
||||
});
|
||||
|
||||
let mut code_selector = gdt::SegmentSelector(0);
|
||||
let mut tss_main_selector = gdt::SegmentSelector(0);
|
||||
let mut tss_int_selector = gdt::SegmentSelector(0);
|
||||
|
||||
let gdt = GDT.call_once(|| {
|
||||
let mut gdt = gdt::Gdt::new();
|
||||
code_selector = gdt.add_entry(gdt::Descriptor::kernel_code_segment());
|
||||
tss_main_selector = gdt.add_entry(gdt::Descriptor::tss_segment(&tss_main));
|
||||
tss_int_selector = gdt.add_entry(gdt::Descriptor::tss_segment(&tss_int));
|
||||
gdt
|
||||
});
|
||||
|
||||
|
|
@ -64,17 +38,19 @@ pub fn init(mut active_table: &mut ActivePageTable) {
|
|||
// println!("gdt 2 lower: {:#x}", gdt.table[2] >> 32 as u32);
|
||||
// println!("gdt 3 upper: {:#x}", gdt.table[3] as u32);
|
||||
// println!("gdt 3 lower: {:#x}", gdt.table[3] >> 32 as u32);
|
||||
// println!("gdt 3 limit: {}", (gdt.table[3] & 0x00ff) as u32);
|
||||
// println!("gdt 3 base : {}", (gdt.table[3] & 0xff00) as u32);
|
||||
// println!("gdt 4 upper: {:#x}", gdt.table[4] as u32);
|
||||
// println!("gdt 4 lower: {:#x}", gdt.table[4] >> 32 as u32);
|
||||
flush!();
|
||||
// flush!();
|
||||
|
||||
gdt.load();
|
||||
unsafe {
|
||||
// reload code segment register
|
||||
println!("set_cs({:#x})", code_selector.0);
|
||||
// println!("set_cs({:#x})", code_selector.0);
|
||||
set_cs(code_selector);
|
||||
// load TSS
|
||||
println!("loading tss {:?}", tss_main_selector);
|
||||
// println!("loading tss {:?}", tss_main_selector);
|
||||
load_tss(tss_main_selector);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,24 +10,15 @@ lazy_static! {
|
|||
idt.debug.set_handler_fn(exception::debug);
|
||||
idt.non_maskable_interrupt.set_handler_fn(exception::non_maskable);
|
||||
idt.breakpoint.set_handler_fn(exception::breakpoint);
|
||||
idt.breakpoint.set_gate_type(GateType::TaskGate32);
|
||||
idt.breakpoint.set_selector(0x18);
|
||||
|
||||
idt.overflow.set_handler_fn(exception::overflow);
|
||||
idt.bound_range_exceeded.set_handler_fn(exception::bound_range);
|
||||
idt.invalid_opcode.set_handler_fn(exception::invalid_opcode);
|
||||
idt.device_not_available.set_handler_fn(exception::device_not_available);
|
||||
idt.double_fault.set_handler_fn(exception::double_fault);
|
||||
// idt.double_fault.set_gate_type(GateType::TaskGate32);
|
||||
// idt.double_fault.set_selector(0x18);
|
||||
|
||||
idt.segment_not_present.set_handler_fn(exception::segment_not_present);
|
||||
idt.stack_segment_fault.set_handler_fn(exception::stack_segment);
|
||||
idt.general_protection_fault.set_handler_fn(exception::general_protection);
|
||||
idt.page_fault.set_handler_fn(exception::page_fault);
|
||||
idt.page_fault.set_gate_type(GateType::TaskGate32);
|
||||
idt.page_fault.set_selector(0x18);
|
||||
|
||||
idt.x87_floating_point.set_handler_fn(exception::x87_fpu);
|
||||
idt.alignment_check.set_handler_fn(exception::alignment_check);
|
||||
idt.machine_check.set_handler_fn(exception::machine_check);
|
||||
|
|
|
|||
|
|
@ -44,15 +44,16 @@ exception!(divide_by_zero, {
|
|||
exception!(debug, {});
|
||||
exception!(non_maskable, {});
|
||||
exception!(breakpoint, {
|
||||
// unsafe {
|
||||
// asm!("hlt");
|
||||
// }
|
||||
println!("breakpoint inner function");
|
||||
flush!();
|
||||
});
|
||||
exception!(overflow, {});
|
||||
exception!(bound_range, {});
|
||||
exception!(invalid_opcode, {});
|
||||
exception!(device_not_available, {});
|
||||
exception_err!(double_fault, { panic!("double fault non recoverable") });
|
||||
exception_err!(double_fault, {
|
||||
panic!("double fault non recoverable");
|
||||
});
|
||||
exception!(coprocessor_segment_overrun, {});
|
||||
exception_err!(invalid_tss, {});
|
||||
exception_err!(segment_not_present, {});
|
||||
|
|
@ -69,9 +70,6 @@ pub extern "x86-interrupt" fn page_fault(
|
|||
println!("Error code: {:?}", code);
|
||||
println!("{:#?}", stack_frame);
|
||||
flush!();
|
||||
unsafe {
|
||||
asm!("hlt");
|
||||
}
|
||||
}
|
||||
|
||||
exception!(x87_fpu, {});
|
||||
|
|
|
|||
|
|
@ -60,9 +60,9 @@ pub fn kmain() -> ! {
|
|||
// }
|
||||
// stack_overflow();
|
||||
|
||||
unsafe {
|
||||
*(0xdead as *mut u32) = 42;
|
||||
};
|
||||
// unsafe {
|
||||
// *(0xdead as *mut u32) = 42;
|
||||
// };
|
||||
|
||||
// x86::instructions::interrupts::int3();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue