]> git.donarmstrong.com Git - qmk_firmware.git/blob - tool/mbed/mbed-sdk/libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC176X/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_LPC176X / 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     
50     exit(main());
51 }
52
53 int _kill(int pid, int sig) {
54     errno = EINVAL;
55     return -1;
56 }
57
58 void _exit(int status) {
59     exit(status);
60 }
61
62 int _getpid(void) {
63         return 1;
64 }
65
66 void *_sbrk(unsigned int incr) {
67     void *mem;
68     
69     unsigned int next = ((((unsigned int)heap_pointer + incr) + 7) & ~7);
70     if (next > __get_MSP()) {
71         mem = NULL;
72     } else {
73         mem = (void *)heap_pointer;
74     }
75     heap_pointer = (void *)next;
76     
77     return mem;
78 }
79
80 }