Merge mainline into gfxmenu

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2010-02-03 01:24:07 +01:00
commit 1f534b6908
279 changed files with 9437 additions and 3021 deletions

View file

@ -73,18 +73,6 @@ grub_core_cmd_unset (struct grub_command *cmd __attribute__ ((unused)),
return 0;
}
static grub_err_t
grub_core_cmd_export (struct grub_command *cmd __attribute__ ((unused)),
int argc, char **args)
{
if (argc < 1)
return grub_error (GRUB_ERR_BAD_ARGUMENT,
"no environment variable specified");
grub_env_export (args[0]);
return 0;
}
/* insmod MODULE */
static grub_err_t
grub_core_cmd_insmod (struct grub_command *cmd __attribute__ ((unused)),
@ -193,8 +181,6 @@ grub_register_core_commands (void)
"[ENVVAR=VALUE]", "Set an environment variable.");
grub_register_command ("unset", grub_core_cmd_unset,
"ENVVAR", "Remove an environment variable.");
grub_register_command ("export", grub_core_cmd_export,
"ENVVAR", "Export a variable.");
grub_register_command ("ls", grub_core_cmd_ls,
"[ARG]", "List devices or files.");
grub_register_command ("insmod", grub_core_cmd_insmod,

View file

@ -86,7 +86,7 @@ grub_device_iterate (int (*hook) (const char *name))
struct part_ent
{
struct part_ent *next;
char name[0];
char *name;
} *ents;
int iterate_disk (const char *disk_name)
@ -118,6 +118,7 @@ grub_device_iterate (int (*hook) (const char *name))
if (!ret)
ret = hook (p->name);
grub_free (p->name);
grub_free (p);
p = next;
}
@ -138,15 +139,20 @@ grub_device_iterate (int (*hook) (const char *name))
if (! partition_name)
return 1;
p = grub_malloc (sizeof (p->next) + grub_strlen (disk->name) + 1 +
grub_strlen (partition_name) + 1);
p = grub_malloc (sizeof (*p));
if (!p)
{
grub_free (partition_name);
return 1;
}
grub_sprintf (p->name, "%s,%s", disk->name, partition_name);
p->name = grub_xasprintf ("%s,%s", disk->name, partition_name);
if (!p->name)
{
grub_free (partition_name);
grub_free (p);
return 1;
}
grub_free (partition_name);
p->next = ents;

View file

@ -441,7 +441,7 @@ grub_disk_read (grub_disk_t disk, grub_disk_addr_t sector,
grub_errno = GRUB_ERR_NONE;
num = ((size + GRUB_DISK_SECTOR_SIZE - 1)
num = ((size + real_offset + GRUB_DISK_SECTOR_SIZE - 1)
>> GRUB_DISK_SECTOR_BITS);
p = grub_realloc (tmp_buf, num << GRUB_DISK_SECTOR_BITS);
@ -464,12 +464,14 @@ grub_disk_read (grub_disk_t disk, grub_disk_addr_t sector,
if (disk->read_hook)
while (size)
{
grub_size_t to_read = (size > GRUB_DISK_SECTOR_SIZE) ? GRUB_DISK_SECTOR_SIZE : size;
(disk->read_hook) (sector, real_offset,
((size > GRUB_DISK_SECTOR_SIZE)
? GRUB_DISK_SECTOR_SIZE
: size));
to_read);
if (grub_errno != GRUB_ERR_NONE)
goto finish;
sector++;
size -= GRUB_DISK_SECTOR_SIZE - real_offset;
size -= to_read - real_offset;
real_offset = 0;
}

View file

@ -341,6 +341,7 @@ grub_dl_resolve_symbols (grub_dl_t mod, Elf_Ehdr *e)
switch (type)
{
case STT_NOTYPE:
case STT_OBJECT:
/* Resolve a global symbol. */
if (sym->st_name != 0 && sym->st_shndx == 0)
{
@ -350,15 +351,13 @@ grub_dl_resolve_symbols (grub_dl_t mod, Elf_Ehdr *e)
"the symbol `%s' not found", name);
}
else
sym->st_value = 0;
break;
case STT_OBJECT:
sym->st_value += (Elf_Addr) grub_dl_get_section_addr (mod,
sym->st_shndx);
if (bind != STB_LOCAL)
if (grub_dl_register_symbol (name, (void *) sym->st_value, mod))
return grub_errno;
{
sym->st_value += (Elf_Addr) grub_dl_get_section_addr (mod,
sym->st_shndx);
if (bind != STB_LOCAL)
if (grub_dl_register_symbol (name, (void *) sym->st_value, mod))
return grub_errno;
}
break;
case STT_FUNC:
@ -628,12 +627,10 @@ grub_dl_load (const char *name)
return 0;
}
filename = (char *) grub_malloc (grub_strlen (grub_dl_dir) + 1
+ grub_strlen (name) + 4 + 1);
filename = grub_xasprintf ("%s/%s.mod", grub_dl_dir, name);
if (! filename)
return 0;
grub_sprintf (filename, "%s/%s.mod", grub_dl_dir, name);
mod = grub_dl_load_file (filename);
grub_free (filename);

View file

@ -1,7 +1,7 @@
/* efi.c - generic EFI support */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2006,2007,2008,2009 Free Software Foundation, Inc.
* Copyright (C) 2006,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
@ -162,6 +162,8 @@ grub_exit (void)
for (;;) ;
}
/* On i386, a firmware-independant grub_reboot() is provided by realmode.S. */
#ifndef __i386__
void
grub_reboot (void)
{
@ -169,6 +171,7 @@ grub_reboot (void)
efi_call_4 (grub_efi_system_table->runtime_services->reset_system,
GRUB_EFI_RESET_COLD, GRUB_EFI_SUCCESS, 0, NULL);
}
#endif
void
grub_halt (void)

