2 * Copyright (C) 2012 Michael Brown <mbrown@fensystems.co.uk>.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 * You can also choose to distribute this program under the terms of
20 * the Unmodified Binary Distribution Licence (as given in the file
21 * COPYING.UBDL), provided that you have satisfied its requirements.
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
28 * VMware logfile console
33 #include <ipxe/console.h>
34 #include <ipxe/lineconsole.h>
35 #include <ipxe/init.h>
36 #include <ipxe/guestrpc.h>
37 #include <config/console.h>
39 /** VMware logfile console buffer size */
40 #define VMCONSOLE_BUFSIZE 128
42 /* Set default console usage if applicable */
43 #if ! ( defined ( CONSOLE_VMWARE ) && CONSOLE_EXPLICIT ( CONSOLE_VMWARE ) )
45 #define CONSOLE_VMWARE ( CONSOLE_USAGE_ALL & ~CONSOLE_USAGE_TUI )
48 /** VMware logfile console GuestRPC channel */
49 static int vmconsole_channel;
51 /** VMware logfile console line buffer */
54 char message[VMCONSOLE_BUFSIZE];
55 } vmconsole_buffer = {
59 /** VMware logfile console ANSI escape sequence handlers */
60 static struct ansiesc_handler vmconsole_handlers[] = {
64 /** VMware logfile line console */
65 static struct line_console vmconsole_line = {
66 .buffer = vmconsole_buffer.message,
67 .len = sizeof ( vmconsole_buffer.message ),
69 .handlers = vmconsole_handlers,
73 /** VMware logfile console recursion marker */
74 static int vmconsole_entered;
77 * Print a character to VMware logfile console
79 * @v character Character to be printed
81 static void vmconsole_putchar ( int character ) {
84 /* Ignore if we are already mid-logging */
85 if ( vmconsole_entered )
88 /* Fill line buffer */
89 if ( line_putchar ( &vmconsole_line, character ) == 0 )
92 /* Guard against re-entry */
93 vmconsole_entered = 1;
95 /* Send log message */
96 if ( ( rc = guestrpc_command ( vmconsole_channel,
97 vmconsole_buffer.prefix, NULL, 0 ) ) <0){
98 DBG ( "VMware console could not send log message: %s\n",
102 /* Clear re-entry flag */
103 vmconsole_entered = 0;
106 /** VMware logfile console driver */
107 struct console_driver vmconsole __console_driver = {
108 .putchar = vmconsole_putchar,
109 .disabled = CONSOLE_DISABLED,
110 .usage = CONSOLE_VMWARE,
114 * Initialise VMware logfile console
117 static void vmconsole_init ( void ) {
120 /* Attempt to open console */
121 vmconsole_channel = guestrpc_open();
122 if ( vmconsole_channel < 0 ) {
123 rc = vmconsole_channel;
124 DBG ( "VMware console could not be initialised: %s\n",
129 /* Mark console as available */
130 vmconsole.disabled = 0;
134 * VMware logfile console initialisation function
136 struct init_fn vmconsole_init_fn __init_fn ( INIT_CONSOLE ) = {
137 .initialise = vmconsole_init,