bsd-user: Add FreeBSD tty ioctl definitions
Add os-ioctl-ttycom.h with terminal control ioctl definitions including TARGET_TIOCGETA, TARGET_TIOCSETA, window size ioctls, and the target_termios structure for terminal I/O control. Signed-off-by: Stacey Son <sson@FreeBSD.org> Reviewed-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com> Signed-off-by: Warner Losh <imp@bsdimp.com>
Stacey Son committed
Mar 13, 2026 at 22:11 UTC
4ec26ae28a14897b179355a27baf64e501fcfad1
1 file changed
+239
bsd-user/freebsd/os-ioctl-ttycom.h
new
+239
@@ -0,0 +1,239 @@
1
+/*
2
+ * FreeBSD ttycom definitions for ioctl(2) emulation
3
+ *
4
+ * Copyright (c) 2013 Stacey D. Son
5
+ *
6
+ * SPDX-License-Identifier: GPL-2.0-or-later
7
+ */
8
+#ifndef BSD_USER_FREEBSD_OS_IOCTL_TTYCOM_H
9
+#define BSD_USER_FREEBSD_OS_IOCTL_TTYCOM_H
10
+
11
+#include "os-ioctl-ioccom.h"
12
+
13
+/* From sys/ttycom.h and sys/_termios.h */
14
+
15
+#define TARGET_VEOF 0 /* ICANON */
16
+#define TARGET_VEOL 1 /* ICANON */
17
+#define TARGET_VEOL2 2 /* ICANON together with IEXTEN */
18
+#define TARGET_VERASE 3 /* ICANON */
19
+#define TARGET_VWERASE 4 /* ICANON together with IEXTEN */
20
+#define TARGET_VKILL 5 /* ICANON */
21
+#define TARGET_VREPRINT 6 /* ICANON together with IEXTEN */
22
+#define TARGET_VERASE2 7 /* ICANON */
23
+#define TARGET_VINTR 8 /* ISIG */
24
+#define TARGET_VQUIT 9 /* ISIG */
25
+#define TARGET_VSUSP 10 /* ISIG */
26
+#define TARGET_VDSUSP 11 /* ISIG together with IEXTEN */
27
+#define TARGET_VSTART 12 /* IXON, IXOFF */
28
+#define TARGET_VSTOP 13 /* IXON, IXOFF */
29
+#define TARGET_VLNEXT 14 /* IEXTEN */
30
+#define TARGET_VDISCARD 15 /* IEXTEN */
31
+#define TARGET_VMIN 16 /* !ICANON */
32
+#define TARGET_VTIME 17 /* !ICANON */
33
+#define TARGET_VSTATUS 18 /* ICANON together with IEXTEN */
34
+/* 19 spare 2 */
35
+#define TARGET_NCCS 20
36
+
37
+/*
38
+ * Input flags - software input processing
39
+ */
40
+#define TARGET_IGNBRK 0x00000001 /* ignore BREAK condition */
41
+#define TARGET_BRKINT 0x00000002 /* map BREAK to SIGINTR */
42
+#define TARGET_IGNPAR 0x00000004 /* ignore (discard) parity errors */
43
+#define TARGET_PARMRK 0x00000008 /* mark parity and framing errors */
44
+#define TARGET_INPCK 0x00000010 /* enable checking of parity errors */
45
+#define TARGET_ISTRIP 0x00000020 /* strip 8th bit off chars */
46
+#define TARGET_INLCR 0x00000040 /* map NL into CR */
47
+#define TARGET_IGNCR 0x00000080 /* ignore CR */
48
+#define TARGET_ICRNL 0x00000100 /* map CR to NL (ala CRMOD) */
49
+#define TARGET_IXON 0x00000200 /* enable output flow control */
50
+#define TARGET_IXOFF 0x00000400 /* enable input flow control */
51
+#define TARGET_IXANY 0x00000800 /* any char will restart after stop */
52
+#define TARGET_IMAXBEL 0x00002000 /* ring bell on input queue full */
53
+#define TARGET_IUTF8 0x00004000 /* assume input is utf-8 encoded */
54
+
55
+/*
56
+ * Output flags - software output processing
57
+ */
58
+#define TARGET_OPOST 0x00000001 /* enable following output processing */
59
+#define TARGET_ONLCR 0x00000002 /* map NL to CR-NL (ala CRMOD) */
60
+#define TARGET_TABDLY 0x00000004 /* tab delay mask */
61
+#define TARGET_TAB0 0x00000000 /* no tab delay and expansion */
62
+#define TARGET_TAB3 0x00000004 /* expand tabs to spaces */
63
+#define TARGET_ONOEOT 0x00000008 /* discard EOT's (^D) on output) */
64
+#define TARGET_OCRNL 0x00000010 /* map CR to NL on output */
65
+#define TARGET_ONOCR 0x00000020 /* no CR output at column 0 */
66
+#define TARGET_ONLRET 0x00000040 /* NL performs CR function */
67
+
68
+/*
69
+ * Control flags - hardware control of terminal
70
+ */
71
+#define TARGET_CIGNORE 0x00000001 /* ignore control flags */
72
+#define TARGET_CSIZE 0x00000300 /* character size mask */
73
+#define TARGET_CS5 0x00000000 /* 5 bits (pseudo) */
74
+#define TARGET_CS6 0x00000100 /* 6 bits */
75
+#define TARGET_CS7 0x00000200 /* 7 bits */
76
+#define TARGET_CS8 0x00000300 /* 8 bits */
77
+#define TARGET_CSTOPB 0x00000400 /* send 2 stop bits */
78
+#define TARGET_CREAD 0x00000800 /* enable receiver */
79
+#define TARGET_PARENB 0x00001000 /* parity enable */
80
+#define TARGET_PARODD 0x00002000 /* odd parity, else even */
81
+#define TARGET_HUPCL 0x00004000 /* hang up on last close */
82
+#define TARGET_CLOCAL 0x00008000 /* ignore modem status lines */
83
+#define TARGET_CCTS_OFLOW 0x00010000 /* CTS flow control of output */
84
+#define TARGET_CRTSCTS (TARGET_CCTS_OFLOW | TARGET_CRTS_IFLOW)
85
+#define TARGET_CRTS_IFLOW 0x00020000 /* RTS flow control of input */
86
+#define TARGET_CDTR_IFLOW 0x00040000 /* DTR flow control of input */
87
+#define TARGET_CDSR_OFLOW 0x00080000 /* DSR flow control of output */
88
+#define TARGET_CCAR_OFLOW 0x00100000 /* DCD flow control of output */
89
+#define TARGET_CNO_RTSDTR 0x00200000 /* Do not assert RTS or DTR automatically */
90
+
91
+/*
92
+ * "Local" flags - dumping ground for other state
93
+ */
94
+#define TARGET_ECHOKE 0x00000001 /* visual erase for line kill */
95
+#define TARGET_ECHOE 0x00000002 /* visually erase chars */
96
+#define TARGET_ECHOK 0x00000004 /* echo NL after line kill */
97
+#define TARGET_ECHO 0x00000008 /* enable echoing */
98
+#define TARGET_ECHONL 0x00000010 /* echo NL even if ECHO is off */
99
+#define TARGET_ECHOPRT 0x00000020 /* visual erase mode for hardcopy */
100
+#define TARGET_ECHOCTL 0x00000040 /* echo control chars as ^(Char) */
101
+#define TARGET_ISIG 0x00000080 /* enable signals INTR, QUIT, [D]SUSP */
102
+#define TARGET_ICANON 0x00000100 /* canonicalize input lines */
103
+#define TARGET_ALTWERASE 0x00000200 /* use alternate WERASE algorithm */
104
+#define TARGET_IEXTEN 0x00000400 /* enable DISCARD and LNEXT */
105
+#define TARGET_EXTPROC 0x00000800 /* external processing */
106
+#define TARGET_TOSTOP 0x00400000 /* stop background jobs from output */
107
+#define TARGET_FLUSHO 0x00800000 /* output being flushed (state) */
108
+#define TARGET_NOKERNINFO 0x02000000 /* no kernel output from VSTATUS */
109
+#define TARGET_PENDIN 0x20000000 /* XXX retype pending input (state) */
110
+#define TARGET_NOFLSH 0x80000000 /* don't flush after interrupt */
111
+
112
+struct target_termios {
113
+ uint32_t c_iflag; /* input flags */
114
+ uint32_t c_oflag; /* output flags */
115
+ uint32_t c_cflag; /* control flags */
116
+ uint32_t c_lflag; /* local flags */
117
+ uint8_t c_cc[TARGET_NCCS]; /* control chars */
118
+ uint32_t c_ispeed; /* input speed */
119
+ uint32_t c_ospeed; /* output speed */
120
+};
121
+
122
+
123
+struct target_winsize {
124
+ uint16_t ws_row; /* rows, in characters */
125
+ uint16_t ws_col; /* columns, in characters */
126
+ uint16_t ws_xpixel; /* horizontal size, pixels */
127
+ uint16_t ws_ypixel; /* vertical size, pixels */
128
+};
129
+
130
+ /* 0-2 compat */
131
+ /* 3-7 unused */
132
+ /* 8-10 compat */
133
+ /* 11-12 unused */
134
+#define TARGET_TIOCEXCL TARGET_IO('t', 13) /* set exclusive use of tty */
135
+#define TARGET_TIOCNXCL TARGET_IO('t', 14) /* reset exclusive use of tty */
136
+#define TARGET_TIOCGPTN TARGET_IOR('t', 15, int) /* Get pts number. */
137
+#define TARGET_TIOCFLUSH TARGET_IOW('t', 16, int) /* flush buffers */
138
+ /* 17-18 compat */
139
+/* get termios struct */
140
+#define TARGET_TIOCGETA TARGET_IOR('t', 19, struct target_termios)
141
+/* set termios struct */
142
+#define TARGET_TIOCSETA TARGET_IOW('t', 20, struct target_termios)
143
+/* drain output, set */
144
+#define TARGET_TIOCSETAW TARGET_IOW('t', 21, struct target_termios)
145
+/* drn out, fls in, set */
146
+#define TARGET_TIOCSETAF TARGET_IOW('t', 22, struct target_termios)
147
+ /* 23-25 unused */
148
+#define TARGET_TIOCGETD TARGET_IOR('t', 26, int) /* get line discipline */
149
+#define TARGET_TIOCSETD TARGET_IOW('t', 27, int) /* set line discipline */
150
+#define TARGET_TIOCPTMASTER TARGET_IO('t', 28) /* pts master validation */
151
+ /* 29-85 unused */
152
+/* get ttywait timeout */
153
+#define TARGET_TIOCGDRAINWAIT TARGET_IOR('t', 86, int)
154
+/* set ttywait timeout */
155
+#define TARGET_TIOCSDRAINWAIT TARGET_IOW('t', 87, int)
156
+ /* 88 unused */
157
+ /* 89-91 conflicts: tun and tap */
158
+/* enable/get timestamp of last input event */
159
+#define TARGET_TIOCTIMESTAMP TARGET_IOR('t', 89, struct target_timeval)
160
+/* modem: get wait on close */
161
+#define TARGET_TIOCMGDTRWAIT TARGET_IOR('t', 90, int)
162
+/* modem: set wait on close */
163
+#define TARGET_TIOCMSDTRWAIT TARGET_IOW('t', 91, int)
164
+ /* 92-93 tun and tap */
165
+ /* 94-97 conflicts: tun and tap */
166
+/* wait till output drained */
167
+#define TARGET_TIOCDRAIN TARGET_IO('t', 94)
168
+ /* pty: generate signal */
169
+#define TARGET_TIOCSIG TARGET_IOWINT('t', 95)
170
+/* pty: external processing */
171
+#define TARGET_TIOCEXT TARGET_IOW('t', 96, int)
172
+/* become controlling tty */
173
+#define TARGET_TIOCSCTTY TARGET_IO('t', 97)
174
+/* become virtual console */
175
+#define TARGET_TIOCCONS TARGET_IOW('t', 98, int)
176
+/* get session id */
177
+#define TARGET_TIOCGSID TARGET_IOR('t', 99, int)
178
+ /* 100 unused */
179
+/* simulate ^T status message */
180
+#define TARGET_TIOCSTAT TARGET_IO('t', 101)
181
+ /* pty: set/clr usr cntl mode */
182
+#define TARGET_TIOCUCNTL TARGET_IOW('t', 102, int)
183
+/* usr cntl op "n" */
184
+#define TARGET_TIOCCMD(n) TARGET_IO('u', n)
185
+/* set window size */
186
+#define TARGET_TIOCSWINSZ TARGET_IOW('t', 103, struct target_winsize)
187
+/* get window size */
188
+#define TARGET_TIOCGWINSZ TARGET_IOR('t', 104, struct target_winsize)
189
+ /* 105 unused */
190
+/* get all modem bits */
191
+#define TARGET_TIOCMGET TARGET_IOR('t', 106, int)
192
+#define TARGET_TIOCM_LE 0001 /* line enable */
193
+#define TARGET_TIOCM_DTR 0002 /* data terminal ready */
194
+#define TARGET_TIOCM_RTS 0004 /* request to send */
195
+#define TARGET_TIOCM_ST 0010 /* secondary transmit */
196
+#define TARGET_TIOCM_SR 0020 /* secondary receive */
197
+#define TARGET_TIOCM_CTS 0040 /* clear to send */
198
+#define TARGET_TIOCM_DCD 0100 /* data carrier detect */
199
+#define TARGET_TIOCM_RI 0200 /* ring indicate */
200
+#define TARGET_TIOCM_DSR 0400 /* data set ready */
201
+#define TARGET_TIOCM_CD TARGET_TIOCM_DCD
202
+#define TARGET_TIOCM_CAR TARGET_TIOCM_DCD
203
+#define TARGET_TIOCM_RNG TARGET_TIOCM_RI
204
+#define TARGET_TIOCMBIC TARGET_IOW('t', 107, int) /* bic modem bits */
205
+#define TARGET_TIOCMBIS TARGET_IOW('t', 108, int) /* bis modem bits */
206
+#define TARGET_TIOCMSET TARGET_IOW('t', 109, int) /* set all modem bits */
207
+/* start output, like ^Q */
208
+#define TARGET_TIOCSTART TARGET_IO('t', 110)
209
+/* stop output, like ^S */
210
+#define TARGET_TIOCSTOP TARGET_IO('t', 111)
211
+/* pty: set/clear packet mode */
212
+#define TARGET_TIOCPKT TARGET_IOW('t', 112, int)
213
+#define TARGET_TIOCPKT_DATA 0x00 /* data packet */
214
+#define TARGET_TIOCPKT_FLUSHREAD 0x01 /* flush packet */
215
+#define TARGET_TIOCPKT_FLUSHWRITE 0x02 /* flush packet */
216
+#define TARGET_TIOCPKT_STOP 0x04 /* stop output */
217
+#define TARGET_TIOCPKT_START 0x08 /* start output */
218
+#define TARGET_TIOCPKT_NOSTOP 0x10 /* no more ^S, ^Q */
219
+#define TARGET_TIOCPKT_DOSTOP 0x20 /* now do ^S ^Q */
220
+#define TARGET_TIOCPKT_IOCTL 0x40 /* state change of pty driver */
221
+#define TARGET_TIOCNOTTY TARGET_IO('t', 113) /* void tty association */
222
+#define TARGET_TIOCSTI TARGET_IOW('t', 114, char) /* simulate terminal input */
223
+#define TARGET_TIOCOUTQ TARGET_IOR('t', 115, int) /* output queue size */
224
+ /* 116-117 compat */
225
+#define TARGET_TIOCSPGRP TARGET_IOW('t', 118, int) /* set pgrp of tty */
226
+#define TARGET_TIOCGPGRP TARGET_IOR('t', 119, int) /* get pgrp of tty */
227
+#define TARGET_TIOCCDTR TARGET_IO('t', 120) /* clear data terminal ready */
228
+#define TARGET_TIOCSDTR TARGET_IO('t', 121) /* set data terminal ready */
229
+#define TARGET_TIOCCBRK TARGET_IO('t', 122) /* clear break bit */
230
+#define TARGET_TIOCSBRK TARGET_IO('t', 123) /* set break bit */
231
+ /* 124-127 compat */
232
+
233
+#define TARGET_TTYDISC 0 /* termios tty line discipline */
234
+#define TARGET_SLIPDISC 4 /* serial IP discipline */
235
+#define TARGET_PPPDISC 5 /* PPP discipline */
236
+#define TARGET_NETGRAPHDISC 6 /* Netgraph tty node discipline */
237
+#define TARGET_H4DISC 7 /* Netgraph Bluetooth H4 discipline */
238
+
239
+#endif /* BSD_USER_FREEBSD_OS_IOCTL_TTYCOM_H */