merge mainline in bidi

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2010-05-06 15:18:46 +02:00
commit 42d2c16b39
6 changed files with 141 additions and 63 deletions

View file

@ -1,3 +1,39 @@
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

@ -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

@ -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

@ -149,14 +149,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)
{ {
@ -164,25 +165,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. */
@ -276,7 +282,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

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
} }