From ed5d024c8b4961b6d722bf45d2c98846afdc1191 Mon Sep 17 00:00:00 2001 From: Aleksa Vučković Date: Thu, 7 Oct 2021 12:04:07 +0200 Subject: Calling global constructors --- src/boot.s | 1 + src/crti.s | 16 ++++++++++++++++ src/crtn.s | 10 ++++++++++ src/kernel.c | 9 ++++++++- 4 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 src/crti.s create mode 100644 src/crtn.s (limited to 'src') diff --git a/src/boot.s b/src/boot.s index 172fd14..a043012 100644 --- a/src/boot.s +++ b/src/boot.s @@ -84,6 +84,7 @@ _start: stack since (pushed 0 bytes so far), so the alignment has thus been preserved and the call is well defined. */ + call _init call kernel_main /* diff --git a/src/crti.s b/src/crti.s new file mode 100644 index 0000000..30dd4ea --- /dev/null +++ b/src/crti.s @@ -0,0 +1,16 @@ +/* x86 crti.s */ +.section .init +.global _init +.type _init, @function +_init: + push %ebp + movl %esp, %ebp + /* gcc will nicely put the contents of crtbegin.o's .init section here. */ + +.section .fini +.global _fini +.type _fini, @function +_fini: + push %ebp + movl %esp, %ebp + /* gcc will nicely put the contents of crtbegin.o's .fini section here. */ diff --git a/src/crtn.s b/src/crtn.s new file mode 100644 index 0000000..1da795d --- /dev/null +++ b/src/crtn.s @@ -0,0 +1,10 @@ +/* x86 crtn.s */ +.section .init + /* gcc will nicely put the contents of crtend.o's .init section here. */ + popl %ebp + ret + +.section .fini + /* gcc will nicely put the contents of crtend.o's .fini section here. */ + popl %ebp + ret diff --git a/src/kernel.c b/src/kernel.c index dd81d33..2c71ba4 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -111,14 +111,21 @@ void terminal_writestring(const char* data) { terminal_write(data, strlen(data)); } + +char *rec; +__attribute__ ((constructor)) void foo(void) +{ + rec="aleksa"; +} void kernel_main(void) { terminal_initialize(); - for(size_t i=0;i<80;i++) + for(size_t i=0;i<50;i++) { for(size_t j=0;j