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
20 FILE_LICENCE ( GPL2_OR_LATER );
24 * VMware logfile console
29 #include <ipxe/console.h>
30 #include <ipxe/lineconsole.h>
31 #include <ipxe/init.h>
32 #include <ipxe/guestrpc.h>
33 #include <config/console.h>
35 /** VMware logfile console buffer size */
36 #define VMCONSOLE_BUFSIZE 128
38 /* Set default console usage if applicable */
39 #if ! ( defined ( CONSOLE_VMWARE ) && CONSOLE_EXPLICIT ( CONSOLE_VMWARE ) )
41 #define CONSOLE_VMWARE ( CONSOLE_USAGE_ALL & ~CONSOLE_USAGE_TUI )
44 /** VMware logfile console GuestRPC channel */
45 static int vmconsole_channel;
47 /** VMware logfile console line buffer */
50 char message[VMCONSOLE_BUFSIZE];
51 } vmconsole_buffer = {
55 /** VMware logfile console ANSI escape sequence handlers */
56 static struct ansiesc_handler vmconsole_handlers[] = {
60 /** VMware logfile line console */
61 static struct line_console vmconsole_line = {
62 .buffer = vmconsole_buffer.message,
63 .len = sizeof ( vmconsole_buffer.message ),
65 .handlers = vmconsole_handlers,
69 /** VMware logfile console recursion marker */
70 static int vmconsole_entered;
73 * Print a character to VMware logfile console
75 * @v character Character to be printed
77 static void vmconsole_putchar ( int character ) {
80 /* Ignore if we are already mid-logging */
81 if ( vmconsole_entered )
84 /* Fill line buffer */
85 if ( line_putchar ( &vmconsole_line, character ) == 0 )
88 /* Guard against re-entry */
89 vmconsole_entered = 1;
91 /* Send log message */
92 if ( ( rc = guestrpc_command ( vmconsole_channel,
93 vmconsole_buffer.prefix, NULL, 0 ) ) <0){
94 DBG ( "VMware console could not send log message: %s\n",
98 /* Clear re-entry flag */
99 vmconsole_entered = 0;
102 /** VMware logfile console driver */
103 struct console_driver vmconsole __console_driver = {
104 .putchar = vmconsole_putchar,
105 .disabled = CONSOLE_DISABLED,
106 .usage = CONSOLE_VMWARE,
110 * Initialise VMware logfile console
113 static void vmconsole_init ( void ) {
116 /* Attempt to open console */
117 vmconsole_channel = guestrpc_open();
118 if ( vmconsole_channel < 0 ) {
119 rc = vmconsole_channel;
120 DBG ( "VMware console could not be initialised: %s\n",
125 /* Mark console as available */
126 vmconsole.disabled = 0;
130 * VMware logfile console initialisation function
132 struct init_fn vmconsole_init_fn __init_fn ( INIT_CONSOLE ) = {
133 .initialise = vmconsole_init,