Thu Apr 20 00:42:24 2023 UTC ()
Add reloc keyworkd to let EFI bootstrap load amd64 kernel at any address

EFI bootstrap assumes it can copy the amd64 kernel to its ELF load
address (that is KERNTEXTOFF - KERNBASE = 0x200000), but it can
clash with previous UEFI memory allocation, as described here:
http://mail-index.netbsd.org/tech-kern/2023/04/07/msg028833.html

This change adds a reloc keyword for controling where the EFI
boostrap will copy the kernel image. Possible values are:
default - the default and prior behavior, copy at 0x200000.
none - do not copy and use the kernel image where it was loaded.
address - specify an explicit address where to copy the kernel.

This comes with an amd64 kernel patch that makes it self-relocatable.
It first discover where it was loaded in memory, and if this is
different than the expected 0x200000, hhe the kernel relocates
itself and start over at the right address.


(manu)
diff -r1.218 -r1.219 src/sys/arch/amd64/amd64/locore.S
diff -r1.21 -r1.22 src/sys/arch/i386/stand/efiboot/boot.c
diff -r1.12 -r1.13 src/sys/arch/i386/stand/efiboot/efiboot.c
diff -r1.11 -r1.12 src/sys/arch/i386/stand/efiboot/efiboot.h
diff -r1.5 -r1.6 src/sys/arch/i386/stand/efiboot/bootia32/efibootia32.c
diff -r1.2 -r1.3 src/sys/arch/i386/stand/efiboot/bootia32/startprog32.S
diff -r1.5 -r1.6 src/sys/arch/i386/stand/efiboot/bootx64/efibootx64.c
diff -r1.3 -r1.4 src/sys/arch/i386/stand/efiboot/bootx64/startprog64.S
diff -r1.78 -r1.79 src/sys/arch/i386/stand/lib/exec.c

cvs diff -r1.218 -r1.219 src/sys/arch/amd64/amd64/locore.S (expand / switch to unified diff)

--- src/sys/arch/amd64/amd64/locore.S 2023/03/03 14:32:48 1.218
+++ src/sys/arch/amd64/amd64/locore.S 2023/04/20 00:42:23 1.219
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: locore.S,v 1.218 2023/03/03 14:32:48 riastradh Exp $ */ 1/* $NetBSD: locore.S,v 1.219 2023/04/20 00:42:23 manu Exp $ */
2 2
3/* 3/*
4 * Copyright-o-rama! 4 * Copyright-o-rama!
5 */ 5 */
6 6
7/* 7/*
8 * Copyright (c) 1998, 2000, 2007, 2008, 2016 The NetBSD Foundation, Inc. 8 * Copyright (c) 1998, 2000, 2007, 2008, 2016 The NetBSD Foundation, Inc.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * This code is derived from software contributed to The NetBSD Foundation 11 * This code is derived from software contributed to The NetBSD Foundation
12 * by Charles M. Hannum and by Maxime Villard. 12 * by Charles M. Hannum and by Maxime Villard.
13 * 13 *
14 * Redistribution and use in source and binary forms, with or without 14 * Redistribution and use in source and binary forms, with or without
@@ -446,26 +446,34 @@ tmpstk: @@ -446,26 +446,34 @@ tmpstk:
446/* 446/*
447 * Some hackage to deal with 64bit symbols in 32 bit mode. 447 * Some hackage to deal with 64bit symbols in 32 bit mode.
448 * This may not be needed if things are cleaned up a little. 448 * This may not be needed if things are cleaned up a little.
449 */ 449 */
450 450
451 .text 451 .text
452 .globl _C_LABEL(kernel_text) 452 .globl _C_LABEL(kernel_text)
453 .set _C_LABEL(kernel_text),KERNTEXTOFF 453 .set _C_LABEL(kernel_text),KERNTEXTOFF
454 454
455ENTRY(start) 455ENTRY(start)
456#ifndef XENPV 456#ifndef XENPV
457 .code32 457 .code32
458 458
 459 call next
 460next: pop %edi
 461 sub $(next - kernel_text), %edi
 462
 463 /* If not KERNBASE, reloc ourselves to KERNBASE */
 464 cmpl $(KERNTEXTOFF_LO - KERNBASE_LO), %edi
 465 jne selfreloc_start
 466
