4 * Copyright (c) 2017 Heinrich Schuchardt <xypron.glpk@gmx.de>
6 * SPDX-License-Identifier: GPL-2.0+
9 #include <efi_selftest.h>
12 struct efi_simple_text_output_protocol *con_out;
13 struct efi_simple_input_interface *con_in;
16 * Print a pointer to an u16 string
19 * @buf: pointer to buffer address
20 * on return position of terminating zero word
22 static void pointer(void *pointer, u16 **buf)
26 uintptr_t p = (uintptr_t)pointer;
29 for (i = 8 * sizeof(p) - 4; i >= 0; i -= 4) {
41 * Print an unsigned 32bit value as decimal number to an u16 string
43 * @value: value to be printed
44 * @buf: pointer to buffer address
45 * on return position of terminating zero word
47 static void uint2dec(u32 value, u16 **buf)
55 * Increment by .5 and multiply with
56 * (2 << 60) / 1,000,000,000 = 0x44B82FA0.9B5A52CC
57 * to move the first digit to bit 60-63.
60 f += (0x9B5A52DULL * value) >> 28;
61 f += 0x44B82FA0ULL * value;
63 for (i = 0; i < 10; ++i) {
64 /* Write current digit */
68 /* Eliminate current digit */
69 f &= 0xfffffffffffffff;
80 * Print a signed 32bit value as decimal number to an u16 string
82 * @value: value to be printed
83 * @buf: pointer to buffer address
84 * on return position of terminating zero word
86 static void int2dec(s32 value, u16 **buf)
102 * Print a formatted string to the EFI console
104 * @fmt: format string
105 * @...: optional arguments
107 void efi_st_printf(const char *fmt, ...)
146 int2dec(va_arg(args, s32), &pos);
149 pointer(va_arg(args, void*), &pos);
152 s = va_arg(args, const char *);
157 uint2dec(va_arg(args, u32), &pos);
169 con_out->output_string(con_out, buf);
173 * Reads an Unicode character from the input device.
175 * @return: Unicode character
177 u16 efi_st_get_key(void)
179 struct efi_input_key input_key;
182 /* Wait for next key */
184 ret = con_in->read_key_stroke(con_in, &input_key);
185 } while (ret == EFI_NOT_READY);
186 return input_key.unicode_char;