/*
 *  Function prototypes used by the iBCS2 emulator
 *
 * $Id: ibcs.h,v 1.19 1994/05/26 15:04:56 mike Exp $
 * $Source: /var/CVS/ibcs/include/ibcs/ibcs.h,v $
 */
#include <linux/ptrace.h>	/* for pt_regs */
#include <linux/sched.h>
#include <linux/signal.h>
#include <linux/unistd.h>

#include <ibcs/stream.h>


/* Magic... 1.1.10 changes the format of a task_struct. This is where
 * we figure out what we are doing.
 */
#ifdef INIT_FILES
#  define FD	files->fd
#  define FDI(x)	files->x
#else
#  define FD	filp
#  define FDI(x)	x
#endif
#ifdef INIT_MM
#  define MM(x)	mm->x
#else
#  define MM(x)	x
#endif


typedef int (*sysfun_p)();


extern sysfun_p sys_call_table[];

#define SYS(name)	(sys_call_table[__NR_##name])


/*
 * the function prefix sys_... are used by linux in native mode.
 * ibcs_... are emulation interfaces for routine that differ from iBCS2 
 * and linux.  The xnx_... are xenix routines.  Note, just because
 * xnx routines are listed doesn't mean we support native xenix binaries.
 * (yet :-)
 */
typedef struct IBCS_function {
	void *	kfunc;	/* function to call (sys_..., ibcs_... or xnx_...)
			 * or pointer to a sub class.
			 */
	short	nargs;	/* number of args to kfunc or Ukn, Spl or Fast */
#ifdef IBCS_TRACE
	short	trace;	/* trace function we can turn tracing on or off */
	char *	name;	/* name of function (for tracing) */
	char *	args;	/* how to print the arg list (see plist) */
#endif
} IBCS_func;

struct ibcs_statfs {
	short f_type;
	long f_bsize;
	long f_frsize;
	long f_blocks;
	long f_bfree;
	long f_files;
	long f_ffree;
	char f_fname[6];
	char f_fpack[6];
};

struct ibcs_stat {
        unsigned short st_dev;
        unsigned short st_ino;
        unsigned short st_mode;
        unsigned short st_nlink;
        unsigned short st_uid;
        unsigned short st_gid;
        unsigned short st_rdev;
        unsigned long  st_size;
        unsigned long  st_atime;
        unsigned long  st_mtime;
        unsigned long  st_ctime;
};

/* coff.c */
extern int ibcs_fork(struct pt_regs * regs);
extern int ibcs_pipe(struct pt_regs * regs);
extern int ibcs_getpid(struct pt_regs * regs);
extern int ibcs_getuid(struct pt_regs * regs);
extern int ibcs_getgid(struct pt_regs * regs);
extern int ibcs_wait(struct pt_regs * regs);
extern int ibcs_execv(struct pt_regs * regs);
extern int ibcs_exec(struct pt_regs * regs);
extern int ibcs_read(int fd, char *buf, int nbytes);
extern int ibcs_procids(struct pt_regs * regs);
extern int ibcs_select(struct pt_regs *regs);
extern int ibcs_time(void);

/* emulate.c */
#ifdef INIT_MM
extern void iABI_emulate_real(struct pt_regs * regs);
#else
extern void iABI_emulate(struct pt_regs *regs);
#endif
extern void ibcs_exit(int n);
extern int iABI_errors(int errno);
extern int ibcs_syscall(struct pt_regs *regs);

/* fcntl.c */
extern int ibcs_fcntl(struct pt_regs *regs);

/* ioctl.c */
extern int ibcs_ioctl(int fd, unsigned int ioctl_num, void *arg);

/* ipc.c */
extern int ibcs_semsys (struct pt_regs *regs);
extern int ibcs_shmsys (struct pt_regs *regs);
extern int ibcs_msgsys (struct pt_regs *regs);

/* mmap.c */
extern int ibcs_mmap(unsigned int vaddr, unsigned int vsize, int prot,
 		     int flags, int fd, unsigned int file_offset);

