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 MAC address to an u16 string
18 * @pointer: mac address
19 * @buf: pointer to buffer address
20 * on return position of terminating zero word
22 static void mac(void *pointer
, u16
**buf
)
26 u8
*p
= (u8
*)pointer
;
30 for (i
= 0; i
< ARP_HLEN
; ++i
) {
34 for (j
= 4; j
>= 0; j
-= 4) {
35 c
= (byte
>> j
) & 0x0f;
47 * Print a pointer to an u16 string
50 * @buf: pointer to buffer address
51 * on return position of terminating zero word
53 static void pointer(void *pointer
, u16
**buf
)
57 uintptr_t p
= (uintptr_t)pointer
;
60 for (i
= 8 * sizeof(p
) - 4; i
>= 0; i
-= 4) {
72 * Print an unsigned 32bit value as decimal number to an u16 string
74 * @value: value to be printed
75 * @buf: pointer to buffer address
76 * on return position of terminating zero word
78 static void uint2dec(u32 value
, u16
**buf
)
86 * Increment by .5 and multiply with
87 * (2 << 60) / 1,000,000,000 = 0x44B82FA0.9B5A52CC
88 * to move the first digit to bit 60-63.
91 f
+= (0x9B5A52DULL
* value
) >> 28;
92 f
+= 0x44B82FA0ULL
* value
;
94 for (i
= 0; i
< 10; ++i
) {
95 /* Write current digit */
99 /* Eliminate current digit */
100 f
&= 0xfffffffffffffff;
111 * Print a signed 32bit value as decimal number to an u16 string
113 * @value: value to be printed
114 * @buf: pointer to buffer address
115 * on return position of terminating zero word
117 static void int2dec(s32 value
, u16
**buf
)
133 * Print a colored formatted string to the EFI console
135 * @color color, see constants in efi_api.h, use -1 for no color
137 * @... optional arguments
139 void efi_st_printc(int color
, const char *fmt
, ...)
151 con_out
->set_attribute(con_out
, (unsigned long)color
);
181 int2dec(va_arg(args
, s32
), &pos
);
188 mac(va_arg(args
, void*), &pos
);
193 u
= va_arg(args
, u16
*);
196 con_out
->output_string(con_out
,
199 con_out
->output_string(con_out
, u
);
204 pointer(va_arg(args
, void*), &pos
);
208 s
= va_arg(args
, const char *);
213 uint2dec(va_arg(args
, u32
), &pos
);
225 con_out
->output_string(con_out
, buf
);
227 con_out
->set_attribute(con_out
, EFI_LIGHTGRAY
);
231 * Reads an Unicode character from the input device.
233 * @return: Unicode character
235 u16
efi_st_get_key(void)
237 struct efi_input_key input_key
;
240 /* Wait for next key */
242 ret
= con_in
->read_key_stroke(con_in
, &input_key
);
243 } while (ret
== EFI_NOT_READY
);
244 return input_key
.unicode_char
;