2
* GRUB -- GRand Unified Bootloader
3
* Copyright (C) 2006 Free Software Foundation, Inc.
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
#include <grub/term.h>
21
#include <grub/misc.h>
22
#include <grub/types.h>
24
#include <grub/efi/efi.h>
25
#include <grub/efi/api.h>
26
#include <grub/efi/console.h>
29
grub_console_standard_color = GRUB_EFI_TEXT_ATTR (GRUB_EFI_YELLOW,
30
GRUB_EFI_BACKGROUND_BLACK);
32
grub_console_normal_color = GRUB_EFI_TEXT_ATTR (GRUB_EFI_LIGHTGRAY,
33
GRUB_EFI_BACKGROUND_BLACK);
35
grub_console_highlight_color = GRUB_EFI_TEXT_ATTR (GRUB_EFI_BLACK,
36
GRUB_EFI_BACKGROUND_LIGHTGRAY);
38
static int read_key = -1;
41
grub_console_putchar (grub_uint32_t c)
43
grub_efi_char16_t str[2];
44
grub_efi_simple_text_output_interface_t *o;
46
o = grub_efi_system_table->con_out;
48
/* For now, do not try to use a surrogate pair. */
52
str[0] = (grub_efi_char16_t) (c & 0xffff);
55
/* Should this test be cached? */
56
if (c > 0x7f && o->test_string (o, str) != GRUB_EFI_SUCCESS)
59
o->output_string (o, str);
63
grub_console_getcharwidth (grub_uint32_t c __attribute__ ((unused)))
65
/* For now, every printable character has the width 1. */
70
grub_console_checkkey (void)
72
grub_efi_simple_input_interface_t *i;
73
grub_efi_input_key_t key;
74
grub_efi_status_t status;
79
i = grub_efi_system_table->con_in;
80
status = i->read_key_stroke (i, &key);
84
case GRUB_EFI_SUCCESS:
90
grub_printf ("scan_code=%x,unicode_char=%x ",
91
(unsigned) key.scan_code,
92
(unsigned) key.unicode_char);
93
grub_gotoxy (xy >> 8, xy & 0xff);
97
case GRUB_EFI_NOT_READY:
98
//grub_printf ("not ready ");
102
//grub_printf ("device error ");
107
if (status == GRUB_EFI_SUCCESS)
109
switch (key.scan_code)
112
read_key = key.unicode_char;
153
grub_console_getkey (void)
155
grub_efi_simple_input_interface_t *i;
156
grub_efi_boot_services_t *b;
157
grub_efi_uintn_t index;
158
grub_efi_status_t status;
168
i = grub_efi_system_table->con_in;
169
b = grub_efi_system_table->boot_services;
173
status = b->wait_for_event (1, &(i->wait_for_key), &index);
174
if (status != GRUB_EFI_SUCCESS)
177
grub_console_checkkey ();
179
while (read_key < 0);
187
grub_console_getwh (void)
189
grub_efi_simple_text_output_interface_t *o;
190
grub_efi_uintn_t columns, rows;
192
o = grub_efi_system_table->con_out;
193
if (o->query_mode (o, o->mode->mode, &columns, &rows) != GRUB_EFI_SUCCESS)
195
/* Why does this fail? */
200
return ((columns << 8) | rows);
204
grub_console_getxy (void)
206
grub_efi_simple_text_output_interface_t *o;
208
o = grub_efi_system_table->con_out;
209
return ((o->mode->cursor_column << 8) | o->mode->cursor_row);
213
grub_console_gotoxy (grub_uint8_t x, grub_uint8_t y)
215
grub_efi_simple_text_output_interface_t *o;
217
o = grub_efi_system_table->con_out;
218
o->set_cursor_position (o, x, y);
222
grub_console_cls (void)
224
grub_efi_simple_text_output_interface_t *o;
225
grub_efi_int32_t orig_attr;
227
o = grub_efi_system_table->con_out;
228
orig_attr = o->mode->attribute;
229
o->set_attributes (o, GRUB_EFI_BACKGROUND_BLACK);
231
o->set_attributes (o, orig_attr);
235
grub_console_setcolorstate (grub_term_color_state state)
237
grub_efi_simple_text_output_interface_t *o;
239
o = grub_efi_system_table->con_out;
242
case GRUB_TERM_COLOR_STANDARD:
243
o->set_attributes (o, grub_console_standard_color);
245
case GRUB_TERM_COLOR_NORMAL:
246
o->set_attributes (o, grub_console_normal_color);
248
case GRUB_TERM_COLOR_HIGHLIGHT:
249
o->set_attributes (o, grub_console_highlight_color);
257
grub_console_setcolor (grub_uint8_t normal_color, grub_uint8_t highlight_color)
259
grub_console_normal_color = normal_color;
260
grub_console_highlight_color = highlight_color;
264
grub_console_setcursor (int on)
266
grub_efi_simple_text_output_interface_t *o;
268
o = grub_efi_system_table->con_out;
269
o->enable_cursor (o, on);
272
static struct grub_term grub_console_term =
277
.putchar = grub_console_putchar,
278
.getcharwidth = grub_console_getcharwidth,
279
.checkkey = grub_console_checkkey,
280
.getkey = grub_console_getkey,
281
.getwh = grub_console_getwh,
282
.getxy = grub_console_getxy,
283
.gotoxy = grub_console_gotoxy,
284
.cls = grub_console_cls,
285
.setcolorstate = grub_console_setcolorstate,
286
.setcolor = grub_console_setcolor,
287
.setcursor = grub_console_setcursor,
293
grub_console_init (void)
295
/* FIXME: it is necessary to consider the case where no console control
296
is present but the default is already in text mode. */
297
if (! grub_efi_set_text_mode (1))
299
grub_error (GRUB_ERR_BAD_DEVICE, "cannot set text mode");
303
grub_term_register (&grub_console_term);
304
grub_term_set_current (&grub_console_term);
308
grub_console_fini (void)
310
grub_term_unregister (&grub_console_term);