| Index: emcore/trunk/init.c | 
| — | — | @@ -180,7 +180,7 @@ | 
| 181 | 181 | switch (option->type) | 
| 182 | 182 | { | 
| 183 | 183 | case BOOTTYPE_PIGGYBACKED: | 
| 184 |  | -            done = execimage(option->source, true) > 0;
 | 
|  | 184 | +            done = execimage(option->source, true) != NULL; | 
| 185 | 185 | break; | 
| 186 | 186 |  | 
| 187 | 187 | #ifdef HAVE_BOOTFLASH | 
| — | — | @@ -195,7 +195,7 @@ | 
| 196 | 196 | free(buffer); | 
| 197 | 197 | break; | 
| 198 | 198 | } | 
| 199 |  | -            done = execimage(buffer, false);
 | 
|  | 199 | +            done = execimage(buffer, false) != NULL; | 
| 200 | 200 | if (!done) free(buffer); | 
| 201 | 201 | break; | 
| 202 | 202 | } | 
| — | — | @@ -225,7 +225,7 @@ | 
| 226 | 226 | break; | 
| 227 | 227 | } | 
| 228 | 228 | close(fd); | 
| 229 |  | -            done = execimage(buffer, false);
 | 
|  | 229 | +            done = execimage(buffer, false) != NULL; | 
| 230 | 230 | if (!done) free(buffer); | 
| 231 | 231 | break; | 
| 232 | 232 | } | 
| Index: emcore/trunk/execimage.c | 
| — | — | @@ -27,31 +27,92 @@ | 
| 28 | 28 | #include "mmu.h" | 
| 29 | 29 |  | 
| 30 | 30 |  | 
| 31 |  | -int execimage(void* image, bool nomalloc)
 | 
