simmagic.h 5.01 KB
/*
 * Copyright (C) 1996-1998 by the Board of Trustees
 *    of Leland Stanford Junior University.
 * 
 * This file is part of the SimOS distribution. 
 * See LICENSE file for terms of the license. 
 *
 */

/*****************************************************************
 * simmagic.h
 *
 * Interface between the OS view of the machine and the SimOS
 * device simulators.
 *
 * Created by: John Chapin, 05/95
 * Revision history:
 *   06/95  (Dan Teodosiu) added interrupt subsystem support.
 *   06/95  (John Chapin)  added register access, interrupt event codes
 *   06/95  (John Chapin)  moved flash defines out, added universal I/O ops
 *   11/95  (John Chapin)  added PPC version 2 support
 *   07/96  (Dan Teodosiu) complete OS/SimOS overhaul
 *   02/97  (Ben Werther)  generalized number of devices per machine
 *
 ****************************************************************/

#ifndef _SIM_MAGIC_H
#define _SIM_MAGIC_H

/* Interval (in simulated cycles) for polling input devs */
#define MAGIC_POLL_INTERVAL    100000

#ifdef TORNADO
/*
 * tornado runs mipsy. (bugnion)
 */
#undef MAGIC_POLL_INTERVAL
#define MAGIC_POLL_INTERVAL    10000
#endif

/* This function initializes:
 *  - all MAGIC's (PPR's, PPC's, etc.)
 *  - all BDOOR device registers
 *  - all devices and device interrupt handlers
 *  - device polling
 */
extern void sim_magic_init(int restoreFromChkpt);


/* Access types: given a virtual KSEG1 address, Mipsy wants to know
 * the kind of access performed.
 */
typedef enum {
   SIMMAGIC_DIRECT,               /* processed by sim_magic.c */
   SIMMAGIC_UNCACHED,             /* Flashlite: regular uncached access */
   SIMMAGIC_UNCACHED_ACCELERATED  /* Flashlite: uncached accelerated access */
} SimMagic_accesstype;

/* Determine kind of access based on VA.
 * NOTE: we now squeeze the T5 64bit address space into a 32bit one.
 *       See the "SimOS to FLASH Physical Address Mapping" doc.
 */
extern SimMagic_accesstype SimMagic_kseg1_accesstype(uint VA);


/* Get an OSPC line into the specified buffer.
 * This is called by Mipsy from CacheCmdDone (see the comment in that
 * routine and in simmagic.c) so that OSPC gets can be emulated. The
 * routine returns a delay which is 0 if this OSPC access should not
 * stall, or otherwise the maximum number of ticks for which the
 * access should be stalled. Note that CacheCmdUnstall may be called
 * later (when the OSPC access becomes available) to allow the access
 * to complete.
 *
 * NOTE: this routine is a nop if Flashlite is used or if the
 * requested address doesn't correspond to a valid OSPC offset.
 */
extern int sim_magic_OSPC_access(int cpuNum, /* CPU making the access */
				 uint VA,    /* accessed VA */
				 byte *data  /* data buffer for OSPC data */
				 );

/* Called by mem system to inform simmagic that an OSPC access has
 * stalled or timed out. This controls whether an interrupt is
 * generated or not when the SIPS arrives.
 */
extern void sim_magic_OSPC_stalled(int cpuNum, /* CPU number */
				   VA  va,     /* VA for OSPC access */
				   int stalled /* stalled or not? */
				   );


/* Function type for functions called by the simulator when fielding
 * a ref to the backdoor. If the function returns != 0, then the
 * requested access is illegal and should be bus-errored.
 */
typedef int (*MagicFunction)(int   cpuNum, /* CPU making this access */
			     uint  VA,     /* accessed virtual address */
			     int   type,   /* access type */
			     void* buff);  /* buff width acc to type */


/* Checkpointing support */
extern void sim_magic_cpt(int restoreFromChkpt);

/* called when checkpointing, so that timeLeft field can be updated. */
extern void TimerUpdateTimeLeft(void);
/* called when restoring from a checkpoint */
extern void InstallTimers(void);
/* called by Embra */
void InstallPoller(void);
/* called by embra to check if address is coherent */
extern int SimMagic_IsIncoherent(uint pAddr);
/* called by flash_interface to report bad cache lines */
extern void SimMagic_MakeIncoherent(uint pAddr);
/* called by flash_interface to extract info from MAGIC that must be
 * pushed into Flite when restoring from a checkpoint.
 */
extern unsigned char      SimMagic_GetIbitTableEntry(int cpunum, int entry);
extern uint64 SimMagic_GetIECPending(int cpunum);
extern uint64 SimMagic_GetIECTrans(int cpunum);
extern uint64 SimMagic_GetIECEnable(int cpunum);

/* interrupt raise/clear. This is used by some of the simulators for
 * internally generated interrupts.
 */
void RaiseIBit(int cpu, IEC code);
void ClearIBit(int cpu, IEC code);


extern Result SimMagic_DoPIO(int cpuNum, PA addr,
			  int isRead, int size, void *data);

/*
 * Structure and macros used to get the machine number from a device number
 */
typedef struct devicetomachinestruct {
   int *console;
   int *ether;
   int *clock;
} DeviceToMachineStruct;

#define M_FROM_CONSOLE(_d)           deviceToMachine.console[_d]
#define M_FROM_ETHER_CONTROLLER(_d)  deviceToMachine.ether[_d]
#define M_FROM_CLOCK(_d)             deviceToMachine.clock[_d]

extern DeviceToMachineStruct deviceToMachine;

#endif /* _SIM_MAGIC_H */