merge with mainline

This commit is contained in:
BVK Chaitanya 2010-05-12 10:40:35 +05:30
commit 49b9bacdee
10 changed files with 616 additions and 578 deletions

View file

@ -1,3 +1,99 @@
2010-05-09 Vladimir Serbinenko <phcoder@gmail.com>
Transform (broken) vga terminal into (working) vga video driver.
* conf/i386-pc.rmk (vga_mod_SOURCES): Change term/i386/pc/vga.c to
video/i386/pc/vga.c.
* include/grub/video.h (grub_video_driver_id):
Add GRUB_VIDEO_DRIVER_VGA.
* term/i386/pc/vga.c: Renamed to ...
* video/i386/pc/vga.c: ...this
(DEBUG_VGA): Removed.
(CHAR_WIDTH): Likewise.
(CHAR_HEIGHT): Likewise.
(TEXT_WIDTH): Likewise.
(TEXT_HEIGHT): Likewise.
(DEFAULT_FG_COLOR): Likewise.
(DEFAULT_BG_COLOR): Likewise.
(colored_char): Likewise.
(xpos): Likewise.
(ypos): Likewise.
(cursor_state): Likewise.
(fg_color): Likewise.
(bg_color): Likewise.
(text_buf): Likewise.
(page): Likewise.
(font): Likewise.
(framebuffer): New variable.
(set_read_map): Disabled.
(setup): New variable.
(is_target): Likewise.
(grub_vga_mod_init): Likewise.
(grub_vga_mod_fini): Likewise.
(check_vga_mem): Likewise.
(write_char): Likewise.
(write_cursor): Likewise.
(scroll_up): Likewise.
(grub_vga_putchar): Likewise.
(grub_vga_getcharwidth): Likewise.
(grub_vga_getwh): Likewise.
(grub_vga_getxy): Likewise.
(grub_vga_gotoxy): Likewise.
(grub_vga_cls): Likewise.
(grub_vga_setcolorstate): Likewise.
(grub_vga_setcursor): Likewise.
(grub_video_vga_init): New function.
(grub_video_vga_setup): Likewise.
(grub_video_vga_fini): Likewise.
(update_target): Likewise.
(grub_video_vga_blit_bitmap): Likewise.
(grub_video_vga_blit_render_target): Likewise.
(grub_video_vga_set_active_render_target): Likewise.
(grub_video_vga_get_active_render_target): Likewise.
(grub_video_vga_swap_buffers): Likewise.
(grub_video_vga_set_palette): Likewise.
(grub_video_vga_get_info_and_fini): Likewise.
(grub_vga_term): Removed.
(grub_video_vga_adapter): New variable.
(GRUB_MOD_INIT): Register a video driver instead of terminal.
(GRUB_MOD_FINI): Unrefister a video driver instead of terminal.
2010-05-05 Vladimir Serbinenko <phcoder@gmail.com>
* video/readers/jpeg.c: Indented.
2010-05-05 Vladimir Serbinenko <phcoder@gmail.com>
Various jpeg cleanups.
* video/readers/jpeg.c (grub_jpeg_get_huff_code): Use ARRAY_SIZE.
(grub_jpeg_decode_quan_table): Use sizeof.
(grub_jpeg_decode_du): Use ARRAY_SIZE.
2010-05-05 Peter Hurley <No e-mail available> (tiny change)
* video/readers/jpeg.c (grub_jpeg_decode_huff_table): Loop over all
tables. Ignore non-last ac bit.
(grub_jpeg_decode_quan_table): Likewise.
2010-05-05 Vladimir Serbinenko <phcoder@gmail.com>
* include/grub/ieee1275/ieee1275.h (grub_ieee1275_flag): New value
GRUB_IEEE1275_FLAG_NO_PRE1_5M_CLAIM.
* kern/ieee1275/cmain.c (grub_ieee1275_find_options): Set
GRUB_IEEE1275_FLAG_NO_PRE1_5M_CLAIM on qemu.
* kern/ieee1275/init.c (grub_claim_heap): Don0t allocate below
1.5MiB if GRUB_IEEE1275_FLAG_NO_PRE1_5M_CLAIM is set.
2010-05-05 Vladimir Serbinenko <phcoder@gmail.com>
* term/ieee1275/ofconsole.c (grub_ofconsole_getkey): Fix off-by-one
error.
2010-05-05 Vladimir Serbinenko <phcoder@gmail.com>
* term/ieee1275/ofconsole.c (grub_ofconsole_readkey): Support C0 code.
2010-05-03 Vladimir Serbinenko <phcoder@gmail.com> 2010-05-03 Vladimir Serbinenko <phcoder@gmail.com>
* commands/parttool.c (grub_cmd_parttool): Fix #if !GRUB_NO_MODULES * commands/parttool.c (grub_cmd_parttool): Fix #if !GRUB_NO_MODULES