459 /* Warm boot */ 467 /* Warm boot */
460 movw $0x1234,0x472 468 movw $0x1234,0x472
461 469
462 /* 470 /*
463 * Load parameters from the stack (32 bits): 471 * Load parameters from the stack (32 bits):
464 * boothowto, [bootdev], bootinfo, esym, biosextmem, biosbasemem 472 * boothowto, [bootdev], bootinfo, esym, biosextmem, biosbasemem
465 * We are not interested in 'bootdev'. 473 * We are not interested in 'bootdev'.
466 */ 474 */
467 475
468 /* Load 'boothowto' */ 476 /* Load 'boothowto' */
469 movl 4(%esp),%eax 477 movl 4(%esp),%eax
470 movl %eax,RELOC(boothowto) 478 movl %eax,RELOC(boothowto)
471 479
@@ -1747,13 +1755,148 @@ LABEL(noibrs_enter_end) @@ -1747,13 +1755,148 @@ LABEL(noibrs_enter_end)
1747LABEL(noibrs_leave) 1755LABEL(noibrs_leave)
1748 NOIBRS_LEAVE 1756 NOIBRS_LEAVE
1749LABEL(noibrs_leave_end) 1757LABEL(noibrs_leave_end)
1750 1758
1751LABEL(mds_leave) 1759LABEL(mds_leave)
1752 pushq $GSEL(GDATA_SEL, SEL_KPL) 1760 pushq $GSEL(GDATA_SEL, SEL_KPL)
1753 verw (%rsp) 1761 verw (%rsp)
1754 addq $8,%rsp 1762 addq $8,%rsp
1755LABEL(mds_leave_end) 1763LABEL(mds_leave_end)
1756 1764
1757LABEL(nomds_leave) 1765LABEL(nomds_leave)
1758 NOMDS_LEAVE 1766 NOMDS_LEAVE
1759LABEL(nomds_leave_end) 1767LABEL(nomds_leave_end)
 1768
 1769/*
 1770 * selfreloc(loadddr edi)
 1771 * This is adapted from sys/arch/i386/i386/locore.S
 1772 */
 1773 .code32
 1774ENTRY(selfreloc_start)
 1775 movl %edi, %ebx /* loadaddr saved in ebx */
 1776 movl %edi, %esi /* src */
 1777 movl $_RELOC(kernel_text), %edi /* dest */
 1778 movl 16(%esp),%ecx /* esym */
 1779 subl $_RELOC(kernel_text), %ecx /* size */
 1780
 1781#if defined(NO_OVERLAP)
 1782 movl %ecx, %eax
 1783#else
 1784 movl %edi, %eax
 1785 subl %esi, %eax
 1786 cmpl %ecx, %eax /* overlapping? */
 1787 movl %ecx, %eax
 1788 jb .Lbackwards
 1789#endif
 1790 /* nope, copy forwards. */
 1791 shrl $2, %ecx /* copy by words */
 1792 rep
 1793 movsl
 1794 and $3, %eax /* any bytes left? */
 1795 jnz .Ltrailing
 1796 jmp .Lcopy_done
 1797
 1798.Ltrailing:
 1799 cmp $2, %eax
 1800 jb 11f
 1801 movw (%esi), %ax
 1802 movw %ax, (%edi)
 1803 je .Lcopy_done
 1804 movb 2(%esi), %al
 1805 movb %al, 2(%edi)
 1806 jmp .Lcopy_done
 180711: movb (%esi), %al
 1808 movb %al, (%edi)
 1809 jmp .Lcopy_done
 1810
 1811#if !defined(NO_OVERLAP)
 1812.Lbackwards:
 1813 addl %ecx, %edi /* copy backwards. */
 1814 addl %ecx, %esi
 1815 and $3, %eax /* any fractional bytes? */
 1816 jnz .Lback_align
 1817.Lback_aligned:
 1818 shrl $2, %ecx
 1819 subl $4, %esi
 1820 subl $4, %edi
 1821 std
 1822 rep
 1823 movsl
 1824 cld
 1825 jmp .Lcopy_done
 1826
 1827.Lback_align:
 1828 sub %eax, %esi
 1829 sub %eax, %edi
 1830 cmp $2, %eax
 1831 jb 11f
 1832 je 12f
 1833 movb 2(%esi), %al
 1834 movb %al, 2(%edi)
 183512: movw (%esi), %ax
 1836 movw %ax, (%edi)
 1837 jmp .Lback_aligned
 183811: movb (%esi), %al
 1839 movb %al, (%edi)
 1840 jmp .Lback_aligned
 1841#endif
 1842 /* End of copy kernel */
 1843.Lcopy_done:
 1844 cld /* LynxOS depends on it */
 1845
 1846 /* load current selfreloc_start addesss in $edi */
 1847 movl %ebx, %edi /* loadaddr was saved in ebx */
 1848 addl $(selfreloc_start - kernel_text), %edi
 1849
 1850 /* Prepare jump address */
 1851 lea (selfreloc_start32a - selfreloc_start)(%edi), %eax
 1852 movl %eax, (selfreloc_start32r - selfreloc_start)(%edi)
 1853
 1854 /* Setup GDT */
 1855 lea (gdt - selfreloc_start)(%edi), %eax
 1856 mov %eax, (gdtrr - selfreloc_start)(%edi)
 1857 lgdt (gdtr - selfreloc_start)(%edi)
 1858
 1859 /* Jump to set %cs */
 1860 ljmp *(selfreloc_start32r - selfreloc_start)(%edi)
 1861
 1862 .align 4
 1863selfreloc_start32a:
 1864 movl $0x10, %eax /* #define DATA_SEGMENT 0x10 */
 1865 movw %ax, %ds
 1866 movw %ax, %es
 1867 movw %ax, %fs
 1868 movw %ax, %gs
 1869 movw %ax, %ss
 1870
 1871 /* Disable Paging in CR0 */
 1872 movl %cr0, %eax
 1873 andl $(~CR0_PG), %eax
 1874 movl %eax, %cr0
 1875
 1876 /* Disable PAE in CR4 */
 1877 movl %cr4, %eax
 1878 andl $(~CR4_PAE), %eax
 1879 movl %eax, %cr4
 1880
 1881 jmp selfreloc_start32b
 1882
 1883 .align 4
 1884selfreloc_start32b:
 1885 xor %eax, %eax
 1886 movl $_RELOC(start), %esi
 1887 jmp *%esi
 1888
 1889 .align 16
 1890selfreloc_start32r:
 1891 .long 0
 1892 .long 0x08 /* #define CODE_SEGMENT 0x08 */
 1893 .align 16
 1894gdt:
 1895 .long 0, 0
 1896 .byte 0xff, 0xff, 0x00, 0x00, 0x00, 0x9f, 0xcf, 0x00
 1897 .byte 0xff, 0xff, 0x00, 0x00, 0x00, 0x93, 0xcf, 0x00
 1898gdtr:
 1899 .word gdtr - gdt
 1900gdtrr:
 1901 .quad
 1902END(selfreloc_start)

cvs diff -r1.21 -r1.22 src/sys/arch/i386/stand/efiboot/boot.c (expand / switch to unified diff)

