3 * Runtime functions for C++
5 * Copyright (C) 2008 Pawel Dziepak
7 * This is set of functions that are needed to correctly execute code written
8 * in the C++ programming language. Main part of this file is runtime_start()
9 * function, which calls all constructors of global and static objects.
12 #include "manes/error.h"
14 /* Calls constructors of all global and static objects */
15 void runtime_start() {
18 int bss_size
= (int)&_bss_end
- (int)&_bss
;
19 char *bss
= (char*)&_bss
;
21 /* Clear bss section */
22 for (int i
= 0; i
< (int)bss_size
; i
++) bss
[i
] = 0;
24 /* Threre is a constructors list: __CTOR_LIST__
25 * First entry of the list is the number of constructors.
26 * Other entries are pointers to the constructors.
27 * Everyting is set in the linker script
29 extern void (*__CTOR_LIST__
)();
30 void (**constr
)() = &__CTOR_LIST__
;
31 int number
= *(int*)constr
;
33 for (int i
= 1; i
<= number
; i
++) (constr
[i
])();
36 /* Code that should be executed when program exit, which won't ever
39 void *__dso_handle
__attribute__((weak
));
40 extern "C" void __cxa_atexit(void (*)(void *), void *, void *) {
41 /* manes::error er("runtime: attempt to terminate kernel process");
45 namespace __cxxabiv1
{
46 /* Function shows error message when a call to pure virtual function
48 extern "C" void __cxa_pure_virtual(void) {
49 manes::error
er("runtime: call to pure virtual function");