13584Ssos/*-
23584Ssos * Copyright (c) 1994 Sean Eric Fagan
3230132Suqs * Copyright (c) 1994 S��ren Schmidt
411397Sswallace * Copyright (c) 1995 Steven Wallace
53584Ssos * All rights reserved.
63584Ssos *
73584Ssos * Redistribution and use in source and binary forms, with or without
83584Ssos * modification, are permitted provided that the following conditions
93584Ssos * are met:
103584Ssos * 1. Redistributions of source code must retain the above copyright
113584Ssos *    notice, this list of conditions and the following disclaimer
123584Ssos *    in this position and unchanged.
133584Ssos * 2. Redistributions in binary form must reproduce the above copyright
143584Ssos *    notice, this list of conditions and the following disclaimer in the
153584Ssos *    documentation and/or other materials provided with the distribution.
163584Ssos * 3. The name of the author may not be used to endorse or promote products
1797748Sschweikh *    derived from this software without specific prior written permission
183584Ssos *
193584Ssos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
203584Ssos * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
213584Ssos * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
223584Ssos * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
233584Ssos * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
243584Ssos * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
253584Ssos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
263584Ssos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
273584Ssos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
283584Ssos * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
293584Ssos */
303584Ssos
31115684Sobrien#include <sys/cdefs.h>
32115684Sobrien__FBSDID("$FreeBSD$");
33115684Sobrien
343584Ssos#include <sys/param.h>
3511397Sswallace#include <sys/systm.h>
3614885Sswallace#include <sys/namei.h>
3711397Sswallace#include <sys/sysproto.h>
38162954Sphk#include <sys/clock.h>
3991388Srobert#include <sys/jail.h>
4011397Sswallace#include <sys/kernel.h>
41141488Sjhb#include <sys/malloc.h>
4224205Sbde#include <sys/filio.h>
4311397Sswallace#include <sys/vnode.h>
44141488Sjhb#include <sys/syscallsubr.h>
4511397Sswallace#include <sys/sysctl.h>
46160241Sjhb#include <sys/sysent.h>
47141488Sjhb#include <sys/unistd.h>
4811397Sswallace
493584Ssos#include <machine/cpu.h>
503584Ssos
5111397Sswallace#include <i386/ibcs2/ibcs2_types.h>
5214885Sswallace#include <i386/ibcs2/ibcs2_unistd.h>
5311397Sswallace#include <i386/ibcs2/ibcs2_signal.h>
5411397Sswallace#include <i386/ibcs2/ibcs2_util.h>
5511397Sswallace#include <i386/ibcs2/ibcs2_proto.h>
5611397Sswallace#include <i386/ibcs2/ibcs2_xenix.h>
5711397Sswallace#include <i386/ibcs2/ibcs2_xenix_syscall.h>
583584Ssos
5954655Seivind
6011397Sswallaceextern struct sysent xenix_sysent[];
6111397Sswallace
6211397Sswallaceint
6383366Sjulianibcs2_xenix(struct thread *td, struct ibcs2_xenix_args *uap)
643584Ssos{
6583366Sjulian	struct trapframe *tf = td->td_frame;
6611397Sswallace        struct sysent *callp;
67147820Sjhb        u_int code;
68147820Sjhb	int error;
693584Ssos
7011397Sswallace	code = (tf->tf_eax & 0xff00) >> 8;
7111397Sswallace	callp = &xenix_sysent[code];
7211397Sswallace
73160798Sjhb	if (code < IBCS2_XENIX_MAXSYSCALL)
74147820Sjhb		error = ((*callp->sy_call)(td, (void *)uap));
75160798Sjhb	else
76147820Sjhb		error = ENOSYS;
77147820Sjhb	return (error);
783584Ssos}
793584Ssos
8011397Sswallaceint
8183366Sjulianxenix_rdchk(td, uap)
8283366Sjulian	struct thread *td;
8311397Sswallace	struct xenix_rdchk_args *uap;
8411397Sswallace{
85160192Sjhb	int data, error;
863584Ssos
8711397Sswallace	DPRINTF(("IBCS2: 'xenix rdchk'\n"));
88160192Sjhb
89160192Sjhb	error = kern_ioctl(td, uap->fd, FIONREAD, (caddr_t)&data);
90160192Sjhb	if (error)
91160192Sjhb		return (error);
92160192Sjhb	td->td_retval[0] = data ? 1 : 0;
93160192Sjhb	return (0);
9411397Sswallace}
9511397Sswallace
9611397Sswallaceint
9783366Sjulianxenix_chsize(td, uap)
9883366Sjulian	struct thread *td;
9911397Sswallace	struct xenix_chsize_args *uap;
1003584Ssos{
10111397Sswallace	struct ftruncate_args sa;
1023584Ssos
10311397Sswallace	DPRINTF(("IBCS2: 'xenix chsize'\n"));
104107849Salfred	sa.fd = uap->fd;
105107849Salfred	sa.length = uap->size;
106225617Skmacy	return sys_ftruncate(td, &sa);
1073584Ssos}
1083584Ssos
1093584Ssos
11011397Sswallaceint
11183366Sjulianxenix_ftime(td, uap)
11283366Sjulian	struct thread *td;
11311397Sswallace	struct xenix_ftime_args *uap;
1143584Ssos{
11511397Sswallace	struct timeval tv;
11626819Ssef	struct ibcs2_timeb {
117103870Salfred		unsigned long time __packed;
11826819Ssef		unsigned short millitm;
11926819Ssef		short timezone;
12026819Ssef		short dstflag;
12126819Ssef	} itb;
12211397Sswallace
12311397Sswallace	DPRINTF(("IBCS2: 'xenix ftime'\n"));
12411397Sswallace	microtime(&tv);
12511397Sswallace	itb.time = tv.tv_sec;
12611397Sswallace	itb.millitm = (tv.tv_usec / 1000);
127110299Sphk	itb.timezone = tz_minuteswest;
128110299Sphk	itb.dstflag = tz_dsttime != DST_NONE;
12911397Sswallace
130107849Salfred	return copyout((caddr_t)&itb, (caddr_t)uap->tp,
13126819Ssef		       sizeof(struct ibcs2_timeb));
13211397Sswallace}
13311397Sswallace
13411397Sswallaceint
13583366Sjulianxenix_nap(struct thread *td, struct xenix_nap_args *uap)
13611397Sswallace{
1373584Ssos	long period;
1383584Ssos
139107849Salfred	DPRINTF(("IBCS2: 'xenix nap %d ms'\n", uap->millisec));
140107849Salfred	period = (long)uap->millisec / (1000/hz);
1413584Ssos	if (period)
142167086Sjhb		pause("nap", period);
1433584Ssos	return 0;
1443584Ssos}
1453584Ssos
14611397Sswallaceint
14783366Sjulianxenix_utsname(struct thread *td, struct xenix_utsname_args *uap)
1483584Ssos{
1493584Ssos	struct ibcs2_sco_utsname {
1503584Ssos		char sysname[9];
1513584Ssos		char nodename[9];
1523584Ssos		char release[16];
1533584Ssos		char kernelid[20];
1543584Ssos		char machine[9];
1553584Ssos		char bustype[9];
1563584Ssos		char sysserial[10];
1573584Ssos		unsigned short sysorigin;
1583584Ssos		unsigned short sysoem;
1593584Ssos		char numusers[9];
1603584Ssos		unsigned short numcpu;
1613584Ssos	} ibcs2_sco_uname;
1623584Ssos
16311397Sswallace	DPRINTF(("IBCS2: 'xenix sco_utsname'\n"));
1643584Ssos	bzero(&ibcs2_sco_uname, sizeof(struct ibcs2_sco_utsname));
16541514Sarchie	strncpy(ibcs2_sco_uname.sysname, ostype,
16641514Sarchie		sizeof(ibcs2_sco_uname.sysname) - 1);
16791393Srobert	getcredhostname(td->td_ucred, ibcs2_sco_uname.nodename,
16891388Srobert	    sizeof(ibcs2_sco_uname.nodename) - 1);
16941514Sarchie	strncpy(ibcs2_sco_uname.release, osrelease,
17041514Sarchie		sizeof(ibcs2_sco_uname.release) - 1);
17141514Sarchie	strncpy(ibcs2_sco_uname.kernelid, version,
17241514Sarchie		sizeof(ibcs2_sco_uname.kernelid) - 1);
17341514Sarchie	strncpy(ibcs2_sco_uname.machine, machine,
17441514Sarchie		sizeof(ibcs2_sco_uname.machine) - 1);
17541514Sarchie	strncpy(ibcs2_sco_uname.bustype, "ISA/EISA",
17641514Sarchie		sizeof(ibcs2_sco_uname.bustype) - 1);
17741514Sarchie	strncpy(ibcs2_sco_uname.sysserial, "no charge",
17841514Sarchie		sizeof(ibcs2_sco_uname.sysserial) - 1);
17941514Sarchie	strncpy(ibcs2_sco_uname.numusers, "unlim",
18041514Sarchie		sizeof(ibcs2_sco_uname.numusers) - 1);
1813584Ssos	ibcs2_sco_uname.sysorigin = 0xFFFF;
1823584Ssos	ibcs2_sco_uname.sysoem = 0xFFFF;
1833584Ssos	ibcs2_sco_uname.numcpu = 1;
18438354Sbde	return copyout((caddr_t)&ibcs2_sco_uname,
18538354Sbde		       (caddr_t)(void *)(intptr_t)uap->addr,
1863584Ssos		       sizeof(struct ibcs2_sco_utsname));
1873584Ssos}
1883584Ssos
1893584Ssosint
19083366Sjulianxenix_scoinfo(struct thread *td, struct xenix_scoinfo_args *uap)
1913584Ssos{
19211397Sswallace  /* scoinfo (not documented) */
19383366Sjulian  td->td_retval[0] = 0;
19411397Sswallace  return 0;
1953584Ssos}
19614885Sswallace
19714885Sswallaceint
19883366Sjulianxenix_eaccess(struct thread *td, struct xenix_eaccess_args *uap)
19914885Sswallace{
200141488Sjhb	char *path;
201141488Sjhb        int error, bsd_flags;
20214885Sswallace
203141488Sjhb	bsd_flags = 0;
204141488Sjhb	if (uap->flags & IBCS2_R_OK)
205141488Sjhb		bsd_flags |= R_OK;
206141488Sjhb	if (uap->flags & IBCS2_W_OK)
207141488Sjhb		bsd_flags |= W_OK;
208141488Sjhb	if (uap->flags & IBCS2_X_OK)
209141488Sjhb		bsd_flags |= X_OK;
21014885Sswallace
211141488Sjhb	CHECKALTEXIST(td, uap->path, &path);
212155401Sjhb	error = kern_eaccess(td, path, UIO_SYSSPACE, bsd_flags);
213141488Sjhb	free(path, M_TEMP);
214141488Sjhb        return (error);
21514885Sswallace}
216