GDT and IDT in kernel space

Paging constructs completed, remap kernel before jumping to kmain
Panic will do a stack trace
Remove SSE from none target
This commit is contained in:
Jeremy Soller 2016-08-15 14:34:20 -06:00
commit cc8fe85e6a
18 changed files with 523 additions and 235 deletions

View file

@ -4,9 +4,10 @@
/// defined in other files inside of the `arch` module
use externs::memset;
use gdt;
use idt;
use memory::{self, Frame};
use paging::{self, entry, PhysicalAddress};
use paging::{self, entry, Page, PhysicalAddress};
/// Test of zero values in BSS.
static BSS_TEST_ZERO: usize = 0;
@ -18,28 +19,14 @@ extern {
fn kmain() -> !;
}
extern {
/// The starting byte of the text (code) data segment.
static mut __text_start: u8;
/// The ending byte of the text (code) data segment.
static mut __text_end: u8;
/// The starting byte of the _.rodata_ (read-only data) segment.
static mut __rodata_start: u8;
/// The ending byte of the _.rodata_ (read-only data) segment.
static mut __rodata_end: u8;
/// The starting byte of the _.data_ segment.
static mut __data_start: u8;
/// The ending byte of the _.data_ segment.
static mut __data_end: u8;
/// The starting byte of the _.bss_ (uninitialized data) segment.
static mut __bss_start: u8;
/// The ending byte of the _.bss_ (uninitialized data) segment.
static mut __bss_end: u8;
}
#[no_mangle]
pub unsafe extern fn kstart() -> ! {
asm!("xchg bx, bx" : : : : "intel", "volatile");
extern {
/// The starting byte of the _.bss_ (uninitialized data) segment.
static mut __bss_start: u8;
/// The ending byte of the _.bss_ (uninitialized data) segment.
static mut __bss_end: u8;
}
// Zero BSS, this initializes statics that are set to 0
{
@ -55,6 +42,9 @@ pub unsafe extern fn kstart() -> ! {
debug_assert_eq!(BSS_TEST_NONZERO, 0xFFFFFFFFFFFFFFFF);
}
// Set up GDT
gdt::init();
// Set up IDT
idt::init(blank);
@ -62,28 +52,13 @@ pub unsafe extern fn kstart() -> ! {
let mut allocator = memory::init(0, &__bss_end as *const u8 as usize);
// Initialize paging
let mut pager = paging::init();
// Remap a section with `flags`
let mut remap_section = |start_ref: &u8, end_ref: &u8, flags: entry::EntryFlags| {
let start = start_ref as *const _ as usize;
let end = end_ref as *const _ as usize;
for i in 0..(start - end + paging::PAGE_SIZE - 1)/paging::PAGE_SIZE {
let frame = Frame::containing_address(PhysicalAddress::new(start + i * paging::PAGE_SIZE));
pager.identity_map(frame, flags, &mut allocator);
}
};
// Remap text read-only
{
asm!("xchg bx, bx" : : : : "intel", "volatile");
//TODO remap_section(& __text_start, & __text_end, entry::PRESENT);
}
let mut active_table = paging::init(&mut allocator);
asm!("xchg bx, bx" : : : : "intel", "volatile");
kmain();
}
interrupt!(blank, {
asm!("xchg bx, bx" : : : : "intel", "volatile");
println!("INTERRUPT");
});