View file

@ -63,11 +63,10 @@ grub_efi_set_prefix (void)
if (p)
*p = '\0';
prefix = grub_malloc (1 + grub_strlen (device) + 1
+ grub_strlen (file) + 1);
prefix = grub_xasprintf ("(%s)%s", device, file);
if (prefix)
{
grub_sprintf (prefix, "(%s)%s", device, file);
grub_env_set ("prefix", prefix);
grub_free (prefix);
}
@ -82,6 +81,5 @@ void
grub_efi_fini (void)
{
grub_efidisk_fini ();
grub_efi_mm_fini ();
grub_console_fini ();
}

View file

@ -172,7 +172,7 @@ grub_elf32_phdr_iterate (grub_elf_t elf,
/* Calculate the amount of memory spanned by the segments. */
grub_size_t
grub_elf32_size (grub_elf_t elf)
grub_elf32_size (grub_elf_t elf, Elf32_Addr *base)
{
Elf32_Addr segments_start = (Elf32_Addr) -1;
Elf32_Addr segments_end = 0;
@ -198,6 +198,9 @@ grub_elf32_size (grub_elf_t elf)
grub_elf32_phdr_iterate (elf, calcsize, 0);
if (base)
*base = 0;
if (nr_phdrs == 0)
{
grub_error (GRUB_ERR_BAD_OS, "no program headers present");
@ -211,10 +214,12 @@ grub_elf32_size (grub_elf_t elf)
return 0;
}
if (base)
*base = segments_start;
return segments_end - segments_start;
}
/* Load every loadable segment into memory specified by `_load_hook'. */
grub_err_t
grub_elf32_load (grub_elf_t _elf, grub_elf32_load_hook_t _load_hook,
@ -353,7 +358,7 @@ grub_elf64_phdr_iterate (grub_elf_t elf,
/* Calculate the amount of memory spanned by the segments. */
grub_size_t
grub_elf64_size (grub_elf_t elf)
grub_elf64_size (grub_elf_t elf, Elf64_Addr *base)
{
Elf64_Addr segments_start = (Elf64_Addr) -1;
Elf64_Addr segments_end = 0;
@ -379,6 +384,9 @@ grub_elf64_size (grub_elf_t elf)
grub_elf64_phdr_iterate (elf, calcsize, 0);
if (base)
*base = 0;
if (nr_phdrs == 0)
{
grub_error (GRUB_ERR_BAD_OS, "no program headers present");
@ -392,6 +400,9 @@ grub_elf64_size (grub_elf_t elf)
return 0;
}
if (base)
*base = segments_start;
return segments_end - segments_start;
}

View file

@ -18,34 +18,15 @@
*/
#include <grub/env.h>
#include <grub/env_private.h>
#include <grub/misc.h>
#include <grub/mm.h>
/* The size of the hash table. */
#define HASHSZ 13
/* A hashtable for quick lookup of variables. */
struct grub_env_context
{
/* A hash table for variables. */
struct grub_env_var *vars[HASHSZ];
/* One level deeper on the stack. */
struct grub_env_context *prev;
};
/* This is used for sorting only. */
struct grub_env_sorted_var
{
struct grub_env_var *var;
struct grub_env_sorted_var *next;
};
/* The initial context. */
static struct grub_env_context initial_context;
/* The current context. */
static struct grub_env_context *current_context = &initial_context;
struct grub_env_context *grub_current_context = &initial_context;
/* Return the hash representation of the string S. */
static unsigned int
@ -60,88 +41,20 @@ grub_env_hashval (const char *s)
return i % HASHSZ;
}
static struct grub_env_var *
struct grub_env_var *
grub_env_find (const char *name)
{
struct grub_env_var *var;
int idx = grub_env_hashval (name);
/* Look for the variable in the current context. */
for (var = current_context->vars[idx]; var; var = var->next)
for (var = grub_current_context->vars[idx]; var; var = var->next)
if (grub_strcmp (var->name, name) == 0)
return var;
return 0;
}
grub_err_t
grub_env_context_open (int export)
{
struct grub_env_context *context;
int i;
context = grub_zalloc (sizeof (*context));
if (! context)
return grub_errno;
context->prev = current_context;
current_context = context;
/* Copy exported variables. */
for (i = 0; i < HASHSZ; i++)
{
struct grub_env_var *var;
for (var = context->prev->vars[i]; var; var = var->next)
{
if (export && var->type == GRUB_ENV_VAR_GLOBAL)
{
if (grub_env_set (var->name, var->value) != GRUB_ERR_NONE)
{
grub_env_context_close ();
return grub_errno;
}
grub_env_export (var->name);
grub_register_variable_hook (var->name, var->read_hook, var->write_hook);
}
}
}
return GRUB_ERR_NONE;
}
grub_err_t
grub_env_context_close (void)
{
struct grub_env_context *context;
int i;
if (! current_context->prev)
grub_fatal ("cannot close the initial context");
/* Free the variables associated with this context. */
for (i = 0; i < HASHSZ; i++)
{
struct grub_env_var *p, *q;
for (p = current_context->vars[i]; p; p = q)
{
q = p->next;
grub_free (p->name);
if (p->type != GRUB_ENV_VAR_DATA)
grub_free (p->value);
grub_free (p);
}
}
/* Restore the previous context. */
context = current_context->prev;
grub_free (current_context);
current_context = context;
return GRUB_ERR_NONE;
}
static void
grub_env_insert (struct grub_env_context *context,
struct grub_env_var *var)
@ -165,26 +78,6 @@ grub_env_remove (struct grub_env_var *var)
var->next->prevp = var->prevp;
}
grub_err_t
grub_env_export (const char *name)
{
struct grub_env_var *var;
var = grub_env_find (name);
if (! var)
{
grub_err_t err;
err = grub_env_set (name, "");
if (err)
return err;
var = grub_env_find (name);
}
var->type = GRUB_ENV_VAR_GLOBAL;
return GRUB_ERR_NONE;
}
grub_err_t
grub_env_set (const char *name, const char *val)
{
@ -216,9 +109,8 @@ grub_env_set (const char *name, const char *val)
if (! var)
return grub_errno;
/* This is not necessary, because GRUB_ENV_VAR_LOCAL == 0. But leave
this for readability. */
var->type = GRUB_ENV_VAR_LOCAL;
/* This is not necessary. But leave this for readability. */
var->global = 0;
var->name = grub_strdup (name);
if (! var->name)
@ -228,7 +120,7 @@ grub_env_set (const char *name, const char *val)
if (! var->value)
goto fail;
grub_env_insert (current_context, var);
grub_env_insert (grub_current_context, var);
return GRUB_ERR_NONE;
@ -273,8 +165,7 @@ grub_env_unset (const char *name)
grub_env_remove (var);
grub_free (var->name);
if (var->type != GRUB_ENV_VAR_DATA)
grub_free (var->value);
grub_free (var->value);
grub_free (var);
}
@ -290,14 +181,10 @@ grub_env_iterate (int (*func) (struct grub_env_var *var))
{
struct grub_env_var *var;
for (var = current_context->vars[i]; var; var = var->next)
for (var = grub_current_context->vars[i]; var; var = var->next)
{
struct grub_env_sorted_var *p, **q;
/* Ignore data slots. */
if (var->type == GRUB_ENV_VAR_DATA)
continue;
sorted_var = grub_malloc (sizeof (*sorted_var));
if (! sorted_var)
goto fail;
@ -353,84 +240,3 @@ grub_register_variable_hook (const char *name,
return GRUB_ERR_NONE;
}
static char *
mangle_data_slot_name (const char *name)
{
char *mangled_name;
mangled_name = grub_malloc (grub_strlen (name) + 2);
if (! mangled_name)
return 0;
grub_sprintf (mangled_name, "\e%s", name);
return mangled_name;
}
grub_err_t
grub_env_set_data_slot (const char *name, const void *ptr)
{
char *mangled_name;
struct grub_env_var *var;
mangled_name = mangle_data_slot_name (name);
if (! mangled_name)
goto fail;
/* If the variable does already exist, just update the variable. */
var = grub_env_find (mangled_name);
if (var)
{
var->value = (char *) ptr;
return GRUB_ERR_NONE;
}
/* The variable does not exist, so create a new one. */
var = grub_zalloc (sizeof (*var));
if (! var)
goto fail;
var->type = GRUB_ENV_VAR_DATA;
var->name = mangled_name;
var->value = (char *) ptr;
grub_env_insert (current_context, var);
return GRUB_ERR_NONE;
fail:
grub_free (mangled_name);
return grub_errno;
}
void *
grub_env_get_data_slot (const char *name)
{
char *mangled_name;
void *ptr = 0;
mangled_name = mangle_data_slot_name (name);
if (! mangled_name)
goto fail;
ptr = grub_env_get (mangled_name);
grub_free (mangled_name);
fail:
return ptr;
}
void
grub_env_unset_data_slot (const char *name)
{
char *mangled_name;
mangled_name = mangle_data_slot_name (name);
if (! mangled_name)
return;
grub_env_unset (mangled_name);
grub_free (mangled_name);
}

View file

@ -20,6 +20,7 @@
#include <grub/err.h>
#include <grub/misc.h>
#include <stdarg.h>
#include <grub/i18n.h>
#define GRUB_MAX_ERRMSG 256
#define GRUB_ERROR_STACK_SIZE 10
@ -44,7 +45,7 @@ grub_error (grub_err_t n, const char *fmt, ...)
grub_errno = n;
va_start (ap, fmt);
grub_vsprintf (grub_errmsg, fmt, ap);
grub_vsnprintf (grub_errmsg, sizeof (grub_errmsg), _(fmt), ap);
va_end (ap);
return n;
@ -56,7 +57,7 @@ grub_fatal (const char *fmt, ...)
va_list ap;
va_start (ap, fmt);
grub_vprintf (fmt, ap);
grub_vprintf (_(fmt), ap);
va_end (ap);
grub_abort ();
@ -121,7 +122,7 @@ grub_print_error (void)
do
{
if (grub_errno != GRUB_ERR_NONE)
grub_err_printf ("error: %s\n", grub_errmsg);
grub_err_printf (_("error: %s.\n"), grub_errmsg);
}
while (grub_error_pop ());

View file

@ -1,7 +1,7 @@
/* startup.S - bootstrap GRUB itself */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2006,2007 Free Software Foundation, Inc.
* Copyright (C) 2006,2007,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
@ -62,3 +62,5 @@ codestart:
movl %eax, EXT_C(grub_efi_system_table)
call EXT_C(grub_main)
ret
#include "../realmode.S"

View file

@ -59,7 +59,7 @@ VARIABLE(grub_linux_real_addr)
VARIABLE(grub_linux_is_bzimage)
.long 0
FUNCTION(grub_linux16_boot)
FUNCTION(grub_linux16_real_boot)
/* Must be done before zImage copy. */
call EXT_C(grub_dl_unload_all)

View file

@ -1,6 +1,6 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc.
* Copyright (C) 2002,2003,2004,2005,2006,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
@ -18,6 +18,7 @@
#include <grub/kernel.h>
#include <grub/mm.h>
#include <grub/machine/boot.h>
#include <grub/machine/init.h>
#include <grub/machine/memory.h>
#include <grub/machine/console.h>
@ -56,22 +57,36 @@ static char *
make_install_device (void)
{
/* XXX: This should be enough. */
char dev[100];
char dev[100], *ptr = dev;
if (grub_prefix[0] != '(')
{
/* No hardcoded root partition - make it from the boot drive and the
partition number encoded at the install time. */
grub_sprintf (dev, "(%cd%u", (grub_boot_drive & 0x80) ? 'h' : 'f',
grub_boot_drive & 0x7f);
if (grub_boot_drive == GRUB_BOOT_MACHINE_PXE_DL)
{
grub_strcpy (dev, "(pxe");
ptr += sizeof ("(pxe") - 1;
}
else
{
grub_snprintf (dev, sizeof (dev),
"(%cd%u", (grub_boot_drive & 0x80) ? 'h' : 'f',
grub_boot_drive & 0x7f);
ptr += grub_strlen (ptr);
if (grub_install_dos_part >= 0)
grub_sprintf (dev + grub_strlen (dev), ",%u", grub_install_dos_part + 1);
if (grub_install_dos_part >= 0)
grub_snprintf (ptr, sizeof (dev) - (ptr - dev),
",%u", grub_install_dos_part + 1);
ptr += grub_strlen (ptr);
if (grub_install_bsd_part >= 0)
grub_sprintf (dev + grub_strlen (dev), ",%c", grub_install_bsd_part + 'a');
if (grub_install_bsd_part >= 0)
grub_snprintf (ptr, sizeof (dev) - (ptr - dev), ",%c",
grub_install_bsd_part + 'a');
ptr += grub_strlen (ptr);
}
grub_sprintf (dev + grub_strlen (dev), ")%s", grub_prefix);
grub_snprintf (ptr, sizeof (dev) - (ptr - dev), ")%s", grub_prefix);
grub_strcpy (grub_prefix, dev);
}

View file

@ -22,7 +22,7 @@
#include <grub/types.h>
#include <grub/err.h>
#include <grub/misc.h>
#include <grub/i386/cmos.h>
#include <grub/cmos.h>
#define QEMU_CMOS_MEMSIZE_HIGH 0x35
#define QEMU_CMOS_MEMSIZE_LOW 0x34

View file

@ -1,6 +1,6 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 1999,2000,2001,2002,2003,2005,2006,2007,2009 Free Software Foundation, Inc.
* Copyright (C) 1999,2000,2001,2002,2003,2005,2006,2007,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
@ -16,6 +16,7 @@
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/i386/pc/memory.h>
/*
* Note: These functions defined in this file may be called from C.

View file

@ -75,10 +75,6 @@ grub_machine_set_prefix (void)
char *filename;
char *prefix;
if (grub_env_get ("prefix"))
/* We already set prefix in grub_machine_init(). */
return;
if (grub_prefix[0])
{
grub_env_set ("prefix", grub_prefix);
@ -111,11 +107,12 @@ grub_machine_set_prefix (void)
*lastslash = '\0';
grub_translate_ieee1275_path (filename);
newprefix = grub_malloc (grub_strlen (prefix)
+ grub_strlen (filename));
grub_sprintf (newprefix, "%s%s", prefix, filename);
grub_free (prefix);
prefix = newprefix;
newprefix = grub_xasprintf ("%s%s", prefix, filename);
if (newprefix)
{
grub_free (prefix);
prefix = newprefix;
}
}
}

View file

@ -38,7 +38,7 @@ grub_children_iterate (char *devpath,
grub_ieee1275_phandle_t dev;
grub_ieee1275_phandle_t child;
char *childtype, *childpath;
char *childname, *fullname;
char *childname;
int ret = 0;
if (grub_ieee1275_finddevice (devpath, &dev))
@ -63,19 +63,12 @@ grub_children_iterate (char *devpath,
grub_free (childtype);
return 0;
}
fullname = grub_malloc (IEEE1275_MAX_PATH_LEN);
if (!fullname)
{
grub_free (childname);
grub_free (childpath);
grub_free (childtype);
return 0;
}
do
{
struct grub_ieee1275_devalias alias;
grub_ssize_t actual;
char *fullname;
if (grub_ieee1275_get_property (child, "device_type", childtype,
IEEE1275_MAX_PROP_LEN, &actual))
@ -89,18 +82,25 @@ grub_children_iterate (char *devpath,
IEEE1275_MAX_PROP_LEN, &actual))
continue;
grub_sprintf (fullname, "%s/%s", devpath, childname);
fullname = grub_xasprintf ("%s/%s", devpath, childname);
if (!fullname)
{
grub_free (childname);
grub_free (childpath);
grub_free (childtype);
return 0;
}
alias.type = childtype;
alias.path = childpath;
alias.name = fullname;
ret = hook (&alias);
grub_free (fullname);
if (ret)
break;
}
while (grub_ieee1275_peer (child, &child));
grub_free (fullname);
grub_free (childname);
grub_free (childpath);
grub_free (childtype);
@ -330,12 +330,11 @@ grub_ieee1275_parse_args (const char *path, enum grub_ieee1275_parse_type ptype)
{
char *filepath = comma + 1;
ret = grub_malloc (grub_strlen (filepath) + 1);
/* Make sure filepath has leading backslash. */
if (filepath[0] != '\\')
grub_sprintf (ret, "\\%s", filepath);
ret = grub_xasprintf ("\\%s", filepath);
else
grub_strcpy (ret, filepath);
ret = grub_strdup (filepath);
}
}
else if (ptype == GRUB_PARSE_PARTITION)
@ -383,15 +382,10 @@ grub_ieee1275_encode_devname (const char *path)
/* GRUB partition 1 is OF partition 0. */
partno++;
/* Assume partno will require less than five bytes to encode. */
encoding = grub_malloc (grub_strlen (device) + 3 + 5);
grub_sprintf (encoding, "(%s,%d)", device, partno);
encoding = grub_xasprintf ("(%s,%d)", device, partno);
}
else
{
encoding = grub_malloc (grub_strlen (device) + 2);
grub_sprintf (encoding, "(%s)", device);
}
encoding = grub_xasprintf ("(%s)", device);
grub_free (partition);
grub_free (device);

View file

@ -114,7 +114,6 @@ grub_set_root_dev (void)
const char *prefix;
grub_register_variable_hook ("root", 0, grub_env_write_root);
grub_env_export ("root");
prefix = grub_env_get ("prefix");
@ -159,12 +158,14 @@ grub_main (void)
/* Load pre-loaded modules and free the space. */
grub_register_exported_symbols ();
#ifdef GRUB_LINKER_HAVE_INIT
grub_arch_dl_init_linker ();
#endif
grub_load_modules ();
/* It is better to set the root device as soon as possible,
for convenience. */
grub_machine_set_prefix ();
grub_env_export ("prefix");
grub_set_root_dev ();
grub_register_core_commands ();

7
kern/mips/cache.S Normal file
View file

@ -0,0 +1,7 @@
#include <grub/symbol.h>
FUNCTION (grub_cpu_flush_cache)
FUNCTION (grub_arch_sync_caches)
#include "cache_flush.S"
j $ra

23
kern/mips/cache_flush.S Normal file
View file

@ -0,0 +1,23 @@
move $t2, $a0
addu $t3, $a0, $a1
srl $t2, $t2, 5
sll $t2, $t2, 5
addu $t3, $t3, 0x1f
srl $t3, $t3, 5
sll $t3, $t3, 5
move $t0, $t2
subu $t1, $t3, $t2
1:
cache 1, 0($t0)
addiu $t0, $t0, 0x1
addiu $t1, $t1, 0xffff
bne $t1, $zero, 1b
sync
move $t0, $t2
subu $t1, $t3, $t2
2:
cache 0, 0($t0)
addiu $t0, $t0, 0x1
addiu $t1, $t1, 0xffff
bne $t1, $zero, 2b
sync

237
kern/mips/dl.c Normal file
View file

@ -0,0 +1,237 @@
/* dl-386.c - arch-dependent part of loadable module support */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2002,2005,2007,2009 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/dl.h>
#include <grub/elf.h>
#include <grub/misc.h>
#include <grub/err.h>
#include <grub/cpu/types.h>
#include <grub/mm.h>
/* Dummy __gnu_local_gp. Resolved by linker. */
static char __gnu_local_gp_dummy;
/* Check if EHDR is a valid ELF header. */
grub_err_t
grub_arch_dl_check_header (void *ehdr)
{
Elf_Ehdr *e = ehdr;
/* Check the magic numbers. */
#ifdef WORDS_BIGENDIAN
if (e->e_ident[EI_CLASS] != ELFCLASS32
|| e->e_ident[EI_DATA] != ELFDATA2MSB
|| e->e_machine != EM_MIPS)
#else
if (e->e_ident[EI_CLASS] != ELFCLASS32
|| e->e_ident[EI_DATA] != ELFDATA2LSB
|| e->e_machine != EM_MIPS)
#endif
return grub_error (GRUB_ERR_BAD_OS, "invalid arch specific ELF magic");
return GRUB_ERR_NONE;
}
/* Relocate symbols. */
grub_err_t
grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
{
Elf_Ehdr *e = ehdr;
Elf_Shdr *s;
Elf_Word entsize;
unsigned i;
grub_size_t gp_size = 0;
/* FIXME: suboptimal. */
grub_uint32_t *gp, *gpptr;
grub_uint32_t gp0;
/* Find a symbol table. */
for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff);
i < e->e_shnum;
i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize))
if (s->sh_type == SHT_SYMTAB)
break;
if (i == e->e_shnum)
return grub_error (GRUB_ERR_BAD_MODULE, "no symtab found");
entsize = s->sh_entsize;
/* Find reginfo. */
for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff);
i < e->e_shnum;
i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize))
if (s->sh_type == SHT_MIPS_REGINFO)
break;
if (i == e->e_shnum)
return grub_error (GRUB_ERR_BAD_MODULE, "no reginfo found");
gp0 = ((grub_uint32_t *)((char *) e + s->sh_offset))[5];
for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff);
i < e->e_shnum;
i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize))
if (s->sh_type == SHT_REL)
{
grub_dl_segment_t seg;
/* Find the target segment. */
for (seg = mod->segment; seg; seg = seg->next)
if (seg->section == s->sh_info)
break;
if (seg)
{
Elf_Rel *rel, *max;
for (rel = (Elf_Rel *) ((char *) e + s->sh_offset),
max = rel + s->sh_size / s->sh_entsize;
rel < max;
rel++)
switch (ELF_R_TYPE (rel->r_info))
{
case R_MIPS_GOT16:
case R_MIPS_CALL16:
case R_MIPS_GPREL32:
gp_size += 4;
break;
}
}
}
if (gp_size > 0x08000)
return grub_error (GRUB_ERR_OUT_OF_RANGE, "__gnu_local_gp is too big\n");
gpptr = gp = grub_malloc (gp_size);
if (!gp)
return grub_errno;
for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff);
i < e->e_shnum;
i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize))
if (s->sh_type == SHT_REL)
{
grub_dl_segment_t seg;
/* Find the target segment. */
for (seg = mod->segment; seg; seg = seg->next)
if (seg->section == s->sh_info)
break;
if (seg)
{
Elf_Rel *rel, *max;
for (rel = (Elf_Rel *) ((char *) e + s->sh_offset),
max = rel + s->sh_size / s->sh_entsize;
rel < max;
rel++)
{
Elf_Word *addr;
Elf_Sym *sym;
if (seg->size < rel->r_offset)
return grub_error (GRUB_ERR_BAD_MODULE,
"reloc offset is out of the segment");
addr = (Elf_Word *) ((char *) seg->addr + rel->r_offset);
sym = (Elf_Sym *) ((char *) mod->symtab
+ entsize * ELF_R_SYM (rel->r_info));
if (sym->st_value == (grub_addr_t) &__gnu_local_gp_dummy)
sym->st_value = (grub_addr_t) gp;
switch (ELF_R_TYPE (rel->r_info))
{
case R_MIPS_HI16:
{
grub_uint32_t value;
Elf_Rel *rel2;
/* Handle partner lo16 relocation. Lower part is
treated as signed. Hence add 0x8000 to compensate.
*/
value = (*(grub_uint16_t *) addr << 16)
+ sym->st_value + 0x8000;
for (rel2 = rel + 1; rel2 < max; rel2++)
if (ELF_R_SYM (rel2->r_info)
== ELF_R_SYM (rel->r_info)
&& ELF_R_TYPE (rel2->r_info) == R_MIPS_LO16)
{
value += *(grub_int16_t *)
((char *) seg->addr + rel2->r_offset);
break;
}
*(grub_uint16_t *) addr = (value >> 16) & 0xffff;
}
break;
case R_MIPS_LO16:
*(grub_uint16_t *) addr += (sym->st_value) & 0xffff;
break;
case R_MIPS_32:
*(grub_uint32_t *) addr += sym->st_value;
break;
case R_MIPS_GPREL32:
*(grub_uint32_t *) addr = sym->st_value
+ *(grub_uint32_t *) addr + gp0 - (grub_uint32_t)gp;
break;
case R_MIPS_26:
{
grub_uint32_t value;
grub_uint32_t raw;
raw = (*(grub_uint32_t *) addr) & 0x3ffffff;
value = raw << 2;
value += sym->st_value;
raw = (value >> 2) & 0x3ffffff;
*(grub_uint32_t *) addr =
raw | ((*(grub_uint32_t *) addr) & 0xfc000000);
}
break;
case R_MIPS_GOT16:
case R_MIPS_CALL16:
/* FIXME: reuse*/
*gpptr = sym->st_value + *(grub_uint16_t *) addr;
*(grub_uint16_t *) addr
= sizeof (grub_uint32_t) * (gpptr - gp);
gpptr++;
break;
default:
{
grub_free (gp);
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
"Unknown relocation type %d\n",
ELF_R_TYPE (rel->r_info));
}
break;
}
}
}
}
return GRUB_ERR_NONE;
}
void
grub_arch_dl_init_linker (void)
{
grub_dl_register_symbol ("__gnu_local_gp", &__gnu_local_gp_dummy, 0);
}

