This patchset, when applied against Hervé's QEMU raven branch, provides a basic serial console for PReP machines when launched from QEMU with -nographic.
There is still some further work to be done with setting up a proper ISA bridge device but it seemed worthwhile handling the required console changes first as a self-contained patchset.
Mark Cave-Ayland (3): libopenbios: move console selection from compile-time to runtime escc/pc_serial: separate uart_* functions into separate namespaces ppc: enable basic PReP serial console
openbios-devel/arch/amd64/console.c | 11 ++-- openbios-devel/arch/amd64/openbios.c | 3 ++ openbios-devel/arch/ppc/qemu/console.c | 50 ++++++++++++++++-- openbios-devel/arch/ppc/qemu/init.c | 31 +++++++++-- openbios-devel/arch/ppc/qemu/main.c | 5 +- openbios-devel/arch/sparc32/console.c | 21 +++++--- openbios-devel/arch/sparc32/openbios.c | 8 ++- openbios-devel/arch/sparc64/console.c | 15 ++++-- 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/config/examples/ppc_config.xml | 1 + openbios-devel/drivers/escc.c | 50 +++++++++--------- openbios-devel/drivers/pc_serial.c | 10 ++-- openbios-devel/include/drivers/drivers.h | 10 ++-- openbios-devel/include/libopenbios/console.h | 25 +++++++++ openbios-devel/libopenbios/build.xml | 1 + openbios-devel/libopenbios/console.c | 68 +++++++++++++++++++++++++ 19 files changed, 287 insertions(+), 65 deletions(-) create mode 100644 openbios-devel/include/libopenbios/console.h create mode 100644 openbios-devel/libopenbios/console.c
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
In order to allow architectures to support both ESCC and PC serial, add an escc_ prefix to the ESCC serial functions so that they can both co-exist within the same binary.
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/ppc/qemu/console.c | 8 ++--- openbios-devel/arch/sparc32/console.c | 8 ++--- openbios-devel/arch/sparc32/openbios.c | 2 +- openbios-devel/arch/sparc64/console.c | 2 +- openbios-devel/drivers/escc.c | 50 +++++++++++++++--------------- openbios-devel/drivers/pc_serial.c | 10 +++--- openbios-devel/include/drivers/drivers.h | 10 +++--- 7 files changed, 45 insertions(+), 45 deletions(-)
diff --git a/openbios-devel/arch/ppc/qemu/console.c b/openbios-devel/arch/ppc/qemu/console.c index affafc1..25b21c0 100644 --- a/openbios-devel/arch/ppc/qemu/console.c +++ b/openbios-devel/arch/ppc/qemu/console.c @@ -24,7 +24,7 @@ static int mac_putchar(int c) { #ifdef CONFIG_DEBUG_CONSOLE_SERIAL - serial_putchar(c); + escc_uart_putchar(c & 0xff); #endif return c; } @@ -32,7 +32,7 @@ static int mac_putchar(int c) static int mac_availchar(void) { #ifdef CONFIG_DEBUG_CONSOLE_SERIAL - if (uart_charav(CONFIG_SERIAL_PORT)) + if (escc_uart_charav(CONFIG_SERIAL_PORT)) return 1; #endif return 0; @@ -41,8 +41,8 @@ static int mac_availchar(void) static int mac_getchar(void) { #ifdef CONFIG_DEBUG_CONSOLE_SERIAL - if (uart_charav(CONFIG_SERIAL_PORT)) - return (uart_getchar(CONFIG_SERIAL_PORT)); + if (escc_uart_charav(CONFIG_SERIAL_PORT)) + return (escc_uart_getchar(CONFIG_SERIAL_PORT)); #endif return 0; } diff --git a/openbios-devel/arch/sparc32/console.c b/openbios-devel/arch/sparc32/console.c index 9a6912b..61c2e23 100644 --- a/openbios-devel/arch/sparc32/console.c +++ b/openbios-devel/arch/sparc32/console.c @@ -22,7 +22,7 @@ static int arch_putchar(int c) { #ifdef CONFIG_DEBUG_CONSOLE_SERIAL - serial_putchar(c); + escc_uart_putchar(c); #endif return c; } @@ -30,7 +30,7 @@ static int arch_putchar(int c) static int arch_availchar(void) { #ifdef CONFIG_DEBUG_CONSOLE_SERIAL - if (uart_charav(CONFIG_SERIAL_PORT)) + if (escc_uart_charav(CONFIG_SERIAL_PORT)) return 1; #endif #ifdef CONFIG_DEBUG_CONSOLE_VIDEO @@ -43,8 +43,8 @@ static int arch_availchar(void) static int arch_getchar(void) { #ifdef CONFIG_DEBUG_CONSOLE_SERIAL - if (uart_charav(CONFIG_SERIAL_PORT)) - return (uart_getchar(CONFIG_SERIAL_PORT)); + if (escc_uart_charav(CONFIG_SERIAL_PORT)) + return (escc_uart_getchar(CONFIG_SERIAL_PORT)); #endif #ifdef CONFIG_DEBUG_CONSOLE_VIDEO if (keyboard_dataready()) diff --git a/openbios-devel/arch/sparc32/openbios.c b/openbios-devel/arch/sparc32/openbios.c index a8b20b2..abdfe7c 100644 --- a/openbios-devel/arch/sparc32/openbios.c +++ b/openbios-devel/arch/sparc32/openbios.c @@ -941,7 +941,7 @@ int openbios(void) #endif #ifdef CONFIG_DEBUG_CONSOLE #ifdef CONFIG_DEBUG_CONSOLE_SERIAL - uart_init(hwdef->serial_base | (CONFIG_SERIAL_PORT? 0ULL: 4ULL), + escc_uart_init(hwdef->serial_base | (CONFIG_SERIAL_PORT? 0ULL: 4ULL), CONFIG_SERIAL_SPEED); #endif #ifdef CONFIG_DEBUG_CONSOLE_VIDEO diff --git a/openbios-devel/arch/sparc64/console.c b/openbios-devel/arch/sparc64/console.c index 1cb00d9..6ab5cba 100644 --- a/openbios-devel/arch/sparc64/console.c +++ b/openbios-devel/arch/sparc64/console.c @@ -28,7 +28,7 @@ static int arch_putchar(int c) { #ifdef CONFIG_DEBUG_CONSOLE_SERIAL - serial_putchar(c); + uart_putchar(c); #endif return c; } diff --git a/openbios-devel/drivers/escc.c b/openbios-devel/drivers/escc.c index 5690625..105a47d 100644 --- a/openbios-devel/drivers/escc.c +++ b/openbios-devel/drivers/escc.c @@ -11,7 +11,7 @@ * serial console functions * ****************************************************************** */
-static volatile unsigned char *serial_dev; +static volatile unsigned char *escc_serial_dev;
#define CTRL(addr) (*(volatile unsigned char *)(uintptr_t)(addr)) #ifdef CONFIG_DRIVER_ESCC_SUN @@ -54,25 +54,25 @@ static volatile unsigned char *serial_dev; #define Rx_CH_AV 0x1 /* Rx Character Available */ #define Tx_BUF_EMP 0x4 /* Tx Buffer empty */
-int uart_charav(uintptr_t port) +int escc_uart_charav(uintptr_t port) { return (CTRL(port) & Rx_CH_AV) != 0; }
-char uart_getchar(uintptr_t port) +char escc_uart_getchar(uintptr_t port) { - while (!uart_charav(port)) + while (!escc_uart_charav(port)) ; return DATA(port) & 0177; }
-static void uart_putchar(uintptr_t port, unsigned char c) +static void escc_uart_port_putchar(uintptr_t port, unsigned char c) { - if (!serial_dev) + if (!escc_serial_dev) return;
if (c == '\n') - uart_putchar(port, '\r'); + escc_uart_port_putchar(port, '\r'); while (!(CTRL(port) & Tx_BUF_EMP)) ; DATA(port) = c; @@ -102,31 +102,31 @@ static void uart_init_line(volatile unsigned char *port, unsigned long baud)
}
-int uart_init(phys_addr_t port, unsigned long speed) +int escc_uart_init(phys_addr_t port, unsigned long speed) { #ifdef CONFIG_DRIVER_ESCC_SUN - serial_dev = (unsigned char *)ofmem_map_io(port & ~7ULL, ZS_REGS); - serial_dev += port & 7ULL; + escc_serial_dev = (unsigned char *)ofmem_map_io(port & ~7ULL, ZS_REGS); + escc_serial_dev += port & 7ULL; #else - serial_dev = (unsigned char *)(uintptr_t)port; + escc_serial_dev = (unsigned char *)(uintptr_t)port; #endif - uart_init_line(serial_dev, speed); + uart_init_line(escc_serial_dev, speed); return -1; }
-void serial_putchar(int c) +void escc_uart_putchar(int c) { - uart_putchar((uintptr_t)serial_dev, (unsigned char) (c & 0xff)); + escc_uart_port_putchar((uintptr_t)escc_serial_dev, (unsigned char) (c & 0xff)); }
void serial_cls(void) { - serial_putchar(27); - serial_putchar('['); - serial_putchar('H'); - serial_putchar(27); - serial_putchar('['); - serial_putchar('J'); + escc_uart_putchar(27); + escc_uart_putchar('['); + escc_uart_putchar('H'); + escc_uart_putchar(27); + escc_uart_putchar('['); + escc_uart_putchar('J'); }
/* ( addr len -- actual ) */ @@ -142,8 +142,8 @@ escc_read(ucell *address) if (len < 1) printk("escc_read: bad len, addr %p len %x\n", addr, len);
- if (uart_charav(*address)) { - *addr = (char)uart_getchar(*address); + if (escc_uart_charav(*address)) { + *addr = (char)escc_uart_getchar(*address); PUSH(1); } else { PUSH(0); @@ -161,7 +161,7 @@ escc_write(ucell *address) addr = (unsigned char *)cell2pointer(POP());
for (i = 0; i < len; i++) { - uart_putchar(*address, addr[i]); + escc_uart_port_putchar(*address, addr[i]); } PUSH(len); } @@ -194,7 +194,7 @@ escc_open(ucell *address) free(args); } #else - *address = (unsigned long)serial_dev; // XXX + *address = (unsigned long)escc_serial_dev; // XXX #endif RET ( -1 ); } @@ -470,7 +470,7 @@ escc_init(const char *path, phys_addr_t addr) escc_add_channel(buf, "a", addr, 1); escc_add_channel(buf, "b", addr, 0);
- serial_dev = (unsigned char *)addr + IO_ESCC_OFFSET + + escc_serial_dev = (unsigned char *)addr + IO_ESCC_OFFSET + (CONFIG_SERIAL_PORT ? 0 : 0x20); } #endif diff --git a/openbios-devel/drivers/pc_serial.c b/openbios-devel/drivers/pc_serial.c index 5882a05..6192f18 100644 --- a/openbios-devel/drivers/pc_serial.c +++ b/openbios-devel/drivers/pc_serial.c @@ -40,10 +40,10 @@ char uart_getchar(int port) return ((char) inb(RBR(port)) & 0177); }
-static void uart_putchar(int port, unsigned char c) +static void uart_port_putchar(int port, unsigned char c) { if (c == '\n') - uart_putchar(port, '\r'); + uart_port_putchar(port, '\r'); while (!(inb(LSR(port)) & 0x20)); outb(c, THR(port)); } @@ -91,9 +91,9 @@ int uart_init(int port, unsigned long speed) return -1; }
-void serial_putchar(int c) +void uart_putchar(int c) { - uart_putchar(CONFIG_SERIAL_PORT, (unsigned char) (c & 0xff)); + uart_port_putchar(CONFIG_SERIAL_PORT, (unsigned char) (c & 0xff)); } #endif
@@ -129,7 +129,7 @@ pc_serial_write(unsigned long *address) addr = (unsigned char *)POP();
for (i = 0; i < len; i++) { - uart_putchar(*address, addr[i]); + uart_port_putchar(*address, addr[i]); } PUSH(len); } diff --git a/openbios-devel/include/drivers/drivers.h b/openbios-devel/include/drivers/drivers.h index 47d730f..52bc881 100644 --- a/openbios-devel/include/drivers/drivers.h +++ b/openbios-devel/include/drivers/drivers.h @@ -109,13 +109,13 @@ void ob_pc_serial_init(const char *path, const char *dev_name, uint64_t base, int uart_init(int port, unsigned long speed); int uart_charav(int port); char uart_getchar(int port); -void serial_putchar(int c); +void uart_putchar(int c); #endif #ifdef CONFIG_DRIVER_ESCC -int uart_init(phys_addr_t port, unsigned long speed); -int uart_charav(uintptr_t port); -char uart_getchar(uintptr_t port); -void serial_putchar(int c); +int escc_uart_init(phys_addr_t port, unsigned long speed); +int escc_uart_charav(uintptr_t port); +char escc_uart_getchar(uintptr_t port); +void escc_uart_putchar(int c); void serial_cls(void); #ifdef CONFIG_DRIVER_ESCC_SUN int keyboard_dataready(void);
This patch follows on from the previous patchsets and provides a basic PReP serial console when launched under QEMU with -nographic. This is done by including the PC serial driver as part of the PPC binary build and setting up a prep_console_ops structure for use when PReP architecture is detected.
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/ppc/qemu/console.c | 32 +++++++++++++++++++++++++ openbios-devel/arch/ppc/qemu/init.c | 28 ++++++++++++++++------ openbios-devel/arch/ppc/qemu/main.c | 5 +++- openbios-devel/config/examples/ppc_config.xml | 1 + 4 files changed, 58 insertions(+), 8 deletions(-)
diff --git a/openbios-devel/arch/ppc/qemu/console.c b/openbios-devel/arch/ppc/qemu/console.c index 25b21c0..53a3215 100644 --- a/openbios-devel/arch/ppc/qemu/console.c +++ b/openbios-devel/arch/ppc/qemu/console.c @@ -53,4 +53,36 @@ struct _console_ops mac_console_ops = { .getchar = mac_getchar };
+static int prep_putchar(int c) +{ +#ifdef CONFIG_DEBUG_CONSOLE_SERIAL + uart_putchar(c & 0xff); +#endif + return c; +} + +static int prep_availchar(void) +{ +#ifdef CONFIG_DEBUG_CONSOLE_SERIAL + if (uart_charav(CONFIG_SERIAL_PORT)) + return 1; +#endif + return 0; +} + +static int prep_getchar(void) +{ +#ifdef CONFIG_DEBUG_CONSOLE_SERIAL + if (uart_charav(CONFIG_SERIAL_PORT)) + return (uart_getchar(CONFIG_SERIAL_PORT)); +#endif + return 0; +} + +struct _console_ops prep_console_ops = { + .putchar = prep_putchar, + .availchar = prep_availchar, + .getchar = prep_getchar +}; + #endif // CONFIG_DEBUG_CONSOLE diff --git a/openbios-devel/arch/ppc/qemu/init.c b/openbios-devel/arch/ppc/qemu/init.c index 48d39b6..4eb0f0e 100644 --- a/openbios-devel/arch/ppc/qemu/init.c +++ b/openbios-devel/arch/ppc/qemu/init.c @@ -163,7 +163,7 @@ static const pci_arch_t known_arch[] = { }; unsigned long isa_io_base;
-extern struct _console_ops mac_console_ops; +extern struct _console_ops mac_console_ops, prep_console_ops;
void entry(void) @@ -188,7 +188,11 @@ entry(void) isa_io_base = arch->io_base;
#ifdef CONFIG_DEBUG_CONSOLE - init_console(mac_console_ops); + if (is_apple()) { + init_console(mac_console_ops); + } else { + init_console(prep_console_ops); + } #endif
if (temp != 1) { @@ -658,6 +662,11 @@ arch_of_init(void)
ofmem_t *ofmem = ofmem_arch_get_private();
+ if (!is_apple()) { + /* Initialise PReP serial port */ + ob_pc_serial_init("", "serial", arch->io_base, 0x3f8ULL, 0); + } + openbios_init(); modules_init(); setup_timers(); @@ -823,12 +832,17 @@ arch_of_init(void) #endif
if (fw_cfg_read_i16(FW_CFG_NOGRAPHIC)) { - if (CONFIG_SERIAL_PORT) { - stdin_path = "scca"; - stdout_path = "scca"; + if (is_apple()) { + if (CONFIG_SERIAL_PORT) { + stdin_path = "scca"; + stdout_path = "scca"; + } else { + stdin_path = "sccb"; + stdout_path = "sccb"; + } } else { - stdin_path = "sccb"; - stdout_path = "sccb"; + stdin_path = "/serial"; + stdout_path = "/serial"; }
/* Some bootloaders force the output to the screen device, so diff --git a/openbios-devel/arch/ppc/qemu/main.c b/openbios-devel/arch/ppc/qemu/main.c index 30a4375..44b1666 100644 --- a/openbios-devel/arch/ppc/qemu/main.c +++ b/openbios-devel/arch/ppc/qemu/main.c @@ -22,6 +22,7 @@ #include "libc/diskio.h" #include "libc/vsprintf.h" #include "kernel.h" +#include "drivers/drivers.h" #include "libopenbios/ofmem.h" #define NO_QEMU_PROTOS #include "arch/common/fw_cfg.h" @@ -78,5 +79,7 @@ boot( void ) check_preloaded_kernel(); }
- update_nvram(); + if (is_apple()) { + update_nvram(); + } } diff --git a/openbios-devel/config/examples/ppc_config.xml b/openbios-devel/config/examples/ppc_config.xml index 5bb789f..200775d 100644 --- a/openbios-devel/config/examples/ppc_config.xml +++ b/openbios-devel/config/examples/ppc_config.xml @@ -8,6 +8,7 @@ <option name="CONFIG_DEBUG_INTERPRETER" type="boolean" value="false"/> <option name="CONFIG_DEBUG_CONSOLE" type="boolean" value="true"/> <option name="CONFIG_DEBUG_CONSOLE_SERIAL" type="boolean" value="true"/> + <option name="CONFIG_DRIVER_PC_SERIAL" type="boolean" value="true"/> <option name="CONFIG_SERIAL_PORT" type="integer" value="0"/> <option name="CONFIG_SERIAL_SPEED" type="integer" value="115200"/> <option name="CONFIG_DEBUG_CONSOLE_VGA" type="boolean" value="true"/>