[OpenBIOS] r256 - openbios-devel/arch/ppc/qemu

svn at openbios.org svn at openbios.org
Mon Nov 24 13:23:02 CET 2008


Author: stepan
Date: 2008-11-24 13:23:01 +0100 (Mon, 24 Nov 2008)
New Revision: 256

Modified:
   openbios-devel/arch/ppc/qemu/console.c
   openbios-devel/arch/ppc/qemu/init.c
   openbios-devel/arch/ppc/qemu/qemu.c
Log:
Copy serial support from arch/amd64/console.c

Signed-off-by: Laurent Vivier <Laurent at lvivier.info> 
Acked-by: Stefan Reinauer <stepan at coresystems.de>



Modified: openbios-devel/arch/ppc/qemu/console.c
===================================================================
--- openbios-devel/arch/ppc/qemu/console.c	2008-11-24 12:21:36 UTC (rev 255)
+++ openbios-devel/arch/ppc/qemu/console.c	2008-11-24 12:23:01 UTC (rev 256)
@@ -1,4 +1,3 @@
-
 /*
  *      <console.c>
  *
@@ -13,12 +12,119 @@
  */
 
 #include "openbios/config.h"
+#include "openbios/kernel.h"
 #include "openbios/bindings.h"
 #include "libc/diskio.h"
 #include "ofmem.h"
 #include "qemu/qemu.h"
 
+#ifdef CONFIG_DEBUG_CONSOLE
 
