Permalink
Browse files

Switch to our segments

  • Loading branch information...
jermar committed Mar 6, 2017
1 parent 75b6780 commit 39d890e3b3bc932aa7adfd67cbd267c4c893d3b9
Showing with 22 additions and 6 deletions.
  1. +22 −6 src/main.rs
View
@@ -69,6 +69,10 @@ pub static MULTIBOOT_HEADER: MultibootHeader =
unsafe { &hardcoded_unmapped_load_address },
start);
const fn selector(s: u16) -> u16 {
s << 3
}
#[repr(C)]
pub struct Des {
limit_0_15: u16,
@@ -153,13 +157,25 @@ pub static BOOTSTRAP_GDTR: Gdtr = Gdtr {
#[naked]
#[no_mangle]
pub extern "C" fn start() -> ! {
const CODE_SEG: u32 = selector(1) as u32;
const DATA_SEG: u32 = selector(2) as u32;
unsafe {
asm!(
"
cli
cld
lgdtl BOOTSTRAP_GDTR
" : : : : "volatile");
asm!("
cli
cld
lgdtl $0
movl $1, %eax
mov %ax, %ds
mov %ax, %es
mov %ax, %fs
mov %ax, %gs
mov %ax, %ss
ljmpl $2, $$label.${:uid}
label.${:uid}:
" : : "*m" (&BOOTSTRAP_GDTR), "Z" (DATA_SEG), "Z" (CODE_SEG) : "memory" : "volatile");
}
loop {}
}

0 comments on commit 39d890e

Please sign in to comment.