Browse Source

[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>
tags/v1.20.1
Michael Brown 12 years ago
parent
commit
e024cd39a8

+ 9
- 0
src/arch/i386/core/video_subr.c View File

11
 #include <ipxe/console.h>
11
 #include <ipxe/console.h>
12
 #include <ipxe/init.h>
12
 #include <ipxe/init.h>
13
 #include "vga.h"
13
 #include "vga.h"
14
+#include <config/console.h>
15
+
16
+/* Set default console usage if applicable */
17
+#if ! ( defined ( CONSOLE_DIRECT_VGA ) && \
18
+	CONSOLE_EXPLICIT ( CONSOLE_DIRECT_VGA ) )
19
+#undef CONSOLE_DIRECT_VGA
20
+#define CONSOLE_DIRECT_VGA CONSOLE_USAGE_ALL
21
+#endif
14
 
22
 
15
 struct console_driver vga_console __console_driver;
23
 struct console_driver vga_console __console_driver;
16
 
24
 
97
 struct console_driver vga_console __console_driver = {
105
 struct console_driver vga_console __console_driver = {
98
 	.putchar = vga_putc,
106
 	.putchar = vga_putc,
99
 	.disabled = 1,
107
 	.disabled = 1,
108
+	.usage = CONSOLE_DIRECT_VGA,
100
 };
109
 };
101
 
110
 
102
 struct init_fn video_init_fn __init_fn ( INIT_EARLY ) = {
111
 struct init_fn video_init_fn __init_fn ( INIT_EARLY ) = {

+ 8
- 0
src/arch/i386/firmware/pcbios/bios_console.c View File

23
 #include <ipxe/console.h>
23
 #include <ipxe/console.h>
24
 #include <ipxe/ansiesc.h>
24
 #include <ipxe/ansiesc.h>
25
 #include <ipxe/keymap.h>
25
 #include <ipxe/keymap.h>
26
+#include <config/console.h>
26
 
27
 
27
 #define ATTR_BOLD		0x08
28
 #define ATTR_BOLD		0x08
28
 
29
 
48
 
49
 
49
 #define ATTR_DEFAULT		ATTR_FCOL_WHITE
50
 #define ATTR_DEFAULT		ATTR_FCOL_WHITE
50
 
51
 
52
+/* Set default console usage if applicable */
53
+#if ! ( defined ( CONSOLE_PCBIOS ) && CONSOLE_EXPLICIT ( CONSOLE_PCBIOS ) )
54
+#undef CONSOLE_PCBIOS
55
+#define CONSOLE_PCBIOS CONSOLE_USAGE_ALL
56
+#endif
57
+
51
 /** Current character attribute */
58
 /** Current character attribute */
52
 static unsigned int bios_attr = ATTR_DEFAULT;
59
 static unsigned int bios_attr = ATTR_DEFAULT;
53
 
60
 
319
 	.putchar = bios_putchar,
326
 	.putchar = bios_putchar,
320
 	.getchar = bios_getchar,
327
 	.getchar = bios_getchar,
321
 	.iskey = bios_iskey,
328
 	.iskey = bios_iskey,
329
+	.usage = CONSOLE_PCBIOS,
322
 };
330
 };

+ 8
- 0
src/arch/i386/interface/vmware/vmconsole.c View File

29
 #include <ipxe/lineconsole.h>
29
 #include <ipxe/lineconsole.h>
30
 #include <ipxe/init.h>
30
 #include <ipxe/init.h>
31
 #include <ipxe/guestrpc.h>
31
 #include <ipxe/guestrpc.h>
32
+#include <config/console.h>
32
 
33
 
33
 /** VMware logfile console buffer size */
34
 /** VMware logfile console buffer size */
34
 #define VMCONSOLE_BUFSIZE 128
35
 #define VMCONSOLE_BUFSIZE 128
35
 
36
 
37
+/* Set default console usage if applicable */
38
+#if ! ( defined ( CONSOLE_VMWARE ) && CONSOLE_EXPLICIT ( CONSOLE_VMWARE ) )
39
+#undef CONSOLE_VMWARE
40
+#define CONSOLE_VMWARE CONSOLE_USAGE_ALL
41
+#endif
42
+
36
 /** VMware logfile console GuestRPC channel */
