blob: ef527211f8a89a3a6e1e90cd44b7ddb753ef6483 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* $Id: termios.h,v 1.11 2001/06/01 08:12:11 davem Exp $ */
2#ifndef _SPARC64_TERMIOS_H
3#define _SPARC64_TERMIOS_H
4
5#include <asm/ioctls.h>
6#include <asm/termbits.h>
7
8#if defined(__KERNEL__) || defined(__DEFINE_BSD_TERMIOS)
9struct sgttyb {
10 char sg_ispeed;
11 char sg_ospeed;
12 char sg_erase;
13 char sg_kill;
14 short sg_flags;
15};
16
17struct tchars {
18 char t_intrc;
19 char t_quitc;
20 char t_startc;
21 char t_stopc;
22 char t_eofc;
23 char t_brkc;
24};
25
26struct ltchars {
27 char t_suspc;
28 char t_dsuspc;
29 char t_rprntc;
30 char t_flushc;
31 char t_werasc;
32 char t_lnextc;
33};
34#endif /* __KERNEL__ */
35
36struct sunos_ttysize {
37 int st_lines; /* Lines on the terminal */
38 int st_columns; /* Columns on the terminal */
39};
40
Linus Torvalds1da177e2005-04-16 15:20:36 -070041struct winsize {
42 unsigned short ws_row;
43 unsigned short ws_col;
44 unsigned short ws_xpixel;
45 unsigned short ws_ypixel;
46};
47
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#ifdef __KERNEL__
49#include <linux/module.h>
50
51/*
52 * c_cc characters in the termio structure. Oh, how I love being
53 * backwardly compatible. Notice that character 4 and 5 are
54 * interpreted differently depending on whether ICANON is set in
55 * c_lflag. If it's set, they are used as _VEOF and _VEOL, otherwise
56 * as _VMIN and V_TIME. This is for compatibility with OSF/1 (which
57 * is compatible with sysV)...
58 */
59#define _VMIN 4
60#define _VTIME 5
61
62/* intr=^C quit=^\ erase=del kill=^U
63 eof=^D eol=\0 eol2=\0 sxtc=\0
64 start=^Q stop=^S susp=^Z dsusp=^Y
65 reprint=^R discard=^U werase=^W lnext=^V
66 vmin=\1 vtime=\0
67*/
68#define INIT_C_CC "\003\034\177\025\004\000\000\000\021\023\032\031\022\025\027\026\001"
69
70/*
71 * Translate a "termio" structure into a "termios". Ugh.
72 */
73#define user_termio_to_kernel_termios(termios, termio) \
74({ \
75 unsigned short tmp; \
David S. Millere55c57e2005-06-24 20:11:03 -070076 int err; \
77 err = get_user(tmp, &(termio)->c_iflag); \
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 (termios)->c_iflag = (0xffff0000 & ((termios)->c_iflag)) | tmp; \
David S. Millere55c57e2005-06-24 20:11:03 -070079 err |= get_user(tmp, &(termio)->c_oflag); \
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 (termios)->c_oflag = (0xffff0000 & ((termios)->c_oflag)) | tmp; \
David S. Millere55c57e2005-06-24 20:11:03 -070081 err |= get_user(tmp, &(termio)->c_cflag); \
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 (termios)->c_cflag = (0xffff0000 & ((termios)->c_cflag)) | tmp; \
David S. Millere55c57e2005-06-24 20:11:03 -070083 err |= get_user(tmp, &(termio)->c_lflag); \
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 (termios)->c_lflag = (0xffff0000 & ((termios)->c_lflag)) | tmp; \
David S. Millere55c57e2005-06-24 20:11:03 -070085 err |= copy_from_user((termios)->c_cc, (termio)->c_cc, NCC); \
86 err; \
Linus Torvalds1da177e2005-04-16 15:20:36 -070087})
88
89/*
90 * Translate a "termios" structure into a "termio". Ugh.
91 *
92 * Note the "fun" _VMIN overloading.
93 */
94#define kernel_termios_to_user_termio(termio, termios) \
95({ \
David S. Millere55c57e2005-06-24 20:11:03 -070096 int err; \
97 err = put_user((termios)->c_iflag, &(termio)->c_iflag); \
98 err |= put_user((termios)->c_oflag, &(termio)->c_oflag); \
99 err |= put_user((termios)->c_cflag, &(termio)->c_cflag); \
100 err |= put_user((termios)->c_lflag, &(termio)->c_lflag); \
101 err |= put_user((termios)->c_line, &(termio)->c_line); \
102 err |= copy_to_user((termio)->c_cc, (termios)->c_cc, NCC); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 if (!((termios)->c_lflag & ICANON)) { \
David S. Millere55c57e2005-06-24 20:11:03 -0700104 err |= put_user((termios)->c_cc[VMIN], &(termio)->c_cc[_VMIN]); \
105 err |= put_user((termios)->c_cc[VTIME], &(termio)->c_cc[_VTIME]); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 } \
David S. Millere55c57e2005-06-24 20:11:03 -0700107 err; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108})
109
110#define user_termios_to_kernel_termios(k, u) \
111({ \
David S. Millere55c57e2005-06-24 20:11:03 -0700112 int err; \
113 err = get_user((k)->c_iflag, &(u)->c_iflag); \
114 err |= get_user((k)->c_oflag, &(u)->c_oflag); \
115 err |= get_user((k)->c_cflag, &(u)->c_cflag); \
116 err |= get_user((k)->c_lflag, &(u)->c_lflag); \
117 err |= get_user((k)->c_line, &(u)->c_line); \
118 err |= copy_from_user((k)->c_cc, (u)->c_cc, NCCS); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 if((k)->c_lflag & ICANON) { \
David S. Millere55c57e2005-06-24 20:11:03 -0700120 err |= get_user((k)->c_cc[VEOF], &(u)->c_cc[VEOF]); \
121 err |= get_user((k)->c_cc[VEOL], &(u)->c_cc[VEOL]); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 } else { \
David S. Millere55c57e2005-06-24 20:11:03 -0700123 err |= get_user((k)->c_cc[VMIN], &(u)->c_cc[_VMIN]); \
124 err |= get_user((k)->c_cc[VTIME], &(u)->c_cc[_VTIME]); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 } \
David Miller6050afb2007-10-17 19:38:10 -0700126 err |= get_user((k)->c_ispeed, &(u)->c_ispeed); \
127 err |= get_user((k)->c_ospeed, &(u)->c_ospeed); \
David S. Millere55c57e2005-06-24 20:11:03 -0700128 err; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129})
130
131#define kernel_termios_to_user_termios(u, k) \
132({ \
David S. Millere55c57e2005-06-24 20:11:03 -0700133 int err; \
134 err = put_user((k)->c_iflag, &(u)->c_iflag); \
135 err |= put_user((k)->c_oflag, &(u)->c_oflag); \
136 err |= put_user((k)->c_cflag, &(u)->c_cflag); \
137 err |= put_user((k)->c_lflag, &(u)->c_lflag); \
138 err |= put_user((k)->c_line, &(u)->c_line); \
139 err |= copy_to_user((u)->c_cc, (k)->c_cc, NCCS); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 if(!((k)->c_lflag & ICANON)) { \
David S. Millere55c57e2005-06-24 20:11:03 -0700141 err |= put_user((k)->c_cc[VMIN], &(u)->c_cc[_VMIN]); \
142 err |= put_user((k)->c_cc[VTIME], &(u)->c_cc[_VTIME]); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 } else { \
David S. Millere55c57e2005-06-24 20:11:03 -0700144 err |= put_user((k)->c_cc[VEOF], &(u)->c_cc[VEOF]); \
145 err |= put_user((k)->c_cc[VEOL], &(u)->c_cc[VEOL]); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 } \
David Miller6050afb2007-10-17 19:38:10 -0700147 err |= put_user((k)->c_ispeed, &(u)->c_ispeed); \
148 err |= put_user((k)->c_ospeed, &(u)->c_ospeed); \
149 err; \
150})
151
152#define user_termios_to_kernel_termios_1(k, u) \
153({ \
154 int err; \
155 err = get_user((k)->c_iflag, &(u)->c_iflag); \
156 err |= get_user((k)->c_oflag, &(u)->c_oflag); \
157 err |= get_user((k)->c_cflag, &(u)->c_cflag); \
158 err |= get_user((k)->c_lflag, &(u)->c_lflag); \
159 err |= get_user((k)->c_line, &(u)->c_line); \
160 err |= copy_from_user((k)->c_cc, (u)->c_cc, NCCS); \
161 if((k)->c_lflag & ICANON) { \
162 err |= get_user((k)->c_cc[VEOF], &(u)->c_cc[VEOF]); \
163 err |= get_user((k)->c_cc[VEOL], &(u)->c_cc[VEOL]); \
164 } else { \
165 err |= get_user((k)->c_cc[VMIN], &(u)->c_cc[_VMIN]); \
166 err |= get_user((k)->c_cc[VTIME], &(u)->c_cc[_VTIME]); \
167 } \
168 err; \
169})
170
171#define kernel_termios_to_user_termios_1(u, k) \
172({ \
173 int err; \
174 err = put_user((k)->c_iflag, &(u)->c_iflag); \
175 err |= put_user((k)->c_oflag, &(u)->c_oflag); \
176 err |= put_user((k)->c_cflag, &(u)->c_cflag); \
177 err |= put_user((k)->c_lflag, &(u)->c_lflag); \
178 err |= put_user((k)->c_line, &(u)->c_line); \
179 err |= copy_to_user((u)->c_cc, (k)->c_cc, NCCS); \
180 if(!((k)->c_lflag & ICANON)) { \
181 err |= put_user((k)->c_cc[VMIN], &(u)->c_cc[_VMIN]); \
182 err |= put_user((k)->c_cc[VTIME], &(u)->c_cc[_VTIME]); \
183 } else { \
184 err |= put_user((k)->c_cc[VEOF], &(u)->c_cc[VEOF]); \
185 err |= put_user((k)->c_cc[VEOL], &(u)->c_cc[VEOL]); \
186 } \
David S. Millere55c57e2005-06-24 20:11:03 -0700187 err; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188})
189
190#endif /* __KERNEL__ */
191
192#endif /* _SPARC64_TERMIOS_H */