1 /*- 2 * Copyright (c) 2011 Google, Inc. 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 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 24 * SUCH DAMAGE. 25 */ 26 27 #include <sys/cdefs.h> 28 __FBSDID("$FreeBSD$"); 29 30 #include <stand.h> 31 #include <sys/font.h> 32 #include "bootstrap.h" 33 #include "libuserboot.h" 34 35 int console; 36 37 static struct console *userboot_comconsp; 38 39 static void userboot_cons_probe(struct console *cp); 40 static int userboot_cons_init(int); 41 static void userboot_comcons_probe(struct console *cp); 42 static int userboot_comcons_init(int); 43 static void userboot_cons_putchar(int); 44 static int userboot_cons_getchar(void); 45 static int userboot_cons_poll(void); 46 47 struct console userboot_console = { 48 "userboot", 49 "userboot", 50 0, 51 userboot_cons_probe, 52 userboot_cons_init, 53 userboot_cons_putchar, 54 userboot_cons_getchar, 55 userboot_cons_poll, 56 }; 57 58 /* 59 * Provide a simple alias to allow loader scripts to set the 60 * console to comconsole without resulting in an error 61 */ 62 struct console userboot_comconsole = { 63 "comconsole", 64 "comconsole", 65 0, 66 userboot_comcons_probe, 67 userboot_comcons_init, 68 userboot_cons_putchar, 69 userboot_cons_getchar, 70 userboot_cons_poll, 71 }; 72 73 static void 74 userboot_cons_probe(struct console *cp) 75 { 76 77 cp->c_flags |= (C_PRESENTIN | C_PRESENTOUT); 78 } 79 80 static int 81 userboot_cons_init(int arg) 82 { 83 84 return (0); 85 } 86 87 static void 88 userboot_comcons_probe(struct console *cp) 89 { 90 91 /* 92 * Save the console pointer so the comcons_init routine 93 * can set the C_PRESENT* flags. They are not set 94 * here to allow the existing userboot console to 95 * be elected the default. 96 */ 97 userboot_comconsp = cp; 98 } 99 100 static int 101 userboot_comcons_init(int arg) 102 { 103 104 /* 105 * Set the C_PRESENT* flags to allow the comconsole 106 * to be selected as the active console 107 */ 108 userboot_comconsp->c_flags |= (C_PRESENTIN | C_PRESENTOUT); 109 return (0); 110 } 111 112 static void 113 userboot_cons_putchar(int c) 114 { 115 116 CALLBACK(putc, c); 117 } 118 119 static int 120 userboot_cons_getchar() 121 { 122 123 return (CALLBACK(getc)); 124 } 125 126 static int 127 userboot_cons_poll() 128 { 129 130 return (CALLBACK(poll)); 131 } 132