43
 /** VMware logfile console GuestRPC channel */
37
 static int vmconsole_channel;
44
 static int vmconsole_channel;
38
 
45
 
87
 struct console_driver vmconsole __console_driver = {
94
 struct console_driver vmconsole __console_driver = {
88
 	.putchar = vmconsole_putchar,
95
 	.putchar = vmconsole_putchar,
89
 	.disabled = 1,
96
 	.disabled = 1,
97
+	.usage = CONSOLE_VMWARE,
90
 };
98
 };
91
 
99
 
92
 /**
100
 /**

+ 6
- 1
src/core/console.c View File

7
 
7
 
8
 FILE_LICENCE ( GPL2_OR_LATER );
8
 FILE_LICENCE ( GPL2_OR_LATER );
9
 
9
 
10
+/** Current console usage */
11
+int console_usage = CONSOLE_USAGE_STDOUT;
12
+
10
 /**
13
 /**
11
  * Write a single character to each console device.
14
  * Write a single character to each console device.
12
  *
15
  *
26
 		putchar ( '\r' );
29
 		putchar ( '\r' );
27
 
30
 
28
 	for_each_table_entry ( console, CONSOLES ) {
31
 	for_each_table_entry ( console, CONSOLES ) {
29
-		if ( ( ! console->disabled ) && console->putchar )
32
+		if ( ( ! console->disabled ) &&
33
+		     ( console_usage & console->usage ) &&
34
+		     console->putchar )
30
 			console->putchar ( character );
35
 			console->putchar ( character );
31
 	}
36
 	}
32
 }
37
 }

+ 38
- 16
src/core/debug.c View File

21
 #include <stdio.h>
21
 #include <stdio.h>
22
 #include <stdint.h>
22
 #include <stdint.h>
23
 #include <stdarg.h>
23
 #include <stdarg.h>
24
-#include <ipxe/io.h>
24
+#include <ipxe/console.h>
25
+
26
+/**
27
+ * Print debug message
28
+ *
29
+ * @v fmt		Format string
30
+ * @v ...		Arguments
31
+ */
32
+void dbg_printf ( const char *fmt, ... ) {
33
+	int saved_usage;
34
+	va_list args;
35
+
36
+	/* Mark console as in use for debugging messages */
37
+	saved_usage = console_set_usage ( CONSOLE_USAGE_DEBUG );
38
+
39
+	/* Print message */
40
+	va_start ( args, fmt );
41
+	vprintf ( fmt, args );
42
+	va_end ( args );
43
+
44
+	/* Restore console usage */
45
+	console_set_usage ( saved_usage );
46
+}
25
 
47
 
26
 /**
48
 /**
27
  * Pause until a key is pressed
49
  * Pause until a key is pressed
28
  *
50
  *
29
  */
51
  */
30
 void dbg_pause ( void ) {
52
 void dbg_pause ( void ) {
31
-	printf ( "\nPress a key..." );
53
+	dbg_printf ( "\nPress a key..." );
32
 	getchar();
54
 	getchar();
33
-	printf ( "\r              \r" );
55
+	dbg_printf ( "\r              \r" );
34
 }
56
 }
35
 
57
 
36
 /**
58
 /**
38
  *
60
  *
39
  */
61
  */
40
 void dbg_more ( void ) {
62
 void dbg_more ( void ) {
41
-	printf ( "---more---" );
63
+	dbg_printf ( "---more---" );
42
 	getchar();
64
 	getchar();
43
-	printf ( "\r          \r" );
65
+	dbg_printf ( "\r          \r" );
44
 }
66
 }
45
 
67
 
