Christophe Lyon | 073831a | 2011-01-24 17:37:40 +0100 | [diff] [blame] | 1 | /* |
| 2 | ** Copyright (C) ARM Limited, 2005. All rights reserved. |
| 3 | */ |
| 4 | |
Christophe Lyon | 6f4d36f | 2011-07-19 16:18:19 +0200 | [diff] [blame] | 5 | #if defined(__cplusplus) |
| 6 | #include <cstdio> |
| 7 | #else |
Christophe Lyon | 073831a | 2011-01-24 17:37:40 +0100 | [diff] [blame] | 8 | #include <stdio.h> |
Christophe Lyon | 6f4d36f | 2011-07-19 16:18:19 +0200 | [diff] [blame] | 9 | #endif |
Christophe Lyon | 073831a | 2011-01-24 17:37:40 +0100 | [diff] [blame] | 10 | #include <rt_misc.h> |
| 11 | |
| 12 | // Heap base from scatter file |
| 13 | extern int Image$$HEAP$$ZI$$Base; |
| 14 | //#pragma import(__use_two_region_memory) |
| 15 | |
| 16 | extern void core_init(void); |
| 17 | |
| 18 | /* |
| 19 | The functions below are patched onto main. |
| 20 | */ |
| 21 | |
| 22 | extern void $Super$$main(void); |
| 23 | |
| 24 | void $Sub$$main(void) |
| 25 | { |
| 26 | core_init(); // does some extra setup work |
| 27 | |
| 28 | $Super$$main(); // calls the original function |
| 29 | } |
| 30 | |
| 31 | |
| 32 | /* |
| 33 | This function re-implements the C Library semihosted function. The stack pointer |
| 34 | has aready been set and is passed back to the function, The base of the heap is |
| 35 | set from the scatter file |
| 36 | */ |
| 37 | __value_in_regs struct __initial_stackheap __user_initial_stackheap( |
| 38 | unsigned R0, unsigned SP, unsigned R2, unsigned SL) |
| 39 | { |
| 40 | struct __initial_stackheap config; |
| 41 | |
| 42 | config.heap_base = (unsigned int)&Image$$HEAP$$ZI$$Base; // placed by scatterfile |
| 43 | config.stack_base = SP; // inherit SP from the execution environment |
| 44 | |
| 45 | return config; |
| 46 | } |