Kernel/LibC: Add support for init_array and fini_array
This commit is contained in:
@@ -216,6 +216,14 @@ higher_half:
|
||||
# call global constuctors
|
||||
call _init
|
||||
|
||||
movl $__init_array_start, %ebx
|
||||
jmp 2f
|
||||
1: movl (%ebx), %eax
|
||||
call *%eax
|
||||
addl $4, %ebx
|
||||
2: cmpl $__init_array_end, %ebx
|
||||
jne 1b
|
||||
|
||||
# call to the kernel itself (clear ebp for stacktrace)
|
||||
xorl %ebp, %ebp
|
||||
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
.section .text
|
||||
|
||||
.global _start
|
||||
_start:
|
||||
# Set up end of the stack frame linked list.
|
||||
movl $0, %ebp
|
||||
pushl %ebp # rip=0
|
||||
pushl %ebp # rbp=0
|
||||
movl %esp, %ebp
|
||||
|
||||
# Prepare signals, memory allocation, stdio and such.
|
||||
#call initialize_standard_library
|
||||
|
||||
# Run the global constructors.
|
||||
call _init
|
||||
|
||||
# Run main
|
||||
call main
|
||||
|
||||
# Terminate the process with the exit code.
|
||||
movl %eax, %edi
|
||||
call exit
|
||||
.size _start, . - _start
|
||||
@@ -1,9 +1,9 @@
|
||||
/* x86 crti.s */
|
||||
/* i686 crti.s */
|
||||
.section .init
|
||||
.global _init
|
||||
.type _init, @function
|
||||
_init:
|
||||
push %ebp
|
||||
pushl %ebp
|
||||
movl %esp, %ebp
|
||||
/* gcc will nicely put the contents of crtbegin.o's .init section here. */
|
||||
|
||||
@@ -11,6 +11,14 @@ _init:
|
||||
.global _fini
|
||||
.type _fini, @function
|
||||
_fini:
|
||||
push %ebp
|
||||
pushl %ebp
|
||||
movl %esp, %ebp
|
||||
/* gcc will nicely put the contents of crtbegin.o's .fini section here. */
|
||||
|
||||
.section .init_array
|
||||
.global __init_array_start
|
||||
__init_array_start:
|
||||
|
||||
.section .fini_array
|
||||
.global __fini_array_start
|
||||
__fini_array_start:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* x86 crtn.s */
|
||||
/* i686 crtn.s */
|
||||
.section .init
|
||||
/* gcc will nicely put the contents of crtend.o's .init section here. */
|
||||
popl %ebp
|
||||
@@ -8,3 +8,11 @@
|
||||
/* gcc will nicely put the contents of crtend.o's .fini section here. */
|
||||
popl %ebp
|
||||
ret
|
||||
|
||||
.section .init_array
|
||||
.global __init_array_end
|
||||
__init_array_end:
|
||||
|
||||
.section .fini_array
|
||||
.global __fini_array_end
|
||||
__fini_array_end:
|
||||
|
||||
Reference in New Issue
Block a user