Module Name: src Committed By: martin Date: Sat May 13 11:45:54 UTC 2023
Modified Files: src/share/man/man4 [netbsd-9]: options.4 src/share/man/man8/man8.x86 [netbsd-9]: boot.8 dosboot.8 pxeboot.8 src/sys/arch/amd64/amd64 [netbsd-9]: locore.S src/sys/arch/amd64/conf [netbsd-9]: files.amd64 std.amd64 src/sys/arch/i386/stand/efiboot [netbsd-9]: boot.c efiboot.c efiboot.h version src/sys/arch/i386/stand/efiboot/bootia32 [netbsd-9]: efibootia32.c startprog32.S src/sys/arch/i386/stand/efiboot/bootx64 [netbsd-9]: efibootx64.c startprog64.S src/sys/arch/i386/stand/lib [netbsd-9]: exec.c Log Message: Pull up following revision(s) (requested by manu in ticket #1632): share/man/man8/man8.x86/boot.8: revision 1.27 sys/arch/i386/stand/efiboot/version: revision 1.3 share/man/man8/man8.x86/boot.8: revision 1.28 (via patch) share/man/man8/man8.x86/boot.8: revision 1.29 (via patch) sys/arch/i386/stand/lib/exec.c: revision 1.79 sys/arch/i386/stand/efiboot/efiboot.c: revision 1.13 sys/arch/i386/stand/efiboot/bootx64/efibootx64.c: revision 1.6 sys/arch/i386/stand/efiboot/bootia32/efibootia32.c: revision 1.6 sys/arch/i386/stand/efiboot/boot.c: revision 1.22 sys/arch/amd64/amd64/locore.S: revision 1.219 sys/arch/i386/stand/efiboot/bootia32/startprog32.S: revision 1.3 sys/arch/i386/stand/efiboot/efiboot.h: revision 1.12 sys/arch/amd64/conf/files.amd64: revision 1.121 sys/arch/amd64/conf/std.amd64: revision 1.13 share/man/man8/man8.x86/pxeboot.8: revision 1.6 sys/arch/i386/stand/efiboot/bootx64/startprog64.S: revision 1.4 sys/arch/amd64/amd64/locore.S: revision 1.220 share/man/man8/man8.x86/dosboot.8: revision 1.4 share/man/man4/options.4: revision 1.524 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. Merge x86 boot options in x86/boot(8) and add undocumented UEFI options We were supposed to keep the option list in x86/boot(8), x86/dosoot(8) and x86/pxeboot(8) in sync, but it did not happen, hence it may work better with all the options in x86/boot(8). Also add the undocumented UEFI boot options. Add a SELFRELOC kernel option for the sake of documentation clarity. Instead of telling that x86/boot(8) reloc command needs a kernel able to self relocate, we can tell it needs a kernel built with the SELFRELOC option. This keeps the reader from wondering what could make a kernel able to self relocate. Remove XXX todo marker left by mistake Raise the version for new feature (here reloc command) Suggested by Masanobu SAITOH To generate a diff of this commit: cvs rdiff -u -r1.506.2.2 -r1.506.2.3 src/share/man/man4/options.4 cvs rdiff -u -r1.15.2.4 -r1.15.2.5 src/share/man/man8/man8.x86/boot.8 cvs rdiff -u -r1.3 -r1.3.14.1 src/share/man/man8/man8.x86/dosboot.8 cvs rdiff -u -r1.4 -r1.4.14.1 src/share/man/man8/man8.x86/pxeboot.8 cvs rdiff -u -r1.185 -r1.185.2.1 src/sys/arch/amd64/amd64/locore.S cvs rdiff -u -r1.112 -r1.112.4.1 src/sys/arch/amd64/conf/files.amd64 cvs rdiff -u -r1.11 -r1.11.20.1 src/sys/arch/amd64/conf/std.amd64 cvs rdiff -u -r1.13.2.3 -r1.13.2.4 src/sys/arch/i386/stand/efiboot/boot.c cvs rdiff -u -r1.10.2.2 -r1.10.2.3 src/sys/arch/i386/stand/efiboot/efiboot.c cvs rdiff -u -r1.9.2.1 -r1.9.2.2 src/sys/arch/i386/stand/efiboot/efiboot.h cvs rdiff -u -r1.1.26.1 -r1.1.26.2 src/sys/arch/i386/stand/efiboot/version cvs rdiff -u -r1.4.6.1 -r1.4.6.2 \ src/sys/arch/i386/stand/efiboot/bootia32/efibootia32.c cvs rdiff -u -r1.2 -r1.2.26.1 \ src/sys/arch/i386/stand/efiboot/bootia32/startprog32.S cvs rdiff -u -r1.4.6.1 -r1.4.6.2 \ src/sys/arch/i386/stand/efiboot/bootx64/efibootx64.c cvs rdiff -u -r1.3 -r1.3.24.1 \ src/sys/arch/i386/stand/efiboot/bootx64/startprog64.S cvs rdiff -u -r1.73.2.1 -r1.73.2.2 src/sys/arch/i386/stand/lib/exec.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/share/man/man4/options.4 diff -u src/share/man/man4/options.4:1.506.2.2 src/share/man/man4/options.4:1.506.2.3 --- src/share/man/man4/options.4:1.506.2.2 Mon Oct 25 15:47:50 2021 +++ src/share/man/man4/options.4 Sat May 13 11:45:54 2023 @@ -1,4 +1,4 @@ -.\" $NetBSD: options.4,v 1.506.2.2 2021/10/25 15:47:50 martin Exp $ +.\" $NetBSD: options.4,v 1.506.2.3 2023/05/13 11:45:54 martin Exp $ .\" .\" Copyright (c) 1996 .\" Perry E. Metzger. All rights reserved. @@ -1300,6 +1300,14 @@ See and .Xr vnconfig 8 for more information. +.It Cd options SELFRELOC +Make the kernel able to self relocate at bootstrap, so that it can +run whatever its load address is. +This is intented to be used withe the +.Ic reloc +boostrap command documented in +.Xr x86/boot 8 , +to workaround UEFI bugs, and is only available on amd64. .It Cd options SPLDEBUG Help the kernel programmer find bugs related to the interrupt priority level. Index: src/share/man/man8/man8.x86/boot.8 diff -u src/share/man/man8/man8.x86/boot.8:1.15.2.4 src/share/man/man8/man8.x86/boot.8:1.15.2.5 --- src/share/man/man8/man8.x86/boot.8:1.15.2.4 Wed Jul 15 15:51:03 2020 +++ src/share/man/man8/man8.x86/boot.8 Sat May 13 11:45:53 2023 @@ -1,4 +1,4 @@ -.\" $NetBSD: boot.8,v 1.15.2.4 2020/07/15 15:51:03 martin Exp $ +.\" $NetBSD: boot.8,v 1.15.2.5 2023/05/13 11:45:53 martin Exp $ .\" .\" Copyright (c) 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -99,7 +99,7 @@ master boot record - see .Xr x86/mbr 8 ) . .Ss Normal Operation Once running, a banner similar to the following will appear: -.Bd -unfilled -offset indent +.Bd -literal -offset indent >> NetBSD BIOS Boot, revision 3.0 >> (user@buildhost, builddate) >> Memory: 637/15360 k @@ -113,7 +113,7 @@ In the example above, it will be which is the file .Pa /netbsd on partition -.Dq a +.Dq Li a of the .Nx .Tn MBR @@ -122,7 +122,7 @@ partition of the first hard disk known t .Po which is an .Tn IDE -or similar device - see the +or similar device \(em see the .Sx BUGS section .Pc . @@ -173,12 +173,12 @@ input of these commands: .\" also duplicated in the x86-specific x86/dosboot.8 and x86/pxeboot.8; .\" please try to keep all relevant files synchronized. .Bl -tag -width 04n -offset 04n -.It Ic boot Oo Va device : Oc Ns Oo Va filename Oc Oo Fl 1234abcdmqsvxz Oc +.It Ic boot Oo Ar device Ns Ic \&: Oc Ns Oo Ar filename Oc Oo Fl 1234abcdmqsvxz Oc The default -.Va device +.Ar device will be set to the disk from which the boot loader was loaded. The partition is set to the first match in this list: -.Bl -enum -compact +.Bl -enum .It The first .Xr gpt 8 @@ -193,30 +193,30 @@ The first partition with a file system t .It The first partition. .El +.Pp To boot from an alternate disk, the full name of the device should be given at the prompt. -.Va device +.Ar device is of the form -.Va NAME=partition_label +.Li NAME= Ns Ar partition_label when booting from a .Xr gpt 8 partitioned disk. Otherwise, the syntax is -.Xo Va xd -.Op Va N Ns Op Va x +.Xo Ar xd\^ Ns +.Op Ar N\^ Ns Op Ar x .Xc where -.Va xd +.Ar xd is the device from which to boot, -.Va N +.Ar N is the unit number, and -.Va x +.Ar x is the partition letter. .Pp -In the later case, the following list of supported devices may +In the latter case, the following list of supported devices may vary from installation to installation: -.Pp -.Bl -hang -compact +.Bl -hang .It hd Hard disks as numbered by the BIOS. This includes ST506, IDE, ESDI, RLL disks on a WD100[2367] or @@ -238,7 +238,7 @@ attribute set. Inner RAIDframe partitions can also be given to the .Ic dev command using he -.Va NAME=partition_label +.Li NAME= Ns Ar partition_label syntax. .El .Pp @@ -261,7 +261,7 @@ Options are: .Bl -tag -width xxx .It Fl 1 Sets the machine-dependent flag -.Sy RB_MD1 +.Dv RB_MD1 in .Va boothowto . In @@ -270,7 +270,7 @@ this disables multiprocessor boot; the kernel will boot in uniprocessor mode. .It Fl 2 Sets the machine-dependent flag -.Sy RB_MD2 +.Dv RB_MD2 in .Va boothowto . In @@ -278,7 +278,7 @@ In this disables ACPI. .It Fl 3 Sets the machine-dependent flag -.Sy RB_MD3 +.Dv RB_MD3 in .Va boothowto . In @@ -286,7 +286,7 @@ In this disables SVS. .It Fl 4 Sets the machine-dependent flag -.Sy RB_MD4 +.Dv RB_MD4 in .Va boothowto . In @@ -294,7 +294,7 @@ In this has no effect. .It Fl a Sets the -.Sy RB_ASKNAME +.Dv RB_ASKNAME flag in .Va boothowto . This causes the kernel to prompt for the root file system device, @@ -302,13 +302,13 @@ the system crash dump device, and the pa .Xr init 8 . .It Fl b Sets the -.Sy RB_HALT +.Dv RB_HALT flag in .Va boothowto . This causes subsequent reboot attempts to halt instead of rebooting. .It Fl c Sets the -.Sy RB_USERCONF +.Dv RB_USERCONF flag in .Va boothowto . This causes the kernel to enter the @@ -320,7 +320,7 @@ allows devices to be enabled or disabled to be modified before the kernel attempts to attach the devices. .It Fl d Sets the -.Sy RB_KDB +.Dv RB_KDB flag in .Va boothowto . Requests the kernel to enter debug mode, in which it @@ -328,100 +328,114 @@ waits for a connection from a kernel deb .Xr ddb 4 . .It Fl m Sets the -.Sy RB_MINIROOT +.Dv RB_MINIROOT flag in .Va boothowto . Informs the kernel that a mini-root file system is present in memory. .It Fl q Sets the -.Sy AB_QUIET +.Dv AB_QUIET flag in .Va boothowto . Boot the system in quiet mode. .It Fl s Sets the -.Sy RB_SINGLE +.Dv RB_SINGLE flag in .Va boothowto . Boot the system in single-user mode. .It Fl v Sets the -.Sy AB_VERBOSE +.Dv AB_VERBOSE flag in .Va boothowto . Boot the system in verbose mode. .It Fl x Sets the -.Sy AB_DEBUG +.Dv AB_DEBUG flag in .Va boothowto . Boot the system with debug messages enabled. .It Fl z Sets the -.Sy AB_SILENT +.Dv AB_SILENT flag in .Va boothowto . Boot the system in silent mode. .El -.It Ic consdev Va dev Ns Oo Ns , Ns Va speed Oc +.It Ic consdev Ar dev\| Ns Oo Ns Ic \&, Ns Ar speed Oc +[Not available for +.Xr x86/dosboot 8 ] Immediately switch the console to the specified device -.Va dev +.Ar dev and reprint the banner. -.Va dev +.Ar dev must be one of .\" .Bl -item -width com[0123]kbd -offset indent -compact -.Ar pc , com0 , com1 , com2 , -.Ar com3 , com0kbd , com1kbd , com2kbd , -.Ar com3kbd , +.Li pc , com0 , com1 , com2 , +.Li com3 , com0kbd , com1kbd , com2kbd , +.Li com3kbd , or -.Ar auto . +.Li auto . See .Sx Console Selection Policy in .Xr x86/boot_console 8 . .Pp A -.Va speed +.Ar speed for the serial port is optional and defaults to 9600. If a value of zero is specified, then the current baud rate (set by the BIOS) will be used. Setting the -.Va speed +.Ar speed with the -.Ar pc +.Li pc device is not possible. -.It Ic dev Op Va device +.It Ic dev Op Ar device Set the default drive and partition for subsequent file system operations. Without an argument, print the current setting. -.Va device +.Ar device is of the form specified in -.Cm boot . -.It Ic fs Va file +.Ic boot . +.It Ic devpath +[Only available for UEFI boot] Dump UEFI device paths. +.It Ic efivar +[Only available for UEFI boot] Dump UEFI environment variables from NVRAM. +.It Ic fs Ar file +[Only available for BIOS and UEFI boot] Load a file system image from the specified .Ar file , and request the kernel to use it as the root file system. The .Xr makefs 8 utility may be used to create suitable file system images. +.It Ic gop Op Va mode_index +[Only available for UEFI boot] Without argument, list the available +video modes. If an argument is given, select a video mode. .It Ic help Print an overview about commands and arguments. -.It Ic load Va module Op Ar arguments +.It Ic load Ar module Op Ar arguments +[Not available for +.Xr x86/dosboot 8 ] Load the specified kernel -.Va module , +.Ar module , and pass it the specified .Ar arguments . If the module name is not an absolute path, -.Pa /stand/ Xo Ns -.Aq Sy arch Ns +.Bd -ragged -offset indent -compact +.Pa /stand/ Ns Xo Ns +.Aq Ar arch Ns .Pa / Ns -.Aq Sy osversion Ns +.Aq Ar osversion Ns .Pa /modules/ Ns -.Aq Sy module Ns +.Aq Ar module Ns .Pa / Ns -.Aq Sy module Ns +.Aq Ar module Ns .Pa .kmod .Xc +.Ed is used. Possible uses of the .Ic load @@ -448,15 +462,15 @@ being separated with spaces Override the default boot device. .Ar dev is of the form -.Va NAME=partition_label +.Li NAME= Ns Ar partition_label for .Xr gpt 8 -partitionned disks. It can also be a unit name -.Po Dq wd0 -.Pc , +partitioned disks. +It can also be a unit name +.Pq Ql wd0 , or an interface name -.Po Dq bge0 , -.Dq wm0 , +.Po Ql bge0 , +.Ql wm0 , \&... .Pc for cases where the root file system has to be loaded @@ -474,32 +488,32 @@ See .Sx Console Selection Policy in .Xr x86/boot_console 8 . -.It Xo Ic ip Ns = Ns -.Ar my_ip : Ns Ar serv_ip : Ns Ar gw_ip : Ns -.Ar mask : Ns Ar host : Ns Ar iface +.It Xo Ic ip Ns Li \&= Ns +.Ar my_ip Ns Li \&: Ns Ar serv_ip Ns Li \&: Ns Ar gw_ip Ns Li \&: Ns +.Ar mask Ns Li \&: Ns Ar host Ns Li \&: Ns Ar iface .Xc Specify various parameters for a network boot (IPs are in dot notation), each one separated by a colon: .Bl -tag -width xxxxxxx -.It Va my_ip +.It Ar my_ip address of the host -.It Va serv_ip +.It Ar serv_ip address of the NFS server -.It Va gw_ip +.It Ar gw_ip address of the gateway -.It Va mask +.It Ar mask network mask -.It Va host +.It Ar host address of the host -.It Va iface +.It Ar iface interface -.Po e.g., Dq xennet0 +.Po e.g., Dq Li xennet0 or -.Dq eth0 +.Dq Li eth0 .Pc .El -.It Ic nfsroot Ns = Ns Ar address : Ns Ar rootpath +.It Ic nfsroot Ns = Ns Ar address Ns Li \&: Ns Ar rootpath Boot the system with root on NFS. .Ar address is the address of the NFS server, and @@ -509,42 +523,68 @@ is the remote mount point for the root f Pass a list of PCI IDs for use with the PCI backend driver, .Xr pciback 4 . .Ar pcidevs -is formed of multiple IDs (in bus:device.function notation), +is formed of multiple IDs (in +.Ar bus Ns Li \&: Ns Ar device Ns Li \&. Ns Ar function +notation), each ID being surrounded with brackets. PCI domain IDs are currently ignored. See .Xr pciback 4 . .El -.It Ic ls Op Pa path +.It Ic ls Op Ar path +[Not available for +.Xr x86/pxeboot 8 ] Print a directory listing of -.Pa path , +.Ar path , containing inode number, filename, and file type. -.Pa path +.Ar path can contain a device specification. +.It Ic memmap +[Only available for UEFI boot] Dump UEFI memory map. .It Ic menu +[Only available for BIOS and UEFI boot] Display the boot menu and initiate a countdown, similarly to what would have happened if interactive mode had not been entered. -.It Ic modules Bro Ar on | off | enabled | disabled Brc +.It Ic modules Bro Li \^on \ + No \(or Li off \ + No \(or Li enabled \ + No \(or Li disabled\^ \ + Brc +[Not available for +.Xr x86/dosboot 8 ] The values -.Ar enabled , on +.Ql enabled , +.Ql on will enable module loading for -.Cm boot +.Ic boot and -.Cm multiboot , +.Ic multiboot , whereas -.Ar disabled , off +.Ql disabled , +.Ql off will turn off the feature. -.It Ic multiboot Va kernel Op Ar arguments +.It Ic mode Va fstype +[Only available for +.Xr x86/dosboot 8 ] +Switch file system type; +.Va fstype +should be one of +.Ar dos +or +.Ar ufs . +.It Ic multiboot Ar kernel Op Ar arguments +[Not available for +.Xr x86/dosboot 8 ] Boot the specified -.Va kernel , +.Ar kernel , using the .Dq multiboot protocol instead of the native .Nx boot protocol. The -.Va kernel +.Ar kernel is specified in the same way as with the .Ic boot command. @@ -567,8 +607,10 @@ for single user mode) must be passed as .Ic load command. Options for the hypervisor (such as -.Dq dom0_mem=256M -to reserve 256 MB of memory for DOM0) +.Dq Li dom0_mem=256M +to reserve +.Pf 256 Tn MB +of memory for DOM0) must be passed as options to the .Ic multiboot command. @@ -603,9 +645,32 @@ command. See the foreign operating system's documentation for the available .Ar arguments . .El +.It Ic pkboot +[Only available for BIOS and UEFI boot] Boot a kernel that has +the +.Cd KASLR +option set, for Kernel Address Space Layout Randomizaton. .It Ic quit Reboot the system. +.It Ic reloc Op Va default No \(or Va none No \(or Va address +[Only UEFI boot] Sets where the kernel is copied by bootstrap +before it is started. Values other than default require a kernel +built with the +.Cd SELFRELOC +option, so that can relocate itself at the right address, +otherwise a crash occurs at boot time. +.Bl -tag -width default +.It Va default +Copy the kernel at ELF header load address, this is the historical +behavior. +.It Va none +Leave the kernel where it was loaded and start it as is. +.It Va address +Copy the kernel at given +.Va address . +.El .It Ic rndseed Ar file +[Only available for BIOS and UEFI boot] Load the specified .Ar file and request the kernel to use it as a seed for the @@ -631,16 +696,8 @@ Using the same seed file on more then on or for more than one boot on the same host, will reduce the quality of random numbers and may impact system security. -.It Ic userconf Va command -Pass command -.Va command -to -.Xr userconf 4 -at boot time. -These commands are processed before the interactive -.Xr userconf 4 -shell is executed, if requested. .It Ic splash Ar file +[Only available for BIOS and UEFI boot] Load a graphical image from the specified .Ar file and request the kernel to use it as a splash screen. @@ -655,19 +712,54 @@ GIF, PSD (composited view only), or PIC. -.It Ic vesa Bro Va modenum | Ar on | off | enabled | disabled | list Brc +.It Ic text Op Va mode_index +[Only available UEFI boot] Without argument, list the available +text modes (displayed as column x line in hexadecimal, therefore +.Li 50x19 +means +.Li 80 +columns and +.Li 25 +lines). With an argument, select a text mode. +.It Ic userconf Ar command +[Not available for +.Xr x86/dosboot 8 ] +Pass command +.Ar command +to +.Xr userconf 4 +at boot time. +These commands are processed before the interactive +.Xr userconf 4 +shell is executed, if requested. +.It Ic version Op Ar full +[Only available UEFI boot] Display UEFI bootstrap version. With the +.Op full +argumznt, also display information about UEFI itself. +.It Ic vesa Bro Ar \^modenum \ + No \(or Li on \ + No \(or Li off \ + No \(or Li enabled \ + No \(or Li disabled \ + No \(or Li list Brc +[Only available for BIOS and +.Xr x86/pxeboot 8 ] Initialise the video card to the specified resolution and bit depth. The -.Va modenum +.Ar modenum should be in the form of -.Ar 0x100 , 800x600 , 800x600x32 . +.Ql 0x100 , +.Ql 800x600 , +.Ql 800x600x32 . The values -.Ar enabled , on +.Ql enabled , +.Ql on put the display into the default mode, and -.Ar disabled , off +.Ql disabled , +.Ql off returns the display into standard vga mode. The value -.Ar list +.Ql list lists all supported modes. .El .Pp @@ -681,22 +773,29 @@ The kernel uses information from the boo file system to mount as root. There are three methods: .Bl -tag -width 04n -offset 04n -.It Ic BTINFO_ROOTDEVICE Va from +.\" XXX: what this .Va is supposed to mean? +.It Dv BTINFO_ROOTDEVICE Va from .Xr boot.cfg 5 or multiboot. The bootloader passes the root device name as driver, unit, and -partition (like sd0a). +partition (like +.Ql sd0a Ns ). This will be automatically substituted by a .Xr dk 4 wedge if one is discovered. .Pp -The bootloader passes a wedge name as "wedge:" followed by the name. +If the bootloader passes a wedge name as +.Dq Li wedge: +or +.Dq Li NAME= +followed by the name. The kernel will search for a .Xr dk 4 device with that name. -.It Ic BTINFO_BOOTWEDGE Va determined by bootblock +.It Dv BTINFO_BOOTWEDGE Va determined by bootblock The bootloader passes start offset and length of a hard disk partition -and a offset, size and hash of a "boot area". +and a offset, size and hash of a +.Dq boot area . Then kernel searches all disks and wedges for a block sequence at that offset with a matching hash. @@ -704,14 +803,21 @@ If one is found, the kernel will look fo on that device at the same offset. .Pp An additional partition number is provided if the bootloader also -passed a BTINFO_BOOTDISK record. -This (or partition 'a') will be used +passed a +.Dv BTINFO_BOOTDISK +record. +This (or partition +.Ql a ) +will be used by the kernel as a fallback if there is no matching wedge. -.It Ic BTINFO_BOOTDISK Va determined by bootblock -This uses the device number passed by the BIOS that -distinguishes between floppy, hard drive and CD-ROM boot. +.It Dv BTINFO_BOOTDISK Va determined by bootblock +This uses the device number passed by the +.Tn BIOS +that distinguishes between floppy, hard drive and +.Tn CD-ROM +boot. .Bl -tag -width xxx -.It Ic Floppy +.It Floppy The kernel searches for the .Xr fd 4 device with the correct unit, the partition number is used @@ -719,15 +825,19 @@ to select a specific disk format. See .Xr fd 4 for details. -.It Ic Hard drive +.It Hard drive The bootloader passed a partition number and disklabel data (offset, type, checksum, packname). The kernel searches all disks for a matching disklabel. If one is found, the kernel will use that device and partition number. -.It Ic CDROM -The BIOS does not distinguish between multiple CD devices. +.It Tn CDROM +The +.Tn BIOS +does not distinguish between multiple +.Tn CD +devices. The kernel searches for the first .Xr cd 4 device. @@ -760,13 +870,13 @@ bootstraps for and .Nx Ns /amd64 , which should be copied to the -.Pa /efi/boot +.Pa /EFI/boot directory in a .Tn FAT formatted partition of type .Tn EFI (Either -.Xr mbr 8 +.Xr x86/mbr 8 and .Xr gpt 8 , see the @@ -775,7 +885,7 @@ section). .Nx .Tn UEFI bootstrap reads its configuration from the -.Pa /efi/netBSD/boot.cfg +.Pa /EFI/NetBSD/boot.cfg file in the .Tn EFI partition. @@ -803,9 +913,7 @@ Any .Ar filename specified after the boot options, e.g.: .Pp -.Bd -unfilled -offset indent -compact -.Cm boot -d netbsd.test -.Ed +.Dl boot -d netbsd.test .Pp is ignored, and the default kernel is booted. .Pp @@ -837,32 +945,35 @@ field of the disklabel (if it is a hard disk). .Pp .Tn UEFI -implementation are supposed to support either -.Xr mbr 8 +implementations are supposed to support either +.Xr x86/mbr 8 or .Xr gpt 8 -partitionning, but some do not handle the later. +partitioning, but some do not handle the latter. .Tn UEFI -Booting +booting from a .Xr gpt 8 partitioned disk is still possible in this case, by adding an overlapping .Tn EFI partition in the protective -.Xr mbr 8 +.Xr x86/mbr 8 block. This can be achieved using the following commands (you must adapt the hard disk and .Tn EFI partition start end size to fit your setup): -.Dl Ic dd if=/dev/rwd0d bs=512 count=1 of=mbr -.Dl Ic fdisk -FIfaui1s 4/34/32768 -c /usr/mdec/mbr mbr -.Dl Ic dd if=mbr bs=512 count=1 of=/dev/rwd0d conv=notrunc +.Bd -literal -offset indent +dd if=/dev/rwd0d bs=512 count=1 of=mbr +fdisk -FIfaui1s 4/34/32768 -c /usr/mdec/mbr mbr +dd if=mbr bs=512 count=1 of=/dev/rwd0d conv=notrunc +.Ed +.Pp The resulting -.Xr mbr 8 +.Xr x86/mbr 8 partition table will look like this: -.Bd -unfilled -offset indent +.Bd -literal -offset indent 0: GPT Protective MBR (sysid 238) start 1, size 2097151 (1024 MB, Cyls 0-130/138/8) PBR is not bootable: Bad magic number (0x0000) Index: src/share/man/man8/man8.x86/dosboot.8 diff -u src/share/man/man8/man8.x86/dosboot.8:1.3 src/share/man/man8/man8.x86/dosboot.8:1.3.14.1 --- src/share/man/man8/man8.x86/dosboot.8:1.3 Fri Feb 17 22:30:28 2017 +++ src/share/man/man8/man8.x86/dosboot.8 Sat May 13 11:45:53 2023 @@ -1,4 +1,4 @@ -.\" $NetBSD: dosboot.8,v 1.3 2017/02/17 22:30:28 christos Exp $ +.\" $NetBSD: dosboot.8,v 1.3.14.1 2023/05/13 11:45:53 martin Exp $ .\" .\" Copyright (c) 1997 .\" Matthias Drochner. All rights reserved. @@ -95,54 +95,16 @@ by prepending a block device name in ter followed by a colon (see .Xr x86/boot 8 and examples). -.It Fl adqsv +.It Fl 1234abcdmqsvxz Flags passed to the kernel, see .Xr x86/boot 8 . .El .Pp -The commands accepted after the -.Fl c -flag or in interactive mode are: -.\" NOTE: some of this text is duplicated in the MI boot.8 -.\" and in other x86-specific *boot.8 files; -.\" please try to keep all relevant files synchronized. -.Bl -tag -width 04n -offset 04n -.It Ic boot Oo Va device : Oc Ns Oo Va filename Oc Oo Fl 1234abcdmqsvxz Oc -Boot -.Nx . See -.Cm boot -in .Xr x86/boot 8 -for full details. -.It Ic dev Op device -Set the default device and partition for subsequent file system operations. -Without an operand, print the current setting. -This setting doesn't apply to -.Tn MS-DOS -mode. -.It Ic help -Print an overview about commands and arguments. -.It Ic ls Op Pa path -Print a directory listing of -.Pa path , -containing inode number, filename and file type. -This command works in UFS mode only. -.Pa path -can contain a device specification. -.It Ic mode Va fstype -Switch file system type; -.Va fstype -should be one of -.Ar dos -or -.Ar ufs . -.It Ic quit -Leave the -.Nm -program and exit to -.Tn MS-DOS . -.El +for commands accepted after the +.Fl c +flag or in interactive mode. .Pp .Nm is also installed in the Index: src/share/man/man8/man8.x86/pxeboot.8 diff -u src/share/man/man8/man8.x86/pxeboot.8:1.4 src/share/man/man8/man8.x86/pxeboot.8:1.4.14.1 --- src/share/man/man8/man8.x86/pxeboot.8:1.4 Sat Feb 18 21:39:53 2017 +++ src/share/man/man8/man8.x86/pxeboot.8 Sat May 13 11:45:53 2023 @@ -1,4 +1,4 @@ -.\" $NetBSD: pxeboot.8,v 1.4 2017/02/18 21:39:53 wiz Exp $ +.\" $NetBSD: pxeboot.8,v 1.4.14.1 2023/05/13 11:45:53 martin Exp $ .\" .\" Copyright (c) 2003 .\" Matthias Drochner. All rights reserved. @@ -220,26 +220,9 @@ case to access the kernel file, matching kernel's behaviour. .El .Pp -The commands accepted in interactive mode are: -.\" NOTE: some of this text is duplicated in the MI boot.8 -.\" and in other x86-specific *boot.8 files; -.\" please try to keep all relevant files synchronized. -.Bl -tag -width 04n -offset 04n -.It Ic boot Oo Va device : Oc Ns Oo Va filename Oc Oo Fl 1234abcdmqsvxz Oc -Boot -.Nx . See -.Cm boot -in .Xr x86/boot 8 -for full details. -.It Ic help -Print an overview about commands and arguments. -.It Ic quit -Leave the -.Nm -program. -.El +for the commands accepted in interactive mode. .Pp By default the output from .Nm Index: src/sys/arch/amd64/amd64/locore.S diff -u src/sys/arch/amd64/amd64/locore.S:1.185 src/sys/arch/amd64/amd64/locore.S:1.185.2.1 --- src/sys/arch/amd64/amd64/locore.S:1.185 Sat May 18 13:32:12 2019 +++ src/sys/arch/amd64/amd64/locore.S Sat May 13 11:45:53 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: locore.S,v 1.185 2019/05/18 13:32:12 maxv Exp $ */ +/* $NetBSD: locore.S,v 1.185.2.1 2023/05/13 11:45:53 martin Exp $ */ /* * Copyright-o-rama! @@ -155,6 +155,7 @@ #include "opt_ddbparam.h" #include "opt_modular.h" #include "opt_realmem.h" +#include "opt_selfreloc.h" #include "opt_compat_netbsd.h" #include "opt_compat_netbsd32.h" @@ -437,6 +438,16 @@ ENTRY(start) #ifndef XENPV .code32 +#ifdef SELFRELOC + call next +next: pop %edi + sub $(next - kernel_text), %edi + + /* If not KERNBASE, reloc ourselves to KERNBASE */ + cmpl $(KERNTEXTOFF_LO - KERNBASE_LO), %edi + jne selfreloc_start +#endif /* SELFRELOC */ + /* Warm boot */ movw $0x1234,0x472 @@ -1701,3 +1712,140 @@ LABEL(mds_leave_end) LABEL(nomds_leave) NOMDS_LEAVE LABEL(nomds_leave_end) + +#ifdef SELFRELOC +/* + * selfreloc(loadddr edi) + * This is adapted from sys/arch/i386/i386/locore.S + */ + .code32 +ENTRY(selfreloc_start) + movl %edi, %ebx /* loadaddr saved in ebx */ + movl %edi, %esi /* src */ + movl $_RELOC(kernel_text), %edi /* dest */ + movl 16(%esp),%ecx /* esym */ + subl $_RELOC(kernel_text), %ecx /* size */ + +#if defined(NO_OVERLAP) + movl %ecx, %eax +#else + movl %edi, %eax + subl %esi, %eax + cmpl %ecx, %eax /* overlapping? */ + movl %ecx, %eax + jb .Lbackwards +#endif + /* nope, copy forwards. */ + shrl $2, %ecx /* copy by words */ + rep + movsl + and $3, %eax /* any bytes left? */ + jnz .Ltrailing + jmp .Lcopy_done + +.Ltrailing: + cmp $2, %eax + jb 11f + movw (%esi), %ax + movw %ax, (%edi) + je .Lcopy_done + movb 2(%esi), %al + movb %al, 2(%edi) + jmp .Lcopy_done +11: movb (%esi), %al + movb %al, (%edi) + jmp .Lcopy_done + +#if !defined(NO_OVERLAP) +.Lbackwards: + addl %ecx, %edi /* copy backwards. */ + addl %ecx, %esi + and $3, %eax /* any fractional bytes? */ + jnz .Lback_align +.Lback_aligned: + shrl $2, %ecx + subl $4, %esi + subl $4, %edi + std + rep + movsl + cld + jmp .Lcopy_done + +.Lback_align: + sub %eax, %esi + sub %eax, %edi + cmp $2, %eax + jb 11f + je 12f + movb 2(%esi), %al + movb %al, 2(%edi) +12: movw (%esi), %ax + movw %ax, (%edi) + jmp .Lback_aligned +11: movb (%esi), %al + movb %al, (%edi) + jmp .Lback_aligned +#endif + /* End of copy kernel */ +.Lcopy_done: + cld /* LynxOS depends on it */ + + /* load current selfreloc_start addesss in $edi */ + movl %ebx, %edi /* loadaddr was saved in ebx */ + addl $(selfreloc_start - kernel_text), %edi + + /* Prepare jump address */ + lea (selfreloc_start32a - selfreloc_start)(%edi), %eax + movl %eax, (selfreloc_start32r - selfreloc_start)(%edi) + + /* Setup GDT */ + lea (gdt - selfreloc_start)(%edi), %eax + mov %eax, (gdtrr - selfreloc_start)(%edi) + lgdt (gdtr - selfreloc_start)(%edi) + + /* Jump to set %cs */ + ljmp *(selfreloc_start32r - selfreloc_start)(%edi) + + .align 4 +selfreloc_start32a: + movl $0x10, %eax /* #define DATA_SEGMENT 0x10 */ + movw %ax, %ds + movw %ax, %es + movw %ax, %fs + movw %ax, %gs + movw %ax, %ss + + /* Disable Paging in CR0 */ + movl %cr0, %eax + andl $(~CR0_PG), %eax + movl %eax, %cr0 + + /* Disable PAE in CR4 */ + movl %cr4, %eax + andl $(~CR4_PAE), %eax + movl %eax, %cr4 + + jmp selfreloc_start32b + + .align 4 +selfreloc_start32b: + xor %eax, %eax + movl $_RELOC(start), %esi + jmp *%esi + + .align 16 +selfreloc_start32r: + .long 0 + .long 0x08 /* #define CODE_SEGMENT 0x08 */ + .align 16 +gdt: + .long 0, 0 + .byte 0xff, 0xff, 0x00, 0x00, 0x00, 0x9f, 0xcf, 0x00 + .byte 0xff, 0xff, 0x00, 0x00, 0x00, 0x93, 0xcf, 0x00 +gdtr: + .word gdtr - gdt +gdtrr: + .quad +END(selfreloc_start) +#endif /* SELFRELOC */ Index: src/sys/arch/amd64/conf/files.amd64 diff -u src/sys/arch/amd64/conf/files.amd64:1.112 src/sys/arch/amd64/conf/files.amd64:1.112.4.1 --- src/sys/arch/amd64/conf/files.amd64:1.112 Fri Feb 15 08:54:01 2019 +++ src/sys/arch/amd64/conf/files.amd64 Sat May 13 11:45:53 2023 @@ -1,4 +1,4 @@ -# $NetBSD: files.amd64,v 1.112 2019/02/15 08:54:01 nonaka Exp $ +# $NetBSD: files.amd64,v 1.112.4.1 2023/05/13 11:45:53 martin Exp $ # # new style config file for amd64 architecture # @@ -22,6 +22,9 @@ defparam opt_physmem.h PHYSMEM_MAX_ADDR # Enable GCC spectre V2 mitigation options defflag opt_spectre.h SPECTRE_V2_GCC_MITIGATION +# Enable kernel self-relocation at bootstrap +defflag opt_selfreloc.h SELFRELOC + # # XXX these are just here at the moment so that we can share files # with the i386 (they include the opt_*.h for these) Index: src/sys/arch/amd64/conf/std.amd64 diff -u src/sys/arch/amd64/conf/std.amd64:1.11 src/sys/arch/amd64/conf/std.amd64:1.11.20.1 --- src/sys/arch/amd64/conf/std.amd64:1.11 Thu Jan 12 05:24:36 2017 +++ src/sys/arch/amd64/conf/std.amd64 Sat May 13 11:45:53 2023 @@ -1,4 +1,4 @@ -# $NetBSD: std.amd64,v 1.11 2017/01/12 05:24:36 ryo Exp $ +# $NetBSD: std.amd64,v 1.11.20.1 2023/05/13 11:45:53 martin Exp $ # # standard, required NetBSD/amd64 'options' @@ -14,6 +14,8 @@ options MULTIPROCESSOR options CHILD_MAX=1024 # 160 is too few options OPEN_MAX=1024 # 128 is too few +options SELFRELOC + mainbus0 at root cpu* at mainbus? ioapic* at mainbus? apid ? Index: src/sys/arch/i386/stand/efiboot/boot.c diff -u src/sys/arch/i386/stand/efiboot/boot.c:1.13.2.3 src/sys/arch/i386/stand/efiboot/boot.c:1.13.2.4 --- src/sys/arch/i386/stand/efiboot/boot.c:1.13.2.3 Fri Sep 27 09:32:22 2019 +++ src/sys/arch/i386/stand/efiboot/boot.c Sat May 13 11:45:53 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: boot.c,v 1.13.2.3 2019/09/27 09:32:22 martin Exp $ */ +/* $NetBSD: boot.c,v 1.13.2.4 2023/05/13 11:45:53 martin Exp $ */ /*- * Copyright (c) 2016 Kimihiro Nonaka <non...@netbsd.org> @@ -78,6 +78,7 @@ void command_menu(char *); #endif void command_modules(char *); void command_multiboot(char *); +void command_reloc(char *); void command_text(char *); void command_version(char *); @@ -103,6 +104,7 @@ const struct bootblk_command commands[] #endif { "modules", command_modules }, { "multiboot", command_multiboot }, + { "reloc", command_reloc }, { "rndseed", rnd_add }, { "splash", splash_add }, { "text", command_text }, @@ -409,6 +411,7 @@ command_help(char *arg) #endif "modules {on|off|enabled|disabled}\n" "multiboot [dev:][filename] [<args>]\n" + "reloc {address|none|default}\n" "rndseed {path_to_rndseed_file}\n" "splash {path_to_image_file}\n" "text [{modenum|list}]\n" @@ -632,6 +635,48 @@ command_multiboot(char *arg) } void +command_reloc(char *arg) +{ + char *ep; + + if (*arg == '\0') { + switch (efi_reloc_type) { + case RELOC_NONE: + printf("reloc: none\n"); + break; + case RELOC_ADDR: + printf("reloc: %p\n", (void *)efi_kernel_reloc); + break; + case RELOC_DEFAULT: + default: + printf("reloc: default\n"); + break; + } + goto out; + } + + if (strcmp(arg, "default") == 0) { + efi_reloc_type = RELOC_DEFAULT; + goto out; + } + + if (strcmp(arg, "none") == 0) { + efi_reloc_type = RELOC_NONE; + goto out; + } + + errno = 0; + efi_kernel_reloc = strtoul(arg, &ep, 0); + if (ep == arg || *ep != '\0' || errno) + printf("could not parse address \"%s\"\n", arg); + else + efi_reloc_type = RELOC_ADDR; +out: + return; + +} + +void command_version(char *arg) { CHAR16 *path; Index: src/sys/arch/i386/stand/efiboot/efiboot.c diff -u src/sys/arch/i386/stand/efiboot/efiboot.c:1.10.2.2 src/sys/arch/i386/stand/efiboot/efiboot.c:1.10.2.3 --- src/sys/arch/i386/stand/efiboot/efiboot.c:1.10.2.2 Mon Feb 10 18:59:48 2020 +++ src/sys/arch/i386/stand/efiboot/efiboot.c Sat May 13 11:45:53 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: efiboot.c,v 1.10.2.2 2020/02/10 18:59:48 martin Exp $ */ +/* $NetBSD: efiboot.c,v 1.10.2.3 2023/05/13 11:45:53 martin Exp $ */ /*- * Copyright (c) 2016 Kimihiro Nonaka <non...@netbsd.org> @@ -36,7 +36,9 @@ EFI_DEVICE_PATH *efi_bootdp; enum efi_boot_device_type efi_bootdp_type = BOOT_DEVICE_TYPE_HD; EFI_LOADED_IMAGE *efi_li; uintptr_t efi_main_sp; -physaddr_t efi_loadaddr, efi_kernel_start; +physaddr_t efi_loadaddr, efi_kernel_start, efi_load_start; +physaddr_t efi_kernel_reloc = 0; +enum efi_reloc_type efi_reloc_type = RELOC_DEFAULT; u_long efi_kernel_size; bool efi_cleanuped; struct btinfo_efimemmap *btinfo_efimemmap = NULL; Index: src/sys/arch/i386/stand/efiboot/efiboot.h diff -u src/sys/arch/i386/stand/efiboot/efiboot.h:1.9.2.1 src/sys/arch/i386/stand/efiboot/efiboot.h:1.9.2.2 --- src/sys/arch/i386/stand/efiboot/efiboot.h:1.9.2.1 Tue Sep 17 19:32:00 2019 +++ src/sys/arch/i386/stand/efiboot/efiboot.h Sat May 13 11:45:53 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: efiboot.h,v 1.9.2.1 2019/09/17 19:32:00 martin Exp $ */ +/* $NetBSD: efiboot.h,v 1.9.2.2 2023/05/13 11:45:53 martin Exp $ */ /*- * Copyright (c) 2016 Kimihiro Nonaka <non...@netbsd.org> @@ -53,7 +53,13 @@ extern enum efi_boot_device_type { } efi_bootdp_type; extern EFI_LOADED_IMAGE *efi_li; extern uintptr_t efi_main_sp; -extern physaddr_t efi_loadaddr, efi_kernel_start; +extern physaddr_t efi_loadaddr, efi_kernel_start, efi_load_start; +extern physaddr_t efi_kernel_reloc; +extern enum efi_reloc_type { + RELOC_DEFAULT, + RELOC_NONE, + RELOC_ADDR, +} efi_reloc_type; extern u_long efi_kernel_size; extern bool efi_cleanuped; void efi_cleanup(void); Index: src/sys/arch/i386/stand/efiboot/version diff -u src/sys/arch/i386/stand/efiboot/version:1.1.26.1 src/sys/arch/i386/stand/efiboot/version:1.1.26.2 --- src/sys/arch/i386/stand/efiboot/version:1.1.26.1 Sun Aug 4 19:20:49 2019 +++ src/sys/arch/i386/stand/efiboot/version Sat May 13 11:45:53 2023 @@ -1,4 +1,4 @@ -$NetBSD: version,v 1.1.26.1 2019/08/04 19:20:49 martin Exp $ +$NetBSD: version,v 1.1.26.2 2023/05/13 11:45:53 martin Exp $ NOTE ANY CHANGES YOU MAKE TO THE EFI BOOTLOADER HERE. The format of this file is important - make sure the entries are appended on end, last item @@ -6,3 +6,4 @@ is taken as the current. 1.0: Initial version. 1.1: Add CD/DVD-ROM, serial, PXE boot and UEFI memory map compaction support. +1.2: Add reloc command Index: src/sys/arch/i386/stand/efiboot/bootia32/efibootia32.c diff -u src/sys/arch/i386/stand/efiboot/bootia32/efibootia32.c:1.4.6.1 src/sys/arch/i386/stand/efiboot/bootia32/efibootia32.c:1.4.6.2 --- src/sys/arch/i386/stand/efiboot/bootia32/efibootia32.c:1.4.6.1 Tue Sep 17 19:32:00 2019 +++ src/sys/arch/i386/stand/efiboot/bootia32/efibootia32.c Sat May 13 11:45:53 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: efibootia32.c,v 1.4.6.1 2019/09/17 19:32:00 martin Exp $ */ +/* $NetBSD: efibootia32.c,v 1.4.6.2 2023/05/13 11:45:53 martin Exp $ */ /*- * Copyright (c) 2016 Kimihiro Nonaka <non...@netbsd.org> @@ -76,7 +76,7 @@ startprog(physaddr_t entry, uint32_t arg (*startprog32)(entry, argc, argv, (physaddr_t)startprog32 + startprog32_size, - efi_kernel_start, efi_kernel_start + efi_loadaddr, + efi_kernel_start, efi_load_start, efi_kernel_size, startprog32); } Index: src/sys/arch/i386/stand/efiboot/bootia32/startprog32.S diff -u src/sys/arch/i386/stand/efiboot/bootia32/startprog32.S:1.2 src/sys/arch/i386/stand/efiboot/bootia32/startprog32.S:1.2.26.1 --- src/sys/arch/i386/stand/efiboot/bootia32/startprog32.S:1.2 Fri Feb 24 12:24:25 2017 +++ src/sys/arch/i386/stand/efiboot/bootia32/startprog32.S Sat May 13 11:45:53 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: startprog32.S,v 1.2 2017/02/24 12:24:25 nonaka Exp $ */ +/* $NetBSD: startprog32.S,v 1.2.26.1 2023/05/13 11:45:53 martin Exp $ */ /* NetBSD: startprog.S,v 1.4 2016/12/04 08:21:08 maxv Exp */ /* @@ -117,6 +117,11 @@ start: movl 24(%ebp), %edi /* dest */ movl 28(%ebp), %esi /* src */ movl 32(%ebp), %ecx /* size */ + + /* skip copy if same source and destination */ + cmpl %edi,%esi + jz .Lcopy_done + #if defined(NO_OVERLAP) movl %ecx, %eax #else Index: src/sys/arch/i386/stand/efiboot/bootx64/efibootx64.c diff -u src/sys/arch/i386/stand/efiboot/bootx64/efibootx64.c:1.4.6.1 src/sys/arch/i386/stand/efiboot/bootx64/efibootx64.c:1.4.6.2 --- src/sys/arch/i386/stand/efiboot/bootx64/efibootx64.c:1.4.6.1 Tue Sep 17 19:32:00 2019 +++ src/sys/arch/i386/stand/efiboot/bootx64/efibootx64.c Sat May 13 11:45:53 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: efibootx64.c,v 1.4.6.1 2019/09/17 19:32:00 martin Exp $ */ +/* $NetBSD: efibootx64.c,v 1.4.6.2 2023/05/13 11:45:53 martin Exp $ */ /*- * Copyright (c) 2016 Kimihiro Nonaka <non...@netbsd.org> @@ -80,7 +80,7 @@ startprog(physaddr_t entry, uint32_t arg memcpy(newsp, argv, sizeof(*argv) * argc); } - (*startprog64)(efi_kernel_start, efi_kernel_start + efi_loadaddr, + (*startprog64)(efi_kernel_start, efi_load_start, (physaddr_t)newsp, efi_kernel_size, startprog64, entry); } Index: src/sys/arch/i386/stand/efiboot/bootx64/startprog64.S diff -u src/sys/arch/i386/stand/efiboot/bootx64/startprog64.S:1.3 src/sys/arch/i386/stand/efiboot/bootx64/startprog64.S:1.3.24.1 --- src/sys/arch/i386/stand/efiboot/bootx64/startprog64.S:1.3 Sat Feb 11 10:23:39 2017 +++ src/sys/arch/i386/stand/efiboot/bootx64/startprog64.S Sat May 13 11:45:53 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: startprog64.S,v 1.3 2017/02/11 10:23:39 nonaka Exp $ */ +/* $NetBSD: startprog64.S,v 1.3.24.1 2023/05/13 11:45:53 martin Exp $ */ /* NetBSD: startprog.S,v 1.3 2003/02/01 14:48:18 dsl Exp */ /* starts program in protected mode / flat space @@ -97,6 +97,10 @@ start: cli + /* skip copy if same source and destination */ + cmpq %rdi,%rsi + jz .Lcopy_done + /* Copy kernel */ mov %rcx, %r12 /* original kernel size */ movq %rdi, %r11 /* for misaligned check */ Index: src/sys/arch/i386/stand/lib/exec.c diff -u src/sys/arch/i386/stand/lib/exec.c:1.73.2.1 src/sys/arch/i386/stand/lib/exec.c:1.73.2.2 --- src/sys/arch/i386/stand/lib/exec.c:1.73.2.1 Tue Sep 17 19:31:59 2019 +++ src/sys/arch/i386/stand/lib/exec.c Sat May 13 11:45:53 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: exec.c,v 1.73.2.1 2019/09/17 19:31:59 martin Exp $ */ +/* $NetBSD: exec.c,v 1.73.2.2 2023/05/13 11:45:53 martin Exp $ */ /* * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. @@ -464,6 +464,7 @@ exec_netbsd(const char *file, physaddr_t struct btinfo_symtab btinfo_symtab; u_long extmem; u_long basemem; + u_long entry; int error; #ifdef EFIBOOT int i; @@ -494,6 +495,8 @@ exec_netbsd(const char *file, physaddr_t goto out; } #ifdef EFIBOOT + efi_load_start = marks[MARK_START]; + /* adjust to the real load address */ marks[MARK_START] -= efi_loadaddr; marks[MARK_ENTRY] -= efi_loadaddr; @@ -549,6 +552,8 @@ exec_netbsd(const char *file, physaddr_t if (callback != NULL) (*callback)(); + + entry = marks[MARK_ENTRY]; #ifdef EFIBOOT /* Copy bootinfo to safe arena. */ for (i = 0; i < bootinfo->nentries; i++) { @@ -560,8 +565,22 @@ exec_netbsd(const char *file, physaddr_t efi_kernel_start = marks[MARK_START]; efi_kernel_size = image_end - (efi_loadaddr + efi_kernel_start); + + switch (efi_reloc_type) { + case RELOC_NONE: + entry += (efi_load_start - efi_kernel_start); + efi_kernel_start = efi_load_start; + break; + case RELOC_ADDR: + entry += (efi_kernel_reloc - efi_kernel_start); + efi_kernel_start = efi_kernel_reloc; + break; + case RELOC_DEFAULT: + default: + break; + } #endif - startprog(marks[MARK_ENTRY], BOOT_NARGS, boot_argv, + startprog(entry, BOOT_NARGS, boot_argv, x86_trunc_page(basemem * 1024)); panic("exec returned");