/* open.c */
extern int ibcs_statfs(const char * path, struct ibcs_statfs * buf);
extern int ibcs_fstatfs(unsigned int fd, struct ibcs_statfs * buf);
extern int ibcs_open(const char * fname, int flag, int mode);
extern int ibcs_getdents(int fd, char *buf, int nybtes);

/* poll.c */
struct poll{
	int fd;
	short events;
	short revents;
};
extern int ibcs_poll(struct poll * ufds, size_t nfds, int timeout);

/* hrtsys.c */
extern int ibcs_hrtsys(struct pt_regs * regs);

/* secureware.c */
extern int sw_security(int cmd, void *p1, void *p2, void *p3, void *p4, void *p5);

/* signal.c */
/* For mapping signal numbers */
extern unsigned long *signal_map_to_linux[];
extern unsigned long *signal_map_from_linux[];
void ibcs_sig_handler (struct pt_regs * regs, int sig, __sighandler_t handler);
extern int ibcs_signal(struct pt_regs * regs);
extern int ibcs_sigset(struct pt_regs * regs);
void ibcs_sighold (struct pt_regs * regs);
void ibcs_sigrelse (struct pt_regs * regs);
void ibcs_sigignore (struct pt_regs * regs);
void ibcs_sigpause (struct pt_regs * regs);
extern int ibcs_sigfunc(struct pt_regs * regs);
extern int ibcs_kill(int pid, int sig);

/* socket.c */
extern int ibcs_getsockopt(unsigned long *sp);
extern int ibcs_setsockopt(unsigned long *sp);

/* stat.c */
extern int ibcs_stat(char * filename, struct ibcs_stat * statbuf);
extern int ibcs_lstat(char * filename, struct ibcs_stat * statbuf);
extern int ibcs_fstat(unsigned int fd, struct ibcs_stat * statbuf);

/* stream.c */
extern int ibcs_getmsg(int fd, struct strbuf *ctlptr, struct strbuf *dataptr,
			int *flags);
extern int ibcs_putmsg(int fd, struct strbuf *ctlptr, struct strbuf *dataptr,
			int *flags);

/* sysconf.c */
extern int ibcs_sysconf(int name);

/* Kernels 1.1.10 and later have sysfs as a system call. */
#ifndef __NR_sysfs
/* sysfs.c */
extern int ibcs_sysfs(struct pt_regs * regs);
#endif

/* sysi86.c */
extern int ibcs_sysi86(struct pt_regs * regs);

/* ulimit.c */
extern int ibcs_ulimit(int cmd, int val);

/* utsname.c */
extern int abi_utsname(unsigned long addr);
extern int sco_utsname(unsigned long addr);
extern int v7_utsname(unsigned long addr);

/* wysev386.c */
extern int wv386_gethostname(char *name, int len);
extern int wv386_getdomainname(char *name, int len);
extern int wv386_wait3(int *loc);
extern int wv386_socket(struct pt_regs *regs);
extern int wv386_connect(struct pt_regs *regs);
extern int wv386_accept(struct pt_regs *regs);
extern int wv386_send(struct pt_regs *regs);
extern int wv386_recv(struct pt_regs *regs);
extern int wv386_bind(struct pt_regs *regs);
extern int wv386_setsockopt(struct pt_regs *regs);
extern int wv386_listen(struct pt_regs *regs);
extern int wv386_getsockopt(struct pt_regs *regs);
extern int wv386_recvfrom(struct pt_regs *regs);
extern int wv386_sendto(struct pt_regs *regs);
extern int wv386_shutdown(struct pt_regs *regs);
extern int wv386_socketpair(struct pt_regs *regs);
extern int wv386_getpeername(struct pt_regs *regs);
extern int wv386_getsockname(struct pt_regs *regs);

/* From wysev386i.c */
extern int wv386_ioctl(int fd, unsigned int ioctl_num, void *arg);

/* From socksys.c */
extern void init_socksys(void);
extern void cleanup_socksys(void);

/* From sysisc.c */
extern int isc_setostype(int);
