Skip to content

Commit 7e5465b

Browse files
junjiemao1shenfang2019
authored andcommitted
cstart: initialize .bss
The initialization of .bss is available only when the test is loaded by an ELF loader, which is not the case when it is started directly by a multiboot-compliant bootloader. This patch explicitly clears .bss, except the stack which is already in use when initializing .bss. Signed-off-by: Junjie Mao <[email protected]>
1 parent f174ee6 commit 7e5465b

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

lib/x86/setup.c

+8
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "processor.h"
1919
#include "smp.h"
2020

21+
extern char bss_start;
2122
extern char edata;
2223

2324
struct mbi_bootinfo {
@@ -55,6 +56,8 @@ struct mbi_mem {
5556
void setup_env(char *env, int size);
5657
void setup_multiboot(struct mbi_bootinfo *bootinfo);
5758
void setup_libcflat(void);
59+
void bss_init(void);
60+
5861

5962
char *initrd;
6063
u32 initrd_size;
@@ -151,6 +154,11 @@ unsigned long setup_tss(u8 *stacktop)
151154
}
152155
#endif
153156

157+
void bss_init(void)
158+
{
159+
memset(&bss_start, 0, &edata - &bss_start);
160+
}
161+
154162
void setup_multiboot(struct mbi_bootinfo *bi)
155163
{
156164
struct mbi_module *mods;

x86/cstart64.S

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ipi_vector = 0x20
55

66
max_cpus = MAX_TEST_CPUS
77

8-
.bss
8+
.section stack
99

1010
. = . + 4096 * max_cpus
1111
.align 16
@@ -104,6 +104,7 @@ gdt32_end:
104104

105105
.code64
106106
start64:
107+
call bss_init
107108
call load_idt
108109
load_tss
109110
call reset_apic

x86/flat.lds

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ SECTIONS
1414
. = ALIGN(16);
1515
.rodata : { *(.rodata) }
1616
. = ALIGN(16);
17+
.stack : { *(stack) }
18+
. = ALIGN(16);
19+
bss_start = .;
1720
.bss : { *(.bss) }
1821
. = ALIGN(4K);
1922
edata = .;

0 commit comments

Comments
 (0)