1 #include <linux/console.h>
2 #include <linux/kernel.h>
3 #include <linux/init.h>
4 #include <linux/string.h>
7 #include <asm/processor.h>
9 /* Simple VGA output */
12 #include <asm/setup.h>
13 #define VGABASE (__ISA_IO_base + 0xb8000)
15 #include <asm/bootsetup.h>
16 #define VGABASE ((void __iomem *)0xffffffff800b8000UL)
19 #define MAX_YPOS max_ypos
20 #define MAX_XPOS max_xpos
22 static int max_ypos = 25, max_xpos = 80;
23 static int current_ypos = 1, current_xpos = 0;
25 static void early_vga_write(struct console *con, const char *str, unsigned n)
30 while ((c = *str++) != '\0' && n-- > 0) {
31 if (current_ypos >= MAX_YPOS) {
32 /* scroll 1 line up */
33 for (k = 1, j = 0; k < MAX_YPOS; k++, j++) {
34 for (i = 0; i < MAX_XPOS; i++) {
35 writew(readw(VGABASE + 2*(MAX_XPOS*k + i)),
36 VGABASE + 2*(MAX_XPOS*j + i));
39 for (i = 0; i < MAX_XPOS; i++)
40 writew(0x720, VGABASE + 2*(MAX_XPOS*j + i));
41 current_ypos = MAX_YPOS-1;
46 } else if (c != '\r') {
47 writew(((0x7 << 8) | (unsigned short) c),
48 VGABASE + 2*(MAX_XPOS*current_ypos +
50 if (current_xpos >= MAX_XPOS) {
58 static struct console early_vga_console = {
60 .write = early_vga_write,
61 .flags = CON_PRINTBUFFER,
65 /* Serial functions loosely based on a similar package from Klaus P. Gerlicher */
67 static int early_serial_base = 0x3f8; /* ttyS0 */
73 #define TXR 0 /* Transmit register (WRITE) */
74 #define RXR 0 /* Receive register (READ) */
75 #define IER 1 /* Interrupt Enable */
76 #define IIR 2 /* Interrupt ID */
77 #define FCR 2 /* FIFO control */
78 #define LCR 3 /* Line control */
79 #define MCR 4 /* Modem control */
80 #define LSR 5 /* Line Status */
81 #define MSR 6 /* Modem Status */
82 #define DLL 0 /* Divisor Latch Low */
83 #define DLH 1 /* Divisor latch High */
85 static int early_serial_putc(unsigned char ch)
87 unsigned timeout = 0xffff;
88 while ((inb(early_serial_base + LSR) & XMTRDY) == 0 && --timeout)
90 outb(ch, early_serial_base + TXR);
91 return timeout ? 0 : -1;
94 static void early_serial_write(struct console *con, const char *s, unsigned n)
96 while (*s && n-- > 0) {
97 early_serial_putc(*s);
99 early_serial_putc('\r');
104 #define DEFAULT_BAUD 9600
106 static __init void early_serial_init(char *s)
110 unsigned baud = DEFAULT_BAUD;
118 if (!strncmp(s,"0x",2)) {
119 early_serial_base = simple_strtoul(s, &e, 16);
121 static int bases[] = { 0x3f8, 0x2f8 };
123 if (!strncmp(s,"ttyS",4))
125 port = simple_strtoul(s, &e, 10);
126 if (port > 1 || s == e)
128 early_serial_base = bases[port];
130 s += strcspn(s, ",");
135 outb(0x3, early_serial_base + LCR); /* 8n1 */
136 outb(0, early_serial_base + IER); /* no interrupt */
137 outb(0, early_serial_base + FCR); /* no fifo */
138 outb(0x3, early_serial_base + MCR); /* DTR + RTS */
141 baud = simple_strtoul(s, &e, 0);
142 if (baud == 0 || s == e)
146 divisor = 115200 / baud;
147 c = inb(early_serial_base + LCR);
148 outb(c | DLAB, early_serial_base + LCR);
149 outb(divisor & 0xff, early_serial_base + DLL);
150 outb((divisor >> 8) & 0xff, early_serial_base + DLH);
151 outb(c & ~DLAB, early_serial_base + LCR);
154 static struct console early_serial_console = {
156 .write = early_serial_write,
157 .flags = CON_PRINTBUFFER,
161 /* Direct interface for emergencies */
162 struct console *early_console = &early_vga_console;
163 static int early_console_initialized = 0;
165 void early_printk(const char *fmt, ...)
172 n = vscnprintf(buf,512,fmt,ap);
173 early_console->write(early_console,buf,n);
177 static int keep_early;
179 int __init setup_early_printk(char *opt)
184 if (early_console_initialized)
187 opt = strchr(opt, '=') + 1;
189 strlcpy(buf,opt,sizeof(buf));
190 space = strchr(buf, ' ');
194 if (strstr(buf,"keep"))
197 if (!strncmp(buf, "serial", 6)) {
198 early_serial_init(buf + 6);
199 early_console = &early_serial_console;
200 } else if (!strncmp(buf, "ttyS", 4)) {
201 early_serial_init(buf);
202 early_console = &early_serial_console;
203 } else if (!strncmp(buf, "vga", 3)
204 && SCREEN_INFO.orig_video_isVGA == 1) {
205 max_xpos = SCREEN_INFO.orig_video_cols;
206 max_ypos = SCREEN_INFO.orig_video_lines;
207 early_console = &early_vga_console;
209 early_console_initialized = 1;
210 register_console(early_console);
214 void __init disable_early_printk(void)
216 if (!early_console_initialized || !early_console)
219 printk("disabling early console\n");
220 unregister_console(early_console);
221 early_console_initialized = 0;
223 printk("keeping early console\n");
227 __setup("earlyprintk=", setup_early_printk);