46
 /**
68
 /**
57
 	unsigned int i;
79
 	unsigned int i;
58
 	uint8_t byte;
80
 	uint8_t byte;
59
 
81
 
60
-	printf ( "%08lx :", ( dispaddr + offset ) );
82
+	dbg_printf ( "%08lx :", ( dispaddr + offset ) );
61
 	for ( i = offset ; i < ( offset + 16 ) ; i++ ) {
83
 	for ( i = offset ; i < ( offset + 16 ) ; i++ ) {
62
 		if ( i >= len ) {
84
 		if ( i >= len ) {
63
-			printf ( "   " );
85
+			dbg_printf ( "   " );
64
 			continue;
86
 			continue;
65
 		}
87
 		}
66
-		printf ( "%c%02x",
67
-			 ( ( ( i % 16 ) == 8 ) ? '-' : ' ' ), bytes[i] );
88
+		dbg_printf ( "%c%02x",
89
+			     ( ( ( i % 16 ) == 8 ) ? '-' : ' ' ), bytes[i] );
68
 	}
90
 	}
69
-	printf ( " : " );
91
+	dbg_printf ( " : " );
70
 	for ( i = offset ; i < ( offset + 16 ) ; i++ ) {
92
 	for ( i = offset ; i < ( offset + 16 ) ; i++ ) {
71
 		if ( i >= len ) {
93
 		if ( i >= len ) {
72
-			printf ( " " );
94
+			dbg_printf ( " " );
73
 			continue;
95
 			continue;
74
 		}
96
 		}
75
 		byte = bytes[i];
97
 		byte = bytes[i];
76
 		if ( ( byte < 0x20 ) || ( byte >= 0x7f ) )
98
 		if ( ( byte < 0x20 ) || ( byte >= 0x7f ) )
77
 			byte = '.';
99
 			byte = '.';
78
-		printf ( "%c", byte );
100
+		dbg_printf ( "%c", byte );
79
 	}
101
 	}
80
-	printf ( "\n" );
102
+	dbg_printf ( "\n" );
81
 }
103
 }
82
 
104
 
83
 /**
105
 /**
157
  * @v stream		Message stream ID
179
  * @v stream		Message stream ID
158
  */
180
  */
159
 void dbg_autocolourise ( unsigned long stream ) {
181
 void dbg_autocolourise ( unsigned long stream ) {
160
-	printf ( "\033[%dm",
161
-		 ( stream ? ( 31 + dbg_autocolour ( stream ) ) : 0 ) );
182
+	dbg_printf ( "\033[%dm",
183
+		     ( stream ? ( 31 + dbg_autocolour ( stream ) ) : 0 ) );
162
 }
184
 }
163
 
185
 
164
 /**
186
 /**
166
  *
188
  *
167
  */
189
  */
168
 void dbg_decolourise ( void ) {
190
 void dbg_decolourise ( void ) {
169
-	printf ( "\033[0m" );
191
+	dbg_printf ( "\033[0m" );
170
 }
192
 }

+ 8
- 0
src/core/serial_console.c View File

1
 #include <ipxe/init.h>
1
 #include <ipxe/init.h>
2
 #include <ipxe/serial.h>
2
 #include <ipxe/serial.h>
3
 #include <ipxe/console.h>
3
 #include <ipxe/console.h>
4
+#include <config/console.h>
4
 
5
 
5
 /** @file
6
 /** @file
6
  *
7
  *
8
  *
9
  *
9
  */
10
  */
10
 
11
 
12
+/* Set default console usage if applicable */
13
+#if ! ( defined ( CONSOLE_SERIAL ) && CONSOLE_EXPLICIT ( CONSOLE_SERIAL ) )
14
+#undef CONSOLE_SERIAL
15
+#define CONSOLE_SERIAL CONSOLE_USAGE_ALL
16
+#endif
17
+
11
 struct console_driver serial_console __console_driver;
18
 struct console_driver serial_console __console_driver;
12
 
19
 
13
 static void serial_console_init ( void ) {
20
 static void serial_console_init ( void ) {
21
 	.getchar = serial_getc,
28
 	.getchar = serial_getc,
22
 	.iskey = serial_ischar,
29
 	.iskey = serial_ischar,
23
 	.disabled = 1,
30
 	.disabled = 1,
31
+	.usage = CONSOLE_SERIAL,
24
 };
32
 };
25
 
33
 
