~hamo/ubuntu/precise/grub2/grub2.hi_res

« back to all changes in this revision

Viewing changes to term/efi/console.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson, Colin Watson, Robert Millan, Updated translations
  • Date: 2010-11-22 12:24:56 UTC
  • mfrom: (1.26.4 upstream) (17.3.36 sid)
  • mto: (17.3.43 sid)
  • mto: This revision was merged to the branch mainline in revision 89.
  • Revision ID: james.westby@ubuntu.com-20101122122456-y82z3sfb7k4zfdcc
Tags: 1.99~20101122-1
[ Colin Watson ]
* New Bazaar snapshot.  Too many changes to list in full, but some of the
  more user-visible ones are as follows:
  - GRUB script:
    + Function parameters, "break", "continue", "shift", "setparams",
      "return", and "!".
    + "export" command supports multiple variable names.
    + Multi-line quoted strings support.
    + Wildcard expansion.
  - sendkey support.
  - USB hotunplugging and USB serial support.
  - Rename CD-ROM to cd on BIOS.
  - Add new --boot-directory option to grub-install, grub-reboot, and
    grub-set-default; the old --root-directory option is still accepted
    but was often confusing.
  - Basic btrfs detection/UUID support (but no file reading yet).
  - bash-completion for utilities.
  - If a device is listed in device.map, always assume that it is
    BIOS-visible rather than using extra layers such as LVM or RAID.
  - Add grub-mknetdir script (closes: #550658).
  - Remove deprecated "root" command.
  - Handle RAID devices containing virtio components.
  - GRUB Legacy configuration file support (via grub-menulst2cfg).
  - Keyboard layout support (via grub-mklayout and grub-kbdcomp).
  - Check generated grub.cfg for syntax errors before saving.
  - Pause execution for at most ten seconds if any errors are displayed,
    so that the user has a chance to see them.
  - Support submenus.
  - Write embedding zone using Reed-Solomon, so that it's robust against
    being partially overwritten (closes: #550702, #591416, #593347).
  - GRUB_DISABLE_LINUX_RECOVERY and GRUB_DISABLE_NETBSD_RECOVERY merged
    into a single GRUB_DISABLE_RECOVERY variable.
  - Fix loader memory allocation failure (closes: #551627).
  - Don't call savedefault on recovery entries (closes: #589325).
  - Support triple-indirect blocks on ext2 (closes: #543924).
  - Recognise DDF1 fake RAID (closes: #603354).

[ Robert Millan ]
* Use dpkg architecture wildcards.

[ Updated translations ]
* Slovenian (Vanja Cvelbar).  Closes: #604003
* Dzongkha (dawa pemo via Tenzin Dendup).  Closes: #604102

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  GRUB  --  GRand Unified Bootloader
3
 
 *  Copyright (C) 2006,2007,2008  Free Software Foundation, Inc.
4
 
 *
5
 
 *  GRUB 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 3 of the License, or
8
 
 *  (at your option) any later version.
9
 
 *
10
 
 *  GRUB 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.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
17
 
 */
18
 
 
19
 
#include <grub/term.h>
20
 
#include <grub/misc.h>
21
 
#include <grub/types.h>
22
 
#include <grub/err.h>
23
 
#include <grub/efi/efi.h>
24
 
#include <grub/efi/api.h>
25
 
#include <grub/efi/console.h>
26
 
 
27
 
static grub_uint8_t
28
 
grub_console_standard_color = GRUB_EFI_TEXT_ATTR (GRUB_EFI_YELLOW,
29
 
                                                  GRUB_EFI_BACKGROUND_BLACK);
30
 
static grub_uint8_t
31
 
grub_console_normal_color = GRUB_EFI_TEXT_ATTR (GRUB_EFI_LIGHTGRAY,
32
 
                                                GRUB_EFI_BACKGROUND_BLACK);
33
 
static grub_uint8_t
34
 
grub_console_highlight_color = GRUB_EFI_TEXT_ATTR (GRUB_EFI_BLACK,
35
 
                                                   GRUB_EFI_BACKGROUND_LIGHTGRAY);
36
 
 
37
 
static int read_key = -1;
38
 
 
39
 
static grub_uint32_t
40
 
map_char (grub_uint32_t c)
41
 
{
42
 
  if (c > 0x7f)
43
 
    {
44
 
      /* Map some unicode characters to the EFI character.  */
45
 
      switch (c)
46
 
        {
47
 
        case 0x2190:    /* left arrow */
48
 
          c = 0x25c4;
49
 
          break;
50
 
        case 0x2191:    /* up arrow */
51
 
          c = 0x25b2;
52
 
          break;
53
 
        case 0x2192:    /* right arrow */
54
 
          c = 0x25ba;
55
 
          break;
56
 
        case 0x2193:    /* down arrow */
57
 
          c = 0x25bc;
58
 
          break;
59
 
        case 0x2501:    /* horizontal line */
60
 
          c = 0x2500;
61
 
          break;
62
 
        case 0x2503:    /* vertical line */
63
 
          c = 0x2502;
64
 
          break;
65
 
        case 0x250F:    /* upper-left corner */
66
 
          c = 0x250c;
67
 
          break;
68
 
        case 0x2513:    /* upper-right corner */
69
 
          c = 0x2510;
70
 
          break;
71
 
        case 0x2517:    /* lower-left corner */
72
 
          c = 0x2514;
73
 
          break;
74
 
        case 0x251B:    /* lower-right corner */
75
 
          c = 0x2518;
76
 
          break;
77
 
 
78
 
        default:
79
 
          c = '?';
80
 
          break;
81
 
        }
82
 
    }
83
 
 
84
 
  return c;
85
 
}
86
 
 
87
 
static void
88
 
grub_console_putchar (grub_uint32_t c)
89
 
{
90
 
  grub_efi_char16_t str[2];
91
 
  grub_efi_simple_text_output_interface_t *o;
92
 
 
93
 
  o = grub_efi_system_table->con_out;
94
 
 
95
 
  /* For now, do not try to use a surrogate pair.  */
96
 
  if (c > 0xffff)
97
 
    c = '?';
98
 
 
99
 
  str[0] = (grub_efi_char16_t)  map_char (c & 0xffff);
100
 
  str[1] = 0;
101
 
 
102
 
  /* Should this test be cached?  */
103
 
  if (c > 0x7f && efi_call_2 (o->test_string, o, str) != GRUB_EFI_SUCCESS)
104
 
    return;
105
 
 
106
 
  efi_call_2 (o->output_string, o, str);
107
 
}
108
 
 
109
 
static grub_ssize_t
110
 
grub_console_getcharwidth (grub_uint32_t c __attribute__ ((unused)))
111
 
{
112
 
  /* For now, every printable character has the width 1.  */
113
 
  return 1;
114
 
}
115
 
 
116
 
static int
117
 
grub_console_checkkey (void)
118
 
{
119
 
  grub_efi_simple_input_interface_t *i;
120
 
  grub_efi_input_key_t key;
121
 
  grub_efi_status_t status;
122
 
 
123
 
  if (read_key >= 0)
124
 
    return 1;
125
 
 
126
 
  i = grub_efi_system_table->con_in;
127
 
  status = efi_call_2 (i->read_key_stroke, i, &key);
128
 
#if 0
129
 
  switch (status)
130
 
    {
131
 
    case GRUB_EFI_SUCCESS:
132
 
      {
133
 
        grub_uint16_t xy;
134
 
 
135
 
        xy = grub_getxy ();
136
 
        grub_gotoxy (0, 0);
137
 
        grub_printf ("scan_code=%x,unicode_char=%x  ",
138
 
                     (unsigned) key.scan_code,
139
 
                     (unsigned) key.unicode_char);
140
 
        grub_gotoxy (xy >> 8, xy & 0xff);
141
 
      }
142
 
      break;
143
 
 
144
 
    case GRUB_EFI_NOT_READY:
145
 
      //grub_printf ("not ready   ");
146
 
      break;
147
 
 
148
 
    default:
149
 
      //grub_printf ("device error   ");
150
 
      break;
151
 
    }
152
 
#endif
153
 
 
154
 
  if (status == GRUB_EFI_SUCCESS)
155
 
    {
156
 
      switch (key.scan_code)
157
 
        {
158
 
        case 0x00:
159
 
          read_key = key.unicode_char;
160
 
          break;
161
 
        case 0x01:
162
 
          read_key = 16;
163
 
          break;
164
 
        case 0x02:
165
 
          read_key = 14;
166
 
          break;
167
 
        case 0x03:
168
 
          read_key = 6;
169
 
          break;
170
 
        case 0x04:
171
 
          read_key = 2;
172
 
          break;
173
 
        case 0x05:
174
 
          read_key = 1;
175
 
          break;
176
 
        case 0x06:
177
 
          read_key = 5;
178
 
          break;
179
 
        case 0x07:
180
 
          break;
181
 
        case 0x08:
182
 
          read_key = 4;
183
 
          break;
184
 
        case 0x09:
185
 
          break;
186
 
        case 0x0a:
187
 
          break;
188
 
        case 0x0b:
189
 
          read_key = 24;
190
 
          break;
191
 
        case 0x0c:
192
 
          read_key = 1;
193
 
          break;
194
 
        case 0x0d:
195
 
          read_key = 5;
196
 
          break;
197
 
        case 0x17:
198
 
          read_key = '\e';
199
 
          break;
200
 
        default:
201
 
          break;
202
 
        }
203
 
    }
204
 
 
205
 
  return read_key;
206
 
}
207
 
 
208
 
static int
209
 
grub_console_getkey (void)
210
 
{
211
 
  grub_efi_simple_input_interface_t *i;
212
 
  grub_efi_boot_services_t *b;
213
 
  grub_efi_uintn_t index;
214
 
  grub_efi_status_t status;
215
 
  int key;
216
 
 
217
 
  if (read_key >= 0)
218
 
    {
219
 
      key = read_key;
220
 
      read_key = -1;
221
 
      return key;
222
 
    }
223
 
 
224
 
  i = grub_efi_system_table->con_in;
225
 
  b = grub_efi_system_table->boot_services;
226
 
 
227
 
  do
228
 
    {
229
 
      status = efi_call_3 (b->wait_for_event, 1, &(i->wait_for_key), &index);
230
 
      if (status != GRUB_EFI_SUCCESS)
231
 
        return -1;
232
 
 
233
 
      grub_console_checkkey ();
234
 
    }
235
 
  while (read_key < 0);
236
 
 
237
 
  key = read_key;
238
 
  read_key = -1;
239
 
  return key;
240
 
}
241
 
 
242
 
static grub_uint16_t
243
 
grub_console_getwh (void)
244
 
{
245
 
  grub_efi_simple_text_output_interface_t *o;
246
 
  grub_efi_uintn_t columns, rows;
247
 
 
248
 
  o = grub_efi_system_table->con_out;
249
 
  if (efi_call_4 (o->query_mode, o, o->mode->mode, &columns, &rows) != GRUB_EFI_SUCCESS)
250
 
    {
251
 
      /* Why does this fail?  */
252
 
      columns = 80;
253
 
      rows = 25;
254
 
    }
255
 
 
256
 
  return ((columns << 8) | rows);
257
 
}
258
 
 
259
 
static grub_uint16_t
260
 
grub_console_getxy (void)
261
 
{
262
 
  grub_efi_simple_text_output_interface_t *o;
263
 
 
264
 
  o = grub_efi_system_table->con_out;
265
 
  return ((o->mode->cursor_column << 8) | o->mode->cursor_row);
266
 
}
267
 
 
268
 
static void
269
 
grub_console_gotoxy (grub_uint8_t x, grub_uint8_t y)
270
 
{
271
 
  grub_efi_simple_text_output_interface_t *o;
272
 
 
273
 
  o = grub_efi_system_table->con_out;
274
 
  efi_call_3 (o->set_cursor_position, o, x, y);
275
 
}
276
 
 
277
 
static void
278
 
grub_console_cls (void)
279
 
{
280
 
  grub_efi_simple_text_output_interface_t *o;
281
 
  grub_efi_int32_t orig_attr;
282
 
 
283
 
  o = grub_efi_system_table->con_out;
284
 
  orig_attr = o->mode->attribute;
285
 
  efi_call_2 (o->set_attributes, o, GRUB_EFI_BACKGROUND_BLACK);
286
 
  efi_call_1 (o->clear_screen, o);
287
 
  efi_call_2 (o->set_attributes, o, orig_attr);
288
 
}
289
 
 
290
 
static void
291
 
grub_console_setcolorstate (grub_term_color_state state)
292
 
{
293
 
  grub_efi_simple_text_output_interface_t *o;
294
 
 
295
 
  o = grub_efi_system_table->con_out;
296
 
 
297
 
  switch (state) {
298
 
    case GRUB_TERM_COLOR_STANDARD:
299
 
      efi_call_2 (o->set_attributes, o, grub_console_standard_color);
300
 
      break;
301
 
    case GRUB_TERM_COLOR_NORMAL:
302
 
      efi_call_2 (o->set_attributes, o, grub_console_normal_color);
303
 
      break;
304
 
    case GRUB_TERM_COLOR_HIGHLIGHT:
305
 
      efi_call_2 (o->set_attributes, o, grub_console_highlight_color);
306
 
      break;
307
 
    default:
308
 
      break;
309
 
  }
310
 
}
311
 
 
312
 
static void
313
 
grub_console_setcolor (grub_uint8_t normal_color, grub_uint8_t highlight_color)
314
 
{
315
 
  grub_console_normal_color = normal_color;
316
 
  grub_console_highlight_color = highlight_color;
317
 
}
318
 
 
319
 
static void
320
 
grub_console_getcolor (grub_uint8_t *normal_color, grub_uint8_t *highlight_color)
321
 
{
322
 
  *normal_color = grub_console_normal_color;
323
 
  *highlight_color = grub_console_highlight_color;
324
 
}
325
 
 
326
 
static void
327
 
grub_console_setcursor (int on)
328
 
{
329
 
  grub_efi_simple_text_output_interface_t *o;
330
 
 
331
 
  o = grub_efi_system_table->con_out;
332
 
  efi_call_2 (o->enable_cursor, o, on);
333
 
}
334
 
 
335
 
static struct grub_term_input grub_console_term_input =
336
 
  {
337
 
    .name = "console",
338
 
    .checkkey = grub_console_checkkey,
339
 
    .getkey = grub_console_getkey,
340
 
  };
341
 
 
342
 
static struct grub_term_output grub_console_term_output =
343
 
  {
344
 
    .name = "console",
345
 
    .putchar = grub_console_putchar,
346
 
    .getcharwidth = grub_console_getcharwidth,
347
 
    .getwh = grub_console_getwh,
348
 
    .getxy = grub_console_getxy,
349
 
    .gotoxy = grub_console_gotoxy,
350
 
    .cls = grub_console_cls,
351
 
    .setcolorstate = grub_console_setcolorstate,
352
 
    .setcolor = grub_console_setcolor,
353
 
    .getcolor = grub_console_getcolor,
354
 
    .setcursor = grub_console_setcursor
355
 
  };
356
 
 
357
 
void
358
 
grub_console_init (void)
359
 
{
360
 
  /* FIXME: it is necessary to consider the case where no console control
361
 
     is present but the default is already in text mode.  */
362
 
  if (! grub_efi_set_text_mode (1))
363
 
    {
364
 
      grub_error (GRUB_ERR_BAD_DEVICE, "cannot set text mode");
365
 
      return;
366
 
    }
367
 
 
368
 
  grub_term_register_input ("console", &grub_console_term_input);
369
 
  grub_term_register_output ("console", &grub_console_term_output);
370
 
}
371
 
 
372
 
void
373
 
grub_console_fini (void)
374
 
{
375
 
  grub_term_unregister_input (&grub_console_term_input);
376
 
  grub_term_unregister_output (&grub_console_term_output);
377
 
}