1 /* Copyright 2011 Adam Green (http://mbed.org/users/AdamGreen/)
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
7 http://www.apache.org/licenses/LICENSE-2.0
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
15 /* Provide routines which hook the MRI debug monitor into GCC4MBED projects. */
17 #include <sys/types.h>
22 extern unsigned int __bss_start__
;
23 extern unsigned int __bss_end__
;
24 extern unsigned int __end__
;
27 void __libc_init_array(void);
28 void software_init_hook(void) __attribute((weak
));
29 void exit(int ErrorCode
);
32 int bssSize
= (int)&__bss_end__
- (int)&__bss_start__
;
35 memset(&__bss_start__
, 0, bssSize
);
39 __mriInit(MRI_INIT_PARAMETERS
);
40 if (MRI_BREAK_ON_INIT
)
46 mainReturnValue
= main();
47 exit(mainReturnValue
);
51 int __real__read(int file
, char *ptr
, int len
);
52 int __wrap__read(int file
, char *ptr
, int len
)
54 if (MRI_SEMIHOST_STDIO
&& file
< 3)
55 return __mriNewlib_SemihostRead(file
, ptr
, len
);
56 return __real__read(file
, ptr
, len
);
60 int __real__write(int file
, char *ptr
, int len
);
61 int __wrap__write(int file
, char *ptr
, int len
)
63 if (MRI_SEMIHOST_STDIO
&& file
< 3)
64 return __mriNewlib_SemihostWrite(file
, ptr
, len
);
65 return __real__write(file
, ptr
, len
);
69 int __real__isatty(int file
);
70 int __wrap__isatty(int file
)
72 /* Hardcoding the stdin/stdout/stderr handles to be interactive tty devices, unlike mbed.ar */
75 return __real__isatty(file
);
79 int __wrap_semihost_connected(void)
81 /* MRI makes it look like there is no mbed interface attached since it disables the JTAG portion but MRI does
82 support some of the mbed semihost calls when it is running so force it to return -1, indicating that the
83 interface is attached. */
98 void __cxa_pure_virtual(void)
103 /* Trap calls to malloc/free/realloc in ISR. */
104 void __malloc_lock(void)
106 if (__get_IPSR() != 0)
110 void __malloc_unlock(void)
115 /* Turn off the errno macro and use actual external global variable instead. */
119 /* Dynamic memory allocation related syscalls. */
120 caddr_t
_sbrk(int incr
)
122 static unsigned char* heap
= (unsigned char*)&__end__
;
123 unsigned char* prev_heap
= heap
;
124 unsigned char* new_heap
= heap
+ incr
;
126 if (new_heap
>= (unsigned char*)__get_MSP()) {
132 return (caddr_t
) prev_heap
;