--- src/sys/arch/i386/stand/efiboot/boot.c 2022/06/08 21:43:45 1.21
+++ src/sys/arch/i386/stand/efiboot/boot.c 2023/04/20 00:42:24 1.22
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: boot.c,v 1.21 2022/06/08 21:43:45 wiz Exp $ */ 1/* $NetBSD: boot.c,v 1.22 2023/04/20 00:42:24 manu Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2016 Kimihiro Nonaka <nonaka@netbsd.org> 4 * Copyright (c) 2016 Kimihiro Nonaka <nonaka@netbsd.org>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -73,52 +73,54 @@ void command_root(char *); @@ -73,52 +73,54 @@ void command_root(char *);
73void command_dev(char *); 73void command_dev(char *);
74void command_devpath(char *); 74void command_devpath(char *);
75void command_efivar(char *); 75void command_efivar(char *);
76void command_gop(char *); 76void command_gop(char *);
77#if LIBSA_ENABLE_LS_OP 77#if LIBSA_ENABLE_LS_OP
78void command_ls(char *); 78void command_ls(char *);
79#endif 79#endif
80void command_memmap(char *); 80void command_memmap(char *);
81#ifndef SMALL 81#ifndef SMALL
82void command_menu(char *); 82void command_menu(char *);
83#endif 83#endif
84void command_modules(char *); 84void command_modules(char *);
85void command_multiboot(char *); 85void command_multiboot(char *);
 86void command_reloc(char *);
86void command_text(char *); 87void command_text(char *);
87void command_version(char *); 88void command_version(char *);
88 89
89const struct bootblk_command commands[] = { 90const struct bootblk_command commands[] = {
90 { "help", command_help }, 91 { "help", command_help },
91 { "?", command_help }, 92 { "?", command_help },
92 { "quit", command_quit }, 93 { "quit", command_quit },
93 { "boot", command_boot }, 94 { "boot", command_boot },
94 { "pkboot", command_pkboot }, 95 { "pkboot", command_pkboot },
95 { "consdev", command_consdev }, 96 { "consdev", command_consdev },
96 { "root", command_root }, 97 { "root", command_root },
97 { "dev", command_dev }, 98 { "dev", command_dev },
98 { "devpath", command_devpath }, 99 { "devpath", command_devpath },
99 { "efivar", command_efivar }, 100 { "efivar", command_efivar },
100 { "fs", fs_add }, 101 { "fs", fs_add },
101 { "gop", command_gop }, 102 { "gop", command_gop },
102 { "load", module_add }, 103 { "load", module_add },
103#if LIBSA_ENABLE_LS_OP 104#if LIBSA_ENABLE_LS_OP
104 { "ls", command_ls }, 105 { "ls", command_ls },
105#endif 106#endif
106 { "memmap", command_memmap }, 107 { "memmap", command_memmap },
107#ifndef SMALL 108#ifndef SMALL
108 { "menu", command_menu }, 109 { "menu", command_menu },
109#endif 110#endif
110 { "modules", command_modules }, 111 { "modules", command_modules },
111 { "multiboot", command_multiboot }, 112 { "multiboot", command_multiboot },
 113 { "reloc", command_reloc },
112 { "rndseed", rnd_add }, 114 { "rndseed", rnd_add },
113 { "splash", splash_add }, 115 { "splash", splash_add },
114 { "text", command_text }, 116 { "text", command_text },
115 { "userconf", userconf_add }, 117 { "userconf", userconf_add },
116 { "version", command_version }, 118 { "version", command_version },
117 { NULL, NULL }, 119 { NULL, NULL },
118}; 120};
119 121
120static char *default_fsname; 122static char *default_fsname;
121static char *default_devname; 123static char *default_devname;
122static int default_unit, default_partition; 124static int default_unit, default_partition;
123static const char *default_filename; 125static const char *default_filename;
124static const char *default_part_name; 126static const char *default_part_name;
@@ -396,26 +398,27 @@ command_help(char *arg) @@ -396,26 +398,27 @@ command_help(char *arg)
396 "devpath\n" 398 "devpath\n"
397 "efivar\n" 399 "efivar\n"
398 "gop [{modenum|list}]\n" 400 "gop [{modenum|list}]\n"
399 "load {path_to_module}\n" 401 "load {path_to_module}\n"
400#if LIBSA_ENABLE_LS_OP 402#if LIBSA_ENABLE_LS_OP
401 "ls [dev:][path]\n" 403 "ls [dev:][path]\n"
402#endif 404#endif
403 "memmap [{sorted|unsorted|compact}]\n" 405 "memmap [{sorted|unsorted|compact}]\n"
404#ifndef SMALL 406#ifndef SMALL
405 "menu (reenters boot menu, if defined in boot.cfg)\n" 407 "menu (reenters boot menu, if defined in boot.cfg)\n"
406#endif 408#endif
407 "modules {on|off|enabled|disabled}\n" 409 "modules {on|off|enabled|disabled}\n"
408 "multiboot [dev:][filename] [<args>]\n" 410 "multiboot [dev:][filename] [<args>]\n"
 411 "reloc {address|none|default}\n"
409 "rndseed {path_to_rndseed_file}\n" 412 "rndseed {path_to_rndseed_file}\n"
410 "splash {path_to_image_file}\n" 413 "splash {path_to_image_file}\n"
411 "text [{modenum|list}]\n" 414 "text [{modenum|list}]\n"
412 "userconf {command}\n" 415 "userconf {command}\n"
413 "version\n" 416 "version\n"
414 "help|?\n" 417 "help|?\n"
415 "quit\n"); 418 "quit\n");
416} 419}
417 420
418#if LIBSA_ENABLE_LS_OP 421#if LIBSA_ENABLE_LS_OP
419void 422void
420command_ls(char *arg) 423command_ls(char *arg)
421{ 424{
@@ -631,26 +634,68 @@ void @@ -631,26 +634,68 @@ void
631command_multiboot(char *arg) 634command_multiboot(char *arg)
632{ 635{
633 char *filename; 636 char *filename;
634 637
635 filename = arg; 638 filename = arg;
636 if (exec_multiboot(filename, gettrailer(arg)) < 0) 639 if (exec_multiboot(filename, gettrailer(arg)) < 0)
637 printf("multiboot: %s: %s\n", sprint_bootsel(filename), 640 printf("multiboot: %s: %s\n", sprint_bootsel(filename),
638 strerror(errno)); 641 strerror(errno));
639 else 642 else
640 printf("boot returned\n"); 643 printf("boot returned\n");
641} 644}
642 645
643void 646void
 647command_reloc(char *arg)
 648{
 649 char *ep;
 650
 651 if (*arg == '\0') {
 652 switch (efi_reloc_type) {
 653 case RELOC_NONE:
 654 printf("reloc: none\n");
 655 break;
 656 case RELOC_ADDR:
 657 printf("reloc: %p\n", (void *)efi_kernel_reloc);
 658 break;
 659 case RELOC_DEFAULT:
 660 default:
 661 printf("reloc: default\n");
 662 break;
 663 }
 664 goto out;
 665 }
 666
 667 if (strcmp(arg, "default") == 0) {
 668 efi_reloc_type = RELOC_DEFAULT;
 669 goto out;
 670 }
 671
 672 if (strcmp(arg, "none") == 0) {
 673 efi_reloc_type = RELOC_NONE;
 674 goto out;
 675 }
 676
 677 errno = 0;
 678 efi_kernel_reloc = strtoul(arg, &ep, 0);
 679 if (ep == arg || *ep != '\0' || errno)
 680 printf("could not parse address \"%s\"\n", arg);
 681 else
 682 efi_reloc_type = RELOC_ADDR;
 683out:
 684 return;
 685
 686}
 687
 688void
644command_version(char *arg) 689command_version(char *arg)
645{ 690{
646 CHAR16 *path; 691 CHAR16 *path;
647 char *upath, *ufirmware; 692 char *upath, *ufirmware;
648 int rv; 693 int rv;
649 694
650 if (strcmp(arg, "full") == 0) { 695 if (strcmp(arg, "full") == 0) {
651 printf("ImageBase: 0x%" PRIxPTR "\n", 696 printf("ImageBase: 0x%" PRIxPTR "\n",
652 (uintptr_t)efi_li->ImageBase); 697 (uintptr_t)efi_li->ImageBase);
653 printf("Stack: 0x%" PRIxPTR "\n", efi_main_sp); 698 printf("Stack: 0x%" PRIxPTR "\n", efi_main_sp);
654 printf("EFI version: %d.%02d\n", 699 printf("EFI version: %d.%02d\n",
655 ST->Hdr.Revision >> 16, ST->Hdr.Revision & 0xffff); 700 ST->Hdr.Revision >> 16, ST->Hdr.Revision & 0xffff);
656 ufirmware = NULL; 701 ufirmware = NULL;

cvs diff -r1.12 -r1.13 src/sys/arch/i386/stand/efiboot/efiboot.c (expand / switch to unified diff)

--- src/sys/arch/i386/stand/efiboot/efiboot.c 2020/02/09 12:13:39 1.12
+++ src/sys/arch/i386/stand/efiboot/efiboot.c 2023/04/20 00:42:24 1.13
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: efiboot.c,v 1.12 2020/02/09 12:13:39 jmcneill Exp $ */ 1/* $NetBSD: efiboot.c,v 1.13 2023/04/20 00:42:24 manu Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2016 Kimihiro Nonaka <nonaka@netbsd.org> 4 * Copyright (c) 2016 Kimihiro Nonaka <nonaka@netbsd.org>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -26,27 +26,29 @@ @@ -26,27 +26,29 @@
26 * SUCH DAMAGE. 26 * SUCH DAMAGE.
27 */ 27 */
28 28
29#include "efiboot.h" 29#include "efiboot.h"
30 30
31#include "bootinfo.h" 31#include "bootinfo.h"
32#include "devopen.h" 32#include "devopen.h"
33 33
34EFI_HANDLE IH; 34EFI_HANDLE IH;
35EFI_DEVICE_PATH *efi_bootdp; 35EFI_DEVICE_PATH *efi_bootdp;
36enum efi_boot_device_type efi_bootdp_type = BOOT_DEVICE_TYPE_HD; 36enum efi_boot_device_type efi_bootdp_type = BOOT_DEVICE_TYPE_HD;
37EFI_LOADED_IMAGE *efi_li; 37EFI_LOADED_IMAGE *efi_li;
38uintptr_t efi_main_sp; 38uintptr_t efi_main_sp;
39physaddr_t efi_loadaddr, efi_kernel_start; 39physaddr_t efi_loadaddr, efi_kernel_start, efi_load_start;
 40physaddr_t efi_kernel_reloc = 0;
 41enum efi_reloc_type efi_reloc_type = RELOC_DEFAULT;