View file

@ -1,4 +1,3 @@
/* reader.c - reader support */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2009 Free Software Foundation, Inc.
@ -17,8 +16,20 @@
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/types.h>
#include <grub/mm.h>
#include <grub/reader.h>
#include <grub/parser.h>
#include <grub/kernel.h>
#include <grub/env.h>
#include <grub/mips/kernel.h>
void
grub_machine_set_prefix (void)
{
grub_env_set ("prefix", grub_prefix);
}
extern char _end[];
grub_addr_t
grub_arch_modules_addr (void)
{
return (grub_addr_t) _end;
}

View file

@ -0,0 +1,61 @@
#include <grub/kernel.h>
#include <grub/misc.h>
#include <grub/env.h>
#include <grub/time.h>
#include <grub/types.h>
#include <grub/misc.h>
#include <grub/mm.h>
#include <grub/time.h>
#include <grub/machine/kernel.h>
#include <grub/machine/memory.h>
#include <grub/cpu/kernel.h>
#define RAMSIZE (*(grub_uint32_t *) ((16 << 20) - 264))
grub_uint32_t
grub_get_rtc (void)
{
static int calln = 0;
return calln++;
}
void
grub_machine_init (void)
{
grub_mm_init_region ((void *) GRUB_MACHINE_MEMORY_USABLE,
RAMSIZE - (GRUB_MACHINE_MEMORY_USABLE & 0x7fffffff));
grub_install_get_time_ms (grub_rtc_get_time_ms);
}
void
grub_machine_fini (void)
{
}
void
grub_exit (void)
{
while (1);
}
void
grub_halt (void)
{
while (1);
}
void
grub_reboot (void)
{
while (1);
}
grub_err_t
grub_machine_mmap_iterate (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t,
grub_uint64_t,
grub_uint32_t))
{
hook (0, RAMSIZE,
GRUB_MACHINE_MEMORY_AVAILABLE);
return GRUB_ERR_NONE;
}