+/* ******************************************************************
+ *                       serial console functions
+ * ****************************************************************** */
+
+#ifdef CONFIG_DEBUG_CONSOLE_SERIAL
+
+#define UART(port)	(port==2?0x2f8:0x3f8)
+
+#define RBR(port)	(UART(port) + 0)
+#define THR(port)	(UART(port) + 0)
+#define IER(port)	(UART(port) + 1)
+#define IIR(port)	(UART(port) + 2)
+#define LCR(port)	(UART(port) + 3)
+#define MCR(port)	(UART(port) + 4)
+#define LSR(port)	(UART(port) + 5)
+#define MSR(port)	(UART(port) + 6)
+#define SCR(port)	(UART(port) + 7)
+#define DLL(port)	(UART(port) + 0)
+#define DLM(port)	(UART(port) + 1)
+
+static int uart_charav(int port)
+{
+	if (!port)
+		return -1;
+	return ((inb(LSR(port)) & 1) != 0);
+}
+
+static char uart_getchar(int port)
+{
+	if (!port)
+		return -1;
+	while (!uart_charav(port));
+	return ((char) inb(RBR(port)) & 0177);
+}
+
+static void uart_putchar(int port, unsigned char c)
+{
+	if (!port)
+		return -1;
+        while (!(inb(LSR(port)) & 0x20));
+        outb(c, THR(port));
+}
+
+static void serial_putchar(int c)
+{
+	if (c == '\n')
+		uart_putchar(CONFIG_SERIAL_PORT, '\r');
+	uart_putchar(CONFIG_SERIAL_PORT, c);
+}
+
+static void uart_init_line(int port, unsigned long baud)
+{
+	int i, baudconst;
+
+	switch (baud) {
+	case 115200:
+		baudconst = 1;
+		break;
+	case 57600:
+		baudconst = 2;
+		break;
+	case 38400:
+		baudconst = 3;
+		break;
+	case 19200:
+		baudconst = 6;
+		break;
+	case 9600:
+	default:
+		baudconst = 12;
+		break;
+	}
+
+	outb(0x87, LCR(port));
+	outb(0x00, DLM(port));
+	outb(baudconst, DLL(port));
+	outb(0x07, LCR(port));
+	outb(0x0f, MCR(port));
+
+	for (i = 10; i > 0; i--) {
+		if (inb(LSR(port)) == (unsigned int) 0)
+			break;
+		inb(RBR(port));
+	}
+}
+
+int
+serial_init(void)
+{
+	if (CONFIG_SERIAL_PORT)
+		uart_init_line(CONFIG_SERIAL_PORT, CONFIG_SERIAL_SPEED);
+	return -1;
+}
+
+static void serial_cls(void)
+{
+	serial_putchar(27);
+	serial_putchar('[');
+	serial_putchar('H');
+	serial_putchar(27);
+	serial_putchar('[');
+	serial_putchar('J');
+}
+#endif	// CONFIG_DEBUG_CONSOLE_SERIAL
+
 typedef struct osi_fb_info {
 	unsigned long   mphys;
 	int             rb, w, h, depth;
@@ -43,5 +149,40 @@
 
 #include "../../../modules/console.c"
 
+/* ******************************************************************
+ *      common functions, implementing simple concurrent console
+ * ****************************************************************** */
 
+int putchar(int c)
+{
+#ifdef CONFIG_DEBUG_CONSOLE_SERIAL
+        serial_putchar(c);
+#endif
+        return c;
+}
 
+int availchar(void)
+{
+#ifdef CONFIG_DEBUG_CONSOLE_SERIAL
+	if (uart_charav(CONFIG_SERIAL_PORT))
+        	return 1;
+#endif
+        return 0;
+}
+
+int getchar(void)
+{
+#ifdef CONFIG_DEBUG_CONSOLE_SERIAL
+	if (uart_charav(CONFIG_SERIAL_PORT))
+		return (uart_getchar(CONFIG_SERIAL_PORT));
+#endif
+        return 0;
+}
+
+void cls(void)
+{
+#ifdef CONFIG_DEBUG_CONSOLE_SERIAL
+	serial_cls();
+#endif
+}
+#endif	// CONFIG_DEBUG_CONSOLE

Modified: openbios-devel/arch/ppc/qemu/init.c
===================================================================
--- openbios-devel/arch/ppc/qemu/init.c	2008-11-24 12:21:36 UTC (rev 255)
+++ openbios-devel/arch/ppc/qemu/init.c	2008-11-24 12:23:01 UTC (rev 256)
@@ -70,6 +70,11 @@
 {
 	arch = &known_arch[ARCH_HEATHROW];
 	isa_io_base = arch->io_base;
+#ifdef CONFIG_DEBUG_CONSOLE
+#ifdef CONFIG_DEBUG_CONSOLE_SERIAL
+	serial_init();
+#endif
+#endif
 	printk("\n");
 	printk("=============================================================\n");
 	printk("OpenBIOS %s [%s]\n", OPENBIOS_RELEASE, OPENBIOS_BUILD_DATE );

Modified: openbios-devel/arch/ppc/qemu/qemu.c
===================================================================
--- openbios-devel/arch/ppc/qemu/qemu.c	2008-11-24 12:21:36 UTC (rev 255)
+++ openbios-devel/arch/ppc/qemu/qemu.c	2008-11-24 12:23:01 UTC (rev 256)
@@ -19,24 +19,23 @@
 #include "openbios/config.h"
 #include "openbios/kernel.h"
 #include "openbios/nvram.h"
+#include "openbios/bindings.h"
 #include "libc/vsprintf.h"
 #include "libc/string.h"
 #include "libc/byteorder.h"
 #include "qemu/qemu.h"
 #include <stdarg.h>
 
-#define UART_BASE 0x3f8
-
 // FIXME
 unsigned long virt_offset = 0;
 
 //#define DUMP_NVRAM
 
 void
-exit( int status )
+exit( int status __attribute__ ((unused)))
 {
 	for (;;);
-}
+} __attribute__ ((noreturn))
 
 void
 fatal_error( const char *err )
@@ -50,10 +49,6 @@
 {
 	printk("Panic: %s\n", err );
 	exit(0);
-
-	/* won't come here... this keeps the gcc happy */
-	for( ;; )
-		;
 }
 
 
@@ -92,62 +87,6 @@
 /*	TTY iface							*/
 /************************************************************************/
 
-static int ttychar = -1;
-
-static int
-tty_avail( void )
-{
-	return 1;
-}
-
-static int
-tty_putchar( int c )
-{
-	if( tty_avail() ) {
-		while (!(inb(UART_BASE + 0x05) & 0x20))
-			;
-		outb(c, UART_BASE);
-		while (!(inb(UART_BASE + 0x05) & 0x40))
-			;
-	}
-	return c;
-}
-
-int
-availchar( void )
-{
-	if( !tty_avail() )
-		return 0;
-
-	if( ttychar < 0 )
-		ttychar = inb(UART_BASE);
-	return (ttychar >= 0);
-}
-
-int
-getchar( void )
-{
-	int ch;
-
-	if( !tty_avail() )
-		return 0;
-
-	if( ttychar < 0 )
-		return inb(UART_BASE);
-	ch = ttychar;
-	ttychar = -1;
-	return ch;
-}
-
-int
-putchar( int c )
-{
-	if (c == '\n')
-		tty_putchar('\r');
-	return tty_putchar(c);
-}
-
-
 /************************************************************************/
 /*	briQ specific stuff						*/
 /************************************************************************/




More information about the OpenBIOS mailing list