1
/* chainloader.c - boot another boot loader */
3
* GRUB -- GRand Unified Bootloader
4
* Copyright (C) 2002,2004,2007,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/loader.h>
21
#include <grub/file.h>
23
#include <grub/device.h>
24
#include <grub/disk.h>
25
#include <grub/misc.h>
26
#include <grub/types.h>
27
#include <grub/partition.h>
29
#include <grub/command.h>
30
#include <grub/machine/biosnum.h>
31
#include <grub/i18n.h>
32
#include <grub/video.h>
34
#include <grub/cpu/relocator.h>
36
static grub_dl_t my_mod;
37
static struct grub_relocator *rel;
38
static grub_uint32_t edx = 0xffffffff;
40
#define GRUB_NTLDR_SEGMENT 0x2000
43
grub_ntldr_boot (void)
45
struct grub_relocator16_state state = {
46
.cs = GRUB_NTLDR_SEGMENT,
56
grub_video_set_mode ("text", 0, 0);
58
return grub_relocator16_boot (rel, state);
62
grub_ntldr_unload (void)
64
grub_relocator_unload (rel);
66
grub_dl_unref (my_mod);
71
grub_cmd_ntldr (grub_command_t cmd __attribute__ ((unused)),
72
int argc, char *argv[])
77
grub_size_t ntldrsize;
81
return grub_error (GRUB_ERR_BAD_ARGUMENT, "no file specified");
85
rel = grub_relocator_new ();
89
file = grub_file_open (argv[0]);
94
grub_relocator_chunk_t ch;
95
err = grub_relocator_alloc_chunk_addr (rel, &ch, 0x7C00,
96
GRUB_DISK_SECTOR_SIZE);
99
bs = get_virtual_current_address (ch);
102
edx = grub_get_root_biosnumber ();
103
dev = grub_device_open (0);
105
if (dev && dev->disk)
107
err = grub_disk_read (dev->disk, 0, 0, GRUB_DISK_SECTOR_SIZE, bs);
110
grub_device_close (dev);
116
grub_device_close (dev);
118
ntldrsize = grub_file_size (file);
120
grub_relocator_chunk_t ch;
121
err = grub_relocator_alloc_chunk_addr (rel, &ch, GRUB_NTLDR_SEGMENT << 4,
125
ntldr = get_virtual_current_address (ch);
128
if (grub_file_read (file, ntldr, ntldrsize)
129
!= (grub_ssize_t) ntldrsize)
132
grub_loader_set (grub_ntldr_boot, grub_ntldr_unload, 1);
133
return GRUB_ERR_NONE;
138
grub_file_close (file);
140
grub_ntldr_unload ();
145
static grub_command_t cmd;
149
cmd = grub_register_command ("ntldr", grub_cmd_ntldr,
150
0, N_("Load NTLDR or BootMGR."));
156
grub_unregister_command (cmd);