7 BOOT_GET_MEMORY_MAP equ 56
8 BOOT_EXIT_BOOT_SERVICES equ 232
15 ; args: RCX, RDX, R8, and R9.
20 lea rax, [mmap_descver]
24 mov rbx, [rax + BOOT_SERVICES]
25 call [rbx + BOOT_GET_MEMORY_MAP]
31 mov rbx, [rax + BOOT_SERVICES]
32 call [rbx + BOOT_EXIT_BOOT_SERVICES]
34 ; move code to absolute 1000h
37 sub rax, .after_call - start
38 mov rsi, rax ; source address
39 mov rdi, start ; destination
43 rep movsd ; copy code to make it absolute
50 ; switch to 32-bit compatibility long mode
76 ; clear and enable fifo
77 mov al, FIFO_ENABLE_CLEAR
81 mov al, MCTL_DTR_RTS_OUT2
87 ; ----------- 32bit code ----------
98 ; disable paging to deactivate long mode
103 ; disable long mode (EFER.LME = 0)
104 ; TODO: EFER is MSR c0000080, LME is bit 8
110 ; load 16bit IVT descriptor
111 cli ; just to make sure
114 ; load 16bit code segment and jump to 16bit code
117 ; ---------- 16bit real mode code ----------
134 ; move stack to the top of 640k
141 ; run 16bit video bios test
162 mov ax, [bx + 2] ; segment
166 mov ax, [bx] ; offset
178 hexdig db '0123456789abcdef'
186 mov al, [bx + hexdig]
192 mov al, [bx + hexdig]
207 ; wait until transmit register is empty
210 and al, LST_TREG_EMPTY
227 ; ---------- data ------------
239 mmapbuf: times 4096 db 0
241 str_hello db 'hello!',13,10,0
248 gdt: ; 0: null segment
250 ; 1: code - base:0, lim:4g, G:4k, 32bit, avl, pres|app, dpl:0, type:code/non-conf/rd
253 ; 2: data - base:0, lim:4g, G:4k, 32bit, avl, pres|app, dpl:0, type:data/rw
262 ; real mode IDTR pseudo-descriptor pointing to the IVT at addr 0