- Fix GCC 12 build failure * 0001-Fix-Werror-array-bounds-array-subscript-0-is-outside.patch * 0002-reed_solomon-Fix-array-subscript-0-is-outside-array-.patch - Revised * grub2-btrfs-01-add-ability-to-boot-from-subvolumes.patch OBS-URL: https://build.opensuse.org/request/show/978629 OBS-URL: https://build.opensuse.org/package/show/Base:System/trustedgrub2?expand=0&rev=25
495 lines
19 KiB
Diff
495 lines
19 KiB
Diff
From 04de53cb4adc0ae6429b0715c3f1dd8a62ff9a0f Mon Sep 17 00:00:00 2001
|
|
From: Michael Chang <mchang@suse.com>
|
|
Date: Wed, 16 Mar 2022 17:05:01 +0800
|
|
Subject: [PATCH 1/2] Fix -Werror=array-bounds array subscript 0 is outside
|
|
array bounds
|
|
|
|
The grub is failing to build with gcc-12 in many places like this:
|
|
|
|
In function 'init_cbfsdisk',
|
|
inlined from 'grub_mod_init' at ../../grub-core/fs/cbfs.c:391:3:
|
|
../../grub-core/fs/cbfs.c:345:7: error: array subscript 0 is outside array bounds of 'grub_uint32_t[0]' {aka 'unsigned int[]'} [-Werror=array-bounds]
|
|
345 | ptr = *(grub_uint32_t *) 0xfffffffc;
|
|
| ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
This is caused by gcc regression in 11/12 [1]. In a nut shell, the
|
|
warning is about detected invalid accesses at non-zero offsets to null
|
|
pointers. Since hardwired constant address is treated as NULL plus an
|
|
offset in the same underlying code, the warning is therefore triggered.
|
|
|
|
Instead of inserting #pragma all over the places where literal pointers
|
|
are accessed to avoid diagnosing array-bounds, we can try to borrow the
|
|
idea from linux kernel that the absolute_pointer macro [2][3] is used to
|
|
disconnect a pointer using literal address from it's original object,
|
|
hence gcc won't be able to make assumptions on the boundary while doing
|
|
pointer arithmetic. With that we can greatly reduce the code we have to
|
|
cover up by making initial literal pointer assignment to use the new
|
|
wrapper but not having to track everywhere literal pointers are
|
|
accessed. This also makes code looks cleaner.
|
|
|
|
[1]
|
|
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99578
|
|
[2]
|
|
https://elixir.bootlin.com/linux/v5.16.14/source/include/linux/compiler.h#L180
|
|
[3]
|
|
https://elixir.bootlin.com/linux/v5.16.14/source/include/linux/compiler-gcc.h#L31
|
|
|
|
Signed-off-by: Michael Chang <mchang@suse.com>
|
|
---
|
|
grub-core/bus/cs5536.c | 4 ++--
|
|
grub-core/commands/acpi.c | 4 ++--
|
|
grub-core/commands/efi/loadbios.c | 9 +++++----
|
|
grub-core/commands/i386/pc/drivemap.c | 9 ++++++---
|
|
grub-core/commands/i386/pc/sendkey.c | 12 ++++++------
|
|
grub-core/disk/i386/pc/biosdisk.c | 4 ++--
|
|
grub-core/fs/cbfs.c | 2 +-
|
|
grub-core/kern/i386/pc/acpi.c | 4 ++--
|
|
grub-core/kern/i386/pc/mmap.c | 2 +-
|
|
grub-core/loader/i386/multiboot_mbi.c | 2 +-
|
|
grub-core/loader/multiboot_mbi2.c | 4 ++--
|
|
grub-core/mmap/i386/pc/mmap.c | 26 +++++++++++++-------------
|
|
grub-core/net/drivers/i386/pc/pxe.c | 12 ++++++------
|
|
grub-core/term/i386/pc/console.c | 5 ++---
|
|
grub-core/term/i386/pc/vga_text.c | 6 +++---
|
|
grub-core/term/ns8250.c | 7 ++++++-
|
|
grub-core/video/i386/pc/vbe.c | 6 +++---
|
|
include/grub/compiler.h | 11 +++++++++++
|
|
18 files changed, 74 insertions(+), 55 deletions(-)
|
|
|
|
--- a/grub-core/bus/cs5536.c
|
|
+++ b/grub-core/bus/cs5536.c
|
|
@@ -331,8 +331,8 @@
|
|
|
|
{
|
|
volatile grub_uint32_t *oc;
|
|
- oc = grub_pci_device_map_range (dev, 0x05022000,
|
|
- GRUB_CS5536_USB_OPTION_REGS_SIZE);
|
|
+ oc = grub_absolute_pointer (grub_pci_device_map_range (dev, 0x05022000,
|
|
+ GRUB_CS5536_USB_OPTION_REGS_SIZE));
|
|
|
|
oc[GRUB_CS5536_USB_OPTION_REG_UOCMUX] =
|
|
(oc[GRUB_CS5536_USB_OPTION_REG_UOCMUX]
|
|
--- a/grub-core/commands/acpi.c
|
|
+++ b/grub-core/commands/acpi.c
|
|
@@ -167,7 +167,7 @@
|
|
struct grub_acpi_rsdp_v10 *v1;
|
|
struct grub_acpi_rsdp_v20 *v2;
|
|
|
|
- ebda = (grub_uint8_t *) (grub_addr_t) ((*((grub_uint16_t *)0x40e)) << 4);
|
|
+ ebda = (grub_uint8_t *) (grub_addr_t) ((*((grub_uint16_t *)grub_absolute_pointer(0x40e))) << 4);
|
|
grub_dprintf ("acpi", "EBDA @%p\n", ebda);
|
|
if (ebda)
|
|
ebda_kb_len = *(grub_uint16_t *) ebda;
|
|
@@ -297,7 +297,7 @@
|
|
*target = 0;
|
|
|
|
grub_dprintf ("acpi", "Switching EBDA\n");
|
|
- (*((grub_uint16_t *) 0x40e)) = ((grub_addr_t) targetebda) >> 4;
|
|
+ (*((grub_uint16_t *) grub_absolute_pointer(0x40e))) = ((grub_addr_t) targetebda) >> 4;
|
|
grub_dprintf ("acpi", "EBDA switched\n");
|
|
|
|
return GRUB_ERR_NONE;
|
|
--- a/grub-core/commands/efi/loadbios.c
|
|
+++ b/grub-core/commands/efi/loadbios.c
|
|
@@ -46,7 +46,7 @@
|
|
grub_uint32_t *rom_ptr;
|
|
grub_pci_device_t dev = { .bus = 0, .device = 0, .function = 0};
|
|
|
|
- rom_ptr = (grub_uint32_t *) VBIOS_ADDR;
|
|
+ rom_ptr = grub_absolute_pointer (VBIOS_ADDR);
|
|
if (*rom_ptr != BLANK_MEM)
|
|
{
|
|
grub_puts_ (N_("ROM image is present."));
|
|
@@ -96,8 +96,8 @@
|
|
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;
|
|
+ ebda_seg_ptr = grub_absolute_pointer (EBDA_SEG_ADDR);
|
|
+ low_mem_ptr = grub_absolute_pointer (LOW_MEM_ADDR);
|
|
if ((*ebda_seg_ptr) || (*low_mem_ptr))
|
|
return;
|
|
|
|
@@ -132,7 +132,8 @@
|
|
*ebda_seg_ptr = FAKE_EBDA_SEG;
|
|
*low_mem_ptr = (FAKE_EBDA_SEG >> 6);
|
|
|
|
- *((grub_uint16_t *) (FAKE_EBDA_SEG << 4)) = 640 - *low_mem_ptr;
|
|
+ /* *((grub_uint16_t *) (FAKE_EBDA_SEG << 4)) = 640 - *low_mem_ptr; */
|
|
+ *((grub_uint16_t *) (grub_absolute_pointer (FAKE_EBDA_SEG << 4))) = 640 - *low_mem_ptr;
|
|
|
|
if (acpi)
|
|
grub_memcpy ((char *) ((FAKE_EBDA_SEG << 4) + 16), acpi, 1024 - 16);
|
|
--- a/grub-core/commands/i386/pc/drivemap.c
|
|
+++ b/grub-core/commands/i386/pc/drivemap.c
|
|
@@ -31,9 +31,6 @@
|
|
|
|
GRUB_MOD_LICENSE ("GPLv3+");
|
|
|
|
-/* Real mode IVT slot (seg:off far pointer) for interrupt 0x13. */
|
|
-static grub_uint32_t *const int13slot = (grub_uint32_t *) (4 * 0x13);
|
|
-
|
|
/* Remember to update enum opt_idxs accordingly. */
|
|
static const struct grub_arg_option options[] = {
|
|
/* TRANSLATORS: In this file "mapping" refers to a change GRUB makes so if
|
|
@@ -280,6 +277,9 @@
|
|
grub_uint8_t *handler_base = 0;
|
|
/* Address of the map within the deployed bundle. */
|
|
int13map_node_t *handler_map;
|
|
+ /* Real mode IVT slot (seg:off far pointer) for interrupt 0x13. */
|
|
+ grub_uint32_t *int13slot = (grub_uint32_t *) grub_absolute_pointer (4 * 0x13);
|
|
+
|
|
|
|
int i;
|
|
int entries = 0;
|
|
@@ -354,6 +354,9 @@
|
|
static grub_err_t
|
|
uninstall_int13_handler (void)
|
|
{
|
|
+ /* Real mode IVT slot (seg:off far pointer) for interrupt 0x13. */
|
|
+ grub_uint32_t *int13slot = (grub_uint32_t *) grub_absolute_pointer (4 * 0x13);
|
|
+
|
|
if (! grub_drivemap_oldhandler)
|
|
return GRUB_ERR_NONE;
|
|
|
|
--- a/grub-core/commands/i386/pc/sendkey.c
|
|
+++ b/grub-core/commands/i386/pc/sendkey.c
|
|
@@ -216,12 +216,12 @@
|
|
grub_sendkey_postboot (void)
|
|
{
|
|
/* For convention: pointer to flags. */
|
|
- grub_uint32_t *flags = (grub_uint32_t *) 0x417;
|
|
+ grub_uint32_t *flags = grub_absolute_pointer (0x417);
|
|
|
|
*flags = oldflags;
|
|
|
|
- *((char *) 0x41a) = 0x1e;
|
|
- *((char *) 0x41c) = 0x1e;
|
|
+ *((char *) grub_absolute_pointer (0x41a)) = 0x1e;
|
|
+ *((char *) grub_absolute_pointer (0x41c)) = 0x1e;
|
|
|
|
return GRUB_ERR_NONE;
|
|
}
|
|
@@ -231,13 +231,13 @@
|
|
grub_sendkey_preboot (int noret __attribute__ ((unused)))
|
|
{
|
|
/* For convention: pointer to flags. */
|
|
- grub_uint32_t *flags = (grub_uint32_t *) 0x417;
|
|
+ grub_uint32_t *flags = grub_absolute_pointer (0x417);
|
|
|
|
oldflags = *flags;
|
|
|
|
/* Set the sendkey. */
|
|
- *((char *) 0x41a) = 0x1e;
|
|
- *((char *) 0x41c) = keylen + 0x1e;
|
|
+ *((char *) grub_absolute_pointer (0x41a)) = 0x1e;
|
|
+ *((char *) grub_absolute_pointer (0x41c)) = keylen + 0x1e;
|
|
grub_memcpy ((char *) 0x41e, sendkey, 0x20);
|
|
|
|
/* Transform "any ctrl" to "right ctrl" flag. */
|
|
--- a/grub-core/disk/i386/pc/biosdisk.c
|
|
+++ b/grub-core/disk/i386/pc/biosdisk.c
|
|
@@ -367,7 +367,7 @@
|
|
if (version)
|
|
{
|
|
struct grub_biosdisk_drp *drp
|
|
- = (struct grub_biosdisk_drp *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR;
|
|
+ = (struct grub_biosdisk_drp *) grub_absolute_pointer (GRUB_MEMORY_MACHINE_SCRATCH_ADDR);
|
|
|
|
/* Clear out the DRP. */
|
|
grub_memset (drp, 0, sizeof (*drp));
|
|
@@ -654,7 +654,7 @@
|
|
GRUB_MOD_INIT(biosdisk)
|
|
{
|
|
struct grub_biosdisk_cdrp *cdrp
|
|
- = (struct grub_biosdisk_cdrp *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR;
|
|
+ = (struct grub_biosdisk_cdrp *) grub_absolute_pointer (GRUB_MEMORY_MACHINE_SCRATCH_ADDR);
|
|
grub_uint8_t boot_drive;
|
|
|
|
if (grub_disk_firmware_is_tainted)
|
|
--- a/grub-core/fs/cbfs.c
|
|
+++ b/grub-core/fs/cbfs.c
|
|
@@ -342,7 +342,7 @@
|
|
grub_uint32_t ptr;
|
|
struct cbfs_header *head;
|
|
|
|
- ptr = *(grub_uint32_t *) 0xfffffffc;
|
|
+ ptr = *((grub_uint32_t *) grub_absolute_pointer (0xfffffffc));
|
|
head = (struct cbfs_header *) (grub_addr_t) ptr;
|
|
grub_dprintf ("cbfs", "head=%p\n", head);
|
|
|
|
--- a/grub-core/kern/i386/pc/acpi.c
|
|
+++ b/grub-core/kern/i386/pc/acpi.c
|
|
@@ -27,7 +27,7 @@
|
|
grub_uint8_t *ebda, *ptr;
|
|
|
|
grub_dprintf ("acpi", "Looking for RSDP. Scanning EBDA\n");
|
|
- ebda = (grub_uint8_t *) ((* ((grub_uint16_t *) 0x40e)) << 4);
|
|
+ ebda = (grub_uint8_t *) ((* ((grub_uint16_t *) grub_absolute_pointer (0x40e))) << 4);
|
|
ebda_len = * (grub_uint16_t *) ebda;
|
|
if (! ebda_len) /* FIXME do we really need this check? */
|
|
goto scan_bios;
|
|
@@ -55,7 +55,7 @@
|
|
grub_uint8_t *ebda, *ptr;
|
|
|
|
grub_dprintf ("acpi", "Looking for RSDP. Scanning EBDA\n");
|
|
- ebda = (grub_uint8_t *) ((* ((grub_uint16_t *) 0x40e)) << 4);
|
|
+ ebda = (grub_uint8_t *) ((* ((grub_uint16_t *) grub_absolute_pointer (0x40e))) << 4);
|
|
ebda_len = * (grub_uint16_t *) ebda;
|
|
if (! ebda_len) /* FIXME do we really need this check? */
|
|
goto scan_bios;
|
|
--- a/grub-core/kern/i386/pc/mmap.c
|
|
+++ b/grub-core/kern/i386/pc/mmap.c
|
|
@@ -143,7 +143,7 @@
|
|
{
|
|
grub_uint32_t cont = 0;
|
|
struct grub_machine_mmap_entry *entry
|
|
- = (struct grub_machine_mmap_entry *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR;
|
|
+ = (struct grub_machine_mmap_entry *) grub_absolute_pointer (GRUB_MEMORY_MACHINE_SCRATCH_ADDR);
|
|
int e820_works = 0;
|
|
|
|
while (1)
|
|
--- a/grub-core/loader/i386/multiboot_mbi.c
|
|
+++ b/grub-core/loader/i386/multiboot_mbi.c
|
|
@@ -284,7 +284,7 @@
|
|
struct grub_vbe_mode_info_block *mode_info;
|
|
#if GRUB_MACHINE_HAS_VBE
|
|
grub_vbe_status_t status;
|
|
- void *scratch = (void *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR;
|
|
+ void *scratch = grub_absolute_pointer (GRUB_MEMORY_MACHINE_SCRATCH_ADDR);
|
|
|
|
status = grub_vbe_bios_get_controller_info (scratch);
|
|
if (status != GRUB_VBE_STATUS_OK)
|
|
--- a/grub-core/loader/multiboot_mbi2.c
|
|
+++ b/grub-core/loader/multiboot_mbi2.c
|
|
@@ -445,7 +445,7 @@
|
|
fill_vbe_tag (struct multiboot_tag_vbe *tag)
|
|
{
|
|
grub_vbe_status_t status;
|
|
- void *scratch = (void *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR;
|
|
+ void *scratch = grub_absolute_pointer (GRUB_MEMORY_MACHINE_SCRATCH_ADDR);
|
|
|
|
tag->type = MULTIBOOT_TAG_TYPE_VBE;
|
|
tag->size = 0;
|
|
@@ -518,7 +518,7 @@
|
|
#if defined (GRUB_MACHINE_PCBIOS)
|
|
{
|
|
grub_vbe_status_t status;
|
|
- void *scratch = (void *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR;
|
|
+ void *scratch = grub_absolute_pointer (GRUB_MEMORY_MACHINE_SCRATCH_ADDR);
|
|
status = grub_vbe_bios_get_mode (scratch);
|
|
vbe_mode = *(grub_uint32_t *) scratch;
|
|
if (status != GRUB_VBE_STATUS_OK)
|
|
--- a/grub-core/mmap/i386/pc/mmap.c
|
|
+++ b/grub-core/mmap/i386/pc/mmap.c
|
|
@@ -88,13 +88,13 @@
|
|
= min (grub_mmap_get_post64 (), 0xfc000000ULL) >> 16;
|
|
|
|
/* Correct BDA. */
|
|
- *((grub_uint16_t *) 0x413) = grub_mmap_get_lower () >> 10;
|
|
+ *((grub_uint16_t *) grub_absolute_pointer (0x413)) = grub_mmap_get_lower () >> 10;
|
|
|
|
/* Save old interrupt handlers. */
|
|
- grub_machine_mmaphook_int12offset = *((grub_uint16_t *) 0x48);
|
|
- grub_machine_mmaphook_int12segment = *((grub_uint16_t *) 0x4a);
|
|
- grub_machine_mmaphook_int15offset = *((grub_uint16_t *) 0x54);
|
|
- grub_machine_mmaphook_int15segment = *((grub_uint16_t *) 0x56);
|
|
+ grub_machine_mmaphook_int12offset = *((grub_uint16_t *) grub_absolute_pointer (0x48));
|
|
+ grub_machine_mmaphook_int12segment = *((grub_uint16_t *) grub_absolute_pointer (0x4a));
|
|
+ grub_machine_mmaphook_int15offset = *((grub_uint16_t *) grub_absolute_pointer (0x54));
|
|
+ grub_machine_mmaphook_int15segment = *((grub_uint16_t *) grub_absolute_pointer (0x56));
|
|
|
|
grub_dprintf ("mmap", "hooktarget = %p\n", hooktarget);
|
|
|
|
@@ -102,11 +102,11 @@
|
|
grub_memcpy (hooktarget, &grub_machine_mmaphook_start,
|
|
&grub_machine_mmaphook_end - &grub_machine_mmaphook_start);
|
|
|
|
- *((grub_uint16_t *) 0x4a) = ((grub_addr_t) hooktarget) >> 4;
|
|
- *((grub_uint16_t *) 0x56) = ((grub_addr_t) hooktarget) >> 4;
|
|
- *((grub_uint16_t *) 0x48) = &grub_machine_mmaphook_int12
|
|
+ *((grub_uint16_t *) grub_absolute_pointer (0x4a)) = ((grub_addr_t) hooktarget) >> 4;
|
|
+ *((grub_uint16_t *) grub_absolute_pointer (0x56)) = ((grub_addr_t) hooktarget) >> 4;
|
|
+ *((grub_uint16_t *) grub_absolute_pointer (0x48)) = &grub_machine_mmaphook_int12
|
|
- &grub_machine_mmaphook_start;
|
|
- *((grub_uint16_t *) 0x54) = &grub_machine_mmaphook_int15
|
|
+ *((grub_uint16_t *) grub_absolute_pointer (0x54)) = &grub_machine_mmaphook_int15
|
|
- &grub_machine_mmaphook_start;
|
|
|
|
return GRUB_ERR_NONE;
|
|
@@ -116,10 +116,10 @@
|
|
preboot_rest (void)
|
|
{
|
|
/* Restore old interrupt handlers. */
|
|
- *((grub_uint16_t *) 0x48) = grub_machine_mmaphook_int12offset;
|
|
- *((grub_uint16_t *) 0x4a) = grub_machine_mmaphook_int12segment;
|
|
- *((grub_uint16_t *) 0x54) = grub_machine_mmaphook_int15offset;
|
|
- *((grub_uint16_t *) 0x56) = grub_machine_mmaphook_int15segment;
|
|
+ *((grub_uint16_t *) grub_absolute_pointer (0x48)) = grub_machine_mmaphook_int12offset;
|
|
+ *((grub_uint16_t *) grub_absolute_pointer (0x4a)) = grub_machine_mmaphook_int12segment;
|
|
+ *((grub_uint16_t *) grub_absolute_pointer (0x54)) = grub_machine_mmaphook_int15offset;
|
|
+ *((grub_uint16_t *) grub_absolute_pointer (0x56)) = grub_machine_mmaphook_int15segment;
|
|
|
|
return GRUB_ERR_NONE;
|
|
}
|
|
--- a/grub-core/net/drivers/i386/pc/pxe.c
|
|
+++ b/grub-core/net/drivers/i386/pc/pxe.c
|
|
@@ -174,7 +174,7 @@
|
|
grub_uint8_t *ptr, *end;
|
|
struct grub_net_buff *buf;
|
|
|
|
- isr = (void *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR;
|
|
+ isr = (void *) grub_absolute_pointer (GRUB_MEMORY_MACHINE_SCRATCH_ADDR);
|
|
|
|
if (!in_progress)
|
|
{
|
|
@@ -256,11 +256,11 @@
|
|
struct grub_pxe_undi_tbd *tbd;
|
|
char *buf;
|
|
|
|
- trans = (void *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR;
|
|
+ trans = (void *) grub_absolute_pointer (GRUB_MEMORY_MACHINE_SCRATCH_ADDR);
|
|
grub_memset (trans, 0, sizeof (*trans));
|
|
- tbd = (void *) (GRUB_MEMORY_MACHINE_SCRATCH_ADDR + 128);
|
|
+ tbd = (void *) grub_absolute_pointer (GRUB_MEMORY_MACHINE_SCRATCH_ADDR + 128);
|
|
grub_memset (tbd, 0, sizeof (*tbd));
|
|
- buf = (void *) (GRUB_MEMORY_MACHINE_SCRATCH_ADDR + 256);
|
|
+ buf = (void *) grub_absolute_pointer (GRUB_MEMORY_MACHINE_SCRATCH_ADDR + 256);
|
|
grub_memcpy (buf, pack->data, pack->tail - pack->data);
|
|
|
|
trans->tbd = SEGOFS ((grub_addr_t) tbd);
|
|
@@ -287,7 +287,7 @@
|
|
grub_pxe_open (struct grub_net_card *dev __attribute__ ((unused)))
|
|
{
|
|
struct grub_pxe_undi_open *ou;
|
|
- ou = (void *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR;
|
|
+ ou = (void *) grub_absolute_pointer (GRUB_MEMORY_MACHINE_SCRATCH_ADDR);
|
|
grub_memset (ou, 0, sizeof (*ou));
|
|
ou->pkt_filter = 4;
|
|
grub_pxe_call (GRUB_PXENV_UNDI_OPEN, ou, pxe_rm_entry);
|
|
@@ -382,7 +382,7 @@
|
|
if (! pxenv)
|
|
return;
|
|
|
|
- ui = (void *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR;
|
|
+ ui = (void *) grub_absolute_pointer (GRUB_MEMORY_MACHINE_SCRATCH_ADDR);
|
|
grub_memset (ui, 0, sizeof (*ui));
|
|
grub_pxe_call (GRUB_PXENV_UNDI_GET_INFORMATION, ui, pxe_rm_entry);
|
|
|
|
--- a/grub-core/term/i386/pc/console.c
|
|
+++ b/grub-core/term/i386/pc/console.c
|
|
@@ -238,12 +238,11 @@
|
|
return (regs.eax & 0xff) + (('a' - 1) | GRUB_TERM_CTRL);
|
|
}
|
|
|
|
-static const struct grub_machine_bios_data_area *bios_data_area =
|
|
- (struct grub_machine_bios_data_area *) GRUB_MEMORY_MACHINE_BIOS_DATA_AREA_ADDR;
|
|
-
|
|
static int
|
|
grub_console_getkeystatus (struct grub_term_input *term __attribute__ ((unused)))
|
|
{
|
|
+ const struct grub_machine_bios_data_area *bios_data_area =
|
|
+ (struct grub_machine_bios_data_area *) grub_absolute_pointer (GRUB_MEMORY_MACHINE_BIOS_DATA_AREA_ADDR);
|
|
/* conveniently GRUB keystatus is modelled after BIOS one. */
|
|
return bios_data_area->keyboard_flag_lower & ~0x80;
|
|
}
|
|
--- a/grub-core/term/i386/pc/vga_text.c
|
|
+++ b/grub-core/term/i386/pc/vga_text.c
|
|
@@ -45,15 +45,15 @@
|
|
static struct grub_term_coordinate grub_curr_pos;
|
|
|
|
#ifdef __mips__
|
|
-#define VGA_TEXT_SCREEN ((grub_uint16_t *) 0xb00b8000)
|
|
+#define VGA_TEXT_SCREEN ((grub_uint16_t *) grub_absolute_pointer (0xb00b8000))
|
|
#define cr_read grub_vga_cr_read
|
|
#define cr_write grub_vga_cr_write
|
|
#elif defined (MODE_MDA)
|
|
-#define VGA_TEXT_SCREEN ((grub_uint16_t *) 0xb0000)
|
|
+#define VGA_TEXT_SCREEN ((grub_uint16_t *) grub_absolute_pointer (0xb0000))
|
|
#define cr_read grub_vga_cr_bw_read
|
|
#define cr_write grub_vga_cr_bw_write
|
|
#else
|
|
-#define VGA_TEXT_SCREEN ((grub_uint16_t *) 0xb8000)
|
|
+#define VGA_TEXT_SCREEN ((grub_uint16_t *) grub_absolute_pointer (0xb8000))
|
|
#define cr_read grub_vga_cr_read
|
|
#define cr_write grub_vga_cr_write
|
|
#endif
|
|
--- a/grub-core/term/ns8250.c
|
|
+++ b/grub-core/term/ns8250.c
|
|
@@ -28,7 +28,6 @@
|
|
|
|
#ifdef GRUB_MACHINE_PCBIOS
|
|
#include <grub/machine/memory.h>
|
|
-static const unsigned short *serial_hw_io_addr = (const unsigned short *) GRUB_MEMORY_MACHINE_BIOS_DATA_AREA_ADDR;
|
|
#define GRUB_SERIAL_PORT_NUM 4
|
|
#else
|
|
#include <grub/machine/serial.h>
|
|
@@ -237,6 +236,9 @@
|
|
void
|
|
grub_ns8250_init (void)
|
|
{
|
|
+#ifdef GRUB_MACHINE_PCBIOS
|
|
+ const unsigned short *serial_hw_io_addr = (const unsigned short *) grub_absolute_pointer (GRUB_MEMORY_MACHINE_BIOS_DATA_AREA_ADDR);
|
|
+#endif
|
|
unsigned i;
|
|
for (i = 0; i < GRUB_SERIAL_PORT_NUM; i++)
|
|
if (serial_hw_io_addr[i])
|
|
@@ -272,6 +274,9 @@
|
|
grub_port_t
|
|
grub_ns8250_hw_get_port (const unsigned int unit)
|
|
{
|
|
+#ifdef GRUB_MACHINE_PCBIOS
|
|
+ const unsigned short *serial_hw_io_addr = (const unsigned short *) grub_absolute_pointer (GRUB_MEMORY_MACHINE_BIOS_DATA_AREA_ADDR);
|
|
+#endif
|
|
if (unit < GRUB_SERIAL_PORT_NUM
|
|
&& !(dead_ports & (1 << unit)))
|
|
return serial_hw_io_addr[unit];
|
|
--- a/grub-core/video/i386/pc/vbe.c
|
|
+++ b/grub-core/video/i386/pc/vbe.c
|
|
@@ -514,7 +514,7 @@
|
|
|
|
/* Use low memory scratch area as temporary storage
|
|
for VESA BIOS call. */
|
|
- vbe_ib = (struct grub_vbe_info_block *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR;
|
|
+ vbe_ib = (struct grub_vbe_info_block *) grub_absolute_pointer (GRUB_MEMORY_MACHINE_SCRATCH_ADDR);
|
|
|
|
/* Prepare info block. */
|
|
grub_memset (vbe_ib, 0, sizeof (*vbe_ib));
|
|
@@ -574,7 +574,7 @@
|
|
|
|
/* Use low memory scratch area as temporary storage for VESA BIOS calls. */
|
|
flat_panel_info = (struct grub_vbe_flat_panel_info *)
|
|
- (GRUB_MEMORY_MACHINE_SCRATCH_ADDR + sizeof (struct grub_video_edid_info));
|
|
+ grub_absolute_pointer (GRUB_MEMORY_MACHINE_SCRATCH_ADDR + sizeof (struct grub_video_edid_info));
|
|
|
|
if (controller_info.version >= 0x200
|
|
&& (grub_vbe_bios_get_ddc_capabilities (&ddc_level) & 0xff)
|
|
@@ -676,7 +676,7 @@
|
|
== GRUB_VBE_MEMORY_MODEL_PACKED_PIXEL)
|
|
{
|
|
struct grub_vbe_palette_data *palette
|
|
- = (struct grub_vbe_palette_data *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR;
|
|
+ = (struct grub_vbe_palette_data *) grub_absolute_pointer (GRUB_MEMORY_MACHINE_SCRATCH_ADDR);
|
|
unsigned i;
|
|
|
|
/* Make sure that the BIOS can reach the palette. */
|
|
--- a/include/grub/compiler.h
|
|
+++ b/include/grub/compiler.h
|
|
@@ -48,4 +48,15 @@
|
|
# define WARN_UNUSED_RESULT
|
|
#endif
|
|
|
|
+#if defined(__GNUC__)
|
|
+# define grub_absolute_pointer(val) \
|
|
+({ \
|
|
+ unsigned long __ptr; \
|
|
+ __asm__ ("" : "=r"(__ptr) : "0"((void *)(val))); \
|
|
+ (void *) (__ptr); \
|
|
+})
|
|
+#else
|
|
+# define grub_absolute_pointer(val) ((void *)(val))
|
|
+#endif
|
|
+
|
|
#endif /* ! GRUB_COMPILER_HEADER */
|