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 ;; - [X] 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.
13 ;; - [ ] We want to show the user's input on the screen while reading
17 EFI_NOT_READY = 0x8000_0000_0000_0000 or 6
19 ;; Based on https://wiki.osdev.org/Uefi.inc
26 struc EFI_TABLE_HEADER {
34 struc EFI_SYSTEM_TABLE {
36 .FirmwareVendor dq ? ; CHAR16*
37 .FirmwareRevision dd ? ; UINT32
39 .ConsoleInHandle dq ? ; EFI_HANDLE
40 .ConIn dq ? ; EFI_SIMPLE_TEXT_INPUT_PROTOCOL*
41 .ConsoleOutHandle dq ? ; EFI_HANDLE
42 .ConOut dq ? ; EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL*
45 struct EFI_SYSTEM_TABLE
47 struc EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL {
48 .Reset dq ? ; EFI_TEXT_RESET
49 .OutputString dq ? ; EFI_TEXT_STRING
52 struct EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
54 struc EFI_SIMPLE_TEXT_INPUT_PROTOCOL {
55 .Reset dq ? ; EFI_INPUT_RESET
56 .ReadKeyStroke dq ? ; EFI_INPUT_READ_KEY
59 struct EFI_SIMPLE_TEXT_INPUT_PROTOCOL
62 .ScanCode dw ? ; UINT16
63 .UnicodeChar dw ? ; CHAR16
70 section '.text' code executable readable
73 ; At program startup, RDX contains an EFI_SYSTEM_TABLE*.
74 mov [system_table], rdx
77 mov rdx, hello_string.len
88 mov rdx, hello_string.len
93 ;; Print a string of the given length.
96 ;; - RCX = String buffer
97 ;; - RDX = String length
105 ; We take an input string of bytes without any terminator. We need to turn
106 ; this string into a string of words, terminated by a null character.
113 mov al, byte [r8 + rsi]
114 lea rdx, [.output_buffer + rcx]
119 lea rdx, [.output_buffer + rcx]
125 lea rdx, [.output_buffer + r10]
128 ; At this point we have our null-terminated word-string at .output_buffer. Now
129 ; we just need to print it.
131 mov rcx, [system_table] ; EFI_SYSTEM_TABLE* rcx
132 mov rcx, [rcx + EFI_SYSTEM_TABLE.ConOut] ; EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL* rcx
133 mov rdx, .output_buffer
134 mov rbx, [rcx + EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString] ; EFI_TEXT_STRING rbx
140 ;; Read a character as an ASCII byte into the given buffer.
143 ;; - RCX = Character buffer (1 byte)
147 mov rcx, [system_table] ; EFI_SYSTEM_TABLE* rcx
148 mov rcx, [rcx + EFI_SYSTEM_TABLE.ConIn] ; EFI_SIMPLE_TEXT_INPUT_PROTOCOL* rcx
149 mov rbx, [rcx + EFI_SIMPLE_TEXT_INPUT_PROTOCOL.ReadKeyStroke] ; EFI_INPUT_READ_KEY rbx
150 mov rdx, input_key ; EFI_INPUT_KEY* rdx
155 mov r8, EFI_NOT_READY
159 mov ax, [input_key.UnicodeChar]
164 section '.data' readable writable
166 system_table dq ? ; EFI_SYSTEM_TABLE*
168 hello_string db 'Hello, world!', 0xD, 0xA, 'Here is some more text.', 0xD, 0xA
169 .len = $ - hello_string
171 print_string.output_buffer rq 0x400
175 input_key EFI_INPUT_KEY