Mon Dec 12 16:39:16 2011 UTC ()
make sure to set O_ASYNC on stdin to enable ttycons "interrupts"


(jmcneill)
diff -r1.9 -r1.10 src/sys/arch/usermode/dev/ttycons.c
diff -r1.36 -r1.37 src/sys/arch/usermode/include/thunk.h
diff -r1.41 -r1.42 src/sys/arch/usermode/usermode/thunk.c

cvs diff -r1.9 -r1.10 src/sys/arch/usermode/dev/ttycons.c (expand / switch to unified diff)

--- src/sys/arch/usermode/dev/ttycons.c 2011/12/12 16:06:15 1.9
+++ src/sys/arch/usermode/dev/ttycons.c 2011/12/12 16:39:16 1.10
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ttycons.c,v 1.9 2011/12/12 16:06:15 jmcneill Exp $ */ 1/* $NetBSD: ttycons.c,v 1.10 2011/12/12 16:39:16 jmcneill Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2007 Jared D. McNeill <jmcneill@invisible.ca> 4 * Copyright (c) 2007 Jared D. McNeill <jmcneill@invisible.ca>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -17,27 +17,27 @@ @@ -17,27 +17,27 @@
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29#include <sys/cdefs.h> 29#include <sys/cdefs.h>
30__KERNEL_RCSID(0, "$NetBSD: ttycons.c,v 1.9 2011/12/12 16:06:15 jmcneill Exp $"); 30__KERNEL_RCSID(0, "$NetBSD: ttycons.c,v 1.10 2011/12/12 16:39:16 jmcneill Exp $");
31 31
32#include <sys/param.h> 32#include <sys/param.h>
33#include <sys/conf.h> 33#include <sys/conf.h>
34#include <sys/proc.h> 34#include <sys/proc.h>
35#include <sys/systm.h> 35#include <sys/systm.h>
36#include <sys/device.h> 36#include <sys/device.h>
37#include <sys/kauth.h> 37#include <sys/kauth.h>
38#include <sys/termios.h> 38#include <sys/termios.h>
39#include <sys/tty.h> 39#include <sys/tty.h>
40 40
41#include <dev/cons.h> 41#include <dev/cons.h>
42 42
43#include <machine/mainbus.h> 43#include <machine/mainbus.h>
@@ -126,26 +126,28 @@ ttycons_attach(device_t parent, device_t @@ -126,26 +126,28 @@ ttycons_attach(device_t parent, device_t
126 sc->sc_tty->t_oproc = ttycons_start; 126 sc->sc_tty->t_oproc = ttycons_start;
127 sc->sc_tty->t_param = ttycons_param; 127 sc->sc_tty->t_param = ttycons_param;
128 128
129 maj = cdevsw_lookup_major(&ttycons_cdevsw); 129 maj = cdevsw_lookup_major(&ttycons_cdevsw);
130 cn_tab->cn_dev = makedev(maj, device_unit(self)); 130 cn_tab->cn_dev = makedev(maj, device_unit(self));
131 sc->sc_tty->t_dev = cn_tab->cn_dev; 131 sc->sc_tty->t_dev = cn_tab->cn_dev;
132 132
133 sc->sc_rd_sih = softint_establish(SOFTINT_SERIAL, 133 sc->sc_rd_sih = softint_establish(SOFTINT_SERIAL,
134 ttycons_softintr, sc); 134 ttycons_softintr, sc);
135 if (sc->sc_rd_sih == NULL) 135 if (sc->sc_rd_sih == NULL)
136 panic("couldn't establish ttycons softint handler\n"); 136 panic("couldn't establish ttycons softint handler\n");
137 137
138 thunk_signal(SIGIO, ttycons_intr); 138 thunk_signal(SIGIO, ttycons_intr);
 139 if (thunk_set_stdin_sigio(true) != 0)
 140 panic("couldn't enable stdin async mode");
139} 141}
140 142
141void 143void
142ttycons_consinit(void) 144ttycons_consinit(void)
143{ 145{
144 struct thunk_termios t; 146 struct thunk_termios t;
145 147
146 thunk_tcgetattr(0, &t); 148 thunk_tcgetattr(0, &t);
147 t.c_lflag &= ~(ECHO|ICANON); 149 t.c_lflag &= ~(ECHO|ICANON);
148 t.c_cc[VTIME] = 0; 150 t.c_cc[VTIME] = 0;
149 t.c_cc[VMIN] = 1; 151 t.c_cc[VMIN] = 1;
150 thunk_tcsetattr(0, TCSANOW, &t); 152 thunk_tcsetattr(0, TCSANOW, &t);
151 153

cvs diff -r1.36 -r1.37 src/sys/arch/usermode/include/thunk.h (expand / switch to unified diff)

--- src/sys/arch/usermode/include/thunk.h 2011/12/11 22:33:49 1.36
+++ src/sys/arch/usermode/include/thunk.h 2011/12/12 16:39:16 1.37
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: thunk.h,v 1.36 2011/12/11 22:33:49 jmcneill Exp $ */ 1/* $NetBSD: thunk.h,v 1.37 2011/12/12 16:39:16 jmcneill Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2011 Jared D. McNeill <jmcneill@invisible.ca> 4 * Copyright (c) 2011 Jared D. McNeill <jmcneill@invisible.ca>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -82,26 +82,27 @@ void thunk_abort(void); @@ -82,26 +82,27 @@ void thunk_abort(void);
82 82
83int thunk_geterrno(void); 83int thunk_geterrno(void);
84void thunk_seterrno(int err); 84void thunk_seterrno(int err);
85 85
86int thunk_getcontext(ucontext_t *); 86int thunk_getcontext(ucontext_t *);
87int thunk_setcontext(const ucontext_t *); 87int thunk_setcontext(const ucontext_t *);
88void thunk_makecontext(ucontext_t *ucp, void (*func)(void),  88void thunk_makecontext(ucontext_t *ucp, void (*func)(void),
89 int nargs, void *arg1, void *arg2, void *arg3); 89 int nargs, void *arg1, void *arg2, void *arg3);
90int thunk_swapcontext(ucontext_t *, ucontext_t *); 90int thunk_swapcontext(ucontext_t *, ucontext_t *);
91 91
92int thunk_tcgetattr(int, struct thunk_termios *); 92int thunk_tcgetattr(int, struct thunk_termios *);
93int thunk_tcsetattr(int, int, const struct thunk_termios *); 93int thunk_tcsetattr(int, int, const struct thunk_termios *);
94 94
 95int thunk_set_stdin_sigio(int);
95int thunk_pollchar(void); 96int thunk_pollchar(void);
96int thunk_getchar(void); 97int thunk_getchar(void);
97void thunk_putchar(int); 98void thunk_putchar(int);
98 99
99int thunk_execv(const char *, char * const []); 100int thunk_execv(const char *, char * const []);
100 101
101int thunk_open(const char *, int, mode_t); 102int thunk_open(const char *, int, mode_t);
102int thunk_fstat_getsize(int, ssize_t *, ssize_t *); 103int thunk_fstat_getsize(int, ssize_t *, ssize_t *);
103ssize_t thunk_pread(int, void *, size_t, off_t); 104ssize_t thunk_pread(int, void *, size_t, off_t);
104ssize_t thunk_pwrite(int, const void *, size_t, off_t); 105ssize_t thunk_pwrite(int, const void *, size_t, off_t);
105int thunk_fsync(int); 106int thunk_fsync(int);
106int thunk_mkstemp(char *); 107int thunk_mkstemp(char *);
107int thunk_unlink(const char *); 108int thunk_unlink(const char *);

cvs diff -r1.41 -r1.42 src/sys/arch/usermode/usermode/thunk.c (expand / switch to unified diff)

--- src/sys/arch/usermode/usermode/thunk.c 2011/12/11 22:33:49 1.41
+++ src/sys/arch/usermode/usermode/thunk.c 2011/12/12 16:39:16 1.42
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: thunk.c,v 1.41 2011/12/11 22:33:49 jmcneill Exp $ */ 1/* $NetBSD: thunk.c,v 1.42 2011/12/12 16:39:16 jmcneill Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2011 Jared D. McNeill <jmcneill@invisible.ca> 4 * Copyright (c) 2011 Jared D. McNeill <jmcneill@invisible.ca>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -18,27 +18,27 @@ @@ -18,27 +18,27 @@
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29#include <sys/cdefs.h> 29#include <sys/cdefs.h>
30#ifdef __NetBSD__ 30#ifdef __NetBSD__
31__RCSID("$NetBSD: thunk.c,v 1.41 2011/12/11 22:33:49 jmcneill Exp $"); 31__RCSID("$NetBSD: thunk.c,v 1.42 2011/12/12 16:39:16 jmcneill Exp $");
32#endif 32#endif
33 33
34#include <sys/types.h> 34#include <sys/types.h>
35#include <sys/mman.h> 35#include <sys/mman.h>
36#include <sys/reboot.h> 36#include <sys/reboot.h>
37#include <sys/poll.h> 37#include <sys/poll.h>
38#include <machine/vmparam.h> 38#include <machine/vmparam.h>
39 39
40#include <aio.h> 40#include <aio.h>
41#include <assert.h> 41#include <assert.h>
42#include <errno.h> 42#include <errno.h>
43#include <fcntl.h> 43#include <fcntl.h>
44#include <stdarg.h> 44#include <stdarg.h>
@@ -311,26 +311,41 @@ thunk_tcgetattr(int fd, struct thunk_ter @@ -311,26 +311,41 @@ thunk_tcgetattr(int fd, struct thunk_ter
311 return 0; 311 return 0;
312} 312}
313 313
314int 314int
315thunk_tcsetattr(int fd, int action, const struct thunk_termios *tt) 315thunk_tcsetattr(int fd, int action, const struct thunk_termios *tt)
316{ 316{
317 struct termios t; 317 struct termios t;
318 318
319 thunk_to_termios(tt, &t); 319 thunk_to_termios(tt, &t);
320 return tcsetattr(fd, action, &t); 320 return tcsetattr(fd, action, &t);
321} 321}
322 322
323int 323int
 324thunk_set_stdin_sigio(int onoff)
 325{
 326 int flags;
 327
 328 flags = fcntl(STDIN_FILENO, F_GETFL, 0);
 329
 330 if (onoff)
 331 flags |= O_ASYNC;
 332 else
 333 flags &= ~O_ASYNC;
 334
 335 return fcntl(STDIN_FILENO, F_SETFL, flags);
 336}
 337
 338int
324thunk_pollchar(void) 339thunk_pollchar(void)
325{ 340{
326 struct pollfd fds[1]; 341 struct pollfd fds[1];
327 342
328 fds[0].fd = STDIN_FILENO; 343 fds[0].fd = STDIN_FILENO;
329 fds[0].events = POLLIN; 344 fds[0].events = POLLIN;
330 fds[0].revents = 0; 345 fds[0].revents = 0;
331 346
332 if (poll(fds, __arraycount(fds), 0) > 0) { 347 if (poll(fds, __arraycount(fds), 0) > 0) {
333 if (fds[0].revents & POLLIN) { 348 if (fds[0].revents & POLLIN) {
334 return getchar(); 349 return getchar();
335 } 350 }
336 } 351 }