소스 검색

[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 년 전
부모
커밋
e024cd39a8

+ 9
- 0
src/arch/i386/core/video_subr.c 파일 보기

@@ -11,6 +11,14 @@
11 11
 #include <ipxe/console.h>
12 12
 #include <ipxe/init.h>
13 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 23
 struct console_driver vga_console __console_driver;
16 24
 
@@ -97,6 +105,7 @@ static void vga_putc(int byte)
97 105
 struct console_driver vga_console __console_driver = {
98 106
 	.putchar = vga_putc,
99 107
 	.disabled = 1,
108
+	.usage = CONSOLE_DIRECT_VGA,
100 109
 };
101 110
 
102 111
 struct init_fn video_init_fn __init_fn ( INIT_EARLY ) = {

+ 8
- 0
src/arch/i386/firmware/pcbios/bios_console.c 파일 보기

@@ -23,6 +23,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
23 23
 #include <ipxe/console.h>
24 24
 #include <ipxe/ansiesc.h>
25 25
 #include <ipxe/keymap.h>
26
+#include <config/console.h>
26 27
 
27 28
 #define ATTR_BOLD		0x08
28 29
 
@@ -48,6 +49,12 @@ FILE_LICENCE ( GPL2_OR_LATER );
48 49
 
49 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 58
 /** Current character attribute */
52 59
 static unsigned int bios_attr = ATTR_DEFAULT;
53 60
 
@@ -319,4 +326,5 @@ struct console_driver bios_console __console_driver = {
319 326
 	.putchar = bios_putchar,
320 327
 	.getchar = bios_getchar,
321 328
 	.iskey = bios_iskey,
329
+	.usage = CONSOLE_PCBIOS,
322 330
 };

+ 8
- 0
src/arch/i386/interface/vmware/vmconsole.c 파일 보기

@@ -29,10 +29,17 @@ FILE_LICENCE ( GPL2_OR_LATER );
29 29
 #include <ipxe/lineconsole.h>
30 30
 #include <ipxe/init.h>
31 31
 #include <ipxe/guestrpc.h>
32
+#include <config/console.h>
32 33
 
33 34
 /** VMware logfile console buffer size */
34 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 43
 /** VMware logfile console GuestRPC channel */
37 44
 static int vmconsole_channel;
38 45
 
@@ -87,6 +94,7 @@ static void vmconsole_putchar ( int character ) {
87 94
 struct console_driver vmconsole __console_driver = {
88 95
 	.putchar = vmconsole_putchar,
89 96
 	.disabled = 1,
97
+	.usage = CONSOLE_VMWARE,
90 98
 };
91 99
 
92 100
 /**

+ 6
- 1
src/core/console.c 파일 보기

@@ -7,6 +7,9 @@
7 7
 
8 8
 FILE_LICENCE ( GPL2_OR_LATER );
9 9
 
10
+/** Current console usage */
11
+int console_usage = CONSOLE_USAGE_STDOUT;
12
+
10 13
 /**
11 14
  * Write a single character to each console device.
12 15
  *
@@ -26,7 +29,9 @@ void putchar ( int character ) {
26 29
 		putchar ( '\r' );
27 30
 
28 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 35
 			console->putchar ( character );
31 36
 	}
32 37
 }

+ 38
- 16
src/core/debug.c 파일 보기

@@ -21,16 +21,38 @@ FILE_LICENCE ( GPL2_OR_LATER );
21 21
 #include <stdio.h>
22 22
 #include <stdint.h>
23 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 49
  * Pause until a key is pressed
28 50
  *
29 51
  */
30 52
 void dbg_pause ( void ) {
31
-	printf ( "\nPress a key..." );
53
+	dbg_printf ( "\nPress a key..." );
32 54
 	getchar();
33
-	printf ( "\r              \r" );
55
+	dbg_printf ( "\r              \r" );
34 56
 }
35 57
 
36 58
 /**
@@ -38,9 +60,9 @@ void dbg_pause ( void ) {
38 60
  *
39 61
  */
40 62
 void dbg_more ( void ) {
41
-	printf ( "---more---" );
63
+	dbg_printf ( "---more---" );
42 64
 	getchar();
43
-	printf ( "\r          \r" );
65
+	dbg_printf ( "\r          \r" );
44 66
 }
45 67
 
46 68
 /**
@@ -57,27 +79,27 @@ static void dbg_hex_dump_da_row ( unsigned long dispaddr, const void *data,
57 79
 	unsigned int i;
58 80
 	uint8_t byte;
59 81
 
60
-	printf ( "%08lx :", ( dispaddr + offset ) );
82
+	dbg_printf ( "%08lx :", ( dispaddr + offset ) );
61 83
 	for ( i = offset ; i < ( offset + 16 ) ; i++ ) {
62 84
 		if ( i >= len ) {
63
-			printf ( "   " );
85
+			dbg_printf ( "   " );
64 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 92
 	for ( i = offset ; i < ( offset + 16 ) ; i++ ) {
71 93
 		if ( i >= len ) {
72
-			printf ( " " );
94
+			dbg_printf ( " " );
73 95
 			continue;
74 96
 		}
75 97
 		byte = bytes[i];
76 98
 		if ( ( byte < 0x20 ) || ( byte >= 0x7f ) )
77 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,8 +179,8 @@ static int dbg_autocolour ( unsigned long stream ) {
157 179
  * @v stream		Message stream ID
158 180
  */
159 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,5 +188,5 @@ void dbg_autocolourise ( unsigned long stream ) {
166 188
  *
167 189
  */
168 190
 void dbg_decolourise ( void ) {
169
-	printf ( "\033[0m" );
191
+	dbg_printf ( "\033[0m" );
170 192
 }

+ 8
- 0
src/core/serial_console.c 파일 보기

@@ -1,6 +1,7 @@
1 1
 #include <ipxe/init.h>
2 2
 #include <ipxe/serial.h>
3 3
 #include <ipxe/console.h>
4
+#include <config/console.h>
4 5
 
5 6
 /** @file
6 7
  *
@@ -8,6 +9,12 @@
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 18
 struct console_driver serial_console __console_driver;
12 19
 
13 20
 static void serial_console_init ( void ) {
@@ -21,6 +28,7 @@ struct console_driver serial_console __console_driver = {
21 28
 	.getchar = serial_getc,
22 29
 	.iskey = serial_ischar,
23 30
 	.disabled = 1,
31
+	.usage = CONSOLE_SERIAL,
24 32
 };
25 33
 
26 34
 /**

+ 3
- 13
src/include/compiler.h 파일 보기

@@ -260,19 +260,9 @@ REQUEST_EXPANDED ( CONFIG_SYMBOL );
260 260
 
261 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 266
 extern void dbg_autocolourise ( unsigned long id );
277 267
 extern void dbg_decolourise ( void );
278 268
 extern void dbg_hex_dump_da ( unsigned long dispaddr,

+ 50
- 1
src/include/ipxe/console.h 파일 보기

@@ -75,6 +75,13 @@ struct console_driver {
75 75
 	 *
76 76
 	 */
77 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 87
 /** Console driver table */
@@ -99,7 +106,49 @@ struct console_driver {
99 106
  */
100 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 153
 extern int iskey ( void );
105 154
 extern int getkey ( unsigned long timeout );

+ 8
- 0
src/interface/efi/efi_console.c 파일 보기

@@ -23,6 +23,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
23 23
 #include <ipxe/efi/efi.h>
24 24
 #include <ipxe/ansiesc.h>
25 25
 #include <ipxe/console.h>
26
+#include <config/console.h>
26 27
 
27 28
 #define ATTR_BOLD		0x08
28 29
 
@@ -48,6 +49,12 @@ FILE_LICENCE ( GPL2_OR_LATER );
48 49
 
49 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 58
 /** Current character attribute */
52 59
 static unsigned int efi_attr = ATTR_DEFAULT;
53 60
 
@@ -273,4 +280,5 @@ struct console_driver efi_console __console_driver = {
273 280
 	.putchar = efi_putchar,
274 281
 	.getchar = efi_getchar,
275 282
 	.iskey = efi_iskey,
283
+	.usage = CONSOLE_EFI,
276 284
 };

+ 9
- 0
src/interface/linux/linux_console.c 파일 보기

@@ -33,6 +33,14 @@ FILE_LICENCE(GPL2_OR_LATER);
33 33
 #include <linux/termios.h>
34 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 44
 static void linux_console_putchar(int c)
37 45
 {
38 46
 	/* write to stdout */
@@ -79,6 +87,7 @@ struct console_driver linux_console __console_driver = {
79 87
 	.putchar = linux_console_putchar,
80 88
 	.getchar = linux_console_getchar,
81 89
 	.iskey = linux_console_iskey,
90
+	.usage = CONSOLE_LINUX,
82 91
 };
83 92
 
84 93
 static int linux_tcgetattr(int fd, struct termios *termios_p)

+ 8
- 0
src/net/udp/syslog.c 파일 보기

@@ -34,6 +34,13 @@ FILE_LICENCE ( GPL2_OR_LATER );
34 34
 #include <ipxe/console.h>
35 35
 #include <ipxe/lineconsole.h>
36 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 45
 /** The syslog server */
39 46
 static struct sockaddr_tcpip logserver = {
@@ -106,6 +113,7 @@ static void syslog_putchar ( int character ) {
106 113
 struct console_driver syslog_console __console_driver = {
107 114
 	.putchar = syslog_putchar,
108 115
 	.disabled = 1,
116
+	.usage = CONSOLE_SYSLOG,
109 117
 };
110 118
 
111 119
 /******************************************************************************

Loading…
취소
저장