40u_long efi_kernel_size; 42u_long efi_kernel_size;
41bool efi_cleanuped; 43bool efi_cleanuped;
42struct btinfo_efimemmap *btinfo_efimemmap = NULL; 44struct btinfo_efimemmap *btinfo_efimemmap = NULL;
43 45
44static EFI_PHYSICAL_ADDRESS heap_start = EFI_ALLOCATE_MAX_ADDRESS; 46static EFI_PHYSICAL_ADDRESS heap_start = EFI_ALLOCATE_MAX_ADDRESS;
45static UINTN heap_size = 1 * 1024 * 1024; /* 1MB */ 47static UINTN heap_size = 1 * 1024 * 1024; /* 1MB */
46static struct btinfo_efi btinfo_efi; 48static struct btinfo_efi btinfo_efi;
47 49
48static void efi_heap_init(void); 50static void efi_heap_init(void);
49 51
50EFI_STATUS EFIAPI efi_main(EFI_HANDLE, EFI_SYSTEM_TABLE *); 52EFI_STATUS EFIAPI efi_main(EFI_HANDLE, EFI_SYSTEM_TABLE *);
51EFI_STATUS EFIAPI 53EFI_STATUS EFIAPI
52efi_main(EFI_HANDLE imageHandle, EFI_SYSTEM_TABLE *systemTable) 54efi_main(EFI_HANDLE imageHandle, EFI_SYSTEM_TABLE *systemTable)

