summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
authorMichael Brown2012-03-26 18:25:08 +0200
committerMichael Brown2012-03-26 18:40:01 +0200
commite024cd39a877ea1b37b9004dbd8f33448418cb36 (patch)
tree8bc44239bc5920d06b8381edef5aa37a4784aaf3 /src/core
parent[console] Remove unused "btext" console (diff)
downloadipxe-e024cd39a877ea1b37b9004dbd8f33448418cb36.tar.gz
ipxe-e024cd39a877ea1b37b9004dbd8f33448418cb36.tar.xz
ipxe-e024cd39a877ea1b37b9004dbd8f33448418cb36.zip
[console] Allow usage to be defined independently for each console
Add the concept of a "console usage", such as "standard output" or "debug messages". Allow usages to be associated with each console independently. For example, to send debugging output via the serial port, while preventing it from appearing on the local console: #define CONSOLE_SERIAL CONSOLE_USAGE_ALL #define CONSOLE_PCBIOS ( CONSOLE_USAGE_ALL & ~CONSOLE_USAGE_DEBUG ) If no usages are explicitly specified, then a default set of usages will be applied. For example: #define CONSOLE_SERIAL will have the same affect as #define CONSOLE_SERIAL CONSOLE_USAGE_ALL Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/core')
-rw-r--r--src/core/console.c7
-rw-r--r--src/core/debug.c54
-rw-r--r--src/core/serial_console.c8
3 files changed, 52 insertions, 17 deletions
diff --git a/src/core/console.c b/src/core/console.c
index f27edf468..a26a3ef63 100644
--- a/src/core/console.c
+++ b/src/core/console.c
@@ -7,6 +7,9 @@
FILE_LICENCE ( GPL2_OR_LATER );
+/** Current console usage */
+int console_usage = CONSOLE_USAGE_STDOUT;
+
/**
* Write a single character to each console device.
*
@@ -26,7 +29,9 @@ void putchar ( int character ) {
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 );
}
}
diff --git a/src/core/debug.c b/src/core/debug.c
index 8fca8d90d..fc90c64a1 100644
--- a/src/core/debug.c
+++ b/src/core/debug.c
@@ -21,16 +21,38 @@ FILE_LICENCE ( GPL2_OR_LATER );
#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" );
}
/**
@@ -38,9 +60,9 @@ void dbg_pause ( void ) {
*
*/
void dbg_more ( void ) {
- printf ( "---more---" );
+ dbg_printf ( "---more---" );
getchar();
- printf ( "\r \r" );
+ dbg_printf ( "\r \r" );
}
/**
@@ -57,27 +79,27 @@ static void dbg_hex_dump_da_row ( unsigned long dispaddr, const void *data,
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" );
}
/**
@@ -157,8 +179,8 @@ static int dbg_autocolour ( unsigned long stream ) {
* @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 ) );
}
/**
@@ -166,5 +188,5 @@ void dbg_autocolourise ( unsigned long stream ) {
*
*/
void dbg_decolourise ( void ) {
- printf ( "\033[0m" );
+ dbg_printf ( "\033[0m" );
}
diff --git a/src/core/serial_console.c b/src/core/serial_console.c
index b05a06b17..52bd53760 100644
--- a/src/core/serial_console.c
+++ b/src/core/serial_console.c
@@ -1,6 +1,7 @@
#include <ipxe/init.h>
#include <ipxe/serial.h>
#include <ipxe/console.h>
+#include <config/console.h>
/** @file
*
@@ -8,6 +9,12 @@
*
*/
+/* 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 ) {
@@ -21,6 +28,7 @@ struct console_driver serial_console __console_driver = {
.getchar = serial_getc,
.iskey = serial_ischar,
.disabled = 1,
+ .usage = CONSOLE_SERIAL,
};
/**