218
kern/mips/startup.S Normal file
View file

@ -0,0 +1,218 @@
/* startup.S - Startup code for the MIPS. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2009 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/symbol.h>
#include <grub/cpu/kernel.h>
#include <grub/machine/memory.h>
#define BASE_ADDR 8
.extern __bss_start
.extern _end
.globl __start, _start, start
__start:
_start:
start:
bal codestart
base:
. = _start + GRUB_KERNEL_CPU_COMPRESSED_SIZE
compressed_size:
.long 0
. = _start + GRUB_KERNEL_CPU_TOTAL_MODULE_SIZE
total_module_size:
.long 0
. = _start + GRUB_KERNEL_CPU_KERNEL_IMAGE_SIZE
kernel_image_size:
.long 0
codestart:
/* Save our base. */
move $s0, $ra
/* Parse arguments. Has to be done before relocation.
So need to do it in asm. */
#ifdef GRUB_MACHINE_MIPS_YEELOONG
/* $a2 has the environment. */
move $t0, $a2
argcont:
lw $t1, 0($t0)
beq $t1, $zero, argdone
#define DO_PARSE(str, reg) \
addiu $t2, $s0, (str-base);\
bal parsestr;\
beq $v0, $zero, 1f;\
move reg, $v0;\
b 2f;\
1:
DO_PARSE (busclockstr, $s2)
DO_PARSE (cpuclockstr, $s3)
DO_PARSE (memsizestr, $s4)
DO_PARSE (highmemsizestr, $s5)
2:
addiu $t0, $t0, 4
b argcont
parsestr:
move $v0, $zero
move $t3, $t1
3:
lb $t4, 0($t2)
lb $t5, 0($t3)
addiu $t2, $t2, 1
addiu $t3, $t3, 1
beq $t5, $zero, 1f
beq $t5, $t4, 3b
bne $t4, $zero, 1f
addiu $t3, $t3, 0xffff
digcont:
lb $t5, 0($t3)
/* Substract '0' from digit. */
addiu $t5, $t5, 0xffd0
bltz $t5, 1f
addiu $t4, $t5, 0xfff7
bgtz $t4, 1f
/* Multiply $v0 by 10 with bitshifts. */
sll $v0, $v0, 1
sll $t4, $v0, 2
addu $v0, $v0, $t4
addu $v0, $v0, $t5
addiu $t3, $t3, 1
b digcont
1:
jr $ra
busclockstr: .asciiz "busclock="
cpuclockstr: .asciiz "cpuclock="
memsizestr: .asciiz "memsize="
highmemsizestr: .asciiz "highmemsize="
.p2align 2
argdone:
#endif
/* Decompress the payload. */
addiu $a0, $s0, GRUB_KERNEL_CPU_RAW_SIZE - BASE_ADDR
lui $a1, %hi(compressed)
addiu $a1, %lo(compressed)
lw $a2, (GRUB_KERNEL_CPU_COMPRESSED_SIZE - BASE_ADDR)($s0)
move $s1, $a1
/* $a0 contains source compressed address, $a1 is destination,
$a2 is compressed size. FIXME: put LZMA here. Don't clober $s0,
$s1, $s2, $s3, $s4 and $s5.
On return $v0 contains uncompressed size.
*/
move $v0, $a2
reloccont:
lb $t4, 0($a0)
sb $t4, 0($a1)
addiu $a1,$a1,1
addiu $a0,$a0,1
addiu $a2, 0xffff
bne $a2, $0, reloccont
move $a0, $s1
move $a1, $v0
#include "cache_flush.S"
lui $t1, %hi(cont)
addiu $t1, %lo(cont)
jr $t1
. = _start + GRUB_KERNEL_CPU_RAW_SIZE
compressed:
. = _start + GRUB_KERNEL_CPU_PREFIX
VARIABLE(grub_prefix)
/* to be filled by grub-mkelfimage */
/*
* Leave some breathing room for the prefix.
*/
. = _start + GRUB_KERNEL_CPU_DATA_END
#ifdef GRUB_MACHINE_MIPS_YEELOONG
VARIABLE (grub_arch_busclock)
.long 0
VARIABLE (grub_arch_cpuclock)
.long 0
VARIABLE (grub_arch_memsize)
.long 0
VARIABLE (grub_arch_highmemsize)
.long 0
#endif
cont:
#ifdef GRUB_MACHINE_MIPS_YEELOONG
lui $t1, %hi(grub_arch_busclock)
addiu $t1, %lo(grub_arch_busclock)
sw $s2, 0($t1)
sw $s3, 4($t1)
sw $s4, 8($t1)
sw $s5, 12($t1)
#endif
/* Move the modules out of BSS. */
lui $t1, %hi(_start)
addiu $t1, %lo(_start)
lw $t2, (GRUB_KERNEL_CPU_KERNEL_IMAGE_SIZE - BASE_ADDR)($s0)
addu $t2, $t1, $t2
lui $t1, %hi(_end)
addiu $t1, %lo(_end)
addiu $t1, (GRUB_MOD_ALIGN-1)
li $t3, (GRUB_MOD_ALIGN-1)
nor $t3, $t3, $0
and $t1, $t1, $t3
lw $t3, (GRUB_KERNEL_CPU_TOTAL_MODULE_SIZE - BASE_ADDR)($s0)
/* Backward copy. */
add $t1, $t1, $t3
add $t2, $t2, $t3
addiu $t1, $t1, 0xffff
addiu $t2, $t2, 0xffff
/* $t2 is source. $t1 is destination. $t3 is size. */
modulesmovcont:
lb $t4, 0($t2)
sb $t4, 0($t1)
addiu $t1,$t1,0xffff
addiu $t2,$t2,0xffff
addiu $t3, 0xffff
bne $t3, $0, modulesmovcont
/* Clean BSS. */
lui $t1, %hi(__bss_start)
addiu $t1, %lo(__bss_start)
lui $t2, %hi(_end)
addiu $t2, %lo(_end)
bsscont:
sb $0,0($t1)
addiu $t1,$t1,1
sltu $t3,$t1,$t2
bne $t3, $0, bsscont
li $sp, GRUB_MACHINE_MEMORY_STACK_HIGH
lui $t1, %hi(grub_main)
addiu $t1, %lo(grub_main)
jr $t1

