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

« back to all changes in this revision

Viewing changes to term/efi/console.c

Tags: upstream-1.98+20100705
ImportĀ upstreamĀ versionĀ 1.98+20100705

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#include <grub/efi/api.h>
25
25
#include <grub/efi/console.h>
26
26
 
27
 
static grub_uint8_t
 
27
static const grub_uint8_t
28
28
grub_console_standard_color = GRUB_EFI_TEXT_ATTR (GRUB_EFI_YELLOW,
29
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
30
 
37
31
static int read_key = -1;
38
32
 
39
33
static grub_uint32_t
40
34
map_char (grub_uint32_t c)
41
35
{
42
 
  if (c > 0x7f)
 
36
  /* Map some unicode characters to the EFI character.  */
 
37
  switch (c)
43
38
    {
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
 
        }
 
39
    case GRUB_UNICODE_LEFTARROW:
 
40
      c = GRUB_UNICODE_BLACK_LEFT_TRIANGLE;
 
41
      break;
 
42
    case GRUB_UNICODE_UPARROW:
 
43
      c = GRUB_UNICODE_BLACK_UP_TRIANGLE;
 
44
      break;
 
45
    case GRUB_UNICODE_RIGHTARROW:
 
46
      c = GRUB_UNICODE_BLACK_RIGHT_TRIANGLE;
 
47
      break;
 
48
    case GRUB_UNICODE_DOWNARROW:
 
49
      c = GRUB_UNICODE_BLACK_DOWN_TRIANGLE;
 
50
      break;
 
51
    case GRUB_UNICODE_HLINE:
 
52
      c = GRUB_UNICODE_LIGHT_HLINE;
 
53
      break;
 
54
    case GRUB_UNICODE_VLINE:
 
55
      c = GRUB_UNICODE_LIGHT_VLINE;
 
56
      break;
 
57
    case GRUB_UNICODE_CORNER_UL:
 
58
      c = GRUB_UNICODE_LIGHT_CORNER_UL;
 
59
      break;
 
60
    case GRUB_UNICODE_CORNER_UR:
 
61
      c = GRUB_UNICODE_LIGHT_CORNER_UR;
 
62
      break;
 
63
    case GRUB_UNICODE_CORNER_LL:
 
64
      c = GRUB_UNICODE_LIGHT_CORNER_LL;
 
65
      break;
 
66
    case GRUB_UNICODE_CORNER_LR:
 
67
      c = GRUB_UNICODE_LIGHT_CORNER_LR;
 
68
      break;
82
69
    }
83
70
 
84
71
  return c;
85
72
}
86
73
 
87
74
static void
88
 
grub_console_putchar (grub_uint32_t c)
 
75
grub_console_putchar (struct grub_term_output *term __attribute__ ((unused)),
 
76
                      const struct grub_unicode_glyph *c)
89
77
{
90
 
  grub_efi_char16_t str[2];
 
78
  grub_efi_char16_t str[2 + c->ncomb];
91
79
  grub_efi_simple_text_output_interface_t *o;
 
80
  unsigned i, j;
92
81
 
93
82
  o = grub_efi_system_table->con_out;
94
83
 
95
84
  /* 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;
 
85
  if (c->base > 0xffff)
 
86
    str[0] = '?';
 
87
  else
 
88
    str[0] = (grub_efi_char16_t)  map_char (c->base & 0xffff);
 
89
  j = 1;
 
90
  for (i = 0; i < c->ncomb; i++)
 
91
    if (c->base < 0xffff)
 
92
      str[j++] = c->combining[i].code;
 
93
  str[j] = 0;
101
94
 
102
95
  /* Should this test be cached?  */
103
 
  if (c > 0x7f && efi_call_2 (o->test_string, o, str) != GRUB_EFI_SUCCESS)
 
96
  if ((c->base > 0x7f || c->ncomb)
 
97
      && efi_call_2 (o->test_string, o, str) != GRUB_EFI_SUCCESS)
104
98
    return;
105
99
 
106
100
  efi_call_2 (o->output_string, o, str);
107
101
}
108
102
 
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
103
static int
117
 
grub_console_checkkey (void)
 
104
grub_console_checkkey (struct grub_term_input *term __attribute__ ((unused)))
118
105
{
119
106
  grub_efi_simple_input_interface_t *i;
120
107
  grub_efi_input_key_t key;
209
196
}
210
197
 
211
198
static int
212
 
grub_console_getkey (void)
 
199
grub_console_getkey (struct grub_term_input *term)
213
200
{
214
201
  grub_efi_simple_input_interface_t *i;
215
202
  grub_efi_boot_services_t *b;
233
220
      if (status != GRUB_EFI_SUCCESS)
234
221
        return -1;
235
222
 
236
 
      grub_console_checkkey ();
 
223
      grub_console_checkkey (term);
237
224
    }
