| 99 |
theseven |
1 |
#include "syscallwrappers.h"
|
|
|
2 |
|
|
|
3 |
|
|
|
4 |
#define EMBIOS_APP_HEADER(threadnamestr, stacksizebytes, mainfunc, threadprio) \
|
| 299 |
theseven |
5 |
extern char __bss_start; \
|
|
|
6 |
extern char __bss_end; \
|
| 116 |
theseven |
7 |
void __embios_init() \
|
|
|
8 |
{ \
|
| 299 |
theseven |
9 |
asm volatile("swi\t2\n\tldr\tr3, =__embios_required_version\nldr\tr3, [r3]\n\t" \
|
|
|
10 |
"ldr\tr2, [r0]\n\tcmp\tr3, r2\n\tldrls\tr1, [r0,#4]\n\tcmpls\tr1, r3\n\t" \
|
|
|
11 |
"movhi\tr0, #0\n\tldrhi\tr1, =__embios_incompatible_api_str\n\t" \
|
|
|
12 |
"swihi\t1\n\tldr\tr1, =__embios_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 |
} \
|
| 299 |
theseven |
17 |
uint32_t __embios_thread_stack[stacksizebytes >> 2] __attribute__((section(".stack"))); \
|
| 100 |
theseven |
18 |
const char __embios_thread_name[] = threadnamestr; \
|
| 99 |
theseven |
19 |
struct embios_app_header \
|
|
|
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; \
|
|
|
32 |
} __embios_executable_hdr __attribute__((section(".execheader"))) = \
|
|
|
33 |
{ \
|
|
|
34 |
.signature = "emBIexec", \
|
|
|
35 |
.version = 0, \
|
|
|
36 |
.baseaddr = &__embios_executable_hdr, \
|
|
|
37 |
.size = -1, \
|
|
|
38 |
.crc32 = 0, \
|
|
|
39 |
.stackaddr = __embios_thread_stack, \
|
|
|
40 |
.stacksize = stacksizebytes, \
|
| 116 |
theseven |
41 |
.entrypoint = __embios_init, \
|
| 99 |
theseven |
42 |
.threadname = __embios_thread_name, \
|
|
|
43 |
.threadtype = 0, \
|
|
|
44 |
.threadpriority = threadprio \
|
|
|
45 |
}; \
|
| 299 |
theseven |
46 |
struct embios_syscall_table* __embios_syscall __attribute__((section(".stack"))); \
|
| 100 |
theseven |
47 |
const uint32_t __embios_required_version = EMBIOS_API_VERSION; \
|
|
|
48 |
const char __embios_incompatible_api_str[] = "Incompatible API version!\nGot %d, need %d";
|