/*
 *	kiface.h - run-time kernel interface
 *	Copyright (C) 2000 Fred Barnes <frmb2@ukc.ac.uk>
 *
 *	This program is free software; you can redistribute it and/or modify
 *	it under the terms of the GNU General Public License as published by
 *	the Free Software Foundation; either version 2 of the License, or
 *	(at your option) any later version.
 *
 *	This program is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *	GNU General Public License for more details.
 *
 *	You should have received a copy of the GNU General Public License
 *	along with this program; if not, write to the Free Software
 *	Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#ifndef __KIFACE_H
#define __KIFACE_H

#define K_IN 1
#define K_OUT 2
#define K_OUTWORD 3
#define K_OUTBYTE 4
#define K_RUNP 5
#define K_STARTP 6
#define K_ENDP 7
#define K_STOPP 8
#define K_PAUSE 9
#define K_LDTIMER 10
#define K_TIN 11
#define K_ALTWT 12
#define K_TALTWT 13
#define K_ENBC 14
#define K_ENBT 15
#define K_DISS 16
#define K_DISC 17
#define K_DIST 18
#define K_RANGERR 19
#define K_SETERR 20
#define K_NORM 21
#define K_UNPACKSN 22
#define K_POSTNORMSN 23
#define K_ROUNDSN 24
#define K_SAVEL 25
#define K_STLB 26
#define K_STLF 27
#define K_OVERFLOW 28
#define K_TRAP 29
#define K_BRANGERR 30
#define K_BSETERR 31
#define K_B_DISPATCH 32
#define K_BX_DISPATCH 33
#define K_RES_RELEASE 34
#define K_RES_CLAIM 35
#define K_ZERODIV 36
#define K_IN8 37
#define K_IN32 38
#define K_OUT8 39
#define K_OUT32 40
#define K_KERNEL_RUN 41
#define K_DYNPROC_EXIT 42
#define K_MNEW 43
#define K_MFREE 44
#define K_MALLOC 45
#define K_MRELEASE 46
#define K_DYNPROC_SUSPEND 47
#define K_FMUL 48
#define K_MIN 49
#define K_MOUT 50
#define K_MIN64 51
#define K_MOUT64 52
#define K_XABLE 53
#define K_XIN 54
#define K_XMIN 55
#define K_XMIN64 56
#define K_XEND 57
#define K_NDISC 58
#define K_NDIST 59
#define K_NDISS 60
#define K_EXTIN 61
#define K_EXTOUT 62
#define K_EXTVRFY 63
#define K_EXTIN8 64
#define K_EXTIN32 65
#define K_EXTOUT8 66
#define K_EXTOUT32 67
#define K_EXTOUTBYTE 68
#define K_EXTOUTWORD 69
#define K_EXTENBC 70
#define K_EXTNDISC 71
#ifdef PROCESS_PRIORITY
#define K_GETPRI 72
#define K_SETPRI 73
#endif
#define K_EXTMIN 74
#define K_EXTMIN64 75
#define K_EXTMOUT 76
#define K_EXTMOUT64 77
#define K_MINN 78
#define K_MOUTN 79
#define K_XMINN 80
#define K_EXTMINN 81
#define K_EXTMOUTN 82
#define K_OOS_WAIT_INT 83
#define K_MRELEASEP 84
#define K_ENBC3 85
#define K_ENBT3 86
#ifdef PROCESS_PRIORITY
#define K_SAVEPRI 87
#define K_STPRIF 88
#define K_STPRIB 89
#endif
#define K_FASTTIN 90
#define K_LDWSMAP 91
#define K_ULWSMAP 92
#define K_RMWSMAP 93
#define K_MPPCLONE 94
#define K_MPPSERIALISE 95
#define K_MPPDESERIALISE 96
#define K_MTNEW 97
#define K_MTFREE 98
#define K_MTCLONE 99

#ifdef WANT_CCSP_TABLE
static char *ccsp_entrytable[] = {\
	NULL, "_X_in", "_X_out", "_X_outword", "_X_outbyte", "_X_runp", "_X_startp", "_X_endp", \
	"_X_stopp", "_X_pause", "_X_ldtimer", "_X_tin", "_X_altwt", "_X_taltwt", "_X_enbc", "_X_enbt", \
	"_X_diss", "_X_disc", "_X_dist", "_X_RangeCheckError", "_X_Seterr", "_X_norm", NULL, NULL, \
	"_X_scheduler", "_X_savel", "_X_stlb", "_X_stlf", "_X_overflow", "_X_trap", "_X_BasicRangeError", "_X_BSeterr", \
	"_X_b_dispatch", "_X_bx_dispatch", "_X_res_claim", "_X_res_release", "_X_zero_div", NULL, NULL, NULL, NULL, \
	"_X_kernel_run", "_X_dynproc_exit", "_X_mnew", "_X_mfree", "_X_malloc", "_X_mrelease", "_X_dynproc_suspend", \
	"_X_fmul", "_X_min", "_X_mout", "_X_min64", "_X_mout64", "_X_xable", "_X_xin", "_X_xmin", "_X_xmin64", "_X_xend", \
	"_X_ndisc", "_X_ndist", "_X_ndiss", NULL /* extin */, NULL /* extout */, NULL /* extvrfy */, NULL /* extin8 */,
	NULL /* extin32 */, NULL /* extout8 */, NULL /* extout32 */, NULL /* extoutbyte */, NULL /* extoutword */,
	NULL /* extenbc */, NULL /* extndisc */, NULL /* getpri */, NULL /* setpri */, NULL /* extmin */, NULL /* extmin64 */,
	NULL /* extmout */, NULL /* extmout64 */, "_X_minn", "_X_moutn", "_X_xminn", NULL /* extminn */, NULL /* extmoutn */,
	NULL /* ooswaitint */, "_X_mreleasep", NULL /* enbc3 */, NULL /* enbt3 */, NULL /* savepri */, NULL /* stprif */,
	NULL /* stprib */, NULL /* Y_fasttin */, NULL /* ldwsmap */, NULL /* ulwsmap */, NULL /* rmwsmap */, NULL /* mppclone */,
	NULL /* mppserialise */, NULL /* mppdeserialise */, "_X_mtnew", "_X_mtfree", "_X_mtclone"};