View file

@ -185,7 +185,7 @@ vbetest_mod_CFLAGS = $(COMMON_CFLAGS)
vbetest_mod_LDFLAGS = $(COMMON_LDFLAGS) vbetest_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For vga.mod. # For vga.mod.
vga_mod_SOURCES = term/i386/pc/vga.c vga_mod_SOURCES = video/i386/pc/vga.c
vga_mod_CFLAGS = $(COMMON_CFLAGS) vga_mod_CFLAGS = $(COMMON_CFLAGS)
vga_mod_LDFLAGS = $(COMMON_LDFLAGS) vga_mod_LDFLAGS = $(COMMON_LDFLAGS)

View file

@ -100,6 +100,9 @@ enum grub_ieee1275_flag
/* Open Hack'Ware don't support the ANSI sequence. */ /* Open Hack'Ware don't support the ANSI sequence. */
GRUB_IEEE1275_FLAG_NO_ANSI, GRUB_IEEE1275_FLAG_NO_ANSI,
/* OpenFirmware hangs on qemu if one requests any memory below 1.5 MiB. */
GRUB_IEEE1275_FLAG_NO_PRE1_5M_CLAIM,
}; };
extern int EXPORT_FUNC(grub_ieee1275_test_flag) (enum grub_ieee1275_flag flag); extern int EXPORT_FUNC(grub_ieee1275_test_flag) (enum grub_ieee1275_flag flag);

View file

@ -181,7 +181,8 @@ typedef enum grub_video_driver_id
GRUB_VIDEO_DRIVER_VBE, GRUB_VIDEO_DRIVER_VBE,
GRUB_VIDEO_DRIVER_EFI_UGA, GRUB_VIDEO_DRIVER_EFI_UGA,
GRUB_VIDEO_DRIVER_EFI_GOP, GRUB_VIDEO_DRIVER_EFI_GOP,
GRUB_VIDEO_DRIVER_SM712 GRUB_VIDEO_DRIVER_SM712,
GRUB_VIDEO_DRIVER_VGA
} grub_video_driver_id_t; } grub_video_driver_id_t;
struct grub_video_adapter struct grub_video_adapter

View file

@ -59,6 +59,7 @@ grub_ieee1275_find_options (void)
char tmp[32]; char tmp[32];
int is_smartfirmware = 0; int is_smartfirmware = 0;
int is_olpc = 0; int is_olpc = 0;
int is_qemu = 0;
grub_ieee1275_finddevice ("/", &root); grub_ieee1275_finddevice ("/", &root);
grub_ieee1275_finddevice ("/options", &options); grub_ieee1275_finddevice ("/options", &options);
@ -79,6 +80,11 @@ grub_ieee1275_find_options (void)
if (rc >= 0 && !grub_strcmp (tmp, "OLPC")) if (rc >= 0 && !grub_strcmp (tmp, "OLPC"))
is_olpc = 1; is_olpc = 1;
rc = grub_ieee1275_get_property (root, "model",
tmp, sizeof (tmp), 0);
if (rc >= 0 && !grub_strcmp (tmp, "Emulated PC"))
is_qemu = 1;
if (is_smartfirmware) if (is_smartfirmware)
{ {
/* Broken in all versions */ /* Broken in all versions */
@ -135,6 +141,10 @@ grub_ieee1275_find_options (void)
grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_OFDISK_SDCARD_ONLY); grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_OFDISK_SDCARD_ONLY);
} }
if (is_qemu)
/* OpenFirmware hangs on qemu if one requests any memory below 1.5 MiB. */
grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_NO_PRE1_5M_CLAIM);
if (! grub_ieee1275_finddevice ("/rom/boot-rom", &bootrom)) if (! grub_ieee1275_finddevice ("/rom/boot-rom", &bootrom))
{ {
rc = grub_ieee1275_get_property (bootrom, "model", tmp, sizeof (tmp), 0); rc = grub_ieee1275_get_property (bootrom, "model", tmp, sizeof (tmp), 0);

View file

@ -133,6 +133,17 @@ static void grub_claim_heap (void)
if (type != 1) if (type != 1)
return 0; return 0;
if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_NO_PRE1_5M_CLAIM))
{
if (addr + len <= 0x180000)
return 0;
if (addr < 0x180000)
{
len = addr + len - 0x180000;
addr = 0x180000;
}
}
len -= 1; /* Required for some firmware. */ len -= 1; /* Required for some firmware. */
/* Never exceed HEAP_MAX_SIZE */ /* Never exceed HEAP_MAX_SIZE */

