Skip to content

Commit

Permalink
build: BIOS linker scripts adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
mintsuki committed Dec 19, 2021
1 parent ed82bd6 commit 66ac709
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 48 deletions.
17 changes: 9 additions & 8 deletions decompressor/linker.ld
Original file line number Diff line number Diff line change
@@ -1,39 +1,40 @@
OUTPUT_FORMAT(elf32-i386)
OUTPUT_ARCH(i386)
ENTRY(_start)

SECTIONS
{
. = 0x70000;

.text : {
KEEP(*(.entry*))
*(.text*)
*(.entry)
*(.text .text.*)
}

.rodata : {
*(.rodata*)
*(.rodata .rodata.*)
}

.data : {
*(.data*)
*(.data .data.*)
}

.bss : {
bss_begin = .;
*(COMMON)
*(.bss*)
*(.bss .bss.*)
bss_end = .;
}

.symtab : {
.symtab 0 : {
*(.symtab)
}

.strtab : {
.strtab 0 : {
*(.strtab)
}

.shstrtab : {
.shstrtab 0 : {
*(.shstrtab)
}

Expand Down
26 changes: 15 additions & 11 deletions stage23/linker.ld
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
OUTPUT_FORMAT(elf32-i386)
OUTPUT_ARCH(i386)
ENTRY(_start)

SECTIONS
{
. = 0x8000;

.entry : {
*(.entry*)
*(.entry)
}

.realmode : {
*(.realmode*)
*(.realmode)
}

.stage2.text : {
*.s2.o(.text*)
*.s2.o(.text .text.*)
}

.stage2.build-id : {
Expand All @@ -23,14 +24,17 @@ SECTIONS
}

.stage2.data : {
*.s2.o(.data*)
*.s2.o(.rodata*)
*.s2.o(.no_unwind)
s2_data_begin = .;
*.s2.o(.data .data.*)
s2_data_end = .;
*.s2.o(.rodata .rodata.*)
*(.stage2_map)
}

.stage3.text : {
stage3_addr = .;
*(.text*)
*(.text .text.*)
}

.stage3.build-id : {
Expand All @@ -39,11 +43,11 @@ SECTIONS
}

.stage3.data : {
*(.rodata*)
*(.full_map*)
*(.no_unwind*)
*(.rodata .rodata.*)
*(.full_map)
*(.no_unwind)
data_begin = .;
*(.data*)
*(.data .data.*)
limine_sys_size = . - 0x8000;
}

Expand All @@ -54,7 +58,7 @@ SECTIONS
.bss : {
bss_begin = .;
*(COMMON)
*(.bss*)
*(.bss .bss.*)
bss_end = .;
data_end = .;
}
Expand Down
26 changes: 15 additions & 11 deletions stage23/linker_dbg.ld
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
OUTPUT_FORMAT(elf32-i386)
OUTPUT_ARCH(i386)
ENTRY(_start)

SECTIONS
{
. = 0x8000;

.entry : {
*(.entry*)
*(.entry)
}

.realmode : {
*(.realmode*)
*(.realmode)
}

.stage2.text : {
*.s2.o(.text*)
*.s2.o(.text .text.*)
}

.stage2.build-id : {
Expand All @@ -23,14 +24,17 @@ SECTIONS
}

.stage2.data : {
*.s2.o(.data*)
*.s2.o(.rodata*)
*.s2.o(.no_unwind)
s2_data_begin = .;
*.s2.o(.data .data.*)
s2_data_end = .;
*.s2.o(.rodata .rodata.*)
*(.stage2_map)
}

.stage3.text : {
stage3_addr = .;
*(.text*)
*(.text .text.*)
}

.stage3.build-id : {
Expand All @@ -39,11 +43,11 @@ SECTIONS
}

.stage3.data : {
*(.rodata*)
*(.full_map*)
*(.no_unwind*)
*(.rodata .rodata.*)
*(.full_map)
*(.no_unwind)
data_begin = .;
*(.data*)
*(.data .data.*)
limine_sys_size = . - 0x8000;
}

Expand All @@ -54,7 +58,7 @@ SECTIONS
.bss : {
bss_begin = .;
*(COMMON)
*(.bss*)
*(.bss .bss.*)
bss_end = .;
data_end = .;
}
Expand Down
24 changes: 14 additions & 10 deletions stage23/linker_nomap.ld
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
OUTPUT_FORMAT(elf32-i386)
OUTPUT_ARCH(i386)
ENTRY(_start)

SECTIONS
{
. = 0x8000;

.entry : {
*(.entry*)
*(.entry)
}

.realmode : {
*(.realmode*)
*(.realmode)
}

.stage2.text : {
*.s2.o(.text*)
*.s2.o(.text .text.*)
}

.stage2.build-id : {
Expand All @@ -23,14 +24,17 @@ SECTIONS
}

.stage2.data : {
*.s2.o(.data*)
*.s2.o(.rodata*)
*.s2.o(.no_unwind)
s2_data_begin = .;
*.s2.o(.data .data.*)
s2_data_end = .;
*.s2.o(.rodata .rodata.*)
*(.stage2_map)
}

.stage3.text : {
stage3_addr = .;
*(.text*)
*(.text .text.*)
}

.stage3.build-id : {
Expand All @@ -39,11 +43,11 @@ SECTIONS
}

.stage3.data : {
*(.rodata*)
*(.rodata .rodata.*)
full_map = .;
*(.no_unwind*)
*(.no_unwind)
data_begin = .;
*(.data*)
*(.data .data.*)
limine_sys_size = . - 0x8000;
}

Expand All @@ -54,7 +58,7 @@ SECTIONS
.bss : {
bss_begin = .;
*(COMMON)
*(.bss*)
*(.bss .bss.*)
bss_end = .;
data_end = .;
}
Expand Down
19 changes: 11 additions & 8 deletions stage23/linker_stage2only.ld
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
OUTPUT_FORMAT(elf32-i386)
OUTPUT_ARCH(i386)
ENTRY(_start)

SECTIONS
{
. = 0x8000;

.entry : {
*(.entry*)
*(.entry)
}

.realmode : {
*(.realmode*)
*(.realmode)
}

.stage2.text : {
*.s2.o(.text*)
*.s2.o(.text .text.*)
}

.stage2.build-id : {
Expand All @@ -23,10 +24,11 @@ SECTIONS
}

.stage2.data : {
*.s2.o(.rodata*)
*.s2.o(.no_unwind*)
data_begin = .;
*.s2.o(.data*)
*.s2.o(.no_unwind)
s2_data_begin = .;
*.s2.o(.data .data.*)
s2_data_end = .;
*.s2.o(.rodata .rodata.*)
stage2_map = .;
stage3_common = .;
full_map = .;
Expand All @@ -35,6 +37,7 @@ SECTIONS
getchar = .;
menu = .;
stage3_addr = .;
data_begin = .;
}

.stage3.build-id : {
Expand All @@ -49,7 +52,7 @@ SECTIONS
.bss : {
bss_begin = .;
*(COMMON)
*(.bss*)
*(.bss .bss.*)
bss_end = .;
data_end = .;
}
Expand Down
19 changes: 19 additions & 0 deletions stage23/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -581,24 +581,43 @@ void menu(__attribute__((unused)) bool timeout_enabled) {
static struct e820_entry_t *rewound_memmap = NULL;
static size_t rewound_memmap_entries = 0;
static uint8_t *rewound_data;
#if bios == 1
static uint8_t *rewound_s2_data;
#endif

extern symbol data_begin;
extern symbol data_end;
#if bios == 1
extern symbol s2_data_begin;
extern symbol s2_data_end;
#endif

__attribute__((noreturn, used))
static void _menu(bool timeout_enabled) {
size_t data_size = (uintptr_t)data_end - (uintptr_t)data_begin;
#if bios == 1
size_t s2_data_size = (uintptr_t)s2_data_end - (uintptr_t)s2_data_begin;
#endif

if (rewound_memmap != NULL) {
memcpy(data_begin, rewound_data, data_size);
#if bios == 1
memcpy(s2_data_begin, rewound_s2_data, s2_data_size);
#endif
memcpy(memmap, rewound_memmap, rewound_memmap_entries * sizeof(struct e820_entry_t));
memmap_entries = rewound_memmap_entries;
} else {
rewound_data = ext_mem_alloc(data_size);
#if bios == 1
rewound_s2_data = ext_mem_alloc(s2_data_size);
#endif
rewound_memmap = ext_mem_alloc(256 * sizeof(struct e820_entry_t));
memcpy(rewound_memmap, memmap, memmap_entries * sizeof(struct e820_entry_t));
rewound_memmap_entries = memmap_entries;
memcpy(rewound_data, data_begin, data_size);
#if bios == 1
memcpy(rewound_s2_data, s2_data_begin, s2_data_size);
#endif
}

if (bad_config == false) {
Expand Down

0 comments on commit 66ac709

Please sign in to comment.