aboutsummaryrefslogtreecommitdiffstats
path: root/foci.h
diff options
context:
space:
mode:
authorClyne Sullivan <clyne@bitgloo.com>2025-01-27 14:13:14 -0500
committerClyne Sullivan <clyne@bitgloo.com>2025-01-27 14:13:14 -0500
commitbe2b73fa7b0da33d96200c4f51b8c3f5f76130c3 (patch)
tree53cb2fdc520c2f8d55848b2d620c3e2558ede6a9 /foci.h
parent614978068704180412b9926e3bc647f730492139 (diff)
more const; add msp430 PoC
Diffstat (limited to 'foci.h')
-rw-r--r--foci.h40
1 files changed, 24 insertions, 16 deletions
diff --git a/foci.h b/foci.h
index c61e302..c7d6fcb 100644
--- a/foci.h
+++ b/foci.h
@@ -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);