4 * Copyright (c) 2009 Antti Kantee. All Rights Reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
16 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * Experimental proof-of-concept program:
31 * tip-on-booze. Uses rump kernel for ucom driver + underlying
32 * hardware. Just shovels bits back and forth between the user
33 * terminal and the ucom device.
35 * Seems to drop an occasional character for output here and there.
36 * Haven't pinpointed the problem yet. It happens commonly for certain
37 * patterns such as ctrl-U followed by immediate typing. Tipsy is quite
38 * sober despite this "feature".
41 #include <sys/types.h>
42 #include <sys/ioctl.h>
44 #include <rump/rump.h>
45 #include <rump/rump_syscalls.h>
58 * We use a shovel thread to get the bits from the rump kernel and
59 * print them on the terminal. The reason for a thread instead of
60 * polling is that we currently have no way to poll two fd's when
61 * they are in different kernels (stdin in the host, ucom in rump).
68 int fd
= (int)(intptr_t)arg
;
71 n
= rump_sys_read(fd
, buf
, sizeof(buf
));
72 if (__predict_false(n
<= 0)) {
78 if (write(STDOUT_FILENO
, buf
, n
) != n
)
79 err(1, "write to console");
84 main(int argc
, char *argv
[])
92 if (argc
== 2 && strcmp(argv
[1], "probe") == 0) {
95 fprintf(stderr
, "mind the usage\n");
101 rump_boot_sethowto(RUMP_AB_VERBOSE
);
106 com
= rump_sys_open("/dev/dtyU0", O_RDWR
);
108 err(1, "rump ucom open failed");
111 * Setup the com port. You might need to tweak this.
113 if (rump_sys_ioctl(com
, TIOCGETA
, &tios
) == -1)
114 err(1, "rump get term");
115 tios
.c_cflag
&= ~(CSIZE
|PARENB
);
117 tios
.c_cflag
|= CLOCAL
;
118 tios
.c_iflag
&= ~(ISTRIP
|ICRNL
);
119 tios
.c_oflag
&= ~OPOST
;
120 tios
.c_lflag
&= ~(ICANON
|ISIG
|IEXTEN
|ECHO
);
122 tios
.c_cc
[VTIME
] = 0;
123 if (rump_sys_ioctl(com
, TIOCSETA
, &tios
) == -1)
124 err(1, "rump set term");
127 if (tcgetattr(STDIN_FILENO
, &tios
) == -1)
128 err(1, "host get term");
129 tios
.c_oflag
&= ~OPOST
;
130 tios
.c_iflag
&= ~(INPCK
|ICRNL
);
131 tios
.c_lflag
&= ~(ICANON
|IEXTEN
|ECHO
);
132 tios
.c_cc
[VINTR
] = tios
.c_cc
[VQUIT
] = tios
.c_cc
[VSUSP
]
133 = tios
.c_cc
[VDSUSP
] = tios
.c_cc
[VDISCARD
] = tios
.c_cc
[VREPRINT
]
134 = tios
.c_cc
[VLNEXT
] = _POSIX_VDISABLE
;
136 tios
.c_cc
[VTIME
] = 0;
137 if (tcsetattr(STDIN_FILENO
, TCSADRAIN
, &tios
) == -1)
138 err(1, "host set term");
140 if (pthread_create(&pt
, NULL
, shovel
, (void *)(intptr_t)com
) == -1)
141 err(1, "pthread create");
143 /* read stdin, feed that into the rump kernel */
148 if (rump_sys_write(com
, &ch
, 1) != 1)
149 err(1, "rump write");