View file

@ -1,513 +0,0 @@
/*
* 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);
}

View file

@ -194,14 +194,15 @@ grub_ofconsole_getcolor (grub_uint8_t *normal_color, grub_uint8_t *highlight_col
*highlight_color = grub_ofconsole_highlight_color; *highlight_color = grub_ofconsole_highlight_color;
} }
#define ANSI_C0 0x9b
static int static int
grub_ofconsole_readkey (int *key) grub_ofconsole_readkey (int *key)
{ {
char c; grub_uint8_t c;
grub_ssize_t actual = 0; grub_ssize_t actual = 0;
grub_ieee1275_read (stdin_ihandle, &c, 1, &actual); grub_ieee1275_read (stdin_ihandle, &c, 1, &actual);
if (actual > 0) if (actual > 0)
switch(c) switch(c)
{ {
@ -209,25 +210,30 @@ grub_ofconsole_readkey (int *key)
/* Backspace: Ctrl-h. */ /* Backspace: Ctrl-h. */
c = '\b'; c = '\b';
break; break;
case ANSI_C0:
case '\e': case '\e':
{ {
grub_uint64_t start; grub_uint64_t start;
grub_ieee1275_read (stdin_ihandle, &c, 1, &actual);
/* On 9600 we have to wait up to 12 milliseconds. */ if (c == '\e')
start = grub_get_time_ms ();
while (actual <= 0 && grub_get_time_ms () - start < 12)
grub_ieee1275_read (stdin_ihandle, &c, 1, &actual);
if (actual <= 0)
{ {
*key = '\e'; grub_ieee1275_read (stdin_ihandle, &c, 1, &actual);
return 1;
/* On 9600 we have to wait up to 12 milliseconds. */
start = grub_get_time_ms ();
while (actual <= 0 && grub_get_time_ms () - start < 12)
grub_ieee1275_read (stdin_ihandle, &c, 1, &actual);
if (actual <= 0)
{
*key = '\e';
return 1;
}
if (c != '[')
return 0;
} }
if (c != '[')
return 0;
grub_ieee1275_read (stdin_ihandle, &c, 1, &actual); grub_ieee1275_read (stdin_ihandle, &c, 1, &actual);
/* On 9600 we have to wait up to 12 milliseconds. */ /* On 9600 we have to wait up to 12 milliseconds. */
@ -321,7 +327,7 @@ grub_ofconsole_getkey (void)
static grub_uint16_t static grub_uint16_t
grub_ofconsole_getxy (void) grub_ofconsole_getxy (void)
{ {
return ((grub_curr_x - 1) << 8) | grub_curr_y; return (grub_curr_x << 8) | grub_curr_y;
} }
static void static void

412
video/i386/pc/vga.c Normal file
View file

@ -0,0 +1,412 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2000,2001,2002,2003,2004,2005,2007,2008,2009,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/>.
*/
#define grub_video_render_target grub_video_fbrender_target
#include <grub/machine/vga.h>
#include <grub/machine/console.h>
#include <grub/cpu/io.h>
#include <grub/mm.h>
#include <grub/video.h>
#include <grub/video_fb.h>
#include <grub/types.h>
#include <grub/dl.h>
#include <grub/misc.h>
#define VGA_WIDTH 640
#define VGA_HEIGHT 350
#define VGA_MEM ((grub_uint8_t *) GRUB_MEMORY_MACHINE_VGA_ADDR)
#define PAGE_OFFSET(x) ((x) * (VGA_WIDTH * VGA_HEIGHT / 8))
static unsigned char text_mode;
static unsigned char saved_map_mask;
static struct
{
struct grub_video_mode_info mode_info;
struct grub_video_render_target *render_target;
grub_uint8_t *temporary_buffer;
int front_page;
int back_page;
} framebuffer;
#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);
}
#if 0
/* 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);
}
#endif
/* 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 int setup = 0;
static int is_target = 0;
static grub_err_t
grub_video_vga_init (void)
{
return GRUB_ERR_NONE;
}
static grub_err_t
grub_video_vga_setup (unsigned int width, unsigned int height,
unsigned int mode_type, unsigned int mode_mask)
{
grub_err_t err;
if ((width && width != VGA_WIDTH) || (height && height != VGA_HEIGHT))
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "no matching mode found");
framebuffer.temporary_buffer = grub_malloc (VGA_HEIGHT * VGA_WIDTH);
framebuffer.front_page = 0;
framebuffer.back_page = 0;
if (!framebuffer.temporary_buffer)
return grub_errno;
saved_map_mask = get_map_mask ();
text_mode = grub_vga_set_mode (0x10);
setup = 1;
set_map_mask (0x0f);
set_start_address (PAGE_OFFSET (framebuffer.front_page));
framebuffer.mode_info.width = VGA_WIDTH;
framebuffer.mode_info.height = VGA_HEIGHT;
framebuffer.mode_info.mode_type = GRUB_VIDEO_MODE_TYPE_INDEX_COLOR;
if (grub_video_check_mode_flag (mode_type, mode_mask,
GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED, 1))
{
framebuffer.back_page = 1;
framebuffer.mode_info.mode_type |= GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED;
}
framebuffer.mode_info.bpp = 8;
framebuffer.mode_info.bytes_per_pixel = 1;
framebuffer.mode_info.pitch = VGA_WIDTH;
framebuffer.mode_info.number_of_colors = 16;
framebuffer.mode_info.red_mask_size = 0;
framebuffer.mode_info.red_field_pos = 0;
framebuffer.mode_info.green_mask_size = 0;
framebuffer.mode_info.green_field_pos = 0;
framebuffer.mode_info.blue_mask_size = 0;
framebuffer.mode_info.blue_field_pos = 0;
framebuffer.mode_info.reserved_mask_size = 0;
framebuffer.mode_info.reserved_field_pos = 0;
framebuffer.mode_info.blit_format
= grub_video_get_blit_format (&framebuffer.mode_info);
err = grub_video_fb_create_render_target_from_pointer (&framebuffer.render_target,
&framebuffer.mode_info,
framebuffer.temporary_buffer);
if (err)
{
grub_dprintf ("video", "Couldn't create FB target\n");
return err;
}
is_target = 1;
err = grub_video_fb_set_active_render_target (framebuffer.render_target);
if (err)
return err;
err = grub_video_fb_set_palette (0, GRUB_VIDEO_FBSTD_NUMCOLORS,
grub_video_fbstd_colors);
return GRUB_ERR_NONE;
}
static grub_err_t
grub_video_vga_fini (void)
{
if (setup)
{
set_map_mask (saved_map_mask);
grub_vga_set_mode (text_mode);
}
setup = 0;
grub_free (framebuffer.temporary_buffer);
framebuffer.temporary_buffer = 0;
return GRUB_ERR_NONE;
}
static inline void
update_target (void)
{
int plane;
if (!is_target)
return;
for (plane = 0x01; plane <= 0x08; plane <<= 1)
{
grub_uint8_t *ptr;
volatile grub_uint8_t *ptr2;
unsigned cbyte = 0;
int shift = 7;
set_map_mask (plane);
for (ptr = framebuffer.temporary_buffer,
ptr2 = VGA_MEM + PAGE_OFFSET (framebuffer.back_page);
ptr < framebuffer.temporary_buffer + VGA_WIDTH * VGA_HEIGHT; ptr++)
{
cbyte |= (!!(plane & *ptr)) << shift;
shift--;
if (shift == -1)
{
*ptr2++ = cbyte;
shift = 7;
cbyte = 0;
}
}
}
}
static grub_err_t
grub_video_vga_blit_bitmap (struct grub_video_bitmap *bitmap,
enum grub_video_blit_operators oper, int x, int y,
int offset_x, int offset_y,
unsigned int width, unsigned int height)
{
grub_err_t ret;
ret = grub_video_fb_blit_bitmap (bitmap, oper, x, y, offset_x, offset_y,
width, height);
update_target ();
return ret;
}
static grub_err_t
grub_video_vga_blit_render_target (struct grub_video_fbrender_target *source,
enum grub_video_blit_operators oper,
int x, int y, int offset_x, int offset_y,
unsigned int width, unsigned int height)
{
grub_err_t ret;
ret = grub_video_fb_blit_render_target (source, oper, x, y,
offset_x, offset_y, width, height);
update_target ();
return ret;
}
static grub_err_t
grub_video_vga_set_active_render_target (struct grub_video_render_target *target)
{
if (target == GRUB_VIDEO_RENDER_TARGET_DISPLAY)
{
is_target = 1;
target = framebuffer.render_target;
}
else
is_target = 0;
return grub_video_fb_set_active_render_target (target);
}
static grub_err_t
grub_video_vga_get_active_render_target (struct grub_video_render_target **target)
{
grub_err_t err;
err = grub_video_fb_get_active_render_target (target);
if (err)
return err;
if (*target == framebuffer.render_target)
*target = GRUB_VIDEO_RENDER_TARGET_DISPLAY;
return GRUB_ERR_NONE;
}
static grub_err_t
grub_video_vga_swap_buffers (void)
{
if (!(framebuffer.mode_info.mode_type & GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED))
return GRUB_ERR_NONE;
/* Activate the other page. */
framebuffer.front_page = !framebuffer.front_page;
framebuffer.back_page = !framebuffer.back_page;
wait_vretrace ();
set_start_address (PAGE_OFFSET (framebuffer.front_page));
return GRUB_ERR_NONE;
}
static grub_err_t
grub_video_vga_set_palette (unsigned int start __attribute__ ((unused)),
unsigned int count __attribute__ ((unused)),
struct grub_video_palette_data *palette_data __attribute__ ((unused)))
{
return grub_error (GRUB_ERR_IO, "can't change palette");
}
static grub_err_t
grub_video_vga_get_info_and_fini (struct grub_video_mode_info *mode_info,
void **framebuf)
{
set_map_mask (0xf);
grub_memcpy (mode_info, &(framebuffer.mode_info), sizeof (*mode_info));
mode_info->bpp = 1;
mode_info->bytes_per_pixel = 0;
mode_info->pitch = VGA_WIDTH / 8;
mode_info->number_of_colors = 1;
mode_info->bg_red = 0;
mode_info->bg_green = 0;
mode_info->bg_blue = 0;
mode_info->bg_alpha = 255;
mode_info->fg_red = 255;
mode_info->fg_green = 255;
mode_info->fg_blue = 255;
mode_info->fg_alpha = 255;
*framebuf = VGA_MEM + PAGE_OFFSET (framebuffer.front_page);
grub_video_fb_fini ();
grub_free (framebuffer.temporary_buffer);
framebuffer.temporary_buffer = 0;
setup = 0;
return GRUB_ERR_NONE;
}
static struct grub_video_adapter grub_video_vga_adapter =
{
.name = "VGA Video Driver",
.id = GRUB_VIDEO_DRIVER_VGA,
.init = grub_video_vga_init,
.fini = grub_video_vga_fini,
.setup = grub_video_vga_setup,
.get_info = grub_video_fb_get_info,
.get_info_and_fini = grub_video_vga_get_info_and_fini,
.set_palette = grub_video_vga_set_palette,
.get_palette = grub_video_fb_get_palette,
.set_viewport = grub_video_fb_set_viewport,
.get_viewport = grub_video_fb_get_viewport,
.map_color = grub_video_fb_map_color,
.map_rgb = grub_video_fb_map_rgb,
.map_rgba = grub_video_fb_map_rgba,
.unmap_color = grub_video_fb_unmap_color,
.fill_rect = grub_video_fb_fill_rect,
.blit_bitmap = grub_video_vga_blit_bitmap,
.blit_render_target = grub_video_vga_blit_render_target,
.scroll = grub_video_fb_scroll,
.swap_buffers = grub_video_vga_swap_buffers,
.create_render_target = grub_video_fb_create_render_target,
.delete_render_target = grub_video_fb_delete_render_target,
.set_active_render_target = grub_video_vga_set_active_render_target,
.get_active_render_target = grub_video_vga_get_active_render_target,
.next = 0
};
GRUB_MOD_INIT(vga)
{
grub_video_register (&grub_video_vga_adapter);
}
GRUB_MOD_FINI(vga)
{
grub_video_unregister (&grub_video_vga_adapter);
}

