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