Skip to content

Commit

Permalink
misc: Unwind both .data and .bss
Browse files Browse the repository at this point in the history
  • Loading branch information
mintsuki committed Dec 12, 2021
1 parent 2f66e0f commit 88cd9dc
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 27 deletions.
4 changes: 0 additions & 4 deletions stage23/entry.s2.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,12 @@ void entry(uint8_t boot_drive, int boot_from) {

term_notready();

{
struct rm_regs r = {0};
r.eax = 0x0003;
rm_int(0x10, &r, &r);

current_video_mode = -1;

outb(0x3d4, 0x0a);
outb(0x3d5, 0x20);
}

init_e820();
init_memmap();
Expand Down
4 changes: 3 additions & 1 deletion stage23/linker.ld
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ SECTIONS
}

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

Expand All @@ -54,6 +55,7 @@ SECTIONS
*(COMMON)
*(.bss*)
bss_end = .;
data_end = .;
}

.symtab 0 : {
Expand Down
4 changes: 3 additions & 1 deletion stage23/linker_dbg.ld
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ SECTIONS
}

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

Expand All @@ -54,6 +55,7 @@ SECTIONS
*(COMMON)
*(.bss*)
bss_end = .;
data_end = .;
}

.symtab 0 : {
Expand Down
4 changes: 3 additions & 1 deletion stage23/linker_nomap.ld
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ SECTIONS
}

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

Expand All @@ -54,6 +55,7 @@ SECTIONS
*(COMMON)
*(.bss*)
bss_end = .;
data_end = .;
}

.symtab 0 : {
Expand Down
4 changes: 3 additions & 1 deletion stage23/linker_stage2only.ld
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ SECTIONS
}

.stage2.data : {
*.s2.o(.data*)
*.s2.o(.rodata*)
data_begin = .;
*.s2.o(.data*)
stage2_map = .;
stage3_common = .;
full_map = .;
Expand All @@ -49,6 +50,7 @@ SECTIONS
*(COMMON)
*(.bss*)
bss_end = .;
data_end = .;
}

.symtab 0 : {
Expand Down
4 changes: 2 additions & 2 deletions stage23/linker_uefi.ld
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ SECTIONS
*(.rodata*)
*(.got.plt)
*(.got)
data_begin = .;
*(.data*)
*(.sdata)
/* the EFI loader doesn't seem to like a .bss section, so we stick
it all into .data: */
bss_begin = .;
*(.sbss)
*(.scommon)
*(.dynbss)
*(.bss)
*(COMMON)
bss_end = .;
data_end = .;
*(.rel.local)
*(.full_map*)
}
Expand Down
8 changes: 4 additions & 4 deletions stage23/linker_uefi32.ld
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,21 @@ SECTIONS
.data :
{
*(.rodata*)
*(.got.plt)
*(.got)
data_begin = .;
*(.data)
*(.data1)
*(.data.*)
*(.sdata)
*(.got.plt)
*(.got)
/* the EFI loader doesn't seem to like a .bss section, so we stick
it all into .data: */
bss_begin = .;
*(.sbss)
*(.scommon)
*(.dynbss)
*(.bss)
*(COMMON)
bss_end = .;
data_end = .;
*(.full_map*)
}
.note.gnu.build-id : { *(.note.gnu.build-id) }
Expand Down
8 changes: 4 additions & 4 deletions stage23/linker_uefi32_nomap.ld
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,21 @@ SECTIONS
.data :
{
*(.rodata*)
*(.got.plt)
*(.got)
data_begin = .;
*(.data)
*(.data1)
*(.data.*)
*(.sdata)
*(.got.plt)
*(.got)
/* the EFI loader doesn't seem to like a .bss section, so we stick
it all into .data: */
bss_begin = .;
*(.sbss)
*(.scommon)
*(.dynbss)
*(.bss)
*(COMMON)
bss_end = .;
data_end = .;
full_map = .;
}
.note.gnu.build-id : { *(.note.gnu.build-id) }
Expand Down
4 changes: 2 additions & 2 deletions stage23/linker_uefi_nomap.ld
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ SECTIONS
*(.rodata*)
*(.got.plt)
*(.got)
data_begin = .;
*(.data*)
*(.sdata)
/* the EFI loader doesn't seem to like a .bss section, so we stick
it all into .data: */
bss_begin = .;
*(.sbss)
*(.scommon)
*(.dynbss)
*(.bss)
*(COMMON)
bss_end = .;
data_end = .;
*(.rel.local)
full_map = .;
}
Expand Down
14 changes: 7 additions & 7 deletions stage23/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -578,10 +578,10 @@ 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_bss;
static uint8_t *rewound_data;

extern symbol bss_begin;
extern symbol bss_end;
extern symbol data_begin;
extern symbol data_end;

bool *bad_config = NULL;

Expand All @@ -591,18 +591,18 @@ static void _menu(bool timeout_enabled) {
bad_config = ext_mem_alloc(1);
}

size_t bss_size = (uintptr_t)bss_end - (uintptr_t)bss_begin;
size_t data_size = (uintptr_t)data_end - (uintptr_t)data_begin;

if (rewound_memmap != NULL) {
memcpy(bss_begin, rewound_bss, bss_size);
memcpy(data_begin, rewound_data, data_size);
memcpy(memmap, rewound_memmap, rewound_memmap_entries * sizeof(struct e820_entry_t));
memmap_entries = rewound_memmap_entries;
} else {
rewound_bss = ext_mem_alloc(bss_size);
rewound_data = ext_mem_alloc(data_size);
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_bss, bss_begin, bss_size);
memcpy(rewound_data, data_begin, data_size);
}

if (*bad_config == false) {
Expand Down

0 comments on commit 88cd9dc

Please sign in to comment.