blob: 6fc5736daf9a8d7f15c35105d2635cf8cf0251ec (
plain)
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
|
#include "cmsis.h"
#include <sys/types.h>
#include <errno.h>
extern "C" {
struct SCS3Regions {
unsigned long Dummy;
unsigned long* InitRam;
unsigned long* StartRam;
unsigned long InitSizeRam;
unsigned long ZeroSizeRam;
};
extern unsigned long __cs3_regions;
extern unsigned long __cs3_heap_start;
int main(void);
void __libc_init_array(void);
void exit(int ErrorCode);
static void *heap_pointer = NULL;
void __cs3_start_c(void) {
static SCS3Regions* pCS3Regions = (SCS3Regions*)&__cs3_regions;
unsigned long* pulDest;
unsigned long* pulSrc;
unsigned long ByteCount;
unsigned long i;
pulSrc = pCS3Regions->InitRam;
pulDest = pCS3Regions->StartRam;
ByteCount = pCS3Regions->InitSizeRam;
if (pulSrc != pulDest) {
for(i = 0 ; i < ByteCount ; i += sizeof(unsigned long)) {
*(pulDest++) = *(pulSrc++);
}
} else {
pulDest = (unsigned long*)(void*)((char*)pulDest + ByteCount);
}
ByteCount = pCS3Regions->ZeroSizeRam;
for(i = 0 ; i < ByteCount ; i += sizeof(unsigned long)) {
*(pulDest++) = 0;
}
heap_pointer = &__cs3_heap_start;
__libc_init_array();
exit(main());
}
int _kill(int pid, int sig) {
errno = EINVAL;
return -1;
}
void _exit(int status) {
exit(status);
}
int _getpid(void) {
return 1;
}
void *_sbrk(unsigned int incr) {
void *mem;
unsigned int next = ((((unsigned int)heap_pointer + incr) + 7) & ~7);
if (next > __get_MSP()) {
mem = NULL;
} else {
mem = (void *)heap_pointer;
}
heap_pointer = (void *)next;
return mem;
}
}
|