Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctness fixes for stage2 #328

Merged
merged 2 commits into from
Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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