From 2bf6012d7f50ad13c5974e9fd137c37016bcffdd Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 5 May 2010 18:42:33 +0200 Subject: [PATCH 1/6] * term/ieee1275/ofconsole.c (grub_ofconsole_readkey): Support C0 code. --- ChangeLog | 4 ++++ term/ieee1275/ofconsole.c | 34 ++++++++++++++++++++-------------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2a6d5e12a..2cfed5f1e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-05-05 Vladimir Serbinenko + + * term/ieee1275/ofconsole.c (grub_ofconsole_readkey): Support C0 code. + 2010-05-03 Vladimir Serbinenko * commands/parttool.c (grub_cmd_parttool): Fix #if !GRUB_NO_MODULES diff --git a/term/ieee1275/ofconsole.c b/term/ieee1275/ofconsole.c index c0f895a15..26a43bdf4 100644 --- a/term/ieee1275/ofconsole.c +++ b/term/ieee1275/ofconsole.c @@ -194,14 +194,15 @@ grub_ofconsole_getcolor (grub_uint8_t *normal_color, grub_uint8_t *highlight_col *highlight_color = grub_ofconsole_highlight_color; } +#define ANSI_C0 0x9b + static int grub_ofconsole_readkey (int *key) { - char c; + grub_uint8_t c; grub_ssize_t actual = 0; grub_ieee1275_read (stdin_ihandle, &c, 1, &actual); - if (actual > 0) switch(c) { @@ -209,25 +210,30 @@ grub_ofconsole_readkey (int *key) /* Backspace: Ctrl-h. */ c = '\b'; break; + case ANSI_C0: case '\e': { grub_uint64_t start; - grub_ieee1275_read (stdin_ihandle, &c, 1, &actual); - /* 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) + if (c == '\e') { - *key = '\e'; - return 1; + grub_ieee1275_read (stdin_ihandle, &c, 1, &actual); + + /* 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); /* On 9600 we have to wait up to 12 milliseconds. */ From a7fc080b56efd933a8e301ab074dc7da893247c7 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 5 May 2010 18:44:02 +0200 Subject: [PATCH 2/6] * term/ieee1275/ofconsole.c (grub_ofconsole_getkey): Fix off-by-one error. --- ChangeLog | 5 +++++ term/ieee1275/ofconsole.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 2cfed5f1e..6a8b7af7d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-05-05 Vladimir Serbinenko + + * term/ieee1275/ofconsole.c (grub_ofconsole_getkey): Fix off-by-one + error. + 2010-05-05 Vladimir Serbinenko * term/ieee1275/ofconsole.c (grub_ofconsole_readkey): Support C0 code. diff --git a/term/ieee1275/ofconsole.c b/term/ieee1275/ofconsole.c index 26a43bdf4..898f9ceab 100644 --- a/term/ieee1275/ofconsole.c +++ b/term/ieee1275/ofconsole.c @@ -327,7 +327,7 @@ grub_ofconsole_getkey (void) static grub_uint16_t grub_ofconsole_getxy (void) { - return ((grub_curr_x - 1) << 8) | grub_curr_y; + return (grub_curr_x << 8) | grub_curr_y; } static void From 7e720a9bc1a99411ee12ea561b7ec4bcaeb1dcc6 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 5 May 2010 18:52:13 +0200 Subject: [PATCH 3/6] * 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. --- ChangeLog | 9 +++++++++ include/grub/ieee1275/ieee1275.h | 3 +++ kern/ieee1275/cmain.c | 10 ++++++++++ kern/ieee1275/init.c | 11 +++++++++++ 4 files changed, 33 insertions(+) diff --git a/ChangeLog b/ChangeLog index 6a8b7af7d..c38bf213d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2010-05-05 Vladimir Serbinenko + + * 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 * term/ieee1275/ofconsole.c (grub_ofconsole_getkey): Fix off-by-one diff --git a/include/grub/ieee1275/ieee1275.h b/include/grub/ieee1275/ieee1275.h index 2b2c36f8f..b30909c68 100644 --- a/include/grub/ieee1275/ieee1275.h +++ b/include/grub/ieee1275/ieee1275.h @@ -100,6 +100,9 @@ enum grub_ieee1275_flag /* Open Hack'Ware don't support the ANSI sequence. */ 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); diff --git a/kern/ieee1275/cmain.c b/kern/ieee1275/cmain.c index c1185f82c..e59d43646 100644 --- a/kern/ieee1275/cmain.c +++ b/kern/ieee1275/cmain.c @@ -59,6 +59,7 @@ grub_ieee1275_find_options (void) char tmp[32]; int is_smartfirmware = 0; int is_olpc = 0; + int is_qemu = 0; grub_ieee1275_finddevice ("/", &root); grub_ieee1275_finddevice ("/options", &options); @@ -79,6 +80,11 @@ grub_ieee1275_find_options (void) if (rc >= 0 && !grub_strcmp (tmp, "OLPC")) 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) { /* Broken in all versions */ @@ -135,6 +141,10 @@ grub_ieee1275_find_options (void) 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)) { rc = grub_ieee1275_get_property (bootrom, "model", tmp, sizeof (tmp), 0); diff --git a/kern/ieee1275/init.c b/kern/ieee1275/init.c index 75f261a71..b48df37bc 100644 --- a/kern/ieee1275/init.c +++ b/kern/ieee1275/init.c @@ -133,6 +133,17 @@ static void grub_claim_heap (void) if (type != 1) 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. */ /* Never exceed HEAP_MAX_SIZE */ From e5507505467b3e6ac1058dc1c24217240ac1910e Mon Sep 17 00:00:00 2001 From: Peter Hurley Date: Wed, 5 May 2010 21:03:59 +0200 Subject: [PATCH 4/6] * video/readers/jpeg.c (grub_jpeg_decode_huff_table): Loop over all tables. Ignore non-last ac bit. (grub_jpeg_decode_quan_table): Likewise. --- ChangeLog | 6 ++++++ video/readers/jpeg.c | 9 ++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index c38bf213d..0efe3c5e2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-05-05 Peter Hurley (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 * include/grub/ieee1275/ieee1275.h (grub_ieee1275_flag): New value diff --git a/video/readers/jpeg.c b/video/readers/jpeg.c index 5e749b8fd..c82b30c9c 100644 --- a/video/readers/jpeg.c +++ b/video/readers/jpeg.c @@ -178,8 +178,10 @@ grub_jpeg_decode_huff_table (struct grub_jpeg_data *data) next_marker = data->file->offset; next_marker += grub_jpeg_get_word (data); + while (data->file->offset + sizeof (count) + 1 <= next_marker) + { id = grub_jpeg_get_byte (data); - ac = (id >> 4); + ac = (id >> 4) & 1; id &= 0xF; if (id > 1) return grub_error (GRUB_ERR_BAD_FILE_TYPE, @@ -213,6 +215,7 @@ grub_jpeg_decode_huff_table (struct grub_jpeg_data *data) base <<= 1; } + } if (data->file->offset != next_marker) grub_error (GRUB_ERR_BAD_FILE_TYPE, "jpeg: extra byte in huffman table"); @@ -229,6 +232,8 @@ grub_jpeg_decode_quan_table (struct grub_jpeg_data *data) next_marker = data->file->offset; next_marker += grub_jpeg_get_word (data); + while (data->file->offset + sizeof (data->quan_table[id]) + 1 <= next_marker) + { id = grub_jpeg_get_byte (data); if (id >= 0x10) /* Upper 4-bit is precision. */ return grub_error (GRUB_ERR_BAD_FILE_TYPE, @@ -241,6 +246,8 @@ grub_jpeg_decode_quan_table (struct grub_jpeg_data *data) if (grub_file_read (data->file, &data->quan_table[id], 64) != 64) return grub_errno; + } + if (data->file->offset != next_marker) grub_error (GRUB_ERR_BAD_FILE_TYPE, "jpeg: extra byte in quantization table"); From 09ddcd11fb3b93ce4cec40b84ee806847154fc09 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 5 May 2010 21:18:10 +0200 Subject: [PATCH 5/6] 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. --- ChangeLog | 8 ++++++++ video/readers/jpeg.c | 21 +++++++++++++-------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0efe3c5e2..d3b2b44d1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2010-05-05 Vladimir Serbinenko + + 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 (tiny change) * video/readers/jpeg.c (grub_jpeg_decode_huff_table): Loop over all diff --git a/video/readers/jpeg.c b/video/readers/jpeg.c index c82b30c9c..f46b7f83f 100644 --- a/video/readers/jpeg.c +++ b/video/readers/jpeg.c @@ -153,10 +153,11 @@ grub_jpeg_get_number (struct grub_jpeg_data *data, int num) static int grub_jpeg_get_huff_code (struct grub_jpeg_data *data, int id) { - int code, i; + int code; + unsigned i; code = 0; - for (i = 0; i < 16; i++) + for (i = 0; i < ARRAY_SIZE (data->huff_maxval[id]); i++) { code <<= 1; if (grub_jpeg_get_bit (data)) @@ -171,9 +172,10 @@ grub_jpeg_get_huff_code (struct grub_jpeg_data *data, int id) static grub_err_t 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_uint8_t count[16]; + unsigned i; next_marker = data->file->offset; next_marker += grub_jpeg_get_word (data); @@ -192,7 +194,7 @@ grub_jpeg_decode_huff_table (struct grub_jpeg_data *data) return grub_errno; n = 0; - for (i = 0; i < 16; i++) + for (i = 0; i < ARRAY_SIZE (count); i++) n += count[i]; id += ac * 2; @@ -205,7 +207,7 @@ grub_jpeg_decode_huff_table (struct grub_jpeg_data *data) base = 0; ofs = 0; - for (i = 0; i < 16; i++) + for (i = 0; i < ARRAY_SIZE (count); i++) { base += count[i]; ofs += count[i]; @@ -243,7 +245,9 @@ grub_jpeg_decode_quan_table (struct grub_jpeg_data *data) return grub_error (GRUB_ERR_BAD_FILE_TYPE, "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], + sizeof (data->quan_table[id])) + != sizeof (data->quan_table[id])) return grub_errno; } @@ -451,7 +455,8 @@ grub_jpeg_idct_transform (jpeg_data_unit_t du) static void 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)); @@ -464,7 +469,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]; pos = 1; - while (pos < 64) + while (pos < ARRAY_SIZE (data->quan_table[qt])) { int num, val; From 2bf61a980bb1a3ef2fafdec1783e3582a75096f3 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 5 May 2010 21:19:55 +0200 Subject: [PATCH 6/6] * video/readers/jpeg.c: Indented. --- ChangeLog | 4 +++ video/readers/jpeg.c | 84 ++++++++++++++++++++++---------------------- 2 files changed, 46 insertions(+), 42 deletions(-) diff --git a/ChangeLog b/ChangeLog index d3b2b44d1..76b1de28f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-05-05 Vladimir Serbinenko + + * video/readers/jpeg.c: Indented. + 2010-05-05 Vladimir Serbinenko Various jpeg cleanups. diff --git a/video/readers/jpeg.c b/video/readers/jpeg.c index f46b7f83f..9d88163bd 100644 --- a/video/readers/jpeg.c +++ b/video/readers/jpeg.c @@ -182,41 +182,41 @@ grub_jpeg_decode_huff_table (struct grub_jpeg_data *data) while (data->file->offset + sizeof (count) + 1 <= next_marker) { - id = grub_jpeg_get_byte (data); + id = grub_jpeg_get_byte (data); ac = (id >> 4) & 1; - id &= 0xF; - if (id > 1) - return grub_error (GRUB_ERR_BAD_FILE_TYPE, - "jpeg: too many huffman tables"); + 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; + if (grub_file_read (data->file, &count, sizeof (count)) != + sizeof (count)) + return grub_errno; - n = 0; - for (i = 0; i < ARRAY_SIZE (count); i++) - n += count[i]; + 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; + 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; + 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]; + 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; + data->huff_maxval[id][i] = base; + data->huff_offset[id][i] = ofs - base; - base <<= 1; - } + base <<= 1; + } } if (data->file->offset != next_marker) @@ -234,21 +234,22 @@ grub_jpeg_decode_quan_table (struct grub_jpeg_data *data) next_marker = data->file->offset; next_marker += grub_jpeg_get_word (data); - while (data->file->offset + sizeof (data->quan_table[id]) + 1 <= next_marker) + while (data->file->offset + sizeof (data->quan_table[id]) + 1 + <= next_marker) { - 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"); + 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) - return grub_error (GRUB_ERR_BAD_FILE_TYPE, - "jpeg: too many quantization tables"); + if (id > 1) + return grub_error (GRUB_ERR_BAD_FILE_TYPE, + "jpeg: too many quantization tables"); - if (grub_file_read (data->file, &data->quan_table[id], - sizeof (data->quan_table[id])) - != sizeof (data->quan_table[id])) - return grub_errno; + if (grub_file_read (data->file, &data->quan_table[id], + sizeof (data->quan_table[id])) + != sizeof (data->quan_table[id])) + return grub_errno; } @@ -712,7 +713,7 @@ grub_video_reader_jpeg (struct grub_video_bitmap **bitmap, #if defined(JPEG_DEBUG) static grub_err_t grub_cmd_jpegtest (grub_command_t cmd __attribute__ ((unused)), - int argc, char **args) + int argc, char **args) { struct grub_video_bitmap *bitmap = 0; @@ -747,8 +748,7 @@ GRUB_MOD_INIT (jpeg) grub_video_bitmap_reader_register (&jpeg_reader); #if defined(JPEG_DEBUG) cmd = grub_register_command ("jpegtest", grub_cmd_jpegtest, - "FILE", - "Tests loading of JPEG bitmap."); + "FILE", "Tests loading of JPEG bitmap."); #endif }