[OpenBIOS] [commit] r1230 - in trunk/openbios-devel: arch/amd64 arch/ppc/qemu arch/sparc32 arch/sparc64 arch/unix arch/x86 include/libopenbios libopenbios
repository service
svn at openbios.org
Fri Oct 25 12:38:09 CEST 2013
Author: mcayland
Date: Fri Oct 25 12:38:08 2013
New Revision: 1230
URL: http://tracker.coreboot.org/trac/openbios/changeset/1230
Log:
libopenbios: move console selection from compile-time to runtime
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 at ilande.co.uk>
CC: Andreas Färber <afaerber at suse.de>
CC: Hervé Poussineau <hpoussin at reactos.org>
Added:
trunk/openbios-devel/include/libopenbios/console.h
trunk/openbios-devel/libopenbios/console.c
- copied, changed from r1229, trunk/openbios-devel/arch/ppc/qemu/console.c
Modified:
trunk/openbios-devel/arch/amd64/console.c
trunk/openbios-devel/arch/amd64/openbios.c
trunk/openbios-devel/arch/ppc/qemu/console.c
trunk/openbios-devel/arch/ppc/qemu/init.c
trunk/openbios-devel/arch/sparc32/console.c
trunk/openbios-devel/arch/sparc32/openbios.c
trunk/openbios-devel/arch/sparc64/console.c
trunk/openbios-devel/arch/sparc64/openbios.c
trunk/openbios-devel/arch/unix/unix.c
trunk/openbios-devel/arch/x86/console.c
trunk/openbios-devel/arch/x86/openbios.c
trunk/openbios-devel/libopenbios/build.xml
Modified: trunk/openbios-devel/arch/amd64/console.c
==============================================================================
--- trunk/openbios-devel/arch/amd64/console.c Fri Sep 13 16:16:01 2013 (r1229)
+++ trunk/openbios-devel/arch/amd64/console.c Fri Oct 25 12:38:08 2013 (r1230)
@@ -361,7 +361,7 @@
* 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 @@
return c;
}
-int availchar(void)
+int arch_availchar(void)
{
#ifdef CONFIG_DEBUG_CONSOLE_SERIAL
if (uart_charav(CONFIG_SERIAL_PORT))
@@ -385,7 +385,7 @@
return 0;
}
-int getchar(void)
+int arch_getchar(void)
{
#ifdef CONFIG_DEBUG_CONSOLE_SERIAL
if (uart_charav(CONFIG_SERIAL_PORT))
@@ -408,5 +408,10 @@
#endif
}
+struct _console_ops arch_console_ops = {
+ .putchar = arch_putchar,
+ .availchar = arch_availchar,
+ .getchar = arch_getchar
+};
#endif // CONFIG_DEBUG_CONSOLE
Modified: trunk/openbios-devel/arch/amd64/openbios.c
==============================================================================
--- trunk/openbios-devel/arch/amd64/openbios.c Fri Sep 13 16:16:01 2013 (r1229)
+++ trunk/openbios-devel/arch/amd64/openbios.c Fri Oct 25 12:38:08 2013 (r1230)
@@ -50,9 +50,12 @@
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
Modified: trunk/openbios-devel/arch/ppc/qemu/console.c
==============================================================================
--- trunk/openbios-devel/arch/ppc/qemu/console.c Fri Sep 13 16:16:01 2013 (r1229)
+++ trunk/openbios-devel/arch/ppc/qemu/console.c Fri Oct 25 12:38:08 2013 (r1230)
@@ -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 @@
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 @@
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 @@
#endif
return 0;
}
+
+struct _console_ops mac_console_ops = {
+ .putchar = mac_putchar,
+ .availchar = mac_availchar,
+ .getchar = mac_getchar
+};
+
#endif // CONFIG_DEBUG_CONSOLE
Modified: trunk/openbios-devel/arch/ppc/qemu/init.c
==============================================================================
--- trunk/openbios-devel/arch/ppc/qemu/init.c Fri Sep 13 16:16:01 2013 (r1229)
+++ trunk/openbios-devel/arch/ppc/qemu/init.c Fri Oct 25 12:38:08 2013 (r1230)
@@ -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 @@
};
unsigned long isa_io_base;
+extern struct _console_ops mac_console_ops;
+
void
entry(void)
{
@@ -184,6 +187,10 @@
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 (;;) {
Modified: trunk/openbios-devel/arch/sparc32/console.c
==============================================================================
--- trunk/openbios-devel/arch/sparc32/console.c Fri Sep 13 16:16:01 2013 (r1229)
+++ trunk/openbios-devel/arch/sparc32/console.c Fri Oct 25 12:38:08 2013 (r1230)
@@ -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 @@
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 @@
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 @@
return 0;
}
+struct _console_ops arch_console_ops = {
+ .putchar = arch_putchar,
+ .availchar = arch_availchar,
+ .getchar = arch_getchar
+};
+
#endif // CONFIG_DEBUG_CONSOLE
Modified: trunk/openbios-devel/arch/sparc32/openbios.c
==============================================================================
--- trunk/openbios-devel/arch/sparc32/openbios.c Fri Sep 13 16:16:01 2013 (r1229)
+++ trunk/openbios-devel/arch/sparc32/openbios.c Fri Oct 25 12:38:08 2013 (r1230)
@@ -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 @@
setup_uuid();
}
+extern struct _console_ops arch_console_ops;
+
int openbios(void)
{
unsigned int i;
@@ -927,6 +930,9 @@
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();
Modified: trunk/openbios-devel/arch/sparc64/console.c
==============================================================================
--- trunk/openbios-devel/arch/sparc64/console.c Fri Sep 13 16:16:01 2013 (r1229)
+++ trunk/openbios-devel/arch/sparc64/console.c Fri Oct 25 12:38:08 2013 (r1230)
@@ -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 @@
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 @@
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 @@
return 0;
}
+struct _console_ops arch_console_ops = {
+ .putchar = arch_putchar,
+ .availchar = arch_availchar,
+ .getchar = arch_getchar
+};
+
#endif // CONFIG_DEBUG_CONSOLE
Modified: trunk/openbios-devel/arch/sparc64/openbios.c
==============================================================================
--- trunk/openbios-devel/arch/sparc64/openbios.c Fri Sep 13 16:16:01 2013 (r1229)
+++ trunk/openbios-devel/arch/sparc64/openbios.c Fri Oct 25 12:38:08 2013 (r1230)
@@ -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 @@
unsigned long isa_io_base;
+extern struct _console_ops arch_console_ops;
+
int openbios(void)
{
unsigned int i;
@@ -598,6 +601,7 @@
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
Modified: trunk/openbios-devel/arch/unix/unix.c
==============================================================================
--- trunk/openbios-devel/arch/unix/unix.c Fri Sep 13 16:16:01 2013 (r1229)
+++ trunk/openbios-devel/arch/unix/unix.c Fri Oct 25 12:38:08 2013 (r1230)
@@ -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 @@
* functions used by primitives
*/
-int availchar(void)
+static int unix_availchar(void)
{
int tmp = getc(stdin);
if (tmp != EOF) {
@@ -189,6 +190,23 @@
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 @@
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;
Modified: trunk/openbios-devel/arch/x86/console.c
==============================================================================
--- trunk/openbios-devel/arch/x86/console.c Fri Sep 13 16:16:01 2013 (r1229)
+++ trunk/openbios-devel/arch/x86/console.c Fri Oct 25 12:38:08 2013 (r1230)
@@ -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 @@
* 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 @@
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 @@
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 @@
#endif
}
+struct _console_ops arch_console_ops = {
+ .putchar = arch_putchar,
+ .availchar = arch_availchar,
+ .getchar = arch_getchar
+};
#endif // CONFIG_DEBUG_CONSOLE
Modified: trunk/openbios-devel/arch/x86/openbios.c
==============================================================================
--- trunk/openbios-devel/arch/x86/openbios.c Fri Sep 13 16:16:01 2013 (r1229)
+++ trunk/openbios-devel/arch/x86/openbios.c Fri Oct 25 12:38:08 2013 (r1230)
@@ -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 @@
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
Added: trunk/openbios-devel/include/libopenbios/console.h
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/openbios-devel/include/libopenbios/console.h Fri Oct 25 12:38:08 2013 (r1230)
@@ -0,0 +1,25 @@
+/*
+ * <console.h>
+ *
+ * Shared console routines
+ *
+ * Copyright (C) 2013 Mark Cave-Ayland (mark.cave-ayland at 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 */
Modified: trunk/openbios-devel/libopenbios/build.xml
==============================================================================
--- trunk/openbios-devel/libopenbios/build.xml Fri Sep 13 16:16:01 2013 (r1229)
+++ trunk/openbios-devel/libopenbios/build.xml Fri Oct 25 12:38:08 2013 (r1230)
@@ -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"/>
Copied and modified: trunk/openbios-devel/libopenbios/console.c (from r1229, trunk/openbios-devel/arch/ppc/qemu/console.c)
==============================================================================
--- trunk/openbios-devel/arch/ppc/qemu/console.c Fri Sep 13 16:16:01 2013 (r1229, copy source)
+++ trunk/openbios-devel/libopenbios/console.c Fri Oct 25 12:38:08 2013 (r1230)
@@ -4,6 +4,7 @@
* Simple text console
*
* Copyright (C) 2005 Stefan Reinauer <stepan at openbios.org>
+ * Copyright (C) 2013 Mark Cave-Ayland <mark.cave-ayland at 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
@@ -13,36 +14,55 @@
#include "config.h"
#include "libopenbios/bindings.h"
+#include "libopenbios/console.h"
#include "drivers/drivers.h"
-#ifdef CONFIG_DEBUG_CONSOLE
/* ******************************************************************
* 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)
{
-#ifdef CONFIG_DEBUG_CONSOLE_SERIAL
- serial_putchar(c);
-#endif
- return c;
+ return (*console_ops.putchar)(c);
}
int availchar(void)
{
-#ifdef CONFIG_DEBUG_CONSOLE_SERIAL
- if (uart_charav(CONFIG_SERIAL_PORT))
- return 1;
-#endif
- return 0;
+ return (*console_ops.availchar)();
}
int getchar(void)
{
-#ifdef CONFIG_DEBUG_CONSOLE_SERIAL
- if (uart_charav(CONFIG_SERIAL_PORT))
- return (uart_getchar(CONFIG_SERIAL_PORT));
-#endif
- return 0;
+ return (*console_ops.getchar)();
}
-#endif // CONFIG_DEBUG_CONSOLE
+#endif // CONFIG_DEBUG_CONSOLE
More information about the OpenBIOS
mailing list