pull-in func-params again

This commit is contained in:
BVK Chaitanya 2010-05-12 17:59:09 +05:30
commit 2e961bd737
18 changed files with 1056 additions and 801 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>
* commands/parttool.c (grub_cmd_parttool): Fix #if !GRUB_NO_MODULES

View File

@ -660,7 +660,7 @@ normal_mod_CFLAGS = $(COMMON_CFLAGS)
normal_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For sh.mod.
sh_mod_SOURCES = script/main.c script/script.c script/execute.c \
sh_mod_SOURCES = script/main.c script/script.c script/argv.c script/execute.c \
script/function.c script/lexer.c grub_script.tab.c grub_script.yy.c
sh_mod_CFLAGS = $(COMMON_CFLAGS) $(POSIX_CFLAGS) -Wno-error
sh_mod_LDFLAGS = $(COMMON_LDFLAGS)

View File

@ -185,7 +185,7 @@ vbetest_mod_CFLAGS = $(COMMON_CFLAGS)
vbetest_mod_LDFLAGS = $(COMMON_LDFLAGS)
# 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_LDFLAGS = $(COMMON_LDFLAGS)

View File

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

View File

@ -64,6 +64,13 @@ struct grub_script_arg
struct grub_script_arg *next;
};
/* An argument vector. */
struct grub_script_argv
{
int argc;
char **args;
};
/* A complete argument. It consists of a list of one or more `struct
grub_script_arg's. */
struct grub_script_arglist
@ -74,15 +81,6 @@ struct grub_script_arglist
int argcount;
};
/* Scope for grub script constructs. */
struct grub_script_scope
{
struct grub_script_scope *next;
char **args;
unsigned int argc;
};
/* A single command line. */
struct grub_script_cmdline
{
@ -225,6 +223,11 @@ struct grub_parser_param
struct grub_lexer_param *lexerstate;
};
void grub_script_argv_free (struct grub_script_argv *argv);
int grub_script_argv_next (struct grub_script_argv *argv);
int grub_script_argv_append (struct grub_script_argv *argv, const char *s);
int grub_script_argv_split_append (struct grub_script_argv *argv, char *s);
struct grub_script_arglist *
grub_script_create_arglist (struct grub_parser_param *state);

View File

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

View File

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

View File

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

128
script/argv.c Normal file
View File

@ -0,0 +1,128 @@
/* argv.c - methods for constructing argument vector */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 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/mm.h>
#include <grub/script_sh.h>
#define ARG_ALLOCATION_UNIT (32 * sizeof (char))
#define ARGV_ALLOCATION_UNIT (8 * sizeof (void*))
void
grub_script_argv_free (struct grub_script_argv *argv)
{
int i;
if (argv->args)
{
for (i = 0; i < argv->argc; i++)
grub_free (argv->args[i]);
grub_free (argv->args);
}
argv->argc = 0;
argv->args = 0;
}
/* Prepare for next argc. */
int
grub_script_argv_next (struct grub_script_argv *argv)
{
char **p = argv->args;
if (argv->argc == 0)
{
p = grub_malloc (ALIGN_UP (2 * sizeof (char *), ARG_ALLOCATION_UNIT));
if (! p)
return 1;
argv->argc = 1;
argv->args = p;
argv->args[0] = 0;
argv->args[1] = 0;
return 0;
}
if (! argv->args[argv->argc - 1])
return 0;
p = grub_realloc (p, ALIGN_UP ((argv->argc + 1) * sizeof (char *),
ARG_ALLOCATION_UNIT));
if (! p)
return 1;
argv->argc++;
argv->args = p;
argv->args[argv->argc] = 0;
return 0;
}
/* Append `s' to the last argument. */
int
grub_script_argv_append (struct grub_script_argv *argv, const char *s)
{
int a, b;
char *p = argv->args[argv->argc - 1];
if (! s)
return 0;
a = p ? grub_strlen (p) : 0;
b = grub_strlen (s);
p = grub_realloc (p, ALIGN_UP ((a + b + 1) * sizeof (char),
ARG_ALLOCATION_UNIT));
if (! p)
return 1;
grub_strcpy (p + a, s);
argv->args[argv->argc - 1] = p;
return 0;
}
/* Split `s' and append words as multiple arguments. */
int
grub_script_argv_split_append (struct grub_script_argv *argv, char *s)
{
char ch;
char *p;
int errors = 0;
if (! s)
return 0;
while (! errors && *s)
{
p = s;
while (*s && ! grub_isspace (*s))
s++;
ch = *s;
*s = '\0';
errors += grub_script_argv_append (argv, p);
*s = ch;
while (*s && grub_isspace (*s))
s++;
if (*s)
errors += grub_script_argv_next (argv);
}
return errors;
}

