6 ;; [TODO] We need to provide the following:
7 ;; - [X] Print a string of a given length
8 ;; - [ ] Print a single character
9 ;; - [ ] Terminate the program (? - What should this do?)
10 ;; - [ ] Read a single character
11 ;; - This should allow the user to type in a string, and then feed the
12 ;; buffer to us one character at a time.
16 ;; Based on https://wiki.osdev.org/Uefi.inc
23 struc EFI_TABLE_HEADER {
31 struc EFI_SYSTEM_TABLE {
33 .FirmwareVendor dq ? ; CHAR16*
34 .FirmwareRevision dd ? ; UINT32
36 .ConsoleInHandle dq ? ; EFI_HANDLE
37 .ConIn dq ? ; EFI_SIMPLE_TEXT_INPUT_PROTOCOL*
38 .ConsoleOutHandle dq ? ; EFI_HANDLE
39 .ConOut dq ? ; EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL*
42 struct EFI_SYSTEM_TABLE
44 struc EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL {
45 .Reset dq ? ; EFI_TEXT_RESET
46 .OutputString dq ? ; EFI_TEXT_STRING
49 struct EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
53 section '.text' code executable readable
56 ; At program startup, RDX contains an EFI_SYSTEM_TABLE*.
57 mov [system_table], rdx
60 mov rdx, hello_string.len
64 mov rdx, hello_string.len
68 mov rdx, hello_string.len
73 ;; Print a string of the given length.
76 ;; - RCX = String buffer
77 ;; - RDX = String length
85 ; We take an input string of bytes without any terminator. We need to turn
86 ; this string into a string of words, terminated by a null character.
93 mov al, byte [r8 + rsi]
94 lea rdx, [.output_buffer + rcx]
99 lea rdx, [.output_buffer + rcx]
105 lea rdx, [.output_buffer + r10]
108 ; At this point we have our null-terminated word-string at .output_buffer. Now
109 ; we just need to print it.
111 mov rcx, [system_table] ; EFI_SYSTEM_TABLE* rcx
112 mov rcx, [rcx + EFI_SYSTEM_TABLE.ConOut] ; EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL* rcx
113 mov rdx, .output_buffer
114 mov rbx, [rcx + EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString] ; EFI_TEXT_STRING rbx
120 section '.data' readable writable
122 system_table dq ? ; EFI_SYSTEM_TABLE*
124 hello_string db 'Hello, world!', 0xD, 0xA, 'Here is some more text.', 0xD, 0xA
125 .len = $ - hello_string
127 print_string.output_buffer rq 0x400