26
 /**
34
 /**

+ 3
- 13
src/include/compiler.h View File

260
 
260
 
261
 #ifndef ASSEMBLY
261
 #ifndef ASSEMBLY
262
 
262
 
263
-/** printf() for debugging
264
- *
265
- * This function exists so that the DBG() macros can expand to
266
- * printf() calls without dragging the printf() prototype into scope.
267
- *
268
- * As far as the compiler is concerned, dbg_printf() and printf() are
269
- * completely unrelated calls; it's only at the assembly stage that
270
- * references to the dbg_printf symbol are collapsed into references
271
- * to the printf symbol.
272
- */
273
-extern int __attribute__ (( format ( printf, 1, 2 ) )) 
274
-dbg_printf ( const char *fmt, ... ) asm ( "printf" );
275
-
263
+/** printf() for debugging */
264
+extern void __attribute__ (( format ( printf, 1, 2 ) ))
265
+dbg_printf ( const char *fmt, ... );
276
 extern void dbg_autocolourise ( unsigned long id );
266
 extern void dbg_autocolourise ( unsigned long id );
277
 extern void dbg_decolourise ( void );
267
 extern void dbg_decolourise ( void );
278
 extern void dbg_hex_dump_da ( unsigned long dispaddr,
268
 extern void dbg_hex_dump_da ( unsigned long dispaddr,

+ 50
- 1
src/include/ipxe/console.h View File

75
 	 *
75
 	 *
76
 	 */
76
 	 */
77
 	int ( *iskey ) ( void );
77
 	int ( *iskey ) ( void );
78
+
79
+	/** Console usage bitmask
80
+	 *
81
+	 * This is the bitwise OR of zero or more @c CONSOLE_USAGE_XXX
82
+	 * values.
83
+	 */
84
+	int usage;
78
 };
85
 };
79
 
86
 
80
 /** Console driver table */
87
 /** Console driver table */
99
  */
106
  */
100
 #define __console_driver __table_entry ( CONSOLES, 01 )
107
 #define __console_driver __table_entry ( CONSOLES, 01 )
101
 
108
 
102
-/* Function prototypes */
109
+/**
110
+ * @defgroup consoleusage Console usages
111
+ * @{
112
+ */
113
+
114
+/** Standard output */
115
+#define CONSOLE_USAGE_STDOUT 0x0001
116
+
117
+/** Debug messages */
118
+#define CONSOLE_USAGE_DEBUG 0x0002
119
+
120
+/** All console usages */
121
+#define CONSOLE_USAGE_ALL ( CONSOLE_USAGE_STDOUT | CONSOLE_USAGE_DEBUG )
122
+
123
+/** @} */
124
+
125
+/**
126
+ * Test to see if console has an explicit usage
127
+ *
128
+ * @v console		Console definition (e.g. CONSOLE_PCBIOS)
129
+ * @ret explicit	Console has an explicit usage
130
+ *
131
+ * This relies upon the trick that the expression ( 2 * N + 1 ) will
132
+ * be valid even if N is defined to be empty, since it will then
133
+ * evaluate to give ( 2 * + 1 ) == ( 2 * +1 ) == 2.
134
+ */
135
+#define CONSOLE_EXPLICIT( console ) ( ( 2 * console + 1 ) != 2 )
136
+
137
+extern int console_usage;
138
+
139
+/**
140
+ * Set console usage
141
+ *
142
+ * @v usage		New console usage
143
+ * @ret old_usage	Previous console usage
144
+ */
145
+static inline __attribute__ (( always_inline )) int
146
+console_set_usage ( int usage ) {
147
+	int old_usage = console_usage;
148
+
149
+	console_usage = usage;
150
+	return old_usage;
151
+}
103
 
152
 
104
 extern int iskey ( void );
153
 extern int iskey ( void );
105
 extern int getkey ( unsigned long timeout );
154
 extern int getkey ( unsigned long timeout );

+ 8
- 0
src/interface/efi/efi_console.c View File

23
 #include <ipxe/efi/efi.h>
23
 #include <ipxe/efi/efi.h>
24
 #include <ipxe/ansiesc.h>
