xref: /original-bsd/sys/vax/vax/sys_machdep.c (revision 9a77813a)
1 /*
2  * Copyright (c) 1982, 1986 Regents of the University of California.
3  * All rights reserved.  The Berkeley software License Agreement
4  * specifies the terms and conditions for redistribution.
5  *
6  *	@(#)sys_machdep.c	7.2 (Berkeley) 04/26/89
7  */
8 
9 #include "param.h"
10 #include "systm.h"
11 #include "dir.h"
12 #include "user.h"
13 #include "ioctl.h"
14 #include "file.h"
15 #include "proc.h"
16 #include "uio.h"
17 #include "kernel.h"
18 #include "mtio.h"
19 #include "buf.h"
20 #include "trace.h"
21 
22 #include "dkio.h"
23 #include "pte.h"
24 #include "../vaxuba/ubareg.h"
25 #include "../vaxuba/ubavar.h"
26 
27 resuba()
28 {
29 
30 	if (u.u_error = suser(u.u_cred, &u.u_acflag))
31 		return;
32 	if (u.u_arg[0] < numuba)
33 		ubareset(u.u_arg[0]);
34 }
35 
36 #ifdef TRACE
37 int	nvualarm;
38 
39 vtrace()
40 {
41 	register struct a {
42 		int	request;
43 		int	value;
44 	} *uap;
45 	int vdoualarm();
46 
47 	uap = (struct a *)u.u_ap;
48 	switch (uap->request) {
49 
50 	case VTR_DISABLE:		/* disable a trace point */
51 	case VTR_ENABLE:		/* enable a trace point */
52 		if (uap->value < 0 || uap->value >= TR_NFLAGS)
53 			u.u_error = EINVAL;
54 		else {
55 			u.u_r.r_val1 = traceflags[uap->value];
56 			traceflags[uap->value] = uap->request;
57 		}
58 		break;
59 
60 	case VTR_VALUE:		/* return a trace point setting */
61 		if (uap->value < 0 || uap->value >= TR_NFLAGS)
62 			u.u_error = EINVAL;
63 		else
64 			u.u_r.r_val1 = traceflags[uap->value];
65 		break;
66 
67 	case VTR_UALARM:	/* set a real-time ualarm, less than 1 min */
68 		if (uap->value <= 0 || uap->value > 60 * hz ||
69 		    nvualarm > 5)
70 			u.u_error = EINVAL;
71 		else {
72 			nvualarm++;
73 			timeout(vdoualarm, (caddr_t)u.u_procp->p_pid,
74 			    uap->value);
75 		}
76 		break;
77 
78 	case VTR_STAMP:
79 		trace(TR_STAMP, uap->value, u.u_procp->p_pid);
80 		break;
81 	}
82 }
83 
84 vdoualarm(arg)
85 	int arg;
86 {
87 	register struct proc *p;
88 
89 	p = pfind(arg);
90 	if (p)
91 		psignal(p, 16);
92 	nvualarm--;
93 }
94 #endif
95 
96 #ifdef COMPAT
97 /*
98  * Note: these tables are sorted by
99  * ioctl "code" (in ascending order).
100  */
101 int dctls[] = { DKIOCHDR, 0 };
102 int fctls[] = { FIOCLEX, FIONCLEX, FIOASYNC, FIONBIO, FIONREAD, 0 };
103 int mctls[] = { MTIOCTOP, MTIOCGET, 0 };
104 int tctls[] = {
105 	TIOCGETD, TIOCSETD, TIOCHPCL, TIOCMODG, TIOCMODS,
106 	TIOCGETP, TIOCSETP, TIOCSETN, TIOCEXCL, TIOCNXCL,
107 	TIOCFLUSH,TIOCSETC, TIOCGETC, TIOCREMOTE,TIOCMGET,
108 	TIOCMBIC, TIOCMBIS, TIOCMSET, TIOCSTART,TIOCSTOP,
109 	TIOCPKT,  TIOCNOTTY,TIOCSTI,  TIOCOUTQ, TIOCGLTC,
110 	TIOCSLTC, TIOCSPGRP,TIOCGPGRP,TIOCCDTR, TIOCSDTR,
111 	TIOCCBRK, TIOCSBRK, TIOCLGET, TIOCLSET, TIOCLBIC,
112 	TIOCLBIS, 0
113 };
114 
115 /*
116  * Map an old style ioctl command to new.
117  */
118 mapioctl(cmd)
119 	int cmd;
120 {
121 	register int *map, c;
122 
123 	switch ((cmd >> 8) & 0xff) {
124 
125 	case 'd':
126 		map = dctls;
127 		break;
128 
129 	case 'f':
130 		map = fctls;
131 		break;
132 
133 	case 'm':
134 		map = mctls;
135 		break;
136 
137 	case 't':
138 		map = tctls;
139 		break;
140 
141 	default:
142 		return (0);
143 	}
144 	while ((c = *map) && (c&0xff) < (cmd&0xff))
145 		map++;
146 	if (c && (c&0xff) == (cmd&0xff))
147 		return (c);
148 	return (0);
149 }
150 #endif
151