Code: Select all
[ORG 0x7E00]
[bits 16]
Entry16:
; We are already in 16-bit mode here!
cli ; Disable interrupts.
; Need 16-bit Protected Mode GDT entries!
mov eax, 0x30 ; 16-bit Protected Mode data selector.
mov ds, eax
mov es, eax
mov fs, eax
mov gs, eax
; Disable paging (we need everything to be 1:1 mapped).
mov eax, cr0
mov [savcr0], eax ; save pmode CR0
and eax, 0x7FFFFFFe ; Disable paging bit & enable 16-bit pmode.
mov cr0, eax
lidt [idt_real]
mov sp, 0x8000
jmp 0:GoRMode
GoRMode:
mov ax, 0
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
sti
printHAI:
mov ax,0xB800
mov es,ax
xor ax,ax
mov al,'H'
mov ah,'!'
mov word [es:0],ax
mov al,'A'
mov ah,'!'
mov word [es:2],ax
mov al,'I'
mov ah,'!'
mov word [es:4],ax
mov al,'!'
mov ah,'!'
mov word [es:6],ax
clrScreen:
xor ax,ax
int 0x10
idt_real:
dw 0x3FF ; 256 entries, 4b each = 1K
dd 0 ; Real Mode IVT @ 0x0000
savcr0:
dd 0