]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - stand/kboot/hostcons.c
MFV: xz 5.4.1.
[FreeBSD/FreeBSD.git] / stand / kboot / hostcons.c
1 /*-
2  * Copyright (C) 2014 Nathan Whitehorn
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
18  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
21  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
22  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
23  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #include <sys/cdefs.h>
27 __FBSDID("$FreeBSD$");
28
29 #include <sys/types.h>
30 #include "bootstrap.h"
31 #include "host_syscall.h"
32 #include "termios.h"
33
34 static void hostcons_probe(struct console *cp);
35 static int hostcons_init(int arg);
36 static void hostcons_putchar(int c);
37 static int hostcons_getchar(void);
38 static int hostcons_poll(void);
39
40 struct console hostconsole = {
41         "host",
42         "Host Console",
43         0,
44         hostcons_probe,
45         hostcons_init,
46         hostcons_putchar,
47         hostcons_getchar,
48         hostcons_poll,
49 };
50
51 static struct host_termios old_settings;
52
53 static void
54 hostcons_probe(struct console *cp)
55 {
56
57         cp->c_flags |= C_PRESENTIN|C_PRESENTOUT;
58 }
59
60 static int
61 hostcons_init(int arg)
62 {
63         struct host_termios new_settings;
64
65         host_tcgetattr(0, &old_settings);
66         new_settings = old_settings;
67         host_cfmakeraw(&new_settings);
68         host_tcsetattr(0, HOST_TCSANOW, &new_settings);
69
70         return (0);
71 }
72
73 static void
74 hostcons_putchar(int c)
75 {
76         uint8_t ch = c;
77
78         host_write(1, &ch, 1);
79 }
80
81 static int
82 hostcons_getchar(void)
83 {
84         uint8_t ch;
85         int rv;
86
87         rv = host_read(0, &ch, 1);
88         if (rv == 1)
89                 return (ch);
90         return (-1);
91 }
92
93 static int
94 hostcons_poll(void)
95 {
96         struct host_timeval tv = {0,0};
97         long fds = 1 << 0;
98         int ret;
99
100         ret = host_select(32, &fds, NULL, NULL, &tv);
101         return (ret > 0);
102 }