2
* GRUB -- GRand Unified Bootloader
3
* Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc.
5
* GRUB is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with GRUB; if not, write to the Free Software
17
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26
#include <sys/types.h>
30
#include <grub/setjmp.h>
32
#include <grub/i386/pc/util/biosdisk.h>
34
#include <grub/machine/console.h>
35
#include <grub/util/misc.h>
36
#include <grub/kernel.h>
37
#include <grub/normal.h>
38
#include <grub/util/getroot.h>
40
#include <grub/partition.h>
42
#include <grub_modules_init.h>
45
/* NetBSD uses /boot for its boot block. */
46
# define DEFAULT_DIRECTORY "/grub"
48
# define DEFAULT_DIRECTORY "/boot/grub"
51
#define DEFAULT_DEVICE_MAP DEFAULT_DIRECTORY "/device.map"
53
/* Used for going back to the main function. */
57
grub_arch_modules_addr (void)
63
grub_arch_dl_check_header (void *ehdr)
67
return GRUB_ERR_BAD_MODULE;
71
grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
76
return GRUB_ERR_BAD_MODULE;
80
grub_machine_init (void)
82
signal (SIGINT, SIG_IGN);
87
grub_machine_fini (void)
93
const char *argp_program_version = PACKAGE_STRING;
94
const char *argp_program_bug_address = PACKAGE_BUGREPORT;
95
static char doc[] = "GRUB emulator";
97
static struct argp_option options[] = {
98
{"root-device", 'r', "DEV", 0, "use DEV as the root device [default=guessed]", 0},
99
{"device-map", 'm', "FILE", 0, "use FILE as the device map", 0},
100
{"directory", 'd', "DIR", 0, "use GRUB files in the directory DIR", 0},
101
{"verbose", 'v', 0 , 0, "print verbose messages", 0},
102
{"hold", 'H', "SECONDS", OPTION_ARG_OPTIONAL, "wait until a debugger will attach", 0},
115
parse_opt (int key, char *arg, struct argp_state *state)
117
struct arguments *args = state->input;
122
args->root_dev = arg;
134
args->hold = arg ? atoi (arg) : -1;
139
return ARGP_ERR_UNKNOWN;
144
static struct argp argp = {options, parse_opt, 0, doc, 0, 0, 0};
148
main (int argc, char *argv[])
151
char rootprefix[100];
152
struct arguments args =
154
.dir = DEFAULT_DIRECTORY,
155
.dev_map = DEFAULT_DEVICE_MAP,
159
progname = "grub-emu";
161
argp_parse (&argp, argc, argv, 0, 0, &args);
163
/* Wait until the ARGS.HOLD variable is cleared by an attached debugger. */
164
if (args.hold && verbosity > 0)
165
printf ("Run \"gdb %s %d\", and set ARGS.HOLD to zero.\n",
166
progname, (int) getpid ());
175
/* Make sure that there is a root device. */
178
args.root_dev = grub_guess_root_device (args.dir ? : DEFAULT_DIRECTORY);
181
grub_util_info ("guessing the root device failed, because of `%s'",
183
grub_util_error ("Cannot guess the root device. Specify the option ``--root-device''.");
187
prefix = grub_get_prefix (args.dir ? : DEFAULT_DIRECTORY);
188
sprintf (rootprefix, "%s%s", args.root_dev, prefix);
190
grub_env_set ("prefix", rootprefix);
192
/* XXX: This is a bit unportable. */
193
grub_util_biosdisk_init (args.dev_map);
198
if (setjmp (main_env) == 0)
203
grub_machine_fini ();