Skip to content

Commit

Permalink
Move .BSS zeroing into early assembly, avoid using section attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
fwsGonzo committed Jul 1, 2019
1 parent abd2555 commit 0064e3d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
17 changes: 5 additions & 12 deletions src/crt/c_abi.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,33 +34,26 @@ static void* multiboot_free_begin(intptr_t mb_addr)
void __init_stdlib(uint32_t mb_magic, uint32_t mb_addr)
{
assert(mb_magic == 0x2badb002);
// 1. initialize BSS area
extern char _BSS_START_;
extern char _BSS_END_;

for (char* bss = &_BSS_START_; bss < &_BSS_END_; bss++) {
*bss = 0;
}

// 2. enable printf facilities
// 1. enable printf facilities
init_printf(NULL, __serial_putchr);

// 3. find end of multiboot areas
// 2. find end of multiboot areas
void* free_begin = multiboot_free_begin(mb_addr);
assert(free_begin >= (void*) &_end);

// 4. initialize heap (malloc, etc.)
// 3. initialize heap (malloc, etc.)
extern void __init_heap(void*);
__init_heap(free_begin);

#ifdef EH_ENABLED
/// 5. initialize exceptions before we run constructors
/// 4. initialize exceptions before we run constructors
extern char __eh_frame_start[];
extern void __register_frame(void*);
__register_frame(&__eh_frame_start);
#endif

// 6. call global C/C++ constructors
// 5. call global C/C++ constructors
extern void(*__init_array_start [])();
extern void(*__init_array_end [])();
int count = __init_array_end - __init_array_start;
Expand Down
2 changes: 1 addition & 1 deletion src/hw/serial1.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <stdint.h>

static const uint16_t port = 0x3F8; // Serial port 1
static char initialized __attribute__((section(".data"))) = 0;
static char initialized = 0;

static inline uint8_t inb(int port)
{
Expand Down
1 change: 0 additions & 1 deletion src/kernel/kernel_start.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ static void __init_paging()
void kernel_start(uint32_t eax, uint32_t ebx)
{
kprintf("kernel_start(eax: %x, ebx: %x)\n", eax, ebx);
assert(eax == 0x2badb002);

extern void __init_stdlib(uint32_t, uint32_t);
__init_stdlib(eax, ebx);
Expand Down
9 changes: 8 additions & 1 deletion src/kernel/start.asm
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,14 @@ rock_bottom:
rdtsc
mov DWORD [0x1014], eax

;; eax, ebx still on stack
;; zero .bss (used to be in the C portion, but easier to do here)
extern _BSS_START_
extern _BSS_END_
mov ecx, _BSS_END_
sub ecx, _BSS_START_
mov eax, 0
rep stosb

;; for 32-bit kernels just call kernel_start here
call begin_enter_longmode
add esp, 8
Expand Down

0 comments on commit 0064e3d

Please sign in to comment.