/* 
 * $RCSfile: platform.h,v $
 *
 * x-kernel v3.3
 *
 * Original Copyright (c) 1993,1991,1990,1996  Arizona Board of Regents
 * Modifications Copyright (c) 1993 Massachusetts Board of Regents
 *
 * $Log: platform.h,v $
 * Revision 1.2  1996/01/30 20:51:19  slm
 * Updated copyright and version.
 *
 * Revision 1.1  1995/07/29  02:40:49  slm
 * Initial revision
 *
 * Revision 1.6.1.2.1.2  1994/11/22  22:05:22  hkaram
 * Added xRealloc and FORCE_LASTCALL and some include files
 *
 * Revision 1.6.1.2.1.1  1994/11/12  19:10:45  hkaram
 * New branch
 *
 * Revision 1.6.1.2  1994/06/03  18:04:08  menze
 * Doesn't inlude all.h
 *
 * Revision 1.6.1.1  1994/03/14  21:44:17  umass
 * Contents of all.h moved here
 *
 * Revision 1.6  1994/02/05  00:34:46  menze
 *   [ 1994/02/03          menze ]
 *   Includes all.h
 *
 *   [ 1994/01/28          menze ]
 *   architecture-specific sizes moved to xk_arch.h
 *   ROM declarations moved to rom.h
 *
 * Revision 1.5  1994/01/03  22:11:29  menze
 * sginap takes a long, not an int
 *
 * Revision 1.4  1993/12/16  02:08:00  menze
 * Added prototypes for Pfi, Pfk, Pfv (these are being phased out)
 * Added ENDIAN definition
 * added ROUND4 definition
 * Moved Byte, HalfWord, Word definitions here from all.h
 *
 * Revision 1.3  1993/11/13  00:45:38  menze
 * Original version from UMass
 */

/*
 * "irix" (SGI simulator) version of platform.h
 */

#ifndef platform_h
#define platform_h

#include "xk_debug.h"
#include "xk_arch.h"

#if defined(__GNUC__) && ! defined(XK_DEBUG)
#  define XK_USE_INLINE
#endif
#include <sys/types.h>
#include <netinet/in.h>
#include <malloc.h>
#include <alloca.h>
#include <limits.h>

#include "xtype.h"

/*
#ifdef __STDC__

typedef int (* Pfi)();
typedef void (* Pfv)();

#endif
*/

#include "process.h"
#include "msg_p.h"

/*
 * Definition of standard, global C language features and
 * standard non-x-kernel data types.
 */

# define forever   for ( ; ; )

# define PROCEDURE void
# define PUBLIC
# ifdef  PRIVATE
# undef  PRIVATE
# endif
# define PRIVATE   static

#   define EXPORT
/*
 * If linking with C++ code, define IMPORT so that the C++ compiler
 * recognizes that it is linking with C routines.
 */
#   ifdef __cplusplus
#       define IMPORT extern "C"
#   else
#       define IMPORT extern
#   endif

/*
 * Determines whether header files declare functions with or without
 * prototypes.
 */
# ifdef __STDC__
#   define _ANSI_ARGS_(x)     x
# else
#   define _ANSI_ARGS_(x)     ()
# endif

/*
 * In function declarations, if a function takes no parameters we
 * can specify the parameter list as noargs.
 */
# ifdef __STDC__
#   define noargs        void
# else
#   define noargs
# endif

/* 
 * In function declarations, read only parameters are prefixed by IN, 
 * parameters which are read and modified are prefixed by INOUT, 
 * and write only parameters are prefixed by OUT.  Parameters should
 * appear in the order IN, INOUT, OUT.
 */
# define IN 
# define INOUT
# define OUT

/* generic pointer and value for an invalid generic pointer */
# ifdef __STDC__
    typedef void    *PTR;
# else
    typedef char    *PTR;  
# endif

/*
 * Type definitions.
 */

typedef enum { NO = 0, YES }           YesNoType;
typedef enum { OK = 0, ERROR }         ErrorType; 
typedef enum { CLEAR = 0, SET }        SetClearType; 
/*
 * for use when length matters (e.g., protocol header fields).
 */
