64#if defined(__clang__) || defined(__JETBRAINS_IDE__)
65#define BL_CODE_MODEL 1
68#if !defined(BL_CODE_MODEL) && __STDC_HOSTED__
69#error "compile Blitz libraries with -ffreestanding (see CMakeLists.txt)"
72#pragma GCC optimize ("no-tree-loop-distribute-patterns")
75#include <exec/types.h>
76#include <exec/memory.h>
85static_assert(
sizeof(
BB_BOOL) ==
sizeof(ULONG),
"BB_BOOL must be a long");
105#define BL_WORDRET (-1)
177#define BL_LD(n) ((n) << 8)
178#define BL_LA(n) (0x1000 | ((n) << 8))
179#define BL_LPUSH 0xff00
186#define BL_IFBLITZ 0x8000
187#define BL_IFAMIGA 0x4000
203#define BL_UD0 (BL_LD0 | BL_USED)
204#define BL_UD1 (BL_LD1 | BL_USED)
205#define BL_UD2 (BL_LD2 | BL_USED)
206#define BL_UD3 (BL_LD3 | BL_USED)
207#define BL_UD4 (BL_LD4 | BL_USED)
208#define BL_UD5 (BL_LD5 | BL_USED)
209#define BL_UD6 (BL_LD6 | BL_USED)
210#define BL_UD7 (BL_LD7 | BL_USED)
211#define BL_UA0 (BL_LA0 | BL_USED)
212#define BL_UA1 (BL_LA1 | BL_USED)
213#define BL_UA2 (BL_LA2 | BL_USED)
214#define BL_UA3 (BL_LA3 | BL_USED)
215#define BL_UA6 (BL_LA6 | BL_USED)
217#define BL_BD0 (BL_LD0 | BL_BASE)
218#define BL_BD1 (BL_LD1 | BL_BASE)
219#define BL_BD2 (BL_LD2 | BL_BASE)
220#define BL_BD3 (BL_LD3 | BL_BASE)
221#define BL_BD4 (BL_LD4 | BL_BASE)
222#define BL_BD5 (BL_LD5 | BL_BASE)
223#define BL_BD6 (BL_LD6 | BL_BASE)
224#define BL_BD7 (BL_LD7 | BL_BASE)
225#define BL_BA0 (BL_LA0 | BL_BASE)
226#define BL_BA1 (BL_LA1 | BL_BASE)
227#define BL_BA2 (BL_LA2 | BL_BASE)
228#define BL_BA3 (BL_LA3 | BL_BASE)
229#define BL_BA6 (BL_LA6 | BL_BASE)
239#define BL_IA0 (BL_LA0 | BL_ITEM)
240#define BL_IA1 (BL_LA1 | BL_ITEM)
241#define BL_IA2 (BL_LA2 | BL_ITEM)
242#define BL_IA3 (BL_LA3 | BL_ITEM)
243#define BL_IA6 (BL_LA6 | BL_ITEM)
245#define BL_MD0 (BL_LD0 | BL_MAX)
246#define BL_MD1 (BL_LD1 | BL_MAX)
247#define BL_MD2 (BL_LD2 | BL_MAX)
248#define BL_MD3 (BL_LD3 | BL_MAX)
249#define BL_MD4 (BL_LD4 | BL_MAX)
250#define BL_MD5 (BL_LD5 | BL_MAX)
251#define BL_MD6 (BL_LD6 | BL_MAX)
252#define BL_MD7 (BL_LD7 | BL_MAX)
253#define BL_MA0 (BL_LA0 | BL_MAX)
254#define BL_MA1 (BL_LA1 | BL_MAX)
255#define BL_MA2 (BL_LA2 | BL_MAX)
256#define BL_MA3 (BL_LA3 | BL_MAX)
257#define BL_MA6 (BL_LA6 | BL_MAX)
280#define BL_REG(r) __asm(#r)
287#define BL_CAT_(a, b) a##b
288#define BL_CAT(a, b) BL_CAT_(a, b)
289#define BL_ID(p) BL_CAT(p, __COUNTER__)
291#define BL_NARGS(...) BL_NARGS_(__VA_ARGS__, 20, 19, 18, 17, 16, 15, 14, 13, \
292 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
293#define BL_NARGS_(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, \
294 a15, a16, a17, a18, a19, a20, n, ...) n
298#define BL_HEAD __attribute__((section(".blitzlib.head"), used, aligned(2)))
299#define BL_PACKED __attribute__((packed, aligned(2)))
303#define BL_A(x) ((bl_addr)(x))
307#define BLITZ_ERRCHK __attribute__((section(".blitzlib.errchk"), used))
310#define BLITZ_ERROR_AREA blitz_errchk_start
313#define BLITZ_ROUTINE __attribute__((used))
320#define BLITZ_SYSLIBHEADER(libnum, first, last, init, ret, finit, error, flags) \
321 static const struct BL_PACKED { UWORD moveq, rts; UWORD num; ULONG z6; \
322 UWORD za, fl, ft, lt; ULONG z12; bl_addr in; WORD rt; bl_addr fi; \
323 ULONG z20, z24, z28; bl_addr er; } BL_ID(bl_header_) BL_HEAD = { \
324 0x7000, 0x4e75, (UWORD)(libnum), 0, 0, (flags), (first), (last), 0, \
325 BL_A(init), (ret), BL_A(finit), 0, 0, 0, BL_A(error) }
329#define BLITZ_SYSLIBHEADER7(libnum, first, last, init, ret, finit, error) \
330 BLITZ_SYSLIBHEADER(libnum, first, last, init, ret, finit, error, 0)
335#define BLITZ_LIBHEADER(libnum, init, ret, finit, error) \
336 BLITZ_SYSLIBHEADER(libnum, 0, 0, init, ret, finit, error, 0)
340#define BL_KIND(v) static const UWORD BL_ID(bl_kind_)[3] BL_HEAD = { (v), 0, 0 }
342#define BLITZ_ASTATEMENT() BL_KIND(1)
343#define BLITZ_USTATEMENT() BL_KIND(8 + 1)
344#define BLITZ_AFUNCTION(t) BL_KIND(((t) << 8) + 2)
345#define BLITZ_UFUNCTION() BL_KIND(8 + 2)
346#define BLITZ_ACOMMAND(t) BL_KIND(((t) << 8) + 3)
349#define BLITZ_ARGS(...) \
350 static const struct BL_PACKED { UWORD n; UBYTE t[BL_NARGS(__VA_ARGS__)]; } \
351 BL_ID(bl_args_) BL_HEAD = { BL_NARGS(__VA_ARGS__), { __VA_ARGS__ } }
352#define BLITZ_ARGS0() static const UWORD BL_ID(bl_args_) BL_HEAD = 0
355#define BLITZ_REPARGS(first, num, ...) \
356 static const struct BL_PACKED { UWORD n; UBYTE t[BL_NARGS(__VA_ARGS__)]; } \
357 BL_ID(bl_repargs_) BL_HEAD = { \
358 ((first) << 12) | ((num) << 8) | BL_NARGS(__VA_ARGS__), { __VA_ARGS__ } }
361#define BLITZ_LIBS(...) \
362 static const UWORD BL_ID(bl_libs_)[] BL_HEAD = { __VA_ARGS__, 0 }
363#define BLITZ_LIBS0() static const UWORD BL_ID(bl_libs_) BL_HEAD = 0
366#define BLITZ_SUBS(code, err1, err2) \
367 static const struct BL_PACKED { bl_addr e1, c, e2; } \
368 BL_ID(bl_subs_) BL_HEAD = { BL_A(err1), BL_A(code), BL_A(err2) }
371#define BLITZ_NAME(name, help) \
372 static const struct BL_PACKED { UWORD m1; ULONG next; UWORD num; \
373 char n[sizeof(name)]; char h[sizeof(help)]; } \
374 BL_ID(bl_name_) BL_HEAD = { 0xffff, 0, 0, name, help }
378#define BLITZ_NAME_AT(label, name, help) \
379 static const struct BL_PACKED { UWORD m1; ULONG next; UWORD num; \
380 char n[sizeof(name)]; char h[sizeof(help)]; } \
381 label BL_HEAD = { 0xffff, 0, 0, name, help }
385#define BLITZ_NULLSUB(code, err1, ...) \
386 BL_KIND(0); BL_NULLSUB_LIBS(__VA_ARGS__); BLITZ_SUBS(code, err1, BL_FIRST(__VA_ARGS__))
387#define BL_FIRST(a, ...) a
388#define BL_NULLSUB_LIBS(err2, ...) \
389 static const UWORD BL_ID(bl_libs_)[] BL_HEAD = { __VA_ARGS__ __VA_OPT__(,) 0 }
393#define BLITZ_DUMTOKE(label, name, help) \
394 static const struct BL_PACKED { UWORD k[3]; ULONG next; UWORD num; \
395 char n[sizeof(name)]; char h[sizeof(help)]; } label BL_HEAD = { \
396 { 8, 0, 0 }, 0, 0, name, help }
399#define BLITZ_LIBFIN() \
400 static const struct BL_PACKED { UWORD m1; ULONG z; } \
401 BL_ID(bl_libfin_) BL_HEAD = { 0xffff, 0 }
411#define BLITZ_LIBFIN7(toke, load, save, use, free, defmax, shift) \
412 static const struct BL_PACKED { UWORD m1; bl_addr t, l, s, u, f; \
413 UWORD z, mx, sh; } BL_ID(bl_libfin_) BL_HEAD = { 0xffff, \
414 BL_A(toke), BL_A(load), BL_A(save), BL_A(use), BL_A(free), 0, \
428#define BLITZ_OSLIBHEADER(libnum, init, ret, finit) \
429 static const struct BL_PACKED { UWORD z0, z2; UWORD num; ULONG z6; \
430 UWORD za, fl, ft, lt; ULONG z12; bl_addr in; WORD rt; bl_addr fi; \
431 ULONG z20, z24, z28; bl_addr er; } BL_ID(bl_header_) BL_HEAD = { \
432 0, 0, (UWORD)(libnum), 0, 0, 0, 0, 0, 0, \
433 BL_A(init), (ret), BL_A(finit), 0, 0, 0, 0 }
437#define BL_OSR_d0 0x00
438#define BL_OSR_d1 0x01
439#define BL_OSR_d2 0x02
440#define BL_OSR_d3 0x03
441#define BL_OSR_d4 0x04
442#define BL_OSR_d5 0x05
443#define BL_OSR_d6 0x06
444#define BL_OSR_d7 0x07
445#define BL_OSR_a0 0x10
446#define BL_OSR_a1 0x11
447#define BL_OSR_a2 0x12
448#define BL_OSR_a3 0x13
449#define BL_OSR_a4 0x14
450#define BL_OSR_a5 0x15
451#define BL_OSR_a6 0x16
452#define BL_OSR_a7 0x17
455#define BL_OSREGS(...) BL_CAT(BL_OSR_N, BL_NARGS(__VA_ARGS__))(__VA_ARGS__)
456#define BL_OSR_N1(r) BL_OSR_##r,
457#define BL_OSR_N2(r, ...) BL_OSR_##r, BL_OSR_N1(__VA_ARGS__)
458#define BL_OSR_N3(r, ...) BL_OSR_##r, BL_OSR_N2(__VA_ARGS__)
459#define BL_OSR_N4(r, ...) BL_OSR_##r, BL_OSR_N3(__VA_ARGS__)
460#define BL_OSR_N5(r, ...) BL_OSR_##r, BL_OSR_N4(__VA_ARGS__)
461#define BL_OSR_N6(r, ...) BL_OSR_##r, BL_OSR_N5(__VA_ARGS__)
462#define BL_OSR_N7(r, ...) BL_OSR_##r, BL_OSR_N6(__VA_ARGS__)
463#define BL_OSR_N8(r, ...) BL_OSR_##r, BL_OSR_N7(__VA_ARGS__)
464#define BL_OSR_N9(r, ...) BL_OSR_##r, BL_OSR_N8(__VA_ARGS__)
465#define BL_OSR_N10(r, ...) BL_OSR_##r, BL_OSR_N9(__VA_ARGS__)
466#define BL_OSR_N11(r, ...) BL_OSR_##r, BL_OSR_N10(__VA_ARGS__)
467#define BL_OSR_N12(r, ...) BL_OSR_##r, BL_OSR_N11(__VA_ARGS__)
468#define BL_OSR_N13(r, ...) BL_OSR_##r, BL_OSR_N12(__VA_ARGS__)
469#define BL_OSR_N14(r, ...) BL_OSR_##r, BL_OSR_N13(__VA_ARGS__)
470#define BL_OSR_N15(r, ...) BL_OSR_##r, BL_OSR_N14(__VA_ARGS__)
471#define BL_OSR_N16(r, ...) BL_OSR_##r, BL_OSR_N15(__VA_ARGS__)
472#define BL_OSR_N17(r, ...) BL_OSR_##r, BL_OSR_N16(__VA_ARGS__)
473#define BL_OSR_N18(r, ...) BL_OSR_##r, BL_OSR_N17(__VA_ARGS__)
474#define BL_OSR_N19(r, ...) BL_OSR_##r, BL_OSR_N18(__VA_ARGS__)
476#define BL_NOSREGS(...) (0 __VA_OPT__(+ BL_NARGS(__VA_ARGS__)))
484#define BLITZ_OSCALL(oslib, lvo, name, help, ...) \
485 static const struct BL_PACKED { UWORD k[3]; UWORD lib; WORD off; \
486 UBYTE r[(BL_NOSREGS(__VA_ARGS__) + 2) & ~1]; ULONG next; UWORD num; \
487 char n[sizeof(name)]; char h[sizeof(help)]; } \
488 BL_ID(bl_oscall_) BL_HEAD = { { 6, 0, 0 }, (oslib), (lvo), \
489 { __VA_OPT__(BL_OSREGS(__VA_ARGS__)) 0xff }, 0, 0, name, help }
496#define BLITZ_ENTRY_DECL(label) extern const UWORD label[]
502#define BLITZ_ENTRY_C(f) extern char e_##f[] __asm__("_" #f)
510#define BLITZ_AMIGAONLY(code) ((char *)(code) + 1)
511#define BLITZ_BLITZONLY ((void *)1)
512#define BLITZ_BLITZONLY_CHK(chk) ((char *)(chk) + 1)
513#define BLITZ_NULLSUB_AT(label, code, err1, ...) \
514 const UWORD label[3] BL_HEAD = { 0, 0, 0 }; \
515 BL_NULLSUB_LIBS(__VA_ARGS__); BLITZ_SUBS(code, err1, BL_FIRST(__VA_ARGS__))
526#define BL_TOKVAL(tok, form) (0x80000000UL | ((ULONG)(form) << 16) | (UWORD)(tok))
527#define BL_BTOKVAL(tok, form) (0xC0000000UL | ((ULONG)(form) << 16) | (UWORD)(tok))
528#define BLITZ_TOKE(tok) ((void *)(blitz_tok + BL_TOKVAL(tok, 0)))
533#define BL_STR(x) BL_STR_(x)
534#define BL_ASMTOK(lib, n) "0x80000000+((" BL_STR(lib) "<<7)+" BL_STR(n) ")"
553#define BL_A3_ "+a"(blitz_string)
554#define BLITZ_ALIBJSR(tok, r) BL_JSR_(BL_TOKVAL(tok, 0), r)
555#define BLITZ_ALIBJSR_FORM(tok, form, r) BL_JSR_(BL_TOKVAL(tok, form), r)
556#define BLITZ_BLIBJSR(tok, r) BL_JSR_(BL_BTOKVAL(tok, 0), r)
558#define BL_JSR_(val, r) ({ \
559 register ULONG _d0 __asm("d0") = (r).d0; \
560 register ULONG _d1 __asm("d1") = (r).d1; \
561 register ULONG _a0 __asm("a0") = (r).a0; \
562 register ULONG _a1 __asm("a1") = (r).a1; \
563 __asm volatile("jsr _blitz_tok+%c5" \
564 : "+d"(_d0), "+d"(_d1), "+a"(_a0), "+a"(_a1), BL_A3_ : "i"(val) \
565 : "d2", "d3", "d4", "d5", "d6", "d7", "a2", "a6", "cc", "memory"); \
566 (r).d0 = _d0; (r).d1 = _d1; (r).a0 = _a0; (r).a1 = _a1; _d0; })
568ULONG bl_jsr_clang(ULONG val,
struct bl_regs *r);
569#define BL_JSR_(val, r) bl_jsr_clang(val, &(r))
582#define BLITZ_BASEJSR(base, off, r) ({ \
583 register ULONG _d0 __asm("d0") = (r).d0; \
584 register ULONG _d1 __asm("d1") = (r).d1; \
585 register ULONG _a0 __asm("a0") = (r).a0; \
586 register ULONG _a1 __asm("a1") = (r).a1; \
587 register const void *_a6 __asm("a6") = (base); \
588 __asm volatile("jsr %c5(a6)" \
589 : "+d"(_d0), "+d"(_d1), "+a"(_a0), "+a"(_a1), "+a"(_a6) : "i"(off) \
590 : "d2", "d3", "d4", "d5", "d6", "d7", "a2", "cc", "memory"); \
591 (r).d0 = _d0; (r).d1 = _d1; (r).a0 = _a0; (r).a1 = _a1; _d0; })
593ULONG bl_basejsr_clang(
const void *base,
int off,
struct bl_regs *r);
594#define BLITZ_BASEJSR(base, off, r) bl_basejsr_clang(base, off, &(r))
624#define BLITZ_SYSJSR(base, off, r) ({ \
625 register ULONG _d0 __asm("d0") = (r).d0; \
626 register ULONG _d1 __asm("d1") = (r).d1; \
627 register ULONG _a0 __asm("a0") = (r).a0; \
628 register ULONG _a1 __asm("a1") = (r).a1; \
629 register const void *_a6 __asm("a6") = (base); \
630 __asm volatile("jsr %c5(a6)" \
631 : "+d"(_d0), "+d"(_d1), "+a"(_a0), "+a"(_a1) : "a"(_a6), "i"(off) \
633 (r).d0 = _d0; (r).d1 = _d1; (r).a0 = _a0; (r).a1 = _a1; _d0; })
634#define BLITZ_SYSJSR1(base, off, x0) ({ \
635 register ULONG _d0 __asm("d0") = (x0); \
636 register const void *_a6 __asm("a6") = (base); \
637 __asm volatile("jsr %c2(a6)" \
638 : "+d"(_d0) : "a"(_a6), "i"(off) \
639 : "d1", "a0", "a1", "cc", "memory"); \
641#define BLITZ_SYSJSR2(base, off, x0, x1) ({ \
642 register ULONG _d0 __asm("d0") = (x0); \
643 register ULONG _d1 __asm("d1") = (x1); \
644 register const void *_a6 __asm("a6") = (base); \
645 __asm volatile("jsr %c3(a6)" \
646 : "+d"(_d0), "+d"(_d1) : "a"(_a6), "i"(off) \
647 : "a0", "a1", "cc", "memory"); \
650#define BLITZ_SYSJSR(base, off, r) bl_basejsr_clang(base, off, &(r))
651#define BLITZ_SYSJSR1(base, off, x0) ({ \
652 struct bl_regs r_ = { .d0 = (x0) }; BLITZ_SYSJSR(base, off, r_); })
653#define BLITZ_SYSJSR2(base, off, x0, x1) ({ \
654 struct bl_regs r_ = { .d0 = (x0), .d1 = (x1) }; \
655 BLITZ_SYSJSR(base, off, r_); })
668#define BLITZ_ALIBJSR_A6(tok, base, x) ({ \
669 register ULONG _d0 __asm("d0") = (x); \
670 register const void *_a6 __asm("a6") = (base); \
671 __asm volatile("jsr _blitz_tok+%c3" \
672 : "+d"(_d0), "+a"(_a6), BL_A3_ : "i"(BL_TOKVAL(tok, 0)) \
673 : "d1", "d2", "d3", "d4", "d5", "d6", "d7", "a0", "a1", "cc", "memory"); \
676#define BLITZ_ALIBJSR_A6(tok, base, x) ((void)(base), (ULONG)(x))
684#define BLITZ_ALIBJSR_A2A6(tok, x, a2v, a6v) ({ \
685 register ULONG _d0 __asm("d0") = (ULONG)(x); \
686 register const void *_a2 __asm("a2") = (a2v); \
687 register const void *_a6 __asm("a6") = (a6v); \
688 __asm volatile("jsr _blitz_tok+%c4" \
689 : "+d"(_d0), "+a"(_a2), "+a"(_a6), BL_A3_ : "i"(BL_TOKVAL(tok, 0)) \
690 : "d1", "d2", "d3", "d4", "d5", "d6", "d7", "a0", "a1", "cc", "memory"); \
693#define BLITZ_ALIBJSR_A2A6(tok, x, a2v, a6v) ((void)(a2v), (void)(a6v), (ULONG)(x))
702#define BLITZ_ALIBJSR_CCR(tok, r, cc) ({ \
703 register ULONG _d0 __asm("d0") = (r).d0; \
704 register ULONG _d1 __asm("d1") = (r).d1; \
705 register ULONG _a0 __asm("a0") = (r).a0; \
706 register ULONG _a1 __asm("a1") = (r).a1; \
708 __asm volatile("jsr _blitz_tok+%c6\n\ts" cc " %4" \
709 : "+d"(_d0), "+d"(_d1), "+a"(_a0), "+a"(_a1), "=m"(_cc), BL_A3_ \
710 : "i"(BL_TOKVAL(tok, 0)) \
711 : "d2", "d3", "d4", "d5", "d6", "d7", "a2", "a6", "cc", "memory"); \
712 (r).d0 = _d0; (r).d1 = _d1; (r).a0 = _a0; (r).a1 = _a1; _cc; })
714#define BLITZ_ALIBJSR_CCR(tok, r, cc) ((void)(r), (UBYTE)0)
722#define BLITZ_ALIBJSR_CCR_D0A0(tok, cc, d0p, a0v) ({ \
723 register ULONG _d0 __asm("d0") = *(d0p); \
724 register ULONG _d1 __asm("d1"); \
725 register const void *_a0 __asm("a0") = (a0v); \
726 register ULONG _a1 __asm("a1"); \
728 __asm volatile("jsr _blitz_tok+%c6\n\ts" cc " %4" \
729 : "+d"(_d0), "=d"(_d1), "+a"(_a0), "=a"(_a1), "=m"(_cc), BL_A3_ \
730 : "i"(BL_TOKVAL(tok, 0)) \
731 : "d2", "d3", "d4", "d5", "d6", "d7", "a2", "a6", "cc", "memory"); \
732 *(d0p) = _d0; _cc; })
734#define BLITZ_ALIBJSR_CCR_D0A0(tok, cc, d0p, a0v) ((void)(a0v), (UBYTE)*(d0p))
743#define BL_JSR_D4_(val, x0, x1, x2, x3) ({ \
744 register ULONG _d0 __asm("d0") = (x0); \
745 register ULONG _d1 __asm("d1") = (x1); \
746 register ULONG _d2 __asm("d2") = (x2); \
747 register ULONG _d3 __asm("d3") = (x3); \
748 __asm volatile("jsr _blitz_tok+%c5" \
749 : "+d"(_d0), "+d"(_d1), "+d"(_d2), "+d"(_d3), BL_A3_ : "i"(val) \
750 : "d4", "d5", "d6", "d7", "a0", "a1", "a2", "a6", "cc", "memory"); \
753#define BL_JSR_D4_(val, x0, x1, x2, x3) \
754 ((void)(x1), (void)(x2), (void)(x3), (ULONG)(x0))
756#define BLITZ_ALIBJSR_D4(tok, x0, x1, x2, x3) \
757 BL_JSR_D4_(BL_TOKVAL(tok, 0), x0, x1, x2, x3)
758#define BLITZ_BLIBJSR_D4(tok, x0, x1, x2, x3) \
759 BL_JSR_D4_(BL_BTOKVAL(tok, 0), x0, x1, x2, x3)
779#define BL_NOIPA_ __attribute__((noipa))
783#define BL_ASM_FUNC_(attrs, name, text) \
784 attrs BL_NOIPA_ void name(void) \
786 __asm volatile(text); \
787 __builtin_unreachable(); \
805#define BLITZ_THUNK(entry, cfunc, save) BL_THUNK_(entry, cfunc, save, "", "")
816#define BLITZ_ALIAS(entry, cfunc) \
817 __asm__(" .globl _" #entry "\n .set _" #entry ",_" #cfunc)
837#define BLITZ_ENTRYPOINT __entrypoint __attribute__((no_icf))
839#define BLITZ_ENTRYPOINT
841#define BLITZ_ALIAS_EP(entry, cfunc) \
842 __asm__(" .globl _" #entry "\n .set _" #entry ",_" #cfunc \
843 "\n .globl ___blitz_entrypoint_" #entry \
844 "\n .set ___blitz_entrypoint_" #entry ",_" #cfunc)
848#define BLITZ_EP_MARK(cfunc) \
849 __asm__(" .globl ___blitz_entrypoint_" #cfunc \
850 "\n .set ___blitz_entrypoint_" #cfunc ",_" #cfunc)
857#define BLITZ_EP_KEEP_A6() \
858 register ULONG bl_keep_a6_ __asm("a6"); \
859 __asm__ volatile("" : "=a"(bl_keep_a6_))
860#define BLITZ_EP_KEEP_A6_END() __asm__ volatile("" : : "a"(bl_keep_a6_))
862#define BLITZ_EP_KEEP_A6()
863#define BLITZ_EP_KEEP_A6_END()
865#define BLITZ_THUNK_Z(entry, cfunc, save) \
866 BL_THUNK_(entry, cfunc, save, "", " tst.l d0\n")
867#define BLITZ_THUNK_PRE(entry, cfunc, save, pre) \
868 BL_THUNK_(entry, cfunc, save, " " pre "\n", "")
874#define BLITZ_THUNK_POST(entry, cfunc, save, post) \
875 BL_THUNK_(entry, cfunc, save, "", " " post "\n")
876#define BL_THUNK_(entry, cfunc, save, pre, tail) \
877 BL_ASM_FUNC_(, entry, \
878 " movem.l " save ",-(sp)\n" pre \
879 " jsr _" #cfunc "\n" tail \
880 " movem.l (sp)+," save "\n" \
895#define BLITZ_THUNK_POP(entry, cfunc, save, pre, tail, pop) \
896 BL_ASM_FUNC_(, entry, \
897 " .ifnc \"" save "\",\"\"\n" \
898 " movem.l " save ",-(sp)\n" \
901 " jsr _" #cfunc "\n" \
903 " .ifnc \"" save "\",\"\"\n" \
904 " movem.l (sp)+," save "\n" \
907 " movem.l a0,-(sp)\n" \
908 " movem.l 4(sp),a0\n" \
909 " movem.l a0,4+" #pop "(sp)\n" \
910 " movem.l (sp)+,a0\n" \
911 " lea " #pop "(sp),sp\n" \
928#define BLITZ_ERRCHK_THUNK(entry, cfunc, save) \
929 BL_ASM_FUNC_(BLITZ_ERRCHK, entry, \
930 " movem.l " save ",-(sp)\n" \
931 " jsr _" #cfunc "\n" \
932 " movem.l (sp)+," save "\n" \
943#define BLITZ_ERRCHK_MESSAGE(label, text) \
944 extern const char label[]; \
945 BL_ASM_FUNC_(static BLITZ_ERRCHK, bl_errchk_message_##label, \
946 "_" #label ":\n .asciz \"" text "\"\n .even\n")
952#define BLITZ_ERRCHK_AB(entry, blitz, amiga) \
953 BL_ASM_FUNC_(BLITZ_ERRCHK, entry, \
955 " .long _" #blitz "\n" \
956 " jmp _" #amiga "\n")
966#define BLITZ_ERRCHK_ASM(name, text) \
967 BL_ASM_FUNC_(static BLITZ_ERRCHK, bl_errchk_asm_##name, text "\n")
972#define BLITZ_ASM_ROUTINE(entry, text) BL_ASM_FUNC_(, entry, text "\n")
981#define BLITZ_ASM_BLOCK(name, text) \
982 BL_ASM_FUNC_(static BLITZ_ROUTINE, bl_asm_##name, text "\n")
988#define BLITZ_INLINE(entry, text) \
989 BL_ASM_FUNC_(, entry, \
990 " .word 0xa000,2f-1f\n" \
1000#define BLITZ_AB_ROUTINE(entry, blitzentry, text) \
1001 BL_ASM_FUNC_(, entry, \
1003 " .long _" #blitzentry "\n" text "\n")
1007#ifndef BL_CODE_MODEL
1008#define BLITZ_RUNERR(msg) do { \
1009 register const char *_m __asm("d0") = (msg); \
1010 __asm volatile("trap #0" : : "d"(_m) : "memory"); \
1013#define BLITZ_RUNERR(msg) ((void)(msg))
BB_BOOL
Definition blitzlib.h:84
@ BB_FALSE
Definition blitzlib.h:84
@ BB_TRUE
Definition blitzlib.h:84
char blitz_errchk_start[]
register UBYTE * blitz_locals
Definition blitzlib.h:269
register UBYTE * blitz_globals
Definition blitzlib.h:268
void * bl_addr
Definition blitzlib.h:302
register UBYTE * blitz_string
Definition blitzlib.h:270
Definition blitzlib.h:537
ULONG d0
Definition blitzlib.h:538
ULONG a1
Definition blitzlib.h:538
ULONG d1
Definition blitzlib.h:538
ULONG a0
Definition blitzlib.h:538