3 * Runtime functions for C++
5 * Copyright (C) 2008-2009 Pawel Dziepak
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 /* This is set of functions that are needed to correctly execute code written
24 * in the C++ programming language. Main part of this file is runtime_start()
25 * function, which calls all constructors of global and static objects.
28 #include "manes/error.h"
30 /* Calls constructors of all global and static objects */
31 void runtime_start() {
35 const unsigned int end
= 0x80000;
37 unsigned int bss_size
= (unsigned int)&_bss_end
- (unsigned int)&_bss
+ 0x10000;
38 char *bss
= (char*)&_bss
;
40 char *to
= (char*)0x200000;
41 char *from
= (char*)0x100000;
42 for (unsigned int i
= 0; i
< end
; i
++)
45 /* Clear bss section */
46 for (unsigned int i
= 0; i
< bss_size
; i
++)
49 /* Threre is a constructors list: __CTOR_LIST__
50 * First entry of the list is the number of constructors.
51 * Other entries are pointers to the constructors.
52 * Everyting is set in the linker script
54 extern void (*__CTOR_LIST__
)();
55 void (**constr
)() = &__CTOR_LIST__
;
56 int number
= *(int*)constr
;
58 for (int i
= 1; i
<= number
; i
++) (constr
[i
])();
61 /* Code that should be executed when program exit, which won't ever
64 void *__dso_handle
__attribute__((weak
));
65 extern "C" void __cxa_atexit(void (*)(void *), void *, void *) {
66 /* manes::error er("runtime: attempt to terminate kernel process");
70 namespace __cxxabiv1
{
71 /* Function shows error message when a call to pure virtual function
73 extern "C" void __cxa_pure_virtual(void) {
74 manes::error
er("runtime: call to pure virtual function");