mirror of
https://github.com/ipxe/ipxe
synced 2025-12-22 04:50:25 +03:00
[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>
This commit is contained in:
@@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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" );
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user