[PATCH 12/21] mips: libgloss: Boot and startup code improvements inc.
Aleksandar Rikalo
arikalo@gmail.com
Thu Oct 31 05:49:28 GMT 2024
From: Robert Suchanek <robert.suchanek@imgtec.com>
Add .eh_frame_hdr and .gnu_extab to linker scripts for compactEH
Fix orphaned .gcc_except_table sections in uhi32.ld.
Fix orphaned .gcc_except_table sections in mti32.ld.
Fix VMA-LMA mismatches due to alignment issues.
Signed-off-by: Robert Suchanek <robert.suchanek@imgtec.com>
Signed-off-by: Aleksandar Rikalo <arikalo@gmail.com>
---
libgloss/mips/boot/reset.S | 7 ++++++
libgloss/mips/boot/reset_predef.S | 18 ++++++++++++--
libgloss/mips/hal/minicrt.S | 24 ++++++++++++------
libgloss/mips/mti32.ld | 19 ++++++++++++--
libgloss/mips/uhi32.ld | 41 ++++++++++++++++++++++---------
libgloss/mips/uhi64_64.ld | 41 ++++++++++++++++++++++---------
libgloss/mips/uhi64_n32.ld | 41 ++++++++++++++++++++++---------
7 files changed, 144 insertions(+), 47 deletions(-)
diff --git a/libgloss/mips/boot/reset.S b/libgloss/mips/boot/reset.S
index 81ce55c0c..eb1ff9998 100644
--- a/libgloss/mips/boot/reset.S
+++ b/libgloss/mips/boot/reset.S
@@ -150,6 +150,13 @@ $Lcopy_to_ram_done:
eret
$Lall_done:
+ /* Allow an exit hook to intercept the end of execution */
+ .weak __boot_exit_hook
+ lui a2, %hi(__boot_exit_hook)
+ addiu a2, a2, %lo(__boot_exit_hook)
+ beqz a2, 1f
+ jalr a2
+1:
/*
* If _start returns it will return to this point.
* Just spin here reporting the exit.
diff --git a/libgloss/mips/boot/reset_predef.S b/libgloss/mips/boot/reset_predef.S
index e77de514d..4199c829a 100644
--- a/libgloss/mips/boot/reset_predef.S
+++ b/libgloss/mips/boot/reset_predef.S
@@ -75,6 +75,8 @@ $Lnot_nmi:
/* Init CP0 Status, Count, Compare, Watch*, and Cause */
jal __init_cp0
+#if !defined(HCI)
+
#if (defined(SLINE_ENC) && SLINE_ENC != 0) || (defined(MEM_MAPPED_L2C) && MEM_MAPPED_L2C != 0)
/*
* Initialise L2/L3 cache
@@ -83,10 +85,12 @@ $Lnot_nmi:
jal __init_l23cache
#endif
-
#if defined(ILINE_ENC) && ILINE_ENC != 0
/* Initialize the L1 instruction cache */
jal __init_icache
+#endif
+
+#endif /* !defined(HCI) */
/*
* The changing of Kernel mode cacheability must be done from KSEG1
@@ -99,7 +103,8 @@ $Lnot_nmi:
li a1, 0xf
ins a2, a1, 29, 1 /* changed to KSEG1 address by setting bit 29 */
jalr a2
-#endif
+
+#if !defined(HCI)
#if (defined(SLINE_ENC) && SLINE_ENC != 0) || (defined(MEM_MAPPED_L2C) && MEM_MAPPED_L2C != 0)
/* Support initialising L2 with L1 cache enabled */
@@ -111,6 +116,8 @@ $Lnot_nmi:
jal __init_dcache
#endif
+#endif /* !defined(HCI) */
+
#if defined(HAVE_TLB) && HAVE_TLB
/* Initialize the TLB */
jal __init_tlb
@@ -170,6 +177,13 @@ $Lcopy_to_ram_done:
eret
$Lall_done:
+ /* Allow an exit hook to intercept the end of execution */
+ .weak __boot_exit_hook
+ lui a2, %hi(__boot_exit_hook)
+ addiu a2, a2, %lo(__boot_exit_hook)
+ beqz a2, 1f
+ jalr a2
+1:
/*
* If _start returns it will return to this point.
* Just spin here reporting the exit.
diff --git a/libgloss/mips/hal/minicrt.S b/libgloss/mips/hal/minicrt.S
index fa4759499..bcf6caf77 100644
--- a/libgloss/mips/hal/minicrt.S
+++ b/libgloss/mips/hal/minicrt.S
@@ -1,7 +1,13 @@
#include <mips/asm.h>
+#include <mips/m32c0.h>
#include <mips/regdef.h>
LEAF(_start)
+#ifdef __mips_dsp
+ mfc0 t0, C0_STATUS
+ or t0, t0, SR_MX
+ mtc0 t0, C0_STATUS
+#endif
/* Preserve return address */
move s0, ra
/* Set up global pointer for small data access */
@@ -9,13 +15,13 @@ LEAF(_start)
/* Set up stack pointer */
LA sp, __stack
/* Zero the BSS */
- LA v0, _fbss
- LA v1, _end
- beq v0,v1,2f
+ LA t0, _fbss
+ LA t1, _end
+ beq t0,t1,2f
1:
- addiu v0,v0,4
- sw zero,-4(v0)
- bne v0,v1,1b
+ addiu t0,t0,4
+ sw zero,-4(t0)
+ bne t0,t1,1b
2:
/* Set arguments to be null for main */
li a0, 0
@@ -24,8 +30,12 @@ LEAF(_start)
addiu sp, sp, -(NARGSAVE * SZARG)
/* Jump to C code */
jal main
-
+ /* Call the exit handler */
+ move a0, va0
+ jal __exit
/* Return to boot */
move ra, s0
+ .weak __exit
+AENT(__exit)
jr ra
END(_start)
diff --git a/libgloss/mips/mti32.ld b/libgloss/mips/mti32.ld
index 71f409a67..010f33dc0 100644
--- a/libgloss/mips/mti32.ld
+++ b/libgloss/mips/mti32.ld
@@ -55,15 +55,30 @@ SECTIONS
PROVIDE (etext = .);
_etext = .;
- .eh_frame_hdr : { *(.eh_frame_hdr) }
+ .eh_frame_hdr : { *(.eh_frame_hdr) *(.eh_frame_entry .eh_frame_entry.*) }
.eh_frame : {
/* The .eh_frame section from the crtend file contains the
end of eh_frame marker and it must be last. */
KEEP (*(EXCLUDE_FILE (*crtend.o) .eh_frame))
KEEP (*(.eh_frame))
}
- .gcc_except_table : { *(.gcc_except_table) }
+ .gcc_except_table : { *(.gcc_except_table .gcc_except_table.*) }
+ .gnu_extab : { *(.gnu_extab .gnu_extab.*) }
.jcr : { KEEP (*(.jcr)) }
+ .init_array :
+ {
+ PROVIDE_HIDDEN (__init_array_start = .);
+ KEEP (*(SORT(.init_array.*)))
+ KEEP (*(.init_array))
+ PROVIDE_HIDDEN (__init_array_end = .);
+ }
+ .fini_array :
+ {
+ PROVIDE_HIDDEN (__fini_array_start = .);
+ KEEP (*(SORT(.fini_array.*)))
+ KEEP (*(.fini_array))
+ PROVIDE_HIDDEN (__fini_array_end = .);
+ }
.ctors :
{
/* gcc uses crtbegin.o to find the start of
diff --git a/libgloss/mips/uhi32.ld b/libgloss/mips/uhi32.ld
index d9df8e5e0..96f697add 100644
--- a/libgloss/mips/uhi32.ld
+++ b/libgloss/mips/uhi32.ld
@@ -125,10 +125,12 @@ SECTIONS
. = ALIGN(8);
} = 0
- PROVIDE (__flash_app_start = SIZEOF(.bootrom) + __flash_start);
+ PROVIDE (__flash_app_start = DEFINED(__xip)
+ ? ALIGN(__flash_start + SIZEOF(.bootrom), 0x1000)
+ : __flash_start + SIZEOF(.bootrom));
__aligned_app_start = DEFINED(__xip)
- ? __bev_override + SIZEOF(.bootrom)
+ ? ALIGN(__bev_override + SIZEOF(.bootrom), 0x1000)
: ALIGN(__app_start, 0x1000);
PROVIDE (__ebase_size = 0x200);
@@ -155,7 +157,7 @@ SECTIONS
. = ALIGN(8);
} = 0
- .text . : AT (LOADADDR (.exception_vector) + SIZEOF(.exception_vector)) {
+ .text : {
_ftext = . ;
PROVIDE (eprol = .);
*(.text)
@@ -164,13 +166,13 @@ SECTIONS
*(.mips16.fn.*)
*(.mips16.call.*)
}
- .init . : AT (LOADADDR (.text) + SIZEOF(.text)) {
+ .init : {
KEEP (*(.init))
}
- .fini . : AT (LOADADDR (.init) + SIZEOF(.init)) {
+ .fini : {
KEEP (*(.fini))
}
- .rel.sdata . : AT (LOADADDR (.fini) + SIZEOF(.fini)) {
+ .rel.sdata : {
PROVIDE (__runtime_reloc_start = .);
*(.rel.sdata)
PROVIDE (__runtime_reloc_stop = .);
@@ -178,11 +180,26 @@ SECTIONS
PROVIDE (etext = .);
_etext = .;
- .eh_frame_hdr . : AT (LOADADDR (.rel.sdata) + SIZEOF(.rel.sdata)) { *(.eh_frame_hdr) }
- .eh_frame . : AT (LOADADDR (.eh_frame_hdr) + SIZEOF(.eh_frame_hdr)) { KEEP (*(.eh_frame)) }
- .gcc_except_table . : AT (LOADADDR (.eh_frame) + SIZEOF(.eh_frame)) { *(.gcc_except_table) }
- .jcr . : AT (LOADADDR (.gcc_except_table) + SIZEOF(.gcc_except_table)) { KEEP (*(.jcr)) }
- .ctors . : AT (LOADADDR (.jcr) + SIZEOF(.jcr))
+ .eh_frame_hdr : { *(.eh_frame_hdr) *(.eh_frame_entry .eh_frame_entry.*) }
+ .eh_frame : { KEEP (*(.eh_frame)) }
+ .gcc_except_table : { *(.gcc_except_table .gcc_except_table.*) }
+ .gnu_extab : { *(.gnu_extab .gnu_extab.*) }
+ .jcr : { KEEP (*(.jcr)) }
+ .init_array :
+ {
+ PROVIDE_HIDDEN (__init_array_start = .);
+ KEEP (*(SORT(.init_array.*)))
+ KEEP (*(.init_array))
+ PROVIDE_HIDDEN (__init_array_end = .);
+ }
+ .fini_array :
+ {
+ PROVIDE_HIDDEN (__fini_array_start = .);
+ KEEP (*(SORT(.fini_array.*)))
+ KEEP (*(.fini_array))
+ PROVIDE_HIDDEN (__fini_array_end = .);
+ }
+ .ctors :
{
/* gcc uses crtbegin.o to find the start of
the constructors, so we make sure it is
@@ -206,7 +223,7 @@ SECTIONS
KEEP (*(.ctors))
}
- .dtors . : AT (LOADADDR (.ctors) + SIZEOF(.ctors))
+ .dtors :
{
KEEP (*crtbegin.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
diff --git a/libgloss/mips/uhi64_64.ld b/libgloss/mips/uhi64_64.ld
index 15aeb2ecc..1aece1bf2 100644
--- a/libgloss/mips/uhi64_64.ld
+++ b/libgloss/mips/uhi64_64.ld
@@ -125,10 +125,12 @@ SECTIONS
. = ALIGN(8);
} = 0
- PROVIDE (__flash_app_start = SIZEOF(.bootrom) + __flash_start);
+ PROVIDE (__flash_app_start = DEFINED(__xip)
+ ? ALIGN(__flash_start + SIZEOF(.bootrom), 0x1000)
+ : __flash_start + SIZEOF(.bootrom));
__aligned_app_start = DEFINED(__xip)
- ? __bev_override + SIZEOF(.bootrom)
+ ? ALIGN(__bev_override + SIZEOF(.bootrom), 0x1000)
: ALIGN(__app_start, 0x1000);
PROVIDE (__ebase_size = 0x200);
@@ -155,7 +157,7 @@ SECTIONS
. = ALIGN(8);
} = 0
- .text . : AT (LOADADDR (.exception_vector) + SIZEOF(.exception_vector)) {
+ .text : {
_ftext = . ;
PROVIDE (eprol = .);
*(.text)
@@ -164,13 +166,13 @@ SECTIONS
*(.mips16.fn.*)
*(.mips16.call.*)
}
- .init . : AT (LOADADDR (.text) + SIZEOF(.text)) {
+ .init : {
KEEP (*(.init))
}
- .fini . : AT (LOADADDR (.init) + SIZEOF(.init)) {
+ .fini : {
KEEP (*(.fini))
}
- .rel.sdata . : AT (LOADADDR (.fini) + SIZEOF(.fini)) {
+ .rel.sdata : {
PROVIDE (__runtime_reloc_start = .);
*(.rel.sdata)
PROVIDE (__runtime_reloc_stop = .);
@@ -178,11 +180,26 @@ SECTIONS
PROVIDE (etext = .);
_etext = .;
- .eh_frame_hdr . : AT (LOADADDR (.rel.sdata) + SIZEOF(.rel.sdata)) { *(.eh_frame_hdr) }
- .eh_frame . : AT (LOADADDR (.eh_frame_hdr) + SIZEOF(.eh_frame_hdr)) { KEEP (*(.eh_frame)) }
- .gcc_except_table . : AT (LOADADDR (.eh_frame) + SIZEOF(.eh_frame)) { *(.gcc_except_table) }
- .jcr . : AT (LOADADDR (.gcc_except_table) + SIZEOF(.gcc_except_table)) { KEEP (*(.jcr)) }
- .ctors . : AT (LOADADDR (.jcr) + SIZEOF(.jcr))
+ .eh_frame_hdr : { *(.eh_frame_hdr) *(.eh_frame_entry .eh_frame_entry.*) }
+ .eh_frame : { KEEP (*(.eh_frame)) }
+ .gcc_except_table : { *(.gcc_except_table .gcc_except_table.*) }
+ .gnu_extab : { *(.gnu_extab .gnu_extab.*) }
+ .jcr : { KEEP (*(.jcr)) }
+ .init_array :
+ {
+ PROVIDE_HIDDEN (__init_array_start = .);
+ KEEP (*(SORT(.init_array.*)))
+ KEEP (*(.init_array))
+ PROVIDE_HIDDEN (__init_array_end = .);
+ }
+ .fini_array :
+ {
+ PROVIDE_HIDDEN (__fini_array_start = .);
+ KEEP (*(SORT(.fini_array.*)))
+ KEEP (*(.fini_array))
+ PROVIDE_HIDDEN (__fini_array_end = .);
+ }
+ .ctors :
{
/* gcc uses crtbegin.o to find the start of
the constructors, so we make sure it is
@@ -206,7 +223,7 @@ SECTIONS
KEEP (*(.ctors))
}
- .dtors . : AT (LOADADDR (.ctors) + SIZEOF(.ctors))
+ .dtors :
{
KEEP (*crtbegin.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
diff --git a/libgloss/mips/uhi64_n32.ld b/libgloss/mips/uhi64_n32.ld
index d68f2eaaa..2ca0b4c11 100644
--- a/libgloss/mips/uhi64_n32.ld
+++ b/libgloss/mips/uhi64_n32.ld
@@ -125,10 +125,12 @@ SECTIONS
. = ALIGN(8);
} = 0
- PROVIDE (__flash_app_start = SIZEOF(.bootrom) + __flash_start);
+ PROVIDE (__flash_app_start = DEFINED(__xip)
+ ? ALIGN(__flash_start + SIZEOF(.bootrom), 0x1000)
+ : __flash_start + SIZEOF(.bootrom));
__aligned_app_start = DEFINED(__xip)
- ? __bev_override + SIZEOF(.bootrom)
+ ? ALIGN(__bev_override + SIZEOF(.bootrom), 0x1000)
: ALIGN(__app_start, 0x1000);
PROVIDE (__ebase_size = 0x200);
@@ -155,7 +157,7 @@ SECTIONS
. = ALIGN(8);
} = 0
- .text . : AT (LOADADDR (.exception_vector) + SIZEOF(.exception_vector)) {
+ .text : {
_ftext = . ;
PROVIDE (eprol = .);
*(.text)
@@ -164,13 +166,13 @@ SECTIONS
*(.mips16.fn.*)
*(.mips16.call.*)
}
- .init . : AT (LOADADDR (.text) + SIZEOF(.text)) {
+ .init : {
KEEP (*(.init))
}
- .fini . : AT (LOADADDR (.init) + SIZEOF(.init)) {
+ .fini : {
KEEP (*(.fini))
}
- .rel.sdata . : AT (LOADADDR (.fini) + SIZEOF(.fini)) {
+ .rel.sdata : {
PROVIDE (__runtime_reloc_start = .);
*(.rel.sdata)
PROVIDE (__runtime_reloc_stop = .);
@@ -178,11 +180,26 @@ SECTIONS
PROVIDE (etext = .);
_etext = .;
- .eh_frame_hdr . : AT (LOADADDR (.rel.sdata) + SIZEOF(.rel.sdata)) { *(.eh_frame_hdr) }
- .eh_frame . : AT (LOADADDR (.eh_frame_hdr) + SIZEOF(.eh_frame_hdr)) { KEEP (*(.eh_frame)) }
- .gcc_except_table . : AT (LOADADDR (.eh_frame) + SIZEOF(.eh_frame)) { *(.gcc_except_table) }
- .jcr . : AT (LOADADDR (.gcc_except_table) + SIZEOF(.gcc_except_table)) { KEEP (*(.jcr)) }
- .ctors . : AT (LOADADDR (.jcr) + SIZEOF(.jcr))
+ .eh_frame_hdr : { *(.eh_frame_hdr) *(.eh_frame_entry .eh_frame_entry.*) }
+ .eh_frame : { KEEP (*(.eh_frame)) }
+ .gcc_except_table : { *(.gcc_except_table .gcc_except_table.*) }
+ .gnu_extab : { *(.gnu_extab .gnu_extab.*) }
+ .jcr : { KEEP (*(.jcr)) }
+ .init_array :
+ {
+ PROVIDE_HIDDEN (__init_array_start = .);
+ KEEP (*(SORT(.init_array.*)))
+ KEEP (*(.init_array))
+ PROVIDE_HIDDEN (__init_array_end = .);
+ }
+ .fini_array :
+ {
+ PROVIDE_HIDDEN (__fini_array_start = .);
+ KEEP (*(SORT(.fini_array.*)))
+ KEEP (*(.fini_array))
+ PROVIDE_HIDDEN (__fini_array_end = .);
+ }
+ .ctors :
{
/* gcc uses crtbegin.o to find the start of
the constructors, so we make sure it is
@@ -206,7 +223,7 @@ SECTIONS
KEEP (*(.ctors))
}
- .dtors . : AT (LOADADDR (.ctors) + SIZEOF(.ctors))
+ .dtors :
{
KEEP (*crtbegin.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
--
2.25.1
More information about the Newlib
mailing list