1 #ifndef EXEC_LIBRARIES_H
    2 #define EXEC_LIBRARIES_H
    3 
    4 /*
    5 	exec library definitions (V50)
    6 
    7 	Copyright © 2002 The MorphOS Development Team, All Rights Reserved.
    8 */
    9 
   10 #ifndef EXEC_NODES_H
   11 # include <exec/nodes.h>
   12 #endif
   13 
   14 #ifndef EXEC_MACHINE_H
   15 # include <exec/machine.h>
   16 #endif
   17 
   18 #ifndef UTILITY_TAGITEM_H
   19 # include <utility/tagitem.h>
   20 #endif
   21 
   22 #ifndef EMUL_EMULINTERFACE_H
   23 # include <emul/emulinterface.h>
   24 #endif
   25 
   26 #pragma pack(2)
   27 
   28 
   29 #define LIB_VECTSIZE  6
   30 #define LIB_RESERVED  4
   31 #define LIB_BASE      (-LIB_VECTSIZE)
   32 #define LIB_USERDEF   (LIB_BASE - (LIB_RESERVED * LIB_VECTSIZE))
   33 #define LIB_NONSTD    (LIB_USERDEF)
   34 
   35 #define LIB_OPEN         (-6)
   36 #define LIB_CLOSE        (-12)
   37 #define LIB_EXPUNGE      (-18)
   38 #define LIB_EXTFUNC      (-24)
   39 #define LIB_GETQUERYATTR (-24)	/* LIBF_QUERYINFO */
   40 
   41 
   42 struct Library
   43 {
   44 	struct Node lib_Node;
   45 	UBYTE       lib_Flags;
   46 	UBYTE       lib_pad;
   47 	UWORD       lib_NegSize;
   48 	UWORD       lib_PosSize;
   49 	UWORD       lib_Version;
   50 	UWORD       lib_Revision;
   51 	APTR        lib_IdString;
   52 	ULONG       lib_Sum;
   53 	UWORD       lib_OpenCnt;
   54 };
   55 
   56 #define LIBF_SUMMING   (1 << 0)
   57 #define LIBF_CHANGED   (1 << 1)
   58 #define LIBF_SUMUSED   (1 << 2)
   59 #define LIBF_DELEXP    (1 << 3)
   60 /*
   61  * private
   62  */
   63 #define LIBF_RAMLIB    (1 << 4)
   64 /*
   65  * Needs to be set if the GetQueryAttr function is legal
   66  */
   67 #define LIBF_QUERYINFO (1 << 5)
   68 /*
   69  * The remaining bits are reserved and aren't allowed to be touched
   70  */
   71 
   72 /*
   73  * Useful macro for checking minimum library version/revision
   74  */
   75 #ifdef __GNUC__
   76 #define LIB_MINVER(lib,ver,rev) ({ struct Library *__tlib__ = lib; const UWORD __tver__ = ver; __tlib__->lib_Version > __tver__ || (__tlib__->lib_Version == __tver__ && __tlib__->lib_Revision >= (rev)); })
   77 #else
   78 #define LIB_MINVER(lib,ver,rev) ((lib)->lib_Version > (ver) || ((lib)->lib_Version == (ver) && (lib)->lib_Revision >= (rev)))
   79 #endif
   80 
   81 #ifdef EXEC_OBSOLETE
   82 
   83 #define lh_Node     lib_Node
   84 #define lh_Flags    lib_Flags
   85 #define lh_pad      lib_pad
   86 #define lh_NegSize  lib_NegSize
   87 #define lh_PosSize  lib_PosSize
   88 #define lh_Version  lib_Version
   89 #define lh_Revision lib_Revision
   90 #define lh_IdString lib_IdString
   91 #define lh_Sum      lib_Sum
   92 #define lh_OpenCnt  lib_OpenCnt
   93 
   94 #endif
   95 
   96 /* NewSetFunction extensions
   97  */
   98 
   99 #define SETFUNCTAG_Dummy    (TAG_USER +0x01000000)
  100 
  101 /* Set the machine type of the function
  102  * Default is MACHINE_PPC
  103  */
  104 #define SETFUNCTAG_MACHINE  (SETFUNCTAG_Dummy + 0x1)
  105 
  106 /* Function type specifier
  107  */
  108 
  109 #define SETFUNCTAG_TYPE     (SETFUNCTAG_Dummy + 0x2)
  110 
  111 /* ID String
  112  */
  113 
  114 #define SETFUNCTAG_IDNAME   (SETFUNCTAG_Dummy + 0x3)
  115 
  116 
  117 /*
  118  * Set to TRUE if the replaced function will never be used
  119  * again.
  120  */
  121 #define SETFUNCTAG_DELETE   (SETFUNCTAG_Dummy + 0x4)
  122 
  123 /* See emul/emulinterface.h for more information
  124  */
  125 
  126 /* Save Emulation PPC Registers
  127  * Call Function
  128  * Restore Emulation PPC Registers
  129  * REG_D0 = Result
  130  */
  131 #define SETFUNCTYPE_NORMAL          0
  132 
  133 /* Call Function
  134  * Must use the global register settings of the emulation
  135  * REG_D0 = Result
  136  */
  137 #define SETFUNCTYPE_QUICK           1
  138 
  139 /* Save Emulation PPC Registers
  140  * Call Function
  141  * Restore Emulation PPC Registers
  142  * No Result
  143  * Needed to replace functions like
  144  * forbid,obtainsemaphores which are
  145  * defined as preserving registers
  146  */
  147 #define SETFUNCTYPE_NORMALNR        2
  148 
  149 /* Call Function
  150  * Must use the global register settings of the emulation
  151  * No Result
  152  * Needed to replace functions like
  153  * forbid,obtainsemaphores which are
  154  * defined as preserving registers
  155  */
  156 #define SETFUNCTYPE_QUICKNR         3
  157 
  158 #define SETFUNCTYPE_NORMALSR        4
  159 
  160 #define SETFUNCTYPE_NORMALSRNR      5
  161 
  162 #define SETFUNCTYPE_NORMALD0_D1     6
  163 
  164 #define SETFUNCTYPE_NORMALRESTORE   7
  165 
  166 #define SETFUNCTYPE_SYSTEMV         8
  167 
  168 #define SETFUNCTYPE_NORMALD0D1SR    9
  169 
  170 #define SETFUNCTYPE_NORMALD0D1A0A1SR 10
  171 
  172 
  173 
  174 /* CreateLibrary extensions
  175  */
  176 
  177 #define LIBTAG_BASE         (TAG_USER + 0x01000100)
  178 
  179 /*
  180  * Function/Vector Array
  181  */
  182 #define LIBTAG_FUNCTIONINIT (LIBTAG_BASE+0x0)
  183 /*
  184  * Struct Init
  185  */
  186 #define LIBTAG_STRUCTINIT   (LIBTAG_BASE+0x1)
  187 /*
  188  * Library Init
  189  */
  190 #define LIBTAG_LIBRARYINIT  (LIBTAG_BASE+0x2)
  191 /*
  192  * Init Code Type
  193  */
  194 #define LIBTAG_MACHINE      (LIBTAG_BASE+0x3)
  195 /*
  196  * Library Base Size
  197  */
  198 #define LIBTAG_BASESIZE     (LIBTAG_BASE+0x4)
  199 /*
  200  * SegList Ptr
  201  */
  202 #define LIBTAG_SEGLIST      (LIBTAG_BASE+0x5)
  203 /*
  204  * Library Priority
  205  */
  206 #define LIBTAG_PRI          (LIBTAG_BASE+0x6)
  207 /*
  208  * Library Type..Library,Device,Resource,whatever
  209  */
  210 #define LIBTAG_TYPE         (LIBTAG_BASE+0x7)
  211 /*
  212  * Library Version
  213  * (UWORD)
  214  */
  215 #define LIBTAG_VERSION      (LIBTAG_BASE+0x8)
  216 /*
  217  * Library Flags
  218  */
  219 #define LIBTAG_FLAGS        (LIBTAG_BASE+0x9)
  220 /*
  221  * Library Name
  222  */
  223 #define LIBTAG_NAME         (LIBTAG_BASE+0xa)
  224 /*
  225  * Library IDString
  226  */
  227 #define LIBTAG_IDSTRING     (LIBTAG_BASE+0xb)
  228 /*
  229  * AddDevice(),AddLibrary(),AddResource()..
  230  * depends on LibNode.ln_Type field which
  231  * can be set by some Init function, Struct Scripts
  232  * or LIBTAG_TYPE.
  233  * If you set LIBTAG_PUBLIC the library
  234  * is added to the right system list.
  235  */
  236 #define LIBTAG_PUBLIC       (LIBTAG_BASE+0xc)
  237 /*
  238  * Library Revision
  239  * (UWORD)
  240  */
  241 #define LIBTAG_REVISION     (LIBTAG_BASE+0xd)
  242 /*
  243  * Library QueryInfo Flag
  244  * (Boolean)
  245  */
  246 #define LIBTAG_QUERYINFO    (LIBTAG_BASE+0xe)
  247 
  248 
  249 
  250 /* Private
  251  * don't touch...floating design
  252  */
  253 struct  FuncEntry
  254 {
  255 	struct EmulLibEntry  EmulLibEntry;
  256 	void                *OldFunction;	/* Needed for bookkeeping */
  257 };
  258 
  259 struct  FuncOldEntry
  260 {
  261 	UWORD                Command;
  262 	struct FuncEntry    *FuncEntry;
  263 };
  264 
  265 
  266 /*
  267  * EmulLibEntry.Extension
  268  */
  269 #define FUNCENTRYEXTF_LIBRARY           0x1	/* Entry created by the OS */
  270 #define FUNCENTRYEXTF_SETFUNCTION       0x2	/* Entry created by SetFunction, otherwise MakeFunction */
  271 
  272 /*
  273  * Functionarray first ULONG ID defines the format
  274  * of the functionarray for MakeFunctions()/MakeLibrary().
  275  *
  276  * If there's no such id, the functionarray is a
  277  * 32Bit 68k function ptr array.
  278  * (ULONG) 0xffffffff stops it
  279  */
  280 
  281 /* 68k 16bit relative functionarray ptrs
  282  * (UWORD) 0xffff stops it
  283  */
  284 
  285 #define FUNCARRAY_16BIT_OLD             0xffffffff
  286 
  287 /* PPC 32bit functionarray ptrs 
  288  * (ULONG) 0xffff stops it
  289  */
  290 #define FUNCARRAY_32BIT_NATIVE          0xfffefffe
  291 
  292 /* Starts a functionarray block.
  293  * This way it's possible to mix 68k and PPC
  294  * function definitions.
  295  * BASE:
  296  *  FUNCTIONARRAY_BEGIN
  297  *   FUNCARRAY_32BIT_NATIVE
  298  *    FUNC0
  299  *    FUNC1
  300  *    .
  301  *    FUNCn
  302  *    0xffffffff
  303  *   FUNCn+1  (No ID->32Bit 68k)
  304  *    FUNCn+2
  305  *    .
  306  *    FUNCm
  307  *    0xffffffff
  308  *   FUNCARRAY_16BIT_OLD
  309  *    FUNCm+1-BASE
  310  *    FUNCm+2-BASE
  311  *    .
  312  *    FUNCo-BASE
  313  *    0xffff
  314  *  FUNCTIONARRAY_END
  315  */
  316 
  317 #define FUNCARRAY_BEGIN                 0xfffdfffd
  318 
  319 /* Ends a functionarray block.
  320  */
  321 #define FUNCARRAY_END                   0xfffcfffc
  322 
  323 /* PPC 32bit Quick functionarray ptrs.
  324  * These functions must comply to the emulation's
  325  * register layout which is defined inside the
  326  * emul/emulregs.h. That means the register layout
  327  * MUST also be valid during interrupts/task switches.
  328  * You can't just destroy A7(r31), SR or PC.
  329  *
  330  * You shouldn't use this for any normal code
  331  * as there's no real reason to do so. If you
  332  * really think you need to use it please ask
  333  * us first on the dev mailinglist.
  334  * (ULONG) 0xffffffff stops it
  335  */
  336 #define FUNCARRAY_32BIT_QUICK_NATIVE    0xfffbfffb
  337 
  338 /* PPC 32bit QuickNR(No Result) functionarray ptrs
  339  * (ULONG) 0xffffffff stops it
  340  */
  341 #define FUNCARRAY_32BIT_QUICKNR_NATIVE  0xfffafffa
  342 
  343 /* PPC 32bit no result functionarray ptrs
  344  * (ULONG) 0xffffffff stops it
  345  */
  346 #define FUNCARRAY_32BIT_NR_NATIVE       0xfff9fff9
  347 
  348 /* PPC 32bit SR functionarray ptrs
  349  * (ULONG) 0xffffffff stops it
  350  */
  351 #define FUNCARRAY_32BIT_SR_NATIVE       0xfff8fff8
  352 
  353 /* PPC 32bit SR(no result) functionarray ptrs
  354  * (ULONG) 0xffffffff stops it
  355  */
  356 #define FUNCARRAY_32BIT_SRNR_NATIVE     0xfff7fff7
  357 
  358 /* PPC 32bit D0_D1 functionarray ptrs
  359  * (ULONG) 0xffffffff stops it
  360  */
  361 #define FUNCARRAY_32BIT_D0D1_NATIVE     0xfff6fff6
  362 
  363 /* PPC 32bit Restore1 functionarray ptrs
  364  * (ULONG) 0xffffffff stops it
  365  */
  366 #define FUNCARRAY_32BIT_RESTORE_NATIVE  0xfff5fff5
  367 
  368 /* PPC 32bit SystemV ABI entry
  369  * these function entries DON'T comply
  370  * to the amiga register modell REG_D0-A6
  371  * but comply to the PPC SystemV ABI so
  372  * you can directly use PPC C Argument
  373  * parsing. That way you're also not limited
  374  * with the register count.
  375  * Such library functions can't be used
  376  * by 68k emulation, so you can only use
  377  * them for new code.
  378  * As we allow these new functions to be
  379  * used with old functions we keep the
  380  * 6 bytes function entry steps in the library.
  381  * Layout is
  382  *
  383  * CODE_JMP, &FuncEntry ; Old Entry
  384  * CODE_ILLEGAL, Function ; SystemV ABI Entry
  385  * 
  386  *
  387  * (ULONG) 0xffffffff stops it
  388  */
  389 #define FUNCARRAY_32BIT_SYSTEMV         0xfff4fff4
  390 
  391 /* PPC 32bit D0D1SR functionarray ptrs
  392  * (ULONG) 0xffffffff stops it
  393  */
  394 #define FUNCARRAY_32BIT_D0D1SR_NATIVE     0xfff3fff3
  395 
  396 /* PPC 32bit D0D1A0A1SR functionarray ptrs
  397  * (ULONG) 0xffffffff stops it
  398  */
  399 #define FUNCARRAY_32BIT_D0D1A0A1SR_NATIVE     0xfff2fff2
  400 
  401 
  402 #pragma pack()
  403 
  404 #endif