From: Lizzy Fleckenstein Date: Wed, 21 Sep 2022 18:45:29 +0000 (+0200) Subject: Enable unreal mode X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=51d0e1d5254fc13146820ce4b58c02bcc3111934;p=loadnothing.git Enable unreal mode --- diff --git a/stage1/boot.asm b/stage1/boot.asm index 6144c2a..29a1849 100644 --- a/stage1/boot.asm +++ b/stage1/boot.asm @@ -90,9 +90,39 @@ boot: cmp al, STAGE2SECTORS ; Have we read as many sectors as we requested? jne stage2_error + ; enable to unreal mode + ; https://wiki.osdev.org/Unreal_Mode + cli ; no interrupts + push ds ; save real mode + + lgdt [gdtinfo] ; load gdt register + + mov eax, cr0 ; switch to pmode by + or al, 1 ; set pmode bit + mov cr0, eax + + jmp $+2 ; tell 386/486 to not crash + + mov bx, 0x08 ; select descriptor 1 + mov ds, bx ; 8h = 1000b + + and al, 0xFE ; back to realmode + mov cr0, eax ; by toggling bit again + + pop ds ; get back old segment + sti + jmp STAGE2START ; Hand over control to stage 2 hello db 'Welcome to loadnothing stage 1!', 13, 10, 0 ; \r\n\0 error db 'Error reading stage 2 from disk', 13, 10, 0 ; \r\n\0 +gdtinfo: + dw gdt_end - gdt - 1 ; last byte in table + dd gdt ; start of table + +gdt dd 0, 0 ; entry 0 is always unused +flatdesc db 0xff, 0xff, 0, 0, 0, 10010010b, 11001111b, 0 +gdt_end: + times (446 - ($ - $$)) db 0x00