|  | 31 | +struct scheduler_thread* execimage(void* image, bool copy) | 
| 32 | 32 | { | 
| 33 |  | -    struct execimage_header* header = (struct execimage_header*)image;
 | 
| 34 |  | -    if (memcmp(header, "emBIexec", 8))
 | 
|  | 33 | +    struct emcoreapp_header* header = (struct emcoreapp_header*)image; | 
|  | 34 | +    if (memcmp(header, "emCOexec", 8)) | 
| 35 | 35 | { | 
| 36 |  | -        cprintf(CONSOLE_BOOT, "execimage: Bad signature!\n"
 | 
|  | 36 | +        cprintf(CONSOLE_BOOT, "execimage: Bad signature: " | 
| 37 | 37 | "%02X %02X %02X %02X %02X %02X %02X %02X\n", | 
| 38 | 38 | header->signature[0], header->signature[1], header->signature[2], | 
| 39 | 39 | header->signature[3], header->signature[4], header->signature[5], | 
| 40 | 40 | header->signature[6], header->signature[7]); | 
| 41 |  | -        return -1;
 | 
|  | 41 | +        return NULL; | 
| 42 | 42 | } | 
| 43 |  | -    if (header->version > 0)
 | 
|  | 43 | +    if (header->version != EMCOREAPP_HEADER_VERSION) | 
| 44 | 44 | { | 
| 45 | 45 | cprintf(CONSOLE_BOOT, "execimage: Unsupported version! (%08X)\n", header->version); | 
| 46 |  | -        return -2;
 | 
|  | 46 | +        return NULL; | 
| 47 | 47 | } | 
| 48 |  | -    if (header->baseaddr != image)
 | 
|  | 48 | +    off_t offset = header->textstart; | 
|  | 49 | +    size_t textsize = header->textsize; | 
|  | 50 | +    size_t bsssize = header->bsssize; | 
|  | 51 | +    size_t stacksize = header->stacksize; | 
|  | 52 | +	off_t entrypoint = header->entrypoint; | 
|  | 53 | +	off_t relocstart = header->relocstart - offset; | 
|  | 54 | +	uint32_t reloccount = header->reloccount; | 
|  | 55 | +	bool compressed = header->flags & EMCOREAPP_FLAG_COMPRESSED; | 
|  | 56 | +    size_t finalsize = textsize + bsssize + stacksize; | 
|  | 57 | +    size_t datasize = relocstart + reloccount * 4; | 
|  | 58 | +    size_t tempsize = MAX(finalsize, datasize); | 
|  | 59 | +    if (compressed) | 
| 49 | 60 | { | 
| 50 |  | -        cprintf(CONSOLE_BOOT, "execimage: Image loaded to wrong address! "
 | 
| 51 |  | -                              "(expected: %08X, got: %08X)\n", header->baseaddr, image);
 | 
| 52 |  | -        return -3;
 | 
|  | 61 | +        void* alloc = malloc(tempsize); | 
|  | 62 | +        if (!alloc) | 
|  | 63 | +        { | 
|  | 64 | +            cprintf(CONSOLE_BOOT, "execimage: Out of memory!\n"); | 
|  | 65 | +            return NULL; | 
|  | 66 | +        } | 
|  | 67 | +        uint32_t decompsize; | 
|  | 68 | +        if (ucl_decompress(image + offset, datasize, alloc, &decompsize)) | 
|  | 69 | +        { | 
|  | 70 | +            cprintf(CONSOLE_BOOT, "execimage: Decompression failed!\n"); | 
|  | 71 | +            free(alloc); | 
|  | 72 | +            return NULL; | 
|  | 73 | +        } | 
|  | 74 | +        if (datasize != decompsize) | 
|  | 75 | +        { | 
|  | 76 | +            cprintf(CONSOLE_BOOT, "execimage: Decompressed size mismatch!\n"); | 
|  | 77 | +            free(alloc); | 
|  | 78 | +            return NULL; | 
|  | 79 | +        } | 
|  | 80 | +        if (!copy) free(image); | 
|  | 81 | +        image = alloc; | 
| 53 | 82 | } | 
|  | 83 | +    else if (copy) | 
|  | 84 | +    { | 
|  | 85 | +        void* alloc = malloc(tempsize); | 
|  | 86 | +        if (!alloc) | 
|  | 87 | +        { | 
|  | 88 | +            cprintf(CONSOLE_BOOT, "execimage: Out of memory!\n"); | 
|  | 89 | +            return NULL; | 
|  | 90 | +        } | 
|  | 91 | +        memcpy(alloc, image + offset, datasize); | 
|  | 92 | +        image = alloc; | 
|  | 93 | +    } | 
|  | 94 | +    else | 
|  | 95 | +    { | 
|  | 96 | +        memcpy(image, image + offset, datasize); | 
|  | 97 | +        image = realloc(image, tempsize); | 
|  | 98 | +        if (!image) | 
|  | 99 | +        { | 
|  | 100 | +            cprintf(CONSOLE_BOOT, "execimage: Out of memory!\n"); | 
|  | 101 | +            return NULL; | 
|  | 102 | +        } | 
|  | 103 | +    } | 
|  | 104 | +    for (; reloccount; reloccount--, relocstart += 4) | 
|  | 105 | +    { | 
|  | 106 | +        off_t reloc = *((off_t*)(image + relocstart)); | 
|  | 107 | +        uint32_t data = *((uint32_t*)(image + reloc)); | 
|  | 108 | +        *((void**)(image + reloc)) = image + data; | 
|  | 109 | +    } | 
|  | 110 | +    if (tempsize != finalsize) realloc(image, finalsize); /* Can only shrink => safe */ | 
| 54 | 111 | clean_dcache(); | 
| 55 | 112 | invalidate_icache(); | 
| 56 |  | -    return thread_create(header->threadname, header->entrypoint, header->stackaddr,
 | 
| 57 |  | -                         header->stacksize, header->threadtype, header->threadpriority, true);
 | 
|  | 113 | +    struct scheduler_thread* thread = thread_create(NULL, NULL, image + entrypoint, | 
|  | 114 | +                                                    image + textsize + bsssize, stacksize, | 
|  | 115 | +                                                    USER_THREAD, 127, false); | 
|  | 116 | +    reownalloc(image, thread); | 
|  | 117 | +    thread_resume(thread); | 
|  | 118 | +    return thread; | 
| 58 | 119 | } | 
| Index: emcore/trunk/execimage.h | 
| — | — | @@ -1,6 +1,6 @@ | 
| 2 | 2 | // | 
| 3 | 3 | // | 
| 4 |  | -//    Copyright 2010 TheSeven
 | 
|  | 4 | +//    Copyright 2011 TheSeven | 
| 5 | 5 | // | 
| 6 | 6 | // | 
| 7 | 7 | //    This file is part of emCORE. | 
| — | — | @@ -25,26 +25,36 @@ | 
| 26 | 26 | #define __EXECIMAGE_H__ | 
| 27 | 27 |  | 
| 28 | 28 |  | 
|  | 29 | +#ifdef _TOOL | 
|  | 30 | +#include <stdint.h> | 
|  | 31 | +#else | 
| 29 | 32 | #include "global.h" | 
|  | 33 | +#include "thread.h" | 
|  | 34 | +#endif | 
| 30 | 35 |  | 
| 31 | 36 |  | 
| 32 |  | -struct execimage_header
 | 
|  | 37 | +#define EMCOREAPP_HEADER_VERSION 1 | 
|  | 38 | +struct emcoreapp_header | 
| 33 | 39 | { | 
| 34 |  | -    char signature[8];
 | 
| 35 |  | -    int version;
 | 
| 36 |  | -    void* baseaddr;
 | 
| 37 |  | -    int size;
 | 
| 38 |  | -    uint32_t crc32;
 | 
| 39 |  | -    void* stackaddr;
 | 
| 40 |  | -    int stacksize;
 | 
| 41 |  | -    void* entrypoint;
 | 
| 42 |  | -    char* threadname;
 | 
| 43 |  | -    int threadtype;
 | 
| 44 |  | -    int threadpriority;
 | 
|  | 40 | +	char signature[8]; | 
|  | 41 | +	uint32_t version; | 
|  | 42 | +    off_t textstart; | 
|  | 43 | +    size_t textsize; | 
|  | 44 | +    size_t bsssize; | 
|  | 45 | +    size_t stacksize; | 
|  | 46 | +	off_t entrypoint; | 
|  | 47 | +	off_t relocstart; | 
|  | 48 | +	uint32_t reloccount; | 
|  | 49 | +	uint32_t flags; | 
|  | 50 | +    uint32_t creationtime; | 
| 45 | 51 | }; | 
| 46 | 52 |  | 
|  | 53 | +#define EMCOREAPP_FLAG_COMPRESSED 0x00000001 | 
| 47 | 54 |  | 
| 48 |  | -int execimage(void* image, bool nomalloc);
 | 
| 49 | 55 |  | 
|  | 56 | +#ifndef _TOOL | 
|  | 57 | +struct scheduler_thread* execimage(void* image, bool copy); | 
|  | 58 | +#endif | 
| 50 | 59 |  | 
|  | 60 | + | 
| 51 | 61 | #endif | 
| Index: emcore/trunk/export/emcoreapp.h | 
| — | — | @@ -1,10 +1,8 @@ | 
| 2 | 2 | #include "syscallwrappers.h" | 
| 3 | 3 |  | 
| 4 | 4 |  | 
| 5 |  | -#define EMCORE_APP_HEADER(threadnamestr, stacksizebytes, mainfunc, threadprio)                    \
 | 
| 6 |  | -    extern char __bss_start;                                                                      \
 | 
| 7 |  | -    extern char __bss_end;                                                                        \
 | 
| 8 |  | -    void __emcore_init()                                                                          \
 | 
|  | 5 | +#define EMCORE_APP_HEADER(threadnamestr, mainfunc, threadprio)                                    \ | 
|  | 6 | +    void __attribute__((section(".emcoreentrypoint"))) __emcore_entrypoint()                      \ | 
| 9 | 7 | {                                                                                             \ | 
| 10 | 8 | asm volatile("swi\t2\n\tldr\tr3, =__emcore_required_version\nldr\tr3, [r3]\n\t"           \ | 
| 11 | 9 | "ldr\tr2, [r0]\n\tcmp\tr3, r2\n\tldrls\tr1, [r0,#4]\n\tcmpls\tr1, r3\n\t"    \ | 
| — | — | @@ -11,38 +9,10 @@ | 
| 12 | 10 | "movhi\tr0, #0\n\tldrhi\tr1, =__emcore_incompatible_api_str\n\t"             \ | 
| 13 | 11 | "swihi\t1\n\tldr\tr1, =__emcore_syscall\n\tstr\tr0, [r1]\n\t"                \ | 
| 14 | 12 | ::: "r0", "r1", "r2", "r3", "r12", "lr", "cc", "memory");                        \ | 
| 15 |  | -        memset(&__bss_start, 0, (&__bss_end) - (&__bss_start));                                   \
 | 
|  | 13 | +        thread_set_name(NULL, threadnamestr);                                                     \ | 
|  | 14 | +        thread_set_priority(NULL, threadprio);                                                    \ | 
| 16 | 15 | mainfunc();                                                                               \ | 
| 17 | 16 | }                                                                                             \ | 
| 18 |  | -    uint32_t __emcore_thread_stack[stacksizebytes >> 2] __attribute__((section(".stack")));       \
 | 
| 19 |  | -    const char __emcore_thread_name[] = threadnamestr;                                            \
 | 
| 20 |  | -    struct emcore_app_header                                                                      \
 | 
| 21 |  | -    {                                                                                             \
 | 
| 22 |  | -        char signature[8];                                                                        \
 | 
| 23 |  | -        int version;                                                                              \
 | 
| 24 |  | -        void* baseaddr;                                                                           \
 | 
| 25 |  | -        int size;                                                                                 \
 | 
| 26 |  | -        uint32_t crc32;                                                                           \
 | 
| 27 |  | -        void* stackaddr;                                                                          \
 | 
| 28 |  | -        int stacksize;                                                                            \
 | 
| 29 |  | -        void* entrypoint;                                                                         \
 | 
| 30 |  | -        const char* threadname;                                                                   \
 | 
| 31 |  | -        int threadtype;                                                                           \
 | 
| 32 |  | -        int threadpriority;                                                                       \
 | 
| 33 |  | -    } __emcore_executable_hdr __attribute__((section(".execheader"))) =                           \
 | 
| 34 |  | -    {                                                                                             \
 | 
| 35 |  | -        .signature = "emBIexec",                                                                  \
 | 
| 36 |  | -        .version = 0,                                                                             \
 | 
| 37 |  | -        .baseaddr = &__emcore_executable_hdr,                                                     \
 | 
| 38 |  | -        .size = -1,                                                                               \
 | 
| 39 |  | -        .crc32 = 0,                                                                               \
 | 
| 40 |  | -        .stackaddr = __emcore_thread_stack,                                                       \
 | 
| 41 |  | -        .stacksize = stacksizebytes,                                                              \
 | 
| 42 |  | -        .entrypoint = __emcore_init,                                                              \
 | 
| 43 |  | -        .threadname = __emcore_thread_name,                                                       \
 | 
| 44 |  | -        .threadtype = 0,                                                                          \
 | 
| 45 |  | -        .threadpriority = threadprio                                                              \
 | 
| 46 |  | -    };                                                                                            \
 | 
| 47 |  | -    struct emcore_syscall_table* __emcore_syscall __attribute__((section(".stack")));             \
 | 
|  | 17 | +    struct emcore_syscall_table* __emcore_syscall;                                                \ | 
| 48 | 18 | const uint32_t __emcore_required_version = EMCORE_API_VERSION;                                \ | 
| 49 | 19 | const char __emcore_incompatible_api_str[] = "Incompatible API version!\nGot %d, need %d"; | 
| Index: emcore/trunk/export/syscallwrappers.h | 
| — | — | @@ -32,159 +32,161 @@ | 
| 33 | 33 | extern struct emcore_syscall_table* __emcore_syscall; | 
| 34 | 34 |  | 
| 35 | 35 |  | 
| 36 |  | -#define panic(args...) __emcore_syscall->panic(args)
 | 
| 37 |  | -#define panicf(args...) __emcore_syscall->panicf(args)
 | 
| 38 |  | -#define cprintf(args...) __emcore_syscall->cprintf(args)
 | 
| 39 |  | -#define cvprintf(args...) __emcore_syscall->cvprintf(args)
 | 
| 40 |  | -#define cputc(args...) __emcore_syscall->cputc(args)
 | 
| 41 |  | -#define cputs(args...) __emcore_syscall->cputs(args)
 | 
| 42 |  | -#define cwrite(args...) __emcore_syscall->cwrite(args)
 | 
| 43 |  | -#define cflush(args...) __emcore_syscall->cflush(args)
 | 
| 44 |  | -#define cgetc(args...) __emcore_syscall->cgetc(args)
 | 
| 45 |  | -#define cread(args...) __emcore_syscall->cread(args)
 | 
| 46 |  | -#define creada(args...) __emcore_syscall->creada(args)
 | 
| 47 |  | -#define opendir(args...) __emcore_syscall->opendir(args)
 | 
| 48 |  | -#define closedir(args...) __emcore_syscall->closedir(args)
 | 
| 49 |  | -#define readdir(args...) __emcore_syscall->readdir(args)
 | 
| 50 |  | -#define mkdir(args...) __emcore_syscall->mkdir(args)
 | 
| 51 |  | -#define rmdir(args...) __emcore_syscall->rmdir(args)
 | 
| 52 |  | -#define renderbmp(args...) __emcore_syscall->renderbmp(args)
 | 
| 53 |  | -#define renderchar(args...) __emcore_syscall->renderchar(args)
 | 
| 54 |  | -#define rendertext(args...) __emcore_syscall->rendertext(args)
 | 
| 55 |  | -#define renderfillrect(args...) __emcore_syscall->renderfillrect(args)
 | 
| 56 |  | -#define get_font_width(args...) __emcore_syscall->get_font_width(args)
 | 
| 57 |  | -#define get_font_height(args...) __emcore_syscall->get_font_height(args)
 | 
| 58 |  | -#define execimage(args...) __emcore_syscall->execimage(args)
 | 
| 59 |  | -#define ftruncate(args...) __emcore_syscall->ftruncate(args)
 | 
| 60 |  | -#define fsync(args...) __emcore_syscall->fsync(args)
 | 
| 61 |  | -#define close(args...) __emcore_syscall->close(args)
 | 
| 62 |  | -#define write(args...) __emcore_syscall->write(args)
 | 
| 63 |  | -#define read(args...) __emcore_syscall->read(args)
 | 
| 64 |  | -#define lseek(args...) __emcore_syscall->lseek(args)
 | 
| 65 |  | -#define remove(args...) __emcore_syscall->remove(args)
 | 
| 66 |  | -#define file_open(args...) __emcore_syscall->file_open(args)
 | 
| 67 |  | -#define rename(args...) __emcore_syscall->rename(args)
 | 
| 68 |  | -#define file_creat(args...) __emcore_syscall->file_creat(args)
 | 
| 69 |  | -#define filesize(args...) __emcore_syscall->filesize(args)
 | 
| 70 |  | -#define format(args...) __emcore_syscall->format(args)
 | 
| 71 |  | -#define vuprintf(args...) __emcore_syscall->vuprintf(args)
 | 
| 72 |  | -#define lcdconsole_putc_noblit(args...) __emcore_syscall->lcdconsole_putc_noblit(args)
 | 
| 73 |  | -#define lcdconsole_puts_noblit(args...) __emcore_syscall->lcdconsole_puts_noblit(args)
 | 
| 74 |  | -#define lcdconsole_write_noblit(args...) __emcore_syscall->lcdconsole_write_noblit(args)
 | 
| 75 |  | -#define lcdconsole_update(args...) __emcore_syscall->lcdconsole_update(args)
 | 
| 76 |  | -#define lcdconsole_putc(args...) __emcore_syscall->lcdconsole_putc(args)
 | 
| 77 |  | -#define lcdconsole_puts(args...) __emcore_syscall->lcdconsole_puts(args)
 | 
| 78 |  | -#define lcdconsole_write(args...) __emcore_syscall->lcdconsole_write(args)
 | 
| 79 |  | -#define lcdconsole_get_current_x(args...) __emcore_syscall->lcdconsole_get_current_x(args)
 | 
| 80 |  | -#define lcdconsole_get_current_y(args...) __emcore_syscall->lcdconsole_get_current_y(args)
 | 
| 81 |  | -#define lcdconsole_get_lineend_x(args...) __emcore_syscall->lcdconsole_get_lineend_x(args)
 | 
| 82 |  | -#define lcdconsole_get_lineend_y(args...) __emcore_syscall->lcdconsole_get_lineend_y(args)
 | 
| 83 |  | -#define lcdconsole_progressbar(args...) __emcore_syscall->lcdconsole_progressbar(args)
 | 
| 84 |  | -#define progressbar_init(args...) __emcore_syscall->progressbar_init(args)
 | 
| 85 |  | -#define progressbar_setpos(args...) __emcore_syscall->progressbar_setpos(args)
 | 
| 86 |  | -#define shutdown(args...) __emcore_syscall->shutdown(args)
 | 
| 87 |  | -#define storage_read_sectors_md(args...) __emcore_syscall->storage_read_sectors_md(args)
 | 
| 88 |  | -#define storage_write_sectors_md(args...) __emcore_syscall->storage_write_sectors_md(args)
 | 
| 89 |  | -#define storage_get_info(args...) __emcore_syscall->storage_get_info(args)
 | 
| 90 |  | -#define strcasecmp(args...) __emcore_syscall->strcasecmp(args)
 | 
| 91 |  | -#define strncasecmp(args...) __emcore_syscall->strncasecmp(args)
 | 
| 92 |  | -#define strcasestr(args...) __emcore_syscall->strcasestr(args)
 | 
| 93 |  | -#define strlcat(args...) __emcore_syscall->strlcat(args)
 | 
| 94 |  | -#define strlcpy(args...) __emcore_syscall->strlcpy(args)
 | 
| 95 |  | -#define mutex_init(args...) __emcore_syscall->mutex_init(args)
 | 
| 96 |  | -#define mutex_lock(args...) __emcore_syscall->mutex_lock(args)
 | 
| 97 |  | -#define mutex_unlock(args...) __emcore_syscall->mutex_unlock(args)
 | 
| 98 |  | -#define wakeup_init(args...) __emcore_syscall->wakeup_init(args)
 | 
| 99 |  | -#define wakeup_wait(args...) __emcore_syscall->wakeup_wait(args)
 | 
| 100 |  | -#define wakeup_signal(args...) __emcore_syscall->wakeup_signal(args)
 | 
| 101 |  | -#define sleep(args...) __emcore_syscall->sleep(args)
 | 
| 102 |  | -#define thread_create(args...) __emcore_syscall->thread_create(args)
 | 
| 103 |  | -#define thread_exit(args...) __emcore_syscall->thread_exit(args)
 | 
| 104 |  | -#define thread_suspend(args...) __emcore_syscall->thread_suspend(args)
 | 
| 105 |  | -#define thread_resume(args...) __emcore_syscall->thread_resume(args)
 | 
| 106 |  | -#define thread_terminate(args...) __emcore_syscall->thread_terminate(args)
 | 
| 107 |  | -#define __errno(args...) __emcore_syscall->__errno(args)
 | 
| 108 |  | -#define ucl_decompress(args...) __emcore_syscall->ucl_decompress(args)
 | 
| 109 |  | -#define bootflash_filesize(args...) __emcore_syscall->bootflash_filesize(args)
 | 
| 110 |  | -#define bootflash_attributes(args...) __emcore_syscall->bootflash_attributes(args)
 | 
| 111 |  | -#define bootflash_getaddr(args...) __emcore_syscall->bootflash_getaddr(args)
 | 
| 112 |  | -#define bootflash_read(args...) __emcore_syscall->bootflash_read(args)
 | 
| 113 |  | -#define bootflash_readraw(args...) __emcore_syscall->bootflash_readraw(args)
 | 
| 114 |  | -#define bootflash_writeraw(args...) __emcore_syscall->bootflash_writeraw(args)
 | 
| 115 |  | -#define bootflash_getrawaddr(args...) __emcore_syscall->bootflash_getrawaddr(args)
 | 
| 116 |  | -#define bootflash_is_memmapped(args...) __emcore_syscall->bootflash_is_memmapped(args)
 | 
| 117 |  | -#define read_native_timer(args...) __emcore_syscall->read_native_timer(args)
 | 
| 118 |  | -#define read_usec_timer(args...) __emcore_syscall->read_usec_timer(args)
 | 
| 119 |  | -#define i2c_send(args...) __emcore_syscall->i2c_send(args)
 | 
| 120 |  | -#define i2c_recv(args...) __emcore_syscall->i2c_recv(args)
 | 
| 121 |  | -#define i2c_sendbyte(args...) __emcore_syscall->i2c_sendbyte(args)
 | 
| 122 |  | -#define i2c_recvbyte(args...) __emcore_syscall->i2c_recvbyte(args)
 | 
| 123 |  | -#define interrupt_enable(args...) __emcore_syscall->interrupt_enable(args)
 | 
| 124 |  | -#define interrupt_set_handler(args...) __emcore_syscall->interrupt_set_handler(args)
 | 
| 125 |  | -#define int_timer_set_handler(args...) __emcore_syscall->int_timer_set_handler(args)
 | 
| 126 |  | -#define displaylcd(args...) __emcore_syscall->displaylcd(args)
 | 
| 127 |  | -#define displaylcd_sync(args...) __emcore_syscall->displaylcd_sync(args)
 | 
| 128 |  | -#define displaylcd_busy(args...) __emcore_syscall->displaylcd_busy(args)
 | 
| 129 |  | -#define displaylcd_safe(args...) __emcore_syscall->displaylcd_safe(args)
 | 
| 130 |  | -#define lcd_get_width(args...) __emcore_syscall->lcd_get_width(args)
 | 
| 131 |  | -#define lcd_get_height(args...) __emcore_syscall->lcd_get_height(args)
 | 
| 132 |  | -#define lcd_get_bytes_per_pixel(args...) __emcore_syscall->lcd_get_bytes_per_pixel(args)
 | 
| 133 |  | -#define lcd_translate_color(args...) __emcore_syscall->lcd_translate_color(args)
 | 
| 134 |  | -#define clean_dcache(args...) __emcore_syscall->clean_dcache(args)
 | 
| 135 |  | -#define invalidate_dcache(args...) __emcore_syscall->invalidate_dcache(args)
 | 
| 136 |  | -#define invalidate_icache(args...) __emcore_syscall->invalidate_icache(args)
 | 
| 137 |  | -#define power_off(args...) __emcore_syscall->power_off(args)
 | 
| 138 |  | -#define charging_state(args...) __emcore_syscall->charging_state(args)
 | 
| 139 |  | -#define atoi(args...) __emcore_syscall->atoi(args)
 | 
| 140 |  | -#define memchr(args...) __emcore_syscall->memchr(args)
 | 
| 141 |  | -#define memcmp(args...) __emcore_syscall->memcmp(args)
 | 
| 142 |  | -#define memcpy(args...) __emcore_syscall->memcpy(args)
 | 
| 143 |  | -#define memmove(args...) __emcore_syscall->memmove(args)
 | 
| 144 |  | -#define memset(args...) __emcore_syscall->memset(args)
 | 
| 145 |  | -#define qsort(args...) __emcore_syscall->qsort(args)
 | 
| 146 |  | -#define srand(args...) __emcore_syscall->srand(args)
 | 
| 147 |  | -#define rand(args...) __emcore_syscall->rand(args)
 | 
| 148 |  | -#define snprintf(args...) __emcore_syscall->snprintf(args)
 | 
| 149 |  | -#define vsnprintf(args...) __emcore_syscall->vsnprintf(args)
 | 
| 150 |  | -#define isspace(args...) __emcore_syscall->isspace(args)
 | 
| 151 |  | -#define isdigit(args...) __emcore_syscall->isdigit(args)
 | 
| 152 |  | -#define isxdigit(args...) __emcore_syscall->isxdigit(args)
 | 
| 153 |  | -#define sscanf(args...) __emcore_syscall->sscanf(args)
 | 
| 154 |  | -#define strcat(args...) __emcore_syscall->strcat(args)
 | 
| 155 |  | -#define strchr(args...) __emcore_syscall->strchr(args)
 | 
| 156 |  | -#define strcmp(args...) __emcore_syscall->strcmp(args)
 | 
| 157 |  | -#define strcpy(args...) __emcore_syscall->strcpy(args)
 | 
| 158 |  | -#define strlen(args...) __emcore_syscall->strlen(args)
 | 
| 159 |  | -#define strncmp(args...) __emcore_syscall->strncmp(args)
 | 
| 160 |  | -#define strrchr(args...) __emcore_syscall->strrchr(args)
 | 
| 161 |  | -#define strstr(args...) __emcore_syscall->strstr(args)
 | 
| 162 |  | -#define strtok_r(args...) __emcore_syscall->strtok_r(args)
 | 
| 163 |  | -#define backlight_on(args...) __emcore_syscall->backlight_on(args)
 | 
| 164 |  | -#define backlight_set_fade(args...) __emcore_syscall->backlight_set_fade(args)
 | 
| 165 |  | -#define backlight_set_brightness(args...) __emcore_syscall->backlight_set_brightness(args)
 | 
| 166 |  | -#define get_platform_id(args...) __emcore_syscall->get_platform_id(args)
 | 
| 167 |  | -#define tlsf_create(args...) __emcore_syscall->tlsf_create(args)
 | 
| 168 |  | -#define tlsf_destroy(args...) __emcore_syscall->tlsf_destroy(args)
 | 
| 169 |  | -#define tlsf_malloc(args...) __emcore_syscall->tlsf_malloc(args)
 | 
| 170 |  | -#define tlsf_memalign(args...) __emcore_syscall->tlsf_memalign(args)
 | 
| 171 |  | -#define tlsf_realloc(args...) __emcore_syscall->tlsf_realloc(args)
 | 
| 172 |  | -#define tlsf_free(args...) __emcore_syscall->tlsf_free(args)
 | 
| 173 |  | -#define tlsf_walk_heap(args...) __emcore_syscall->tlsf_walk_heap(args)
 | 
| 174 |  | -#define tlsf_check_heap(args...) __emcore_syscall->tlsf_check_heap(args)
 | 
| 175 |  | -#define tlsf_block_size(args...) __emcore_syscall->tlsf_block_size(args)
 | 
| 176 |  | -#define tlsf_overhead(args...) __emcore_syscall->tlsf_overhead(args)
 | 
| 177 |  | -#define execfirmware(args...) __emcore_syscall->execfirmware(args)
 | 
| 178 |  | -#define button_register_handler(args...) __emcore_syscall->button_register_handler(args)
 | 
| 179 |  | -#define button_unregister_handler(args...) __emcore_syscall->button_unregister_handler(args)
 | 
| 180 |  | -#define clickwheel_get_state(args...) __emcore_syscall->clickwheel_get_state(args)
 | 
| 181 |  | -#define clockgate_enable(args...) __emcore_syscall->clockgate_enable(args)
 | 
| 182 |  | -#define context_switch(args...) __emcore_syscall->context_switch(args)
 | 
| 183 |  | -#define disk_mount(args...) __emcore_syscall->disk_mount(args)
 | 
| 184 |  | -#define disk_unmount(args...) __emcore_syscall->disk_unmount(args)
 | 
| 185 |  | -#define hwkeyaes(args...) __emcore_syscall->hwkeyaes(args)
 | 
| 186 |  | -#define hmacsha1(args...) __emcore_syscall->hmacsha1(args)
 | 
| 187 |  | -#define reset(args...) __emcore_syscall->reset(args)
 | 
| 188 |  | -#define int_dma_set_handler(args...) __emcore_syscall->int_dma_set_handler(args)
 | 
|  | 36 | +#define panic __emcore_syscall->panic | 
|  | 37 | +#define panicf __emcore_syscall->panicf | 
|  | 38 | +#define cprintf __emcore_syscall->cprintf | 
|  | 39 | +#define cvprintf __emcore_syscall->cvprintf | 
|  | 40 | +#define cputc __emcore_syscall->cputc | 
|  | 41 | +#define cputs __emcore_syscall->cputs | 
|  | 42 | +#define cwrite __emcore_syscall->cwrite | 
|  | 43 | +#define cflush __emcore_syscall->cflush | 
|  | 44 | +#define cgetc __emcore_syscall->cgetc | 
|  | 45 | +#define cread __emcore_syscall->cread | 
|  | 46 | +#define creada __emcore_syscall->creada | 
|  | 47 | +#define opendir __emcore_syscall->opendir | 
|  | 48 | +#define closedir __emcore_syscall->closedir | 
|  | 49 | +#define readdir __emcore_syscall->readdir | 
|  | 50 | +#define mkdir __emcore_syscall->mkdir | 
|  | 51 | +#define rmdir __emcore_syscall->rmdir | 
|  | 52 | +#define renderbmp __emcore_syscall->renderbmp | 
|  | 53 | +#define renderchar __emcore_syscall->renderchar | 
|  | 54 | +#define rendertext __emcore_syscall->rendertext | 
|  | 55 | +#define renderfillrect __emcore_syscall->renderfillrect | 
|  | 56 | +#define get_font_width __emcore_syscall->get_font_width | 
|  | 57 | +#define get_font_height __emcore_syscall->get_font_height | 
|  | 58 | +#define execimage __emcore_syscall->execimage | 
|  | 59 | +#define ftruncate __emcore_syscall->ftruncate | 
|  | 60 | +#define fsync __emcore_syscall->fsync | 
|  | 61 | +#define close __emcore_syscall->close | 
|  | 62 | +#define write __emcore_syscall->write | 
|  | 63 | +#define read __emcore_syscall->read | 
|  | 64 | +#define lseek __emcore_syscall->lseek | 
|  | 65 | +#define remove __emcore_syscall->remove | 
|  | 66 | +#define file_open __emcore_syscall->file_open | 
|  | 67 | +#define rename __emcore_syscall->rename | 
|  | 68 | +#define file_creat __emcore_syscall->file_creat | 
|  | 69 | +#define filesize __emcore_syscall->filesize | 
|  | 70 | +#define format __emcore_syscall->format | 
|  | 71 | +#define vuprintf __emcore_syscall->vuprintf | 
|  | 72 | +#define lcdconsole_putc_noblit __emcore_syscall->lcdconsole_putc_noblit | 
|  | 73 | +#define lcdconsole_puts_noblit __emcore_syscall->lcdconsole_puts_noblit | 
|  | 74 | +#define lcdconsole_write_noblit __emcore_syscall->lcdconsole_write_noblit | 
|  | 75 | +#define lcdconsole_update __emcore_syscall->lcdconsole_update | 
|  | 76 | +#define lcdconsole_putc __emcore_syscall->lcdconsole_putc | 
|  | 77 | +#define lcdconsole_puts __emcore_syscall->lcdconsole_puts | 
|  | 78 | +#define lcdconsole_write __emcore_syscall->lcdconsole_write | 
|  | 79 | +#define lcdconsole_get_current_x __emcore_syscall->lcdconsole_get_current_x | 
|  | 80 | +#define lcdconsole_get_current_y __emcore_syscall->lcdconsole_get_current_y | 
|  | 81 | +#define lcdconsole_get_lineend_x __emcore_syscall->lcdconsole_get_lineend_x | 
|  | 82 | +#define lcdconsole_get_lineend_y __emcore_syscall->lcdconsole_get_lineend_y | 
|  | 83 | +#define lcdconsole_progressbar __emcore_syscall->lcdconsole_progressbar | 
|  | 84 | +#define progressbar_init __emcore_syscall->progressbar_init | 
|  | 85 | +#define progressbar_setpos __emcore_syscall->progressbar_setpos | 
|  | 86 | +#define shutdown __emcore_syscall->shutdown | 
|  | 87 | +#define storage_read_sectors_md __emcore_syscall->storage_read_sectors_md | 
|  | 88 | +#define storage_write_sectors_md __emcore_syscall->storage_write_sectors_md | 
|  | 89 | +#define storage_get_info __emcore_syscall->storage_get_info | 
|  | 90 | +#define strcasecmp __emcore_syscall->strcasecmp | 
|  | 91 | +#define strncasecmp __emcore_syscall->strncasecmp | 
|  | 92 | +#define strcasestr __emcore_syscall->strcasestr | 
|  | 93 | +#define strlcat __emcore_syscall->strlcat | 
|  | 94 | +#define strlcpy __emcore_syscall->strlcpy | 
|  | 95 | +#define mutex_init __emcore_syscall->mutex_init | 
|  | 96 | +#define mutex_lock __emcore_syscall->mutex_lock | 
|  | 97 | +#define mutex_unlock __emcore_syscall->mutex_unlock | 
|  | 98 | +#define wakeup_init __emcore_syscall->wakeup_init | 
|  | 99 | +#define wakeup_wait __emcore_syscall->wakeup_wait | 
|  | 100 | +#define wakeup_signal __emcore_syscall->wakeup_signal | 
|  | 101 | +#define sleep __emcore_syscall->sleep | 
|  | 102 | +#define thread_create __emcore_syscall->thread_create | 
|  | 103 | +#define thread_exit __emcore_syscall->thread_exit | 
|  | 104 | +#define thread_suspend __emcore_syscall->thread_suspend | 
|  | 105 | +#define thread_resume __emcore_syscall->thread_resume | 
|  | 106 | +#define thread_terminate __emcore_syscall->thread_terminate | 
|  | 107 | +#define __errno __emcore_syscall->__errno | 
|  | 108 | +#define ucl_decompress __emcore_syscall->ucl_decompress | 
|  | 109 | +#define bootflash_filesize __emcore_syscall->bootflash_filesize | 
|  | 110 | +#define bootflash_attributes __emcore_syscall->bootflash_attributes | 
|  | 111 | +#define bootflash_getaddr __emcore_syscall->bootflash_getaddr | 
|  | 112 | +#define bootflash_read __emcore_syscall->bootflash_read | 
|  | 113 | +#define bootflash_readraw __emcore_syscall->bootflash_readraw | 
|  | 114 | +#define bootflash_writeraw __emcore_syscall->bootflash_writeraw | 
|  | 115 | +#define bootflash_getrawaddr __emcore_syscall->bootflash_getrawaddr | 
|  | 116 | +#define bootflash_is_memmapped __emcore_syscall->bootflash_is_memmapped | 
|  | 117 | +#define read_native_timer __emcore_syscall->read_native_timer | 
|  | 118 | +#define read_usec_timer __emcore_syscall->read_usec_timer | 
|  | 119 | +#define i2c_send __emcore_syscall->i2c_send | 
|  | 120 | +#define i2c_recv __emcore_syscall->i2c_recv | 
|  | 121 | +#define i2c_sendbyte __emcore_syscall->i2c_sendbyte | 
|  | 122 | +#define i2c_recvbyte __emcore_syscall->i2c_recvbyte | 
|  | 123 | +#define interrupt_enable __emcore_syscall->interrupt_enable | 
|  | 124 | +#define interrupt_set_handler __emcore_syscall->interrupt_set_handler | 
|  | 125 | +#define int_timer_set_handler __emcore_syscall->int_timer_set_handler | 
|  | 126 | +#define displaylcd __emcore_syscall->displaylcd | 
|  | 127 | +#define displaylcd_sync __emcore_syscall->displaylcd_sync | 
|  | 128 | +#define displaylcd_busy __emcore_syscall->displaylcd_busy | 
|  | 129 | +#define displaylcd_safe __emcore_syscall->displaylcd_safe | 
|  | 130 | +#define lcd_get_width __emcore_syscall->lcd_get_width | 
|  | 131 | +#define lcd_get_height __emcore_syscall->lcd_get_height | 
|  | 132 | +#define lcd_get_bytes_per_pixel __emcore_syscall->lcd_get_bytes_per_pixel | 
|  | 133 | +#define lcd_translate_color __emcore_syscall->lcd_translate_color | 
|  | 134 | +#define clean_dcache __emcore_syscall->clean_dcache | 
|  | 135 | +#define invalidate_dcache __emcore_syscall->invalidate_dcache | 
|  | 136 | +#define invalidate_icache __emcore_syscall->invalidate_icache | 
|  | 137 | +#define power_off __emcore_syscall->power_off | 
|  | 138 | +#define charging_state __emcore_syscall->charging_state | 
|  | 139 | +#define atoi __emcore_syscall->atoi | 
|  | 140 | +#define memchr __emcore_syscall->memchr | 
|  | 141 | +#define memcmp __emcore_syscall->memcmp | 
|  | 142 | +#define memcpy __emcore_syscall->memcpy | 
|  | 143 | +#define memmove __emcore_syscall->memmove | 
|  | 144 | +#define memset __emcore_syscall->memset | 
|  | 145 | +#define qsort __emcore_syscall->qsort | 
|  | 146 | +#define srand __emcore_syscall->srand | 
|  | 147 | +#define rand __emcore_syscall->rand | 
|  | 148 | +#define snprintf __emcore_syscall->snprintf | 
|  | 149 | +#define vsnprintf __emcore_syscall->vsnprintf | 
|  | 150 | +#define isspace __emcore_syscall->isspace | 
|  | 151 | +#define isdigit __emcore_syscall->isdigit | 
|  | 152 | +#define isxdigit __emcore_syscall->isxdigit | 
|  | 153 | +#define sscanf __emcore_syscall->sscanf | 
|  | 154 | +#define strcat __emcore_syscall->strcat | 
|  | 155 | +#define strchr __emcore_syscall->strchr | 
|  | 156 | +#define strcmp __emcore_syscall->strcmp | 
|  | 157 | +#define strcpy __emcore_syscall->strcpy | 
|  | 158 | +#define strlen __emcore_syscall->strlen | 
|  | 159 | +#define strncmp __emcore_syscall->strncmp | 
|  | 160 | +#define strrchr __emcore_syscall->strrchr | 
|  | 161 | +#define strstr __emcore_syscall->strstr | 
|  | 162 | +#define strtok_r __emcore_syscall->strtok_r | 
|  | 163 | +#define backlight_on __emcore_syscall->backlight_on | 
|  | 164 | +#define backlight_set_fade __emcore_syscall->backlight_set_fade | 
|  | 165 | +#define backlight_set_brightness __emcore_syscall->backlight_set_brightness | 
|  | 166 | +#define get_platform_id __emcore_syscall->get_platform_id | 
|  | 167 | +#define tlsf_create __emcore_syscall->tlsf_create | 
|  | 168 | +#define tlsf_destroy __emcore_syscall->tlsf_destroy | 
|  | 169 | +#define tlsf_malloc __emcore_syscall->tlsf_malloc | 
|  | 170 | +#define tlsf_memalign __emcore_syscall->tlsf_memalign | 
|  | 171 | +#define tlsf_realloc __emcore_syscall->tlsf_realloc | 
|  | 172 | +#define tlsf_free __emcore_syscall->tlsf_free | 
|  | 173 | +#define tlsf_walk_heap __emcore_syscall->tlsf_walk_heap | 
|  | 174 | +#define tlsf_check_heap __emcore_syscall->tlsf_check_heap | 
|  | 175 | +#define tlsf_block_size __emcore_syscall->tlsf_block_size | 
|  | 176 | +#define tlsf_overhead __emcore_syscall->tlsf_overhead | 
|  | 177 | +#define execfirmware __emcore_syscall->execfirmware | 
|  | 178 | +#define button_register_handler __emcore_syscall->button_register_handler | 
|  | 179 | +#define button_unregister_handler __emcore_syscall->button_unregister_handler | 
|  | 180 | +#define clickwheel_get_state __emcore_syscall->clickwheel_get_state | 
|  | 181 | +#define clockgate_enable __emcore_syscall->clockgate_enable | 
|  | 182 | +#define context_switch __emcore_syscall->context_switch | 
|  | 183 | +#define disk_mount __emcore_syscall->disk_mount | 
|  | 184 | +#define disk_unmount __emcore_syscall->disk_unmount | 
|  | 185 | +#define hwkeyaes __emcore_syscall->hwkeyaes | 
|  | 186 | +#define hmacsha1 __emcore_syscall->hmacsha1 | 
|  | 187 | +#define reset __emcore_syscall->reset | 
|  | 188 | +#define int_dma_set_handler __emcore_syscall->int_dma_set_handler | 
|  | 189 | +#define thread_set_name __emcore_syscall->thread_set_name | 
|  | 190 | +#define thread_set_priority __emcore_syscall->thread_set_priority | 
| 189 | 191 |  | 
| 190 | 192 |  | 
| 191 | 193 | #endif | 
| Index: emcore/trunk/export/syscallapi.h | 
| — | — | @@ -68,7 +68,7 @@ | 
| 69 | 69 | /* update this to latest version if a change to the api struct breaks | 
| 70 | 70 | backwards compatibility (and please take the opportunity to sort in any | 
| 71 | 71 | new function which are "waiting" at the end of the function table) */ | 
| 72 |  | -#define EMCORE_MIN_API_VERSION 0
 | 
|  | 72 | +#define EMCORE_MIN_API_VERSION 1 | 
| 73 | 73 |  | 
| 74 | 74 | /* NOTE: To support backwards compatibility, only add new functions at | 
| 75 | 75 | the end of the structure.  Every time you add a new function, | 
| — | — | @@ -229,6 +229,8 @@ | 
| 230 | 230 | typeof(hmacsha1) *hmacsha1; | 
| 231 | 231 | typeof(reset) *reset; | 
| 232 | 232 | typeof(int_dma_set_handler) *int_dma_set_handler; | 
|  | 233 | +    typeof(thread_set_name) *thread_set_name; | 
|  | 234 | +    typeof(thread_set_priority) *thread_set_priority; | 
| 233 | 235 | }; | 
| 234 | 236 |  | 
| 235 | 237 |  | 
| Index: emcore/trunk/syscallapi.c | 
| — | — | @@ -196,5 +196,7 @@ | 
| 197 | 197 | #ifdef HAVE_HMACSHA1 | 
| 198 | 198 | .hmacsha1 = hmacsha1, | 
| 199 | 199 | #endif | 
| 200 |  | -    .int_dma_set_handler = int_dma_set_handler
 | 
|  | 200 | +    .int_dma_set_handler = int_dma_set_handler, | 
|  | 201 | +    .thread_set_name = thread_set_name, | 
|  | 202 | +    .thread_set_priority = thread_set_priority | 
| 201 | 203 | }; | 
| Index: emcore/trunk/thread.c | 
| — | — | @@ -434,6 +434,22 @@ | 
| 435 | 435 | return ret; | 
| 436 | 436 | } | 
| 437 | 437 |  | 
|  | 438 | +void thread_set_name(struct scheduler_thread* thread, char* name) | 
|  | 439 | +{ | 
|  | 440 | +    uint32_t mode = enter_critical_section(); | 
|  | 441 | +    if (!thread) thread = current_thread; | 
|  | 442 | +    thread->name = name; | 
|  | 443 | +    leave_critical_section(mode); | 
|  | 444 | +} | 
|  | 445 | + | 
|  | 446 | +void thread_set_priority(struct scheduler_thread* thread, int priority) | 
|  | 447 | +{ | 
|  | 448 | +    uint32_t mode = enter_critical_section(); | 
|  | 449 | +    if (!thread) thread = current_thread; | 
|  | 450 | +    thread->priority = priority; | 
|  | 451 | +    leave_critical_section(mode); | 
|  | 452 | +} | 
|  | 453 | + | 
| 438 | 454 | int thread_terminate(struct scheduler_thread* thread) | 
| 439 | 455 | { | 
| 440 | 456 | struct scheduler_thread* t; | 
| Index: emcore/trunk/usb/usb.c | 
| — | — | @@ -560,6 +560,7 @@ | 
| 561 | 561 | case 21:  // EXECIMAGE | 
| 562 | 562 | if (set_dbgaction(DBGACTION_EXECIMAGE, 0)) break; | 
| 563 | 563 | dbgactionaddr = dbgrecvbuf[1]; | 
|  | 564 | +            dbgactiontype = dbgrecvbuf[2]; | 
| 564 | 565 | break; | 
| 565 | 566 | #ifdef HAVE_BOOTFLASH | 
| 566 | 567 | case 22:  // READ BOOT FLASH | 
| — | — | @@ -735,7 +736,7 @@ | 
| 736 | 737 | break; | 
| 737 | 738 | case DBGACTION_EXECIMAGE: | 
| 738 | 739 | dbgasyncsendbuf[0] = 1; | 
| 739 |  | -                dbgasyncsendbuf[1] = execimage((void*)dbgactionaddr, false);
 | 
|  | 740 | +                dbgasyncsendbuf[1] = (uint32_t)execimage((void*)dbgactionaddr, dbgactiontype); | 
| 740 | 741 | usb_drv_send_nonblocking(dbgendpoints[1], dbgasyncsendbuf, 16); | 
| 741 | 742 | break; | 
| 742 | 743 | case DBGACTION_EXECFIRMWARE: | 
| Index: emcore/trunk/thread.h | 
| — | — | @@ -120,6 +120,8 @@ | 
| 121 | 121 | enum thread_type type, int priority, bool run); | 
| 122 | 122 | int thread_suspend(struct scheduler_thread* thread); | 
| 123 | 123 | int thread_resume(struct scheduler_thread* thread); | 
|  | 124 | +void thread_set_name(struct scheduler_thread* thread, char* name); | 
|  | 125 | +void thread_set_priority(struct scheduler_thread* thread, int priority); | 
| 124 | 126 | int thread_terminate(struct scheduler_thread* thread); | 
| 125 | 127 | int thread_killlevel(enum thread_type type, bool killself); | 
| 126 | 128 | enum thread_state thread_get_state(struct scheduler_thread* thread); |