Code: Select all
; Stage 2
[BITS 16]
[ORG 9000]
; **************************************************
; Program begins here
; **************************************************
;mov ax, cs
;mov ds, ax
;mov es, ax
cli ; Disable interrupts, we want to be alone
xor ax, ax
mov ds, ax ; Set DS-register to 0 - used by lgdt
lgdt [gdt_desc] ; Load the GDT descriptor
cli
mov eax, cr0 ; CR0 into EAX
or eax, 1
mov cr0, eax ; EAX into CR0
cli
jmp 0x10:clear_pipe ; Jump to code segment, offset clear_pipe
[BITS 32] ; We now need 32-bit instructions
clear_pipe:
mov ax, 08h ; Save data segment identifyer
mov ds, ax ; Move a valid data segment into the data segment register
mov ss, ax ; Move a valid data segment into the stack segment register
mov esp, 090000h ; Move the stack pointer to 090000h
; Prove that we are in Protected Mode
;mov 0B8000, 'P'
;mov 0B8001, 1Bh
mov byte [ds:0B8000h], 'P' ; Move the ASCII-code of 'P' into first video memory
mov byte [ds:0B8001h], 0Fh ; Assign a color code
mov byte [ds:0B8002h], 'M'
mov byte [ds:0B8003h], 0Fh
; Hang for testing purposes
hang:
jmp hang
gdt: ; Address for the GDT
gdt_null: ; Null Segment
dw 0
dw 0
gdt_code: ; Code segment, read/execute, nonconforming
dw 0FFFFh
dw 0
db 0
db 10011010b
db 11001111b
db 0
gdt_data: ; Data segment, read/write, expand down
dw 0FFFFh
dw 0
db 0
db 10010010b
db 11001111b
db 0
gdt_end: ; Used to calculate the size of the GDT
gdt_desc: ; The GDT descriptor
db gdt_end - gdt - 1 ; Limit (size) Why minus 1?
dw gdt ; Address of the GDT