/*
** ppc.library emulation
** (c)1998-2001 Frank Wille <frank@phoenix.owl.de>
**
** Private C includes
**
** V0.9  (02.12.2001) phx
**       Added "ppc_" prefix to library base names.
** V0.8f (10.03.2001) phx
**       New flag: PPCLibF_IgnoreNoCacheM68k
** V0.8e (16.12.2000) phx
**       New flags: PPCLibF_NoFreeMemPatch, PPCLibF_NoLoadSegPatch.
** V0.8c (21.10.2000) phx
**       MEMMAGIC identifies memory blocks allocated by the WarpUp kernel.
** V0.7d (22.02.2000) phx
**       New structure member ppc_HID1 for the PLL code.
** V0.6  (10.04.1999) phx
**       MPSemaphore protects the LibBase from reserved0 on.
** V0.5d (10.04.1999) phx
**       Security buffer at end of library base.
**       PortList.
**       MPSemaphore LibMPS replaces all M68k- and PPC-specific
**       semaphores. This will hopefully allow read/write access for
**       both CPUs on all data.
**       Pad-bytes for longword alignment after List structures.
** V0.5b (12.02.1999) phx
**       Moved Ext_UserData into Task.
** V0.5a (26.01.1999) phx
**       Ext_UserData, used by PPCSet/GetAttr PPCTASKTAG_EXTUSERDATA.
** V0.5  (23.01.1999) phx
**       Internal ELFLoadSegPatch. Library memory pool.
** V0.4c (20.01.1999) phx
**       ELF-library support.
**       TaskObjects contains a list of all PowerUp task, launched by
**       the 68k or the PPC. It should be modified from 68k only.
** V0.4b (05.01.1999) phx
**       TimerObject Server task. Support for TimerObjects and signals.
** V0.4  (21.11.1998) phx
**       Infos about PowerPC will be determined on startup. New fields:
**       ppc_PVR, ppc_BusClock, ppc_CPUClock.
** V0.1  (15.11.1998) phx
**       First partially working ppc.library emulation. Synchronous PPC
**       tasks, started by runelf, which only use the basic PowerUp kernel
**       functions for I/O, memory and context-switch seem to work fine.
**       Supported 68k functions:
**        PPCLoadObject,PPCUnloadObject,PPCRunObject,PPCAllocMem,PPCFreeMem,
**        PPCAllocVec,PPCFreeVec,PPCCreateTask(only synchronous),
**        PPCGetObjectAttrs,PPCLoadObjectTagList
**       Supported PowerUp kernel functions:
**        PPCAllocMem,PPCAllocPooled(dummy),PPCAllocVec,
**        PPCAllocVecPooled(dummy),PPCCallM68k,PPCCallOS,PPCClose,
**        PPCCreatePool(dummy),PPCDeletePool(dummy),PPCFreeMem,
**        PPCFreePooled(dummy),PPCFreeVec,PPCFreeVecPooled(dummy),
**        PPCOpen,PPCRead,PPCSeek,PPCWrite
**       Pooled memory functions currently use the normal Alloc/FreeVec
**       functions, because pooled memory support is still missing in WarpOS.
** V0.0  (31.10.1998) phx
**       created
*/

#ifndef PPCLIBEMU_H
#define PPCLIBEMU_H

#include <stdarg.h>
#include <exec/types.h>
#include <exec/lists.h>
#include <exec/libraries.h>
#include <exec/execbase.h>
#include <dos/dos.h>
#include <utility/tagitem.h>
#include <utility/hooks.h>
#include <powerpc/powerpc.h>
#include <powerpc/tasksPPC.h>
#include "mpsema.h"


/* The Library base structure */
struct PPCLibBase {
  struct Library libnode;
  UWORD Flags;
  BPTR SegList;
  APTR WOSLinkerDB;  /* <-- Offset 40 must not change! TOC-pointer for r2 */
  ULONG ppc_PVR;                        /* contains cpu type and revision */
  ULONG ppc_BusClock;
  ULONG ppc_CPUClock;
  struct ExecBase *ppc_SysBase;
  struct PPCBase *ppc_PowerPCBase;      /* Offset 60! Don't move! */
  struct Library *ppc_DOSBase;
  struct Library *ppc_UtilityBase;
  struct Library *ppc_IntuitionBase;
  ULONG ppc_HID1;                       /* contains pll code in msb */
  void *LibPool;                        /* Memory Pool for library alloc. */
  UBYTE reserved0[32];
  struct List ElfObjects;               /* all loaded ELF objects */
  UBYTE reserved1[2];
  struct List TaskObjects;              /* all PowerUp tasks */
  UBYTE reserved2[34];
  struct MPSemaphore LibMPS;            /* LibBase CPU access arbitration */
  UBYTE reserved3[32];
  /* PowerPC-only data below! */
  struct TaskPPC *TimerObjSrv;          /* PPC TimerObject Server Task */
  struct List ElfLibraries;             /* all loaded ELF libraries */
  UBYTE reserved4[2];
  struct List PortList;                 /* global PPC MsgPorts */
  UBYTE reserved5[34];
};

#define PPCLibB_AllErrors 0             /* show requesters for all errors */
#define PPCLibF_AllErrors 1
#define PPCLibB_NoFreeMemPatch 1        /* don't patch FreeMem/FreeVec */
#define PPCLibF_NoFreeMemPatch (1<<1)
#define PPCLibB_NoLoadSegPatch 2        /* don't patch LoadSeg */
#define PPCLibF_NoLoadSegPatch (1<<2)
#define PPCLibB_IgnoreNoCacheM68k 3     /* Ignore NOCACHE mem attr. for 68k */
#define PPCLibF_IgnoreNoCacheM68k (1<<3)
#define PPCLibB_Debug 15                /* debugging mode (serial port) */
#define PPCLibF_Debug (1<<15)


/* magic id for PPC memory allocations */
#define MEMMAGIC (0x7070634d)


#ifdef __VBCC__
#ifdef __PPC__
#include "inlineppc.h"
#else
#include "inline68k.h"
#endif
#else
#error Sorry, no assembler inlines for your compiler.
#endif


#endif /* PPCLIBEMU_H */
