|
|
1.1 root 1: /*
2: * i386/tioc.c
3: *
4: * Convert COH286 tty ioctl's to Sys 5 compatible calls.
5: *
6: * Revised: Wed May 26 16:49:20 1993 CDT
7: */
8:
9: /*
10: * ----------------------------------------------------------------------
11: * Includes.
12: */
13: #include <sys/coherent.h>
14: #include <sgtty.h>
15: #include <errno.h>
16:
17: /*
18: * ----------------------------------------------------------------------
19: * Definitions.
20: * Constants.
21: * Macros with argument lists.
22: * Typedefs.
23: * Enums.
24: */
25:
26: #define OIOC_LOW 0100
27: #define OIOC_HIGH 0110
28:
29: /*
30: * Bits from COH286 sgttyb sg_flags field.
31: */
32: #define O_EVENP 0x0001 /* Allow even parity */
33: #define O_ODDP 0x0002 /* Allow odd parity */
34: #define O_CRMOD 0x0004 /* Map '\r' to '\n' */
35: #define O_ECHO 0x0008 /* Echo input characters */
36: #define O_LCASE 0x0010 /* Lowercase mapping on input */
37: #define O_CBREAK 0x0020 /* Each input character causes wakeup */
38: #define O_RAWIN 0x0040 /* 8-bit input raw */
39: #define O_RAWOUT 0x0080 /* 8-bit output raw */
40: #define O_TANDEM 0x0100 /* flow control protocol */
41: #define O_XTABS 0x0200 /* Expand tabs to spaces */
42: #define O_CRT 0x0400 /* CRT character erase */
43:
44: #define O_RAW (O_RAWIN|O_RAWOUT) /* Raw mode */
45:
46: /*
47: * Names for terminal speeds.
48: */
49: #define O_B0 0 /* Hangup if modem control enabled */
50: #define O_B50 1 /* 50 bps */
51: #define O_B75 2 /* 75 bps */
52: #define O_B110 3 /* 110 bps */
53: #define O_B134 4 /* 134.5 bps (IBM 2741) */
54: #define O_B150 5 /* 150 bps */
55: #define O_B200 6 /* 200 bps */
56: #define O_B300 7 /* 300 bps */
57: #define O_B600 8 /* 600 bps */
58: #define O_B1200 9 /* 1200 bps */
59: #define O_B1800 10 /* 1800 bps */
60: #define O_B2000 11 /* 2000 bps */
61: #define O_B2400 12 /* 2400 bps */
62: #define O_B3600 13 /* 3600 bps */
63: #define O_B4800 14 /* 4800 bps */
64: #define O_B7200 15 /* 7200 bps */
65: #define O_B9600 16 /* 9600 bps */
66: #define O_B19200 17 /* 19200 bps */
67: #define O_EXTA 18 /* External A (DH-11) */
68: #define O_EXTB 19 /* External B (DH-11) */
69:
70: /*
71: * ----------------------------------------------------------------------
72: * Functions.
73: * Import Functions.
74: * Export Functions.
75: * Local Functions.
76: */
77:
78: static void to_s5_sgfld();
79: static void to_s5speed();
80: static void to_coh_sgfld();
81: static void to_cohspeed();
82:
83: /*
84: * ----------------------------------------------------------------------
85: * Global Data.
86: * Import Variables.
87: * Export Variables.
88: * Local Variables.
89: */
90: /*
91: * Here are the COH286 values for tty ioctl's.
92: * In cvtsgtty[] below, subtract 0100 from the 286 COH ioctl value to
93: * index to the equivalent Sys V ioctl.
94: *
95: * OIOCSETP 0100 Terminal set modes (old stty)
96: * OIOCGETP 0101 Terminal get modes (old gtty)
97: * OIOCSETC 0102 Set characters
98: * OIOCGETC 0103 Get characters
99: * OIOCSETN 0104 Set modes w/o delay or out flush
100: * OIOCEXCL 0105 Set exclusive use
101: * OIOCNXCL 0106 Set non-exclusive use
102: * OIOCHPCL 0107 Hang up on last close
103: * OIOCFLUSH 0110 Flush characters in I/O queues
104: */
105: static unsigned short cvtsgtty[] = {
106: TIOCSETP,
107: TIOCGETP,
108: TIOCSETC,
109: TIOCGETC,
110: TIOCSETN,
111: TIOCEXCL,
112: TIOCNXCL,
113: TIOCHPCL,
114: TIOCFLUSH
115: };
116:
117: /*
118: * ----------------------------------------------------------------------
119: * Code.
120: */
121:
122: /*
123: * tioc()
124: *
125: * This function is called by dioctl() whenever a 286 binary does an ioctl().
126: * Its arguments are the arguments for to the ioctl, plus the local driver's
127: * ioctl function, which should support S5 sgtty and termio commands.
128: *
129: * 1. If com is COH 286 TIOC, translate it to S5 TIOC.
130: * 2. If translated com is TIOCSET[NP], convert sgttyb struct *vec to S5.
131: * 3. If translated com is TIOCGETP, point vec to a full S5 struct (COH 286
132: * sgttyb struct is 2 bytes shorter than S5 format).
133: * 4. Call driver's ioctl().
134: * 5. If just finished a converted TIOCGETP, convert back to COH 286 sgttyb.
135: */
136: void tioc(dev, com, vec, iocfn)
137: int dev, com, vec, (*iocfn)();
138: {
139: struct sgttyb sg;
140: int my_com = com, my_vec = vec, old_getp = 0;
141:
142: if (com >= OIOC_LOW && com <= OIOC_HIGH && u.u_error==0) {
143: my_com = cvtsgtty[com - OIOC_LOW];
144: if (my_com==TIOCSETP || my_com==TIOCSETN) {
145: ukcopy(vec, &sg, sizeof (struct sgttyb));
146: sg.sg_flags &= 0xffff;
147: to_s5_sgfld(&sg);
148: my_vec = &sg;
149: }
150: if (my_com==TIOCGETP) {
151: old_getp = 1;
152: my_vec = &sg;
153: }
154: }
155: (*iocfn)(dev, my_com, my_vec);
156: if (old_getp && u.u_error==0) {
157: to_coh_sgfld(my_vec);
158: kucopy(my_vec, vec, sizeof(struct sgttyb)-2);
159: }
160: }
161:
162: /*
163: * to_s5_sgfld()
164: *
165: * Convert fields in a sgttyb struct from COH 286 format to Sys 5.
166: */
167: static void to_s5_sgfld(sgp)
168: struct sgttyb * sgp;
169: {
170: unsigned int f = sgp->sg_flags, g = 0;
171:
172: /*
173: * Convert sg_ispeed and sg_ospeed.
174: */
175: to_s5speed(&(sgp->sg_ispeed));
176: to_s5speed(&(sgp->sg_ospeed));
177:
178: /*
179: * Convert sg_flags.
180: * f is old COH 286 flags.
181: * g is new Sys V flags.
182: */
183: if (f & O_EVENP)
184: g |= EVENP;
185: if (f & O_ODDP)
186: g |= ODDP;
187: if (f & O_CRMOD)
188: g |= CRMOD;
189: if (f & O_ECHO)
190: g |= ECHO;
191: if (f & O_LCASE)
192: g |= LCASE;
193: if (f & O_CBREAK)
194: g |= CBREAK; /* No CBREAK in Sys 5 sgtty. */
195: /* Only one RAW bit in Sys 5 sgtty. */
196: if ((f & O_RAWIN)&&(f & O_RAWOUT))
197: g |= RAW;
198: if (f & O_RAWIN)
199: g |= RAWIN;
200: if (f & O_RAWOUT)
201: g |= RAWOUT;
202: if (f & O_TANDEM)
203: g |= TANDEM; /* No TANDEM in Sys 5 sgtty. */
204: if (f & O_XTABS)
205: g |= XTABS;
206: if (f & O_CRT)
207: g |= CRT; /* No CRT in Sys 5 sgtty. */
208: sgp->sg_flags = g;
209: }
210:
211: /*
212: * to_s5speed()
213: *
214: * Convert speed from COH286 to Sys5.
215: * Here are the numbers:
216: * const. COH286 Sys5
217: * B0 0 0
218: * B50 1 1
219: * B75 2 2
220: * B110 3 3
221: * B134 4 4
222: * B150 5 5
223: * B200 6 6
224: * B300 7 7
225: * B600 8 8
226: * B1200 9 9
227: * B1800 10 10
228: * B2000 11 -
229: * B2400 12 11
230: * B3600 13 -
231: * B4800 14 12
232: * B7200 15 -
233: * B9600 16 13
234: * B19200 17 14
235: * EXTA 18 14
236: * EXTB 19 15
237: */
238: #define BADSPD 99
239:
240: static void to_s5speed(speed)
241: unsigned char *speed;
242: {
243: static char s5sp[]={B0,B50,B75,B110,B134,B150,B200,B300,B600,B1200,
244: B1800,BADSPD,B2400,BADSPD,B4800,BADSPD,B9600,EXTA,EXTA,EXTB};
245:
246: if (*speed >= sizeof(s5sp))
247: u.u_error = EINVAL;
248: else if (s5sp[*speed] == BADSPD)
249: u.u_error = EINVAL;
250: else *speed = s5sp[*speed];
251: }
252:
253: /*
254: * to_coh_sgfld()
255: *
256: * Convert fields in a sgttyb struct from Sys V format to COH 286.
257: */
258: static void to_coh_sgfld(sgp)
259: struct sgttyb * sgp;
260: {
261: unsigned int f = sgp->sg_flags, g = 0;
262:
263: /*
264: * Convert sg_ispeed and sg_ospeed.
265: */
266: to_cohspeed(&(sgp->sg_ispeed));
267: to_cohspeed(&(sgp->sg_ospeed));
268:
269: /*
270: * Convert sg_flags.
271: * f is old Sys V flags.
272: * g is new COH 286 flags.
273: */
274: if (f & EVENP)
275: g |= O_EVENP;
276: if (f & ODDP)
277: g |= O_ODDP;
278: if (f & CRMOD)
279: g |= O_CRMOD;
280: if (f & ECHO)
281: g |= O_ECHO;
282: if (f & LCASE)
283: g |= O_LCASE;
284: if (f & CBREAK)
285: g |= O_CBREAK; /* No CBREAK in Sys 5 sgtty. */
286: if (f & RAWIN) /* Only one RAW bit in Sys 5 sgtty. */
287: g |= O_RAWIN;
288: if (f & RAWOUT)
289: g |= O_RAWOUT;
290: if (f & TANDEM)
291: g |= O_TANDEM; /* No TANDEM in Sys 5 sgtty. */
292: if (f & XTABS)
293: g |= O_XTABS;
294: if (f & CRT)
295: g |= O_CRT; /* No CRT in Sys 5 sgtty. */
296: sgp->sg_flags = g;
297: }
298:
299: static void to_cohspeed(speed)
300: unsigned char *speed;
301: {
302: static char cohsp[]={O_B0,O_B50,O_B75,O_B110,O_B134,O_B150,O_B200,
303: O_B300,O_B600,O_B1200,O_B1800,O_B2400,O_B4800,O_B9600,O_EXTA,
304: O_EXTB};
305:
306: if (*speed >= sizeof(cohsp))
307: u.u_error = EINVAL;
308: else *speed = cohsp[*speed];
309: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.