Module Name:    src
Committed By:   manu
Date:           Fri May  5 00:34:41 UTC 2023

Modified Files:
        src/share/man/man4: options.4
        src/share/man/man8/man8.x86: boot.8
        src/sys/arch/amd64/amd64: locore.S
        src/sys/arch/amd64/conf: files.amd64 std.amd64

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.523 -r1.524 src/share/man/man4/options.4
cvs rdiff -u -r1.27 -r1.28 src/share/man/man8/man8.x86/boot.8
cvs rdiff -u -r1.219 -r1.220 src/sys/arch/amd64/amd64/locore.S
cvs rdiff -u -r1.120 -r1.121 src/sys/arch/amd64/conf/files.amd64
cvs rdiff -u -r1.12 -r1.13 src/sys/arch/amd64/conf/std.amd64

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.523 src/share/man/man4/options.4:1.524
--- src/share/man/man4/options.4:1.523	Sun Aug 28 14:29:05 2022
+++ src/share/man/man4/options.4	Fri May  5 00:34:41 2023
@@ -1,4 +1,4 @@
-.\"	$NetBSD: options.4,v 1.523 2022/08/28 14:29:05 riastradh Exp $
+.\"	$NetBSD: options.4,v 1.524 2023/05/05 00:34:41 manu Exp $
 .\"
 .\" Copyright (c) 1996
 .\" 	Perry E. Metzger.  All rights reserved.
@@ -1307,6 +1307,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.27 src/share/man/man8/man8.x86/boot.8:1.28
--- src/share/man/man8/man8.x86/boot.8:1.27	Mon Apr 24 13:55:45 2023
+++ src/share/man/man8/man8.x86/boot.8	Fri May  5 00:34:40 2023
@@ -1,4 +1,4 @@
-.\"	$NetBSD: boot.8,v 1.27 2023/04/24 13:55:45 manu Exp $
+.\"	$NetBSD: boot.8,v 1.28 2023/05/05 00:34:40 manu Exp $
 .\"
 .\" Copyright (c) 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -655,8 +655,10 @@ 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
-that can relocate itself at the right address, otherwise a crash
-occurs at boot time.
+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

Index: src/sys/arch/amd64/amd64/locore.S
diff -u src/sys/arch/amd64/amd64/locore.S:1.219 src/sys/arch/amd64/amd64/locore.S:1.220
--- src/sys/arch/amd64/amd64/locore.S:1.219	Thu Apr 20 00:42:23 2023
+++ src/sys/arch/amd64/amd64/locore.S	Fri May  5 00:34:41 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.219 2023/04/20 00:42:23 manu Exp $	*/
+/*	$NetBSD: locore.S,v 1.220 2023/05/05 00:34:41 manu Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -156,6 +156,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"
@@ -456,6 +457,7 @@ ENTRY(start)
 #ifndef XENPV
 	.code32
 
+#ifdef SELFRELOC
 	call	next
 next:	pop	%edi
 	sub     $(next - kernel_text), %edi 
@@ -463,6 +465,7 @@ next:	pop	%edi
 	/* If not KERNBASE, reloc ourselves to KERNBASE */
 	cmpl	$(KERNTEXTOFF_LO - KERNBASE_LO), %edi
 	jne	selfreloc_start
+#endif /* SELFRELOC */
 
 	/* Warm boot */
 	movw	$0x1234,0x472
@@ -1766,6 +1769,7 @@ LABEL(nomds_leave)
 	NOMDS_LEAVE
 LABEL(nomds_leave_end)
 
+#ifdef SELFRELOC
 /*
  * selfreloc(loadddr edi)
  * This is adapted from sys/arch/i386/i386/locore.S
@@ -1900,3 +1904,4 @@ gdtr:
 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.120 src/sys/arch/amd64/conf/files.amd64:1.121
--- src/sys/arch/amd64/conf/files.amd64:1.120	Wed Oct 21 13:31:51 2020
+++ src/sys/arch/amd64/conf/files.amd64	Fri May  5 00:34:41 2023
@@ -1,4 +1,4 @@
-#	$NetBSD: files.amd64,v 1.120 2020/10/21 13:31:51 christos Exp $
+#	$NetBSD: files.amd64,v 1.121 2023/05/05 00:34:41 manu Exp $
 #
 # new style config file for amd64 architecture
 #
@@ -20,6 +20,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.12 src/sys/arch/amd64/conf/std.amd64:1.13
--- src/sys/arch/amd64/conf/std.amd64:1.12	Sat Apr 25 15:26:16 2020
+++ src/sys/arch/amd64/conf/std.amd64	Fri May  5 00:34:41 2023
@@ -1,4 +1,4 @@
-# $NetBSD: std.amd64,v 1.12 2020/04/25 15:26:16 bouyer Exp $
+# $NetBSD: std.amd64,v 1.13 2023/05/05 00:34:41 manu Exp $
 #
 # standard, required NetBSD/amd64 'options'
 
@@ -15,6 +15,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 ?

Reply via email to