Skip to content

Commit

Permalink
Switch to our segments
Browse files Browse the repository at this point in the history
  • Loading branch information
jermar committed Mar 6, 2017
1 parent 75b6780 commit 39d890e
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {}
}
Expand Down

0 comments on commit 39d890e

Please sign in to comment.