cvs diff -r1.11 -r1.12 src/sys/arch/i386/stand/efiboot/efiboot.h (expand / switch to unified diff)

--- src/sys/arch/i386/stand/efiboot/efiboot.h 2021/09/07 11:41:31 1.11
+++ src/sys/arch/i386/stand/efiboot/efiboot.h 2023/04/20 00:42:24 1.12
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: efiboot.h,v 1.11 2021/09/07 11:41:31 nia Exp $ */ 1/* $NetBSD: efiboot.h,v 1.12 2023/04/20 00:42:24 manu Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2016 Kimihiro Nonaka <nonaka@netbsd.org> 4 * Copyright (c) 2016 Kimihiro Nonaka <nonaka@netbsd.org>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -42,27 +42,33 @@ extern EFI_GUID GraphicsOutputProtocol; @@ -42,27 +42,33 @@ extern EFI_GUID GraphicsOutputProtocol;
42void boot(void); 42void boot(void);
43void clearit(void); 43void clearit(void);
44 44
45/* efiboot.c */ 45/* efiboot.c */
46extern EFI_HANDLE IH; 46extern EFI_HANDLE IH;
47extern EFI_DEVICE_PATH *efi_bootdp; 47extern EFI_DEVICE_PATH *efi_bootdp;
48extern enum efi_boot_device_type { 48extern enum efi_boot_device_type {
49 BOOT_DEVICE_TYPE_HD, 49 BOOT_DEVICE_TYPE_HD,
50 BOOT_DEVICE_TYPE_CD, 50 BOOT_DEVICE_TYPE_CD,
51 BOOT_DEVICE_TYPE_NET 51 BOOT_DEVICE_TYPE_NET
52} efi_bootdp_type; 52} efi_bootdp_type;
53extern EFI_LOADED_IMAGE *efi_li; 53extern EFI_LOADED_IMAGE *efi_li;
54extern uintptr_t efi_main_sp; 54extern uintptr_t efi_main_sp;
55extern physaddr_t efi_loadaddr, efi_kernel_start; 55extern physaddr_t efi_loadaddr, efi_kernel_start, efi_load_start;
 56extern physaddr_t efi_kernel_reloc;
 57extern enum efi_reloc_type {
 58 RELOC_DEFAULT,
 59 RELOC_NONE,
 60 RELOC_ADDR,
 61} efi_reloc_type;
56extern u_long efi_kernel_size; 62extern u_long efi_kernel_size;
57extern bool efi_cleanuped; 63extern bool efi_cleanuped;
58void efi_cleanup(void); 64void efi_cleanup(void);
59 65
60/* efichar.c */ 66/* efichar.c */
61size_t ucs2len(const CHAR16 *); 67size_t ucs2len(const CHAR16 *);
62int ucs2_to_utf8(const CHAR16 *, char **); 68int ucs2_to_utf8(const CHAR16 *, char **);
63int utf8_to_ucs2(const char *, CHAR16 **, size_t *); 69int utf8_to_ucs2(const char *, CHAR16 **, size_t *);
64 70
65/* eficons.c */ 71/* eficons.c */
66int cninit(void); 72int cninit(void);
67void efi_consinit(int, int, int); 73void efi_consinit(int, int, int);
68void efi_cons_show(void); 74void efi_cons_show(void);

cvs diff -r1.5 -r1.6 src/sys/arch/i386/stand/efiboot/bootia32/efibootia32.c (expand / switch to unified diff)

--- src/sys/arch/i386/stand/efiboot/bootia32/efibootia32.c 2019/09/13 02:19:45 1.5
+++ src/sys/arch/i386/stand/efiboot/bootia32/efibootia32.c 2023/04/20 00:42:24 1.6
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: efibootia32.c,v 1.5 2019/09/13 02:19:45 manu Exp $ */ 1/* $NetBSD: efibootia32.c,v 1.6 2023/04/20 00:42:24 manu Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2016 Kimihiro Nonaka <nonaka@netbsd.org> 4 * Copyright (c) 2016 Kimihiro Nonaka <nonaka@netbsd.org>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -66,23 +66,23 @@ efi_md_init(void) @@ -66,23 +66,23 @@ efi_md_init(void)
66 __func__, sz, (uintmax_t)status); 66 __func__, sz, (uintmax_t)status);
67 multiboot32 = (void *)(u_long)addr; 67 multiboot32 = (void *)(u_long)addr;
68 CopyMem(multiboot32, multiboot32_start, multiboot32_size); 68 CopyMem(multiboot32, multiboot32_start, multiboot32_size);
69 69
70} 70}
71 71
72/* ARGSUSED */ 72/* ARGSUSED */
73void 73void
74startprog(physaddr_t entry, uint32_t argc, uint32_t *argv, physaddr_t sp) 74startprog(physaddr_t entry, uint32_t argc, uint32_t *argv, physaddr_t sp)
75{ 75{
76 76
77 (*startprog32)(entry, argc, argv, 77 (*startprog32)(entry, argc, argv,
78 (physaddr_t)startprog32 + startprog32_size, 78 (physaddr_t)startprog32 + startprog32_size,
79 efi_kernel_start, efi_kernel_start + efi_loadaddr, 79 efi_kernel_start, efi_load_start,
80 efi_kernel_size, startprog32); 80 efi_kernel_size, startprog32);
81} 81}
82 82
83/* ARGSUSED */ 83/* ARGSUSED */
84void 84void
85multiboot(physaddr_t entry, physaddr_t header, physaddr_t sp, uint32_t magic) 85multiboot(physaddr_t entry, physaddr_t header, physaddr_t sp, uint32_t magic)
86{ 86{
87 (*multiboot32)(entry, header, magic); 87 (*multiboot32)(entry, header, magic);
88} 88}

cvs diff -r1.2 -r1.3 src/sys/arch/i386/stand/efiboot/bootia32/startprog32.S (expand / switch to unified diff)