View file

@ -153,10 +153,11 @@ grub_jpeg_get_number (struct grub_jpeg_data *data, int num)
static int static int
grub_jpeg_get_huff_code (struct grub_jpeg_data *data, int id) grub_jpeg_get_huff_code (struct grub_jpeg_data *data, int id)
{ {
int code, i; int code;
unsigned i;
code = 0; code = 0;
for (i = 0; i < 16; i++) for (i = 0; i < ARRAY_SIZE (data->huff_maxval[id]); i++)
{ {
code <<= 1; code <<= 1;
if (grub_jpeg_get_bit (data)) if (grub_jpeg_get_bit (data))
@ -171,47 +172,51 @@ grub_jpeg_get_huff_code (struct grub_jpeg_data *data, int id)
static grub_err_t static grub_err_t
grub_jpeg_decode_huff_table (struct grub_jpeg_data *data) grub_jpeg_decode_huff_table (struct grub_jpeg_data *data)
{ {
int id, ac, i, n, base, ofs; int id, ac, n, base, ofs;
grub_uint32_t next_marker; grub_uint32_t next_marker;
grub_uint8_t count[16]; grub_uint8_t count[16];
unsigned i;
next_marker = data->file->offset; next_marker = data->file->offset;
next_marker += grub_jpeg_get_word (data); next_marker += grub_jpeg_get_word (data);
id = grub_jpeg_get_byte (data); while (data->file->offset + sizeof (count) + 1 <= next_marker)
ac = (id >> 4);
id &= 0xF;
if (id > 1)
return grub_error (GRUB_ERR_BAD_FILE_TYPE,
"jpeg: too many huffman tables");
if (grub_file_read (data->file, &count, sizeof (count)) !=
sizeof (count))
return grub_errno;
n = 0;
for (i = 0; i < 16; i++)
n += count[i];
id += ac * 2;
data->huff_value[id] = grub_malloc (n);
if (grub_errno)
return grub_errno;
if (grub_file_read (data->file, data->huff_value[id], n) != n)
return grub_errno;
base = 0;
ofs = 0;
for (i = 0; i < 16; i++)
{ {
base += count[i]; id = grub_jpeg_get_byte (data);
ofs += count[i]; ac = (id >> 4) & 1;
id &= 0xF;
if (id > 1)
return grub_error (GRUB_ERR_BAD_FILE_TYPE,
"jpeg: too many huffman tables");
data->huff_maxval[id][i] = base; if (grub_file_read (data->file, &count, sizeof (count)) !=
data->huff_offset[id][i] = ofs - base; sizeof (count))
return grub_errno;
base <<= 1; n = 0;
for (i = 0; i < ARRAY_SIZE (count); i++)
n += count[i];
id += ac * 2;
data->huff_value[id] = grub_malloc (n);
if (grub_errno)
return grub_errno;
if (grub_file_read (data->file, data->huff_value[id], n) != n)
return grub_errno;
base = 0;
ofs = 0;
for (i = 0; i < ARRAY_SIZE (count); i++)
{
base += count[i];
ofs += count[i];
data->huff_maxval[id][i] = base;
data->huff_offset[id][i] = ofs - base;
base <<= 1;
}
} }
if (data->file->offset != next_marker) if (data->file->offset != next_marker)
@ -229,17 +234,24 @@ grub_jpeg_decode_quan_table (struct grub_jpeg_data *data)
next_marker = data->file->offset; next_marker = data->file->offset;
next_marker += grub_jpeg_get_word (data); next_marker += grub_jpeg_get_word (data);
id = grub_jpeg_get_byte (data); while (data->file->offset + sizeof (data->quan_table[id]) + 1
if (id >= 0x10) /* Upper 4-bit is precision. */ <= next_marker)
return grub_error (GRUB_ERR_BAD_FILE_TYPE, {
"jpeg: only 8-bit precision is supported"); id = grub_jpeg_get_byte (data);
if (id >= 0x10) /* Upper 4-bit is precision. */
return grub_error (GRUB_ERR_BAD_FILE_TYPE,
"jpeg: only 8-bit precision is supported");
if (id > 1) if (id > 1)
return grub_error (GRUB_ERR_BAD_FILE_TYPE, return grub_error (GRUB_ERR_BAD_FILE_TYPE,
"jpeg: too many quantization tables"); "jpeg: too many quantization tables");
if (grub_file_read (data->file, &data->quan_table[id], 64) != 64) if (grub_file_read (data->file, &data->quan_table[id],
return grub_errno; sizeof (data->quan_table[id]))
!= sizeof (data->quan_table[id]))
return grub_errno;
}
if (data->file->offset != next_marker) if (data->file->offset != next_marker)
grub_error (GRUB_ERR_BAD_FILE_TYPE, grub_error (GRUB_ERR_BAD_FILE_TYPE,
@ -444,7 +456,8 @@ grub_jpeg_idct_transform (jpeg_data_unit_t du)
static void static void
grub_jpeg_decode_du (struct grub_jpeg_data *data, int id, jpeg_data_unit_t du) grub_jpeg_decode_du (struct grub_jpeg_data *data, int id, jpeg_data_unit_t du)
{ {
int pos, h1, h2, qt; int h1, h2, qt;
unsigned pos;
grub_memset (du, 0, sizeof (jpeg_data_unit_t)); grub_memset (du, 0, sizeof (jpeg_data_unit_t));
@ -457,7 +470,7 @@ grub_jpeg_decode_du (struct grub_jpeg_data *data, int id, jpeg_data_unit_t du)
du[0] = data->dc_value[id] * (int) data->quan_table[qt][0]; du[0] = data->dc_value[id] * (int) data->quan_table[qt][0];
pos = 1; pos = 1;
while (pos < 64) while (pos < ARRAY_SIZE (data->quan_table[qt]))
{ {
int num, val; int num, val;
@ -700,7 +713,7 @@ grub_video_reader_jpeg (struct grub_video_bitmap **bitmap,
#if defined(JPEG_DEBUG) #if defined(JPEG_DEBUG)
static grub_err_t static grub_err_t
grub_cmd_jpegtest (grub_command_t cmd __attribute__ ((unused)), grub_cmd_jpegtest (grub_command_t cmd __attribute__ ((unused)),
int argc, char **args) int argc, char **args)
{ {
struct grub_video_bitmap *bitmap = 0; struct grub_video_bitmap *bitmap = 0;
@ -735,8 +748,7 @@ GRUB_MOD_INIT (jpeg)
grub_video_bitmap_reader_register (&jpeg_reader); grub_video_bitmap_reader_register (&jpeg_reader);
#if defined(JPEG_DEBUG) #if defined(JPEG_DEBUG)
cmd = grub_register_command ("jpegtest", grub_cmd_jpegtest, cmd = grub_register_command ("jpegtest", grub_cmd_jpegtest,
"FILE", "FILE", "Tests loading of JPEG bitmap.");
"Tests loading of JPEG bitmap.");
#endif #endif
} }