2003-01-07 07:54:07 +00:00
|
|
|
/* main.c - the kernel main routine */
|
2002-12-27 08:53:07 +00:00
|
|
|
/*
|
2004-04-04 13:46:03 +00:00
|
|
|
* GRUB -- GRand Unified Bootloader
|
2005-01-04 14:01:45 +00:00
|
|
|
* Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
|
2002-12-27 08:53:07 +00:00
|
|
|
*
|
|
|
|
* This program 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 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
#include <grub/kernel.h>
|
|
|
|
#include <grub/misc.h>
|
|
|
|
#include <grub/mm.h>
|
|
|
|
#include <grub/symbol.h>
|
|
|
|
#include <grub/dl.h>
|
|
|
|
#include <grub/term.h>
|
|
|
|
#include <grub/rescue.h>
|
|
|
|
#include <grub/file.h>
|
|
|
|
#include <grub/device.h>
|
|
|
|
#include <grub/env.h>
|
2002-12-27 08:53:07 +00:00
|
|
|
|
|
|
|
/* Load all modules in core. */
|
|
|
|
static void
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_load_modules (void)
|
2002-12-27 08:53:07 +00:00
|
|
|
{
|
2005-01-04 14:01:45 +00:00
|
|
|
struct grub_module_info *modinfo;
|
2004-04-04 13:46:03 +00:00
|
|
|
struct grub_module_header *header;
|
2005-01-04 14:01:45 +00:00
|
|
|
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;
|
2002-12-27 08:53:07 +00:00
|
|
|
|
2005-01-04 14:01:45 +00:00
|
|
|
for (header = (struct grub_module_header *) (modbase + modinfo->offset);
|
|
|
|
header < (struct grub_module_header *) (modbase + modinfo->size);
|
2004-04-04 13:46:03 +00:00
|
|
|
header = (struct grub_module_header *) ((char *) header + header->size))
|
2002-12-27 08:53:07 +00:00
|
|
|
{
|
2004-04-04 13:46:03 +00:00
|
|
|
if (! grub_dl_load_core ((char *) header + header->offset,
|
2002-12-27 08:53:07 +00:00
|
|
|
(header->size - header->offset)))
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_fatal ("%s", grub_errmsg);
|
2002-12-27 08:53:07 +00:00
|
|
|
}
|
|
|
|
|
2005-01-04 14:01:45 +00:00
|
|
|
/* Add the region where modules reside into dynamic memory. */
|
|
|
|
grub_mm_init_region ((void *) modinfo, modinfo->size);
|
2002-12-27 08:53:07 +00:00
|
|
|
}
|
|
|
|
|
2003-01-07 07:54:07 +00:00
|
|
|
/* Set the root device according to the dl prefix. */
|
|
|
|
static void
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_set_root_dev (void)
|
2003-01-07 07:54:07 +00:00
|
|
|
{
|
|
|
|
const char *prefix;
|
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
prefix = grub_env_get ("prefix");
|
2003-01-07 07:54:07 +00:00
|
|
|
|
|
|
|
if (prefix)
|
|
|
|
{
|
|
|
|
char *dev;
|
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
dev = grub_file_get_device_name (prefix);
|
2003-01-07 07:54:07 +00:00
|
|
|
if (dev)
|
|
|
|
{
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_device_set_root (dev);
|
|
|
|
grub_free (dev);
|
2003-01-07 07:54:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Load the normal mode module and execute the normal mode if possible. */
|
|
|
|
static void
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_load_normal_mode (void)
|
2003-01-07 07:54:07 +00:00
|
|
|
{
|
2003-01-20 04:13:46 +00:00
|
|
|
/* Load the module. */
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_dl_load ("normal");
|
2003-01-07 07:54:07 +00:00
|
|
|
|
|
|
|
/* Ignore any error, because we have the rescue mode anyway. */
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_errno = GRUB_ERR_NONE;
|
2003-01-07 07:54:07 +00:00
|
|
|
}
|
|
|
|
|
2002-12-27 08:53:07 +00:00
|
|
|
/* The main routine. */
|
|
|
|
void
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_main (void)
|
2002-12-27 08:53:07 +00:00
|
|
|
{
|
|
|
|
/* First of all, initialize the machine. */
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_machine_init ();
|
2002-12-27 08:53:07 +00:00
|
|
|
|
|
|
|
/* Hello. */
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_setcolorstate (GRUB_TERM_COLOR_HIGHLIGHT);
|
|
|
|
grub_printf ("Welcome to GRUB!\n\n");
|
|
|
|
grub_setcolorstate (GRUB_TERM_COLOR_STANDARD);
|
2002-12-27 08:53:07 +00:00
|
|
|
|
2003-01-07 07:54:07 +00:00
|
|
|
/* It is better to set the root device as soon as possible,
|
|
|
|
for convenience. */
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_set_root_dev ();
|
2003-01-07 07:54:07 +00:00
|
|
|
|
|
|
|
/* Load pre-loaded modules and free the space. */
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_register_exported_symbols ();
|
|
|
|
grub_load_modules ();
|
2002-12-27 08:53:07 +00:00
|
|
|
|
2003-01-20 04:13:46 +00:00
|
|
|
/* Load the normal mode module. */
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_load_normal_mode ();
|
2003-01-07 07:54:07 +00:00
|
|
|
|
2003-01-20 04:13:46 +00:00
|
|
|
/* Enter the rescue mode. */
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_enter_rescue_mode ();
|
2002-12-27 08:53:07 +00:00
|
|
|
}
|