efiboot
PATCH 1/1 efiboot
hello. Since big parts of my multiboot on efi matured into mmap services here is the rest. I was able to successfully boot invaders and freebsd64 from efi32. This patch is still preview and testing and not for merging
Signature · 2 lines
Regards Vladimir 'phcoder' Serbinenko
conf/common.rmk +7 -0
@@ -546,3 +546,10 @@ gzio_mod_LDFLAGS = $(COMMON_LDFLAGS) bufio_mod_SOURCES = io/bufio.c bufio_mod_CFLAGS = $(COMMON_CFLAGS) bufio_mod_LDFLAGS = $(COMMON_LDFLAGS) + +pkglib_MODULES += lsmmap.mod + +# For lsmmap.mod +lsmmap_mod_SOURCES = commands/lsmmap.c +lsmmap_mod_CFLAGS = $(COMMON_CFLAGS) +lsmmap_mod_LDFLAGS = $(COMMON_LDFLAGS)
conf/i386-coreboot.rmk +1 -6
@@ -105,7 +105,7 @@ pkglib_MODULES = linux.mod multiboot.mod \ aout.mod play.mod serial.mod ata.mod \ memdisk.mod pci.mod lspci.mod reboot.mod \ halt.mod datetime.mod date.mod datehook.mod \ - lsmmap.mod mmap.mod + mmap.mod # For mmap.mod. mmap_mod_SOURCES = mmap/mmap.c mmap/i386/uppermem.c mmap/i386/mmap.c
@@ -188,10 +188,5 @@ datehook_mod_SOURCES = hook/datehook.c datehook_mod_CFLAGS = $(COMMON_CFLAGS) datehook_mod_LDFLAGS = $(COMMON_LDFLAGS) -# For lsmmap.mod -lsmmap_mod_SOURCES = commands/lsmmap.c -lsmmap_mod_CFLAGS = $(COMMON_CFLAGS) -lsmmap_mod_LDFLAGS = $(COMMON_LDFLAGS) - include $(srcdir)/conf/i386.mk include $(srcdir)/conf/common.mk
conf/i386-efi.rmk +11 -1
@@ -83,7 +83,17 @@ grub_install_SOURCES = util/i386/efi/grub-install.in pkglib_MODULES = kernel.mod chain.mod appleldr.mod \ linux.mod halt.mod reboot.mod pci.mod lspci.mod \ datetime.mod date.mod datehook.mod loadbios.mod \ - fixvideo.mod mmap.mod acpi.mod + fixvideo.mod mmap.mod acpi.mod multiboot.mod + +# For multiboot.mod. +multiboot_mod_SOURCES = loader/i386/multiboot.c \ + loader/i386/multiboot_helper.S \ + loader/multiboot2.c \ + loader/efi/multiboot2.c \ + loader/multiboot_loader.c +multiboot_mod_CFLAGS = $(COMMON_CFLAGS) +multiboot_mod_LDFLAGS = $(COMMON_LDFLAGS) +multiboot_mod_ASFLAGS = $(COMMON_ASFLAGS) # For kernel.mod. kernel_mod_EXPORTS = no
conf/i386-ieee1275.rmk +1 -6
@@ -105,7 +105,7 @@ grub_install_SOURCES = util/ieee1275/grub-install.in pkglib_MODULES = halt.mod reboot.mod suspend.mod \ multiboot.mod aout.mod serial.mod linux.mod \ nand.mod memdisk.mod pci.mod lspci.mod datetime.mod \ - date.mod datehook.mod lsmmap.mod mmap.mod + date.mod datehook.mod mmap.mod # For mmap.mod. mmap_mod_SOURCES = mmap/mmap.c mmap/i386/uppermem.c mmap/i386/mmap.c
@@ -187,10 +187,5 @@ datehook_mod_SOURCES = hook/datehook.c datehook_mod_CFLAGS = $(COMMON_CFLAGS) datehook_mod_LDFLAGS = $(COMMON_LDFLAGS) -# For lsmmap.mod -lsmmap_mod_SOURCES = commands/lsmmap.c -lsmmap_mod_CFLAGS = $(COMMON_CFLAGS) -lsmmap_mod_LDFLAGS = $(COMMON_LDFLAGS) - include $(srcdir)/conf/i386.mk include $(srcdir)/conf/common.mk
conf/i386-pc.rmk +0 -16
@@ -307,17 +307,6 @@ lspci_mod_SOURCES = commands/lspci.c lspci_mod_CFLAGS = $(COMMON_CFLAGS) lspci_mod_LDFLAGS = $(COMMON_LDFLAGS) -# For aout.mod -aout_mod_SOURCES = loader/aout.c -aout_mod_CFLAGS = $(COMMON_CFLAGS) -aout_mod_LDFLAGS = $(COMMON_LDFLAGS) - -# For bsd.mod -bsd_mod_SOURCES = loader/i386/bsd.c loader/i386/bsd_helper.S loader/i386/bsd_trampoline.S -bsd_mod_CFLAGS = $(COMMON_CFLAGS) -bsd_mod_LDFLAGS = $(COMMON_LDFLAGS) -bsd_mod_ASFLAGS = $(COMMON_ASFLAGS) - # For usb.mod usb_mod_SOURCES = bus/usb/usb.c bus/usb/usbtrans.c bus/usb/usbhub.c usb_mod_CFLAGS = $(COMMON_CFLAGS)
@@ -373,11 +362,6 @@ datehook_mod_SOURCES = hook/datehook.c datehook_mod_CFLAGS = $(COMMON_CFLAGS) datehook_mod_LDFLAGS = $(COMMON_LDFLAGS) -# For lsmmap.mod -lsmmap_mod_SOURCES = commands/lsmmap.c -lsmmap_mod_CFLAGS = $(COMMON_CFLAGS) -lsmmap_mod_LDFLAGS = $(COMMON_LDFLAGS) - # For ata_pthru.mod. ata_pthru_mod_SOURCES = disk/ata_pthru.c ata_pthru_mod_CFLAGS = $(COMMON_CFLAGS)
conf/i386.rmk +13 -0
@@ -14,3 +14,16 @@ pkglib_MODULES += vga_text.mod vga_text_mod_SOURCES = term/i386/pc/vga_text.c term/i386/vga_common.c vga_text_mod_CFLAGS = $(COMMON_CFLAGS) vga_text_mod_LDFLAGS = $(COMMON_LDFLAGS) + +pkglib_MODULES += aout.mod bsd.mod +# For aout.mod +aout_mod_SOURCES = loader/aout.c +aout_mod_CFLAGS = $(COMMON_CFLAGS) +aout_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For bsd.mod +bsd_mod_SOURCES = loader/i386/bsd.c loader/i386/bsd_helper.S loader/i386/bsd_trampoline.S +bsd_mod_CFLAGS = $(COMMON_CFLAGS) -Werror +bsd_mod_LDFLAGS = $(COMMON_LDFLAGS) +bsd_mod_ASFLAGS = $(COMMON_ASFLAGS) +
conf/powerpc-ieee1275.rmk +1 -7
@@ -113,8 +113,7 @@ pkglib_MODULES = halt.mod \ reboot.mod \ suspend.mod \ multiboot.mod \ - memdisk.mod \ - lsmmap.mod + memdisk.mod # For linux.mod. linux_mod_SOURCES = loader/powerpc/ieee1275/linux.c
@@ -148,10 +147,5 @@ memdisk_mod_SOURCES = disk/memdisk.c memdisk_mod_CFLAGS = $(COMMON_CFLAGS) memdisk_mod_LDFLAGS = $(COMMON_LDFLAGS) -# For lsmmap.mod -lsmmap_mod_SOURCES = commands/lsmmap.c -lsmmap_mod_CFLAGS = $(COMMON_CFLAGS) -lsmmap_mod_LDFLAGS = $(COMMON_LDFLAGS) - include $(srcdir)/conf/common.mk
include/grub/i386/loader.h +0 -2
@@ -27,8 +27,6 @@ extern grub_uint32_t EXPORT_VAR(grub_linux_prot_size);extern char *EXPORT_VAR (grub_linux_tmp_addr );extern char *EXPORT_VAR (grub_linux_real_addr );extern grub_int32_t EXPORT_VAR (grub_linux_is_bzimage ); -extern grub_addr_t EXPORT_VAR (grub_os_area_addr ); -extern grub_size_t EXPORT_VAR (grub_os_area_size );grub_err_t EXPORT_FUNC (grub_linux16_boot ) (void );
include/grub/i386/multiboot.h +2 -2
@@ -22,10 +22,10 @@/* The asm part of the multiboot loader. */ void grub_multiboot_real_boot (grub_addr_t entry,struct grub_multiboot_info *mbi) - __attribute__ ((noreturn)); + __attribute__ ((noreturn,regparm (3 )));void grub_multiboot2_real_boot (grub_addr_t entry,struct grub_multiboot_info *mbi) - __attribute__ ((noreturn)); + __attribute__ ((noreturn,regparm (3 )));extern grub_addr_t grub_multiboot_payload_orig;extern grub_addr_t grub_multiboot_payload_dest;
include/grub/ieee1275/ieee1275.h +0 -1
@@ -172,7 +172,6 @@ int EXPORT_FUNC(grub_children_iterate) (char *devpath, int (*hook) (struct grub_ieee1275_devalias *alias));grub_err_t EXPORT_FUNC (grub_machine_mmap_iterate ) (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, grub_uint64_t, grub_uint32_t)); -int EXPORT_FUNC (grub_claimmap ) (grub_addr_t addr,grub_size_t size);char *EXPORT_FUNC (grub_ieee1275_encode_devname ) (const char *path);char *EXPORT_FUNC (grub_ieee1275_get_filename ) (const char *path);
include/grub/loader.h +4 -0
@@ -63,4 +63,8 @@ void *grub_loader_register_preboot_hook (grub_err_t (*preboot_func) (int noret),/* Unregister given preboot hook. */ void grub_loader_unregister_preboot_hook (void *hnd); +int EXPORT_FUNC (grub_claimmap ) (grub_addr_t addr,grub_size_t size); + +void EXPORT_FUNC (grub_declaimmap ) (grub_addr_t addr,grub_size_t size); +#endif /* ! GRUB_LOADER_HEADER */
include/grub/multiboot2.h +0 -6
@@ -39,12 +39,6 @@ void grub_mb2_arch_unload (struct multiboot_tag_header *tags);grub_err_t -grub_mb2_arch_elf32_hook (Elf32_Phdr *phdr,grub_addr_t *addr); - -grub_err_t -grub_mb2_arch_elf64_hook (Elf64_Phdr *phdr,grub_addr_t *addr); - -grub_err_t grub_mb2_arch_module_alloc (grub_size_t size,grub_addr_t *addr); grub_err_t
kern/efi/mm.c +18 -0
@@ -427,3 +427,21 @@ grub_efi_mm_fini (void) BYTES_TO_PAGES (ALLOCATED_PAGES_SIZE)); } } + +/* XXX: Manage subpage allocations */ +int +grub_claimmap (grub_addr_t addr,grub_size_t size) +{ +void *ret; + ret =grub_efi_allocate_pages (addr & (~0xfff ), + (size + (addr &0xfff ) +0xfff ) >>12 ); +return (! ret) ?-1 :0 ; +} + +/* XXX: Manage subpage allocations */ +void +grub_declaimmap (grub_addr_t addr,grub_size_t size) +{ +grub_efi_free_pages (addr & (~0xfff ), + (size + (addr &0xfff ) +0xfff ) >>12 ); +}
kern/i386/coreboot/init.c +15 -0
@@ -147,3 +147,18 @@ grub_arch_modules_addr (void) {return ALIGN_UP ((grub_addr_t ) _end,GRUB_MOD_ALIGN ); } + +int +grub_claimmap (grub_addr_t addr,grub_size_t size) +{ +if ((addr < grub_os_area_addr) + || (addr + size > grub_os_area_addr + grub_os_area_size)) +return -1 ; +return 0 ; +} + +void +grub_declaimmap (grub_addr_t addr __attribute__ ((unused)), +grub_size_t size __attribute__ ((unused))) +{ +}
kern/i386/pc/init.c +17 -2
@@ -43,8 +43,8 @@ struct mem_regionstatic struct mem_region mem_regions[MAX_REGIONS ];static int num_regions; -grub_addr_t grub_os_area_addr; -grub_size_t grub_os_area_size; +static grub_addr_t grub_os_area_addr; +static grub_size_t grub_os_area_size; void grub_arch_sync_caches (void *address __attribute__ ((unused)),
@@ -232,3 +232,18 @@ grub_arch_modules_addr (void)return GRUB_MEMORY_MACHINE_DECOMPRESSION_ADDR + (grub_kernel_image_size -GRUB_KERNEL_MACHINE_RAW_SIZE ); } + +int +grub_claimmap (grub_addr_t addr,grub_size_t size) +{ +if ((addr < grub_os_area_addr) + || (addr + size > grub_os_area_addr + grub_os_area_size)) +return -1 ; +return 0 ; +} + +void +grub_declaimmap (grub_addr_t addr __attribute__ ((unused)), +grub_size_t size __attribute__ ((unused))) +{ +}
kern/ieee1275/openfw.c +7 -0
@@ -247,6 +247,13 @@ grub_claimmap (grub_addr_t addr, grub_size_t size)return 0 ; } +/* XXX Could someone with better OFW knowledge that me fill this? */ +void +grub_declaimmap (grub_addr_t addr __attribute__ ((unused)), +grub_size_t size __attribute__ ((unused))) +{ +} +/* Get the device arguments of the Open Firmware node name `path'. */ static char *grub_ieee1275_get_devargs (const char *path)
loader/efi/multiboot2.c new file +75 -0
75 lines not on this page · raw message
loader/i386/bsd.c +28 -11
@@ -19,7 +19,6 @@#include <grub/loader.h> #include <grub/cpu/loader.h> #include <grub/cpu/bsd.h> -#include <grub/machine/init.h> #include <grub/machine/memory.h> #include <grub/memory.h> #include <grub/machine/machine.h>
@@ -34,6 +33,10 @@#include <grub/aout.h> #include <grub/command.h> +#ifdef GRUB_MACHINE_EFI +#include <grub/efi/efi.h> +#endif +#define ALIGN_DWORD (a) ALIGN_UP (a, 4)#define ALIGN_QWORD (a) ALIGN_UP (a, 8)#define ALIGN_VAR (a) ((is_64bit) ? (ALIGN_QWORD(a)) : (ALIGN_DWORD(a)))
@@ -516,14 +519,25 @@ grub_freebsd_boot (void)grub_memcpy (trampoline, &grub_bsd64_trampoline_start, &grub_bsd64_trampoline_end - &grub_bsd64_trampoline_start); +#ifdef GRUB_MACHINE_EFI +if (!grub_efi_finish_boot_services ()) +grub_fatal ("cannot exit boot services" ); +#endif +/* Launch trampoline. */ launch_trampoline (entry, entry_hi, pagetable, bi.bi_modulep, kern_end); }else -grub_unix_real_boot (entry, bootflags |FREEBSD_RB_BOOTINFO , bootdev, -0 ,0 ,0 , &bi, bi.bi_modulep, kern_end); + { +#ifdef GRUB_MACHINE_EFI +if (!grub_efi_finish_boot_services ()) +grub_fatal ("cannot exit boot services" ); +#endif +grub_unix_real_boot (entry, bootflags |FREEBSD_RB_BOOTINFO , bootdev, +0 ,0 ,0 , &bi, bi.bi_modulep, kern_end); + }/* Not reached. */ return GRUB_ERR_NONE ; }
@@ -573,6 +587,11 @@ grub_openbsd_boot (void) bootdev = (OPENBSD_B_DEVMAGIC + (unit <<OPENBSD_B_UNITSHIFT ) + (part <<OPENBSD_B_PARTSHIFT )); +#ifdef GRUB_MACHINE_EFI +if (!grub_efi_finish_boot_services ()) +grub_fatal ("cannot exit boot services" ); +#endif + grub_unix_real_boot (entry, bootflags, bootdev, OPENBSD_BOOTARG_APIVER, 0, grub_mmap_get_upper () >> 10, grub_mmap_get_lower () >> 10,
@@ -688,8 +707,7 @@ grub_bsd_elf32_hook (Elf32_Phdr * phdr, grub_addr_t * addr) phdr->p_paddr &=0xFFFFFF ; paddr = phdr->p_paddr; -if ((paddr < grub_os_area_addr) - || (paddr + phdr->p_memsz > grub_os_area_addr + grub_os_area_size)) +if (grub_claimmap (paddr, phdr->p_memsz) <0 )return grub_error (GRUB_ERR_OUT_OF_RANGE ,"Address 0x%x is out of range" , paddr);
@@ -711,8 +729,7 @@ grub_bsd_elf64_hook (Elf64_Phdr * phdr, grub_addr_t * addr) paddr = phdr->p_paddr &0xffffff ; -if ((paddr < grub_os_area_addr) - || (paddr + phdr->p_memsz > grub_os_area_addr + grub_os_area_size)) +if (grub_claimmap (paddr, phdr->p_memsz) <0 )return grub_error (GRUB_ERR_OUT_OF_RANGE ,"Address 0x%x is out of range" , paddr);
@@ -835,7 +852,7 @@ grub_cmd_freebsd (grub_command_t cmd __attribute__ ((unused)), (grub_freebsd_add_meta_module (1, argc, argv, kern_start, kern_end - kern_start)))return grub_errno; -grub_loader_set (grub_freebsd_boot, grub_bsd_unload,1 ); +grub_loader_set (grub_freebsd_boot, grub_bsd_unload,0 ); }return grub_errno;
@@ -850,7 +867,7 @@ grub_cmd_openbsd (grub_command_t cmd __attribute__ ((unused)), grub_bsd_parse_flags (argv[1], openbsd_opts, openbsd_flags));if (grub_bsd_load (argc, argv) ==GRUB_ERR_NONE ) -grub_loader_set (grub_openbsd_boot, grub_bsd_unload,1 ); +grub_loader_set (grub_openbsd_boot, grub_bsd_unload,0 );return grub_errno; }
@@ -864,7 +881,7 @@ grub_cmd_netbsd (grub_command_t cmd __attribute__ ((unused)), grub_bsd_parse_flags (argv[1], netbsd_opts, netbsd_flags));if (grub_bsd_load (argc, argv) ==GRUB_ERR_NONE ) -grub_loader_set (grub_netbsd_boot, grub_bsd_unload,1 ); +grub_loader_set (grub_netbsd_boot, grub_bsd_unload,0 );return grub_errno; }
@@ -982,7 +999,7 @@ grub_cmd_freebsd_module (grub_command_t cmd __attribute__ ((unused)),if ((!file) || (!file->size)) goto fail; -if (kern_end + file->size > grub_os_area_addr + grub_os_area_size) +if (grub_claimmap (kern_end, file->size) <0 ) {grub_error (GRUB_ERR_OUT_OF_RANGE ,"Not enough memory for the module" ); goto fail;
loader/i386/bsd_pagetable.c +17 -21
@@ -1,24 +1,3 @@ -/* -* GRUB -- GRand Unified Bootloader -* Copyright (c) 1998 Michael Smith <[email protected]> -* 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/>. -*/ - -/* Based on the code from FreeBSD originally distributed under the -following terms: */ /*- * Copyright (c) 1998 Michael Smith <[email protected]>
@@ -47,6 +26,23 @@* * $FreeBSD$ */ +/* +* 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/>. +*/ static void
loader/i386/bsd_trampoline.S +18 -21
@@ -1,27 +1,7 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (c) 2003 Peter Wemm <[email protected]> - * 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/>. - */ - -/* Based on the code from FreeBSD originally distributed under the - following terms: */ /*- * Copyright (c) 2003 Peter Wemm <[email protected]> + * Copyright (C) 2009 Free Software Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without
@@ -47,6 +27,23 @@ * * $FreeBSD$ */ +/* + * 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/>. + */ #define MSR_EFER 0xc0000080
loader/i386/efi/linux.c +77 -104
311 lines not on this page · raw message
loader/i386/linux.c +48 -29
150 lines not on this page · raw message
loader/i386/multiboot.c +32 -5
@@ -30,8 +30,9 @@#include <grub/loader.h> #include <grub/machine/loader.h> #include <grub/multiboot.h> -#include <grub/machine/init.h> +#include <grub/machine/machine.h> #include <grub/machine/memory.h> +#include <grub/memory.h> #include <grub/cpu/multiboot.h> #include <grub/elf.h> #include <grub/aout.h>
@@ -42,6 +43,12 @@#include <grub/misc.h> #include <grub/gzio.h> #include <grub/env.h> +#include <grub/cpu/loader.h> +#include <grub/cpu/multiboot.h> + +#ifdef GRUB_MACHINE_EFI +#include <grub/efi/efi.h> +#endif extern grub_dl_t my_mod;static struct grub_multiboot_info *mbi, *mbi_dest;
@@ -53,6 +60,13 @@ static grub_size_t code_size;static grub_err_t grub_multiboot_boot (void ) { +grub_printf ("Boot\n" ); + +#ifdef GRUB_MACHINE_EFI +if (!grub_efi_finish_boot_services ()) +grub_fatal ("cannot exit boot services" ); +#endif +grub_multiboot_real_boot (entry, mbi_dest);/* Not reached. */
@@ -108,14 +122,24 @@ grub_get_multiboot_mmap_len (void)static void grub_fill_multiboot_mmap (struct grub_multiboot_mmap_entry *first_entry) { -struct grub_multiboot_mmap_entry *mmap_entry = (struct grub_multiboot_mmap_entry *) first_entry; +struct grub_multiboot_mmap_entry *mmap_entry + = (struct grub_multiboot_mmap_entry *) first_entry; auto int NESTED_FUNC_ATTR hook (grub_uint64_t, grub_uint64_t, grub_uint32_t); int NESTED_FUNC_ATTR hook (grub_uint64_t addr, grub_uint64_t size, grub_uint32_t type) { mmap_entry->addr = addr; mmap_entry->len = size; - mmap_entry->type = type; +switch (type) + { +case GRUB_MACHINE_MEMORY_AVAILABLE : + mmap_entry->type =GRUB_MULTIBOOT_MEMORY_AVAILABLE ; +break ; + +default : + mmap_entry->type =GRUB_MULTIBOOT_MEMORY_RESERVED ; +break ; + } mmap_entry->size =sizeof (struct grub_multiboot_mmap_entry ) -sizeof (mmap_entry->size); mmap_entry++;
@@ -198,6 +222,7 @@ grub_multiboot (int argc, char *argv[])struct grub_multiboot_header *header;grub_ssize_t len, cmdline_length, boot_loader_name_length;grub_uint32_t mmap_length; +grub_uint64_t lower, upper;int i;grub_loader_unset ();
@@ -285,7 +310,9 @@ grub_multiboot (int argc, char *argv[]) grub_multiboot_payload_dest = header->load_addr; grub_multiboot_payload_size += code_size; - playground =grub_malloc (RELOCATOR_SIZEOF (forward) + grub_multiboot_payload_size +RELOCATOR_SIZEOF (backward)); + playground =grub_malloc (RELOCATOR_SIZEOF (forward) + + grub_multiboot_payload_size + +RELOCATOR_SIZEOF (backward));if (! playground) goto fail;
@@ -369,7 +396,7 @@ grub_multiboot (int argc, char *argv[])if (grub_multiboot_get_bootdev (&mbi->boot_device)) mbi->flags |=MULTIBOOT_INFO_BOOTDEV ; -grub_loader_set (grub_multiboot_boot, grub_multiboot_unload,1 ); +grub_loader_set (grub_multiboot_boot, grub_multiboot_unload,0 ); fail:if (file)
loader/i386/pc/linux.c +5 -7
@@ -71,11 +71,10 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),if (! file) goto fail; -if ((grub_size_t )grub_file_size (file) > grub_os_area_size) +if (grub_claimmap (GRUB_LINUX_BZIMAGE_ADDR ,grub_file_size (file)) <0 ) { -grub_error (GRUB_ERR_OUT_OF_RANGE ,"too big kernel (0x%x > 0x%x)" , - (grub_size_t )grub_file_size (file), - grub_os_area_size); +grub_error (GRUB_ERR_OUT_OF_RANGE ,"too big kernel (0x%x)" , + (grub_size_t )grub_file_size (file)); goto fail; }
@@ -341,9 +340,6 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),worse than that of Linux 2.3.xx, so avoid the last 64kb. */ addr_max -=0x10000 ; -if (addr_max > grub_os_area_addr + grub_os_area_size) - addr_max = grub_os_area_addr + grub_os_area_size; - addr_min = (grub_addr_t ) grub_linux_tmp_addr +GRUB_LINUX_CL_END_OFFSET ; file =grub_file_open (argv[0 ]);
@@ -354,6 +350,8 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),/* Put the initrd as high as possible, 4KiB aligned. */ addr = (addr_max - size) & ~0xFFF ; +while (addr >= addr_min &&grub_claimmap (addr, size) <0 ) + addr -=0x1000 ;if (addr < addr_min) {
loader/i386/pc/multiboot2.c +1 -26
@@ -25,32 +25,6 @@#include <grub/mm.h> grub_err_t -grub_mb2_arch_elf32_hook (Elf32_Phdr *phdr, UNUSED grub_addr_t *addr) -{ -Elf32_Addr paddr = phdr->p_paddr; - -if ((paddr < grub_os_area_addr) - || (paddr + phdr->p_memsz > grub_os_area_addr + grub_os_area_size)) -return grub_error (GRUB_ERR_OUT_OF_RANGE ,"Address 0x%x is out of range" , - paddr); - -return GRUB_ERR_NONE ; -} - -grub_err_t -grub_mb2_arch_elf64_hook (Elf64_Phdr *phdr, UNUSED grub_addr_t *addr) -{ -Elf64_Addr paddr = phdr->p_paddr; - -if ((paddr < grub_os_area_addr) - || (paddr + phdr->p_memsz > grub_os_area_addr + grub_os_area_size)) -return grub_error (GRUB_ERR_OUT_OF_RANGE ,"Address 0x%x is out of range" , - paddr); - -return GRUB_ERR_NONE ; -} - -grub_err_t grub_mb2_arch_module_alloc (grub_size_t size,grub_addr_t *addr) {grub_addr_t modaddr;
@@ -73,6 +47,7 @@ grub_mb2_arch_module_free (grub_addr_t addr, UNUSED grub_size_t size)void grub_mb2_arch_boot (grub_addr_t entry,void *tags) { +grub_stop_floppy ();grub_multiboot2_real_boot (entry, tags); }
loader/ieee1275/multiboot2.c +0 -35
@@ -31,41 +31,6 @@typedef void (*kernel_entry_t ) (unsigned long ,void *,int (void *),unsigned long ,unsigned long ); -/* Claim the memory occupied by the multiboot kernel. */ -grub_err_t -grub_mb2_arch_elf32_hook (Elf32_Phdr *phdr, UNUSED grub_addr_t *addr) -{ -int rc; - - rc =grub_claimmap (phdr->p_paddr, phdr->p_memsz); -if (rc) -return grub_error (GRUB_ERR_OUT_OF_MEMORY ,"Couldn't claim %x - %x" , - phdr->p_paddr, phdr->p_paddr + phdr->p_memsz); - -grub_dprintf ("loader" ,"Loading segment at 0x%x - 0x%x\n" , phdr->p_paddr, - phdr->p_paddr + phdr->p_memsz); - -return GRUB_ERR_NONE ; -} - -/* Claim the memory occupied by the multiboot kernel. */ -grub_err_t -grub_mb2_arch_elf64_hook (Elf64_Phdr *phdr, UNUSED grub_addr_t *addr) -{ -int rc; - - rc =grub_claimmap (phdr->p_paddr, phdr->p_memsz); -if (rc) -return grub_error (GRUB_ERR_OUT_OF_MEMORY ,"Couldn't claim 0x%lx - 0x%lx" , - phdr->p_paddr, phdr->p_paddr + phdr->p_memsz); - -grub_dprintf ("loader" ,"Loading segment at 0x%lx - 0x%lx\n" , - (unsigned long ) phdr->p_paddr, - (unsigned long ) (phdr->p_paddr + phdr->p_memsz)); - -return GRUB_ERR_NONE ; -} -grub_err_t grub_mb2_arch_module_alloc (grub_size_t size,grub_addr_t *addr) {
loader/multiboot2.c +38 -2
@@ -37,6 +37,42 @@ static char *grub_mb2_tags_pos;static grub_size_t grub_mb2_tags_len;static int grub_mb2_tags_count; +/* Claim the memory occupied by the multiboot kernel. */ +static grub_err_t +grub_mb2_elf32_hook (Elf32_Phdr *phdr, UNUSED grub_addr_t *addr) +{ +int rc; + + rc =grub_claimmap (phdr->p_paddr, phdr->p_memsz); +if (rc) +return grub_error (GRUB_ERR_OUT_OF_MEMORY ,"Couldn't claim %x - %x" , + phdr->p_paddr, phdr->p_paddr + phdr->p_memsz); + +grub_dprintf ("loader" ,"Loading segment at 0x%x - 0x%x\n" , phdr->p_paddr, + phdr->p_paddr + phdr->p_memsz); + +return GRUB_ERR_NONE ; +} + +/* Claim the memory occupied by the multiboot kernel. */ +static grub_err_t +grub_mb2_elf64_hook (Elf64_Phdr *phdr, UNUSED grub_addr_t *addr) +{ +int rc; + + rc =grub_claimmap (phdr->p_paddr, phdr->p_memsz); +if (rc) +return grub_error (GRUB_ERR_OUT_OF_MEMORY ,"Couldn't claim 0x%lx - 0x%lx" , + phdr->p_paddr, phdr->p_paddr + phdr->p_memsz); + +grub_dprintf ("loader" ,"Loading segment at 0x%lx - 0x%lx\n" , + (unsigned long ) phdr->p_paddr, + (unsigned long ) (phdr->p_paddr + phdr->p_memsz)); + +return GRUB_ERR_NONE ; +} + +static void grub_mb2_tags_free (void ) {
@@ -278,13 +314,13 @@ grub_mb2_load_elf (grub_elf_t elf, int argc, char *argv[])if (grub_elf_is_elf32 (elf)) { entry = elf->ehdr.ehdr32.e_entry; - err =grub_elf32_load (elf, grub_mb2_arch_elf32_hook, &kern_base, + err =grub_elf32_load (elf, grub_mb2_elf32_hook, &kern_base, &kern_size); }else if (grub_elf_is_elf64 (elf)) { entry = elf->ehdr.ehdr64.e_entry; - err =grub_elf64_load (elf, grub_mb2_arch_elf64_hook, &kern_base, + err =grub_elf64_load (elf, grub_mb2_elf64_hook, &kern_base, &kern_size); }else
loader/multiboot_loader.c +4 -2
@@ -139,7 +139,7 @@ grub_cmd_multiboot_loader (grub_command_t cmd __attribute__ ((unused)),/* XXX Find a better way to identify this. This is for i386-pc */ -#if defined(GRUB_MACHINE_PCBIOS ) || defined(GRUB_MACHINE_LINUXBIOS ) +#if defined(__i386__)if (header_multi_ver_found ==1 ) { grub_dprintf ("multiboot_loader",
@@ -172,7 +172,7 @@ grub_cmd_module_loader (grub_command_t cmd __attribute__ ((unused)), int argc, char *argv[]) { -#if defined(GRUB_MACHINE_PCBIOS ) || defined(GRUB_MACHINE_LINUXBIOS ) +#if defined(__i386__)if (module_version_status ==1 ) { grub_dprintf("multiboot_loader",
@@ -184,7 +184,9 @@ grub_cmd_module_loader (grub_command_t cmd __attribute__ ((unused)), {grub_dprintf ("multiboot_loader" ,"Launching multiboot 2 grub_module2() function\n" ); +#ifndef GRUB_MACHINE_EFI grub_module2 (argc, argv); +#endif }return grub_errno;