Dynamic console devices

David Woodhouse (dwmw2@cam.ac.uk)
Sat, 17 May 1997 02:19:20 +0100


Following the discussion of kernel debugging hardware, and having got
extremely annoyed with my own SMP box chucking up its (altogether too
frequent) kernel panic messages as text underneath my X screen instead of
to the MDA monitor sitting on the shelf across the room, I've made a few
changes to allow a kernel module to call register_console to add a console
device. Naturally, I've added an unregister_console call, too.

The patch has been done against 2.1.3[78]. I also have a patch against Patrick
Caulfield's MDA monitor module to take advantage of the newly exported
functions.

After my exams are over, I'll fix it so that any dynamically added console can
be removed rather than just the most recently registered one. I'll need to
think about concurrency for that, which is why I haven't bothered. At that
point, I'll probably provide patches for the serial and parallel drivers to
dynamically register themselves as a console device.

Q1:
Am I allowed to assume that the lines
console_drivers = console;
and
console_drivers = console->next;

are atomic? If not, then I could have problems with the kernel trying to print
something while the change is half done.

Q2:
The next trick will be to plug a PS/2 keyboard into the PS/2 mouse port on the
motherboard, and attempt to get it to work as a second keyboard. Can anyone
offer me any ideas on the best way to go about this?

Q3: I'd like to keep a copy of the final panic message somewhere in memory
during the reboot, so it can be read back as soon as the machine comes back up.
Can I use video memory for this, on either the VGA or the MDA card? How much
of each is the BIOS likely to wipe as it starts?

Here's the kernel patch; the mda driver patch is at:
ftp://dwmw2.robinson.cam.ac.uk/pub/kernel/mda-0.10-dynamic-console.diff

(mda 0.10 is on sunsite in kernel/misc-cards)

--- linux/kernel/printk.c.orig Wed May 14 12:52:58 1997
+++ linux/kernel/printk.c Wed May 14 12:54:00 1997
@@ -262,7 +262,18 @@
* print any messages that were printed by the kernel before the
* console driver was initialized.
*/
-__initfunc(void register_console(struct console * console))
+int unregister_console(struct console * console)
+{
+ if (console_drivers == console) {
+ console_drivers=console->next;
+ return (0);
+ }
+ else {
+ return (1);
+ }
+}
+
+void register_console(struct console * console)
{
int i,j,len;
int p = log_start;
--- linux/kernel/ksyms.c.orig Wed May 14 12:52:58 1997
+++ linux/kernel/ksyms.c Wed May 14 12:54:00 1997
@@ -51,6 +51,7 @@
#include <linux/swap.h>
#include <linux/ctype.h>
#include <linux/file.h>
+#include <linux/console.h>

#if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_HD) || defined(CONFIG_BLK_DEV_IDE_MODULE) || defined(CONFIG_BLK_DEV_HD_MODULE)
extern struct drive_info_struct drive_info;
@@ -383,3 +384,7 @@
/* binfmt_aout */
EXPORT_SYMBOL(get_write_access);
EXPORT_SYMBOL(put_write_access);
+
+/* dynamic registering of consoles */
+EXPORT_SYMBOL(register_console);
+EXPORT_SYMBOL(unregister_console);
--- linux/include/linux/console.h.orig Wed May 14 12:52:23 1997
+++ linux/include/linux/console.h Wed May 14 12:54:01 1997
@@ -95,6 +95,7 @@
};

extern void register_console(struct console *);
+extern int unregister_console(struct console *);
extern struct console *console_drivers;

#endif /* linux/console.h */

---- ------------------------------------------------ ----
David Woodhouse, WWW: http://dwmw2.robinson.cam.ac.uk/
Robinson College, Email: dwmw2@cam.ac.uk
Cambridge, Tel: +44 (0) 976 658355
CB3 9AN, (n)talk: dwmw2@dwmw2.robinson.cam.ac.uk
England. PGP KEY: finger pgp@dwmw2.robinson.cam.ac.uk
---- ------------------------------------------------ ----