2016-08-14 02:21:46 +02:00
|
|
|
/// This function is where the kernel sets up IRQ handlers
|
|
|
|
/// It is increcibly unsafe, and should be minimal in nature
|
|
|
|
/// It must create the IDT with the correct entries, those entries are
|
|
|
|
/// defined in other files inside of the `arch` module
|
2016-08-14 02:58:31 +02:00
|
|
|
|
2016-08-15 23:01:24 +02:00
|
|
|
use bump_allocator::{HEAP_START, HEAP_SIZE};
|
2016-08-15 19:29:53 +02:00
|
|
|
use externs::memset;
|
2016-08-15 22:34:20 +02:00
|
|
|
use gdt;
|
2016-08-15 19:29:53 +02:00
|
|
|
use idt;
|
2016-08-15 23:01:24 +02:00
|
|
|
use memory;
|
|
|
|
use paging::{self, Page, VirtualAddress};
|
2016-08-15 19:29:53 +02:00
|
|
|
|
|
|
|
/// Test of zero values in BSS.
|
|
|
|
static BSS_TEST_ZERO: usize = 0;
|
|
|
|
/// Test of non-zero values in BSS.
|
|
|
|
static BSS_TEST_NONZERO: usize = 0xFFFFFFFFFFFFFFFF;
|
|
|
|
|
|
|
|
extern {
|
|
|
|
/// Kernel main function
|
|
|
|
fn kmain() -> !;
|
|
|
|
}
|
2016-08-14 17:31:35 +02:00
|
|
|
|
2016-08-14 02:21:46 +02:00
|
|
|
#[no_mangle]
|
2016-08-14 19:45:47 +02:00
|
|
|
pub unsafe extern fn kstart() -> ! {
|
2016-08-15 22:34:20 +02:00
|
|
|
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;
|
|
|
|
}
|
2016-08-14 02:21:46 +02:00
|
|
|
|
2016-08-14 17:31:35 +02:00
|
|
|
// Zero BSS, this initializes statics that are set to 0
|
|
|
|
{
|
|
|
|
let start_ptr = &mut __bss_start as *mut u8;
|
|
|
|
let end_ptr = & __bss_end as *const u8 as usize;
|
|
|
|
|
|
|
|
if start_ptr as usize <= end_ptr {
|
|
|
|
let size = end_ptr - start_ptr as usize;
|
|
|
|
memset(start_ptr, 0, size);
|
|
|
|
}
|
|
|
|
|
2016-08-14 19:45:47 +02:00
|
|
|
debug_assert_eq!(BSS_TEST_ZERO, 0);
|
|
|
|
debug_assert_eq!(BSS_TEST_NONZERO, 0xFFFFFFFFFFFFFFFF);
|
2016-08-14 17:31:35 +02:00
|
|
|
}
|
|
|
|
|
2016-08-15 22:34:20 +02:00
|
|
|
// Set up GDT
|
|
|
|
gdt::init();
|
|
|
|
|
2016-08-15 19:29:53 +02:00
|
|
|
// Set up IDT
|
|
|
|
idt::init(blank);
|
2016-08-14 17:31:35 +02:00
|
|
|
|
2016-08-15 19:29:53 +02:00
|
|
|
// Initialize memory management
|
|
|
|
let mut allocator = memory::init(0, &__bss_end as *const u8 as usize);
|
2016-08-14 02:58:31 +02:00
|
|
|
|
2016-08-15 19:29:53 +02:00
|
|
|
// Initialize paging
|
2016-08-15 22:34:20 +02:00
|
|
|
let mut active_table = paging::init(&mut allocator);
|
2016-08-14 17:31:35 +02:00
|
|
|
|
2016-08-15 23:01:24 +02:00
|
|
|
// Initialize heap
|
|
|
|
let heap_start_page = Page::containing_address(VirtualAddress::new(HEAP_START));
|
|
|
|
let heap_end_page = Page::containing_address(VirtualAddress::new(HEAP_START + HEAP_SIZE-1));
|
|
|
|
|
|
|
|
for page in Page::range_inclusive(heap_start_page, heap_end_page) {
|
|
|
|
active_table.map(page, paging::entry::WRITABLE, &mut allocator);
|
|
|
|
}
|
|
|
|
|
2016-08-15 22:34:20 +02:00
|
|
|
asm!("xchg bx, bx" : : : : "intel", "volatile");
|
2016-08-14 19:45:47 +02:00
|
|
|
kmain();
|
2016-08-14 02:58:31 +02:00
|
|
|
}
|
|
|
|
|
2016-08-14 20:08:42 +02:00
|
|
|
interrupt!(blank, {
|
2016-08-15 22:34:20 +02:00
|
|
|
asm!("xchg bx, bx" : : : : "intel", "volatile");
|
2016-08-14 20:08:42 +02:00
|
|
|
println!("INTERRUPT");
|
|
|
|
});
|