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