]> git.lizzy.rs Git - loadnothing.git/commitdiff
Enable unreal mode main
authorLizzy Fleckenstein <eliasfleckenstein@web.de>
Wed, 21 Sep 2022 18:45:29 +0000 (20:45 +0200)
committerLizzy Fleckenstein <eliasfleckenstein@web.de>
Wed, 21 Sep 2022 18:45:29 +0000 (20:45 +0200)
stage1/boot.asm

index 6144c2acabe828915e12ad434883445b9673680b..29a18494ba0de733d4c926cb6550ab43b9022f7e 100644 (file)
@@ -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