misc/bios: Update and improve linker script and related files

This commit is contained in:
mintsuki 2023-09-11 16:48:37 -05:00
parent 277cec6c88
commit 4b08bede0e
3 changed files with 32 additions and 13 deletions

View File

@ -3,7 +3,7 @@ extern bss_end
extern entry
extern gdt
section .entry
section .entry progbits alloc exec nowrite align=16
global _start
_start:

View File

@ -5,8 +5,10 @@ ENTRY(_start)
PHDRS
{
text_s2 PT_LOAD FLAGS((1 << 0) | (1 << 2)) ;
rodata_s2 PT_LOAD FLAGS((1 << 2)) ;
data_s2 PT_LOAD FLAGS((1 << 1) | (1 << 2)) ;
text_s3 PT_LOAD FLAGS((1 << 0) | (1 << 2)) ;
rodata_s3 PT_LOAD FLAGS((1 << 2)) ;
data_s3 PT_LOAD FLAGS((1 << 1) | (1 << 2)) ;
}
@ -21,17 +23,13 @@ SECTIONS
*libgcc*.a:*(.text .text.*)
} :text_s2
.data.stage2 : {
.rodata.stage2 : {
*.s2.o(.rodata .rodata.*)
*libgcc*.a:*(.rodata .rodata.*)
build_id_s2 = .;
KEEP(*build-id.s2.o(*))
*.s2.o(.no_unwind)
s2_data_begin = .;
*.s2.o(.data .data.*)
*libgcc*.a:*(.data .data.*)
s2_data_end = .;
*.s2.o(.rodata .rodata.*)
*libgcc*.a:*(.rodata .rodata.*)
#ifdef LINKER_STAGE2ONLY
/* stage2 missing symbols overrides */
stage2_map = .;
@ -54,6 +52,15 @@ SECTIONS
*(.stage2_map)
#endif
#endif
} :rodata_s2
.data.stage2 : {
s2_data_begin = .;
*.s2.o(.data .data.*)
*libgcc*.a:*(.data .data.*)
s2_data_end = .;
*.s2.o(.no_unwind)
} :data_s2
#ifndef LINKER_STAGE2ONLY
@ -62,19 +69,25 @@ SECTIONS
*(.text .text.*)
} :text_s3
.data.stage3 : {
.rodata.stage3 : {
*(.rodata .rodata.*)
build_id_s3 = .;
KEEP(*build-id.s3.o(*))
*(.rodata .rodata.*)
#ifdef LINKER_NOMAP
full_map = .;
#else
*(.full_map)
#endif
*(.no_unwind)
} :rodata_s3
.data.stage3 : {
data_begin = .;
*(.data .data.*)
data_end = .;
*(.no_unwind)
} :data_s3
#endif
@ -88,7 +101,6 @@ SECTIONS
*(.bss .bss.*)
*(COMMON)
bss_end = .;
data_end = .;
} :data_s3
/DISCARD/ : {

View File

@ -585,6 +585,7 @@ static size_t rewound_memmap_entries = 0;
static no_unwind uint8_t *rewound_data;
#if defined (BIOS)
static no_unwind uint8_t *rewound_s2_data;
static no_unwind uint8_t *rewound_bss;
#endif
extern symbol data_begin;
@ -592,6 +593,8 @@ extern symbol data_end;
#if defined (BIOS)
extern symbol s2_data_begin;
extern symbol s2_data_end;
extern symbol bss_begin;
extern symbol bss_end;
#endif
static void menu_init_term(void) {
@ -629,12 +632,14 @@ noreturn void _menu(bool first_run) {
size_t data_size = (uintptr_t)data_end - (uintptr_t)data_begin;
#if defined (BIOS)
size_t s2_data_size = (uintptr_t)s2_data_end - (uintptr_t)s2_data_begin;
size_t bss_size = (uintptr_t)bss_end - (uintptr_t)bss_begin;
#endif
if (rewound_memmap != NULL) {
memcpy(data_begin, rewound_data, data_size);
#if defined (BIOS)
memcpy(s2_data_begin, rewound_s2_data, s2_data_size);
memcpy(bss_begin, rewound_bss, bss_size);
#endif
memcpy(memmap, rewound_memmap, rewound_memmap_entries * sizeof(struct memmap_entry));
memmap_entries = rewound_memmap_entries;
@ -642,6 +647,7 @@ noreturn void _menu(bool first_run) {
rewound_data = ext_mem_alloc(data_size);
#if defined (BIOS)
rewound_s2_data = ext_mem_alloc(s2_data_size);
rewound_bss = ext_mem_alloc(bss_size);
#endif
rewound_memmap = ext_mem_alloc(256 * sizeof(struct memmap_entry));
memcpy(rewound_memmap, memmap, memmap_entries * sizeof(struct memmap_entry));
@ -649,6 +655,7 @@ noreturn void _menu(bool first_run) {
memcpy(rewound_data, data_begin, data_size);
#if defined (BIOS)
memcpy(rewound_s2_data, s2_data_begin, s2_data_size);
memcpy(rewound_bss, bss_begin, bss_size);
#endif
}