#endif	/* WANT_CCSP_TABLE */

/* forms of passing arguments */
#define ARGS_ON_STACK 1
#define ARGS_IN_REGS 2
/* forms of kernel call */
#define KCALL_CALL 1			/* plain call */
#define KCALL_STOREIP_JUMP 2		/* store return addr in -4(%ebp) and jump */
#define KCALL_REGIP_JUMP 3		/* store return addr in next param and jump */
#define KCALL_JUMP 4			/* plain jump (non-return only!) */

#ifdef WANT_NEWCCSP_TABLE
typedef struct {
	char *entrypoint;
	int input_mode;
	int call_mode;
	int output_mode;
} newccsp_entrytype;

/* note, the calling convention for the sparc is fixed (with the same entry-points) as follows:
 *	- args passed in regs l0 .. l4, i1
 *	- run-time kernel vars left in regs (i0, i6, i7)
 *	- entrypoint "call"'d
 *	- add 8 to address in the delay slot
 */
static newccsp_entrytype newccsp_entrytable[] = {
	{NULL, 0, 0, 0},
	{"_Y_in", ARGS_IN_REGS, KCALL_STOREIP_JUMP, 0},
	{"_Y_out", ARGS_IN_REGS, KCALL_STOREIP_JUMP, 0},
	{"_Y_outword", ARGS_IN_REGS, KCALL_STOREIP_JUMP, 0},
	{"_Y_outbyte", ARGS_IN_REGS, KCALL_STOREIP_JUMP, 0},
	{"_Y_runp", ARGS_IN_REGS, KCALL_REGIP_JUMP, 0},
	{"_Y_startp", ARGS_IN_REGS, KCALL_REGIP_JUMP, 0},
	{"_Y_endp", ARGS_IN_REGS, KCALL_JUMP, 0},
	{"_X_stopp", ARGS_ON_STACK, KCALL_CALL, 0},
	{"_X_pause", 0, KCALL_CALL, 0},
	{"_X_ldtimer", 0, KCALL_CALL, ARGS_ON_STACK},
	{"_X_tin", ARGS_ON_STACK, KCALL_CALL, 0},
	{"_X_altwt", 0, KCALL_CALL, 0},
	{"_X_taltwt", 0, KCALL_CALL, 0},
	{"_Y_enbc", ARGS_IN_REGS, KCALL_CALL, ARGS_ON_STACK},
	{"_X_enbt", ARGS_ON_STACK, KCALL_CALL, ARGS_ON_STACK},
	{"_X_diss", ARGS_ON_STACK, KCALL_CALL, ARGS_ON_STACK},
	{"_Y_disc", ARGS_IN_REGS, KCALL_CALL, ARGS_ON_STACK},
	{"_X_dist", ARGS_ON_STACK, KCALL_CALL, ARGS_ON_STACK},
	{NULL, 0, 0, 0},
	{NULL, 0, 0, 0},
	{"_X_norm", ARGS_ON_STACK, KCALL_CALL, ARGS_ON_STACK},
	{NULL, 0, 0, 0},
	{NULL, 0, 0, 0},
	{NULL, 0, 0, 0},
	{"_X_savel", ARGS_ON_STACK, KCALL_CALL, 0},
	{"_X_stlb", ARGS_ON_STACK, KCALL_CALL, 0},
	{"_X_stlf", ARGS_ON_STACK, KCALL_CALL, 0},
	{NULL, 0, 0, 0},
	{"_X_trap", ARGS_ON_STACK, KCALL_CALL, ARGS_ON_STACK},
	{"_X_BasicRangeError", 0, KCALL_CALL, 0},
	{"_X_BSeterr", 0, KCALL_CALL, 0},
	{"_X_b_dispatch", 0, 0, 0},
	{"_X_bx_dispatch", 0, 0, 0},
	{"_X_res_release", 0, 0, 0},
	{"_X_res_claim", 0, 0, 0},
	{NULL, 0, 0, 0},
	{"_Y_in8", ARGS_IN_REGS, KCALL_STOREIP_JUMP, 0},
	{"_Y_in32", ARGS_IN_REGS, KCALL_STOREIP_JUMP, 0},
	{"_Y_out8", ARGS_IN_REGS, KCALL_STOREIP_JUMP, 0},
	{"_Y_out32", ARGS_IN_REGS, KCALL_STOREIP_JUMP, 0},
	{"_X_kernel_run", 0, 0, 0},
	{"_X_dynproc_exit", 0, 0, 0},
	{"_X_mnew", ARGS_ON_STACK, KCALL_CALL, ARGS_ON_STACK},
	{"_X_mfree", ARGS_ON_STACK, KCALL_CALL, 0},
	{"_X_malloc", ARGS_ON_STACK, KCALL_CALL, ARGS_ON_STACK},
	{"_X_mrelease", ARGS_ON_STACK, KCALL_CALL, 0},
	{"_X_dynproc_suspend", 0, 0, 0},
	{"_X_fmul", ARGS_ON_STACK, KCALL_CALL, ARGS_ON_STACK},
	{"_X_min", ARGS_IN_REGS, KCALL_STOREIP_JUMP, 0},
	{"_X_mout", ARGS_IN_REGS, KCALL_STOREIP_JUMP, 0},
	{"_X_min64", ARGS_IN_REGS, KCALL_STOREIP_JUMP, 0},
	{"_X_mout64", ARGS_IN_REGS, KCALL_STOREIP_JUMP, 0},
	{"_X_xable", ARGS_IN_REGS, KCALL_STOREIP_JUMP, 0},
	{"_X_xin", ARGS_IN_REGS, KCALL_STOREIP_JUMP, 0},
	{"_X_xmin", ARGS_IN_REGS, KCALL_STOREIP_JUMP, 0},
	{"_X_xmin64", ARGS_IN_REGS, KCALL_STOREIP_JUMP, 0},
	{"_X_xend", ARGS_ON_STACK, KCALL_CALL, 0},
	{"_Y_ndisc", ARGS_IN_REGS, KCALL_CALL, ARGS_ON_STACK},
	{"_X_ndist", ARGS_ON_STACK, KCALL_CALL, ARGS_ON_STACK},
	{"_X_ndiss", ARGS_ON_STACK, KCALL_CALL, ARGS_ON_STACK},
	{"_Y_extin", ARGS_IN_REGS, KCALL_STOREIP_JUMP, 0},
	{"_Y_extout", ARGS_IN_REGS, KCALL_STOREIP_JUMP, 0},
	{"_X_extvrfy", ARGS_ON_STACK, KCALL_CALL, 0},
	{"_Y_extin8", ARGS_IN_REGS, KCALL_STOREIP_JUMP, 0},
	{"_Y_extin32", ARGS_IN_REGS, KCALL_STOREIP_JUMP, 0},
	{"_Y_extout8", ARGS_IN_REGS, KCALL_STOREIP_JUMP, 0},
	{"_Y_extout32", ARGS_IN_REGS, KCALL_STOREIP_JUMP, 0},
	{"_Y_extoutbyte", ARGS_IN_REGS, KCALL_STOREIP_JUMP, 0},
	{"_Y_extoutword", ARGS_IN_REGS, KCALL_STOREIP_JUMP, 0},
	{"_Y_extenbc", ARGS_IN_REGS, KCALL_CALL, ARGS_ON_STACK},
	{"_Y_extndisc", ARGS_IN_REGS, KCALL_CALL, ARGS_ON_STACK},
	{"_X_getpri", 0, KCALL_CALL, ARGS_ON_STACK},
	{"_Y_setpri", ARGS_IN_REGS, KCALL_STOREIP_JUMP, 0},
	{"_Y_extmin", ARGS_IN_REGS, KCALL_STOREIP_JUMP, 0},
	{"_Y_extmin64", ARGS_IN_REGS, KCALL_STOREIP_JUMP, 0},
	{"_Y_extmout", ARGS_IN_REGS, KCALL_STOREIP_JUMP, 0},
	{"_Y_extmout64", ARGS_IN_REGS, KCALL_STOREIP_JUMP, 0},
	{"_X_minn", ARGS_IN_REGS, KCALL_STOREIP_JUMP, 0},
	{"_X_moutn", ARGS_IN_REGS, KCALL_STOREIP_JUMP, 0},
	{"_X_xminn", ARGS_IN_REGS, KCALL_STOREIP_JUMP, 0},
	{"_Y_extminn", ARGS_IN_REGS, KCALL_STOREIP_JUMP, 0},
	{"_Y_extmoutn", ARGS_IN_REGS, KCALL_STOREIP_JUMP, 0},
	{"_Y_ooswaitint", 0, 0, 0},
	{"_X_mreleasep", ARGS_ON_STACK, KCALL_CALL, 0},
	{"_Y_enbc3", ARGS_IN_REGS, KCALL_CALL, ARGS_ON_STACK},
	{"_Y_enbt3", ARGS_IN_REGS, KCALL_CALL, ARGS_ON_STACK},
	{"_Y_savepri", ARGS_IN_REGS, KCALL_CALL, 0},
	{"_Y_stprif", ARGS_IN_REGS, KCALL_CALL, 0},
	{"_Y_stprib", ARGS_IN_REGS, KCALL_CALL, 0},
	{"_Y_fasttin", ARGS_IN_REGS, KCALL_JUMP, 0},
	{"_Y_ldwsmap", ARGS_IN_REGS, KCALL_CALL, 0},
	{"_Y_ulwsmap", ARGS_IN_REGS, KCALL_CALL, 0},
	{"_Y_rmwsmap", ARGS_IN_REGS, KCALL_CALL, 0},
	{"_Y_mppclone", ARGS_IN_REGS, KCALL_CALL, ARGS_ON_STACK},
	{"_Y_mppserialise", ARGS_IN_REGS, KCALL_CALL, 0},
	{"_Y_mppdeserialise", ARGS_IN_REGS, KCALL_CALL, 0},
	{"_X_mtnew", ARGS_ON_STACK, KCALL_CALL, ARGS_ON_STACK},
	{"_X_mtfree", ARGS_ON_STACK, KCALL_CALL, 0},
	{"_X_mtclone", ARGS_ON_STACK, KCALL_CALL, ARGS_ON_STACK}
		
};
#endif	/* WANT_NEWCCSP_TABLE */

#endif	/* !__KIFACE_H */

