| 99 |
theseven |
1 |
#include "syscallwrappers.h"
|
|
|
2 |
|
|
|
3 |
|
| 427 |
farthen |
4 |
#define EMCORE_APP_HEADER(threadnamestr, stacksizebytes, mainfunc, threadprio) \
|
| 299 |
theseven |
5 |
extern char __bss_start; \
|
|
|
6 |
extern char __bss_end; \
|
| 427 |
farthen |
7 |
void __emcore_init() \
|
| 116 |
theseven |
8 |
{ \
|
| 427 |
farthen |
9 |
asm volatile("swi\t2\n\tldr\tr3, =__emcore_required_version\nldr\tr3, [r3]\n\t" \
|
| 299 |
theseven |
10 |
"ldr\tr2, [r0]\n\tcmp\tr3, r2\n\tldrls\tr1, [r0,#4]\n\tcmpls\tr1, r3\n\t" \
|
| 427 |
farthen |
11 |
"movhi\tr0, #0\n\tldrhi\tr1, =__emcore_incompatible_api_str\n\t" \
|
|
|
12 |
"swihi\t1\n\tldr\tr1, =__emcore_syscall\n\tstr\tr0, [r1]\n\t" \
|
| 116 |
theseven |
13 |
::: "r0", "r1", "r2", "r3", "r12", "lr", "cc", "memory"); \
|
| 299 |
theseven |
14 |
memset(&__bss_start, 0, (&__bss_end) - (&__bss_start)); \
|
| 116 |
theseven |
15 |
mainfunc(); \
|
|
|
16 |
} \
|
| 427 |
farthen |
17 |
uint32_t __emcore_thread_stack[stacksizebytes >> 2] __attribute__((section(".stack"))); \
|
|
|
18 |
const char __emcore_thread_name[] = threadnamestr; \
|
|
|
19 |
struct emcore_app_header \
|
| 99 |
theseven |
20 |
{ \
|
|
|
21 |
char signature[8]; \
|
|
|
22 |
int version; \
|
|
|
23 |
void* baseaddr; \
|
|
|
24 |
int size; \
|
|
|
25 |
uint32_t crc32; \
|
|
|
26 |
void* stackaddr; \
|
|
|
27 |
int stacksize; \
|
|
|
28 |
void* entrypoint; \
|
| 100 |
theseven |
29 |
const char* threadname; \
|
| 99 |
theseven |
30 |
int threadtype; \
|
|
|
31 |
int threadpriority; \
|
| 427 |
farthen |
32 |
} __emcore_executable_hdr __attribute__((section(".execheader"))) = \
|
| 99 |
theseven |
33 |
{ \
|
|
|
34 |
.signature = "emBIexec", \
|
|
|
35 |
.version = 0, \
|
| 427 |
farthen |
36 |
.baseaddr = &__emcore_executable_hdr, \
|
| 99 |
theseven |
37 |
.size = -1, \
|
|
|
38 |
.crc32 = 0, \
|
| 427 |
farthen |
39 |
.stackaddr = __emcore_thread_stack, \
|
| 99 |
theseven |
40 |
.stacksize = stacksizebytes, \
|
| 427 |
farthen |
41 |
.entrypoint = __emcore_init, \
|
|
|
42 |
.threadname = __emcore_thread_name, \
|
| 99 |
theseven |
43 |
.threadtype = 0, \
|
|
|
44 |
.threadpriority = threadprio \
|
|
|
45 |
}; \
|
| 427 |
farthen |
46 |
struct emcore_syscall_table* __emcore_syscall __attribute__((section(".stack"))); \
|
|
|
47 |
const uint32_t __emcore_required_version = EMCORE_API_VERSION; \
|
|
|
48 |
const char __emcore_incompatible_api_str[] = "Incompatible API version!\nGot %d, need %d";
|