diff options
Diffstat (limited to 'foci.h')
-rw-r--r-- | foci.h | 40 |
1 files changed, 24 insertions, 16 deletions
@@ -26,22 +26,22 @@ #define ATTR_LEN (0x3F) #define WORD(name, tname, prev, attr) \ - extern const void *name##_body[]; \ + extern const void * const name##_body[]; \ const struct word_t w_##name = { \ name##_body, prev, attr + sizeof(tname) - 1, tname \ }; \ - const void *name##_body[] = { + const void * const name##_body[] = { #define LIT(x) push, (void *)(x) #define FTH(w) enter, (w##_body) #define END fexit, }; #define NATIVE(name, tname, prev, attr) \ - extern const void *name##_body[]; \ + static const void * const name##_body[2]; \ NAKED void name(void); \ - const struct word_t w_##name = { \ + static const struct word_t w_##name = { \ name##_body, prev, \ (attr | ATTR_NATIVE) + sizeof(tname) - 1, tname \ }; \ - const void *name##_body[] = { name, fexit }; \ + static const void * const name##_body[2] = { name, fexit }; \ NAKED void name(void) #define W(name, tname, prev) WORD(name, tname, prev, 0) @@ -49,36 +49,44 @@ #define N(name, tname, prev) NATIVE(name, tname, prev, 0) #define C(name, tname, prev) NATIVE(name, tname, prev, ATTR_IMMEDIATE) -#define NEXT { goto *(*++pp); } - struct word_t { - const void **body; + const void * const *body; const struct word_t *prev; unsigned char attr; char name[]; } __attribute__ ((packed)); #ifdef FOCI_ARM -// ARM Cortex-M: -register intptr_t * sp asm("r0"); // pointer to stack cells -register intptr_t *** rp asm("r1"); // stack of pp -register intptr_t ** pp asm("r2"); // pointer to ip -register intptr_t tmp asm("r8"); -#define STASH asm("push {r0-r2,r8}") -#define RESTORE asm("pop {r0-r2,r8}") +register intptr_t * sp asm("r4"); // pointer to stack cells +register intptr_t *** rp asm("r5"); // stack of pp +register intptr_t ** pp asm("r6"); // pointer to ip +register intptr_t tmp asm("r7"); +#define STASH asm("push {r4-r7}") +#define RESTORE asm("pop {r4-r7}") +#define NEXT goto *(*++pp) #endif // FOCI_ARM #ifdef FOCI_X86_64 -// x86_64 register intptr_t * sp asm("r12"); // pointer to stack cells register intptr_t *** rp asm("r13"); // stack of pp register intptr_t ** pp asm("r14"); // pointer to ip register intptr_t tmp asm("r15"); #define STASH asm("push %r12; push %r13; push %r14") #define RESTORE asm("pop %r14; pop %r13; pop %r12") +#define NEXT goto *(*++pp) #endif // FOCI_X86_64 +#ifdef FOCI_MSP430 +register intptr_t * sp asm("r4"); // pointer to stack cells +register intptr_t *** rp asm("r5"); // stack of pp +register intptr_t ** pp asm("r6"); // pointer to ip +register intptr_t tmp asm("r7"); +#define STASH asm("push r4; push r5; push r6") +#define RESTORE asm("pop r6; pop r5; pop r4") +#define NEXT asm("incd r6;\n br @r6") +#endif // FOCI_MSP430 + extern void foci_putchar(int); extern int foci_getchar(void); |