131
kern/mips/yeeloong/init.c Normal file
View file

@ -0,0 +1,131 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 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/>.
*/
#include <grub/kernel.h>
#include <grub/misc.h>
#include <grub/env.h>
#include <grub/time.h>
#include <grub/types.h>
#include <grub/misc.h>
#include <grub/mm.h>
#include <grub/time.h>
#include <grub/machine/kernel.h>
#include <grub/machine/memory.h>
#include <grub/cpu/kernel.h>
extern void grub_video_sm712_init (void);
extern void grub_video_video_init (void);
extern void grub_video_bitmap_init (void);
extern void grub_font_manager_init (void);
extern void grub_term_gfxterm_init (void);
extern void grub_at_keyboard_init (void);
/* FIXME: use interrupt to count high. */
grub_uint64_t
grub_get_rtc (void)
{
static grub_uint32_t high = 0;
static grub_uint32_t last = 0;
grub_uint32_t low;
asm volatile ("mfc0 %0, $9": "=r" (low));
if (low < last)
high++;
last = low;
return (((grub_uint64_t) high) << 32) | low;
}
grub_err_t
grub_machine_mmap_iterate (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t,
grub_uint64_t,
grub_uint32_t))
{
hook (GRUB_ARCH_LOWMEMPSTART, grub_arch_memsize << 20,
GRUB_MACHINE_MEMORY_AVAILABLE);
hook (GRUB_ARCH_HIGHMEMPSTART, grub_arch_highmemsize << 20,
GRUB_MACHINE_MEMORY_AVAILABLE);
return GRUB_ERR_NONE;
}
static void *
get_modules_end (void)
{
struct grub_module_info *modinfo;
struct grub_module_header *header;
grub_addr_t modbase;
modbase = grub_arch_modules_addr ();
modinfo = (struct grub_module_info *) modbase;
/* Check if there are any modules. */
if ((modinfo == 0) || modinfo->magic != GRUB_MODULE_MAGIC)
return modinfo;
for (header = (struct grub_module_header *) (modbase + modinfo->offset);
header < (struct grub_module_header *) (modbase + modinfo->size);
header = (struct grub_module_header *) ((char *) header + header->size));
return header;
}
void
grub_machine_init (void)
{
void *modend;
modend = get_modules_end ();
grub_mm_init_region (modend, (grub_arch_memsize << 20)
- (((grub_addr_t) modend) - GRUB_ARCH_LOWMEMVSTART));
/* FIXME: use upper memory as well. */
grub_install_get_time_ms (grub_rtc_get_time_ms);
/* Initialize output terminal (can't be done earlier, as gfxterm
relies on a working heap. */
grub_video_sm712_init ();
grub_video_video_init ();
grub_video_bitmap_init ();
grub_font_manager_init ();
grub_term_gfxterm_init ();
grub_at_keyboard_init ();
}
void
grub_machine_fini (void)
{
}
void
grub_exit (void)
{
while (1);
}
void
grub_halt (void)
{
while (1);
}
void
grub_reboot (void)
{
while (1);
}

