|
@@ -10,23 +10,51 @@
|
|
|
* ----------------------------------------------------------------------- */
|
|
|
|
|
|
/*
|
|
|
- * Very simple screen I/O
|
|
|
- * XXX: Probably should add very simple serial I/O?
|
|
|
+ * Very simple screen and serial I/O
|
|
|
*/
|
|
|
|
|
|
#include "boot.h"
|
|
|
|
|
|
+#define DEFAULT_SERIAL_PORT 0x3f8 /* ttyS0 */
|
|
|
+
|
|
|
+static int early_serial_base;
|
|
|
+
|
|
|
+#define XMTRDY 0x20
|
|
|
+
|
|
|
+#define DLAB 0x80
|
|
|
+
|
|
|
+#define TXR 0 /* Transmit register (WRITE) */
|
|
|
+#define RXR 0 /* Receive register (READ) */
|
|
|
+#define IER 1 /* Interrupt Enable */
|
|
|
+#define IIR 2 /* Interrupt ID */
|
|
|
+#define FCR 2 /* FIFO control */
|
|
|
+#define LCR 3 /* Line control */
|
|
|
+#define MCR 4 /* Modem control */
|
|
|
+#define LSR 5 /* Line Status */
|
|
|
+#define MSR 6 /* Modem Status */
|
|
|
+#define DLL 0 /* Divisor Latch Low */
|
|
|
+#define DLH 1 /* Divisor latch High */
|
|
|
+
|
|
|
+#define DEFAULT_BAUD 9600
|
|
|
+
|
|
|
/*
|
|
|
* These functions are in .inittext so they can be used to signal
|
|
|
* error during initialization.
|
|
|
*/
|
|
|
|
|
|
-void __attribute__((section(".inittext"))) putchar(int ch)
|
|
|
+static void __attribute__((section(".inittext"))) serial_putchar(int ch)
|
|
|
{
|
|
|
- struct biosregs ireg;
|
|
|
+ unsigned timeout = 0xffff;
|
|
|
|
|
|
- if (ch == '\n')
|
|
|
- putchar('\r'); /* \n -> \r\n */
|
|
|
+ while ((inb(early_serial_base + LSR) & XMTRDY) == 0 && --timeout)
|
|
|
+ cpu_relax();
|
|
|
+
|
|
|
+ outb(ch, early_serial_base + TXR);
|
|
|
+}
|
|
|
+
|
|
|
+static void __attribute__((section(".inittext"))) bios_putchar(int ch)
|
|
|
+{
|
|
|
+ struct biosregs ireg;
|
|
|
|
|
|
initregs(&ireg);
|
|
|
ireg.bx = 0x0007;
|
|
@@ -36,6 +64,17 @@ void __attribute__((section(".inittext"))) putchar(int ch)
|
|
|
intcall(0x10, &ireg, NULL);
|
|
|
}
|
|
|
|
|
|
+void __attribute__((section(".inittext"))) putchar(int ch)
|
|
|
+{
|
|
|
+ if (ch == '\n')
|
|
|
+ putchar('\r'); /* \n -> \r\n */
|
|
|
+
|
|
|
+ bios_putchar(ch);
|
|
|
+
|
|
|
+ if (early_serial_base != 0)
|
|
|
+ serial_putchar(ch);
|
|
|
+}
|
|
|
+
|
|
|
void __attribute__((section(".inittext"))) puts(const char *str)
|
|
|
{
|
|
|
while (*str)
|
|
@@ -112,3 +151,63 @@ int getchar_timeout(void)
|
|
|
|
|
|
return 0; /* Timeout! */
|
|
|
}
|
|
|
+
|
|
|
+static void early_serial_init(int baud)
|
|
|
+{
|
|
|
+ unsigned char c;
|
|
|
+ unsigned divisor;
|
|
|
+
|
|
|
+ outb(0x3, early_serial_base + LCR); /* 8n1 */
|
|
|
+ outb(0, early_serial_base + IER); /* no interrupt */
|
|
|
+ outb(0, early_serial_base + FCR); /* no fifo */
|
|
|
+ outb(0x3, early_serial_base + MCR); /* DTR + RTS */
|
|
|
+
|
|
|
+ divisor = 115200 / baud;
|
|
|
+ c = inb(early_serial_base + LCR);
|
|
|
+ outb(c | DLAB, early_serial_base + LCR);
|
|
|
+ outb(divisor & 0xff, early_serial_base + DLL);
|
|
|
+ outb((divisor >> 8) & 0xff, early_serial_base + DLH);
|
|
|
+ outb(c & ~DLAB, early_serial_base + LCR);
|
|
|
+}
|
|
|
+
|
|
|
+void console_init(void)
|
|
|
+{
|
|
|
+ int baud = DEFAULT_BAUD;
|
|
|
+ char arg[32];
|
|
|
+ int pos = 0;
|
|
|
+
|
|
|
+ if (cmdline_find_option("earlyprintk", arg, sizeof arg) > 0) {
|
|
|
+ char *e;
|
|
|
+
|
|
|
+ if (!strncmp(arg, "serial", 6)) {
|
|
|
+ early_serial_base = DEFAULT_SERIAL_PORT;
|
|
|
+ pos += 6;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (arg[pos] == ',')
|
|
|
+ pos++;
|
|
|
+
|
|
|
+ if (!strncmp(arg, "ttyS", 4)) {
|
|
|
+ static const int bases[] = { 0x3f8, 0x2f8 };
|
|
|
+ int port = 0;
|
|
|
+
|
|
|
+ if (!strncmp(arg + pos, "ttyS", 4))
|
|
|
+ pos += 4;
|
|
|
+
|
|
|
+ if (arg[pos++] == '1')
|
|
|
+ port = 1;
|
|
|
+
|
|
|
+ early_serial_base = bases[port];
|
|
|
+ }
|
|
|
+
|
|
|
+ if (arg[pos] == ',')
|
|
|
+ pos++;
|
|
|
+
|
|
|
+ baud = simple_strtoull(arg + pos, &e, 0);
|
|
|
+ if (baud == 0 || arg + pos == e)
|
|
|
+ baud = DEFAULT_BAUD;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (early_serial_base != 0)
|
|
|
+ early_serial_init(baud);
|
|
|
+}
|