Skip to content

Commit

Permalink
Merge pull request #328 from Stary2001/fix-stage2
Browse files Browse the repository at this point in the history
Correctness fixes for stage2
  • Loading branch information
phil-opp authored Jan 16, 2023
2 parents 0f6453c + 04b6e14 commit c73786d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 3 additions & 2 deletions bios/stage-2/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ pub extern "C" fn _start(disk_number: u16, partition_table_start: *const u8) ->
}

fn start(disk_number: u16, partition_table_start: *const u8) -> ! {
screen::Writer.write_str(" -> SECOND STAGE\n").unwrap();

// Enter unreal mode before doing anything else.
enter_unreal_mode();

screen::Writer.write_str(" -> SECOND STAGE\n").unwrap();

// parse partition table
let partitions = {
const MAX_ENTRIES: usize = 4;
Expand Down
5 changes: 4 additions & 1 deletion bios/stage-2/src/protected_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ unsafe impl Sync for GdtPointer {}

pub fn enter_unreal_mode() {
let ds: u16;
let ss: u16;
unsafe {
asm!("mov {0:x}, ds", out(reg) ds, options(nomem, nostack, preserves_flags));
asm!("mov {0:x}, ss", out(reg) ss, options(nomem, nostack, preserves_flags));
}

GDT.clear_interrupts_and_load();
Expand All @@ -70,14 +72,15 @@ pub fn enter_unreal_mode() {

// load GDT
unsafe {
asm!("mov {0}, 0x10", "mov ds, {0}", out(reg) _);
asm!("mov {0}, 0x10", "mov ds, {0}", "mov ss, {0}", out(reg) _);
}

// unset protected mode bit again
write_cr0(cr0);

unsafe {
asm!("mov ds, {0:x}", in(reg) ds, options(nostack, preserves_flags));
asm!("mov ss, {0:x}", in(reg) ss, options(nostack, preserves_flags));
asm!("sti");
}
}
Expand Down

0 comments on commit c73786d

Please sign in to comment.