--- src/sys/arch/i386/stand/efiboot/bootia32/startprog32.S 2017/02/24 12:24:25 1.2
+++ src/sys/arch/i386/stand/efiboot/bootia32/startprog32.S 2023/04/20 00:42:24 1.3
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: startprog32.S,v 1.2 2017/02/24 12:24:25 nonaka Exp $ */ 1/* $NetBSD: startprog32.S,v 1.3 2023/04/20 00:42:24 manu Exp $ */
2/* NetBSD: startprog.S,v 1.4 2016/12/04 08:21:08 maxv Exp */ 2/* NetBSD: startprog.S,v 1.4 2016/12/04 08:21:08 maxv Exp */
3 3
4/* 4/*
5 * Ported to boot 386BSD by Julian Elischer (julian@tfs.com) Sept 1992 5 * Ported to boot 386BSD by Julian Elischer (julian@tfs.com) Sept 1992
6 * 6 *
7 * Mach Operating System 7 * Mach Operating System
8 * Copyright (c) 1992, 1991 Carnegie Mellon University 8 * Copyright (c) 1992, 1991 Carnegie Mellon University
9 * All Rights Reserved. 9 * All Rights Reserved.
10 * 10 *
11 * Permission to use, copy, modify and distribute this software and its 11 * Permission to use, copy, modify and distribute this software and its
12 * documentation is hereby granted, provided that both the copyright 12 * documentation is hereby granted, provided that both the copyright
13 * notice and this permission notice appear in all copies of the 13 * notice and this permission notice appear in all copies of the
14 * software, derivative works or modified versions, and any portions 14 * software, derivative works or modified versions, and any portions
@@ -107,26 +107,31 @@ start: @@ -107,26 +107,31 @@ start:
107 addl 16(%ebp), %eax /* ptr to last arg */ 107 addl 16(%ebp), %eax /* ptr to last arg */
108 movl %eax, %esi 108 movl %eax, %esi
109 109
110 std /* backwards */ 110 std /* backwards */
111 rep 111 rep
112 movsl /* copy %ds:(%esi) -> %es:(%edi) */ 112 movsl /* copy %ds:(%esi) -> %es:(%edi) */
113 cld 113 cld
114 mov %edi, %esp /* set new stack pointer */ 114 mov %edi, %esp /* set new stack pointer */
115 115
116 /* Copy kernel */ 116 /* Copy kernel */
117 movl 24(%ebp), %edi /* dest */ 117 movl 24(%ebp), %edi /* dest */
118 movl 28(%ebp), %esi /* src */ 118 movl 28(%ebp), %esi /* src */
119 movl 32(%ebp), %ecx /* size */ 119 movl 32(%ebp), %ecx /* size */
 120
 121 /* skip copy if same source and destination */
 122 cmpl %edi,%esi
 123 jz .Lcopy_done
 124
120#if defined(NO_OVERLAP) 125#if defined(NO_OVERLAP)
121 movl %ecx, %eax 126 movl %ecx, %eax
122#else 127#else
123 movl %edi, %eax 128 movl %edi, %eax
124 subl %esi, %eax 129 subl %esi, %eax
125 cmpl %ecx, %eax /* overlapping? */ 130 cmpl %ecx, %eax /* overlapping? */
126 movl %ecx, %eax 131 movl %ecx, %eax
127 jb .Lbackwards 132 jb .Lbackwards
128#endif 133#endif
129 /* nope, copy forwards. */ 134 /* nope, copy forwards. */
130 shrl $2, %ecx /* copy by words */ 135 shrl $2, %ecx /* copy by words */
131 rep 136 rep
132 movsl 137 movsl

cvs diff -r1.5 -r1.6 src/sys/arch/i386/stand/efiboot/bootx64/efibootx64.c (expand / switch to unified diff)

--- src/sys/arch/i386/stand/efiboot/bootx64/efibootx64.c 2019/09/13 02:19:46 1.5
+++ src/sys/arch/i386/stand/efiboot/bootx64/efibootx64.c 2023/04/20 00:42:24 1.6
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: efibootx64.c,v 1.5 2019/09/13 02:19:46 manu Exp $ */ 1/* $NetBSD: efibootx64.c,v 1.6 2023/04/20 00:42:24 manu Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2016 Kimihiro Nonaka <nonaka@netbsd.org> 4 * Copyright (c) 2016 Kimihiro Nonaka <nonaka@netbsd.org>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -70,23 +70,23 @@ efi_md_init(void) @@ -70,23 +70,23 @@ efi_md_init(void)
70 70
71/* ARGSUSED */ 71/* ARGSUSED */
72void 72void
73startprog(physaddr_t entry, uint32_t argc, uint32_t *argv, physaddr_t sp) 73startprog(physaddr_t entry, uint32_t argc, uint32_t *argv, physaddr_t sp)
74{ 74{
75 uint32_t *newsp = (void *)((char *)startprog64 + startprog64_size); 75 uint32_t *newsp = (void *)((char *)startprog64 + startprog64_size);
76 76
77 /* Copy argv to new stack pointer */ 77 /* Copy argv to new stack pointer */
78 if (argc > 0) { 78 if (argc > 0) {
79 newsp -= argc; 79 newsp -= argc;
80 memcpy(newsp, argv, sizeof(*argv) * argc); 80 memcpy(newsp, argv, sizeof(*argv) * argc);
81 } 81 }
82 82
83 (*startprog64)(efi_kernel_start, efi_kernel_start + efi_loadaddr, 83 (*startprog64)(efi_kernel_start, efi_load_start,
84 (physaddr_t)newsp, efi_kernel_size, startprog64, entry); 84 (physaddr_t)newsp, efi_kernel_size, startprog64, entry);
85} 85}
86 86
87/* ARGSUSED */ 87/* ARGSUSED */
88void 88void
89multiboot(physaddr_t entry, physaddr_t header, physaddr_t sp, uint32_t magic) 89multiboot(physaddr_t entry, physaddr_t header, physaddr_t sp, uint32_t magic)
90{ 90{
91 (*multiboot64)(entry, header, magic); 91 (*multiboot64)(entry, header, magic);
92} 92}