typedef unsigned char  Byte;
typedef unsigned short HalfWord;
typedef unsigned int   Word;


char *strcpy();
void free();

#ifdef __STDC__

u_short ocsum( u_short *buf, int count );
u_short inCkSum( Msg *m, u_short *buf, int len );
void    Kabort(char *);

void	CreateKernelProcess();

extern	char *	xMalloc( unsigned );
extern  char *  xRealloc ( char *, unsigned );

/* SGI syscall prototypes not mentioned in above includes */
int	sginap( long );

#else

extern	char *	xMalloc( );
extern  char *  xRealloc ( );

#endif

#define xFree(buf)  (free(buf))

typedef long *Unspec;
typedef unsigned long ProcessId;
typedef unsigned long ContextId;

#ifndef NULL
#define NULL	((PTR)0)
#endif
#define MAXUNSIGNED	((unsigned) (-1)

#define splx(x)
#define spl7() 1
#define splnet spl7
#define splclk spl7

#define INIT_STACK_SIZE 1024

#define BYTES_PER_WORD	4

#ifndef ENDIAN
/*
 * Definitions for byte order,
 * according to byte significance from low address to high.
 */
#define	LITTLE	1234		/* least-significant byte first (vax) */
#define	BIG	4321		/* most-significant byte first */
#define	PDP	3412		/* LSB first in word, MSW first in long (pdp) */

#define	ENDIAN	BIG		/* byte order on mc68000, tahoe, most others */
#endif

#define CLICKS_PER_SEC  100	/* Clock interrupts per second */

#if !defined(ROUND4)
#define ROUND4(len)  ((len + 3) & ~3)
#endif
#define ROUNDUP(A, B)   ((((Bit32) (A)) + ((B) - 1)) & (~((B)-1)))
#define ROUNDDOWN(A, B)  (((Bit32) (A)) & (~((B)-1)))
#define BETWEEN(A,B,C) ((A) <= (B) && (B) < (C))

typedef	char	*mapKeyPtr_t;
typedef	int	mapVal_t;

typedef char	*statePtr_t;

#ifndef	TRUE
#define	TRUE	1
#define FALSE	0
#endif

#ifdef __PREDICTIONS__
# define PREDICT_FALSE	@0
# define PREDICT_TRUE	@1
#else
# define PREDICT_FALSE
# define PREDICT_TRUE
#endif

#ifdef __LASTCALL__
# define FORCE_LASTCALL	!
#else
# define FORCE_LASTCALL
#endif

/*
 * SGI machine (processor board) names.
 */
#define INDIGO4000_MACHINE_NAME       "IP20"
#define INDIGO_MACHINE_NAME           "IP12"
#define POWER_SERIES400_MACHINE_NAME  "IP7"  /* 4D/4xx */
#define POWER_SERIES300_MACHINE_NAME  "IP6"  /* 4D/3xx */
#define POWER_SERIES200_MACHINE_NAME  "IP5"  /* 4D/2xx */
#define CHALLENGE_MACHINE_NAME        "IP19"

/*
 * SGI MAC layer definitions.
 */
#define IRIX_FDDI_HOSTNAME_PREFIX  "fddi-"

#define	SUCCESS_RET_VAL		0
#define	FAILURE_RET_VAL		(-1)

#define	LO_BYTE_OF_2(word)	 ((u_char) (0xff & (unsigned) word))
#define HI_BYTE_OF_2(word)	 ((u_char) (((unsigned) word) >> 8 ))
#define CAT_BYTES(hiByte,loByte) ((((unsigned)hiByte)<<8) + (unsigned)loByte)


/* 
 * LONG_ALIGNMENT_REQUIRED indicates that int's must be 32-bit aligned
 * on this architecture.
 */
#define LONG_ALIGNMENT_REQUIRED
#define LONG_ALIGNED( address )  (! ((int)(address) & 0x3))
#define SHORT_ALIGNED( address ) ( ! ((int)(address) & 0x1))


#endif
