2
* GRUB -- GRand Unified Bootloader
3
* Copyright (C) 2003,2004,2005,2006,2007,2008,2009,2010 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 3 of the License, or
8
* (at your option) any later version.
10
* GRUB 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, see <http://www.gnu.org/licenses/>.
27
#include <sys/types.h>
32
#include <grub/setjmp.h>
34
#include <grub/emu/hostdisk.h>
35
#include <grub/time.h>
36
#include <grub/emu/console.h>
37
#include <grub/emu/misc.h>
38
#include <grub/kernel.h>
39
#include <grub/normal.h>
40
#include <grub/emu/getroot.h>
42
#include <grub/partition.h>
43
#include <grub/i18n.h>
45
#define ENABLE_RELOCATABLE 0
48
/* Used for going back to the main function. */
49
static jmp_buf main_env;
51
/* Store the prefix specified by an argument. */
52
static char *prefix = NULL;
55
grub_arch_modules_addr (void)
62
grub_arch_dl_check_header (void *ehdr)
66
return GRUB_ERR_BAD_MODULE;
70
grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
75
return GRUB_ERR_BAD_MODULE;
82
longjmp (main_env, 1);
87
#ifdef GRUB_MACHINE_PCBIOS
88
int no_apm __attribute__ ((unused))
96
grub_machine_init (void)
101
grub_machine_set_prefix (void)
103
grub_env_set ("prefix", prefix);
109
grub_machine_fini (void)
111
grub_console_fini ();
116
static struct option options[] =
118
{"root-device", required_argument, 0, 'r'},
119
{"device-map", required_argument, 0, 'm'},
120
{"directory", required_argument, 0, 'd'},
121
{"hold", optional_argument, 0, 'H'},
122
{"help", no_argument, 0, 'h'},
123
{"version", no_argument, 0, 'V'},
124
{"verbose", no_argument, 0, 'v'},
133
"Try `%s --help' for more information.\n", program_name);
136
"Usage: %s [OPTION]...\n"
140
" -r, --root-device=DEV use DEV as the root device [default=guessed]\n"
141
" -m, --device-map=FILE use FILE as the device map [default=%s]\n"
142
" -d, --directory=DIR use GRUB files in the directory DIR [default=%s]\n"
143
" -v, --verbose print verbose messages\n"
144
" -H, --hold[=SECONDS] wait until a debugger will attach\n"
145
" -h, --help display this message and exit\n"
146
" -V, --version print version information and exit\n"
148
"Report bugs to <%s>.\n", program_name, DEFAULT_DEVICE_MAP, DEFAULT_DIRECTORY, PACKAGE_BUGREPORT);
153
void grub_hostfs_init (void);
154
void grub_hostfs_fini (void);
155
void grub_host_init (void);
156
void grub_host_fini (void);
158
void grub_init_all (void);
159
void grub_fini_all (void);
163
main (int argc, char *argv[])
166
char *dir = DEFAULT_DIRECTORY;
167
char *dev_map = DEFAULT_DEVICE_MAP;
168
volatile int hold = 0;
171
set_program_name (argv[0]);
173
while ((opt = getopt_long (argc, argv, "r:d:m:vH:hV", options, 0)) != -1)
189
hold = (optarg ? atoi (optarg) : -1);
194
printf ("%s (%s) %s\n", program_name, PACKAGE_NAME, PACKAGE_VERSION);
202
fprintf (stderr, "Unknown extra argument `%s'.\n", argv[optind]);
206
/* Wait until the ARGS.HOLD variable is cleared by an attached debugger. */
207
if (hold && verbosity > 0)
208
printf ("Run \"gdb %s %d\", and set ARGS.HOLD to zero.\n",
209
program_name, (int) getpid ());
218
signal (SIGINT, SIG_IGN);
219
grub_console_init ();
223
/* XXX: This is a bit unportable. */
224
grub_util_biosdisk_init (dev_map);
230
/* Make sure that there is a root device. */
233
char *device_name = grub_guess_root_device (dir);
235
grub_util_error ("cannot find a device for %s", dir);
237
root_dev = grub_util_get_grub_dev (device_name);
240
grub_util_info ("guessing the root device failed, because of `%s'",
242
grub_util_error ("cannot guess the root device. Specify the option `--root-device'");
246
if (strcmp (root_dev, "host") == 0)
249
dir = grub_make_system_path_relative_to_its_root (dir);
250
prefix = xmalloc (strlen (root_dev) + 2 + strlen (dir) + 1);
251
sprintf (prefix, "(%s)%s", root_dev, dir);
255
if (setjmp (main_env) == 0)
264
grub_machine_fini ();
272
grub_millisleep (grub_uint32_t ms)
280
grub_millisleep (grub_uint32_t ms)
284
ts.tv_sec = ms / 1000;
285
ts.tv_nsec = (ms % 1000) * 1000000;
286
nanosleep (&ts, NULL);
293
grub_register_exported_symbols (void)