View file

@ -25,6 +25,9 @@
#include <grub/env.h>
#include <grub/i18n.h>
static int
grub_vsnprintf_real (char *str, grub_size_t n, const char *fmt, va_list args);
static int
grub_iswordseparator (int c)
{
@ -202,7 +205,7 @@ grub_vprintf (const char *fmt, va_list args)
{
int ret;
ret = grub_vsprintf (0, fmt, args);
ret = grub_vsnprintf_real (0, 0, fmt, args);
return ret;
}
@ -635,11 +638,11 @@ grub_lltoa (char *str, int c, unsigned long long n)
return p;
}
int
grub_vsprintf (char *str, const char *fmt, va_list args)
static int
grub_vsnprintf_real (char *str, grub_size_t max_len, const char *fmt, va_list args)
{
char c;
int count = 0;
grub_size_t count = 0;
auto void write_char (unsigned char ch);
auto void write_str (const char *s);
auto void write_fill (const char ch, int n);
@ -647,7 +650,10 @@ grub_vsprintf (char *str, const char *fmt, va_list args)
void write_char (unsigned char ch)
{
if (str)
*str++ = ch;
{
if (count < max_len)
*str++ = ch;
}
else
grub_putchar (ch);
@ -873,13 +879,64 @@ grub_vsprintf (char *str, const char *fmt, va_list args)
}
int
grub_sprintf (char *str, const char *fmt, ...)
grub_vsnprintf (char *str, grub_size_t n, const char *fmt, va_list ap)
{
grub_size_t ret;
if (!n)
return 0;
n--;
ret = grub_vsnprintf_real (str, n, fmt, ap);
return ret < n ? ret : n;
}
int
grub_snprintf (char *str, grub_size_t n, const char *fmt, ...)
{
va_list ap;
int ret;
va_start (ap, fmt);
ret = grub_vsprintf (str, fmt, ap);
ret = grub_vsnprintf (str, n, fmt, ap);
va_end (ap);
return ret;
}
#define PREALLOC_SIZE 255
char *
grub_xvasprintf (const char *fmt, va_list ap)
{
grub_size_t s, as = PREALLOC_SIZE;
char *ret;
while (1)
{
ret = grub_malloc (as + 1);
if (!ret)
return NULL;
s = grub_vsnprintf_real (ret, as, fmt, ap);
if (s <= as)
return ret;
grub_free (ret);
as = s;
}
}
char *
grub_xasprintf (const char *fmt, ...)
{
va_list ap;
char *ret;
va_start (ap, fmt);
ret = grub_xvasprintf (fmt, ap);
va_end (ap);
return ret;

View file

@ -1,7 +1,7 @@
/* rescue_reader.c - rescue mode reader */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2009 Free Software Foundation, Inc.
* Copyright (C) 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
@ -83,7 +83,7 @@ grub_rescue_run (void)
grub_errno = GRUB_ERR_NONE;
grub_rescue_read_line (&line, 0);
if (! line)
if (! line || line[0] == '\0')
continue;
grub_parser_get_current ()->parse_line (line, grub_rescue_read_line);

View file

@ -90,10 +90,7 @@ grub_machine_set_prefix (void)
}
prefix = grub_ieee1275_encode_devname (bootpath);
path = grub_malloc (grub_strlen (grub_prefix)
+ grub_strlen (prefix)
+ 2);
grub_sprintf(path, "%s%s", prefix, grub_prefix);
path = grub_xasprintf("%s%s", prefix, grub_prefix);
grub_strcpy (grub_prefix, path);