rendered paste body bits 16
org 0
section .text
cli
mov ax, cs
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
mov sp, 0FFFEh
cld
; prepare page directory
xor ax, ax
mov es, ax
mov di, 3000h
mov ecx, 4096/4
xor eax, eax
rep stosd
mov dword [es:3000h], 04001h
mov dword [es:3000h+0F00h], 05001h
mov dword [es:3000h+0FFCh], 06001h
; prepare page tables
mov edx, 1
mov ecx, 0
pg_tbl_lpstart: mov [es:4000h + ecx*4], edx
lea ebx, [edx + 0100000h]
mov [es:5000h + ecx*4], ebx
mov dword [es:6000h + ecx*4], 0
mov dword [es:7000h + ecx*4], 0 ; clear stack too
inc ecx
add edx, 1000h
cmp ecx, 1024
jb pg_tbl_lpstart
mov dword [es:6000h + 0FFCh], 07001h
; prepare gdt
mov ax, 01000h
mov es, ax
mov di, 0
mov ecx, 16384
xor eax, eax
rep stosd
mov dword [es:8], 00000FFFFh
mov dword [es:8+4], 000CF9A00h
mov dword [es:16], 00000FFFFh
mov dword [es:16+4], 000CF9200h
to_pm: mov eax, 03000h
mov cr3, eax
lgdt [gdt_limit]
mov eax, cr0
or eax, 80000001h
mov cr0, eax
jmp dword 8:0F0000004h
section .data
align 4
dw 0
gdt_limit dw 0FFFFh
gdt_base dd 010000h