View File

@ -32,6 +32,12 @@
static unsigned long active_loops;
static unsigned long active_breaks;
/* Scope for grub script functions. */
struct grub_script_scope
{
struct grub_script_argv argv;
};
static struct grub_script_scope *scope = 0;
grub_err_t
@ -52,50 +58,175 @@ grub_script_break (grub_command_t cmd __attribute__((unused)),
return GRUB_ERR_NONE;
}
static char *
grub_script_env_get (const char *name)
static int
grub_env_special (const char *name)
{
char *p = 0;
unsigned long num = 0;
if (grub_isdigit (name[0]) ||
grub_strcmp (name, "#") == 0 ||
grub_strcmp (name, "*") == 0 ||
grub_strcmp (name, "@") == 0)
return 1;
return 0;
}
if (! scope)
return grub_env_get (name);
static char **
grub_script_env_get (const char *name, grub_script_arg_type_t type)
{
int errors = 0;
struct grub_script_argv result = { 0, 0 };
if (grub_isdigit (name[0]))
errors += grub_script_argv_next (&result);
if (! grub_env_special (name))
{
num = grub_strtoul (name, &p, 10);
if (p && *p == '\0')
char *v = grub_env_get (name);
if (v && v[0])
{
if (num == 0)
return 0; /* XXX no file name, for now. */
return (num > scope->argc ? 0 : scope->args[num - 1]);
}
else
{
grub_error (GRUB_ERR_BAD_ARGUMENT, "bad variabe name substitution");
return 0;
if (type == GRUB_SCRIPT_ARG_TYPE_VAR)
errors += grub_script_argv_split_append (&result, v);
else
errors += grub_script_argv_append (&result, v);
}
}
else if (! scope)
errors += grub_script_argv_append (&result, 0);
else if (grub_strcmp (name, "#") == 0)
{
static char buf[32]; /* Rewritten everytime. */
grub_snprintf (buf, sizeof (buf), "%u", scope->argc);
return buf;
char buffer[ERRNO_DIGITS_MAX + 1];
grub_snprintf (buffer, sizeof (buffer), "%u", scope->argv.argc);
errors += grub_script_argv_append (&result, buffer);
}
else if (grub_strcmp (name, "*") == 0)
{
int i;
for (i = 0; ! errors && i < scope->argv.argc; i++)
if (type == GRUB_SCRIPT_ARG_TYPE_VAR)
{
if (i != 0)
errors += grub_script_argv_next (&result);
errors += grub_script_argv_split_append (&result,
scope->argv.args[i]);
}
else
{
if (i != 0)
errors += grub_script_argv_append (&result, " ");
errors += grub_script_argv_append (&result,
scope->argv.args[i]);
}
}
else if (grub_strcmp (name, "@") == 0)
{
int i;
for (i = 0; ! errors && i < scope->argv.argc; i++)
{
if (i != 0)
errors += grub_script_argv_next (&result);
if (type == GRUB_SCRIPT_ARG_TYPE_VAR)
errors += grub_script_argv_split_append (&result,
scope->argv.args[i]);
else
errors += grub_script_argv_append (&result,
scope->argv.args[i]);
}
}
else
return grub_env_get (name);
{
unsigned long num = grub_strtoul (name, 0, 10);
if (num == 0)
; /* XXX no file name, for now. */
else if (num <= scope->argv.argc)
{
if (type == GRUB_SCRIPT_ARG_TYPE_VAR)
errors += grub_script_argv_split_append (&result,
scope->argv.args[num - 1]);
else
errors += grub_script_argv_append (&result,
scope->argv.args[num - 1]);
}
}
if (errors)
{
grub_script_argv_free (&result);
return 0;
}
return result.args;
}
static grub_err_t
grub_script_env_set (const char *name, const char *val)
{
if (grub_isdigit (name[0]) || grub_strcmp (name, "#") == 0)
if (grub_env_special (name))
return grub_error (GRUB_ERR_BAD_ARGUMENT, "bad variable name");
return grub_env_set (name, val);
}
/* Expand arguments in ARGLIST into multiple arguments. */
static int
grub_script_arglist_to_argv (struct grub_script_arglist *arglist,
struct grub_script_argv *argv)
{
int i;
int error = 0;
char **values = 0;
struct grub_script_arg *arg = 0;
struct grub_script_argv result = { 0, 0 };
for (; error == 0 && arglist && arglist->arg; arglist = arglist->next)
{
error += grub_script_argv_next (&result);
arg = arglist->arg;
while (arg)
{
if (error)
break;
switch (arg->type)
{
case GRUB_SCRIPT_ARG_TYPE_VAR:
case GRUB_SCRIPT_ARG_TYPE_DQVAR:
values = grub_script_env_get (arg->str, arg->type);
for (i = 0; values && values[i]; i++)
{
if (i != 0)
error += grub_script_argv_next (&result);
error += grub_script_argv_append (&result, values[i]);
}
grub_free (values);
break;
case GRUB_SCRIPT_ARG_TYPE_TEXT:
if (grub_strlen (arg->str))
error += grub_script_argv_append (&result, arg->str);
break;
case GRUB_SCRIPT_ARG_TYPE_DQSTR:
case GRUB_SCRIPT_ARG_TYPE_SQSTR:
error += grub_script_argv_append (&result, arg->str);
break;
}
arg = arg->next;
}
}
if (error)
return 1;
if (! result.args[result.argc - 1])
result.argc--;
*argv = result;
return 0;
}
static grub_err_t
grub_script_execute_cmd (struct grub_script_cmd *cmd)
{
@ -112,168 +243,26 @@ grub_script_execute_cmd (struct grub_script_cmd *cmd)
return ret;
}
#define ARG_ALLOCATION_UNIT (32 * sizeof (char))
#define ARGV_ALLOCATION_UNIT (8 * sizeof (void*))
/* Expand arguments in ARGLIST into multiple arguments. */
char **
grub_script_execute_arglist_to_argv (struct grub_script_arglist *arglist, int *count)
{
int i;
int oom;
int argc;
int empty;
char *ptr;
char **argv;
char *value;
struct grub_script_arg *arg;
auto void push (char *str);
void push (char *str)
{
char **p;
if (oom)
return;
p = grub_realloc (argv, ALIGN_UP (sizeof(char*) * (argc + 1), ARGV_ALLOCATION_UNIT));
if (!p)
oom = 1;
else
{
p[argc++] = str;
argv = p;
}
}
auto char* append (const char *str, grub_size_t nchar);
char* append (const char *str, grub_size_t nchar)
{
int len;
int old;
char *p;
if (oom || !str)
return 0;
len = nchar ?: grub_strlen (str);
old = argv[argc - 1] ? grub_strlen (argv[argc - 1]) : 0;
p = grub_realloc (argv[argc - 1], ALIGN_UP(old + len + 1, ARG_ALLOCATION_UNIT));
if (p)
{
grub_strncpy (p + old, str, len);
p[old + len] = '\0';
}
else
{
oom = 1;
grub_free (argv[argc - 1]);
}
argv[argc - 1] = p;
return argv[argc - 1];
}
/* Move *STR to the begining of next word, but return current word. */
auto char* move_to_next (char **str);
char* move_to_next (char **str)
{
char *end;
char *start;
if (oom || !str || !*str)
return 0;
start = *str;
while (*start && grub_isspace (*start)) start++;
if (*start == '\0')
return 0;
end = start + 1;
while (*end && !grub_isspace (*end)) end++;
*str = end;
return start;
}
oom = 0;
argv = 0;
argc = 0;
push (0);
for (; arglist; arglist = arglist->next)
{
empty = 1;
arg = arglist->arg;
while (arg)
{
switch (arg->type)
{
case GRUB_SCRIPT_ARG_TYPE_VAR:
value = grub_script_env_get (arg->str);
while (value && *value && (ptr = move_to_next(&value)))
{
empty = 0;
append (ptr, value - ptr);
if (*value) push(0);
}
break;
case GRUB_SCRIPT_ARG_TYPE_TEXT:
if (grub_strlen (arg->str) > 0)
{
empty = 0;
append (arg->str, 0);
}
break;
case GRUB_SCRIPT_ARG_TYPE_DQSTR:
case GRUB_SCRIPT_ARG_TYPE_SQSTR:
empty = 0;
append (arg->str, 0);
break;
case GRUB_SCRIPT_ARG_TYPE_DQVAR:
empty = 0;
append (grub_script_env_get (arg->str), 0);
break;
}
arg = arg->next;
}
if (!empty)
push (0);
}
if (oom)
{
for (i = 0; i < argc; i++)
grub_free (argv[i]);
grub_free (argv);
argv = 0;
}
if (argv)
*count = argc - 1;
return argv;
}
/* Execute a function call. */
grub_err_t
grub_script_function_call (grub_script_function_t func, int argc, char **args)
{
grub_err_t ret = 0;
unsigned long loops = active_loops;
struct grub_script_scope *old_scope;
struct grub_script_scope new_scope;
active_loops = 0;
new_scope.argc = argc;
new_scope.args = args;
grub_list_push (GRUB_AS_LIST_P (&scope), GRUB_AS_LIST (&new_scope));
new_scope.argv.argc = argc;
new_scope.argv.args = args;
old_scope = scope;
scope = &new_scope;
ret = grub_script_execute (func->func);
grub_list_pop (GRUB_AS_LIST_P (&scope));
active_loops = loops;
scope = old_scope;
return ret;
}
@ -282,21 +271,18 @@ grub_err_t
grub_script_execute_cmdline (struct grub_script_cmd *cmd)
{
struct grub_script_cmdline *cmdline = (struct grub_script_cmdline *) cmd;
char **args = 0;
int i = 0;
grub_command_t grubcmd;
grub_err_t ret = 0;
int argcount = 0;
grub_script_function_t func = 0;
char errnobuf[18];
char *cmdname;
struct grub_script_argv argv = { 0, 0 };
/* Lookup the command. */
args = grub_script_execute_arglist_to_argv (cmdline->arglist, &argcount);
if (!args)
if (grub_script_arglist_to_argv (cmdline->arglist, &argv))
return grub_errno;
cmdname = args[0];
cmdname = argv.args[0];
grubcmd = grub_command_find (cmdname);
if (! grubcmd)
{
@ -323,7 +309,7 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd)
grub_free (assign);
grub_snprintf (errnobuf, sizeof (errnobuf), "%d", grub_errno);
grub_script_env_set ("?", errnobuf);
grub_env_set ("?", errnobuf);
grub_print_error ();
@ -333,14 +319,12 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd)
/* Execute the GRUB command or function. */
if (grubcmd)
ret = (grubcmd->func) (grubcmd, argcount - 1, args + 1);
ret = (grubcmd->func) (grubcmd, argv.argc - 1, argv.args + 1);
else
ret = grub_script_function_call (func, argcount - 1, args + 1);
ret = grub_script_function_call (func, argv.argc - 1, argv.args + 1);
/* Free arguments. */
for (i = 0; i < argcount; i++)
grub_free (args[i]);
grub_free (args);
grub_script_argv_free (&argv);
if (grub_errno == GRUB_ERR_TEST_FAILURE)
grub_errno = GRUB_ERR_NONE;
@ -377,7 +361,7 @@ grub_script_execute_cmdif (struct grub_script_cmd *cmd)
/* Check if the commands results in a true or a false. The value is
read from the env variable `?'. */
grub_script_execute_cmd (cmdif->exec_to_evaluate);
result = grub_script_env_get ("?");
result = grub_env_get ("?");
grub_errno = GRUB_ERR_NONE;
@ -395,31 +379,28 @@ grub_script_execute_cmdfor (struct grub_script_cmd *cmd)
{
int i;
int result;
char **args;
int argcount;
struct grub_script_argv argv;
struct grub_script_cmdfor *cmdfor = (struct grub_script_cmdfor *) cmd;
args = grub_script_execute_arglist_to_argv (cmdfor->words, &argcount);
if (!args)
if (grub_script_arglist_to_argv (cmdfor->words, &argv))
return grub_errno;
active_loops++;
result = 0;
for (i = 0; i < argcount; i++)
for (i = 0; i < argv.argc; i++)
{
if (! active_breaks)
{
grub_script_env_set (cmdfor->name->str, args[i]);
grub_script_env_set (cmdfor->name->str, argv.args[i]);
result = grub_script_execute_cmd (cmdfor->list);
}
grub_free (args[i]);
}
if (active_breaks)
active_breaks--;
active_loops--;
grub_free (args);
grub_script_argv_free (&argv);
return result;
}
@ -457,26 +438,20 @@ grub_err_t
grub_script_execute_menuentry (struct grub_script_cmd *cmd)
{
struct grub_script_cmd_menuentry *cmd_menuentry;
char **args = 0;
int argcount = 0;
int i = 0;
struct grub_script_argv argv = {0, 0};
cmd_menuentry = (struct grub_script_cmd_menuentry *) cmd;
if (cmd_menuentry->arglist)
{
args = grub_script_execute_arglist_to_argv (cmd_menuentry->arglist, &argcount);
if (!args)
if (grub_script_arglist_to_argv (cmd_menuentry->arglist, &argv))
return grub_errno;
}
grub_normal_add_menu_entry (argcount, (const char **) args,
grub_normal_add_menu_entry (argv.argc, (const char **) argv.args,
cmd_menuentry->sourcecode);
/* Free arguments. */
for (i = 0; i < argcount; i++)
grub_free (args[i]);
grub_free (args);
grub_script_argv_free (&argv);
return grub_errno;
}

View File

@ -119,7 +119,7 @@ DIGITS [[:digit:]]+
NAME [[:alpha:]_][[:alnum:][:digit:]_]*
ESC \\.
SPECIAL \?|\#
SPECIAL \?|\#|\*|\@
VARIABLE ${NAME}|$\{{NAME}\}|${DIGITS}|$\{{DIGITS}\}|${SPECIAL}|$\{{SPECIAL}\}
DQSTR \"([^\\\"]|{ESC})*\"
SQSTR \'[^\']*\'

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;
}
#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. */
@ -321,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

