summaryrefslogtreecommitdiffstats
path: root/grub-core/term/i386
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 16:29:51 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 16:29:51 +0000
commit6e7a315eb67cb6c113cf37e1d66c4f11a51a2b3e (patch)
tree32451fa3cdd9321fb2591fada9891b2cb70a9cd1 /grub-core/term/i386
parentInitial commit. (diff)
downloadgrub2-upstream.tar.xz
grub2-upstream.zip
Adding upstream version 2.06.upstream/2.06upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'grub-core/term/i386')
-rw-r--r--grub-core/term/i386/coreboot/cbmemc.c147
-rw-r--r--grub-core/term/i386/pc/console.c310
-rw-r--r--grub-core/term/i386/pc/mda_text.c13
-rw-r--r--grub-core/term/i386/pc/vga_text.c288
4 files changed, 758 insertions, 0 deletions
diff --git a/grub-core/term/i386/coreboot/cbmemc.c b/grub-core/term/i386/coreboot/cbmemc.c
new file mode 100644
index 0000000..cea9b84
--- /dev/null
+++ b/grub-core/term/i386/coreboot/cbmemc.c
@@ -0,0 +1,147 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2013 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <grub/term.h>
+#include <grub/types.h>
+#include <grub/misc.h>
+#include <grub/mm.h>
+#include <grub/time.h>
+#include <grub/terminfo.h>
+#include <grub/dl.h>
+#include <grub/coreboot/lbio.h>
+#include <grub/command.h>
+#include <grub/normal.h>
+
+GRUB_MOD_LICENSE ("GPLv3+");
+
+#define CURSOR_MASK ((1 << 28) - 1)
+#define OVERFLOW (1 << 31)
+
+struct grub_linuxbios_cbmemc
+{
+ grub_uint32_t size;
+ grub_uint32_t cursor;
+ char body[0];
+};
+
+static struct grub_linuxbios_cbmemc *cbmemc;
+
+static void
+put (struct grub_term_output *term __attribute__ ((unused)), const int c)
+{
+ grub_uint32_t flags, cursor;
+ if (!cbmemc)
+ return;
+ flags = cbmemc->cursor & ~CURSOR_MASK;
+ cursor = cbmemc->cursor & CURSOR_MASK;
+ if (cursor >= cbmemc->size)
+ return;
+ cbmemc->body[cursor++] = c;
+ if (cursor >= cbmemc->size)
+ {
+ cursor = 0;
+ flags |= OVERFLOW;
+ }
+ cbmemc->cursor = flags | cursor;
+}
+
+struct grub_terminfo_output_state grub_cbmemc_terminfo_output =
+ {
+ .put = put,
+ .size = { 80, 24 }
+ };
+
+static struct grub_term_output grub_cbmemc_term_output =
+ {
+ .name = "cbmemc",
+ .init = grub_terminfo_output_init,
+ .fini = 0,
+ .putchar = grub_terminfo_putchar,
+ .getxy = grub_terminfo_getxy,
+ .getwh = grub_terminfo_getwh,
+ .gotoxy = grub_terminfo_gotoxy,
+ .cls = grub_terminfo_cls,
+ .setcolorstate = grub_terminfo_setcolorstate,
+ .setcursor = grub_terminfo_setcursor,
+ .flags = GRUB_TERM_CODE_TYPE_ASCII,
+ .data = &grub_cbmemc_terminfo_output,
+ .progress_update_divisor = GRUB_PROGRESS_NO_UPDATE
+ };
+
+static int
+iterate_linuxbios_table (grub_linuxbios_table_item_t table_item,
+ void *data __attribute__ ((unused)))
+{
+ if (table_item->tag != GRUB_LINUXBIOS_MEMBER_CBMEMC)
+ return 0;
+ cbmemc = (struct grub_linuxbios_cbmemc *) (grub_addr_t)
+ *(grub_uint64_t *) (table_item + 1);
+ return 1;
+}
+
+static grub_err_t
+grub_cmd_cbmemc (struct grub_command *cmd __attribute__ ((unused)),
+ int argc __attribute__ ((unused)),
+ char *argv[] __attribute__ ((unused)))
+{
+ grub_size_t size, cursor;
+ struct grub_linuxbios_cbmemc *real_cbmemc;
+
+ if (!cbmemc)
+ return grub_error (GRUB_ERR_IO, "no CBMEM console found");
+
+ real_cbmemc = cbmemc;
+ cbmemc = 0;
+ cursor = real_cbmemc->cursor & CURSOR_MASK;
+ if (!(real_cbmemc->cursor & OVERFLOW) && cursor < real_cbmemc->size)
+ size = cursor;
+ else
+ size = real_cbmemc->size;
+ if (real_cbmemc->cursor & OVERFLOW)
+ {
+ if (cursor > size)
+ cursor = 0;
+ grub_xnputs(real_cbmemc->body + cursor, size - cursor);
+ grub_xnputs(real_cbmemc->body, cursor);
+ }
+ else
+ grub_xnputs(real_cbmemc->body, size);
+ cbmemc = real_cbmemc;
+ return 0;
+}
+
+static grub_command_t cmd;
+
+GRUB_MOD_INIT (cbmemc)
+{
+ grub_linuxbios_table_iterate (iterate_linuxbios_table, 0);
+
+ if (cbmemc)
+ grub_term_register_output ("cbmemc", &grub_cbmemc_term_output);
+
+ cmd =
+ grub_register_command ("cbmemc", grub_cmd_cbmemc,
+ 0, N_("Show CBMEM console content."));
+}
+
+
+GRUB_MOD_FINI (cbmemc)
+{
+ grub_term_unregister_output (&grub_cbmemc_term_output);
+ grub_unregister_command (cmd);
+}
diff --git a/grub-core/term/i386/pc/console.c b/grub-core/term/i386/pc/console.c
new file mode 100644
index 0000000..f6142a2
--- /dev/null
+++ b/grub-core/term/i386/pc/console.c
@@ -0,0 +1,310 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2002,2003,2005,2007,2008,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <grub/machine/memory.h>
+#include <grub/machine/console.h>
+#include <grub/term.h>
+#include <grub/types.h>
+#include <grub/machine/int.h>
+
+static grub_uint8_t grub_console_cur_color = 0x7;
+
+static void
+int10_9 (grub_uint8_t ch, grub_uint16_t n)
+{
+ struct grub_bios_int_registers regs;
+
+ regs.eax = ch | 0x0900;
+ regs.ebx = grub_console_cur_color & 0xff;
+ regs.ecx = n;
+ regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT;
+ grub_bios_interrupt (0x10, &regs);
+}
+
+/*
+ * BIOS call "INT 10H Function 03h" to get cursor position
+ * Call with %ah = 0x03
+ * %bh = page
+ * Returns %ch = starting scan line
+ * %cl = ending scan line
+ * %dh = row (0 is top)
+ * %dl = column (0 is left)
+ */
+
+
+static struct grub_term_coordinate
+grub_console_getxy (struct grub_term_output *term __attribute__ ((unused)))
+{
+ struct grub_bios_int_registers regs;
+
+ regs.eax = 0x0300;
+ regs.ebx = 0;
+ regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT;
+ grub_bios_interrupt (0x10, &regs);
+
+ return (struct grub_term_coordinate) {
+ (regs.edx & 0xff), ((regs.edx & 0xff00) >> 8) };
+}
+
+/*
+ * BIOS call "INT 10H Function 02h" to set cursor position
+ * Call with %ah = 0x02
+ * %bh = page
+ * %dh = row (0 is top)
+ * %dl = column (0 is left)
+ */
+static void
+grub_console_gotoxy (struct grub_term_output *term __attribute__ ((unused)),
+ struct grub_term_coordinate pos)
+{
+ struct grub_bios_int_registers regs;
+
+ /* set page to 0 */
+ regs.ebx = 0;
+ regs.eax = 0x0200;
+ regs.edx = (pos.y << 8) | pos.x;
+ regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT;
+ grub_bios_interrupt (0x10, &regs);
+}
+
+/*
+ *
+ * Put the character C on the console. Because GRUB wants to write a
+ * character with an attribute, this implementation is a bit tricky.
+ * If C is a control character (CR, LF, BEL, BS), use INT 10, AH = 0Eh
+ * (TELETYPE OUTPUT). Otherwise, use INT 10, AH = 9 to write character
+ * with attributes and advance cursor. If we are on the last column,
+ * let BIOS to wrap line correctly.
+ */
+static void
+grub_console_putchar_real (grub_uint8_t c)
+{
+ struct grub_bios_int_registers regs;
+ struct grub_term_coordinate pos;
+
+ if (c == 7 || c == 8 || c == 0xa || c == 0xd)
+ {
+ regs.eax = c | 0x0e00;
+ regs.ebx = 0x0001;
+ regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT;
+ grub_bios_interrupt (0x10, &regs);
+ return;
+ }
+
+ /* get the current position */
+ pos = grub_console_getxy (NULL);
+
+ /* write the character with the attribute */
+ int10_9 (c, 1);
+
+ /* check the column with the width */
+ if (pos.x >= 79)
+ {
+ grub_console_putchar_real (0x0d);
+ grub_console_putchar_real (0x0a);
+ }
+ else
+ grub_console_gotoxy (NULL, (struct grub_term_coordinate) { pos.x + 1,
+ pos.y });
+}
+
+static void
+grub_console_putchar (struct grub_term_output *term __attribute__ ((unused)),
+ const struct grub_unicode_glyph *c)
+{
+ grub_console_putchar_real (c->base);
+}
+
+/*
+ * BIOS call "INT 10H Function 09h" to write character and attribute
+ * Call with %ah = 0x09
+ * %al = (character)
+ * %bh = (page number)
+ * %bl = (attribute)
+ * %cx = (number of times)
+ */
+static void
+grub_console_cls (struct grub_term_output *term)
+{
+ /* move the cursor to the beginning */
+ grub_console_gotoxy (term, (struct grub_term_coordinate) { 0, 0 });
+
+ /* write spaces to the entire screen */
+ int10_9 (' ', 80 * 25);
+
+ /* move back the cursor */
+ grub_console_gotoxy (term, (struct grub_term_coordinate) { 0, 0 });
+}
+
+/*
+ * void grub_console_setcursor (int on)
+ * BIOS call "INT 10H Function 01h" to set cursor type
+ * Call with %ah = 0x01
+ * %ch = cursor starting scanline
+ * %cl = cursor ending scanline
+ */
+static void
+grub_console_setcursor (struct grub_term_output *term __attribute__ ((unused)),
+ int on)
+{
+ static grub_uint16_t console_cursor_shape = 0;
+ struct grub_bios_int_registers regs;
+
+ /* check if the standard cursor shape has already been saved */
+ if (!console_cursor_shape)
+ {
+ regs.eax = 0x0300;
+ regs.ebx = 0;
+ regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT;
+ grub_bios_interrupt (0x10, &regs);
+ console_cursor_shape = regs.ecx;
+ if ((console_cursor_shape >> 8) >= (console_cursor_shape & 0xff))
+ console_cursor_shape = 0x0d0e;
+ }
+ /* set %cx to the designated cursor shape */
+ regs.ecx = on ? console_cursor_shape : 0x2000;
+ regs.eax = 0x0100;
+ regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT;
+ grub_bios_interrupt (0x10, &regs);
+}
+
+/*
+ * if there is a character pending, return it; otherwise return -1
+ * BIOS call "INT 16H Function 01H" to check whether a character is pending
+ * Call with %ah = 0x1
+ * Return:
+ * If key waiting to be input:
+ * %ah = keyboard scan code
+ * %al = ASCII character
+ * Zero flag = clear
+ * else
+ * Zero flag = set
+ * BIOS call "INT 16H Function 00H" to read character from keyboard
+ * Call with %ah = 0x0
+ * Return: %ah = keyboard scan code
+ * %al = ASCII character
+ */
+
+static int
+grub_console_getkey (struct grub_term_input *term __attribute__ ((unused)))
+{
+ const grub_uint16_t bypass_table[] = {
+ 0x0100 | GRUB_TERM_ESC, 0x0f00 | GRUB_TERM_TAB, 0x0e00 | GRUB_TERM_BACKSPACE, 0x1c00 | '\r', 0x1c00 | '\n'
+ };
+ struct grub_bios_int_registers regs;
+ unsigned i;
+
+ /*
+ * Due to a bug in apple's bootcamp implementation, INT 16/AH = 0 would
+ * cause the machine to hang at the second keystroke. However, we can
+ * work around this problem by ensuring the presence of keystroke with
+ * INT 16/AH = 1 before calling INT 16/AH = 0.
+ */
+
+ regs.eax = 0x0100;
+ regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT;
+ grub_bios_interrupt (0x16, &regs);
+ if (regs.flags & GRUB_CPU_INT_FLAGS_ZERO)
+ return GRUB_TERM_NO_KEY;
+
+ regs.eax = 0x0000;
+ regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT;
+ grub_bios_interrupt (0x16, &regs);
+ if (!(regs.eax & 0xff))
+ return ((regs.eax >> 8) & 0xff) | GRUB_TERM_EXTENDED;
+
+ if ((regs.eax & 0xff) >= ' ')
+ return regs.eax & 0xff;
+
+ for (i = 0; i < ARRAY_SIZE (bypass_table); i++)
+ if (bypass_table[i] == (regs.eax & 0xffff))
+ return regs.eax & 0xff;
+
+ return (regs.eax & 0xff) + (('a' - 1) | GRUB_TERM_CTRL);
+}
+
+static const struct grub_machine_bios_data_area *bios_data_area =
+ (struct grub_machine_bios_data_area *) GRUB_MEMORY_MACHINE_BIOS_DATA_AREA_ADDR;
+
+static int
+grub_console_getkeystatus (struct grub_term_input *term __attribute__ ((unused)))
+{
+ /* conveniently GRUB keystatus is modelled after BIOS one. */
+ return bios_data_area->keyboard_flag_lower & ~0x80;
+}
+
+static struct grub_term_coordinate
+grub_console_getwh (struct grub_term_output *term __attribute__ ((unused)))
+{
+ return (struct grub_term_coordinate) { 80, 25 };
+}
+
+static void
+grub_console_setcolorstate (struct grub_term_output *term
+ __attribute__ ((unused)),
+ grub_term_color_state state)
+{
+ switch (state) {
+ case GRUB_TERM_COLOR_STANDARD:
+ grub_console_cur_color = GRUB_TERM_DEFAULT_STANDARD_COLOR & 0x7f;
+ break;
+ case GRUB_TERM_COLOR_NORMAL:
+ grub_console_cur_color = grub_term_normal_color & 0x7f;
+ break;
+ case GRUB_TERM_COLOR_HIGHLIGHT:
+ grub_console_cur_color = grub_term_highlight_color & 0x7f;
+ break;
+ default:
+ break;
+ }
+}
+
+static struct grub_term_input grub_console_term_input =
+ {
+ .name = "console",
+ .getkey = grub_console_getkey,
+ .getkeystatus = grub_console_getkeystatus
+ };
+
+static struct grub_term_output grub_console_term_output =
+ {
+ .name = "console",
+ .putchar = grub_console_putchar,
+ .getwh = grub_console_getwh,
+ .getxy = grub_console_getxy,
+ .gotoxy = grub_console_gotoxy,
+ .cls = grub_console_cls,
+ .setcolorstate = grub_console_setcolorstate,
+ .setcursor = grub_console_setcursor,
+ .flags = GRUB_TERM_CODE_TYPE_CP437,
+ .progress_update_divisor = GRUB_PROGRESS_FAST
+ };
+
+void
+grub_console_init (void)
+{
+ grub_term_register_output ("console", &grub_console_term_output);
+ grub_term_register_input ("console", &grub_console_term_input);
+}
+
+void
+grub_console_fini (void)
+{
+ grub_term_unregister_input (&grub_console_term_input);
+ grub_term_unregister_output (&grub_console_term_output);
+}
diff --git a/grub-core/term/i386/pc/mda_text.c b/grub-core/term/i386/pc/mda_text.c
new file mode 100644
index 0000000..c3a5a17
--- /dev/null
+++ b/grub-core/term/i386/pc/mda_text.c
@@ -0,0 +1,13 @@
+#define MODE_MDA 1
+#include "vga_text.c"
+
+GRUB_MOD_INIT(mda_text)
+{
+ grub_term_register_output ("mda_text", &grub_vga_text_term);
+}
+
+GRUB_MOD_FINI(mda_text)
+{
+ grub_term_unregister_output (&grub_vga_text_term);
+}
+
diff --git a/grub-core/term/i386/pc/vga_text.c b/grub-core/term/i386/pc/vga_text.c
new file mode 100644
index 0000000..88fecc5
--- /dev/null
+++ b/grub-core/term/i386/pc/vga_text.c
@@ -0,0 +1,288 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2007, 2008, 2010 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <grub/dl.h>
+#include <grub/cpu/io.h>
+#include <grub/types.h>
+#include <grub/vga.h>
+#include <grub/term.h>
+
+#if defined (GRUB_MACHINE_COREBOOT)
+#include <grub/machine/console.h>
+#endif
+
+/* MODESET is used for testing to force monochrome or colour mode.
+ You shouldn't use mda_text on vga.
+ */
+#ifdef MODESET
+#include <grub/machine/int.h>
+#endif
+
+#if defined (GRUB_MACHINE_COREBOOT) || defined (GRUB_MACHINE_QEMU) || defined (GRUB_MACHINE_MIPS_QEMU_MIPS) || defined (GRUB_MACHINE_MULTIBOOT)
+#include <grub/machine/console.h>
+#endif
+
+GRUB_MOD_LICENSE ("GPLv3+");
+
+#define COLS 80
+#define ROWS 25
+
+static struct grub_term_coordinate grub_curr_pos;
+
+#ifdef __mips__
+#define VGA_TEXT_SCREEN ((grub_uint16_t *) 0xb00b8000)
+#define cr_read grub_vga_cr_read
+#define cr_write grub_vga_cr_write
+#elif defined (MODE_MDA)
+#define VGA_TEXT_SCREEN ((grub_uint16_t *) 0xb0000)
+#define cr_read grub_vga_cr_bw_read
+#define cr_write grub_vga_cr_bw_write
+#else
+#define VGA_TEXT_SCREEN ((grub_uint16_t *) 0xb8000)
+#define cr_read grub_vga_cr_read
+#define cr_write grub_vga_cr_write
+#endif
+
+static grub_uint8_t cur_color = 0x7;
+
+static void
+screen_write_char (int x, int y, short c)
+{
+ VGA_TEXT_SCREEN[y * COLS + x] = grub_cpu_to_le16 (c);
+}
+
+static short
+screen_read_char (int x, int y)
+{
+ return grub_le_to_cpu16 (VGA_TEXT_SCREEN[y * COLS + x]);
+}
+
+static void
+update_cursor (void)
+{
+ unsigned int pos = grub_curr_pos.y * COLS + grub_curr_pos.x;
+ cr_write (pos >> 8, GRUB_VGA_CR_CURSOR_ADDR_HIGH);
+ cr_write (pos & 0xFF, GRUB_VGA_CR_CURSOR_ADDR_LOW);
+}
+
+static void
+inc_y (void)
+{
+ grub_curr_pos.x = 0;
+ if (grub_curr_pos.y < ROWS - 1)
+ grub_curr_pos.y++;
+ else
+ {
+ int x, y;
+ for (y = 0; y < ROWS - 1; y++)
+ for (x = 0; x < COLS; x++)
+ screen_write_char (x, y, screen_read_char (x, y + 1));
+ for (x = 0; x < COLS; x++)
+ screen_write_char (x, ROWS - 1, ' ' | (cur_color << 8));
+ }
+}
+
+static void
+inc_x (void)
+{
+ if (grub_curr_pos.x >= COLS - 1)
+ inc_y ();
+ else
+ grub_curr_pos.x++;
+}
+
+static void
+grub_vga_text_putchar (struct grub_term_output *term __attribute__ ((unused)),
+ const struct grub_unicode_glyph *c)
+{
+ switch (c->base)
+ {
+ case '\b':
+ if (grub_curr_pos.x != 0)
+ screen_write_char (grub_curr_pos.x--, grub_curr_pos.y, ' ');
+ break;
+ case '\n':
+ inc_y ();
+ break;
+ case '\r':
+ grub_curr_pos.x = 0;
+ break;
+ default:
+ screen_write_char (grub_curr_pos.x, grub_curr_pos.y,
+ c->base | (cur_color << 8));
+ inc_x ();
+ }
+
+ update_cursor ();
+}
+
+static struct grub_term_coordinate
+grub_vga_text_getxy (struct grub_term_output *term __attribute__ ((unused)))
+{
+ return grub_curr_pos;
+}
+
+static void
+grub_vga_text_gotoxy (struct grub_term_output *term __attribute__ ((unused)),
+ struct grub_term_coordinate pos)
+{
+ grub_curr_pos = pos;
+ update_cursor ();
+}
+
+static void
+grub_vga_text_cls (struct grub_term_output *term)
+{
+ int i;
+ for (i = 0; i < ROWS * COLS; i++)
+ VGA_TEXT_SCREEN[i] = grub_cpu_to_le16 (' ' | (cur_color << 8));
+ grub_vga_text_gotoxy (term, (struct grub_term_coordinate) { 0, 0 });
+}
+
+static void
+grub_vga_text_setcursor (struct grub_term_output *term __attribute__ ((unused)),
+ int on)
+{
+ grub_uint8_t old;
+ old = cr_read (GRUB_VGA_CR_CURSOR_START);
+ if (on)
+ cr_write (old & ~GRUB_VGA_CR_CURSOR_START_DISABLE,
+ GRUB_VGA_CR_CURSOR_START);
+ else
+ cr_write (old | GRUB_VGA_CR_CURSOR_START_DISABLE,
+ GRUB_VGA_CR_CURSOR_START);
+}
+
+static grub_err_t
+grub_vga_text_init_real (struct grub_term_output *term)
+{
+#ifdef MODESET
+ struct grub_bios_int_registers regs;
+ regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT;
+
+#ifdef MODE_MDA
+ regs.eax = 7;
+#else
+ regs.eax = 3;
+#endif
+ regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT;
+ grub_bios_interrupt (0x10, &regs);
+#endif
+ grub_vga_text_cls (term);
+ return 0;
+}
+
+static grub_err_t
+grub_vga_text_fini_real (struct grub_term_output *term)
+{
+#ifdef MODESET
+ struct grub_bios_int_registers regs;
+ regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT;
+
+ regs.eax = 3;
+ regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT;
+ grub_bios_interrupt (0x10, &regs);
+#endif
+ grub_vga_text_cls (term);
+ return 0;
+}
+
+static struct grub_term_coordinate
+grub_vga_text_getwh (struct grub_term_output *term __attribute__ ((unused)))
+{
+ return (struct grub_term_coordinate) { 80, 25 };
+}
+
+#ifndef MODE_MDA
+
+static void
+grub_vga_text_setcolorstate (struct grub_term_output *term __attribute__ ((unused)),
+ grub_term_color_state state)
+{
+ switch (state) {
+ case GRUB_TERM_COLOR_STANDARD:
+ cur_color = GRUB_TERM_DEFAULT_STANDARD_COLOR & 0x7f;
+ break;
+ case GRUB_TERM_COLOR_NORMAL:
+ cur_color = grub_term_normal_color & 0x7f;
+ break;
+ case GRUB_TERM_COLOR_HIGHLIGHT:
+ cur_color = grub_term_highlight_color & 0x7f;
+ break;
+ default:
+ break;
+ }
+}
+
+#else
+static void
+grub_vga_text_setcolorstate (struct grub_term_output *term __attribute__ ((unused)),
+ grub_term_color_state state)
+{
+ switch (state) {
+ case GRUB_TERM_COLOR_STANDARD:
+ cur_color = 0x07;
+ break;
+ case GRUB_TERM_COLOR_NORMAL:
+ cur_color = 0x07;
+ break;
+ case GRUB_TERM_COLOR_HIGHLIGHT:
+ cur_color = 0x70;
+ break;
+ default:
+ break;
+ }
+}
+#endif
+
+static struct grub_term_output grub_vga_text_term =
+ {
+#ifdef MODE_MDA
+ .name = "mda_text",
+#else
+ .name = "vga_text",
+#endif
+ .init = grub_vga_text_init_real,
+ .fini = grub_vga_text_fini_real,
+ .putchar = grub_vga_text_putchar,
+ .getwh = grub_vga_text_getwh,
+ .getxy = grub_vga_text_getxy,
+ .gotoxy = grub_vga_text_gotoxy,
+ .cls = grub_vga_text_cls,
+ .setcolorstate = grub_vga_text_setcolorstate,
+ .setcursor = grub_vga_text_setcursor,
+ .flags = GRUB_TERM_CODE_TYPE_CP437,
+ .progress_update_divisor = GRUB_PROGRESS_FAST
+ };
+
+#ifndef MODE_MDA
+
+GRUB_MOD_INIT(vga_text)
+{
+#ifdef GRUB_MACHINE_COREBOOT
+ if (!grub_video_coreboot_fbtable)
+#endif
+ grub_term_register_output ("vga_text", &grub_vga_text_term);
+}
+
+GRUB_MOD_FINI(vga_text)
+{
+ grub_term_unregister_output (&grub_vga_text_term);
+}
+
+#endif