summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
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,
};
/**