An x86_64 UEFI operating system.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

23 lines
754 B

use x86_64::instructions::segmentation::{Segment, SS, CS};
use x86_64::structures::gdt::{Descriptor, DescriptorFlags, GlobalDescriptorTable};
static mut GDT: GlobalDescriptorTable = GlobalDescriptorTable::new();
fn kernel_data_segment() -> Descriptor {
use self::DescriptorFlags as Flags;
let flags = Flags::USER_SEGMENT | Flags::PRESENT | Flags::WRITABLE;
Descriptor::UserSegment(flags.bits())
}
pub fn load() {
unsafe {
let cs = GDT.add_entry(Descriptor::kernel_code_segment());
GDT.add_entry(Descriptor::user_code_segment());
GDT.add_entry(Descriptor::user_data_segment());
let ss = GDT.add_entry(kernel_data_segment());
GDT.load();
CS::set_reg(cs);
SS::set_reg(ss);
}
}