summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAleksa Vučković <aleksav013@gmail.com>2021-10-07 12:04:07 +0200
committerAleksa Vučković <aleksav013@gmail.com>2021-10-07 12:04:07 +0200
commited5d024c8b4961b6d722bf45d2c98846afdc1191 (patch)
tree9c3e710bf1f1c64c7cebbffe8527a7c765b96228 /src
parenta9f29cfe168f634434047b55ab16b760e9020680 (diff)
Calling global constructors
Diffstat (limited to 'src')
-rw-r--r--src/boot.s1
-rw-r--r--src/crti.s16
-rw-r--r--src/crtn.s10
-rw-r--r--src/kernel.c9
4 files changed, 35 insertions, 1 deletions
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<i;j++) terminal_writestring("#");
terminal_writestring("Hello, kernel World!\n");
}
+ terminal_writestring(rec);
}