~ubuntu-branches/ubuntu/trusty/grub2/trusty

« back to all changes in this revision

Viewing changes to grub-core/term/i386/pc/console.c

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2014-01-16 15:18:04 UTC
  • mfrom: (17.6.38 experimental)
  • Revision ID: package-import@ubuntu.com-20140116151804-3foouk7fpqcq3sxx
Tags: 2.02~beta2-2
* Convert patch handling to git-dpm.
* Add bi-endian support to ELF parser (Tomohiro B Berry).
* Adjust restore_mkdevicemap.patch to mark get_kfreebsd_version as static,
  to appease "gcc -Werror=missing-prototypes".
* Cherry-pick from upstream:
  - Change grub-macbless' manual page section to 8.
* Install grub-glue-efi, grub-macbless, grub-render-label, and
  grub-syslinux2cfg.
* grub-shell: Pass -no-pad to xorriso when building floppy images.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
#include <grub/types.h>
23
23
#include <grub/machine/int.h>
24
24
 
 
25
static grub_uint8_t grub_console_cur_color = 0x7;
 
26
 
25
27
static void
26
28
int10_9 (grub_uint8_t ch, grub_uint16_t n)
27
29
{
45
47
 */
46
48
 
47
49
 
48
 
static grub_uint16_t
 
50
static struct grub_term_coordinate
49
51
grub_console_getxy (struct grub_term_output *term __attribute__ ((unused)))
50
52
{
51
53
  struct grub_bios_int_registers regs;
55
57
  regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT;  
56
58
  grub_bios_interrupt (0x10, &regs);
57
59
 
58
 
  return ((regs.edx & 0xff) << 8) | ((regs.edx & 0xff00) >> 8);
 
60
  return (struct grub_term_coordinate) {
 
61
    (regs.edx & 0xff), ((regs.edx & 0xff00) >> 8) };
59
62
}
60
63
 
61
64
/*
67
70
 */
68
71
static void
69
72
grub_console_gotoxy (struct grub_term_output *term __attribute__ ((unused)),
70
 
                     grub_uint8_t x, grub_uint8_t y)
 
73
                     struct grub_term_coordinate pos)
71
74
{
72
75
  struct grub_bios_int_registers regs;
73
76
 
74
77
  /* set page to 0 */
75
78
  regs.ebx = 0;
76
79
  regs.eax = 0x0200;
77
 
  regs.edx = (y << 8) | x;
 
80
  regs.edx = (pos.y << 8) | pos.x;
78
81
  regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT;  
79
82
  grub_bios_interrupt (0x10, &regs);
80
83
}
84
87
 * Put the character C on the console. Because GRUB wants to write a
85
88
 * character with an attribute, this implementation is a bit tricky.
86
89
 * If C is a control character (CR, LF, BEL, BS), use INT 10, AH = 0Eh
87
 
 * (TELETYPE OUTPUT). Otherwise, save the original position, put a space,
88
 
 * save the current position, restore the original position, write the
89
 
 * character and the attribute, and restore the current position.
90
 
 *
91
 
 * The reason why this is so complicated is that there is no easy way to
92
 
 * get the height of the screen, and the TELETYPE OUTPUT BIOS call doesn't
93
 
 * support setting a background attribute.
 
90
 * (TELETYPE OUTPUT). Otherwise, use INT 10, AH = 9 to write character
 
91
 * with attributes and advance cursor. If we are on the last column,
 
92
 * let BIOS to wrap line correctly.
94
93
 */
95
94
static void
96
95
grub_console_putchar_real (grub_uint8_t c)
97
96
{
98
97
  struct grub_bios_int_registers regs;
99
 
  grub_uint16_t pos;
 
98
  struct grub_term_coordinate pos;
100
99
 
101
100
  if (c == 7 || c == 8 || c == 0xa || c == 0xd)
102
101
    {
110
109
  /* get the current position */
111
110
  pos = grub_console_getxy (NULL);
112
111
  
 
112
  /* write the character with the attribute */
 
113
  int10_9 (c, 1);
 
114
 
113
115
  /* check the column with the width */
114
 
  if ((pos & 0xff00) >= (79 << 8))
 
116
  if (pos.x >= 79)
115
117
    {
116
118
      grub_console_putchar_real (0x0d);
117
119
      grub_console_putchar_real (0x0a);
118
 
      /* get the current position */
119
 
      pos = grub_console_getxy (NULL);
120
120
    }
121
 
 
122
 
  /* write the character with the attribute */
123
 
  int10_9 (c, 1);
124
 
 
125
 
  grub_console_gotoxy (NULL, ((pos & 0xff00) >> 8) + 1, (pos & 0xff));
 
121
  else
 
122
    grub_console_gotoxy (NULL, (struct grub_term_coordinate) { pos.x + 1,
 
123
          pos.y });
126
124
}
127
125
 
128
126
static void
144
142
grub_console_cls (struct grub_term_output *term)
145
143
{
146
144
  /* move the cursor to the beginning */
147
 
  grub_console_gotoxy (term, 0, 0);
 
145
  grub_console_gotoxy (term, (struct grub_term_coordinate) { 0, 0 });
148
146
 
149
147
  /* write spaces to the entire screen */
150
148
  int10_9 (' ', 80 * 25);
151
149
 
152
150
  /* move back the cursor */
153
 
  grub_console_gotoxy (term, 0, 0);
 
151
  grub_console_gotoxy (term, (struct grub_term_coordinate) { 0, 0 });
154
152
}
155
153
 
156
154
/*
250
248
  return bios_data_area->keyboard_flag_lower & ~0x80;
251
249
}
252
250
 
 
251
static struct grub_term_coordinate
 
252
grub_console_getwh (struct grub_term_output *term __attribute__ ((unused)))
 
253
{
 
254
  return (struct grub_term_coordinate) { 80, 25 };
 
255
}
 
256
 
 
257
static void
 
258
grub_console_setcolorstate (struct grub_term_output *term
 
259
                            __attribute__ ((unused)),
 
260
                            grub_term_color_state state)
 
261
{
 
262
  switch (state) {
 
263
    case GRUB_TERM_COLOR_STANDARD:
 
264
      grub_console_cur_color = GRUB_TERM_DEFAULT_STANDARD_COLOR & 0x7f;
 
265
      break;
 
266
    case GRUB_TERM_COLOR_NORMAL:
 
267
      grub_console_cur_color = grub_term_normal_color & 0x7f;
 
268
      break;
 
269
    case GRUB_TERM_COLOR_HIGHLIGHT:
 
270
      grub_console_cur_color = grub_term_highlight_color & 0x7f;
 
271
      break;
 
272
    default:
 
273
      break;
 
274
  }
 
275
}
 
276
 
253
277
static struct grub_term_input grub_console_term_input =
254
278
  {
255
279
    .name = "console",
268
292
    .setcolorstate = grub_console_setcolorstate,
269
293
    .setcursor = grub_console_setcursor,
270
294
    .flags = GRUB_TERM_CODE_TYPE_CP437,
271
 
    .normal_color = GRUB_TERM_DEFAULT_NORMAL_COLOR,
272
 
    .highlight_color = GRUB_TERM_DEFAULT_HIGHLIGHT_COLOR,
 
295
    .progress_update_divisor = GRUB_PROGRESS_FAST
273
296
  };
274
297
 
275
298
void