Subversion Repositories freemyipod

Rev

Rev 428 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 428 Rev 453
Line 1... Line 1...
1
#include "syscallwrappers.h"
1
#include "syscallwrappers.h"
2
 
2
 
3
 
3
 
4
#define EMCORE_APP_HEADER(threadnamestr, stacksizebytes, mainfunc, threadprio)                    \
4
#define EMCORE_APP_HEADER(threadnamestr, mainfunc, threadprio)                                    \
5
    extern char __bss_start;                                                                      \
-
 
6
    extern char __bss_end;                                                                        \
-
 
7
    void __emcore_init()                                                                          \
5
    void __attribute__((section(".emcoreentrypoint"))) __emcore_entrypoint()                      \
8
    {                                                                                             \
6
    {                                                                                             \
9
        asm volatile("swi\t2\n\tldr\tr3, =__emcore_required_version\nldr\tr3, [r3]\n\t"           \
7
        asm volatile("swi\t2\n\tldr\tr3, =__emcore_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"    \
8
                     "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, =__emcore_incompatible_api_str\n\t"             \
9
                     "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"                \
10
                     "swihi\t1\n\tldr\tr1, =__emcore_syscall\n\tstr\tr0, [r1]\n\t"                \
13
                 ::: "r0", "r1", "r2", "r3", "r12", "lr", "cc", "memory");                        \
11
                 ::: "r0", "r1", "r2", "r3", "r12", "lr", "cc", "memory");                        \
-
 
12
        thread_set_name(NULL, threadnamestr);                                                     \
14
        memset(&__bss_start, 0, (&__bss_end) - (&__bss_start));                                   \
13
        thread_set_priority(NULL, threadprio);                                                    \
15
        mainfunc();                                                                               \
14
        mainfunc();                                                                               \
16
    }                                                                                             \
15
    }                                                                                             \
17
    uint32_t __emcore_thread_stack[stacksizebytes >> 2] __attribute__((section(".stack")));       \
-
 
18
    const char __emcore_thread_name[] = threadnamestr;                                            \
-
 
19
    struct emcore_app_header                                                                      \
16
    struct emcore_syscall_table* __emcore_syscall;                                                \
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;                                                                         \
-
 
29
        const char* threadname;                                                                   \
-
 
30
        int threadtype;                                                                           \
-
 
31
        int threadpriority;                                                                       \
-
 
32
    } __emcore_executable_hdr __attribute__((section(".execheader"))) =                           \
-
 
33
    {                                                                                             \
-
 
34
        .signature = "emBIexec",                                                                  \
-
 
35
        .version = 0,                                                                             \
-
 
36
        .baseaddr = &__emcore_executable_hdr,                                                     \
-
 
37
        .size = -1,                                                                               \
-
 
38
        .crc32 = 0,                                                                               \
-
 
39
        .stackaddr = __emcore_thread_stack,                                                       \
-
 
40
        .stacksize = stacksizebytes,                                                              \
-
 
41
        .entrypoint = __emcore_init,                                                              \
-
 
42
        .threadname = __emcore_thread_name,                                                       \
-
 
43
        .threadtype = 0,                                                                          \
-
 
44
        .threadpriority = threadprio                                                              \
-
 
45
    };                                                                                            \
-
 
46
    struct emcore_syscall_table* __emcore_syscall __attribute__((section(".stack")));             \
-
 
47
    const uint32_t __emcore_required_version = EMCORE_API_VERSION;                                \
17
    const uint32_t __emcore_required_version = EMCORE_API_VERSION;                                \
48
    const char __emcore_incompatible_api_str[] = "Incompatible API version!\nGot %d, need %d";
18
    const char __emcore_incompatible_api_str[] = "Incompatible API version!\nGot %d, need %d";