1
/* multiboot_loader.c - boot multiboot kernel image */
3
* GRUB -- GRand Unified Bootloader
4
* Copyright (C) 2007,2008,2009,2010 Free Software Foundation, Inc.
6
* GRUB is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
11
* GRUB is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
20
#include <grub/multiboot.h>
22
#include <grub/file.h>
26
#include <grub/misc.h>
27
#include <grub/gzio.h>
28
#include <grub/command.h>
29
#include <grub/i18n.h>
34
find_multi_boot1_header (grub_file_t file)
36
struct multiboot_header *header;
37
char buffer[MULTIBOOT_SEARCH];
41
len = grub_file_read (file, buffer, MULTIBOOT_SEARCH);
45
/* Look for the multiboot header in the buffer. The header should
46
be at least 12 bytes and aligned on a 4-byte boundary. */
47
for (header = (struct multiboot_header *) buffer;
48
((char *) header <= buffer + len - 12) || (header = 0);
49
header = (struct multiboot_header *) ((char *) header + 4))
51
if (header->magic == MULTIBOOT_HEADER_MAGIC
52
&& !(header->magic + header->flags + header->checksum))
63
grub_cmd_multiboot_loader (grub_command_t cmd __attribute__ ((unused)),
64
int argc, char *argv[])
67
int header_multi_ver_found = 0;
73
grub_error (GRUB_ERR_BAD_ARGUMENT, "no kernel specified");
77
file = grub_gzfile_open (argv[0], 1);
80
grub_error (GRUB_ERR_BAD_ARGUMENT, "couldn't open file");
84
/* find which header is in the file */
85
if (find_multi_boot1_header (file))
86
header_multi_ver_found = 1;
89
grub_error (GRUB_ERR_BAD_OS, "multiboot header not found");
93
/* close file before calling functions */
95
grub_file_close (file);
97
/* Launch multi boot with header */
99
grub_dprintf ("multiboot_loader",
100
"Launching multiboot 1 grub_multiboot() function\n");
101
grub_multiboot (argc, argv);
107
grub_file_close (file);
109
grub_dl_unref (my_mod);
115
grub_cmd_module_loader (grub_command_t cmd __attribute__ ((unused)),
116
int argc, char *argv[])
119
grub_dprintf("multiboot_loader",
120
"Launching multiboot 1 grub_module() function\n");
121
grub_module (argc, argv);
126
static grub_command_t cmd_multiboot, cmd_module;
128
GRUB_MOD_INIT(multiboot)
131
#ifdef GRUB_USE_MULTIBOOT2
132
grub_register_command ("multiboot2", grub_cmd_multiboot_loader,
133
0, N_("Load a multiboot 2 kernel."));
135
grub_register_command ("multiboot", grub_cmd_multiboot_loader,
136
0, N_("Load a multiboot kernel."));
140
grub_register_command ("module", grub_cmd_module_loader,
141
0, N_("Load a multiboot module."));
146
GRUB_MOD_FINI(multiboot)
148
grub_unregister_command (cmd_multiboot);
149
grub_unregister_command (cmd_module);