1 #include <linux/console.h>
2 #include <linux/kernel.h>
3 #include <linux/init.h>
4 #include <linux/string.h>
6 #include <asm/processor.h>
8 /* Simple VGA output */
11 #define VGABASE (__ISA_IO_base + 0xb8000)
13 #define VGABASE ((void __iomem *)0xffffffff800b8000UL)
19 static int current_ypos = 1, current_xpos = 0;
21 static void early_vga_write(struct console *con, const char *str, unsigned n)
26 while ((c = *str++) != '\0' && n-- > 0) {
27 if (current_ypos >= MAX_YPOS) {
28 /* scroll 1 line up */
29 for (k = 1, j = 0; k < MAX_YPOS; k++, j++) {
30 for (i = 0; i < MAX_XPOS; i++) {
31 writew(readw(VGABASE + 2*(MAX_XPOS*k + i)),
32 VGABASE + 2*(MAX_XPOS*j + i));
35 for (i = 0; i < MAX_XPOS; i++)
36 writew(0x720, VGABASE + 2*(MAX_XPOS*j + i));
37 current_ypos = MAX_YPOS-1;
42 } else if (c != '\r') {
43 writew(((0x7 << 8) | (unsigned short) c),
44 VGABASE + 2*(MAX_XPOS*current_ypos +
46 if (current_xpos >= MAX_XPOS) {
54 static struct console early_vga_console = {
56 .write = early_vga_write,
57 .flags = CON_PRINTBUFFER,
61 /* Serial functions loosely based on a similar package from Klaus P. Gerlicher */
63 static int early_serial_base = 0x3f8; /* ttyS0 */
69 #define TXR 0 /* Transmit register (WRITE) */
70 #define RXR 0 /* Receive register (READ) */
71 #define IER 1 /* Interrupt Enable */
72 #define IIR 2 /* Interrupt ID */
73 #define FCR 2 /* FIFO control */
74 #define LCR 3 /* Line control */
75 #define MCR 4 /* Modem control */
76 #define LSR 5 /* Line Status */
77 #define MSR 6 /* Modem Status */
78 #define DLL 0 /* Divisor Latch Low */
79 #define DLH 1 /* Divisor latch High */
81 static int early_serial_putc(unsigned char ch)
83 unsigned timeout = 0xffff;
84 while ((inb(early_serial_base + LSR) & XMTRDY) == 0 && --timeout)
86 outb(ch, early_serial_base + TXR);
87 return timeout ? 0 : -1;
90 static void early_serial_write(struct console *con, const char *s, unsigned n)
92 while (*s && n-- > 0) {
93 early_serial_putc(*s);
95 early_serial_putc('\r');
100 #define DEFAULT_BAUD 9600
102 static __init void early_serial_init(char *s)
106 unsigned baud = DEFAULT_BAUD;
114 if (!strncmp(s,"0x",2)) {
115 early_serial_base = simple_strtoul(s, &e, 16);
117 static int bases[] = { 0x3f8, 0x2f8 };
119 if (!strncmp(s,"ttyS",4))
121 port = simple_strtoul(s, &e, 10);
122 if (port > 1 || s == e)
124 early_serial_base = bases[port];
126 s += strcspn(s, ",");
131 outb(0x3, early_serial_base + LCR); /* 8n1 */
132 outb(0, early_serial_base + IER); /* no interrupt */
133 outb(0, early_serial_base + FCR); /* no fifo */
134 outb(0x3, early_serial_base + MCR); /* DTR + RTS */
137 baud = simple_strtoul(s, &e, 0);
138 if (baud == 0 || s == e)
142 divisor = 115200 / baud;
143 c = inb(early_serial_base + LCR);
144 outb(c | DLAB, early_serial_base + LCR);
145 outb(divisor & 0xff, early_serial_base + DLL);
146 outb((divisor >> 8) & 0xff, early_serial_base + DLH);
147 outb(c & ~DLAB, early_serial_base + LCR);
150 static struct console early_serial_console = {
152 .write = early_serial_write,
153 .flags = CON_PRINTBUFFER,
157 /* Direct interface for emergencies */
158 struct console *early_console = &early_vga_console;
159 static int early_console_initialized = 0;
161 void early_printk(const char *fmt, ...)
168 n = vscnprintf(buf,512,fmt,ap);
169 early_console->write(early_console,buf,n);
173 static int keep_early;
175 int __init setup_early_printk(char *opt)
180 if (early_console_initialized)
183 opt = strchr(opt, '=') + 1;
185 strlcpy(buf,opt,sizeof(buf));
186 space = strchr(buf, ' ');
190 if (strstr(buf,"keep"))
193 if (!strncmp(buf, "serial", 6)) {
194 early_serial_init(buf + 6);
195 early_console = &early_serial_console;
196 } else if (!strncmp(buf, "ttyS", 4)) {
197 early_serial_init(buf);
198 early_console = &early_serial_console;
199 } else if (!strncmp(buf, "vga", 3)) {
200 early_console = &early_vga_console;
202 early_console_initialized = 1;
203 register_console(early_console);
207 void __init disable_early_printk(void)
209 if (!early_console_initialized || !early_console)
212 printk("disabling early console\n");
213 unregister_console(early_console);
214 early_console_initialized = 0;
216 printk("keeping early console\n");
220 __setup("earlyprintk=", setup_early_printk);