Code: Select all
[BITS 32]
entry:
; check if data segment linked, located, and loaded properly
mov eax,[ds_magic]
mov [mboot_info], ebx
cmp eax,DS_MAGIC
je ds_ok
; display a blinking white-on-blue 'D' and freeze
mov word [0B8000h],9F44h
jmp short $
ds_ok:
; stop using bootloader GDT, and load new GDT
lgdt [gdt_ptr]
mov ax,LINEAR_DATA_SEL
mov ds,ax
mov es,ax
mov ss,ax
mov fs,ax
mov gs,ax
jmp LINEAR_CODE_SEL:testrealmode
testrealmode:
cli
; ------ Ensure that code- and stack-segment limits are 64KB.
mov eax, ds16
mov ss, eax
jmp dword cs16:.2
[BITS 16]
; ------ Disable protected mode; jump to real-mode segment.
.2:
mov eax, cr0
and eax, 0xFE
mov cr0, eax
jmp word 0x00:.3
; ------ Load stack- and data-segment registers
; ------ with proper real-mode segment numbers.
.3: xor ax, ax
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
; ------ Enable A20 line (and thus high memory).
; ------ [http://www.karig.net/0003.html]
mov al, 0xD1
out 0x64, al
mov al, 0x03
out 0x60, al
sti
; ------ Prove this code works -- print "YYYYYYYY" if it does.
testcode:
mov al, 'Y'
mov edi, 0x2FFF00
mov dx, 0xABCD
mov [edi], dx
mov bx, [edi]
cmp bx, 0xABCD
je .1
mov al, 'N'
.1: xor bh, bh
mov bl, 0x20
mov cx, 8
mov ah, 9
int 0x10
; ------ Halt computer.
jmp $
Code: Select all
in function testrealmode.2:
relocation truncated to fit R_386_16