1 // SPDX-License-Identifier: GPL-2.0+
5 * Copyright (c) 2017 Heinrich Schuchardt <xypron.glpk@gmx.de>
8 #include <efi_selftest.h>
11 struct efi_simple_text_output_protocol *con_out;
12 struct efi_simple_input_interface *con_in;
15 * Print a MAC address to an u16 string
17 * @pointer: mac address
18 * @buf: pointer to buffer address
19 * on return position of terminating zero word
21 static void mac(void *pointer, u16 **buf)
25 u8 *p = (u8 *)pointer;
29 for (i = 0; i < ARP_HLEN; ++i) {
33 for (j = 4; j >= 0; j -= 4) {
34 c = (byte >> j) & 0x0f;
46 * Print a pointer to an u16 string
49 * @buf: pointer to buffer address
50 * on return position of terminating zero word
52 static void pointer(void *pointer, u16 **buf)
56 uintptr_t p = (uintptr_t)pointer;
59 for (i = 8 * sizeof(p) - 4; i >= 0; i -= 4) {
71 * Print an unsigned 32bit value as decimal number to an u16 string
73 * @value: value to be printed
74 * @buf: pointer to buffer address
75 * on return position of terminating zero word
77 static void uint2dec(u32 value, u16 **buf)
85 * Increment by .5 and multiply with
86 * (2 << 60) / 1,000,000,000 = 0x44B82FA0.9B5A52CC
87 * to move the first digit to bit 60-63.
90 f += (0x9B5A52DULL * value) >> 28;
91 f += 0x44B82FA0ULL * value;
93 for (i = 0; i < 10; ++i) {
94 /* Write current digit */
98 /* Eliminate current digit */
99 f &= 0xfffffffffffffff;
110 * Print a signed 32bit value as decimal number to an u16 string
112 * @value: value to be printed
113 * @buf: pointer to buffer address
114 * on return position of terminating zero word
116 static void int2dec(s32 value, u16 **buf)
132 * Print a colored formatted string to the EFI console
134 * @color color, see constants in efi_api.h, use -1 for no color
136 * @... optional arguments
138 void efi_st_printc(int color, const char *fmt, ...)
150 con_out->set_attribute(con_out, (unsigned long)color);
180 int2dec(va_arg(args, s32), &pos);
187 mac(va_arg(args, void*), &pos);
192 u = va_arg(args, u16*);
195 con_out->output_string(con_out,
198 con_out->output_string(con_out, u);
203 pointer(va_arg(args, void*), &pos);
207 s = va_arg(args, const char *);
212 uint2dec(va_arg(args, u32), &pos);
224 con_out->output_string(con_out, buf);
226 con_out->set_attribute(con_out, EFI_LIGHTGRAY);
230 * Reads an Unicode character from the input device.
232 * @return: Unicode character
234 u16 efi_st_get_key(void)
236 struct efi_input_key input_key;
239 /* Wait for next key */
241 ret = con_in->read_key_stroke(con_in, &input_key);
242 } while (ret == EFI_NOT_READY);
243 return input_key.unicode_char;