cvs diff -r1.3 -r1.4 src/sys/arch/i386/stand/efiboot/bootx64/startprog64.S (expand / switch to unified diff)

--- src/sys/arch/i386/stand/efiboot/bootx64/startprog64.S 2017/02/11 10:23:39 1.3
+++ src/sys/arch/i386/stand/efiboot/bootx64/startprog64.S 2023/04/20 00:42:24 1.4
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: startprog64.S,v 1.3 2017/02/11 10:23:39 nonaka Exp $ */ 1/* $NetBSD: startprog64.S,v 1.4 2023/04/20 00:42:24 manu Exp $ */
2/* NetBSD: startprog.S,v 1.3 2003/02/01 14:48:18 dsl Exp */ 2/* NetBSD: startprog.S,v 1.3 2003/02/01 14:48:18 dsl Exp */
3 3
4/* starts program in protected mode / flat space 4/* starts program in protected mode / flat space
5 with given stackframe 5 with given stackframe
6 needs global variables flatcodeseg and flatdataseg 6 needs global variables flatcodeseg and flatdataseg
7 (gdt offsets) 7 (gdt offsets)
8 derived from: NetBSD:sys/arch/i386/boot/asm.S 8 derived from: NetBSD:sys/arch/i386/boot/asm.S
9 */ 9 */
10 10
11/* 11/*
12 * Ported to boot 386BSD by Julian Elischer (julian@tfs.com) Sept 1992 12 * Ported to boot 386BSD by Julian Elischer (julian@tfs.com) Sept 1992
13 * 13 *
14 * Mach Operating System 14 * Mach Operating System
@@ -87,26 +87,30 @@ start: @@ -87,26 +87,30 @@ start:
87 * 32bit segment mode from x64 mode. 87 * 32bit segment mode from x64 mode.
88 * %rdi: kernel start address 88 * %rdi: kernel start address
89 * %rsi: loaded kernel address 89 * %rsi: loaded kernel address
90 * %rdx: stack address 90 * %rdx: stack address
91 * %rcx: loaded kernel size 91 * %rcx: loaded kernel size
92 * %r8 : loaded start address 92 * %r8 : loaded start address
93 * %r9 : kernel entry address 93 * %r9 : kernel entry address
94 */ 94 */
95 95
96 cld /* LynxOS depends on it */ 96 cld /* LynxOS depends on it */
97 97
98 cli 98 cli
99 99
 100 /* skip copy if same source and destination */
 101 cmpq %rdi,%rsi
 102 jz .Lcopy_done
 103
100 /* Copy kernel */ 104 /* Copy kernel */
101 mov %rcx, %r12 /* original kernel size */ 105 mov %rcx, %r12 /* original kernel size */
102 movq %rdi, %r11 /* for misaligned check */ 106 movq %rdi, %r11 /* for misaligned check */
103 107
104#if !defined(NO_OVERLAP) 108#if !defined(NO_OVERLAP)
105 movq %rdi, %r13 109 movq %rdi, %r13
106 subq %rsi, %r13 110 subq %rsi, %r13
107#endif 111#endif
108 112
109 shrq $3, %rcx /* count for copy by words */ 113 shrq $3, %rcx /* count for copy by words */
110 jz 8f /* j if less than 8 bytes */ 114 jz 8f /* j if less than 8 bytes */
111 115
112 lea -8(%rdi, %r12), %r14 /* target address of last 8 */ 116 lea -8(%rdi, %r12), %r14 /* target address of last 8 */

cvs diff -r1.78 -r1.79 src/sys/arch/i386/stand/lib/exec.c (expand / switch to unified diff)

