seems like now doesnt violate 16 byte alignment of stack, refactoring
This commit is contained in:
@@ -23,61 +23,54 @@ MEMORY_MAP_SIZE = 0x10000
|
|||||||
|
|
||||||
|
|
||||||
; rcx - color = fore | back
|
; rcx - color = fore | back
|
||||||
efi_set_text_color:
|
proc efi_set_text_color uses rax rdx
|
||||||
push rax rdx
|
|
||||||
mov rax, [efi_table]
|
mov rax, [efi_table]
|
||||||
mov rax, [rax+EFI_SYSTEM_TABLE.ConOut]
|
mov rax, [rax+EFI_SYSTEM_TABLE.ConOut]
|
||||||
mov rdx, rcx ; arg2 - color
|
mov rdx, rcx ; arg2 - color
|
||||||
mov rcx, rax ; arg1 - this
|
mov rcx, rax ; arg1 - this
|
||||||
fstcall [rax+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.SetAttribute]
|
fstcall [rax+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.SetAttribute]
|
||||||
pop rdx rax
|
|
||||||
ret
|
ret
|
||||||
|
endp
|
||||||
|
|
||||||
; rcx - null-terminated string
|
; rcx - null-terminated string
|
||||||
efi_puts:
|
proc efi_puts uses rax rdx
|
||||||
push rax rdx
|
|
||||||
mov rax, [efi_table]
|
mov rax, [efi_table]
|
||||||
mov rax, [rax+EFI_SYSTEM_TABLE.ConOut]
|
mov rax, [rax+EFI_SYSTEM_TABLE.ConOut]
|
||||||
mov rdx, rcx ; arg2 - string
|
mov rdx, rcx ; arg2 - string
|
||||||
mov rcx, rax ; arg1 - this
|
mov rcx, rax ; arg1 - this
|
||||||
fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString]
|
fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString]
|
||||||
pop rdx rax
|
|
||||||
ret
|
ret
|
||||||
|
endp
|
||||||
|
|
||||||
; rcx - char
|
; rcx - char
|
||||||
efi_putc:
|
proc efi_putc uses rax rdx
|
||||||
push rax rdx
|
locals
|
||||||
|
chr dq 0
|
||||||
|
endl
|
||||||
mov rax, [efi_table]
|
mov rax, [efi_table]
|
||||||
mov rax, [rax+EFI_SYSTEM_TABLE.ConOut]
|
mov rax, [rax+EFI_SYSTEM_TABLE.ConOut]
|
||||||
push qword 0
|
mov byte [chr], cl
|
||||||
mov byte [rsp], cl
|
lea rdx, [chr] ; arg2 - string
|
||||||
mov rdx, rsp
|
mov rcx, rax ; arg1 - this
|
||||||
mov rcx, rax
|
|
||||||
fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString]
|
fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString]
|
||||||
add rsp, 8
|
|
||||||
pop rdx rax
|
|
||||||
ret
|
ret
|
||||||
|
endp
|
||||||
|
|
||||||
; print hex without leading zeros
|
; print hex without leading zeros
|
||||||
; rcx - number
|
; rcx - number
|
||||||
efi_print_hex_no_lz:
|
proc efi_print_hex_no_lz uses rax rbx rcx rdx r8 r10 ; TODO also need function that displays with leading zeros
|
||||||
push rax rbx rcx rdx r8
|
locals
|
||||||
|
buf dq 5 dup(0)
|
||||||
push qword 0
|
endl
|
||||||
push qword 0
|
|
||||||
push qword 0
|
|
||||||
push qword 0
|
|
||||||
push qword 0
|
|
||||||
|
|
||||||
xor r10, r10 ; leading zeros end flag
|
xor r10, r10 ; leading zeros end flag
|
||||||
mov rdx, rcx
|
mov rdx, rcx
|
||||||
mov rcx, 64 ; how many nibbles in qword
|
mov rcx, 64 ; how many nibbles in qword
|
||||||
xor r8, r8
|
xor r8, r8
|
||||||
mov byte [rsp + r8*2 ], '0'
|
mov byte [buf + r8*2 ], '0'
|
||||||
mov byte [rsp + r8*2 + 1], 0
|
mov byte [buf + r8*2 + 1], 0
|
||||||
inc r8
|
inc r8
|
||||||
mov byte [rsp + r8*2 ], 'x'
|
mov byte [buf + r8*2 ], 'x'
|
||||||
mov byte [rsp + r8*2 + 1], 0
|
mov byte [buf + r8*2 + 1], 0
|
||||||
inc r8
|
inc r8
|
||||||
.lp:
|
.lp:
|
||||||
sub rcx, 4
|
sub rcx, 4
|
||||||
@@ -95,8 +88,8 @@ efi_print_hex_no_lz:
|
|||||||
@@:
|
@@:
|
||||||
lea rax, [hex_codes + rbx]
|
lea rax, [hex_codes + rbx]
|
||||||
movzx rax, byte [rax]
|
movzx rax, byte [rax]
|
||||||
mov byte [rsp + r8*2 ], al
|
mov byte [buf + r8*2 ], al
|
||||||
mov byte [rsp + r8*2 + 1], 0 ; set high byte to 0 bc UEFI OutputString needs CHAR16
|
mov byte [buf + r8*2 + 1], 0 ; set high byte to 0 bc UEFI OutputString needs CHAR16
|
||||||
inc r8
|
inc r8
|
||||||
|
|
||||||
.lp_cont:
|
.lp_cont:
|
||||||
@@ -105,15 +98,14 @@ efi_print_hex_no_lz:
|
|||||||
|
|
||||||
cmp r8, 2
|
cmp r8, 2
|
||||||
ja @f
|
ja @f
|
||||||
mov byte [rsp + r8*2 ], '0'
|
mov byte [buf + r8*2 ], '0'
|
||||||
mov byte [rsp + r8*2 + 1], 0
|
mov byte [buf + r8*2 + 1], 0
|
||||||
@@:
|
@@:
|
||||||
mov rcx, rsp
|
lea rcx, [buf]
|
||||||
call efi_puts
|
fstcall efi_puts, rcx
|
||||||
|
|
||||||
pop r8 rdx rcx rbx rax
|
|
||||||
add rsp, 8*5
|
|
||||||
ret
|
ret
|
||||||
|
endp
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
@@ -133,48 +125,36 @@ proc main _efi_handle, _efi_table
|
|||||||
fstcall [rax + EFI_BOOT_SERVICES.SetWatchdogTimer], 0, 0, 0, 0
|
fstcall [rax + EFI_BOOT_SERVICES.SetWatchdogTimer], 0, 0, 0, 0
|
||||||
test eax, eax
|
test eax, eax
|
||||||
jz @f
|
jz @f
|
||||||
mov rcx, msg_failed_disable_watchdog
|
fstcall efi_puts, msg_failed_disable_watchdog
|
||||||
call efi_puts
|
|
||||||
jmp $
|
jmp $
|
||||||
@@:
|
@@:
|
||||||
|
|
||||||
mov rcx, EFI_LIGHTGREEN
|
fstcall efi_set_text_color, EFI_LIGHTGREEN
|
||||||
call efi_set_text_color
|
fstcall efi_puts, msg_hello_k64_loader
|
||||||
mov rcx, msg_hello_k64_loader
|
fstcall efi_set_text_color, EFI_LIGHTGRAY
|
||||||
call efi_puts
|
|
||||||
mov rcx, EFI_LIGHTGRAY
|
|
||||||
call efi_set_text_color
|
|
||||||
|
|
||||||
mov rcx, msg_firmware_vendor
|
fstcall efi_puts, msg_firmware_vendor
|
||||||
call efi_puts
|
fstcall efi_puts, [rbx + EFI_SYSTEM_TABLE.FirmwareVendor]
|
||||||
mov rcx, [rbx + EFI_SYSTEM_TABLE.FirmwareVendor]
|
fstcall efi_puts, msg_newline
|
||||||
call efi_puts
|
|
||||||
mov rcx, msg_newline
|
fstcall efi_puts, msg_firmware_revision
|
||||||
call efi_puts
|
fstcall efi_print_hex_no_lz, [rbx + EFI_SYSTEM_TABLE.FirmwareRevision]
|
||||||
mov rcx, msg_firmware_revision
|
fstcall efi_puts, msg_newline
|
||||||
call efi_puts
|
|
||||||
mov ecx, [rbx + EFI_SYSTEM_TABLE.FirmwareRevision]
|
|
||||||
call efi_print_hex_no_lz
|
|
||||||
mov rcx, msg_newline
|
|
||||||
call efi_puts
|
|
||||||
|
|
||||||
; Obtain and print uefi memory map
|
; Obtain and print uefi memory map
|
||||||
mov rbx, [efi_table] ;;
|
mov rbx, [efi_table] ;;
|
||||||
mov r10, [rbx + EFI_SYSTEM_TABLE.BootServices]
|
mov r10, [rbx + EFI_SYSTEM_TABLE.BootServices]
|
||||||
fstcall [r10 + EFI_BOOT_SERVICES.AllocatePages], EFI_ALLOCATE_ANY_PAGES, \
|
fstcall [r10 + EFI_BOOT_SERVICES.AllocatePages], EFI_ALLOCATE_ANY_PAGES, \
|
||||||
EFI_RESERVED_MEMORY_TYPE, MEMORY_MAP_SIZE/0x1000, memory_map
|
EFI_RESERVED_MEMORY_TYPE, MEMORY_MAP_SIZE/0x1000, memory_map
|
||||||
; mov rcx, rax
|
;; call halt_on_error ; TODO
|
||||||
; call efi_print_hex_no_lz
|
|
||||||
; mov rcx, msg_newline
|
|
||||||
; call efi_puts
|
|
||||||
;; call halt_on_error
|
|
||||||
|
|
||||||
mov rbx, [efi_table] ;;
|
mov rbx, [efi_table] ;;
|
||||||
mov r10, [rbx + EFI_SYSTEM_TABLE.BootServices]
|
mov r10, [rbx + EFI_SYSTEM_TABLE.BootServices]
|
||||||
fstcall [r10 + EFI_BOOT_SERVICES.GetMemoryMap], memory_map_size, \
|
fstcall [r10 + EFI_BOOT_SERVICES.GetMemoryMap], memory_map_size, \
|
||||||
[memory_map], memory_map_key, descriptor_size, descriptor_ver
|
[memory_map], memory_map_key, descriptor_size, descriptor_ver
|
||||||
;; call halt_on_error
|
;; call halt_on_error ; TODO
|
||||||
|
|
||||||
|
; TODO iretae through memory map and print it in e820 form
|
||||||
mov rcx, [memory_map]
|
mov rcx, [memory_map]
|
||||||
add rcx, [descriptor_size]
|
add rcx, [descriptor_size]
|
||||||
add rcx, [descriptor_size]
|
add rcx, [descriptor_size]
|
||||||
@@ -183,31 +163,21 @@ proc main _efi_handle, _efi_table
|
|||||||
add rcx, [descriptor_size]
|
add rcx, [descriptor_size]
|
||||||
add rcx, [descriptor_size]
|
add rcx, [descriptor_size]
|
||||||
add rcx, [descriptor_size]
|
add rcx, [descriptor_size]
|
||||||
mov rcx, [rcx]
|
fstcall efi_print_hex_no_lz, qword [rcx]
|
||||||
call efi_print_hex_no_lz
|
fstcall efi_puts, msg_newline
|
||||||
mov rcx, msg_newline
|
|
||||||
call efi_puts
|
|
||||||
|
|
||||||
|
fstcall efi_puts, msg_end_1
|
||||||
|
|
||||||
mov rcx, msg_end_1
|
fstcall efi_print_hex_no_lz, 0x000A000B00C
|
||||||
call efi_puts
|
fstcall efi_puts, msg_newline
|
||||||
|
|
||||||
mov rcx, 0x000A000B00C
|
fstcall efi_print_hex_no_lz, 0xABCDEF133777
|
||||||
call efi_print_hex_no_lz
|
fstcall efi_puts, msg_newline
|
||||||
mov rcx, msg_newline
|
|
||||||
call efi_puts
|
|
||||||
|
|
||||||
|
fstcall efi_print_hex_no_lz, 0xCAFE
|
||||||
|
fstcall efi_puts, msg_newline
|
||||||
|
|
||||||
mov rcx, 0xABCDEF133777
|
fstcall efi_putc, <0+'a'>
|
||||||
call efi_print_hex_no_lz
|
|
||||||
mov rcx, msg_newline
|
|
||||||
call efi_puts
|
|
||||||
|
|
||||||
xor rcx, rcx
|
|
||||||
call efi_print_hex_no_lz
|
|
||||||
mov rcx, msg_newline
|
|
||||||
call efi_puts
|
|
||||||
|
|
||||||
|
|
||||||
jmp $
|
jmp $
|
||||||
endp
|
endp
|
||||||
|
Reference in New Issue
Block a user