From 393808e198a2f6bf32f0af235f13f76e2c08a894 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Thu, 9 Jun 2011 08:18:12 +0200 Subject: [PATCH] fix bug in the initializtion of the BSS section - DO NOT LONGER USE the compiler flag "-fno-zero-initialized-in-bss" --- Makefile.example | 4 ++-- arch/x86/kernel/entry.asm | 2 +- arch/x86/kernel/gdt.c | 4 ++-- arch/x86/kernel/multiboot.c | 2 +- kernel/init.c | 12 ++++++++++++ link.ld | 5 ++--- 6 files changed, 20 insertions(+), 9 deletions(-) diff --git a/Makefile.example b/Makefile.example index 71ff1725..3e87db1e 100644 --- a/Makefile.example +++ b/Makefile.example @@ -26,9 +26,9 @@ MAKE = make NASMFLAGS = -felf32 -g INCLUDE = -I$(TOPDIR)/include -I$(TOPDIR)/arch/$(ARCH)/include -I$(TOPDIR)/lwip/src/include -I$(TOPDIR)/lwip/src/include/ipv4 -I$(TOPDIR)/drivers # Compiler options for final code -CFLAGS = -g -m32 -march=i586 -Wall -O2 -fno-zero-initialized-in-bss -fno-builtin -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc $(INCLUDE) -fno-stack-protector +CFLAGS = -g -m32 -march=i586 -Wall -O2 -fno-builtin -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc $(INCLUDE) -fno-stack-protector # Compiler options for debuuging -#CFLAGS = -g -O -m32 -march=i586 -Wall -fno-zero-initialized-in-bss -fno-builtin -DWITH_FRAME_POINTER -nostdinc $(INCLUDE) -fno-stack-protector +#CFLAGS = -g -O -m32 -march=i586 -Wall -fno-builtin -DWITH_FRAME_POINTER -nostdinc $(INCLUDE) -fno-stack-protector ARFLAGS = rsv RM = rm -rf LDFLAGS = -T link.ld -z max-page-size=4096 --defsym __BUILD_DATE=$(shell date +'%Y%m%d') --defsym __BUILD_TIME=$(shell date +'%H%M%S') diff --git a/arch/x86/kernel/entry.asm b/arch/x86/kernel/entry.asm index 5610c6b8..6fb00652 100644 --- a/arch/x86/kernel/entry.asm +++ b/arch/x86/kernel/entry.asm @@ -73,7 +73,7 @@ stublet: ; clears the current pgd entry xor eax, eax mov cr3, eax -; disable SSE support (TODO) +; at this stage, we disable the SSE support mov eax, cr4 and eax, 0xfffbf9ff mov cr4, eax diff --git a/arch/x86/kernel/gdt.c b/arch/x86/kernel/gdt.c index 5be409c6..53a83b95 100644 --- a/arch/x86/kernel/gdt.c +++ b/arch/x86/kernel/gdt.c @@ -28,10 +28,10 @@ gdt_ptr_t gp; static tss_t task_state_segments[MAX_TASKS] __attribute__ ((aligned (PAGE_SIZE))); -static unsigned char kstacks[MAX_TASKS][KERNEL_STACK_SIZE] __attribute__ ((aligned (PAGE_SIZE))); +static unsigned char kstacks[MAX_TASKS][KERNEL_STACK_SIZE] __attribute__ ((aligned (PAGE_SIZE) section (".data"))); // currently, our kernel has full access to the ioports static gdt_entry_t gdt[GDT_ENTRIES] = {[0 ... GDT_ENTRIES-1] = {0, 0, 0, 0, 0, 0}}; -unsigned char* default_stack_pointer = kstacks[0] + KERNEL_STACK_SIZE - sizeof(size_t); +unsigned char* default_stack_pointer __attribute__ ((section (".data"))) = kstacks[0] + KERNEL_STACK_SIZE - sizeof(size_t); /* * This is in start.asm. We use this to properly reload diff --git a/arch/x86/kernel/multiboot.c b/arch/x86/kernel/multiboot.c index d57b5f96..ec124479 100644 --- a/arch/x86/kernel/multiboot.c +++ b/arch/x86/kernel/multiboot.c @@ -37,7 +37,7 @@ */ /** Global multiboot information structure pointer */ -multiboot_info_t* mb_info = NULL; +multiboot_info_t* mb_info __attribute__ ((section (".data"))) = NULL; #endif /** @brief initialization procedure for Multiboot information structure diff --git a/kernel/init.c b/kernel/init.c index 2ba3b81f..c4dea9b7 100644 --- a/kernel/init.c +++ b/kernel/init.c @@ -43,10 +43,22 @@ void ping_init(void); static volatile int done = 0; +/* + * Note that linker symbols are not variables, they have no memory allocated for + * maintaining a value, rather their address is their value. + */ +extern const void bss_start; +extern const void bss_end; + int lowlevel_init(void) { + // initialize .bss section + memset((void*)&bss_start, 0x00, ((size_t) &bss_end - (size_t) &bss_start)); + koutput_init(); + //kprintf("Now, the BSS section (0x%x - 0x%x) is initialized.\n", (size_t) &bss_start, (size_t) &bss_end); + return 0; } diff --git a/link.ld b/link.ld index bbb2a9d4..ad03b8f5 100644 --- a/link.ld +++ b/link.ld @@ -13,9 +13,6 @@ SECTIONS .text ALIGN(4096) : AT(ADDR(.text)) { *(.text) } - .rdata ALIGN(4096) : AT(ADDR(.rdata)) { - *(.rdata) - } .rodata ALIGN(4096) : AT(ADDR(.rodata)) { *(.rodata) *(.rodata.*) @@ -23,8 +20,10 @@ SECTIONS .data ALIGN(4096) : AT(ADDR(.data)) { *(.data) } + bss_start = .; .bss ALIGN(4096) : AT(ADDR(.bss)) { *(.bss) } + bss_end = .; kernel_end = .; }