home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROS_m68k_bin.lha / AROS / include / aros / machine.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-08  |  13.8 KB  |  370 lines

  1. #ifndef AROS_MACHINE_H
  2. #define AROS_MACHINE_H
  3. /*
  4.     (C) 1995-96 AROS - The Amiga Replacement OS
  5.     $Id: machine.h,v 1.12 1997/01/22 02:46:18 ldp Exp $
  6.  
  7.     NOTE: This file must compile *without* any other header !
  8.  
  9.     Desc: machine.h include file for Amiga/m68k
  10.     Lang: english
  11. */
  12.  
  13. /* Information generated by machine.c */
  14. #define AROS_STACK_GROWS_DOWNWARDS 1 /* Stack direction */
  15. #define AROS_BIG_ENDIAN            1 /* Big or little endian */
  16. #define AROS_SIZEOFULONG           4 /* Size of an ULONG */
  17. #define AROS_WORDALIGN             2 /* Alignment for WORD */
  18. #define AROS_LONGALIGN             2 /* Alignment for LONG */
  19. #define AROS_PTRALIGN              2 /* Alignment for PTR */
  20. #define AROS_IPTRALIGN             2 /* Alignment for IPTR */
  21. #define AROS_DOUBLEALIGN           2 /* Alignment for double */
  22. #define AROS_WORSTALIGN            8 /* Worst case alignment */
  23.  
  24. /*
  25.     How much do I have to add to sp to get the address of the first
  26.     byte on the stack?
  27. */
  28. #define SP_OFFSET 0
  29.  
  30. /*
  31.     BCPL datatypes
  32. */
  33. #define AROS_BPTR_TYPE    unsigned long
  34. #define AROS_BSTR_TYPE  unsigned long
  35. #define MKBADDR(a)    (((unsigned long)(a))>>2)
  36. #define BADDR(a)    (((unsigned long)(a))<<2)
  37.  
  38. /*
  39.     One entry in a libraries' jumptable. For assembler compatibility, the
  40.     field jmp should contain the code for an absolute jmp to a 32bit
  41.     address. There are also a couple of macros which you should use to
  42.     access the vector table from C.
  43. */
  44. struct JumpVec
  45. {
  46.     unsigned short jmp;
  47.     unsigned char vec[4];
  48. };
  49.  
  50. /* Any jump to an unimplemented vector will cause an access to this address */
  51. #define _aros_empty_vector        0xc0edbabe
  52.  
  53. /* Internal macros */
  54. #define __AROS_ASMJMP            0x4EF9
  55. #define __AROS_SET_VEC(v,a)             (*(ULONG*)(v)->vec=(ULONG)(a))
  56. #define __AROS_GET_VEC(v)               ((APTR)(*(ULONG*)(v)->vec))
  57.  
  58. /* Use these to acces a vector table */
  59. #define LIB_VECTSIZE            (sizeof (struct JumpVec))
  60. #define __AROS_GETJUMPVEC(lib,n)        ((struct JumpVec *)(((UBYTE *)lib)-(n*LIB_VECTSIZE)))
  61. #define __AROS_GETVECADDR(lib,n)        (__AROS_GET_VEC(__AROS_GETJUMPVEC(lib,n)))
  62. #define __AROS_SETVECADDR(lib,n,addr)   (__AROS_SET_VEC(__AROS_GETJUMPVEC(lib,n),(APTR)(addr)))
  63. #define __AROS_INITVEC(lib,n)           __AROS_GETJUMPVEC(lib,n)->jmp = __AROS_ASMJMP, \
  64.                     __AROS_SETVECADDR(lib,n,_aros_empty_vector)
  65.  
  66. /*
  67.     The following AROS_LVO_CALLs are not protected by #ifdef/#endif pairs.
  68.     This is because these are really the ones to be defined, not the (protected)
  69.     ones from <aros/libcall.h>. Better to have a compiler warning, than to
  70.     define the wrong ones.
  71.  
  72.     The reason to define them this way (jsr offset(a6)), is to jump over the
  73.     library vector, instead of getting the address from offset+2 and jumping
  74.     to that address. Some libraries may be putting something else (e.g. rts)
  75.     in the vector, instead of a 'jsr address'. Fetching the address from such
  76.     a vector would crash the AROS_LVO_CALLs in <aros/libcall.h>
  77.  
  78.     Furthermore, this (and the shorter code) is exactly the reason
  79.     AROS/include/clib/ *.h and AROS/include/proto/ *.h containing the
  80.     non-registerized versions have to be removed from the directory tree.
  81.     If they are removed, gcc will fetch the compiler-specific protos, with
  82.     the inlines (in case of gcc).
  83. */
  84.  
  85. #define LVO_ARGT(t,v,r) t
  86. #define LVO_ARGV(t,v,r) v
  87. #define LVO_ARGR(t,v,r) r
  88.  
  89. #define AROS_LVO_CALL0(rt,bt,bn,offs,name) \
  90. ({                            \
  91.    {                            \
  92.       register rt _##name##_re __asm("d0");        \
  93.       register struct Library *const _##name##_bn __asm("a6") = (struct Library*)(bn);\
  94.       __asm volatile ("jsr a6@(-"#offs"*6:W)"        \
  95.       : "=r" (_##name##_re)                \
  96.       : "r" (_##name##_bn)                \
  97.       : "d0", "d1", "a0", "a1", "cc", "memory");    \
  98.       _##name##_re;                    \
  99.    }                            \
  100. })
  101.  
  102. #define AROS_LVO_CALL0NR(bt,bn,offs,name)        \
  103. ({                            \
  104.    {                            \
  105.       register struct Library *const _##name##_bn __asm("a6") = (struct Library*)(bn);\
  106.       __asm volatile ("jsr a6@(-"#offs":W)"        \
  107.       : /* no output */                    \
  108.       : "r" (_##name##_bn)                \
  109.       : "d0", "d1", "a0", "a1", "cc", "memory");    \
  110.    }                            \
  111. })
  112.  
  113. #define AROS_LVO_CALL1(rt,a1,bt,bn,offs,name) \
  114. ({                            \
  115.    LVO_ARGT(a1) _##name##_v1 = (LVO_ARGV(a1));    \
  116.    {                            \
  117.       register rt _##name##_re __asm("d0");        \
  118.       register struct Library *const _##name##_bn __asm("a6") = (struct Library*)(bn);\
  119.       register LVO_ARGT(a1) _n1 __asm(LVO_ARGR(a1)) = _##name##_v1;    \
  120.       __asm volatile ("jsr a6@(-"#offs"*6:W)"        \
  121.       : "=r" (_##name##_re)                \
  122.       : "r" (_##name##_bn), "r"(_n1)            \
  123.       : "d0", "d1", "a0", "a1", "cc", "memory");    \
  124.       _##name##_re;                    \
  125.    }                            \
  126. })
  127.  
  128. #define AROS_LVO_CALL1NR(a1,bt,bn,offs,name) \
  129. ({                            \
  130.    LVO_ARGT(a1) _##name##_v1 = (LVO_ARGV(a1));    \
  131.    {                            \
  132.       register struct Library *const _##name##_bn __asm("a6") = (struct Library*)(bn);\
  133.       register LVO_ARGT(a1) _n1 __asm(LVO_ARGR(a1)) = _##name##_v1;    \
  134.       __asm volatile ("jsr a6@(-"#offs"*6:W)"        \
  135.       : /* no output */                                 \
  136.       : "r" (_##name##_bn), "r"(_n1)            \
  137.       : "d0", "d1", "a0", "a1", "cc", "memory");    \
  138.    }                            \
  139. })
  140.  
  141. #define AROS_LVO_CALL2(rt,a1,a2,bt,bn,offs,name) \
  142. ({                            \
  143.    LVO_ARGT(a1) _##name##_v1 = (LVO_ARGV(a1));    \
  144.    LVO_ARGT(a2) _##name##_v2 = (LVO_ARGV(a2));    \
  145.    {                            \
  146.       register rt _##name##_re __asm("d0");        \
  147.       register struct Library *const _##name##_bn __asm("a6") = (struct Library*)(bn);\
  148.       register LVO_ARGT(a1) _n1 __asm(LVO_ARGR(a1)) = _##name##_v1;    \
  149.       register LVO_ARGT(a2) _n2 __asm(LVO_ARGR(a2)) = _##name##_v2;    \
  150.       __asm volatile ("jsr a6@(-"#offs"*6:W)"        \
  151.       : "=r" (_##name##_re)                \
  152.       : "r" (_##name##_bn), "r"(_n1), "r"(_n2)        \
  153.       : "d0", "d1", "a0", "a1", "cc", "memory");    \
  154.       _##name##_re;                    \
  155.    }                            \
  156. })
  157.  
  158. #define AROS_LVO_CALL2NR(a1,a2,bt,bn,offs,name) \
  159. ({                            \
  160.    LVO_ARGT(a1) _##name##_v1 = (LVO_ARGV(a1));    \
  161.    LVO_ARGT(a2) _##name##_v2 = (LVO_ARGV(a2));    \
  162.    {                            \
  163.       register struct Library *const _##name##_bn __asm("a6") = (struct Library*)(bn);\
  164.       register LVO_ARGT(a1) _n1 __asm(LVO_ARGR(a1)) = _##name##_v1;    \
  165.       register LVO_ARGT(a2) _n2 __asm(LVO_ARGR(a2)) = _##name##_v2;    \
  166.       __asm volatile ("jsr a6@(-"#offs"*6:W)"        \
  167.       : /* no output */                                 \
  168.       : "r" (_##name##_bn), "r"(_n1), "r"(_n2)        \
  169.       : "d0", "d1", "a0", "a1", "cc", "memory");    \
  170.    }                            \
  171. })
  172.  
  173. #define AROS_LVO_CALL3(rt,a1,a2,a3,bt,bn,offs,name) \
  174. ({                            \
  175.    LVO_ARGT(a1) _##name##_v1 = (LVO_ARGV(a1));    \
  176.    LVO_ARGT(a2) _##name##_v2 = (LVO_ARGV(a2));    \
  177.    LVO_ARGT(a3) _##name##_v3 = (LVO_ARGV(a3));    \
  178.    {                            \
  179.       register rt _##name##_re __asm("d0");        \
  180.       register struct Library *const _##name##_bn __asm("a6") = (struct Library*)(bn);\
  181.       register LVO_ARGT(a1) _n1 __asm(LVO_ARGR(a1)) = _##name##_v1;    \
  182.       register LVO_ARGT(a2) _n2 __asm(LVO_ARGR(a2)) = _##name##_v2;    \
  183.       register LVO_ARGT(a3) _n3 __asm(LVO_ARGR(a3)) = _##name##_v3;    \
  184.       __asm volatile ("jsr a6@(-"#offs"*6:W)"        \
  185.       : "=r" (_##name##_re)                \
  186.       : "r" (_##name##_bn), "r"(_n1), "r"(_n2), "r"(_n3)\
  187.       : "d0", "d1", "a0", "a1", "cc", "memory");    \
  188.       _##name##_re;                    \
  189.    }                            \
  190. })
  191.  
  192. #define AROS_LVO_CALL3NR(a1,a2,a3,bt,bn,offs,name) \
  193. ({                            \
  194.    LVO_ARGT(a1) _##name##_v1 = (LVO_ARGV(a1));    \
  195.    LVO_ARGT(a2) _##name##_v2 = (LVO_ARGV(a2));    \
  196.    LVO_ARGT(a3) _##name##_v3 = (LVO_ARGV(a3));    \
  197.    {                            \
  198.       register struct Library *const _##name##_bn __asm("a6") = (struct Library*)(bn);\
  199.       register LVO_ARGT(a1) _n1 __asm(LVO_ARGR(a1)) = _##name##_v1;    \
  200.       register LVO_ARGT(a2) _n2 __asm(LVO_ARGR(a2)) = _##name##_v2;    \
  201.       register LVO_ARGT(a3) _n3 __asm(LVO_ARGR(a3)) = _##name##_v3;    \
  202.       __asm volatile ("jsr a6@(-"#offs"*6:W)"        \
  203.       : /* no output */                                 \
  204.       : "r" (_##name##_bn), "r"(_n1), "r"(_n2), "r"(_n3)\
  205.       : "d0", "d1", "a0", "a1", "cc", "memory");    \
  206.    }                            \
  207. })
  208.  
  209. #define AROS_LVO_CALL4(rt,a1,a2,a3,a4,bt,bn,offs,name) \
  210. ({                            \
  211.    LVO_ARGT(a1) _##name##_v1 = (LVO_ARGV(a1));    \
  212.    LVO_ARGT(a2) _##name##_v2 = (LVO_ARGV(a2));    \
  213.    LVO_ARGT(a3) _##name##_v3 = (LVO_ARGV(a3));    \
  214.    LVO_ARGT(a4) _##name##_v4 = (LVO_ARGV(a4));    \
  215.    {                            \
  216.       register rt _##name##_re __asm("d0");        \
  217.       register struct Library *const _##name##_bn __asm("a6") = (struct Library*)(bn);\
  218.       register LVO_ARGT(a1) _n1 __asm(LVO_ARGR(a1)) = _##name##_v1;    \
  219.       register LVO_ARGT(a2) _n2 __asm(LVO_ARGR(a2)) = _##name##_v2;    \
  220.       register LVO_ARGT(a3) _n3 __asm(LVO_ARGR(a3)) = _##name##_v3;    \
  221.       register LVO_ARGT(a4) _n4 __asm(LVO_ARGR(a4)) = _##name##_v4;    \
  222.       __asm volatile ("jsr a6@(-"#offs"*6:W)"        \
  223.       : "=r" (_##name##_re)                \
  224.       : "r" (_##name##_bn), "r"(_n1), "r"(_n2), "r"(_n3), "r"(_n4) \
  225.       : "d0", "d1", "a0", "a1", "cc", "memory");    \
  226.       _##name##_re;                    \
  227.    }                            \
  228. })
  229.  
  230. #define AROS_LVO_CALL4NR(a1,a2,a3,a4,bt,bn,offs,name) \
  231. ({                            \
  232.    LVO_ARGT(a1) _##name##_v1 = (LVO_ARGV(a1));    \
  233.    LVO_ARGT(a2) _##name##_v2 = (LVO_ARGV(a2));    \
  234.    LVO_ARGT(a3) _##name##_v3 = (LVO_ARGV(a3));    \
  235.    LVO_ARGT(a4) _##name##_v4 = (LVO_ARGV(a4));    \
  236.    {                            \
  237.       register struct Library *const _##name##_bn __asm("a6") = (struct Library*)(bn);\
  238.       register LVO_ARGT(a1) _n1 __asm(LVO_ARGR(a1)) = _##name##_v1;    \
  239.       register LVO_ARGT(a2) _n2 __asm(LVO_ARGR(a2)) = _##name##_v2;    \
  240.       register LVO_ARGT(a3) _n3 __asm(LVO_ARGR(a3)) = _##name##_v3;    \
  241.       register LVO_ARGT(a4) _n4 __asm(LVO_ARGR(a4)) = _##name##_v4;    \
  242.       __asm volatile ("jsr a6@(-"#offs"*6:W)"        \
  243.       : /* no output */                                 \
  244.       : "r" (_##name##_bn), "r"(_n1), "r"(_n2), "r"(_n3), "r"(_n4) \
  245.       : "d0", "d1", "a0", "a1", "cc", "memory");    \
  246.    }                            \
  247. })
  248.  
  249. #define AROS_LVO_CALL5(rt,a1,a2,a3,a4,a5,bt,bn,offs,name) \
  250. ({                            \
  251.    LVO_ARGT(a1) _##name##_v1 = (LVO_ARGV(a1));    \
  252.    LVO_ARGT(a2) _##name##_v2 = (LVO_ARGV(a2));    \
  253.    LVO_ARGT(a3) _##name##_v3 = (LVO_ARGV(a3));    \
  254.    LVO_ARGT(a4) _##name##_v4 = (LVO_ARGV(a4));    \
  255.    LVO_ARGT(a5) _##name##_v5 = (LVO_ARGV(a5));    \
  256.    {                            \
  257.       register rt _##name##_re __asm("d0");        \
  258.       register struct Library *const _##name##_bn __asm("a6") = (struct Library*)(bn);\
  259.       register LVO_ARGT(a1) _n1 __asm(LVO_ARGR(a1)) = _##name##_v1;    \
  260.       register LVO_ARGT(a2) _n2 __asm(LVO_ARGR(a2)) = _##name##_v2;    \
  261.       register LVO_ARGT(a3) _n3 __asm(LVO_ARGR(a3)) = _##name##_v3;    \
  262.       register LVO_ARGT(a4) _n4 __asm(LVO_ARGR(a4)) = _##name##_v4;    \
  263.       register LVO_ARGT(a5) _n5 __asm(LVO_ARGR(a5)) = _##name##_v5;    \
  264.       __asm volatile ("jsr a6@(-"#offs"*6:W)"        \
  265.       : "=r" (_##name##_re)                \
  266.       : "r" (_##name##_bn), "r"(_n1), "r"(_n2), "r"(_n3), "r"(_n4), "r"(_n5) \
  267.       : "d0", "d1", "a0", "a1", "cc", "memory");    \
  268.       _##name##_re;                    \
  269.    }                            \
  270. })
  271.  
  272. #define AROS_LVO_CALL5NR(a1,a2,a3,a4,a5,bt,bn,offs,name) \
  273. ({                            \
  274.    LVO_ARGT(a1) _##name##_v1 = (LVO_ARGV(a1));    \
  275.    LVO_ARGT(a2) _##name##_v2 = (LVO_ARGV(a2));    \
  276.    LVO_ARGT(a3) _##name##_v3 = (LVO_ARGV(a3));    \
  277.    LVO_ARGT(a4) _##name##_v4 = (LVO_ARGV(a4));    \
  278.    LVO_ARGT(a5) _##name##_v5 = (LVO_ARGV(a5));    \
  279.    {                            \
  280.       register struct Library *const _##name##_bn __asm("a6") = (struct Library*)(bn);\
  281.       register LVO_ARGT(a1) _n1 __asm(LVO_ARGR(a1)) = _##name##_v1;    \
  282.       register LVO_ARGT(a2) _n2 __asm(LVO_ARGR(a2)) = _##name##_v2;    \
  283.       register LVO_ARGT(a3) _n3 __asm(LVO_ARGR(a3)) = _##name##_v3;    \
  284.       register LVO_ARGT(a4) _n4 __asm(LVO_ARGR(a4)) = _##name##_v4;    \
  285.       register LVO_ARGT(a5) _n5 __asm(LVO_ARGR(a5)) = _##name##_v5;    \
  286.       __asm volatile ("jsr a6@(-"#offs"*6:W)"        \
  287.       : /* no output */                                 \
  288.       : "r" (_##name##_bn), "r"(_n1), "r"(_n2), "r"(_n3), "r"(_n4), "r"(_n5) \
  289.       : "d0", "d1", "a0", "a1", "cc", "memory");    \
  290.    }                            \
  291. })
  292.  
  293. /*
  294.     Find the next valid alignment for a structure if the next x bytes must
  295.     be skipped.
  296. */
  297. #define AROS_ALIGN(x)        (((x)+AROS_WORSTALIGN-1)&-AROS_WORSTALIGN)
  298.  
  299. /* Prototypes */
  300. extern void _aros_not_implemented (void);
  301.  
  302. /* How much stack do we need ? Lots :-) */
  303. #define AROS_STACKSIZE    100000
  304.  
  305. /* The registers */
  306. #define D0 "d0"
  307. #define D1 "d1"
  308. #define D2 "d2"
  309. #define D3 "d3"
  310. #define D4 "d4"
  311. #define D5 "d5"
  312. #define D6 "d6"
  313. #define D7 "d7"
  314. #define A0 "a0"
  315. #define A1 "a1"
  316. #define A2 "a2"
  317. #define A3 "a3"
  318. #define A4 "a4"
  319. #define A5 "a5"
  320. #define A6 "a6"
  321.  
  322. /* SAS/C compatible declarations for register variables */
  323. #ifndef __SASC
  324. #define __d0 __asm("d0")
  325. #define __d1 __asm("d1")
  326. #define __d2 __asm("d2")
  327. #define __d3 __asm("d3")
  328. #define __d4 __asm("d4")
  329. #define __d5 __asm("d5")
  330. #define __d6 __asm("d6")
  331. #define __d7 __asm("d7")
  332.  
  333. #define __a0 __asm("a0")
  334. #define __a1 __asm("a1")
  335. #define __a2 __asm("a2")
  336. #define __a3 __asm("a3")
  337. #define __a4 __asm("a4")
  338. #define __a5 __asm("a5")
  339. #define __a6 __asm("a6")
  340. #endif
  341.  
  342. /* RawDoFmt hook */
  343. #define RDFCALL(hook,data,dptr) ((void(*)(UBYTE __d0,APTR __a3))(hook))(data,dptr);
  344.  
  345. /* What to do with the library base in header, prototype and call */
  346. #define __AROS_LH_BASE(basetype,basename)   basetype basename __asm("a6")
  347. #define __AROS_LP_BASE(basetype,basename)   void * __asm("a6")
  348. #define __AROS_LC_BASE(basetype,basename)   basename
  349.  
  350. /* How to transform an argument in header, prototype and call */
  351. #define __AROS_LHA(type,name,reg)     type name __asm(reg)
  352. #define __AROS_LPA(type,name,reg)     type __asm(reg)
  353. #define __AROS_LCA(type,name,reg)     name
  354. #define __AROS_UFHA(type,name,reg)    type name __asm(reg)
  355. #define __AROS_UFPA(type,name,reg)    type __asm(reg)
  356. #define __AROS_UFCA(type,name,reg)    name
  357.  
  358. /* Prefix for library function in header, prototype and call */
  359. #define __AROS_LH_PREFIX    /* eps */
  360. #define __AROS_LP_PREFIX    /* eps */
  361. #define __AROS_LC_PREFIX    /* eps */
  362. #define __AROS_UFH_PREFIX   /* eps */
  363. #define __AROS_UFP_PREFIX   /* eps */
  364. #define __AROS_UFC_PREFIX   /* eps */
  365.  
  366. /* if this is defined, all AROS_LP*-macros will expand to nothing. */
  367. #define __AROS_USE_MACROS_FOR_LIBCALL
  368.  
  369. #endif /* AROS_MACHINE_H */
  370.