#ifndef AROS_MACHINE_H
#define AROS_MACHINE_H
/*
    (C) 1995-96 AROS - The Amiga Replacement OS
    $Id: machine.h,v 1.7 1996/11/01 02:08:11 aros Exp $

    NOTE: This file must compile *without* any other header !

    Desc: machine.h include file for Amiga/m68k
    Lang: english
*/

/* Information generated by machine.c */
#define AROS_STACK_GROWS_DOWNWARDS 1 /* Stack direction */
#define AROS_BIG_ENDIAN            1 /* Big or little endian */
#define AROS_SIZEOFULONG           4 /* Size of an ULONG */
#define AROS_WORDALIGN             2 /* Alignment for WORD */
#define AROS_LONGALIGN             2 /* Alignment for LONG */
#define AROS_PTRALIGN              2 /* Alignment for PTR */
#define AROS_IPTRALIGN             2 /* Alignment for IPTR */
#define AROS_DOUBLEALIGN           2 /* Alignment for double */
#define AROS_WORSTALIGN            8 /* Worst case alignment */

/*
    How much do I have to add to sp to get the address of the first
    byte on the stack?
*/
#define SP_OFFSET 0

/*
    Replace BPTRs by simple APTRs.
*/
#define AROS_BPTR_TYPE	APTR
#define MKBADDR(a)	((APTR)(a))
#define BADDR(a)	(a)

/*
    One entry in a libraries' jumptable. For assembler compatibility, the
    field jmp should contain the code for an absolute jmp to a 32bit
    address. There are also a couple of macros which you should use to
    access the vector table from C.
*/
struct JumpVec
{
    unsigned short jmp;
    unsigned char vec[4];
};

/* Internal macros */
#define __AROS_ASMJMP			0x4EF9
#define __AROS_SET_VEC(v,a)             (*(ULONG*)(v)->vec=(ULONG)(a))
#define __AROS_GET_VEC(v)               ((APTR)(*(ULONG*)(v)->vec))

/* Use these to acces a vector table */
#define LIB_VECTSIZE			(sizeof (struct JumpVec))
#define __AROS_GETJUMPVEC(lib,n)        ((struct JumpVec *)(((UBYTE *)lib)-(n*LIB_VECTSIZE)))
#define __AROS_GETVECADDR(lib,n)        (__AROS_GET_VEC(__AROS_GETJUMPVEC(lib,n)))
#define __AROS_SETVECADDR(lib,n,addr)   (__AROS_SET_VEC(__AROS_GETJUMPVEC(lib,n),(APTR)(addr)))
#define __AROS_INITVEC(lib,n)           __AROS_GETJUMPVEC(lib,n)->jmp = __AROS_ASMJMP, \
					__AROS_SETVECADDR(lib,n,_aros_not_implemented)

/* ??? */
#define RDFCALL(hook,data,dptr) ((void(*)(UBYTE,APTR))(hook))(data,dptr);

/*
    Find the next valid alignment for a structure if the next x bytes must
    be skipped.
*/
#define AROS_ALIGN(x)        (((x)+AROS_WORSTALIGN-1)&-AROS_WORSTALIGN)

/* Prototypes */
extern void _aros_not_implemented (void);

/* How much stack do we need ? Lots :-) */
#define AROS_STACKSIZE	100000

/* How to map function arguments to CPU registers */
/*
    The library base is mapped to the last argument so that it can be
    ignored by the function.
*/

/* The registers */
#define D0 "d0"
#define D1 "d1"
#define D2 "d2"
#define D3 "d3"
#define D4 "d4"
#define D5 "d5"
#define D6 "d6"
#define D7 "d7"
#define A0 "a0"
#define A1 "a1"
#define A2 "a2"
#define A3 "a3"
#define A4 "a4"
#define A5 "a5"
#define A6 "a6"

/* What to do with the library base in header, prototype and call */
#define __AROS_LH_BASE(basetype,basename)   basetype basename __asm("a6")
#define __AROS_LP_BASE(basetype,basename)   void *  __asm("a6")
#define __AROS_LC_BASE(basetype,basename)   basename

/* How to transform an argument in header, prototype and call */
#define __AROS_LHA(type,name,reg)     type name __asm(reg)
#define __AROS_LPA(type,name,reg)     type __asm(reg)
#define __AROS_LCA(type,name,reg)     name
#define __AROS_UFHA(type,name,reg)    type name __asm(reg)
#define __AROS_UFPA(type,name,reg)    type __asm(reg)
#define __AROS_UFCA(type,name,reg)    name

/* Prefix for library function in header, prototype and call */
#define __AROS_LH_PREFIX    /* eps */
#define __AROS_LP_PREFIX    /* eps */
#define __AROS_LC_PREFIX    /* eps */
#define __AROS_UFH_PREFIX   /* eps */
#define __AROS_UFP_PREFIX   /* eps */
#define __AROS_UFC_PREFIX   /* eps */

/* Postfix for library function in header, prototype and call */
#define __AROS_LH_POSTFIX    /* eps */
#define __AROS_LP_POSTFIX    /* eps */
#define __AROS_LC_POSTFIX    /* eps */
#define __AROS_UFH_POSTFIX   /* eps */
#define __AROS_UFP_POSTFIX   /* eps */
#define __AROS_UFC_POSTFIX   /* eps */

/* if this is defined, all AROS_LP*-macros will expand to nothing. */
#define __AROS_USE_MACROS_FOR_LIBCALL

#endif /* AROS_MACHINE_H */
