]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[riscv] Allow for a non-zero link-time address
authorMichael Brown <mcb30@ipxe.org>
Thu, 1 May 2025 13:24:33 +0000 (14:24 +0100)
committerMichael Brown <mcb30@ipxe.org>
Thu, 1 May 2025 13:49:53 +0000 (14:49 +0100)
Using paging (rather than relocation records) will be easier on 64-bit
RISC-V if we place iPXE within the negative (kernel) virtual address
space.

Allow the link-time address to be non-zero and to vary between 32-bit
and 64-bit builds.  Choose addresses that are expected to be amenable
to the use of paging.

There is no particular need to use a non-zero address in the 32-bit
builds, but doing so allows us to validate that the relocation code is
handling this case correctly.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/arch/riscv/scripts/sbi.lds
src/arch/riscv32/Makefile.sbi
src/arch/riscv64/Makefile.sbi

index afb1902e1962f13532ccf6db8771d49f7c58e1e3..f882f235ea94973b7ffbd305bce0b2a6456a06b8 100644 (file)
@@ -5,10 +5,8 @@
 
 SECTIONS {
 
-    /* Start at virtual address zero */
-    . = 0;
-
     /* Weak symbols that need zero values if not otherwise defined */
+    saved_pos = .;
     .weak 0x0 : {
        _weak = .;
        *(.weak)
@@ -16,6 +14,7 @@ SECTIONS {
        _eweak = .;
     }
     _assert = ASSERT ( ( _weak == _eweak ), ".weak is non-zero length" );
+    _assert = ASSERT ( ( . == saved_pos ), ".weak altered current position" );
 
     /* Prefix code */
     .prefix : {
@@ -105,7 +104,7 @@ SECTIONS {
     _ereloc = ( _reloc + __load_stop_reladyn - __load_start_reladyn );
 
     /* Length of initialised data */
-    _sbi_filesz = ABSOLUTE ( _ereloc );
+    _sbi_filesz = ( ABSOLUTE ( _ereloc ) - ABSOLUTE ( _prefix ) );
 
     /* Unwanted sections */
     /DISCARD/ : {
index d62287770760a068abd82f502dc0085dbe04afc3..5841dd4b5fd24f4b8791983ef8859bf3985a0926 100644 (file)
@@ -1,5 +1,13 @@
 # -*- makefile -*- : Force emacs to use Makefile mode
 
+# Set base virtual address to 0xeb000000
+#
+# This is aligned to a 4MB boundary and so allows 4MB megapages to be
+# used to map the iPXE binary.  The address pattern is also easily
+# recognisable if leaked to unexpected contexts.
+#
+LDFLAGS                += --section-start=.prefix=0xeb000000
+
 # Include generic SBI Makefile
 #
 MAKEDEPS       += arch/riscv/Makefile.sbi
index d62287770760a068abd82f502dc0085dbe04afc3..0f7e1c3739d91d3bc5a4aaa1ae092976ae48ebce 100644 (file)
@@ -1,5 +1,13 @@
 # -*- makefile -*- : Force emacs to use Makefile mode
 
+# Set base virtual address to 0xffffffffeb000000
+#
+# This is aligned to a 2MB boundary and so allows 2MB megapages to be
+# used to map the iPXE binary.  The address pattern is also easily
+# recognisable if leaked to unexpected contexts.
+#
+LDFLAGS                += --section-start=.prefix=0xffffffffeb000000
+
 # Include generic SBI Makefile
 #
 MAKEDEPS       += arch/riscv/Makefile.sbi