View File

@ -16,6 +16,33 @@
# You should have received a copy of the GNU General Public License
# along with GRUB. If not, see <http://www.gnu.org/licenses/>.
# simple arguments
echo one two three
echo "one two three"
echo 'one two three'
# empty arguments
echo a "" b
echo a '' b
echo a $foo b
echo a ${foo} b
echo a "$foo" b
echo a "${foo}" b
# multi-part arguments
echo one"two"three
echo one${two}three
echo one"two"$three
echo one'two'three
echo one${two}three
echo one'two'$three
echo one'two'three"four"five${six}seven$eight
foo=bar
echo $foo ${foo}
echo "$foo" "${foo}"

View File

@ -18,7 +18,7 @@
echo parameter count
function fcount {
echo "$#"
echo fcount "$#"
}
fcount
@ -27,7 +27,7 @@ fcount a b
echo parameter count, with nesting
function ffcount {
echo "$#"
echo ffcount "$#"
fcount
fcount a
fcount a b
@ -39,9 +39,9 @@ ffcount 1 2
echo parameters
function fparam {
echo 1 $1
echo 2 $2
echo 3 $3
echo fparam 1 $1
echo fparam 2 $2
echo fparam 3 $3
}
fparam
@ -50,9 +50,9 @@ fparam a b
echo parameters, with nesting
function ffparam {
echo 1 $1
echo 2 $2
echo 3 $3
echo ffparam 1 $1
echo ffparam 2 $2
echo ffparam 3 $3
fparam
fparam a
fparam a b
@ -61,3 +61,87 @@ function ffparam {
ffparam
ffparam 1
ffparam 1 2
echo parameter expansion with specials
function fstar {
for f in $*
do
echo fstar $f
done
for f in aaa$*bbb
do
echo fstar $f
done
}
fstar
fstar a
fstar a "1 2"
fstar a "1 2" b
function fdqstar {
for f in "$*"
do
echo fdqstar $f
done
for f in aaa"$*"bbb
do
echo fdqstar $f
done
for f in "aaa$*bbb"
do
echo fdqstar $f
done
}
fdqstar
fdqstar a
fdqstar a "1 2"
fdqstar a "1 2" b
function fat {
for f in $@
do
echo fat $f
done
for f in aaa$@bbb
do
echo fat $f
done
}
fat
fat a
fat a "1 2"
fat a "1 2" b
fat a "1 2" b "c d"
fat a "1 2" b "c d" e
function fdqat {
for f in "$@"
do
echo fdqat $f
done
for f in aaa"$@"bbb
do
echo fdqat $f
done
for f in "aaa$@bbb"
do
echo fdqat $f
done
}
# fdqat # this case needs special handling, lets ignore till we really need it.
fdqat a
fdqat a "1 2"
fdqat a "1 2" b
fdqat a "1 2" b "c d"
fdqat a "1 2" b "c d" e

View File

@ -28,7 +28,7 @@ foo=foo
echo "" $foo
echo $bar $foo
bar=""
echo $bar $foo

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
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,47 +172,51 @@ 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);
id = grub_jpeg_get_byte (data);
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++)
while (data->file->offset + sizeof (count) + 1 <= next_marker)
{
base += count[i];
ofs += count[i];
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");
data->huff_maxval[id][i] = base;
data->huff_offset[id][i] = ofs - base;
if (grub_file_read (data->file, &count, sizeof (count)) !=
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)
@ -229,17 +234,24 @@ grub_jpeg_decode_quan_table (struct grub_jpeg_data *data)
next_marker = data->file->offset;
next_marker += grub_jpeg_get_word (data);
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");
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");
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], 64) != 64)
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;
}
if (data->file->offset != next_marker)
grub_error (GRUB_ERR_BAD_FILE_TYPE,
@ -444,7 +456,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));
@ -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];
pos = 1;
while (pos < 64)
while (pos < ARRAY_SIZE (data->quan_table[qt]))
{
int num, val;
@ -700,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;
@ -735,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
}