1
/* loadbios.c - command to load a bios dump */
3
* GRUB -- GRand Unified Bootloader
4
* Copyright (C) 2009 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/>.
21
#include <grub/misc.h>
22
#include <grub/file.h>
23
#include <grub/efi/efi.h>
25
#include <grub/command.h>
26
#include <grub/i18n.h>
28
static grub_efi_guid_t acpi_guid = GRUB_EFI_ACPI_TABLE_GUID;
29
static grub_efi_guid_t acpi2_guid = GRUB_EFI_ACPI_20_TABLE_GUID;
30
static grub_efi_guid_t smbios_guid = GRUB_EFI_SMBIOS_TABLE_GUID;
32
#define EBDA_SEG_ADDR 0x40e
33
#define LOW_MEM_ADDR 0x413
34
#define FAKE_EBDA_SEG 0x9fc0
36
#define BLANK_MEM 0xffffffff
37
#define VBIOS_ADDR 0xc0000
38
#define SBIOS_ADDR 0xf0000
41
enable_rom_area (void)
43
grub_pci_address_t addr;
44
grub_uint32_t *rom_ptr;
45
grub_pci_device_t dev = { .bus = 0, .device = 0, .function = 0};
47
rom_ptr = (grub_uint32_t *) VBIOS_ADDR;
48
if (*rom_ptr != BLANK_MEM)
50
grub_printf ("ROM image is present.\n");
54
/* FIXME: should be macroified. */
55
addr = grub_pci_make_address (dev, 144);
56
grub_pci_write_byte (addr++, 0x30);
57
grub_pci_write_byte (addr++, 0x33);
58
grub_pci_write_byte (addr++, 0x33);
59
grub_pci_write_byte (addr++, 0x33);
60
grub_pci_write_byte (addr++, 0x33);
61
grub_pci_write_byte (addr++, 0x33);
62
grub_pci_write_byte (addr++, 0x33);
63
grub_pci_write_byte (addr, 0);
68
grub_printf ("Can\'t enable ROM area.\n");
78
grub_pci_address_t addr;
79
grub_pci_device_t dev = { .bus = 0, .device = 0, .function = 0};
81
/* FIXME: should be macroified. */
82
addr = grub_pci_make_address (dev, 144);
83
grub_pci_write_byte (addr++, 0x10);
84
grub_pci_write_byte (addr++, 0x11);
85
grub_pci_write_byte (addr++, 0x11);
86
grub_pci_write_byte (addr++, 0x11);
87
grub_pci_write_byte (addr, 0x11);
91
fake_bios_data (int use_rom)
95
grub_uint16_t *ebda_seg_ptr, *low_mem_ptr;
97
ebda_seg_ptr = (grub_uint16_t *) EBDA_SEG_ADDR;
98
low_mem_ptr = (grub_uint16_t *) LOW_MEM_ADDR;
99
if ((*ebda_seg_ptr) || (*low_mem_ptr))
104
for (i = 0; i < grub_efi_system_table->num_table_entries; i++)
106
grub_efi_guid_t *guid =
107
&grub_efi_system_table->configuration_table[i].vendor_guid;
109
if (! grub_memcmp (guid, &acpi2_guid, sizeof (grub_efi_guid_t)))
111
acpi = grub_efi_system_table->configuration_table[i].vendor_table;
112
grub_dprintf ("efi", "ACPI2: %p\n", acpi);
114
else if (! grub_memcmp (guid, &acpi_guid, sizeof (grub_efi_guid_t)))
118
t = grub_efi_system_table->configuration_table[i].vendor_table;
121
grub_dprintf ("efi", "ACPI: %p\n", t);
123
else if (! grub_memcmp (guid, &smbios_guid, sizeof (grub_efi_guid_t)))
125
smbios = grub_efi_system_table->configuration_table[i].vendor_table;
126
grub_dprintf ("efi", "SMBIOS: %p\n", smbios);
130
*ebda_seg_ptr = FAKE_EBDA_SEG;
131
*low_mem_ptr = (FAKE_EBDA_SEG >> 6);
133
*((grub_uint16_t *) (FAKE_EBDA_SEG << 4)) = 640 - *low_mem_ptr;
136
grub_memcpy ((char *) ((FAKE_EBDA_SEG << 4) + 16), acpi, 1024 - 16);
138
if ((use_rom) && (smbios))
139
grub_memcpy ((char *) SBIOS_ADDR, (char *) smbios + 16, 16);
143
grub_cmd_fakebios (struct grub_command *cmd __attribute__ ((unused)),
144
int argc __attribute__ ((unused)),
145
char *argv[] __attribute__ ((unused)))
147
if (enable_rom_area ())
159
grub_cmd_loadbios (grub_command_t cmd __attribute__ ((unused)),
160
int argc, char *argv[])
166
return grub_error (GRUB_ERR_BAD_ARGUMENT, "no ROM image specified");
170
file = grub_file_open (argv[1]);
175
grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid int10 dump size");
177
grub_file_read (file, (void *) 0x40, 4);
179
grub_file_close (file);
184
file = grub_file_open (argv[0]);
189
if ((size < 0x10000) || (size > 0x40000))
190
grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid bios dump size");
191
else if (enable_rom_area ())
193
grub_file_read (file, (void *) VBIOS_ADDR, size);
194
fake_bios_data (size <= 0x40000);
198
grub_file_close (file);
202
static grub_command_t cmd_fakebios, cmd_loadbios;
204
GRUB_MOD_INIT(loadbios)
206
cmd_fakebios = grub_register_command ("fakebios", grub_cmd_fakebios,
207
0, N_("Fake BIOS."));
209
cmd_loadbios = grub_register_command ("loadbios", grub_cmd_loadbios,
210
"BIOS_DUMP [INT10_DUMP]",
211
N_("Load BIOS dump."));
214
GRUB_MOD_FINI(loadbios)
216
grub_unregister_command (cmd_fakebios);
217
grub_unregister_command (cmd_loadbios);