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
142 ; make sure we have video bios vector installed in 10h
143 mov ax, [10h * 4 + 2]
149 .notnull: ; beyond being non-zero, the video bios should really be at c0000h
152 ; unexpected address, make sure it starts with 0aa55h
157 call init_vbios ; seems like garbage, try init
161 mov si, msg_vbios_test
164 ; run 16bit video bios test
184 ; fill framebuffer with xor pattern
208 cmp word [es:bx], 0aa55h
210 mov si, err_vbios_notfound
221 mov si, msg_vbios_init
223 ; don't bother with CRC, just call it
232 msg_vbios_test db 'running video BIOS test',13,10,0
233 msg_vbios_init db 'attempting to initialize video BIOS',13,10,0
234 err_vbios_notfound db 'failed to initialize video BIOS, sig not found at c0000h: ',0
243 mov ax, [bx + 2] ; segment
247 mov ax, [bx] ; offset
259 hexdig db '0123456789abcdef'
267 mov al, [bx + hexdig]
273 mov al, [bx + hexdig]
288 ; wait until transmit register is empty
291 and al, LST_TREG_EMPTY
308 ; ---------- data ------------
320 mmapbuf: times 4096 db 0
322 str_hello db 'hello!',13,10,0
329 gdt: ; 0: null segment
331 ; 1: code - base:0, lim:4g, G:4k, 32bit, avl, pres|app, dpl:0, type:code/non-conf/rd
334 ; 2: data - base:0, lim:4g, G:4k, 32bit, avl, pres|app, dpl:0, type:data/rw
343 ; real mode IDTR pseudo-descriptor pointing to the IVT at addr 0