#include <ipxe/console.h>
#include <ipxe/init.h>
#include "vga.h"
+#include <config/console.h>
+
+/* Set default console usage if applicable */
+#if ! ( defined ( CONSOLE_DIRECT_VGA ) && \
+ CONSOLE_EXPLICIT ( CONSOLE_DIRECT_VGA ) )
+#undef CONSOLE_DIRECT_VGA
+#define CONSOLE_DIRECT_VGA CONSOLE_USAGE_ALL
+#endif
struct console_driver vga_console __console_driver;
struct console_driver vga_console __console_driver = {
.putchar = vga_putc,
.disabled = 1,
+ .usage = CONSOLE_DIRECT_VGA,
};
struct init_fn video_init_fn __init_fn ( INIT_EARLY ) = {
#include <ipxe/console.h>
#include <ipxe/ansiesc.h>
#include <ipxe/keymap.h>
+#include <config/console.h>
#define ATTR_BOLD 0x08
#define ATTR_DEFAULT ATTR_FCOL_WHITE
+/* Set default console usage if applicable */
+#if ! ( defined ( CONSOLE_PCBIOS ) && CONSOLE_EXPLICIT ( CONSOLE_PCBIOS ) )
+#undef CONSOLE_PCBIOS
+#define CONSOLE_PCBIOS CONSOLE_USAGE_ALL
+#endif
+
/** Current character attribute */
static unsigned int bios_attr = ATTR_DEFAULT;
.putchar = bios_putchar,
.getchar = bios_getchar,
.iskey = bios_iskey,
+ .usage = CONSOLE_PCBIOS,
};
#include <ipxe/lineconsole.h>
#include <ipxe/init.h>
#include <ipxe/guestrpc.h>
+#include <config/console.h>
/** VMware logfile console buffer size */
#define VMCONSOLE_BUFSIZE 128
+/* Set default console usage if applicable */
+#if ! ( defined ( CONSOLE_VMWARE ) && CONSOLE_EXPLICIT ( CONSOLE_VMWARE ) )
+#undef CONSOLE_VMWARE
+#define CONSOLE_VMWARE CONSOLE_USAGE_ALL
+#endif
+
/** VMware logfile console GuestRPC channel */
static int vmconsole_channel;
struct console_driver vmconsole __console_driver = {
.putchar = vmconsole_putchar,
.disabled = 1,
+ .usage = CONSOLE_VMWARE,
};
/**
FILE_LICENCE ( GPL2_OR_LATER );
+/** Current console usage */
+int console_usage = CONSOLE_USAGE_STDOUT;
+
/**
* Write a single character to each console device.
*
putchar ( '\r' );
for_each_table_entry ( console, CONSOLES ) {
- if ( ( ! console->disabled ) && console->putchar )
+ if ( ( ! console->disabled ) &&
+ ( console_usage & console->usage ) &&
+ console->putchar )
console->putchar ( character );
}
}
#include <stdio.h>
#include <stdint.h>
#include <stdarg.h>
-#include <ipxe/io.h>
+#include <ipxe/console.h>
+
+/**
+ * Print debug message
+ *
+ * @v fmt Format string
+ * @v ... Arguments
+ */
+void dbg_printf ( const char *fmt, ... ) {
+ int saved_usage;
+ va_list args;
+
+ /* Mark console as in use for debugging messages */
+ saved_usage = console_set_usage ( CONSOLE_USAGE_DEBUG );
+
+ /* Print message */
+ va_start ( args, fmt );
+ vprintf ( fmt, args );
+ va_end ( args );
+
+ /* Restore console usage */
+ console_set_usage ( saved_usage );
+}
/**
* Pause until a key is pressed
*
*/
void dbg_pause ( void ) {
- printf ( "\nPress a key..." );
+ dbg_printf ( "\nPress a key..." );
getchar();
- printf ( "\r \r" );
+ dbg_printf ( "\r \r" );
}
/**
*
*/
void dbg_more ( void ) {
- printf ( "---more---" );
+ dbg_printf ( "---more---" );
getchar();
- printf ( "\r \r" );
+ dbg_printf ( "\r \r" );
}
/**
unsigned int i;
uint8_t byte;
- printf ( "%08lx :", ( dispaddr + offset ) );
+ dbg_printf ( "%08lx :", ( dispaddr + offset ) );
for ( i = offset ; i < ( offset + 16 ) ; i++ ) {
if ( i >= len ) {
- printf ( " " );
+ dbg_printf ( " " );
continue;
}
- printf ( "%c%02x",
- ( ( ( i % 16 ) == 8 ) ? '-' : ' ' ), bytes[i] );
+ dbg_printf ( "%c%02x",
+ ( ( ( i % 16 ) == 8 ) ? '-' : ' ' ), bytes[i] );
}
- printf ( " : " );
+ dbg_printf ( " : " );
for ( i = offset ; i < ( offset + 16 ) ; i++ ) {
if ( i >= len ) {
- printf ( " " );
+ dbg_printf ( " " );
continue;
}
byte = bytes[i];
if ( ( byte < 0x20 ) || ( byte >= 0x7f ) )
byte = '.';
- printf ( "%c", byte );
+ dbg_printf ( "%c", byte );
}
- printf ( "\n" );
+ dbg_printf ( "\n" );
}
/**
* @v stream Message stream ID
*/
void dbg_autocolourise ( unsigned long stream ) {
- printf ( "\033[%dm",
- ( stream ? ( 31 + dbg_autocolour ( stream ) ) : 0 ) );
+ dbg_printf ( "\033[%dm",
+ ( stream ? ( 31 + dbg_autocolour ( stream ) ) : 0 ) );
}
/**
*
*/
void dbg_decolourise ( void ) {
- printf ( "\033[0m" );
+ dbg_printf ( "\033[0m" );
}
#include <ipxe/init.h>
#include <ipxe/serial.h>
#include <ipxe/console.h>
+#include <config/console.h>
/** @file
*
*
*/
+/* Set default console usage if applicable */
+#if ! ( defined ( CONSOLE_SERIAL ) && CONSOLE_EXPLICIT ( CONSOLE_SERIAL ) )
+#undef CONSOLE_SERIAL
+#define CONSOLE_SERIAL CONSOLE_USAGE_ALL
+#endif
+
struct console_driver serial_console __console_driver;
static void serial_console_init ( void ) {
.getchar = serial_getc,
.iskey = serial_ischar,
.disabled = 1,
+ .usage = CONSOLE_SERIAL,
};
/**
#ifndef ASSEMBLY
-/** printf() for debugging
- *
- * This function exists so that the DBG() macros can expand to
- * printf() calls without dragging the printf() prototype into scope.
- *
- * As far as the compiler is concerned, dbg_printf() and printf() are
- * completely unrelated calls; it's only at the assembly stage that
- * references to the dbg_printf symbol are collapsed into references
- * to the printf symbol.
- */
-extern int __attribute__ (( format ( printf, 1, 2 ) ))
-dbg_printf ( const char *fmt, ... ) asm ( "printf" );
-
+/** printf() for debugging */
+extern void __attribute__ (( format ( printf, 1, 2 ) ))
+dbg_printf ( const char *fmt, ... );
extern void dbg_autocolourise ( unsigned long id );
extern void dbg_decolourise ( void );
extern void dbg_hex_dump_da ( unsigned long dispaddr,
*
*/
int ( *iskey ) ( void );
+
+ /** Console usage bitmask
+ *
+ * This is the bitwise OR of zero or more @c CONSOLE_USAGE_XXX
+ * values.
+ */
+ int usage;
};
/** Console driver table */
*/
#define __console_driver __table_entry ( CONSOLES, 01 )
-/* Function prototypes */
+/**
+ * @defgroup consoleusage Console usages
+ * @{
+ */
+
+/** Standard output */
+#define CONSOLE_USAGE_STDOUT 0x0001
+
+/** Debug messages */
+#define CONSOLE_USAGE_DEBUG 0x0002
+
+/** All console usages */
+#define CONSOLE_USAGE_ALL ( CONSOLE_USAGE_STDOUT | CONSOLE_USAGE_DEBUG )
+
+/** @} */
+
+/**
+ * Test to see if console has an explicit usage
+ *
+ * @v console Console definition (e.g. CONSOLE_PCBIOS)
+ * @ret explicit Console has an explicit usage
+ *
+ * This relies upon the trick that the expression ( 2 * N + 1 ) will
+ * be valid even if N is defined to be empty, since it will then
+ * evaluate to give ( 2 * + 1 ) == ( 2 * +1 ) == 2.
+ */
+#define CONSOLE_EXPLICIT( console ) ( ( 2 * console + 1 ) != 2 )
+
+extern int console_usage;
+
+/**
+ * Set console usage
+ *
+ * @v usage New console usage
+ * @ret old_usage Previous console usage
+ */
+static inline __attribute__ (( always_inline )) int
+console_set_usage ( int usage ) {
+ int old_usage = console_usage;
+
+ console_usage = usage;
+ return old_usage;
+}
extern int iskey ( void );
extern int getkey ( unsigned long timeout );
#include <ipxe/efi/efi.h>
#include <ipxe/ansiesc.h>
#include <ipxe/console.h>
+#include <config/console.h>
#define ATTR_BOLD 0x08
#define ATTR_DEFAULT ATTR_FCOL_WHITE
+/* Set default console usage if applicable */
+#if ! ( defined ( CONSOLE_EFI ) && CONSOLE_EXPLICIT ( CONSOLE_EFI ) )
+#undef CONSOLE_EFI
+#define CONSOLE_EFI CONSOLE_USAGE_ALL
+#endif
+
/** Current character attribute */
static unsigned int efi_attr = ATTR_DEFAULT;
.putchar = efi_putchar,
.getchar = efi_getchar,
.iskey = efi_iskey,
+ .usage = CONSOLE_EFI,
};
#include <linux/termios.h>
#include <asm/errno.h>
+#include <config/console.h>
+
+/* Set default console usage if applicable */
+#if ! ( defined ( CONSOLE_LINUX ) && CONSOLE_EXPLICIT ( CONSOLE_LINUX ) )
+#undef CONSOLE_LINUX
+#define CONSOLE_LINUX CONSOLE_USAGE_ALL
+#endif
+
static void linux_console_putchar(int c)
{
/* write to stdout */
.putchar = linux_console_putchar,
.getchar = linux_console_getchar,
.iskey = linux_console_iskey,
+ .usage = CONSOLE_LINUX,
};
static int linux_tcgetattr(int fd, struct termios *termios_p)
#include <ipxe/console.h>
#include <ipxe/lineconsole.h>
#include <ipxe/syslog.h>
+#include <config/console.h>
+
+/* Set default console usage if applicable */
+#if ! ( defined ( CONSOLE_SYSLOG ) && CONSOLE_EXPLICIT ( CONSOLE_SYSLOG ) )
+#undef CONSOLE_SYSLOG
+#define CONSOLE_SYSLOG CONSOLE_USAGE_ALL
+#endif
/** The syslog server */
static struct sockaddr_tcpip logserver = {
struct console_driver syslog_console __console_driver = {
.putchar = syslog_putchar,
.disabled = 1,
+ .usage = CONSOLE_SYSLOG,
};
/******************************************************************************