switch to 32bit done, changed load address, and fixed the partial code
authorJohn Tsiombikas <nuclear@member.fsf.org>
Mon, 4 Jul 2022 15:47:02 +0000 (18:47 +0300)
committerJohn Tsiombikas <nuclear@member.fsf.org>
Mon, 4 Jul 2022 15:47:02 +0000 (18:47 +0300)
move bug due to unaligned end label

Makefile
efitest.asm

index 1f4e102..198f1d8 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -30,4 +30,4 @@ debug: disk.img
 
 
 disasm: bootx64.efi
-       ndisasm -b 64 -o 0x100000 -e 4096 $< >$@
+       ndisasm -b 64 -o 0x1000 -e 4096 $< >$@
index 26d29d1..bae6aa2 100644 (file)
@@ -1,8 +1,36 @@
 ; vi:ft=nasm:
        bits 64
-       org 100000h
+       org 1000h
+
+BOOT_SERVICES          equ 96
+BOOT_GET_MEMORY_MAP    equ 56
+BOOT_EXIT_BOOT_SERVICES        equ 232
 
 start:
+       mov [efihandle], rcx
+       mov [systab], rdx
+
+       ; retrieve memory map
+       ; args: RCX, RDX, R8, and R9.
+       lea rcx, [mmap_size]
+       lea rdx, [mmapbuf]
+       lea r8, [mmap_key]
+       lea r9, [mmap_descsz]
+       lea rax, [mmap_descver]
+       push rax
+       sub rsp, 32
+       mov rax, [systab]
+       mov rbx, [rax + BOOT_SERVICES]
+       call [rbx + BOOT_GET_MEMORY_MAP]
+       add rsp, 40
+       ; exit boot services
+       mov rcx, [efihandle]
+       mov rdx, [mmap_key]
+       mov rax, [systab]
+       mov rbx, [rax + BOOT_SERVICES]
+       call [rbx + BOOT_EXIT_BOOT_SERVICES]
+
+       ; move code to absolute 1000h
        call get_rip
 .after_call:
        sub rax, .after_call - start
@@ -72,6 +100,19 @@ setup_serial:
        out dx, al
        ret
 
+
+       align 8
+efihandle dq 0
+systab dq 0
+; memory map data
+mmap_size dq 4096
+mmap_key dq 0
+mmap_descsz dq 0
+mmap_descver dq 0
+
+       align 4096
+mmapbuf: times 4096 db 0
+
 str_hello db 'hello!',13,10,0
 
        align 4
@@ -110,6 +151,11 @@ start32:
        and eax, 0fffffeffh
        wrmsr
 
+       mov edi, 0a0000h
+       mov ecx, 16000
+       mov eax, 00ff0000h
+       rep stosd
+
        mov esi, str_hello
        call ser_putstr
 
@@ -139,4 +185,5 @@ ser_putstr:
 .done: ret
 
 
+       align 4
 end: