[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:
Michael Brown
2012-03-26 17:25:08 +01:00
parent b35d454422
commit e024cd39a8
11 changed files with 155 additions and 31 deletions

View File

@@ -260,19 +260,9 @@ REQUEST_EXPANDED ( CONFIG_SYMBOL );
#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,

View File

@@ -75,6 +75,13 @@ struct console_driver {
*
*/
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 */
@@ -99,7 +106,49 @@ struct console_driver {
*/
#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 );