automake commit without merge history
This commit is contained in:
parent
265d68cd10
commit
8c41176882
810 changed files with 4980 additions and 2508 deletions
83
grub-core/term/i386/pc/console.c
Normal file
83
grub-core/term/i386/pc/console.c
Normal file
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* 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>
|
||||
|
||||
static const struct grub_machine_bios_data_area *bios_data_area =
|
||||
(struct grub_machine_bios_data_area *) GRUB_MEMORY_MACHINE_BIOS_DATA_AREA_ADDR;
|
||||
|
||||
#define KEYBOARD_LEFT_SHIFT (1 << 0)
|
||||
#define KEYBOARD_RIGHT_SHIFT (1 << 1)
|
||||
#define KEYBOARD_CTRL (1 << 2)
|
||||
#define KEYBOARD_ALT (1 << 3)
|
||||
|
||||
static int
|
||||
grub_console_getkeystatus (void)
|
||||
{
|
||||
grub_uint8_t status = bios_data_area->keyboard_flag_lower;
|
||||
int mods = 0;
|
||||
|
||||
if (status & (KEYBOARD_LEFT_SHIFT | KEYBOARD_RIGHT_SHIFT))
|
||||
mods |= GRUB_TERM_STATUS_SHIFT;
|
||||
if (status & KEYBOARD_CTRL)
|
||||
mods |= GRUB_TERM_STATUS_CTRL;
|
||||
if (status & KEYBOARD_ALT)
|
||||
mods |= GRUB_TERM_STATUS_ALT;
|
||||
|
||||
return mods;
|
||||
}
|
||||
|
||||
static struct grub_term_input grub_console_term_input =
|
||||
{
|
||||
.name = "console",
|
||||
.checkkey = grub_console_checkkey,
|
||||
.getkey = grub_console_getkey,
|
||||
.getkeystatus = grub_console_getkeystatus,
|
||||
};
|
||||
|
||||
static struct grub_term_output grub_console_term_output =
|
||||
{
|
||||
.name = "console",
|
||||
.putchar = grub_console_putchar,
|
||||
.getcharwidth = grub_console_getcharwidth,
|
||||
.getwh = grub_console_getwh,
|
||||
.getxy = grub_console_getxy,
|
||||
.gotoxy = grub_console_gotoxy,
|
||||
.cls = grub_console_cls,
|
||||
.setcolorstate = grub_console_setcolorstate,
|
||||
.setcolor = grub_console_setcolor,
|
||||
.getcolor = grub_console_getcolor,
|
||||
.setcursor = grub_console_setcursor
|
||||
};
|
||||
|
||||
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);
|
||||
}
|
513
grub-core/term/i386/pc/vga.c
Normal file
513
grub-core/term/i386/pc/vga.c
Normal file
|
@ -0,0 +1,513 @@
|
|||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2000,2001,2002,2003,2004,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/>.
|
||||
*/
|
||||
|
||||
// TODO: Deprecated and broken. Needs to be converted to Video Driver!
|
||||
|
||||
#include <grub/machine/vga.h>
|
||||
#include <grub/machine/console.h>
|
||||
#include <grub/cpu/io.h>
|
||||
#include <grub/term.h>
|
||||
#include <grub/types.h>
|
||||
#include <grub/dl.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/font.h>
|
||||
|
||||
#define DEBUG_VGA 0
|
||||
|
||||
#define VGA_WIDTH 640
|
||||
#define VGA_HEIGHT 350
|
||||
#define CHAR_WIDTH 8
|
||||
#define CHAR_HEIGHT 16
|
||||
#define TEXT_WIDTH (VGA_WIDTH / CHAR_WIDTH)
|
||||
#define TEXT_HEIGHT (VGA_HEIGHT / CHAR_HEIGHT)
|
||||
#define VGA_MEM ((grub_uint8_t *) GRUB_MEMORY_MACHINE_VGA_ADDR)
|
||||
#define PAGE_OFFSET(x) ((x) * (VGA_WIDTH * VGA_HEIGHT / 8))
|
||||
|
||||
#define DEFAULT_FG_COLOR 0xa
|
||||
#define DEFAULT_BG_COLOR 0x0
|
||||
|
||||
struct colored_char
|
||||
{
|
||||
/* An Unicode codepoint. */
|
||||
grub_uint32_t code;
|
||||
|
||||
/* Color indexes. */
|
||||
unsigned char fg_color;
|
||||
unsigned char bg_color;
|
||||
|
||||
/* The width of this character minus one. */
|
||||
unsigned char width;
|
||||
|
||||
/* The column index of this character. */
|
||||
unsigned char index;
|
||||
};
|
||||
|
||||
static unsigned char text_mode;
|
||||
static unsigned xpos, ypos;
|
||||
static int cursor_state;
|
||||
static unsigned char fg_color, bg_color;
|
||||
static struct colored_char text_buf[TEXT_WIDTH * TEXT_HEIGHT];
|
||||
static unsigned char saved_map_mask;
|
||||
static int page = 0;
|
||||
static grub_font_t font = 0;
|
||||
|
||||
#define SEQUENCER_ADDR_PORT 0x3C4
|
||||
#define SEQUENCER_DATA_PORT 0x3C5
|
||||
#define MAP_MASK_REGISTER 0x02
|
||||
|
||||
#define CRTC_ADDR_PORT 0x3D4
|
||||
#define CRTC_DATA_PORT 0x3D5
|
||||
#define START_ADDR_HIGH_REGISTER 0x0C
|
||||
#define START_ADDR_LOW_REGISTER 0x0D
|
||||
|
||||
#define GRAPHICS_ADDR_PORT 0x3CE
|
||||
#define GRAPHICS_DATA_PORT 0x3CF
|
||||
#define READ_MAP_REGISTER 0x04
|
||||
|
||||
#define INPUT_STATUS1_REGISTER 0x3DA
|
||||
#define INPUT_STATUS1_VERTR_BIT 0x08
|
||||
|
||||
static inline void
|
||||
wait_vretrace (void)
|
||||
{
|
||||
/* Wait until there is a vertical retrace. */
|
||||
while (! (grub_inb (INPUT_STATUS1_REGISTER) & INPUT_STATUS1_VERTR_BIT));
|
||||
}
|
||||
|
||||
/* Get Map Mask Register. */
|
||||
static unsigned char
|
||||
get_map_mask (void)
|
||||
{
|
||||
unsigned char old_addr;
|
||||
unsigned char old_data;
|
||||
|
||||
old_addr = grub_inb (SEQUENCER_ADDR_PORT);
|
||||
grub_outb (MAP_MASK_REGISTER, SEQUENCER_ADDR_PORT);
|
||||
|
||||
old_data = grub_inb (SEQUENCER_DATA_PORT);
|
||||
|
||||
grub_outb (old_addr, SEQUENCER_ADDR_PORT);
|
||||
|
||||
return old_data;
|
||||
}
|
||||
|
||||
/* Set Map Mask Register. */
|
||||
static void
|
||||
set_map_mask (unsigned char mask)
|
||||
{
|
||||
unsigned char old_addr;
|
||||
|
||||
old_addr = grub_inb (SEQUENCER_ADDR_PORT);
|
||||
grub_outb (MAP_MASK_REGISTER, SEQUENCER_ADDR_PORT);
|
||||
|
||||
grub_outb (mask, SEQUENCER_DATA_PORT);
|
||||
|
||||
grub_outb (old_addr, SEQUENCER_ADDR_PORT);
|
||||
}
|
||||
|
||||
/* Set Read Map Register. */
|
||||
static void
|
||||
set_read_map (unsigned char map)
|
||||
{
|
||||
unsigned char old_addr;
|
||||
|
||||
old_addr = grub_inb (GRAPHICS_ADDR_PORT);
|
||||
|
||||
grub_outb (READ_MAP_REGISTER, GRAPHICS_ADDR_PORT);
|
||||
grub_outb (map, GRAPHICS_DATA_PORT);
|
||||
|
||||
grub_outb (old_addr, GRAPHICS_ADDR_PORT);
|
||||
}
|
||||
|
||||
/* Set start address. */
|
||||
static void
|
||||
set_start_address (unsigned int start)
|
||||
{
|
||||
unsigned char old_addr;
|
||||
|
||||
old_addr = grub_inb (CRTC_ADDR_PORT);
|
||||
|
||||
grub_outb (START_ADDR_LOW_REGISTER, CRTC_ADDR_PORT);
|
||||
grub_outb (start & 0xFF, CRTC_DATA_PORT);
|
||||
|
||||
grub_outb (START_ADDR_HIGH_REGISTER, CRTC_ADDR_PORT);
|
||||
grub_outb (start >> 8, CRTC_DATA_PORT);
|
||||
|
||||
grub_outb (old_addr, CRTC_ADDR_PORT);
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_vga_mod_init (void)
|
||||
{
|
||||
text_mode = grub_vga_set_mode (0x10);
|
||||
cursor_state = 1;
|
||||
fg_color = DEFAULT_FG_COLOR;
|
||||
bg_color = DEFAULT_BG_COLOR;
|
||||
saved_map_mask = get_map_mask ();
|
||||
set_map_mask (0x0f);
|
||||
set_start_address (PAGE_OFFSET (page));
|
||||
font = grub_font_get (""); /* Choose any font, for now. */
|
||||
if (!font)
|
||||
return grub_error (GRUB_ERR_BAD_FONT, "no font loaded");
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_vga_mod_fini (void)
|
||||
{
|
||||
set_map_mask (saved_map_mask);
|
||||
grub_vga_set_mode (text_mode);
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static int
|
||||
check_vga_mem (void *p)
|
||||
{
|
||||
return (p >= (void *) (VGA_MEM + PAGE_OFFSET (page))
|
||||
&& p <= (void *) (VGA_MEM + PAGE_OFFSET (page)
|
||||
+ VGA_WIDTH * VGA_HEIGHT / 8));
|
||||
}
|
||||
|
||||
static void
|
||||
write_char (void)
|
||||
{
|
||||
struct colored_char *p = text_buf + xpos + ypos * TEXT_WIDTH;
|
||||
struct grub_font_glyph *glyph;
|
||||
unsigned char *mem_base;
|
||||
unsigned plane;
|
||||
|
||||
mem_base = (VGA_MEM + xpos +
|
||||
ypos * CHAR_HEIGHT * TEXT_WIDTH + PAGE_OFFSET (page)) - p->index;
|
||||
p -= p->index;
|
||||
|
||||
/* Get glyph for character. */
|
||||
glyph = grub_font_get_glyph (font, p->code);
|
||||
|
||||
for (plane = 0x01; plane <= 0x08; plane <<= 1)
|
||||
{
|
||||
unsigned y;
|
||||
unsigned offset;
|
||||
unsigned char *mem;
|
||||
|
||||
set_map_mask (plane);
|
||||
|
||||
for (y = 0, offset = 0, mem = mem_base;
|
||||
y < CHAR_HEIGHT;
|
||||
y++, mem += TEXT_WIDTH)
|
||||
{
|
||||
/* TODO Re-implement glyph drawing for vga module. */
|
||||
#if 0
|
||||
unsigned i;
|
||||
|
||||
unsigned char_width = 1; /* TODO Figure out wide characters. */
|
||||
for (i = 0; i < char_width && offset < 32; i++)
|
||||
{
|
||||
unsigned char fg_mask, bg_mask;
|
||||
|
||||
fg_mask = (p->fg_color & plane) ? glyph->bitmap[offset] : 0;
|
||||
bg_mask = (p->bg_color & plane) ? ~(glyph->bitmap[offset]) : 0;
|
||||
offset++;
|
||||
|
||||
if (check_vga_mem (mem + i))
|
||||
mem[i] = (fg_mask | bg_mask);
|
||||
}
|
||||
#endif /* 0 */
|
||||
}
|
||||
}
|
||||
|
||||
set_map_mask (0x0f);
|
||||
}
|
||||
|
||||
static void
|
||||
write_cursor (void)
|
||||
{
|
||||
unsigned char *mem = (VGA_MEM + PAGE_OFFSET (page) + xpos
|
||||
+ (ypos * CHAR_HEIGHT + CHAR_HEIGHT - 3) * TEXT_WIDTH);
|
||||
if (check_vga_mem (mem))
|
||||
*mem = 0xff;
|
||||
|
||||
mem += TEXT_WIDTH;
|
||||
if (check_vga_mem (mem))
|
||||
*mem = 0xff;
|
||||
}
|
||||
|
||||
static void
|
||||
scroll_up (void)
|
||||
{
|
||||
unsigned i;
|
||||
unsigned plane;
|
||||
|
||||
/* Do all the work in the other page. */
|
||||
grub_memmove (text_buf, text_buf + TEXT_WIDTH,
|
||||
sizeof (struct colored_char) * TEXT_WIDTH * (TEXT_HEIGHT - 1));
|
||||
|
||||
for (i = TEXT_WIDTH * (TEXT_HEIGHT - 1); i < TEXT_WIDTH * TEXT_HEIGHT; i++)
|
||||
{
|
||||
text_buf[i].code = ' ';
|
||||
text_buf[i].fg_color = 0;
|
||||
text_buf[i].bg_color = 0;
|
||||
text_buf[i].width = 0;
|
||||
text_buf[i].index = 0;
|
||||
}
|
||||
|
||||
for (plane = 1; plane <= 4; plane++)
|
||||
{
|
||||
set_read_map (plane);
|
||||
set_map_mask (1 << plane);
|
||||
grub_memmove (VGA_MEM + PAGE_OFFSET (1 - page), VGA_MEM
|
||||
+ PAGE_OFFSET (page) + VGA_WIDTH * CHAR_HEIGHT / 8,
|
||||
VGA_WIDTH * (VGA_HEIGHT - CHAR_HEIGHT) / 8);
|
||||
}
|
||||
|
||||
set_map_mask (0x0f);
|
||||
grub_memset (VGA_MEM + PAGE_OFFSET (1 - page)
|
||||
+ VGA_WIDTH * (VGA_HEIGHT - CHAR_HEIGHT) / 8, 0,
|
||||
VGA_WIDTH * CHAR_HEIGHT / 8);
|
||||
|
||||
/* Activate the other page. */
|
||||
page = 1 - page;
|
||||
wait_vretrace ();
|
||||
set_start_address (PAGE_OFFSET (page));
|
||||
}
|
||||
|
||||
static void
|
||||
grub_vga_putchar (grub_uint32_t c)
|
||||
{
|
||||
#if DEBUG_VGA
|
||||
static int show = 1;
|
||||
#endif
|
||||
|
||||
if (c == '\a')
|
||||
/* FIXME */
|
||||
return;
|
||||
|
||||
if (c == '\b' || c == '\n' || c == '\r')
|
||||
{
|
||||
/* Erase current cursor, if any. */
|
||||
if (cursor_state)
|
||||
write_char ();
|
||||
|
||||
switch (c)
|
||||
{
|
||||
case '\b':
|
||||
if (xpos > 0)
|
||||
xpos--;
|
||||
break;
|
||||
|
||||
case '\n':
|
||||
if (ypos >= TEXT_HEIGHT - 1)
|
||||
scroll_up ();
|
||||
else
|
||||
ypos++;
|
||||
break;
|
||||
|
||||
case '\r':
|
||||
xpos = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
if (cursor_state)
|
||||
write_cursor ();
|
||||
}
|
||||
else
|
||||
{
|
||||
struct grub_font_glyph *glyph;
|
||||
struct colored_char *p;
|
||||
unsigned char_width = 1;
|
||||
|
||||
glyph = grub_font_get_glyph(font, c);
|
||||
|
||||
if (xpos + char_width > TEXT_WIDTH)
|
||||
grub_putchar ('\n');
|
||||
|
||||
p = text_buf + xpos + ypos * TEXT_WIDTH;
|
||||
p->code = c;
|
||||
p->fg_color = fg_color;
|
||||
p->bg_color = bg_color;
|
||||
p->width = char_width - 1;
|
||||
p->index = 0;
|
||||
|
||||
if (char_width > 1)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
for (i = 1; i < char_width; i++)
|
||||
{
|
||||
p[i].code = ' ';
|
||||
p[i].width = char_width - 1;
|
||||
p[i].index = i;
|
||||
}
|
||||
}
|
||||
|
||||
write_char ();
|
||||
|
||||
xpos += char_width;
|
||||
if (xpos >= TEXT_WIDTH)
|
||||
{
|
||||
xpos = 0;
|
||||
|
||||
if (ypos >= TEXT_HEIGHT - 1)
|
||||
scroll_up ();
|
||||
else
|
||||
ypos++;
|
||||
}
|
||||
|
||||
if (cursor_state)
|
||||
write_cursor ();
|
||||
}
|
||||
|
||||
#if DEBUG_VGA
|
||||
if (show)
|
||||
{
|
||||
grub_uint16_t pos = grub_getxy ();
|
||||
|
||||
show = 0;
|
||||
grub_gotoxy (0, 0);
|
||||
grub_printf ("[%u:%u]", (unsigned) (pos >> 8), (unsigned) (pos & 0xff));
|
||||
grub_gotoxy (pos >> 8, pos & 0xff);
|
||||
show = 1;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static grub_ssize_t
|
||||
grub_vga_getcharwidth (grub_uint32_t c)
|
||||
{
|
||||
#if 0
|
||||
struct grub_font_glyph glyph;
|
||||
|
||||
glyph = grub_font_get_glyph (c);
|
||||
|
||||
return glyph.char_width;
|
||||
#else
|
||||
(void) c; /* Prevent warning. */
|
||||
return 1; /* TODO Fix wide characters? */
|
||||
#endif
|
||||
}
|
||||
|
||||
static grub_uint16_t
|
||||
grub_vga_getwh (void)
|
||||
{
|
||||
return (TEXT_WIDTH << 8) | TEXT_HEIGHT;
|
||||
}
|
||||
|
||||
static grub_uint16_t
|
||||
grub_vga_getxy (void)
|
||||
{
|
||||
return ((xpos << 8) | ypos);
|
||||
}
|
||||
|
||||
static void
|
||||
grub_vga_gotoxy (grub_uint8_t x, grub_uint8_t y)
|
||||
{
|
||||
if (x >= TEXT_WIDTH || y >= TEXT_HEIGHT)
|
||||
{
|
||||
grub_error (GRUB_ERR_OUT_OF_RANGE, "invalid point (%u,%u)",
|
||||
(unsigned) x, (unsigned) y);
|
||||
return;
|
||||
}
|
||||
|
||||
if (cursor_state)
|
||||
write_char ();
|
||||
|
||||
xpos = x;
|
||||
ypos = y;
|
||||
|
||||
if (cursor_state)
|
||||
write_cursor ();
|
||||
}
|
||||
|
||||
static void
|
||||
grub_vga_cls (void)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
wait_vretrace ();
|
||||
for (i = 0; i < TEXT_WIDTH * TEXT_HEIGHT; i++)
|
||||
{
|
||||
text_buf[i].code = ' ';
|
||||
text_buf[i].fg_color = 0;
|
||||
text_buf[i].bg_color = 0;
|
||||
text_buf[i].width = 0;
|
||||
text_buf[i].index = 0;
|
||||
}
|
||||
|
||||
grub_memset (VGA_MEM + PAGE_OFFSET (page), 0, VGA_WIDTH * VGA_HEIGHT / 8);
|
||||
|
||||
xpos = ypos = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
grub_vga_setcolorstate (grub_term_color_state state)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case GRUB_TERM_COLOR_STANDARD:
|
||||
case GRUB_TERM_COLOR_NORMAL:
|
||||
fg_color = DEFAULT_FG_COLOR;
|
||||
bg_color = DEFAULT_BG_COLOR;
|
||||
break;
|
||||
case GRUB_TERM_COLOR_HIGHLIGHT:
|
||||
fg_color = DEFAULT_BG_COLOR;
|
||||
bg_color = DEFAULT_FG_COLOR;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
grub_vga_setcursor (int on)
|
||||
{
|
||||
if (cursor_state != on)
|
||||
{
|
||||
if (cursor_state)
|
||||
write_char ();
|
||||
else
|
||||
write_cursor ();
|
||||
|
||||
cursor_state = on;
|
||||
}
|
||||
}
|
||||
|
||||
static struct grub_term_output grub_vga_term =
|
||||
{
|
||||
.name = "vga",
|
||||
.init = grub_vga_mod_init,
|
||||
.fini = grub_vga_mod_fini,
|
||||
.putchar = grub_vga_putchar,
|
||||
.getcharwidth = grub_vga_getcharwidth,
|
||||
.getwh = grub_vga_getwh,
|
||||
.getxy = grub_vga_getxy,
|
||||
.gotoxy = grub_vga_gotoxy,
|
||||
.cls = grub_vga_cls,
|
||||
.setcolorstate = grub_vga_setcolorstate,
|
||||
.setcursor = grub_vga_setcursor,
|
||||
.flags = 0,
|
||||
};
|
||||
|
||||
GRUB_MOD_INIT(vga)
|
||||
{
|
||||
grub_term_register_output ("vga", &grub_vga_term);
|
||||
}
|
||||
|
||||
GRUB_MOD_FINI(vga)
|
||||
{
|
||||
grub_term_unregister_output (&grub_vga_term);
|
||||
}
|
177
grub-core/term/i386/pc/vga_text.c
Normal file
177
grub-core/term/i386/pc/vga_text.c
Normal file
|
@ -0,0 +1,177 @@
|
|||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2007, 2008 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/i386/vga_common.h>
|
||||
#include <grub/i386/io.h>
|
||||
#include <grub/types.h>
|
||||
|
||||
#define COLS 80
|
||||
#define ROWS 25
|
||||
|
||||
static int grub_curr_x, grub_curr_y;
|
||||
|
||||
#define VGA_TEXT_SCREEN 0xb8000
|
||||
|
||||
#define CRTC_ADDR_PORT 0x3D4
|
||||
#define CRTC_DATA_PORT 0x3D5
|
||||
|
||||
#define CRTC_CURSOR 0x0a
|
||||
#define CRTC_CURSOR_ADDR_HIGH 0x0e
|
||||
#define CRTC_CURSOR_ADDR_LOW 0x0f
|
||||
|
||||
#define CRTC_CURSOR_DISABLE (1 << 5)
|
||||
|
||||
static void
|
||||
screen_write_char (int x, int y, short c)
|
||||
{
|
||||
((short *) VGA_TEXT_SCREEN)[y * COLS + x] = c;
|
||||
}
|
||||
|
||||
static short
|
||||
screen_read_char (int x, int y)
|
||||
{
|
||||
return ((short *) VGA_TEXT_SCREEN)[y * COLS + x];
|
||||
}
|
||||
|
||||
static void
|
||||
update_cursor (void)
|
||||
{
|
||||
unsigned int pos = grub_curr_y * COLS + grub_curr_x;
|
||||
grub_outb (CRTC_CURSOR_ADDR_HIGH, CRTC_ADDR_PORT);
|
||||
grub_outb (pos >> 8, CRTC_DATA_PORT);
|
||||
grub_outb (CRTC_CURSOR_ADDR_LOW, CRTC_ADDR_PORT);
|
||||
grub_outb (pos & 0xFF, CRTC_DATA_PORT);
|
||||
}
|
||||
|
||||
static void
|
||||
inc_y (void)
|
||||
{
|
||||
grub_curr_x = 0;
|
||||
if (grub_curr_y < ROWS - 1)
|
||||
grub_curr_y++;
|
||||
else
|
||||
{
|
||||
int x, y;
|
||||
for (y = 0; y < ROWS; y++)
|
||||
for (x = 0; x < COLS; x++)
|
||||
screen_write_char (x, y, screen_read_char (x, y + 1));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
inc_x (void)
|
||||
{
|
||||
if (grub_curr_x >= COLS - 1)
|
||||
inc_y ();
|
||||
else
|
||||
grub_curr_x++;
|
||||
}
|
||||
|
||||
void
|
||||
grub_console_real_putchar (int c)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case '\b':
|
||||
if (grub_curr_x != 0)
|
||||
screen_write_char (grub_curr_x--, grub_curr_y, ' ');
|
||||
break;
|
||||
case '\n':
|
||||
inc_y ();
|
||||
break;
|
||||
case '\r':
|
||||
grub_curr_x = 0;
|
||||
break;
|
||||
default:
|
||||
screen_write_char (grub_curr_x,
|
||||
grub_curr_y, c | (grub_console_cur_color << 8));
|
||||
inc_x ();
|
||||
}
|
||||
|
||||
update_cursor ();
|
||||
}
|
||||
|
||||
static grub_uint16_t
|
||||
grub_vga_text_getxy (void)
|
||||
{
|
||||
return (grub_curr_x << 8) | grub_curr_y;
|
||||
}
|
||||
|
||||
static void
|
||||
grub_vga_text_gotoxy (grub_uint8_t x, grub_uint8_t y)
|
||||
{
|
||||
grub_curr_x = x;
|
||||
grub_curr_y = y;
|
||||
update_cursor ();
|
||||
}
|
||||
|
||||
static void
|
||||
grub_vga_text_cls (void)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < ROWS * COLS; i++)
|
||||
((short *) VGA_TEXT_SCREEN)[i] = ' ' | (grub_console_cur_color << 8);
|
||||
grub_vga_text_gotoxy (0, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
grub_vga_text_setcursor (int on)
|
||||
{
|
||||
grub_uint8_t old;
|
||||
grub_outb (CRTC_CURSOR, CRTC_ADDR_PORT);
|
||||
old = grub_inb (CRTC_DATA_PORT);
|
||||
if (on)
|
||||
grub_outb (old & ~CRTC_CURSOR_DISABLE, CRTC_DATA_PORT);
|
||||
else
|
||||
grub_outb (old | CRTC_CURSOR_DISABLE, CRTC_DATA_PORT);
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_vga_text_init_fini (void)
|
||||
{
|
||||
grub_vga_text_cls ();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct grub_term_output grub_vga_text_term =
|
||||
{
|
||||
.name = "vga_text",
|
||||
.init = grub_vga_text_init_fini,
|
||||
.fini = grub_vga_text_init_fini,
|
||||
.putchar = grub_console_putchar,
|
||||
.getcharwidth = grub_console_getcharwidth,
|
||||
.getwh = grub_console_getwh,
|
||||
.getxy = grub_vga_text_getxy,
|
||||
.gotoxy = grub_vga_text_gotoxy,
|
||||
.cls = grub_vga_text_cls,
|
||||
.setcolorstate = grub_console_setcolorstate,
|
||||
.setcolor = grub_console_setcolor,
|
||||
.getcolor = grub_console_getcolor,
|
||||
.setcursor = grub_vga_text_setcursor,
|
||||
};
|
||||
|
||||
GRUB_MOD_INIT(vga_text)
|
||||
{
|
||||
grub_term_register_output ("vga_text", &grub_vga_text_term);
|
||||
}
|
||||
|
||||
GRUB_MOD_FINI(vga_text)
|
||||
{
|
||||
grub_term_unregister_output (&grub_vga_text_term);
|
||||
}
|
125
grub-core/term/i386/vga_common.c
Normal file
125
grub-core/term/i386/vga_common.c
Normal file
|
@ -0,0 +1,125 @@
|
|||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2002,2003,2005,2007,2008 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/i386/vga_common.h>
|
||||
#include <grub/term.h>
|
||||
#include <grub/types.h>
|
||||
|
||||
grub_uint8_t grub_console_cur_color = 0x7;
|
||||
static grub_uint8_t grub_console_standard_color = 0x7;
|
||||
static grub_uint8_t grub_console_normal_color = 0x7;
|
||||
static grub_uint8_t grub_console_highlight_color = 0x70;
|
||||
|
||||
static grub_uint32_t
|
||||
map_char (grub_uint32_t c)
|
||||
{
|
||||
if (c > 0x7f)
|
||||
{
|
||||
/* Map some unicode characters to the VGA font, if possible. */
|
||||
switch (c)
|
||||
{
|
||||
case 0x2190: /* left arrow */
|
||||
c = 0x1b;
|
||||
break;
|
||||
case 0x2191: /* up arrow */
|
||||
c = 0x18;
|
||||
break;
|
||||
case 0x2192: /* right arrow */
|
||||
c = 0x1a;
|
||||
break;
|
||||
case 0x2193: /* down arrow */
|
||||
c = 0x19;
|
||||
break;
|
||||
case 0x2501: /* horizontal line */
|
||||
c = 0xc4;
|
||||
break;
|
||||
case 0x2503: /* vertical line */
|
||||
c = 0xb3;
|
||||
break;
|
||||
case 0x250F: /* upper-left corner */
|
||||
c = 0xda;
|
||||
break;
|
||||
case 0x2513: /* upper-right corner */
|
||||
c = 0xbf;
|
||||
break;
|
||||
case 0x2517: /* lower-left corner */
|
||||
c = 0xc0;
|
||||
break;
|
||||
case 0x251B: /* lower-right corner */
|
||||
c = 0xd9;
|
||||
break;
|
||||
|
||||
default:
|
||||
c = '?';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
void
|
||||
grub_console_putchar (grub_uint32_t c)
|
||||
{
|
||||
grub_console_real_putchar (map_char (c));
|
||||
}
|
||||
|
||||
grub_ssize_t
|
||||
grub_console_getcharwidth (grub_uint32_t c __attribute__ ((unused)))
|
||||
{
|
||||
/* For now, every printable character has the width 1. */
|
||||
return 1;
|
||||
}
|
||||
|
||||
grub_uint16_t
|
||||
grub_console_getwh (void)
|
||||
{
|
||||
return (80 << 8) | 25;
|
||||
}
|
||||
|
||||
void
|
||||
grub_console_setcolorstate (grub_term_color_state state)
|
||||
{
|
||||
switch (state) {
|
||||
case GRUB_TERM_COLOR_STANDARD:
|
||||
grub_console_cur_color = grub_console_standard_color;
|
||||
break;
|
||||
case GRUB_TERM_COLOR_NORMAL:
|
||||
grub_console_cur_color = grub_console_normal_color;
|
||||
break;
|
||||
case GRUB_TERM_COLOR_HIGHLIGHT:
|
||||
grub_console_cur_color = grub_console_highlight_color;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
grub_console_setcolor (grub_uint8_t normal_color, grub_uint8_t highlight_color)
|
||||
{
|
||||
grub_console_normal_color = normal_color;
|
||||
grub_console_highlight_color = highlight_color;
|
||||
}
|
||||
|
||||
void
|
||||
grub_console_getcolor (grub_uint8_t *normal_color, grub_uint8_t *highlight_color)
|
||||
{
|
||||
*normal_color = grub_console_normal_color;
|
||||
*highlight_color = grub_console_highlight_color;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue