unified VC4 and ARM runtime code (including C++ runtime), updated some minor bits
[rpi-open-firmware.git] / lib / cxx_runtime.cc
1 /*=============================================================================
2 Copyright (C) 2016-2017 Authors of rpi-open-firmware
3 All rights reserved.
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 FILE DESCRIPTION
16 Crappy C++ runtime.
17
18 =============================================================================*/
19
20 #include <stdint.h>
21 #include <hardware.h>
22 #include <lib/runtime.h>
23
24 extern uintptr_t* __init_array_start;
25 extern uintptr_t* __init_array_end;
26
27 void* operator new[] (size_t sz) {
28 return malloc(sz);
29 }
30
31 void* operator new (size_t sz) {
32 return malloc(sz);
33 }
34
35 void operator delete (void* ptr) {
36 free(ptr);
37 }
38
39 void operator delete[] (void* ptr) {
40 free(ptr);
41 }
42
43 extern "C" void __cxa_pure_virtual() {
44 panic("__cxa_pure_virtual!");
45 }
46
47 void __cxx_init() {
48 unsigned ctor_count = (unsigned)(&__init_array_end - &__init_array_start);
49 void (*static_ctor)();
50
51 printf("__cxx_init: calling %d static constructors (0x%X - 0x%X) ...\n", ctor_count, &__init_array_start, &__init_array_end);
52
53 for (unsigned i = 0; i < ctor_count; i++) {
54 uintptr_t* ptr = (((uintptr_t*)&__init_array_start) + i);
55 static_ctor = reinterpret_cast<void (*)()>(*ptr);
56 static_ctor();
57 }
58 }
This page took 0.093532 seconds and 4 git commands to generate.