From e4e4007fbbeede6f9a59dab6327f0ef3a4675801 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Sun, 12 Sep 2021 15:07:26 +0200 Subject: init: allocate bss at runtime --- src/init/linker.ld | 2 ++ src/init/main.c | 14 +++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) (limited to 'src/init') diff --git a/src/init/linker.ld b/src/init/linker.ld index a59308d..efb44fd 100644 --- a/src/init/linker.ld +++ b/src/init/linker.ld @@ -17,9 +17,11 @@ SECTIONS { *(.data) } + _bss_start = .; .bss BLOCK(4K) : ALIGN(4K) { *(COMMON) *(.bss) } + _bss_end = .; } diff --git a/src/init/main.c b/src/init/main.c index dc5a975..78576aa 100644 --- a/src/init/main.c +++ b/src/init/main.c @@ -6,28 +6,28 @@ #define argify(str) str, sizeof(str) - 1 #define log(str) _syscall_write(tty_fd, argify(str)) -__attribute__((section("text"))) -int tty_fd; +extern char _bss_start; // provided by the linker +extern char _bss_end; -int test; +int tty_fd; void fs_test(void); int main(void) { + // allocate bss + _syscall_memflag(&_bss_start, &_bss_end - &_bss_start, MEMFLAG_PRESENT); + tty_fd = _syscall_open("/tty", sizeof("/tty") - 1); if (tty_fd < 0) _syscall_exit(argify("couldn't open tty")); log(" opened /tty "); - _syscall_memflag(&test, sizeof(int), MEMFLAG_PRESENT); - test = 0; // would cause a pagefault without the memflag call - fs_test(); _syscall_exit(argify("my job here is done.")); } void fs_test(void) { - static char buf[64] __attribute__((section("text"))); + static char buf[64]; int len = 64; handle_t front, back, file; front = _syscall_fs_create(&back); -- cgit v1.2.3