1 #ifndef EMUL_EMULINTERFACE_H
    2 #define EMUL_EMULINTERFACE_H
    3 
    4 #ifndef EXEC_TYPES_H
    5 #include <exec/types.h>
    6 #endif /* EXEC_TYPES_H */
    7 
    8 struct ExecBase;
    9 
   10 #define TRAP_MASK               0x00ff
   11 #define TRAP_AREA_START         0xff00 /* 0xff00 .. 0xffff area */
   12 
   13 /***********************************************************************************
   14  *      Trap: EmulLibEntry.Trap == TRAP_LIB
   15  *    Result: D0
   16  *  Function: Call a PPC Function with std SystemV4 register layout.
   17  *            The 68k frame is saved in the EmulHandle which
   18  *            is passed in gpr2 and MUST not be changed.
   19  *            The Result is passed in gpr3 and then moved to REG_D0.
   20  * Emulation: PC      = *REG_A7
   21  *            REG_A7 += 4;
   22  *      Note: Should be used with complex PPC functions
   23  */
   24 
   25 #define TRAP_LIB                0xff00
   26 
   27 /***********************************************************************************
   28  *      Trap: EmulLibEntry.Trap == TRAP_LIB_QUICK
   29  *    Result: D0
   30  *  Function: Call a PPC Function with 68k emulation register layout.
   31  *            See emulregs.h.
   32  *            You must not kill the REG_SR register.
   33  *            Only A7 and SR is saved to the EmulHandle because
   34  *            they may be needed for Emulation Calls out of the PPC.
   35  *            EmulHandle is passed in gpr2 and MUST not be changed
   36  *            The Result is passed in gpr3 and then moved to REG_D0.
   37  * Emulation: PC      = *REG_A7
   38  *            REG_A7 += 4;
   39  *      Note: Should be used with simple/quick PPC function which don't
   40  *            require many registers.
   41  */
   42 #define TRAP_LIB_QUICK          0xff01
   43 
   44 
   45 /***********************************************************************************
   46  *      Trap: EmulLibEntry.Trap == TRAP_LIBNR
   47  *    Result: None
   48  *  Function: Call a PPC Function with std SystemV4 register layout.
   49  *            The 68k frame is saved in the EmulHandle which
   50  *            is passed in gpr2 and MUST not be changed
   51  *            The PPC function doesn't return any result.
   52  * Emulation: PC      = *REG_A7
   53  *            REG_A7 += 4;
   54  *      Note: Should be used with complex PPC functions
   55  */
   56 #define TRAP_LIBNR              0xff05
   57 
   58 /***********************************************************************************
   59  *      Trap: EmulLibEntry.Trap == TRAP_LIBNR_QUICK
   60  *    Result: None
   61  *  Function: Call a PPC Function with 68k emulation register layout.
   62  *            See emulregs.h.
   63  *            You must not change the emul regs.
   64  *            Only A7 and SR is saved to the EmulHandle because
   65  *            they may be needed for Emulation Calls out of the PPC.
   66  *            EmulHandle is passed in gpr2 and MUST not be changed
   67  *            The PPC function doesn't return any result.
   68  * Emulation: PC      = *REG_A7
   69  *            REG_A7 += 4;
   70  *      Note: Should be used with simple/quick PPC function which don't
   71  *            require many registers.
   72  */
   73 #define TRAP_LIBNR_QUICK        0xff06
   74 
   75 
   76 
   77 
   78 
   79 /***********************************************************************************
   80  *      Trap: TRAP_ISYNC
   81  *  Function: Synchronize the instruction stream of the CPU.
   82  *            PPC's "isync".
   83  * Emulation: PC+=2
   84  */
   85 #define TRAP_ISYNC              0xff0f
   86 
   87 /***********************************************************************************
   88  *      Trap: TRAP_SYNC
   89  *  Function: Synchronize the instruction stream of the CPU.
   90  *            PPC's "sync".
   91  * Emulation: PC+=2
   92  */
   93 #define TRAP_SYNC               0xff10
   94 
   95 
   96 /***********************************************************************************
   97  *      Trap: TRAP_EIEIO
   98  *  Function: Orders the instruction stream of the CPU.
   99  *            PPC's "eieio".
  100  * Emulation: PC+=2
  101  */
  102 #define TRAP_EIEIO              0xff11
  103 
  104 /***********************************************************************************
  105  *      Trap: EmulLibEntry.Trap == TRAP_LIBSR
  106  *    Result: D0 , REG_SR <- MyEmulHandle->SR
  107  *  Function: Call a PPC Function with std SystemV4 register layout.
  108  *            The 68k frame is saved in the EmulHandle which
  109  *            is passed in gpr2 and MUST not be changed
  110  *            The Result is passed in gpr3 and then moved to REG_D0.
  111  *            REG_SR is updated with MyEmulHandle->SR so you're able
  112  *            to change it which may be useful for wrongly used
  113  *            exec memory functions where the result SR may be
  114  *            important.
  115  * Emulation: PC      = *REG_A7
  116  *            REG_A7 += 4;
  117  *      Note: Should be used with complex PPC functions
  118  */
  119 
  120 #define TRAP_LIBSR              0xff12
  121 
  122 /***********************************************************************************
  123  *      Trap: EmulLibEntry.Trap == TRAP_LIBSRNR
  124  *    Result: REG_SR <- MyEmulHandle->SR
  125  *  Function: Call a PPC Function with std SystemV4 register layout.
  126  *            The 68k frame is saved in the EmulHandle which
  127  *            is passed in gpr2 and MUST not be changed
  128  *            The PPC function doesn't return any result.
  129  *            REG_SR is updated with MyEmulHandle->SR so you're able
  130  *            to change it which may be useful for wrongly used
  131  *            exec memory functions where the result SR may be
  132  *            important.
  133  * Emulation: PC      = *REG_A7
  134  *            REG_A7 += 4;
  135  *      Note: Should be used with complex PPC functions
  136  */
  137 #define TRAP_LIBSRNR            0xff13
  138 
  139 
  140 /***********************************************************************************
  141  *      Trap: EmulLibEntry.Trap == TRAP_LIBD0_D1
  142  *    Result: D0 , REG_D1 <- MyEmulHandle->Dn[1]
  143  *  Function: Call a PPC Function with std SystemV4 register layout.
  144  *            The 68k frame is saved in the EmulHandle which
  145  *            is passed in gpr2 and MUST not be changed
  146  *            The Result is passed in gpr3 and then moved to REG_D0.
  147  *            REG_D1 is updated with MyEmulHandle->Dn[1] so you're able
  148  *            to change it which is needed for braindead LoadSeg
  149  *            and software using *Overlays*
  150  * Emulation: PC      = *REG_A7
  151  *            REG_A7 += 4;
  152  *      Note: Should be used with complex PPC functions
  153  */
  154 
  155 #define TRAP_LIBD0_D1           0xff14
  156 
  157 /***********************************************************************************
  158  *      Trap: EmulLibEntry.Trap == TRAP_LIBRESTORE
  159  *    Result: None
  160  *  Function: Call a PPC Function with std SystemV4 register layout.
  161  *            The 68k frame is saved in the EmulHandle which
  162  *            is passed in gpr2 and MUST not be changed
  163  *            The function copies the emulation context registers
  164  *            with the functions inside the EmulHandle.
  165  * Emulation: PC      = *REG_A7
  166  *            REG_A7 += 4;
  167  *      Note: Should only be used in special code. Setjmp/GetA4 inside PPC code.
  168  */
  169 
  170 #define TRAP_LIBRESTORE         0xff15
  171 
  172 /***********************************************************************************
  173  *      Trap: EmulLibEntry.Trap == TRAP_LIBD0_D1_SR
  174  *    Result: D0 , REG_D1 <- MyEmulHandle->Dn[1], REG_SR <- MyEmulHandle->SR
  175  *  Function: Call a PPC Function with std SystemV4 register layout.
  176  *            The 68k frame is saved in the EmulHandle which
  177  *            is passed in gpr2 and MUST not be changed
  178  *            The Result is passed in gpr3 and then moved to REG_D0.
  179  *            REG_D1 is updated with MyEmulHandle->Dn[1] so you're able
  180  *            to change it which is needed for braindead LoadSeg
  181  *            and software using *Overlays*
  182  *            SR is updated.
  183  * Emulation: PC      = *REG_A7
  184  *            REG_A7 += 4;
  185  *      Note: Should be used with complex PPC functions
  186  */
  187 
  188 #define TRAP_LIBD0D1SR          0xff17
  189 
  190 /***********************************************************************************
  191  *      Trap: EmulLibEntry.Trap == TRAP_LIBD0D1A0A1SR
  192  *    Result: D0 , REG_D1 <- MyEmulHandle->Dn[1], REG_A0 <- MyEmulHandle->An[0],
  193  *                 REG_A1 <- MyEmulHandle->An[1], REG_SR <- MyEmulHandle->SR
  194  *  Function: Call a PPC Function with std SystemV4 register layout.
  195  *            The 68k frame is saved in the EmulHandle which
  196  *            is passed in gpr2 and MUST not be changed
  197  *            The Result is passed in gpr3 and then moved to REG_D0.
  198  *            REG_D1, REG_A0, REG_A1 and REG_SR are updated too. 
  199  * Emulation: PC      = *REG_A7
  200  *            REG_A7 += 4;
  201  *      Note: Should be used with complex PPC functions
  202  */
  203 
  204 #define TRAP_LIBD0D1A0A1SR      0xff18
  205 
  206 
  207 
  208 
  209 
  210 #define EMULTAG_NAME            0x0 /* Gives back a Name Ptr */
  211 #define EMULTAG_VERSION         0x1 /* Gives back a Version */
  212 #define EMULTAG_REVISION        0x2 /* Gives back a Revision */
  213 #define EMULTAG_OPCODETABLE     0x3 /* Gives back the 16 Bit Opcodetable Ptr or NULL */
  214 #define EMULTAG_TYPE            0x4 /* Gives back the emulation type */
  215 #define EMULTAG_EMULHANDLE      0x5 /* Gives back the EmulHandle Ptr */
  216 #define EMULTAG_EMULHANDLESIZE  0x6 /* Gives back the EmulHandle Size */
  217 #define EMULTAG_SUPERHANDLE     0x7 /* Gives back the SuperHandle Ptr */
  218 #define EMULTAG_SUPERHANDLESIZE 0x8 /* Gives back the SuperHandle Size */
  219 
  220 
  221 struct EmulCaos
  222 {
  223 	union
  224 	{
  225 		int  Offset;
  226 		APTR Function;
  227 	} caos_Un;
  228 	ULONG reg_d0;
  229 	ULONG reg_d1;
  230 	ULONG reg_d2;
  231 	ULONG reg_d3;
  232 	ULONG reg_d4;
  233 	ULONG reg_d5;
  234 	ULONG reg_d6;
  235 	ULONG reg_d7;
  236 	ULONG reg_a0;
  237 	ULONG reg_a1;
  238 	ULONG reg_a2;
  239 	ULONG reg_a3;
  240 	ULONG reg_a4;
  241 	ULONG reg_a5;
  242 /*
  243  * here you have to put the LibBasePtr if you want
  244  * to call a Library.
  245  */
  246 	ULONG reg_a6;
  247 };
  248 
  249 struct EmulLibEntry
  250 {
  251 	UWORD Trap;
  252 	UWORD Extension; /* MUST be set to 0 if you create it by hand */
  253 	void  (*Func)(void);
  254 };
  255 
  256 struct EmulFunc
  257 {
  258 	UWORD Trap; /* TRAP_FUNC */
  259 	UWORD Extension;
  260 	ULONG Address;
  261 	/* Size 0 for no new Stack
  262 	 */
  263 	ULONG StackSize;
  264 	ULONG Arg1;
  265 	ULONG Arg2;
  266 	ULONG Arg3;
  267 	ULONG Arg4;
  268 	ULONG Arg5;
  269 	ULONG Arg6;
  270 	ULONG Arg7;
  271 	ULONG Arg8;
  272 };
  273 
  274 
  275 
  276 #define GETEMULHANDLE   register struct EmulHandle *MyEmulHandle __asm("r2");
  277 
  278 #ifndef ROMEMUL
  279 
  280 struct SuperHandle
  281 {
  282 	ULONG USP;  /* Userstack */
  283 	ULONG SSP;  /* Supervisor Stack */
  284 	ULONG VBR;  /* Exception Base Register */
  285 	ULONG SFC;  /* SFC Register ...not really used */
  286 	ULONG DFC;  /* DFC Register ...not really used */
  287 	ULONG CACR; /* Cache Control Register ...not really used */
  288 	ULONG TC;
  289 	ULONG ITT0;
  290 	ULONG ITT1;
  291 	ULONG DTT0;
  292 	ULONG DTT1;
  293 	ULONG URP;
  294 	ULONG SRP;
  295 	ULONG BUSCR;
  296 	ULONG PCR;
  297 	ULONG Type; /* SuperHandle Type..not used yet */
  298 
  299 /********************************************************************************************
  300  * Private
  301  * Don't touch
  302  */
  303 	ULONG Private00;
  304 	APTR  Private01;
  305 	APTR  Private02;
  306 	APTR  Private03;
  307 	APTR  Private04;
  308 	ULONG Private05;
  309 	APTR  Private06;
  310 	ULONG Private07;
  311 	APTR  Private08;
  312 	int   Private09;
  313 	int   Private0A;
  314 	int   Private0B;
  315 	ULONG Private0C;
  316 
  317 	ULONG PrivateXX[1024-29];
  318 
  319 /********************************************************************************************
  320  * Public
  321  * Read only
  322  */
  323 	struct ExecBase *GlobalSysBase; /* Global SysBase pointer */
  324 	ULONG ROPrivateXX[1024-1];
  325 };
  326 
  327 struct Float96
  328 {
  329 	ULONG Data[3];
  330 };
  331 
  332 struct EmulHandle
  333 {
  334 	ULONG              Dn[8];                                 /* 0x00 */
  335 	ULONG              An[8];                                 /* 0x20 */
  336 	ULONG              *PC;                                   /* 0x40 Current PC */
  337 	ULONG              SR;                                    /* 0x44 Statusregister */
  338 	struct SuperHandle *SuperHandle;                          /* 0x48 Ptr to SuperHandle */
  339 	ULONG              Type;                                  /* 0x4c EmulHandle Type */
  340 	ULONG              Flags;                                 /* 0x50 Flags */
  341 
  342 	void               (*EmulFunc)(void);                     /* 0x54 Here is the direct Emulation Jump..you have to setup the regframes*/
  343 	ULONG              (*EmulCallOS)(struct EmulCaos*);       /* 0x58 Here is the Emulation Jump for a 68k OSLib Function*/
  344 	ULONG              (*EmulCall68k)(struct EmulCaos*);      /* 0x5c Here is the Emulation Jump for a 68k Function*/
  345 	ULONG              (*EmulCallQuick68k)(struct EmulCaos*); /* 0x60 Here is the Emulation Quick Jump for a 68k Function..r13..r31 are not saved!*/
  346 	ULONG              (*EmulCallDirectOS)(LONG);             /* 0x64 Here is the Emulation Direct Jump for a 68k OSLib Function*/
  347 	ULONG              (*EmulCallDirect68k)(APTR);            /* 0x68 Here is the Emulation Direct Jump for a 68k Function*/
  348 	struct EmulHandle  *OldEmulHandle;                        /* 0x6c Here we record the previous EmulHandle*/
  349 	struct Float96     FPU[8];                                /* 0x70 Not yet used...*/
  350 	ULONG              FPCR;                                  /* 0xd0 Not yet used...*/
  351 	ULONG              FPSR;                                  /* 0xd4 Not yet used...*/
  352 	ULONG              FPIAR;                                 /* 0xd8 Not yet used...*/
  353 	struct HashEntry   *HashEntry;                            /* 0xdc */
  354 /********************************************************************************************
  355  * Private
  356  * Don't touch
  357  * 0xe0
  358  */
  359 
  360 };
  361 
  362 #define EMULFLAGSF_PPC       0x1 /* Set when the emulation runs in full native code */
  363 #define EMULFLAGSF_QUICK     0x2 /* Set when the emulation runs quick native code..
  364                                   * which is basicly still the emul reg layout
  365                                   */
  366 #define EMULFLAGSF_INTERRUPT 0x4 /* Set when the emulation runs in interrupt mode
  367                                   */
  368 
  369 #endif
  370 
  371 
  372 #endif