Resync with trunk
This commit is contained in:
commit
e68d3b243f
706 changed files with 157184 additions and 45875 deletions
|
@ -1,7 +1,7 @@
|
|||
/* acpi.c - Display acpi tables. */
|
||||
/* acpi.c - get acpi tables. */
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2008 Free Software Foundation, Inc.
|
||||
* Copyright (C) 2009 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -16,175 +16,44 @@
|
|||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <grub/types.h>
|
||||
#include <grub/mm.h>
|
||||
|
||||
#include <grub/acpi.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/normal.h>
|
||||
#include <grub/efi/efi.h>
|
||||
#include <grub/efi/api.h>
|
||||
|
||||
static grub_uint32_t read16 (grub_uint8_t *p)
|
||||
struct grub_acpi_rsdp_v10 *
|
||||
grub_machine_acpi_get_rsdpv1 (void)
|
||||
{
|
||||
return grub_le_to_cpu16 (*(grub_uint16_t *)p);
|
||||
}
|
||||
unsigned i;
|
||||
static grub_efi_guid_t acpi_guid = GRUB_EFI_ACPI_TABLE_GUID;
|
||||
|
||||
static grub_uint32_t read32 (grub_uint8_t *p)
|
||||
{
|
||||
return grub_le_to_cpu32 (*(grub_uint32_t *)p);
|
||||
}
|
||||
|
||||
static grub_uint64_t read64 (grub_uint8_t *p)
|
||||
{
|
||||
return grub_le_to_cpu64 (*(grub_uint64_t *)p);
|
||||
}
|
||||
|
||||
static void
|
||||
disp_acpi_table (grub_uint8_t *t)
|
||||
{
|
||||
int i;
|
||||
grub_printf ("%c%c%c%c %4dB rev=%d OEM=", t[0], t[1], t[2], t[3],
|
||||
read32 (t + 4), t[8]);
|
||||
for (i = 0; i < 6; i++)
|
||||
grub_printf ("%c", t[10 + i]);
|
||||
grub_printf (" ");
|
||||
for (i = 0; i < 8; i++)
|
||||
grub_printf ("%c", t[16 + i]);
|
||||
grub_printf (" V=%08lx ", read32 (t + 24));
|
||||
for (i = 0; i < 4; i++)
|
||||
grub_printf ("%c", t[28 + i]);
|
||||
grub_printf (" %08lx\n", read32 (t + 32));
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
disp_acpi_apic_table (grub_uint8_t *t)
|
||||
{
|
||||
grub_uint8_t *d;
|
||||
grub_uint32_t len;
|
||||
grub_uint32_t flags;
|
||||
|
||||
disp_acpi_table (t);
|
||||
grub_printf ("Local APIC=%08lx Flags=%08lx\n",
|
||||
read32 (t + 36), read32 (t + 40));
|
||||
len = read32 (t + 4);
|
||||
len -= 44;
|
||||
d = t + 44;
|
||||
while (len > 0)
|
||||
for (i = 0; i < grub_efi_system_table->num_table_entries; i++)
|
||||
{
|
||||
grub_uint32_t l = d[1];
|
||||
grub_printf (" type=%x l=%d ", d[0], l);
|
||||
grub_efi_guid_t *guid =
|
||||
&grub_efi_system_table->configuration_table[i].vendor_guid;
|
||||
|
||||
switch (d[0])
|
||||
{
|
||||
case 2:
|
||||
grub_printf ("Int Override bus=%x src=%x GSI=%08x Flags=%04x",
|
||||
d[2], d[3], read32 (d + 4), read16 (d + 8));
|
||||
break;
|
||||
case 6:
|
||||
grub_printf ("IOSAPIC Id=%02x GSI=%08x Addr=%016llx",
|
||||
d[2], read32 (d + 4), read64 (d + 8));
|
||||
break;
|
||||
case 7:
|
||||
flags = read32 (d + 8);
|
||||
grub_printf ("LSAPIC ProcId=%02x ID=%02x EID=%02x Flags=%x",
|
||||
d[2], d[3], d[4], flags);
|
||||
if (flags & 1)
|
||||
grub_printf (" Enabled");
|
||||
else
|
||||
grub_printf (" Disabled");
|
||||
if (l >= 17)
|
||||
grub_printf ("\n"
|
||||
" UID val=%08x, Str=%s", read32 (d + 12), d + 16);
|
||||
break;
|
||||
case 8:
|
||||
grub_printf ("Platform INT flags=%04x type=%02x (",
|
||||
read16 (d + 2), d[4]);
|
||||
if (d[4] <= 3)
|
||||
{
|
||||
static const char * const platint_type[4] =
|
||||
{"Nul", "PMI", "INIT", "CPEI"};
|
||||
grub_printf ("%s", platint_type[d[4]]);
|
||||
}
|
||||
else
|
||||
grub_printf ("??");
|
||||
grub_printf (") ID=%02x EID=%02x\n", d[5], d[6]);
|
||||
grub_printf (" IOSAPIC Vec=%02x GSI=%08x source flags=%08x",
|
||||
d[7], read32 (d + 8), read32 (d + 12));
|
||||
break;
|
||||
default:
|
||||
grub_printf (" ??");
|
||||
}
|
||||
grub_printf ("\n");
|
||||
d += l;
|
||||
len -= l;
|
||||
if (! grub_memcmp (guid, &acpi_guid, sizeof (grub_efi_guid_t)))
|
||||
return (struct grub_acpi_rsdp_v10 *)
|
||||
grub_efi_system_table->configuration_table[i].vendor_table;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
disp_acpi_xsdt_table (grub_uint8_t *t)
|
||||
struct grub_acpi_rsdp_v20 *
|
||||
grub_machine_acpi_get_rsdpv2 (void)
|
||||
{
|
||||
grub_uint32_t len;
|
||||
grub_uint8_t *desc;
|
||||
unsigned i;
|
||||
static grub_efi_guid_t acpi20_guid = GRUB_EFI_ACPI_20_TABLE_GUID;
|
||||
|
||||
disp_acpi_table (t);
|
||||
len = read32 (t + 4) - 36;
|
||||
desc = t + 36;
|
||||
while (len > 0)
|
||||
for (i = 0; i < grub_efi_system_table->num_table_entries; i++)
|
||||
{
|
||||
t = read64 (desc);
|
||||
|
||||
if (t[0] == 'A' && t[1] == 'P' && t[2] == 'I' && t[3] == 'C')
|
||||
disp_acpi_apic_table (t);
|
||||
else
|
||||
disp_acpi_table (t);
|
||||
desc += 8;
|
||||
len -= 8;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
disp_acpi_rsdt_table (grub_uint8_t *t)
|
||||
{
|
||||
grub_uint32_t len;
|
||||
grub_uint8_t *desc;
|
||||
|
||||
disp_acpi_table (t);
|
||||
len = read32 (t + 4) - 36;
|
||||
desc = t + 36;
|
||||
while (len > 0)
|
||||
{
|
||||
t = read32 (desc);
|
||||
|
||||
if (t != NULL)
|
||||
disp_acpi_table (t);
|
||||
desc += 4;
|
||||
len -= 4;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
disp_acpi_rsdp_table (grub_uint8_t *rsdp)
|
||||
{
|
||||
grub_uint8_t *t = rsdp;
|
||||
int i;
|
||||
grub_uint8_t *xsdt;
|
||||
|
||||
grub_printf ("RSDP signature:");
|
||||
for (i = 0; i < 8; i++)
|
||||
grub_printf ("%c", t[i]);
|
||||
grub_printf (" chksum:%02x, OEM-ID: ", t[8]);
|
||||
for (i = 0; i < 6; i++)
|
||||
grub_printf ("%c", t[9 + i]);
|
||||
grub_printf (" rev=%d\n", t[15]);
|
||||
grub_printf ("RSDT=%08lx", read32 (t + 16));
|
||||
if (t[15] == 2)
|
||||
{
|
||||
xsdt = read64 (t + 24);
|
||||
grub_printf (" len=%d XSDT=%016llx\n", read32 (t + 20), xsdt);
|
||||
grub_printf ("\n");
|
||||
disp_acpi_xsdt_table (xsdt);
|
||||
}
|
||||
else
|
||||
{
|
||||
grub_printf ("\n");
|
||||
disp_acpi_rsdt_table (read32 (t + 16));
|
||||
grub_efi_guid_t *guid =
|
||||
&grub_efi_system_table->configuration_table[i].vendor_guid;
|
||||
|
||||
if (! grub_memcmp (guid, &acpi20_guid, sizeof (grub_efi_guid_t)))
|
||||
return (struct grub_acpi_rsdp_v20 *)
|
||||
grub_efi_system_table->configuration_table[i].vendor_table;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
190
commands/efi/acpi2.c
Normal file
190
commands/efi/acpi2.c
Normal file
|
@ -0,0 +1,190 @@
|
|||
/* acpi.c - Display acpi tables. */
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2008 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <grub/types.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/normal.h>
|
||||
|
||||
static grub_uint32_t read16 (grub_uint8_t *p)
|
||||
{
|
||||
return grub_le_to_cpu16 (*(grub_uint16_t *)p);
|
||||
}
|
||||
|
||||
static grub_uint32_t read32 (grub_uint8_t *p)
|
||||
{
|
||||
return grub_le_to_cpu32 (*(grub_uint32_t *)p);
|
||||
}
|
||||
|
||||
static grub_uint64_t read64 (grub_uint8_t *p)
|
||||
{
|
||||
return grub_le_to_cpu64 (*(grub_uint64_t *)p);
|
||||
}
|
||||
|
||||
static void
|
||||
disp_acpi_table (grub_uint8_t *t)
|
||||
{
|
||||
int i;
|
||||
grub_printf ("%c%c%c%c %4dB rev=%d OEM=", t[0], t[1], t[2], t[3],
|
||||
read32 (t + 4), t[8]);
|
||||
for (i = 0; i < 6; i++)
|
||||
grub_printf ("%c", t[10 + i]);
|
||||
grub_printf (" ");
|
||||
for (i = 0; i < 8; i++)
|
||||
grub_printf ("%c", t[16 + i]);
|
||||
grub_printf (" V=%08lx ", read32 (t + 24));
|
||||
for (i = 0; i < 4; i++)
|
||||
grub_printf ("%c", t[28 + i]);
|
||||
grub_printf (" %08lx\n", read32 (t + 32));
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
disp_acpi_apic_table (grub_uint8_t *t)
|
||||
{
|
||||
grub_uint8_t *d;
|
||||
grub_uint32_t len;
|
||||
grub_uint32_t flags;
|
||||
|
||||
disp_acpi_table (t);
|
||||
grub_printf ("Local APIC=%08lx Flags=%08lx\n",
|
||||
read32 (t + 36), read32 (t + 40));
|
||||
len = read32 (t + 4);
|
||||
len -= 44;
|
||||
d = t + 44;
|
||||
while (len > 0)
|
||||
{
|
||||
grub_uint32_t l = d[1];
|
||||
grub_printf (" type=%x l=%d ", d[0], l);
|
||||
|
||||
switch (d[0])
|
||||
{
|
||||
case 2:
|
||||
grub_printf ("Int Override bus=%x src=%x GSI=%08x Flags=%04x",
|
||||
d[2], d[3], read32 (d + 4), read16 (d + 8));
|
||||
break;
|
||||
case 6:
|
||||
grub_printf ("IOSAPIC Id=%02x GSI=%08x Addr=%016llx",
|
||||
d[2], read32 (d + 4), read64 (d + 8));
|
||||
break;
|
||||
case 7:
|
||||
flags = read32 (d + 8);
|
||||
grub_printf ("LSAPIC ProcId=%02x ID=%02x EID=%02x Flags=%x",
|
||||
d[2], d[3], d[4], flags);
|
||||
if (flags & 1)
|
||||
grub_printf (" Enabled");
|
||||
else
|
||||
grub_printf (" Disabled");
|
||||
if (l >= 17)
|
||||
grub_printf ("\n"
|
||||
" UID val=%08x, Str=%s", read32 (d + 12), d + 16);
|
||||
break;
|
||||
case 8:
|
||||
grub_printf ("Platform INT flags=%04x type=%02x (",
|
||||
read16 (d + 2), d[4]);
|
||||
if (d[4] <= 3)
|
||||
{
|
||||
static const char * const platint_type[4] =
|
||||
{"Nul", "PMI", "INIT", "CPEI"};
|
||||
grub_printf ("%s", platint_type[d[4]]);
|
||||
}
|
||||
else
|
||||
grub_printf ("??");
|
||||
grub_printf (") ID=%02x EID=%02x\n", d[5], d[6]);
|
||||
grub_printf (" IOSAPIC Vec=%02x GSI=%08x source flags=%08x",
|
||||
d[7], read32 (d + 8), read32 (d + 12));
|
||||
break;
|
||||
default:
|
||||
grub_printf (" ??");
|
||||
}
|
||||
grub_printf ("\n");
|
||||
d += l;
|
||||
len -= l;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
disp_acpi_xsdt_table (grub_uint8_t *t)
|
||||
{
|
||||
grub_uint32_t len;
|
||||
grub_uint8_t *desc;
|
||||
|
||||
disp_acpi_table (t);
|
||||
len = read32 (t + 4) - 36;
|
||||
desc = t + 36;
|
||||
while (len > 0)
|
||||
{
|
||||
t = read64 (desc);
|
||||
|
||||
if (t[0] == 'A' && t[1] == 'P' && t[2] == 'I' && t[3] == 'C')
|
||||
disp_acpi_apic_table (t);
|
||||
else
|
||||
disp_acpi_table (t);
|
||||
desc += 8;
|
||||
len -= 8;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
disp_acpi_rsdt_table (grub_uint8_t *t)
|
||||
{
|
||||
grub_uint32_t len;
|
||||
grub_uint8_t *desc;
|
||||
|
||||
disp_acpi_table (t);
|
||||
len = read32 (t + 4) - 36;
|
||||
desc = t + 36;
|
||||
while (len > 0)
|
||||
{
|
||||
t = read32 (desc);
|
||||
|
||||
if (t != NULL)
|
||||
disp_acpi_table (t);
|
||||
desc += 4;
|
||||
len -= 4;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
disp_acpi_rsdp_table (grub_uint8_t *rsdp)
|
||||
{
|
||||
grub_uint8_t *t = rsdp;
|
||||
int i;
|
||||
grub_uint8_t *xsdt;
|
||||
|
||||
grub_printf ("RSDP signature:");
|
||||
for (i = 0; i < 8; i++)
|
||||
grub_printf ("%c", t[i]);
|
||||
grub_printf (" chksum:%02x, OEM-ID: ", t[8]);
|
||||
for (i = 0; i < 6; i++)
|
||||
grub_printf ("%c", t[9 + i]);
|
||||
grub_printf (" rev=%d\n", t[15]);
|
||||
grub_printf ("RSDT=%08lx", read32 (t + 16));
|
||||
if (t[15] == 2)
|
||||
{
|
||||
xsdt = read64 (t + 24);
|
||||
grub_printf (" len=%d XSDT=%016llx\n", read32 (t + 20), xsdt);
|
||||
grub_printf ("\n");
|
||||
disp_acpi_xsdt_table (xsdt);
|
||||
}
|
||||
else
|
||||
{
|
||||
grub_printf ("\n");
|
||||
disp_acpi_rsdt_table (read32 (t + 16));
|
||||
}
|
||||
}
|
110
commands/efi/fixvideo.c
Normal file
110
commands/efi/fixvideo.c
Normal file
|
@ -0,0 +1,110 @@
|
|||
/* fixvideo.c - fix video problem in efi */
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2009 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <grub/dl.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/file.h>
|
||||
#include <grub/pci.h>
|
||||
#include <grub/command.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
static struct grub_video_patch
|
||||
{
|
||||
const char *name;
|
||||
grub_uint32_t pci_id;
|
||||
grub_uint32_t mmio_bar;
|
||||
grub_uint32_t mmio_reg;
|
||||
grub_uint32_t mmio_old;
|
||||
} video_patches[] =
|
||||
{
|
||||
{"Intel 945GM", 0x27a28086, 0, 0x71184, 0x1000000}, /* DSPBBASE */
|
||||
{"Intel 965GM", 0x2a028086, 0, 0x7119C, 0x1000000}, /* DSPBSURF */
|
||||
{0, 0, 0, 0, 0}
|
||||
};
|
||||
|
||||
static int NESTED_FUNC_ATTR
|
||||
scan_card (grub_pci_device_t dev, grub_pci_id_t pciid)
|
||||
{
|
||||
grub_pci_address_t addr;
|
||||
|
||||
addr = grub_pci_make_address (dev, 2);
|
||||
if (grub_pci_read_byte (addr + 3) == 0x3)
|
||||
{
|
||||
struct grub_video_patch *p = video_patches;
|
||||
|
||||
while (p->name)
|
||||
{
|
||||
if (p->pci_id == pciid)
|
||||
{
|
||||
grub_target_addr_t base;
|
||||
|
||||
grub_printf ("Found graphic card: %s\n", p->name);
|
||||
addr += 8 + p->mmio_bar * 4;
|
||||
base = grub_pci_read (addr);
|
||||
if ((! base) || (base & GRUB_PCI_ADDR_SPACE_IO) ||
|
||||
(base & GRUB_PCI_ADDR_MEM_PREFETCH))
|
||||
grub_printf ("Invalid MMIO bar %d\n", p->mmio_bar);
|
||||
else
|
||||
{
|
||||
base &= GRUB_PCI_ADDR_MEM_MASK;
|
||||
base += p->mmio_reg;
|
||||
|
||||
if (*((volatile grub_uint32_t *) base) != p->mmio_old)
|
||||
grub_printf ("Old value don't match\n");
|
||||
else
|
||||
{
|
||||
*((volatile grub_uint32_t *) base) = 0;
|
||||
if (*((volatile grub_uint32_t *) base))
|
||||
grub_printf ("Set MMIO fails\n");
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
p++;
|
||||
}
|
||||
|
||||
grub_printf ("Unknown graphic card: %x\n", pciid);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_cmd_fixvideo (grub_command_t cmd __attribute__ ((unused)),
|
||||
int argc __attribute__ ((unused)),
|
||||
char *argv[] __attribute__ ((unused)))
|
||||
{
|
||||
grub_pci_iterate (scan_card);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static grub_command_t cmd_fixvideo;
|
||||
|
||||
GRUB_MOD_INIT(fixvideo)
|
||||
{
|
||||
cmd_fixvideo = grub_register_command ("fix_video", grub_cmd_fixvideo,
|
||||
0, N_("Fix video problem."));
|
||||
|
||||
}
|
||||
|
||||
GRUB_MOD_FINI(fixvideo)
|
||||
{
|
||||
grub_unregister_command (cmd_fixvideo);
|
||||
}
|
216
commands/efi/loadbios.c
Normal file
216
commands/efi/loadbios.c
Normal file
|
@ -0,0 +1,216 @@
|
|||
/* loadbios.c - command to load a bios dump */
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2009 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <grub/dl.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/file.h>
|
||||
#include <grub/efi/efi.h>
|
||||
#include <grub/pci.h>
|
||||
#include <grub/command.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
static grub_efi_guid_t acpi_guid = GRUB_EFI_ACPI_TABLE_GUID;
|
||||
static grub_efi_guid_t acpi2_guid = GRUB_EFI_ACPI_20_TABLE_GUID;
|
||||
static grub_efi_guid_t smbios_guid = GRUB_EFI_SMBIOS_TABLE_GUID;
|
||||
|
||||
#define EBDA_SEG_ADDR 0x40e
|
||||
#define LOW_MEM_ADDR 0x413
|
||||
#define FAKE_EBDA_SEG 0x9fc0
|
||||
|
||||
#define BLANK_MEM 0xffffffff
|
||||
#define VBIOS_ADDR 0xc0000
|
||||
#define SBIOS_ADDR 0xf0000
|
||||
|
||||
static int
|
||||
enable_rom_area (void)
|
||||
{
|
||||
grub_pci_address_t addr;
|
||||
grub_uint32_t *rom_ptr;
|
||||
grub_pci_device_t dev = { .bus = 0, .device = 0, .function = 0};
|
||||
|
||||
rom_ptr = (grub_uint32_t *) VBIOS_ADDR;
|
||||
if (*rom_ptr != BLANK_MEM)
|
||||
{
|
||||
grub_printf ("ROM image is present.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
addr = grub_pci_make_address (dev, 36);
|
||||
grub_pci_write_byte (addr++, 0x30);
|
||||
grub_pci_write_byte (addr++, 0x33);
|
||||
grub_pci_write_byte (addr++, 0x33);
|
||||
grub_pci_write_byte (addr++, 0x33);
|
||||
grub_pci_write_byte (addr++, 0x33);
|
||||
grub_pci_write_byte (addr++, 0x33);
|
||||
grub_pci_write_byte (addr++, 0x33);
|
||||
grub_pci_write_byte (addr, 0);
|
||||
|
||||
*rom_ptr = 0;
|
||||
if (*rom_ptr != 0)
|
||||
{
|
||||
grub_printf ("Can\'t enable ROM area.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
lock_rom_area (void)
|
||||
{
|
||||
grub_pci_address_t addr;
|
||||
grub_pci_device_t dev = { .bus = 0, .device = 0, .function = 0};
|
||||
|
||||
addr = grub_pci_make_address (dev, 36);
|
||||
grub_pci_write_byte (addr++, 0x10);
|
||||
grub_pci_write_byte (addr++, 0x11);
|
||||
grub_pci_write_byte (addr++, 0x11);
|
||||
grub_pci_write_byte (addr++, 0x11);
|
||||
grub_pci_write_byte (addr, 0x11);
|
||||
}
|
||||
|
||||
static void
|
||||
fake_bios_data (int use_rom)
|
||||
{
|
||||
unsigned i;
|
||||
void *acpi, *smbios;
|
||||
grub_uint16_t *ebda_seg_ptr, *low_mem_ptr;
|
||||
|
||||
ebda_seg_ptr = (grub_uint16_t *) EBDA_SEG_ADDR;
|
||||
low_mem_ptr = (grub_uint16_t *) LOW_MEM_ADDR;
|
||||
if ((*ebda_seg_ptr) || (*low_mem_ptr))
|
||||
return;
|
||||
|
||||
acpi = 0;
|
||||
smbios = 0;
|
||||
for (i = 0; i < grub_efi_system_table->num_table_entries; i++)
|
||||
{
|
||||
grub_efi_guid_t *guid =
|
||||
&grub_efi_system_table->configuration_table[i].vendor_guid;
|
||||
|
||||
if (! grub_memcmp (guid, &acpi2_guid, sizeof (grub_efi_guid_t)))
|
||||
{
|
||||
acpi = grub_efi_system_table->configuration_table[i].vendor_table;
|
||||
grub_dprintf ("efi", "ACPI2: %p\n", acpi);
|
||||
}
|
||||
else if (! grub_memcmp (guid, &acpi_guid, sizeof (grub_efi_guid_t)))
|
||||
{
|
||||
void *t;
|
||||
|
||||
t = grub_efi_system_table->configuration_table[i].vendor_table;
|
||||
if (! acpi)
|
||||
acpi = t;
|
||||
grub_dprintf ("efi", "ACPI: %p\n", t);
|
||||
}
|
||||
else if (! grub_memcmp (guid, &smbios_guid, sizeof (grub_efi_guid_t)))
|
||||
{
|
||||
smbios = grub_efi_system_table->configuration_table[i].vendor_table;
|
||||
grub_dprintf ("efi", "SMBIOS: %p\n", smbios);
|
||||
}
|
||||
}
|
||||
|
||||
*ebda_seg_ptr = FAKE_EBDA_SEG;
|
||||
*low_mem_ptr = (FAKE_EBDA_SEG >> 6);
|
||||
|
||||
*((grub_uint16_t *) (FAKE_EBDA_SEG << 4)) = 640 - *low_mem_ptr;
|
||||
|
||||
if (acpi)
|
||||
grub_memcpy ((char *) ((FAKE_EBDA_SEG << 4) + 16), acpi, 1024 - 16);
|
||||
|
||||
if ((use_rom) && (smbios))
|
||||
grub_memcpy ((char *) SBIOS_ADDR, (char *) smbios + 16, 16);
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_cmd_fakebios (struct grub_command *cmd __attribute__ ((unused)),
|
||||
int argc __attribute__ ((unused)),
|
||||
char *argv[] __attribute__ ((unused)))
|
||||
{
|
||||
if (enable_rom_area ())
|
||||
{
|
||||
fake_bios_data (1);
|
||||
lock_rom_area ();
|
||||
}
|
||||
else
|
||||
fake_bios_data (0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_cmd_loadbios (grub_command_t cmd __attribute__ ((unused)),
|
||||
int argc, char *argv[])
|
||||
{
|
||||
grub_file_t file;
|
||||
int size;
|
||||
|
||||
if (argc == 0)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, "no ROM image specified");
|
||||
|
||||
if (argc > 1)
|
||||
{
|
||||
file = grub_file_open (argv[1]);
|
||||
if (! file)
|
||||
return grub_errno;
|
||||
|
||||
if (file->size != 4)
|
||||
grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid int10 dump size");
|
||||
else
|
||||
grub_file_read (file, (void *) 0x40, 4);
|
||||
|
||||
grub_file_close (file);
|
||||
if (grub_errno)
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
file = grub_file_open (argv[0]);
|
||||
if (! file)
|
||||
return grub_errno;
|
||||
|
||||
size = file->size;
|
||||
if ((size < 0x10000) || (size > 0x40000))
|
||||
grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid bios dump size");
|
||||
else if (enable_rom_area ())
|
||||
{
|
||||
grub_file_read (file, (void *) VBIOS_ADDR, size);
|
||||
fake_bios_data (size <= 0x40000);
|
||||
lock_rom_area ();
|
||||
}
|
||||
|
||||
grub_file_close (file);
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
static grub_command_t cmd_fakebios, cmd_loadbios;
|
||||
|
||||
GRUB_MOD_INIT(loadbios)
|
||||
{
|
||||
cmd_fakebios = grub_register_command ("fakebios", grub_cmd_fakebios,
|
||||
0, N_("Fake BIOS."));
|
||||
|
||||
cmd_loadbios = grub_register_command ("loadbios", grub_cmd_loadbios,
|
||||
"BIOS_DUMP [INT10_DUMP]",
|
||||
N_("Load BIOS dump."));
|
||||
}
|
||||
|
||||
GRUB_MOD_FINI(loadbios)
|
||||
{
|
||||
grub_unregister_command (cmd_fakebios);
|
||||
grub_unregister_command (cmd_loadbios);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue