1
/* ofconsole.c -- Open Firmware console for GRUB. */
3
* GRUB -- GRand Unified Bootloader
4
* Copyright (C) 2003,2004,2005,2007,2008,2009 Free Software Foundation, Inc.
6
* GRUB is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
11
* GRUB is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
20
#include <grub/term.h>
21
#include <grub/types.h>
22
#include <grub/misc.h>
24
#include <grub/time.h>
25
#include <grub/terminfo.h>
26
#include <grub/ieee1275/console.h>
27
#include <grub/ieee1275/ieee1275.h>
29
static grub_ieee1275_ihandle_t stdout_ihandle;
30
static grub_ieee1275_ihandle_t stdin_ihandle;
32
extern struct grub_terminfo_output_state grub_ofconsole_terminfo_output;
41
/* Use serial colors as they are default on most firmwares and some firmwares
42
ignore set-color!. Additionally output may be redirected to serial. */
43
static struct color colors[] =
46
{0x00, 0x00, 0x00}, // 0 = black
47
{0xA8, 0x00, 0x00}, // 1 = red
48
{0x00, 0xA8, 0x00}, // 2 = green
49
{0xFE, 0xFE, 0x54}, // 3 = yellow
50
{0x00, 0x00, 0xA8}, // 4 = blue
51
{0xA8, 0x00, 0xA8}, // 5 = magenta
52
{0x00, 0xA8, 0xA8}, // 6 = cyan
53
{0xFE, 0xFE, 0xFE} // 7 = white
57
put (struct grub_term_output *term __attribute__ ((unused)), const int c)
61
grub_ieee1275_write (stdout_ihandle, &chr, 1, 0);
65
readkey (struct grub_term_input *term __attribute__ ((unused)))
68
grub_ssize_t actual = 0;
70
grub_ieee1275_read (stdin_ihandle, &c, 1, &actual);
77
grub_ofconsole_dimensions (void)
79
grub_ieee1275_ihandle_t options;
82
if (! grub_ieee1275_finddevice ("/options", &options)
83
&& options != (grub_ieee1275_ihandle_t) -1)
85
if (! grub_ieee1275_get_property_length (options, "screen-#columns",
87
&& lval >= 0 && lval < 1024)
91
if (! grub_ieee1275_get_property (options, "screen-#columns",
93
grub_ofconsole_terminfo_output.width
94
= (grub_uint8_t) grub_strtoul (val, 0, 10);
96
if (! grub_ieee1275_get_property_length (options, "screen-#rows", &lval)
97
&& lval >= 0 && lval < 1024)
100
if (! grub_ieee1275_get_property (options, "screen-#rows",
102
grub_ofconsole_terminfo_output.height
103
= (grub_uint8_t) grub_strtoul (val, 0, 10);
107
/* Use a small console by default. */
108
if (! grub_ofconsole_terminfo_output.width)
109
grub_ofconsole_terminfo_output.width = 80;
110
if (! grub_ofconsole_terminfo_output.height)
111
grub_ofconsole_terminfo_output.height = 24;
115
grub_ofconsole_setcursor (struct grub_term_output *term,
118
grub_terminfo_setcursor (term, on);
120
if (!grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_HAS_CURSORONOFF))
123
/* Understood by the Open Firmware flavour in OLPC. */
125
grub_ieee1275_interpret ("cursor-on", 0);
127
grub_ieee1275_interpret ("cursor-off", 0);
131
grub_ofconsole_init_input (struct grub_term_input *term)
135
if (grub_ieee1275_get_integer_property (grub_ieee1275_chosen, "stdin", &stdin_ihandle,
136
sizeof stdin_ihandle, &actual)
137
|| actual != sizeof stdin_ihandle)
138
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "cannot find stdin");
140
return grub_terminfo_input_init (term);
144
grub_ofconsole_init_output (struct grub_term_output *term)
148
/* The latest PowerMacs don't actually initialize the screen for us, so we
149
* use this trick to re-open the output device (but we avoid doing this on
150
* platforms where it's known to be broken). */
151
if (! grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_BROKEN_OUTPUT))
152
grub_ieee1275_interpret ("output-device output", 0);
154
if (grub_ieee1275_get_integer_property (grub_ieee1275_chosen, "stdout", &stdout_ihandle,
155
sizeof stdout_ihandle, &actual)
156
|| actual != sizeof stdout_ihandle)
157
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "cannot find stdout");
159
/* Initialize colors. */
160
if (! grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_CANNOT_SET_COLORS))
163
for (col = 0; col < ARRAY_SIZE (colors); col++)
164
grub_ieee1275_set_color (stdout_ihandle, col, colors[col].red,
165
colors[col].green, colors[col].blue);
167
/* Set the right fg and bg colors. */
168
grub_terminfo_setcolorstate (term, GRUB_TERM_COLOR_NORMAL);
171
grub_ofconsole_dimensions ();
178
struct grub_terminfo_input_state grub_ofconsole_terminfo_input =
183
struct grub_terminfo_output_state grub_ofconsole_terminfo_output =
190
static struct grub_term_input grub_ofconsole_term_input =
193
.init = grub_ofconsole_init_input,
194
.getkey = grub_terminfo_getkey,
195
.data = &grub_ofconsole_terminfo_input
198
static struct grub_term_output grub_ofconsole_term_output =
201
.init = grub_ofconsole_init_output,
202
.putchar = grub_terminfo_putchar,
203
.getxy = grub_terminfo_getxy,
204
.getwh = grub_terminfo_getwh,
205
.gotoxy = grub_terminfo_gotoxy,
206
.cls = grub_terminfo_cls,
207
.setcolorstate = grub_terminfo_setcolorstate,
208
.setcursor = grub_ofconsole_setcursor,
209
.flags = GRUB_TERM_CODE_TYPE_ASCII,
210
.data = &grub_ofconsole_terminfo_output,
211
.normal_color = GRUB_TERM_DEFAULT_NORMAL_COLOR,
212
.highlight_color = GRUB_TERM_DEFAULT_HIGHLIGHT_COLOR,
215
void grub_terminfo_fini (void);
216
void grub_terminfo_init (void);
219
grub_console_init_early (void)
221
grub_term_register_input ("ofconsole", &grub_ofconsole_term_input);
222
grub_term_register_output ("ofconsole", &grub_ofconsole_term_output);
226
grub_console_init_lately (void)
230
if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_NO_ANSI))
235
grub_terminfo_init ();
236
grub_terminfo_output_register (&grub_ofconsole_term_output, type);
240
grub_console_fini (void)
242
grub_term_unregister_input (&grub_ofconsole_term_input);
243
grub_term_unregister_output (&grub_ofconsole_term_output);
244
grub_terminfo_output_unregister (&grub_ofconsole_term_output);
246
grub_terminfo_fini ();