2 * Copyright (c) 1998 Michael Smith <msmith@freebsd.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * $FreeBSD: src/sys/boot/common/console.c,v 1.5 1999/08/28 00:39:46 peter Exp $
32 #include "bootstrap.h"
34 * Core console support
37 static int cons_set(struct env_var *ev, int flags, void *value);
38 static int cons_find(char *name);
41 * Detect possible console(s) to use. The first probed console
42 * is marked active. Also create the console variable.
44 * XXX Add logic for multiple console support.
53 /* Do all console probes */
54 for (cons = 0; consoles[cons] != NULL; cons++) {
55 consoles[cons]->c_flags = 0;
56 consoles[cons]->c_probe(consoles[cons]);
58 /* Now find the first working one */
60 for (cons = 0; consoles[cons] != NULL && active == -1; cons++) {
61 consoles[cons]->c_flags = 0;
62 consoles[cons]->c_probe(consoles[cons]);
63 if (consoles[cons]->c_flags == (C_PRESENTIN | C_PRESENTOUT))
67 /* Check to see if a console preference has already been registered */
68 prefconsole = getenv("console");
69 if (prefconsole != NULL)
70 prefconsole = strdup(prefconsole);
71 if (prefconsole != NULL) {
72 unsetenv("console"); /* we want to replace this */
73 for (cons = 0; consoles[cons] != NULL; cons++)
74 /* look for the nominated console, use it if it's functional */
75 if (!strcmp(prefconsole, consoles[cons]->c_name) &&
76 (consoles[cons]->c_flags == (C_PRESENTIN | C_PRESENTOUT)))
82 consoles[active]->c_flags |= (C_ACTIVEIN | C_ACTIVEOUT);
83 consoles[active]->c_init(0);
85 printf("Console: %s\n", consoles[active]->c_desc);
86 env_setenv("console", EV_VOLATILE, consoles[active]->c_name, cons_set,
96 /* Loop forever polling all active consoles */
98 for (cons = 0; consoles[cons] != NULL; cons++)
99 if ((consoles[cons]->c_flags & C_ACTIVEIN) &&
100 ((rv = consoles[cons]->c_in()) != -1))
109 for (cons = 0; consoles[cons] != NULL; cons++)
110 if ((consoles[cons]->c_flags & C_ACTIVEIN) &&
111 (consoles[cons]->c_ready() != 0))
121 /* Expand newlines */
125 for (cons = 0; consoles[cons] != NULL; cons++)
126 if (consoles[cons]->c_flags & C_ACTIVEOUT)
127 consoles[cons]->c_out(c);
131 cons_find(char *name)
135 for (cons = 0; consoles[cons] != NULL; cons++)
136 if (!strcmp(consoles[cons]->c_name, name))
145 * XXX Note that the console system design allows for some extension
146 * here (eg. multiple consoles, input/output only, etc.)
149 cons_set(struct env_var *ev, int flags, void *value)
153 if ((value == NULL) || ((active = cons_find(value)) == -1)) {
155 printf("no such console '%s'\n", (char *)value);
156 printf("Available consoles:\n");
157 for (cons = 0; consoles[cons] != NULL; cons++)
158 printf(" %s\n", consoles[cons]->c_name);
162 /* disable all current consoles */
163 for (cons = 0; consoles[cons] != NULL; cons++)
164 consoles[cons]->c_flags &= ~(C_ACTIVEIN | C_ACTIVEOUT);
166 /* enable selected console */
167 consoles[active]->c_flags |= C_ACTIVEIN | C_ACTIVEOUT;
168 consoles[active]->c_init(0);
170 env_setenv(ev->ev_name, flags | EV_NOHOOK, value, NULL, NULL);