]> git.donarmstrong.com Git - qmk_firmware.git/blob - tool/mbed/mbed-sdk/libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC11XX_11CXX/TOOLCHAIN_GCC_CS/sys.cpp
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[qmk_firmware.git] / tool / mbed / mbed-sdk / libraries / mbed / targets / cmsis / TARGET_NXP / TARGET_LPC11XX_11CXX / TOOLCHAIN_GCC_CS / sys.cpp
1 #include "cmsis.h"
2 #include <sys/types.h>
3 #include <errno.h>
4
5 extern "C" {
6
7 struct SCS3Regions {
8     unsigned long   Dummy;
9     unsigned long*  InitRam;
10     unsigned long*  StartRam;
11     unsigned long   InitSizeRam;
12     unsigned long   ZeroSizeRam;
13 };
14
15 extern unsigned long __cs3_regions;
16 extern unsigned long __cs3_heap_start;
17
18 int  main(void);
19 void __libc_init_array(void);
20 void exit(int ErrorCode);
21
22 static void *heap_pointer = NULL;
23
24 void __cs3_start_c(void) {
25     static SCS3Regions* pCS3Regions = (SCS3Regions*)&__cs3_regions;
26     unsigned long* pulDest;
27     unsigned long* pulSrc;
28     unsigned long  ByteCount;
29     unsigned long  i;
30     
31     pulSrc = pCS3Regions->InitRam;
32     pulDest = pCS3Regions->StartRam;
33     ByteCount = pCS3Regions->InitSizeRam;
34     if (pulSrc != pulDest) {
35         for(i = 0 ; i < ByteCount ; i += sizeof(unsigned long)) {
36             *(pulDest++) = *(pulSrc++);
37         }
38     } else {
39         pulDest = (unsigned long*)(void*)((char*)pulDest + ByteCount);
40     }
41     
42     ByteCount = pCS3Regions->ZeroSizeRam;
43     for(i = 0 ; i < ByteCount ; i += sizeof(unsigned long)) {
44         *(pulDest++) = 0;
45     }
46     
47     heap_pointer = &__cs3_heap_start;
48      __libc_init_array();
49     exit(main());
50 }
51
52 int _kill(int pid, int sig) {
53     errno = EINVAL;
54     return -1;
55 }
56
57 void _exit(int status) {
58     exit(status);
59 }
60
61 int _getpid(void) {
62     return 1;
63 }
64
65 void *_sbrk(unsigned int incr) {
66     void *mem;
67     
68     unsigned int next = ((((unsigned int)heap_pointer + incr) + 7) & ~7);
69     if (next > __get_MSP()) {
70         mem = NULL;
71     } else {
72         mem = (void *)heap_pointer;
73     }
74     heap_pointer = (void *)next;
75     
76     return mem;
77 }
78
79 }