Add generated pcidevs files. Fix a small typo in devlist2h.awk.
[dragonfly.git] / sys / emulation / svr4 / svr4_ttold.c
1 /*
2  * Copyright (c) 1998 Mark Newton
3  * Copyright (c) 1994 Christos Zoulas
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. The name of the author may not be used to endorse or promote products
15  *    derived from this software without specific prior written permission
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  * 
28  * $FreeBSD: src/sys/svr4/svr4_ttold.c,v 1.7 1999/12/08 12:00:49 newton Exp $
29  * $DragonFly: src/sys/emulation/svr4/Attic/svr4_ttold.c,v 1.5 2003/08/27 06:07:10 rob Exp $
30  */
31
32 #include <sys/param.h>
33 #include <sys/proc.h>
34 #include <sys/systm.h>
35 #include <sys/file.h>
36 #include <sys/filedesc.h>
37 #include <sys/ioctl_compat.h>
38 #include <sys/termios.h>
39 #include <sys/file2.h>
40
41 #include "svr4.h"
42 #include "svr4_util.h"
43 #include "svr4_ttold.h"
44 #include "svr4_ioctl.h"
45
46
47 static void svr4_tchars_to_bsd_tchars (const struct svr4_tchars *st,
48                                            struct tchars *bt);
49 static void bsd_tchars_to_svr4_tchars (const struct tchars *bt,
50                                            struct svr4_tchars *st);
51 static void svr4_sgttyb_to_bsd_sgttyb (const struct svr4_sgttyb *ss,
52                                            struct sgttyb *bs);
53 static void bsd_sgttyb_to_svr4_sgttyb (const struct sgttyb *bs,
54                                            struct svr4_sgttyb *ss);
55 static void svr4_ltchars_to_bsd_ltchars (const struct svr4_ltchars *sl,
56                                              struct ltchars *bl);
57 static void bsd_ltchars_to_svr4_ltchars (const struct ltchars *bl,
58                                              struct svr4_ltchars *sl);
59
60 #ifdef DEBUG_SVR4
61 static void print_svr4_sgttyb (const char *, struct svr4_sgttyb *);
62 static void print_svr4_tchars (const char *, struct svr4_tchars *);
63 static void print_svr4_ltchars (const char *, struct svr4_ltchars *);
64
65 static void
66 print_svr4_sgttyb(str, ss)
67         const char *str;
68         struct svr4_sgttyb *ss;
69 {
70
71         uprintf("%s\nispeed=%o ospeed=%o ", str, ss->sg_ispeed, ss->sg_ospeed);
72         uprintf("erase=%o kill=%o flags=%o\n", ss->sg_erase, ss->sg_kill,
73             ss->sg_flags);
74 }
75
76 static void
77 print_svr4_tchars(str, st)
78         const char *str;
79         struct svr4_tchars *st;
80 {
81         uprintf("%s\nintrc=%o quitc=%o ", str, st->t_intrc, st->t_quitc);
82         uprintf("startc=%o stopc=%o eofc=%o brkc=%o\n", st->t_startc,
83             st->t_stopc, st->t_eofc, st->t_brkc);
84 }
85
86 static void
87 print_svr4_ltchars(str, sl)
88         const char *str;
89         struct svr4_ltchars *sl;
90 {
91         uprintf("%s\nsuspc=%o dsuspc=%o ", str, sl->t_suspc, sl->t_dsuspc);
92         uprintf("rprntc=%o flushc=%o werasc=%o lnextc=%o\n", sl->t_rprntc,
93             sl->t_flushc, sl->t_werasc, sl->t_lnextc);
94 }
95 #endif /* DEBUG_SVR4 */
96
97 static void
98 svr4_tchars_to_bsd_tchars(st, bt)
99         const struct svr4_tchars        *st;
100         struct tchars                   *bt;
101 {
102         bt->t_intrc  = st->t_intrc;
103         bt->t_quitc  = st->t_quitc;
104         bt->t_startc = st->t_startc;
105         bt->t_stopc  = st->t_stopc;
106         bt->t_eofc   = st->t_eofc;
107         bt->t_brkc   = st->t_brkc;
108 }
109
110
111 static void
112 bsd_tchars_to_svr4_tchars(bt, st)
113         const struct tchars     *bt;
114         struct svr4_tchars      *st;
115 {
116         st->t_intrc  = bt->t_intrc;
117         st->t_quitc  = bt->t_quitc;
118         st->t_startc = bt->t_startc;
119         st->t_stopc  = bt->t_stopc;
120         st->t_eofc   = bt->t_eofc;
121         st->t_brkc   = bt->t_brkc;
122 }
123
124
125 static void
126 svr4_sgttyb_to_bsd_sgttyb(ss, bs)
127         const struct svr4_sgttyb        *ss;
128         struct sgttyb                   *bs;
129 {
130         bs->sg_ispeed = ss->sg_ispeed;
131         bs->sg_ospeed = ss->sg_ospeed;
132         bs->sg_erase  = ss->sg_erase;   
133         bs->sg_kill   = ss->sg_kill;
134         bs->sg_flags  = ss->sg_flags;
135 };
136
137
138 static void
139 bsd_sgttyb_to_svr4_sgttyb(bs, ss)
140         const struct sgttyb     *bs;
141         struct svr4_sgttyb      *ss;
142 {
143         ss->sg_ispeed = bs->sg_ispeed;
144         ss->sg_ospeed = bs->sg_ospeed;
145         ss->sg_erase  = bs->sg_erase;   
146         ss->sg_kill   = bs->sg_kill;
147         ss->sg_flags  = bs->sg_flags;
148 }
149
150
151 static void
152 svr4_ltchars_to_bsd_ltchars(sl, bl)
153         const struct svr4_ltchars       *sl;
154         struct ltchars                  *bl;
155 {
156         bl->t_suspc  = sl->t_suspc;
157         bl->t_dsuspc = sl->t_dsuspc;
158         bl->t_rprntc = sl->t_rprntc;
159         bl->t_flushc = sl->t_flushc;
160         bl->t_werasc = sl->t_werasc;
161         bl->t_lnextc = sl->t_lnextc;
162 }
163
164
165 static void
166 bsd_ltchars_to_svr4_ltchars(bl, sl)
167         const struct ltchars    *bl;
168         struct svr4_ltchars     *sl;
169 {
170         sl->t_suspc  = bl->t_suspc;
171         sl->t_dsuspc = bl->t_dsuspc;
172         sl->t_rprntc = bl->t_rprntc;
173         sl->t_flushc = bl->t_flushc;
174         sl->t_werasc = bl->t_werasc;
175         sl->t_lnextc = bl->t_lnextc;
176 }
177
178
179 int
180 svr4_ttold_ioctl(fp, td, retval, fd, cmd, data)
181         struct file *fp;
182         struct thread *td;
183         register_t *retval;
184         int fd;
185         u_long cmd;
186         caddr_t data;
187 {
188         int                     error;
189
190         *retval = 0;
191
192         switch (cmd) {
193         case SVR4_TIOCGPGRP:
194                 {
195                         pid_t pid;
196
197                         if ((error = fo_ioctl(fp, TIOCGPGRP, (caddr_t) &pid, td)) != 0)
198                             return error;
199
200                         DPRINTF(("TIOCGPGRP %d\n", pid));
201
202                         if ((error = copyout(&pid, data, sizeof(pid))) != 0)
203                                 return error;
204
205                 }
206
207         case SVR4_TIOCSPGRP:
208                 {
209                         pid_t pid;
210
211                         if ((error = copyin(data, &pid, sizeof(pid))) != 0)
212                                 return error;
213
214                         DPRINTF(("TIOCSPGRP %d\n", pid));
215
216                         return fo_ioctl(fp, TIOCSPGRP, (caddr_t) &pid, td);
217                 }
218
219         case SVR4_TIOCGSID:
220                 {
221 #if defined(TIOCGSID)
222                         pid_t pid;
223                         if ((error = fo_ioctl(fp, TIOCGSID, (caddr_t) &pid, td)) != 0)
224                                 return error;
225
226                         DPRINTF(("TIOCGSID %d\n", pid));
227
228                         return copyout(&pid, data, sizeof(pid));
229 #else
230                         uprintf("ioctl(TIOCGSID) for td %p unsupported\n", td);
231                         return EINVAL;
232 #endif
233                 }
234
235         case SVR4_TIOCGETP:
236                 {
237                         struct sgttyb bs;
238                         struct svr4_sgttyb ss;
239
240                         error = fo_ioctl(fp, TIOCGETP, (caddr_t) &bs, td);
241                         if (error)
242                                 return error;
243
244                         bsd_sgttyb_to_svr4_sgttyb(&bs, &ss);
245 #ifdef DEBUG_SVR4
246                         print_svr4_sgttyb("SVR4_TIOCGETP", &ss);
247 #endif /* DEBUG_SVR4 */
248                         return copyout(&ss, data, sizeof(ss));
249                 }
250
251         case SVR4_TIOCSETP:
252         case SVR4_TIOCSETN:
253                 {
254                         struct sgttyb bs;
255                         struct svr4_sgttyb ss;
256
257                         if ((error = copyin(data, &ss, sizeof(ss))) != 0)
258                                 return error;
259
260                         svr4_sgttyb_to_bsd_sgttyb(&ss, &bs);
261 #ifdef DEBUG_SVR4
262                         print_svr4_sgttyb("SVR4_TIOCSET{P,N}", &ss);
263 #endif /* DEBUG_SVR4 */
264                         cmd = (cmd == SVR4_TIOCSETP) ? TIOCSETP : TIOCSETN;
265                         return fo_ioctl(fp, cmd, (caddr_t) &bs, td);
266                 }
267
268         case SVR4_TIOCGETC:
269                 {
270                         struct tchars bt;
271                         struct svr4_tchars st;
272
273                         error = fo_ioctl(fp, TIOCGETC, (caddr_t) &bt, td);
274                         if (error)
275                                 return error;
276
277                         bsd_tchars_to_svr4_tchars(&bt, &st);
278 #ifdef DEBUG_SVR4
279                         print_svr4_tchars("SVR4_TIOCGETC", &st);
280 #endif /* DEBUG_SVR4 */
281                         return copyout(&st, data, sizeof(st));
282                 }
283
284         case SVR4_TIOCSETC:
285                 {
286                         struct tchars bt;
287                         struct svr4_tchars st;
288
289                         if ((error = copyin(data, &st, sizeof(st))) != 0)
290                                 return error;
291
292                         svr4_tchars_to_bsd_tchars(&st, &bt);
293 #ifdef DEBUG_SVR4
294                         print_svr4_tchars("SVR4_TIOCSETC", &st);
295 #endif /* DEBUG_SVR4 */
296                         return fo_ioctl(fp, TIOCSETC, (caddr_t) &bt, td);
297                 }
298
299         case SVR4_TIOCGLTC:
300                 {
301                         struct ltchars bl;
302                         struct svr4_ltchars sl;
303
304                         error = fo_ioctl(fp, TIOCGLTC, (caddr_t) &bl, td);
305                         if (error)
306                                 return error;
307
308                         bsd_ltchars_to_svr4_ltchars(&bl, &sl);
309 #ifdef DEBUG_SVR4
310                         print_svr4_ltchars("SVR4_TIOCGLTC", &sl);
311 #endif /* DEBUG_SVR4 */
312                         return copyout(&sl, data, sizeof(sl));
313                 }
314
315         case SVR4_TIOCSLTC:
316                 {
317                         struct ltchars bl;
318                         struct svr4_ltchars sl;
319
320                         if ((error = copyin(data, &sl, sizeof(sl))) != 0)
321                                 return error;
322
323                         svr4_ltchars_to_bsd_ltchars(&sl, &bl);
324 #ifdef DEBUG_SVR4
325                         print_svr4_ltchars("SVR4_TIOCSLTC", &sl);
326 #endif /* DEBUG_SVR4 */
327                         return fo_ioctl(fp, TIOCSLTC, (caddr_t) &bl, td);
328                 }
329
330         case SVR4_TIOCLGET:
331                 {
332                         int flags;
333                         if ((error = fo_ioctl(fp, TIOCLGET, (caddr_t) &flags, td)) != 0)
334                                 return error;
335                         DPRINTF(("SVR4_TIOCLGET %o\n", flags));
336                         return copyout(&flags, data, sizeof(flags));
337                 }
338
339         case SVR4_TIOCLSET:
340         case SVR4_TIOCLBIS:
341         case SVR4_TIOCLBIC:
342                 {
343                         int flags;
344
345                         if ((error = copyin(data, &flags, sizeof(flags))) != 0)
346                                 return error;
347
348                         switch (cmd) {
349                         case SVR4_TIOCLSET:
350                                 cmd = TIOCLSET;
351                                 break;
352                         case SVR4_TIOCLBIS:
353                                 cmd = TIOCLBIS;
354                                 break;
355                         case SVR4_TIOCLBIC:
356                                 cmd = TIOCLBIC;
357                                 break;
358                         }
359
360                         DPRINTF(("SVR4_TIOCL{SET,BIS,BIC} %o\n", flags));
361                         return fo_ioctl(fp, cmd, (caddr_t) &flags, td);
362                 }
363
364         default:
365                 DPRINTF(("Unknown svr4 ttold %lx\n", cmd));
366                 return 0;       /* ENOSYS really */
367         }
368 }