This repository has been archived by the owner on Dec 6, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
sys.cpp
146 lines (126 loc) · 3.43 KB
/
sys.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//!
//! \file
//! \brief theCore system initialization module.
//!
#include <stdint.h>
#include <stddef.h>
#include <common/irq.hpp>
#include <common/console.hpp>
#include <common/execution.hpp>
// TODO: move it somewhere
void operator delete(void *) noexcept
{
// TODO: call to abort routine
for(;;);
}
// TODO: move it somewhere
void operator delete(void *, unsigned int) noexcept
{
// TODO: call to abort routine
for(;;);
}
// TODO: move this to toolchain-dependent module
#if UINT32_MAX == UINTPTR_MAX
#define STACK_CHK_GUARD 0xe2dee396
#else
#define STACK_CHK_GUARD 0x595e9fbd94fda766
#endif
// TODO: move this to toolchain-dependent module
uintptr_t __stack_chk_guard = STACK_CHK_GUARD;
// TODO: move this to toolchain-dependent module
extern "C" __attribute__((noreturn))
void __stack_chk_fail(void)
{
// TODO: call to abort routine
for(;;);
}
// TODO: move this to toolchain-dependent module
extern "C"
int atexit (void (*func)(void))
{
(void) func;
return 0;
}
// TODO: move this to toolchain-dependent module
extern "C"
int __cxa_guard_acquire(int *gv)
{
// Disable interrupts to prevent concurent access
ecl::irq::disable();
if (*gv == 1) {
// Already locked
return 0;
} else {
*gv = 1;
return 1;
}
}
// TODO: move this to toolchain-dependent module
extern "C"
void __cxa_guard_release(int *gv)
{
(void) gv;
// Object constructed. It is safe to enable interrupts.
ecl::irq::enable();
}
extern "C" void platform_init();
extern "C" void board_init();
extern "C" void kernel_main();
int main();
//! Lowest level C-routine inside the Core
//! \details Performs essential initialization before construction of C++ objects
//! and kernel initialization.
extern "C" void core_main()
{
platform_init();
board_init();
#ifdef CONFIG_USE_BYPASS_CONSOLE
// Dirty hack to make sure pin configuration is established before
// bypass console will be used.
// It should be fixed by configuring console GPIO directly in the platform,
// not in the user's `board_init()` routine. See issue #151.
ecl::wait_for(50);
#endif // CONFIG_USE_BYPASS_CONSOLE
kernel_main();
}
//! Early-main routine performs final initialization steps.
//! \details All global objects must be constructed before entering user's
//! main routine.
//! Kernel in responsible for calling early_main() after it (kernel) will be
//! completely ready.
//! \todo Consider specifying it with noreturn attribute.
extern "C" void early_main()
{
// Platform console subsystem is ready at this stage
ecl::bypass_greeting();
extern uint32_t __init_array_start;
extern uint32_t __init_array_end;
for (uint32_t *p = &__init_array_start; p < &__init_array_end; ++p) {
// Iterator points to a memory which contains an address of a
// initialization function.
// Equivalent of:
// void (*fn)() = p;
// fn();
((void (*)()) *p)();
}
main();
for(;;); // TODO: call to the abort routine
}
// TODO: move this to toolchain-dependent module
extern "C" void __cxa_pure_virtual()
{
// Abort
for(;;);
}
namespace std
{
// TODO: move this to toolchain-dependent module
void __throw_bad_function_call()
{
// TODO: abort
for (;;);
}
}