--- src/sys/arch/i386/stand/lib/exec.c 2022/09/21 14:29:45 1.78
+++ src/sys/arch/i386/stand/lib/exec.c 2023/04/20 00:42:24 1.79
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: exec.c,v 1.78 2022/09/21 14:29:45 riastradh Exp $ */ 1/* $NetBSD: exec.c,v 1.79 2023/04/20 00:42:24 manu Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. 4 * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -455,26 +455,27 @@ common_load_kernel(const char *file, u_l @@ -455,26 +455,27 @@ common_load_kernel(const char *file, u_l
455 455
456 return 0; 456 return 0;
457} 457}
458 458
459int 459int
460exec_netbsd(const char *file, physaddr_t loadaddr, int boothowto, int floppy, 460exec_netbsd(const char *file, physaddr_t loadaddr, int boothowto, int floppy,
461 void (*callback)(void)) 461 void (*callback)(void))
462{ 462{
463 uint32_t boot_argv[BOOT_NARGS]; 463 uint32_t boot_argv[BOOT_NARGS];
464 u_long marks[MARK_MAX]; 464 u_long marks[MARK_MAX];
465 struct btinfo_symtab btinfo_symtab; 465 struct btinfo_symtab btinfo_symtab;
466 u_long extmem; 466 u_long extmem;
467 u_long basemem; 467 u_long basemem;
 468 u_long entry;
468 int error; 469 int error;
469#ifdef EFIBOOT 470#ifdef EFIBOOT
470 int i; 471 int i;
471#endif 472#endif
472 473
473#ifdef DEBUG 474#ifdef DEBUG
474 printf("exec: file=%s loadaddr=0x%lx\n", file ? file : "NULL", 475 printf("exec: file=%s loadaddr=0x%lx\n", file ? file : "NULL",
475 loadaddr); 476 loadaddr);
476#endif 477#endif
477 478
478 BI_ALLOC(BTINFO_MAX); 479 BI_ALLOC(BTINFO_MAX);
479 480
480 BI_ADD(&btinfo_console, BTINFO_CONSOLE, sizeof(struct btinfo_console)); 481 BI_ADD(&btinfo_console, BTINFO_CONSOLE, sizeof(struct btinfo_console));
@@ -487,26 +488,28 @@ exec_netbsd(const char *file, physaddr_t @@ -487,26 +488,28 @@ exec_netbsd(const char *file, physaddr_t
487 488
488 if (has_prekern) { 489 if (has_prekern) {
489 error = common_load_prekern(file, &basemem, &extmem, loadaddr, 490 error = common_load_prekern(file, &basemem, &extmem, loadaddr,
490 floppy, marks); 491 floppy, marks);
491 } else { 492 } else {
492 error = common_load_kernel(file, &basemem, &extmem, loadaddr, 493 error = common_load_kernel(file, &basemem, &extmem, loadaddr,
493 floppy, marks); 494 floppy, marks);
494 } 495 }
495 if (error) { 496 if (error) {
496 errno = error; 497 errno = error;
497 goto out; 498 goto out;
498 } 499 }
499#ifdef EFIBOOT 500#ifdef EFIBOOT
 501 efi_load_start = marks[MARK_START];
 502
500 /* adjust to the real load address */ 503 /* adjust to the real load address */
501 marks[MARK_START] -= efi_loadaddr; 504 marks[MARK_START] -= efi_loadaddr;
502 marks[MARK_ENTRY] -= efi_loadaddr; 505 marks[MARK_ENTRY] -= efi_loadaddr;
503 marks[MARK_DATA] -= efi_loadaddr; 506 marks[MARK_DATA] -= efi_loadaddr;
504 /* MARK_NSYM */ 507 /* MARK_NSYM */
505 marks[MARK_SYM] -= efi_loadaddr; 508 marks[MARK_SYM] -= efi_loadaddr;
506 marks[MARK_END] -= efi_loadaddr; 509 marks[MARK_END] -= efi_loadaddr;
507#endif 510#endif
508 511
509 boot_argv[0] = boothowto; 512 boot_argv[0] = boothowto;
510 boot_argv[1] = 0; 513 boot_argv[1] = 0;
511 boot_argv[2] = vtophys(bootinfo); /* old cyl offset */ 514 boot_argv[2] = vtophys(bootinfo); /* old cyl offset */
512 boot_argv[3] = marks[MARK_END]; 515 boot_argv[3] = marks[MARK_END];
@@ -542,39 +545,55 @@ exec_netbsd(const char *file, physaddr_t @@ -542,39 +545,55 @@ exec_netbsd(const char *file, physaddr_t
542 545
543 btinfo_symtab.nsym = marks[MARK_NSYM]; 546 btinfo_symtab.nsym = marks[MARK_NSYM];
544 btinfo_symtab.ssym = marks[MARK_SYM]; 547 btinfo_symtab.ssym = marks[MARK_SYM];
545 btinfo_symtab.esym = marks[MARK_END]; 548 btinfo_symtab.esym = marks[MARK_END];
546 BI_ADD(&btinfo_symtab, BTINFO_SYMTAB, sizeof(struct btinfo_symtab)); 549 BI_ADD(&btinfo_symtab, BTINFO_SYMTAB, sizeof(struct btinfo_symtab));
547 550
548 /* set new video mode if necessary */ 551 /* set new video mode if necessary */
549 vbe_commit(); 552 vbe_commit();
550 BI_ADD(&btinfo_framebuffer, BTINFO_FRAMEBUFFER, 553 BI_ADD(&btinfo_framebuffer, BTINFO_FRAMEBUFFER,
551 sizeof(struct btinfo_framebuffer)); 554 sizeof(struct btinfo_framebuffer));
552 555
553 if (callback != NULL) 556 if (callback != NULL)
554 (*callback)(); 557 (*callback)();
 558
 559 entry = marks[MARK_ENTRY];
555#ifdef EFIBOOT 560#ifdef EFIBOOT
556 /* Copy bootinfo to safe arena. */ 561 /* Copy bootinfo to safe arena. */
557 for (i = 0; i < bootinfo->nentries; i++) { 562 for (i = 0; i < bootinfo->nentries; i++) {
558 struct btinfo_common *bi = (void *)(u_long)bootinfo->entry[i]; 563 struct btinfo_common *bi = (void *)(u_long)bootinfo->entry[i];
559 char *p = alloc(bi->len); 564 char *p = alloc(bi->len);
560 memcpy(p, bi, bi->len); 565 memcpy(p, bi, bi->len);
561 bootinfo->entry[i] = vtophys(p); 566 bootinfo->entry[i] = vtophys(p);
562 } 567 }
563 568
564 efi_kernel_start = marks[MARK_START]; 569 efi_kernel_start = marks[MARK_START];
565 efi_kernel_size = image_end - (efi_loadaddr + efi_kernel_start); 570 efi_kernel_size = image_end - (efi_loadaddr + efi_kernel_start);
 571
 572 switch (efi_reloc_type) {
 573 case RELOC_NONE:
 574 entry += (efi_load_start - efi_kernel_start);
 575 efi_kernel_start = efi_load_start;
 576 break;
 577 case RELOC_ADDR:
 578 entry += (efi_kernel_reloc - efi_kernel_start);
 579 efi_kernel_start = efi_kernel_reloc;
 580 break;
 581 case RELOC_DEFAULT:
 582 default:
 583 break;
 584 }
566#endif 585#endif
567 startprog(marks[MARK_ENTRY], BOOT_NARGS, boot_argv, 586 startprog(entry, BOOT_NARGS, boot_argv,
568 x86_trunc_page(basemem * 1024)); 587 x86_trunc_page(basemem * 1024));
569 panic("exec returned"); 588 panic("exec returned");
570 589
571out: 590out:
572 BI_FREE(); 591 BI_FREE();
573 bootinfo = NULL; 592 bootinfo = NULL;
574 return -1; 593 return -1;
575} 594}
576 595
577static void 596static void
578extract_device(const char *path, char *buf, size_t buflen) 597extract_device(const char *path, char *buf, size_t buflen)
579{ 598{
580 size_t i; 599 size_t i;