forked from adamgreen/gcc4mbed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgcc4mbed.c
114 lines (86 loc) · 3.03 KB
/
gcc4mbed.c
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
/* Copyright 2012 Adam Green (http://mbed.org/users/AdamGreen/)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* Provide routines which hook the MRI debug monitor into GCC4MBED projects. */
#include <string.h>
#include <mri.h>
extern unsigned int __bss_start__;
extern unsigned int __bss_end__;
extern "C" int main(void);
extern "C" void __libc_init_array(void);
extern "C" void exit(int ErrorCode);
extern "C" void _start(void)
{
int bssSize = (int)&__bss_end__ - (int)&__bss_start__;
int mainReturnValue;
memset(&__bss_start__, 0, bssSize);
if (MRI_ENABLE)
{
__mriInit(MRI_INIT_PARAMETERS);
if (MRI_BREAK_ON_INIT)
__debugbreak();
}
__libc_init_array();
mainReturnValue = main();
exit(mainReturnValue);
}
extern "C" int __real__read(int file, char *ptr, int len);
extern "C" int __wrap__read(int file, char *ptr, int len)
{
if (MRI_SEMIHOST_STDIO && file < 3)
return __mriNewlib_SemihostRead(file, ptr, len);
return __real__read(file, ptr, len);
}
extern "C" int __real__write(int file, char *ptr, int len);
extern "C" int __wrap__write(int file, char *ptr, int len)
{
if (MRI_SEMIHOST_STDIO && file < 3)
return __mriNewlib_SemihostWrite(file, ptr, len);
return __real__write(file, ptr, len);
}
extern "C" int __real__isatty(int file);
extern "C" int __wrap__isatty(int file)
{
/* Hardcoding the stdin/stdout/stderr handles to be interactive tty devices, unlike mbed.ar */
if (file < 3)
return 1;
return __real__isatty(file);
}
extern "C" int __wrap_semihost_connected(void)
{
/* MRI makes it look like there is no mbed interface attached since it disables the JTAG portion but MRI does
support some of the mbed semihost calls when it is running so force it to return -1, indicating that the
interface is attached. */
return -1;
}
extern "C" void abort(void)
{
if (MRI_ENABLE)
__debugbreak();
exit(1);
}
extern "C" void __cxa_pure_virtual(void)
{
abort();
}
extern "C" int __aeabi_unwind_cpp_pr0(int state, void* controlBlock, void* context)
{
abort();
}
extern "C" int __aeabi_unwind_cpp_pr1(int state, void* controlBlock, void* context)
{
abort();
}
extern "C" int __aeabi_unwind_cpp_pr2(int state, void* controlBlock, void* context)
{
abort();
}