238
225
  while (read_key < 0);
239
226
 
243
230
}
244
231
 
245
232
static grub_uint16_t
246
 
grub_console_getwh (void)
 
233
grub_console_getwh (struct grub_term_output *term __attribute__ ((unused)))
247
234
{
248
235
  grub_efi_simple_text_output_interface_t *o;
249
236
  grub_efi_uintn_t columns, rows;
260
247
}
261
248
 
262
249
static grub_uint16_t
263
 
grub_console_getxy (void)
 
250
grub_console_getxy (struct grub_term_output *term __attribute__ ((unused)))
264
251
{
265
252
  grub_efi_simple_text_output_interface_t *o;
266
253
 
269
256
}
270
257
 
271
258
static void
272
 
grub_console_gotoxy (grub_uint8_t x, grub_uint8_t y)
 
259
grub_console_gotoxy (struct grub_term_output *term __attribute__ ((unused)),
 
260
                     grub_uint8_t x, grub_uint8_t y)
273
261
{
274
262
  grub_efi_simple_text_output_interface_t *o;
275
263
 
278
266
}
279
267
 
280
268
static void
281
 
grub_console_cls (void)
 
269
grub_console_cls (struct grub_term_output *term __attribute__ ((unused)))
282
270
{
283
271
  grub_efi_simple_text_output_interface_t *o;
284
272
  grub_efi_int32_t orig_attr;
291
279
}
292
280
 
293
281
static void
294
 
grub_console_setcolorstate (grub_term_color_state state)
 
282
grub_console_setcolorstate (struct grub_term_output *term,
 
283
                            grub_term_color_state state)
295
284
{
296
285
  grub_efi_simple_text_output_interface_t *o;
297
286
 
302
291
      efi_call_2 (o->set_attributes, o, grub_console_standard_color);
303
292
      break;
304
293
    case GRUB_TERM_COLOR_NORMAL:
305
 
      efi_call_2 (o->set_attributes, o, grub_console_normal_color);
 
294
      efi_call_2 (o->set_attributes, o, term->normal_color);
306
295
      break;
307
296
    case GRUB_TERM_COLOR_HIGHLIGHT:
308
 
      efi_call_2 (o->set_attributes, o, grub_console_highlight_color);
 
297
      efi_call_2 (o->set_attributes, o, term->highlight_color);
309
298
      break;
310
299
    default:
311
300
      break;
313
302
}
314
303
 
315
304
static void
316
 
grub_console_setcolor (grub_uint8_t normal_color, grub_uint8_t highlight_color)
317
 
{
318
 
  grub_console_normal_color = normal_color;
319
 
  grub_console_highlight_color = highlight_color;
320
 
}
321
 
 
322
 
static void
323
 
grub_console_getcolor (grub_uint8_t *normal_color, grub_uint8_t *highlight_color)
324
 
{
325
 
  *normal_color = grub_console_normal_color;
326
 
  *highlight_color = grub_console_highlight_color;
327
 
}
328
 
 
329
 
static void
330
 
grub_console_setcursor (int on)
 
305
grub_console_setcursor (struct grub_term_output *term __attribute__ ((unused)),
 
306
                        int on)
331
307
{
332
308
  grub_efi_simple_text_output_interface_t *o;
333
309
 
346
322
  {
347
323
    .name = "console",
348
324
    .putchar = grub_console_putchar,
349
 
    .getcharwidth = grub_console_getcharwidth,
350
325
    .getwh = grub_console_getwh,
351
326
    .getxy = grub_console_getxy,
352
327
    .gotoxy = grub_console_gotoxy,
353
328
    .cls = grub_console_cls,
354
329
    .setcolorstate = grub_console_setcolorstate,
355
 
    .setcolor = grub_console_setcolor,
356
 
    .getcolor = grub_console_getcolor,
357
 
    .setcursor = grub_console_setcursor
 
330
    .setcursor = grub_console_setcursor,
 
331
    .normal_color = GRUB_EFI_TEXT_ATTR (GRUB_EFI_LIGHTGRAY,
 
332
                                        GRUB_EFI_BACKGROUND_BLACK),
 
333
    .highlight_color = GRUB_EFI_TEXT_ATTR (GRUB_EFI_BLACK,
 
334
                                           GRUB_EFI_BACKGROUND_LIGHTGRAY),
 
335
    .flags = GRUB_TERM_CODE_TYPE_VISUAL_GLYPHS
358
336
  };
359
337
 
360
338
void