gdt in place but triple faults because of spin::Once for now
This commit is contained in:
parent
1b7ddd12d9
commit
bea6a729fe
6 changed files with 52 additions and 11 deletions
|
|
@ -13,11 +13,12 @@ spin = "0.4"
|
|||
slab_allocator = "0.3.1"
|
||||
multiboot2 = { path = "multiboot2-elf64" } # added rsdp tag
|
||||
x86 = { path = "x86" } # forked for IA32
|
||||
raw-cpuid = { path = "rust-cpuid" }
|
||||
|
||||
[dependencies.raw-cpuid]
|
||||
# need to use github/master because of features not yet on crates.io
|
||||
git = "https://github.com/gz/rust-cpuid"
|
||||
features = ["nightly"]
|
||||
# [dependencies.raw-cpuid]
|
||||
# # need to use github/master because of features not yet on crates.io
|
||||
# git = "https://github.com/gz/rust-cpuid"
|
||||
# features = ["nightly"]
|
||||
|
||||
[dependencies.lazy_static]
|
||||
version = "1.0.0"
|
||||
|
|
|
|||
34
kernel-rs/src/arch/x86/gdt.rs
Normal file
34
kernel-rs/src/arch/x86/gdt.rs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
use x86::structures::gdt;
|
||||
use x86::structures::tss;
|
||||
use x86::instructions::segmentation::set_cs;
|
||||
use x86::instructions::tables::load_tss;
|
||||
use spin::Once;
|
||||
|
||||
static GDT: Once<gdt::Gdt> = Once::new();
|
||||
static TSS: Once<tss::TaskStateSegment> = Once::new();
|
||||
|
||||
pub fn init() {
|
||||
// let tss = tss::TaskStateSegment::new();
|
||||
let tss = TSS.call_once(|| {
|
||||
let mut tss = tss::TaskStateSegment::new();
|
||||
tss
|
||||
});
|
||||
|
||||
// let mut code_selector = gdt::SegmentSelector(0);
|
||||
// let mut tss_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_selector = gdt.add_entry(gdt::Descriptor::tss_segment(&tss));
|
||||
// gdt
|
||||
// });
|
||||
|
||||
// gdt.load();
|
||||
// unsafe {
|
||||
// // reload code segment register
|
||||
// set_cs(code_selector);
|
||||
// // load TSS
|
||||
// load_tss(tss_selector);
|
||||
// }
|
||||
}
|
||||
|
|
@ -6,6 +6,7 @@ pub mod interrupt;
|
|||
pub mod device;
|
||||
pub mod pti;
|
||||
|
||||
pub mod gdt;
|
||||
pub mod idt;
|
||||
|
||||
use multiboot2;
|
||||
|
|
@ -25,9 +26,6 @@ pub unsafe extern fn x86_rust_start(multiboot_info_addr: usize) {
|
|||
acpi::init().expect("ACPI failed");
|
||||
}
|
||||
|
||||
// set up interrupts
|
||||
idt::init();
|
||||
|
||||
// set up physical allocator
|
||||
::memory::init(&boot_info);
|
||||
|
||||
|
|
@ -37,12 +35,15 @@ pub unsafe extern fn x86_rust_start(multiboot_info_addr: usize) {
|
|||
// set up heap
|
||||
::allocator::init(&mut active_table);
|
||||
|
||||
// set up memory segmentation
|
||||
// gdt::init();
|
||||
|
||||
// set up interrupts
|
||||
idt::init();
|
||||
|
||||
// set up pic & apic
|
||||
device::init(&mut active_table);
|
||||
|
||||
// after core has loaded
|
||||
::memory::init_noncore();
|
||||
|
||||
// primary CPU entry point
|
||||
::kmain();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ pub static mut PTI_CONTEXT_STACK: usize = 0;
|
|||
#[inline(always)]
|
||||
unsafe fn switch_stack(old: usize, new: usize) {
|
||||
let old_esp: usize;
|
||||
|
||||
// save the old esp
|
||||
asm!("" : "={esp}"(old_esp) : : : "intel", "volatile");
|
||||
|
||||
let offset_esp = old - old_esp;
|
||||
|
|
@ -24,6 +26,7 @@ unsafe fn switch_stack(old: usize, new: usize) {
|
|||
offset_esp
|
||||
);
|
||||
|
||||
// switch the esp with the new one
|
||||
asm!("" : : "{esp}"(new_esp) : : "intel", "volatile");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -47,6 +47,8 @@ pub mod arch;
|
|||
|
||||
/// kernel entry point. arch module is responsible for calling this
|
||||
pub fn kmain() -> ! {
|
||||
// core is loaded now
|
||||
memory::init_noncore();
|
||||
|
||||
// x86::instructions::interrupts::int3();
|
||||
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ pub fn deallocate_frames(frame: PhysFrame, count: usize) {
|
|||
|
||||
/// Init memory module after core
|
||||
/// Must be called once, and only once,
|
||||
pub unsafe fn init_noncore() {
|
||||
pub fn init_noncore() {
|
||||
if let Some(ref mut controler) = *MEMORY_CONTROLER.lock() {
|
||||
controler.frame_allocator.set_core(true);
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in a new issue