Some architectures require different console configurations depending upon the machine type. This commit moves the console handlers into a struct _console_ops structure held within libopenbios and switches all our supported architectures over to use it.
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk CC: Andreas Färber afaerber@suse.de CC: Hervé Poussineau hpoussin@reactos.org --- openbios-devel/arch/amd64/console.c | 11 +++-- openbios-devel/arch/amd64/openbios.c | 3 ++ openbios-devel/arch/ppc/qemu/console.c | 14 ++++-- openbios-devel/arch/ppc/qemu/init.c | 7 +++ openbios-devel/arch/sparc32/console.c | 13 +++-- openbios-devel/arch/sparc32/openbios.c | 6 +++ openbios-devel/arch/sparc64/console.c | 13 +++-- openbios-devel/arch/sparc64/openbios.c | 4 ++ openbios-devel/arch/unix/unix.c | 23 ++++++++- openbios-devel/arch/x86/console.c | 12 +++-- openbios-devel/arch/x86/openbios.c | 4 ++ openbios-devel/include/libopenbios/console.h | 25 ++++++++++ openbios-devel/libopenbios/build.xml | 1 + openbios-devel/libopenbios/console.c | 68 ++++++++++++++++++++++++++ 14 files changed, 188 insertions(+), 16 deletions(-) create mode 100644 openbios-devel/include/libopenbios/console.h create mode 100644 openbios-devel/libopenbios/console.c
diff --git a/openbios-devel/arch/amd64/console.c b/openbios-devel/arch/amd64/console.c index ab746f6..71a22b6 100644 --- a/openbios-devel/arch/amd64/console.c +++ b/openbios-devel/arch/amd64/console.c @@ -361,7 +361,7 @@ static unsigned char keyboard_readdata(void) * common functions, implementing simple concurrent console * ****************************************************************** */
-int putchar(int c) +int arch_putchar(int c) { #ifdef CONFIG_DEBUG_CONSOLE_SERIAL serial_putchar(c); @@ -372,7 +372,7 @@ int putchar(int c) return c; }
-int availchar(void) +int arch_availchar(void) { #ifdef CONFIG_DEBUG_CONSOLE_SERIAL if (uart_charav(CONFIG_SERIAL_PORT)) @@ -385,7 +385,7 @@ int availchar(void) return 0; }
-int getchar(void) +int arch_getchar(void) { #ifdef CONFIG_DEBUG_CONSOLE_SERIAL if (uart_charav(CONFIG_SERIAL_PORT)) @@ -408,5 +408,10 @@ void cls(void) #endif }
+struct _console_ops arch_console_ops = { + .putchar = arch_putchar, + .availchar = arch_availchar, + .getchar = arch_getchar +};
#endif // CONFIG_DEBUG_CONSOLE diff --git a/openbios-devel/arch/amd64/openbios.c b/openbios-devel/arch/amd64/openbios.c index db138ad..f632e93 100644 --- a/openbios-devel/arch/amd64/openbios.c +++ b/openbios-devel/arch/amd64/openbios.c @@ -50,9 +50,12 @@ arch_init( void ) bind_func("platform-boot", boot ); }
+extern struct _console_ops arch_console_ops; + int openbios(void) { #ifdef CONFIG_DEBUG_CONSOLE + init_console(arch_console_ops); #ifdef CONFIG_DEBUG_CONSOLE_SERIAL uart_init(CONFIG_SERIAL_PORT, CONFIG_SERIAL_SPEED); #endif diff --git a/openbios-devel/arch/ppc/qemu/console.c b/openbios-devel/arch/ppc/qemu/console.c index c5a9dc8..affafc1 100644 --- a/openbios-devel/arch/ppc/qemu/console.c +++ b/openbios-devel/arch/ppc/qemu/console.c @@ -13,6 +13,7 @@
#include "config.h" #include "libopenbios/bindings.h" +#include "libopenbios/console.h" #include "drivers/drivers.h"
#ifdef CONFIG_DEBUG_CONSOLE @@ -20,7 +21,7 @@ * common functions, implementing simple concurrent console * ****************************************************************** */
-int putchar(int c) +static int mac_putchar(int c) { #ifdef CONFIG_DEBUG_CONSOLE_SERIAL serial_putchar(c); @@ -28,7 +29,7 @@ int putchar(int c) return c; }
-int availchar(void) +static int mac_availchar(void) { #ifdef CONFIG_DEBUG_CONSOLE_SERIAL if (uart_charav(CONFIG_SERIAL_PORT)) @@ -37,7 +38,7 @@ int availchar(void) return 0; }
-int getchar(void) +static int mac_getchar(void) { #ifdef CONFIG_DEBUG_CONSOLE_SERIAL if (uart_charav(CONFIG_SERIAL_PORT)) @@ -45,4 +46,11 @@ int getchar(void) #endif return 0; } + +struct _console_ops mac_console_ops = { + .putchar = mac_putchar, + .availchar = mac_availchar, + .getchar = mac_getchar +}; + #endif // CONFIG_DEBUG_CONSOLE diff --git a/openbios-devel/arch/ppc/qemu/init.c b/openbios-devel/arch/ppc/qemu/init.c index 1124c6f..48d39b6 100644 --- a/openbios-devel/arch/ppc/qemu/init.c +++ b/openbios-devel/arch/ppc/qemu/init.c @@ -23,6 +23,7 @@ #include "config.h" #include "libopenbios/openbios.h" #include "libopenbios/bindings.h" +#include "libopenbios/console.h" #include "drivers/pci.h" #include "arch/common/nvram.h" #include "drivers/drivers.h" @@ -162,6 +163,8 @@ static const pci_arch_t known_arch[] = { }; unsigned long isa_io_base;
+extern struct _console_ops mac_console_ops; + void entry(void) { @@ -184,6 +187,10 @@ entry(void)
isa_io_base = arch->io_base;
+#ifdef CONFIG_DEBUG_CONSOLE + init_console(mac_console_ops); +#endif + if (temp != 1) { printk("Incompatible configuration device version, freezing\n"); for (;;) { diff --git a/openbios-devel/arch/sparc32/console.c b/openbios-devel/arch/sparc32/console.c index f3d1fad..9a6912b 100644 --- a/openbios-devel/arch/sparc32/console.c +++ b/openbios-devel/arch/sparc32/console.c @@ -9,6 +9,7 @@ #include "kernel/kernel.h" #include "drivers/drivers.h" #include "openbios.h" +#include "libopenbios/console.h" #include "libopenbios/ofmem.h" #include "libopenbios/video.h"
@@ -18,7 +19,7 @@ * common functions, implementing simple concurrent console * ****************************************************************** */
-int putchar(int c) +static int arch_putchar(int c) { #ifdef CONFIG_DEBUG_CONSOLE_SERIAL serial_putchar(c); @@ -26,7 +27,7 @@ int putchar(int c) return c; }
-int availchar(void) +static int arch_availchar(void) { #ifdef CONFIG_DEBUG_CONSOLE_SERIAL if (uart_charav(CONFIG_SERIAL_PORT)) @@ -39,7 +40,7 @@ int availchar(void) return 0; }
-int getchar(void) +static int arch_getchar(void) { #ifdef CONFIG_DEBUG_CONSOLE_SERIAL if (uart_charav(CONFIG_SERIAL_PORT)) @@ -52,4 +53,10 @@ int getchar(void) return 0; }
+struct _console_ops arch_console_ops = { + .putchar = arch_putchar, + .availchar = arch_availchar, + .getchar = arch_getchar +}; + #endif // CONFIG_DEBUG_CONSOLE diff --git a/openbios-devel/arch/sparc32/openbios.c b/openbios-devel/arch/sparc32/openbios.c index 270cefb..a8b20b2 100644 --- a/openbios-devel/arch/sparc32/openbios.c +++ b/openbios-devel/arch/sparc32/openbios.c @@ -9,6 +9,7 @@ #include "config.h" #include "libopenbios/openbios.h" #include "libopenbios/bindings.h" +#include "libopenbios/console.h" #include "drivers/drivers.h" #include "asm/types.h" #include "dict.h" @@ -913,6 +914,8 @@ arch_init( void ) setup_uuid(); }
+extern struct _console_ops arch_console_ops; + int openbios(void) { unsigned int i; @@ -927,6 +930,9 @@ int openbios(void) if (!hwdef) for(;;); // Internal inconsistency, hang
+#ifdef CONFIG_DEBUG_CONSOLE + init_console(arch_console_ops); +#endif /* Make sure we setup OFMEM before the MMU as we need malloc() to setup page tables */ ofmem_init();
diff --git a/openbios-devel/arch/sparc64/console.c b/openbios-devel/arch/sparc64/console.c index ec7571c..1cb00d9 100644 --- a/openbios-devel/arch/sparc64/console.c +++ b/openbios-devel/arch/sparc64/console.c @@ -7,6 +7,7 @@
#include "config.h" #include "libopenbios/bindings.h" +#include "libopenbios/console.h" #include "kernel/kernel.h" #include "drivers/drivers.h" #include "libopenbios/fontdata.h" @@ -24,7 +25,7 @@ * common functions, implementing simple concurrent console * ****************************************************************** */
-int putchar(int c) +static int arch_putchar(int c) { #ifdef CONFIG_DEBUG_CONSOLE_SERIAL serial_putchar(c); @@ -32,7 +33,7 @@ int putchar(int c) return c; }
-int availchar(void) +static int arch_availchar(void) { #ifdef CONFIG_DEBUG_CONSOLE_SERIAL if (uart_charav(CONFIG_SERIAL_PORT)) @@ -45,7 +46,7 @@ int availchar(void) return 0; }
-int getchar(void) +static int arch_getchar(void) { #ifdef CONFIG_DEBUG_CONSOLE_SERIAL if (uart_charav(CONFIG_SERIAL_PORT)) @@ -58,4 +59,10 @@ int getchar(void) return 0; }
+struct _console_ops arch_console_ops = { + .putchar = arch_putchar, + .availchar = arch_availchar, + .getchar = arch_getchar +}; + #endif // CONFIG_DEBUG_CONSOLE diff --git a/openbios-devel/arch/sparc64/openbios.c b/openbios-devel/arch/sparc64/openbios.c index 7a894cb..7a76158 100644 --- a/openbios-devel/arch/sparc64/openbios.c +++ b/openbios-devel/arch/sparc64/openbios.c @@ -9,6 +9,7 @@ #include "config.h" #include "libopenbios/openbios.h" #include "libopenbios/bindings.h" +#include "libopenbios/console.h" #include "drivers/drivers.h" #include "dict.h" #include "arch/common/nvram.h" @@ -577,6 +578,8 @@ arch_init( void )
unsigned long isa_io_base;
+extern struct _console_ops arch_console_ops; + int openbios(void) { unsigned int i; @@ -598,6 +601,7 @@ int openbios(void) for(;;); // Internal inconsistency, hang
#ifdef CONFIG_DEBUG_CONSOLE + init_console(arch_console_ops); #ifdef CONFIG_DEBUG_CONSOLE_SERIAL uart_init(CONFIG_SERIAL_PORT, CONFIG_SERIAL_SPEED); #endif diff --git a/openbios-devel/arch/unix/unix.c b/openbios-devel/arch/unix/unix.c index 65e67bc..1f628eb 100644 --- a/openbios-devel/arch/unix/unix.c +++ b/openbios-devel/arch/unix/unix.c @@ -32,6 +32,7 @@ #include "kernel/stack.h" #include "arch/unix/plugins.h" #include "libopenbios/bindings.h" +#include "libopenbios/console.h" #include "libopenbios/openbios.h" #include "openbios-version.h"
@@ -179,7 +180,7 @@ static ucell read_dictionary(char *fil) * functions used by primitives */
-int availchar(void) +static int unix_availchar(void) { int tmp = getc(stdin); if (tmp != EOF) { @@ -189,6 +190,23 @@ int availchar(void) return 0; }
+static int unix_putchar(int c) +{ + putc(c, stdout); + return c; +} + +static int unix_getchar(void) +{ + return getc(stdin); +} + +static struct _console_ops unix_console_ops = { + .putchar = unix_putchar, + .availchar = unix_availchar, + .getchar = unix_getchar +}; + u8 inb(u32 reg) { #ifdef CONFIG_PLUGINS @@ -498,6 +516,9 @@ int main(int argc, char *argv[]) return 1; }
+ /* Initialise console */ + init_console(unix_console_ops); + if ((dict = (unsigned char *) malloc(DICTIONARY_SIZE)) == NULL) { printk("panic: not enough memory.\n"); return 1; diff --git a/openbios-devel/arch/x86/console.c b/openbios-devel/arch/x86/console.c index 0bde0c6..906e69c 100644 --- a/openbios-devel/arch/x86/console.c +++ b/openbios-devel/arch/x86/console.c @@ -8,6 +8,7 @@ #include "config.h" #include "kernel/kernel.h" #include "openbios.h" +#include "libopenbios/console.h"
#ifdef CONFIG_DEBUG_CONSOLE
@@ -361,7 +362,7 @@ static unsigned char keyboard_readdata(void) * common functions, implementing simple concurrent console * ****************************************************************** */
-int putchar(int c) +static int arch_putchar(int c) { #ifdef CONFIG_DEBUG_CONSOLE_SERIAL serial_putchar(c); @@ -372,7 +373,7 @@ int putchar(int c) return c; }
-int availchar(void) +static int arch_availchar(void) { #ifdef CONFIG_DEBUG_CONSOLE_SERIAL if (uart_charav(CONFIG_SERIAL_PORT)) @@ -385,7 +386,7 @@ int availchar(void) return 0; }
-int getchar(void) +static int arch_getchar(void) { #ifdef CONFIG_DEBUG_CONSOLE_SERIAL if (uart_charav(CONFIG_SERIAL_PORT)) @@ -408,5 +409,10 @@ void cls(void) #endif }
+struct _console_ops arch_console_ops = { + .putchar = arch_putchar, + .availchar = arch_availchar, + .getchar = arch_getchar +};
#endif // CONFIG_DEBUG_CONSOLE diff --git a/openbios-devel/arch/x86/openbios.c b/openbios-devel/arch/x86/openbios.c index d259a5b..23721bc 100644 --- a/openbios-devel/arch/x86/openbios.c +++ b/openbios-devel/arch/x86/openbios.c @@ -9,6 +9,7 @@ #include "config.h" #include "libopenbios/openbios.h" #include "libopenbios/bindings.h" +#include "libopenbios/console.h" #include "asm/types.h" #include "dict.h" #include "kernel/kernel.h" @@ -75,9 +76,12 @@ arch_init( void ) bind_func("(go)", go ); }
+extern struct _console_ops arch_console_ops; + int openbios(void) { #ifdef CONFIG_DEBUG_CONSOLE + init_console(arch_console_ops); #ifdef CONFIG_DEBUG_CONSOLE_SERIAL uart_init(CONFIG_SERIAL_PORT, CONFIG_SERIAL_SPEED); #endif diff --git a/openbios-devel/include/libopenbios/console.h b/openbios-devel/include/libopenbios/console.h new file mode 100644 index 0000000..899dab8 --- /dev/null +++ b/openbios-devel/include/libopenbios/console.h @@ -0,0 +1,25 @@ +/* + * <console.h> + * + * Shared console routines + * + * Copyright (C) 2013 Mark Cave-Ayland (mark.cave-ayland@ilande.co.uk) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation + * + */ + +#ifndef _H_CONSOLE +#define _H_CONSOLE + +struct _console_ops { + int (*putchar)(int c); + int (*availchar)(void); + int (*getchar)(void); +}; + +void init_console(struct _console_ops ops); + +#endif /* _H_CONSOLE */ diff --git a/openbios-devel/libopenbios/build.xml b/openbios-devel/libopenbios/build.xml index c2f3e0e..feb8f6c 100644 --- a/openbios-devel/libopenbios/build.xml +++ b/openbios-devel/libopenbios/build.xml @@ -6,6 +6,7 @@ <object source="bootcode_load.c" condition="LOADER_BOOTCODE"/> <object source="bootinfo_load.c" condition="LOADER_BOOTINFO"/> <object source="client.c"/> + <object source="console.c"/> <object source="elf_info.c" /> <object source="elf_load.c" condition="LOADER_ELF"/> <object source="font_8x8.c" condition="FONT_8X8"/> diff --git a/openbios-devel/libopenbios/console.c b/openbios-devel/libopenbios/console.c new file mode 100644 index 0000000..7f3aad8 --- /dev/null +++ b/openbios-devel/libopenbios/console.c @@ -0,0 +1,68 @@ +/* + * <console.c> + * + * Simple text console + * + * Copyright (C) 2005 Stefan Reinauer stepan@openbios.org + * Copyright (C) 2013 Mark Cave-Ayland mark.cave-ayland@ilande.co.uk + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation + * + */ + +#include "config.h" +#include "libopenbios/bindings.h" +#include "libopenbios/console.h" +#include "drivers/drivers.h" + +/* ****************************************************************** + * common functions, implementing simple concurrent console + * ****************************************************************** */ + +/* Dummy routines for when console is unassigned */ + +static int dummy_putchar(int c) +{ + return c; +} + +static int dummy_availchar(void) +{ + return 0; +} + +static int dummy_getchar(void) +{ + return 0; +} + +struct _console_ops console_ops = { + .putchar = dummy_putchar, + .availchar = dummy_availchar, + .getchar = dummy_getchar +}; + +#ifdef CONFIG_DEBUG_CONSOLE + +void init_console(struct _console_ops ops) +{ + console_ops = ops; +} + +int putchar(int c) +{ + return (*console_ops.putchar)(c); +} + +int availchar(void) +{ + return (*console_ops.availchar)(); +} + +int getchar(void) +{ + return (*console_ops.getchar)(); +} +#endif // CONFIG_DEBUG_CONSOLE