24
 #include <ipxe/ansiesc.h>
25
 #include <ipxe/console.h>
25
 #include <ipxe/console.h>
26
+#include <config/console.h>
26
 
27
 
27
 #define ATTR_BOLD		0x08
28
 #define ATTR_BOLD		0x08
28
 
29
 
48
 
49
 
49
 #define ATTR_DEFAULT		ATTR_FCOL_WHITE
50
 #define ATTR_DEFAULT		ATTR_FCOL_WHITE
50
 
51
 
52
+/* Set default console usage if applicable */
53
+#if ! ( defined ( CONSOLE_EFI ) && CONSOLE_EXPLICIT ( CONSOLE_EFI ) )
54
+#undef CONSOLE_EFI
55
+#define CONSOLE_EFI CONSOLE_USAGE_ALL
56
+#endif
57
+
51
 /** Current character attribute */
58
 /** Current character attribute */
52
 static unsigned int efi_attr = ATTR_DEFAULT;
59
 static unsigned int efi_attr = ATTR_DEFAULT;
53
 
60
 
273
 	.putchar = efi_putchar,
280
 	.putchar = efi_putchar,
274
 	.getchar = efi_getchar,
281
 	.getchar = efi_getchar,
275
 	.iskey = efi_iskey,
282
 	.iskey = efi_iskey,
283
+	.usage = CONSOLE_EFI,
276
 };
284
 };

+ 9
- 0
src/interface/linux/linux_console.c View File

33
 #include <linux/termios.h>
33
 #include <linux/termios.h>
34
 #include <asm/errno.h>
34
 #include <asm/errno.h>
35
 
35
 
36
+#include <config/console.h>
37
+
38
+/* Set default console usage if applicable */
39
+#if ! ( defined ( CONSOLE_LINUX ) && CONSOLE_EXPLICIT ( CONSOLE_LINUX ) )
40
+#undef CONSOLE_LINUX
41
+#define CONSOLE_LINUX CONSOLE_USAGE_ALL
42
+#endif
43
+
36
 static void linux_console_putchar(int c)
44
 static void linux_console_putchar(int c)
37
 {
45
 {
38
 	/* write to stdout */
46
 	/* write to stdout */
79
 	.putchar = linux_console_putchar,
87
 	.putchar = linux_console_putchar,
80
 	.getchar = linux_console_getchar,
88
 	.getchar = linux_console_getchar,
81
 	.iskey = linux_console_iskey,
89
 	.iskey = linux_console_iskey,
90
+	.usage = CONSOLE_LINUX,
82
 };
91
 };
83
 
92
 
84
 static int linux_tcgetattr(int fd, struct termios *termios_p)
93
 static int linux_tcgetattr(int fd, struct termios *termios_p)

+ 8
- 0
src/net/udp/syslog.c View File

34
 #include <ipxe/console.h>
34
 #include <ipxe/console.h>
35
 #include <ipxe/lineconsole.h>
35
 #include <ipxe/lineconsole.h>
36
 #include <ipxe/syslog.h>
36
 #include <ipxe/syslog.h>
37
+#include <config/console.h>
38
+
39
+/* Set default console usage if applicable */
40
+#if ! ( defined ( CONSOLE_SYSLOG ) && CONSOLE_EXPLICIT ( CONSOLE_SYSLOG ) )
41
+#undef CONSOLE_SYSLOG
42
+#define CONSOLE_SYSLOG CONSOLE_USAGE_ALL
43
+#endif
37
 
44
 
38
 /** The syslog server */
45
 /** The syslog server */
39
 static struct sockaddr_tcpip logserver = {
46
 static struct sockaddr_tcpip logserver = {
106
 struct console_driver syslog_console __console_driver = {
113
 struct console_driver syslog_console __console_driver = {
107
 	.putchar = syslog_putchar,
114
 	.putchar = syslog_putchar,
108
 	.disabled = 1,
115
 	.disabled = 1,
116
+	.usage = CONSOLE_SYSLOG,
109
 };
117
 };
110
 
118
 
111
 /******************************************************************************
119
 /******************************************************************************

Loading…
Cancel
Save