2003-05-31 18:35:21 +00:00
|
|
|
|
/*
|
|
|
|
|
* (C) Copyright 2002
|
2011-04-13 09:43:26 +00:00
|
|
|
|
* Daniel Engstr<EFBFBD>m, Omicron Ceti AB, <daniel@omicron.se>
|
2003-05-31 18:35:21 +00:00
|
|
|
|
*
|
|
|
|
|
* See file CREDITS for list of people who contributed to this
|
|
|
|
|
* project.
|
|
|
|
|
*
|
|
|
|
|
* 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; either version 2 of
|
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
|
* MA 02111-1307 USA
|
|
|
|
|
*/
|
|
|
|
|
|
2003-06-27 21:31:46 +00:00
|
|
|
|
#include <common.h>
|
|
|
|
|
#include <pci.h>
|
2009-05-16 10:14:54 +00:00
|
|
|
|
#include <stdio_dev.h>
|
2003-05-31 18:35:21 +00:00
|
|
|
|
#include <i8042.h>
|
2003-06-27 21:31:46 +00:00
|
|
|
|
#include <asm/ptrace.h>
|
|
|
|
|
#include <asm/realmode.h>
|
|
|
|
|
#include <asm/io.h>
|
|
|
|
|
#include <asm/pci.h>
|
2003-05-31 18:35:21 +00:00
|
|
|
|
|
|
|
|
|
/* basic textmode I/O from linux kernel */
|
|
|
|
|
static char *vidmem = (char *)0xb8000;
|
|
|
|
|
static int vidport;
|
|
|
|
|
static int lines, cols;
|
|
|
|
|
static int orig_x, orig_y;
|
|
|
|
|
|
|
|
|
|
static void beep(int dur)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
2003-06-27 21:31:46 +00:00
|
|
|
|
|
2003-05-31 18:35:21 +00:00
|
|
|
|
outb_p(3, 0x61);
|
2011-04-13 09:43:26 +00:00
|
|
|
|
for (i = 0; i < 10*dur; i++)
|
2003-05-31 18:35:21 +00:00
|
|
|
|
udelay(1000);
|
2011-04-13 09:43:26 +00:00
|
|
|
|
|
2003-05-31 18:35:21 +00:00
|
|
|
|
outb_p(0, 0x61);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void scroll(void)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
2011-04-13 09:43:26 +00:00
|
|
|
|
memcpy(vidmem, vidmem + cols * 2, (lines - 1) * cols * 2);
|
|
|
|
|
for (i = (lines - 1) * cols * 2; i < lines * cols * 2; i += 2)
|
2003-05-31 18:35:21 +00:00
|
|
|
|
vidmem[i] = ' ';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void __video_putc(const char c, int *x, int *y)
|
|
|
|
|
{
|
|
|
|
|
if (c == '\n') {
|
2003-06-27 21:31:46 +00:00
|
|
|
|
(*x) = 0;
|
2011-04-13 09:43:26 +00:00
|
|
|
|
if (++(*y) >= lines) {
|
2003-05-31 18:35:21 +00:00
|
|
|
|
scroll();
|
|
|
|
|
(*y)--;
|
|
|
|
|
}
|
2003-06-27 21:31:46 +00:00
|
|
|
|
} else if (c == '\b') {
|
2003-05-31 18:35:21 +00:00
|
|
|
|
if ((*x) != 0) {
|
|
|
|
|
--(*x);
|
2011-04-13 09:43:26 +00:00
|
|
|
|
vidmem[((*x) + cols * (*y)) * 2] = ' ';
|
2003-05-31 18:35:21 +00:00
|
|
|
|
}
|
2003-06-27 21:31:46 +00:00
|
|
|
|
} else if (c == '\r') {
|
2003-05-31 18:35:21 +00:00
|
|
|
|
(*x) = 0;
|
2003-06-27 21:31:46 +00:00
|
|
|
|
|
|
|
|
|
} else if (c == '\a') {
|
2003-05-31 18:35:21 +00:00
|
|
|
|
beep(3);
|
2003-06-27 21:31:46 +00:00
|
|
|
|
|
|
|
|
|
} else if (c == '\t') {
|
2003-05-31 18:35:21 +00:00
|
|
|
|
__video_putc(' ', x, y);
|
|
|
|
|
__video_putc(' ', x, y);
|
|
|
|
|
__video_putc(' ', x, y);
|
|
|
|
|
__video_putc(' ', x, y);
|
|
|
|
|
__video_putc(' ', x, y);
|
|
|
|
|
__video_putc(' ', x, y);
|
|
|
|
|
__video_putc(' ', x, y);
|
|
|
|
|
__video_putc(' ', x, y);
|
2003-06-27 21:31:46 +00:00
|
|
|
|
} else if (c == '\v') {
|
2003-05-31 18:35:21 +00:00
|
|
|
|
switch ((*x) % 8) {
|
|
|
|
|
case 0:
|
|
|
|
|
__video_putc(' ', x, y);
|
|
|
|
|
case 7:
|
|
|
|
|
__video_putc(' ', x, y);
|
|
|
|
|
case 6:
|
|
|
|
|
__video_putc(' ', x, y);
|
|
|
|
|
case 5:
|
|
|
|
|
__video_putc(' ', x, y);
|
|
|
|
|
case 4:
|
|
|
|
|
__video_putc(' ', x, y);
|
|
|
|
|
case 3:
|
|
|
|
|
__video_putc(' ', x, y);
|
|
|
|
|
case 2:
|
|
|
|
|
__video_putc(' ', x, y);
|
|
|
|
|
case 1:
|
|
|
|
|
__video_putc(' ', x, y);
|
|
|
|
|
}
|
2003-06-27 21:31:46 +00:00
|
|
|
|
} else if (c == '\f') {
|
2003-05-31 18:35:21 +00:00
|
|
|
|
int i;
|
2011-04-13 09:43:26 +00:00
|
|
|
|
for (i = 0; i < lines * cols * 2; i += 2)
|
2003-05-31 18:35:21 +00:00
|
|
|
|
vidmem[i] = 0;
|
|
|
|
|
(*x) = 0;
|
|
|
|
|
(*y) = 0;
|
|
|
|
|
} else {
|
2011-04-13 09:43:26 +00:00
|
|
|
|
vidmem[((*x) + cols * (*y)) * 2] = c;
|
|
|
|
|
if (++(*x) >= cols) {
|
2003-05-31 18:35:21 +00:00
|
|
|
|
(*x) = 0;
|
2011-04-13 09:43:26 +00:00
|
|
|
|
if (++(*y) >= lines) {
|
2003-05-31 18:35:21 +00:00
|
|
|
|
scroll();
|
|
|
|
|
(*y)--;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void video_putc(const char c)
|
|
|
|
|
{
|
|
|
|
|
int x,y,pos;
|
2003-06-27 21:31:46 +00:00
|
|
|
|
|
2003-05-31 18:35:21 +00:00
|
|
|
|
x = orig_x;
|
|
|
|
|
y = orig_y;
|
2003-06-27 21:31:46 +00:00
|
|
|
|
|
2003-05-31 18:35:21 +00:00
|
|
|
|
__video_putc(c, &x, &y);
|
|
|
|
|
|
|
|
|
|
orig_x = x;
|
|
|
|
|
orig_y = y;
|
2003-06-27 21:31:46 +00:00
|
|
|
|
|
2003-05-31 18:35:21 +00:00
|
|
|
|
pos = (x + cols * y) * 2; /* Update cursor position */
|
|
|
|
|
outb_p(14, vidport);
|
|
|
|
|
outb_p(0xff & (pos >> 9), vidport+1);
|
|
|
|
|
outb_p(15, vidport);
|
|
|
|
|
outb_p(0xff & (pos >> 1), vidport+1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void video_puts(const char *s)
|
|
|
|
|
{
|
|
|
|
|
int x,y,pos;
|
|
|
|
|
char c;
|
|
|
|
|
|
|
|
|
|
x = orig_x;
|
|
|
|
|
y = orig_y;
|
|
|
|
|
|
2011-04-13 09:43:26 +00:00
|
|
|
|
while ((c = *s++) != '\0')
|
2003-05-31 18:35:21 +00:00
|
|
|
|
__video_putc(c, &x, &y);
|
|
|
|
|
|
|
|
|
|
orig_x = x;
|
|
|
|
|
orig_y = y;
|
|
|
|
|
|
|
|
|
|
pos = (x + cols * y) * 2; /* Update cursor position */
|
|
|
|
|
outb_p(14, vidport);
|
|
|
|
|
outb_p(0xff & (pos >> 9), vidport+1);
|
|
|
|
|
outb_p(15, vidport);
|
|
|
|
|
outb_p(0xff & (pos >> 1), vidport+1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int video_init(void)
|
|
|
|
|
{
|
|
|
|
|
u16 pos;
|
2003-06-27 21:31:46 +00:00
|
|
|
|
|
2009-05-16 10:14:54 +00:00
|
|
|
|
static struct stdio_dev vga_dev;
|
|
|
|
|
static struct stdio_dev kbd_dev;
|
2003-06-27 21:31:46 +00:00
|
|
|
|
|
2003-05-31 18:35:21 +00:00
|
|
|
|
vidmem = (char *) 0xb8000;
|
|
|
|
|
vidport = 0x3d4;
|
|
|
|
|
|
|
|
|
|
lines = 25;
|
|
|
|
|
cols = 80;
|
2003-06-27 21:31:46 +00:00
|
|
|
|
|
2003-05-31 18:35:21 +00:00
|
|
|
|
outb_p(14, vidport);
|
|
|
|
|
pos = inb_p(vidport+1);
|
|
|
|
|
pos <<= 8;
|
|
|
|
|
outb_p(15, vidport);
|
|
|
|
|
pos |= inb_p(vidport+1);
|
2003-06-27 21:31:46 +00:00
|
|
|
|
|
2003-05-31 18:35:21 +00:00
|
|
|
|
orig_x = pos%cols;
|
|
|
|
|
orig_y = pos/cols;
|
|
|
|
|
|
2003-06-27 21:31:46 +00:00
|
|
|
|
#if 0
|
2003-05-31 18:35:21 +00:00
|
|
|
|
printf("pos %x %d %d\n", pos, orig_x, orig_y);
|
2003-06-27 21:31:46 +00:00
|
|
|
|
#endif
|
2011-04-13 09:43:26 +00:00
|
|
|
|
if (orig_y > lines)
|
2003-05-31 18:35:21 +00:00
|
|
|
|
orig_x = orig_y =0;
|
2003-06-27 21:31:46 +00:00
|
|
|
|
|
2003-05-31 18:35:21 +00:00
|
|
|
|
memset(&vga_dev, 0, sizeof(vga_dev));
|
2003-06-27 21:31:46 +00:00
|
|
|
|
strcpy(vga_dev.name, "vga");
|
|
|
|
|
vga_dev.ext = 0;
|
|
|
|
|
vga_dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_SYSTEM;
|
|
|
|
|
vga_dev.putc = video_putc; /* 'putc' function */
|
|
|
|
|
vga_dev.puts = video_puts; /* 'puts' function */
|
|
|
|
|
vga_dev.tstc = NULL; /* 'tstc' function */
|
|
|
|
|
vga_dev.getc = NULL; /* 'getc' function */
|
|
|
|
|
|
2011-04-13 09:43:26 +00:00
|
|
|
|
if (stdio_register(&vga_dev) == 0)
|
|
|
|
|
return 1;
|
2003-06-27 21:31:46 +00:00
|
|
|
|
|
2011-04-13 09:43:26 +00:00
|
|
|
|
if (i8042_kbd_init())
|
2003-05-31 18:35:21 +00:00
|
|
|
|
return 1;
|
2003-06-27 21:31:46 +00:00
|
|
|
|
|
2003-05-31 18:35:21 +00:00
|
|
|
|
memset(&kbd_dev, 0, sizeof(kbd_dev));
|
2003-06-27 21:31:46 +00:00
|
|
|
|
strcpy(kbd_dev.name, "kbd");
|
|
|
|
|
kbd_dev.ext = 0;
|
|
|
|
|
kbd_dev.flags = DEV_FLAGS_INPUT | DEV_FLAGS_SYSTEM;
|
|
|
|
|
kbd_dev.putc = NULL; /* 'putc' function */
|
|
|
|
|
kbd_dev.puts = NULL; /* 'puts' function */
|
|
|
|
|
kbd_dev.tstc = i8042_tstc; /* 'tstc' function */
|
|
|
|
|
kbd_dev.getc = i8042_getc; /* 'getc' function */
|
|
|
|
|
|
2011-04-13 09:43:26 +00:00
|
|
|
|
if (stdio_register(&kbd_dev) == 0)
|
|
|
|
|
return 1;
|
|
|
|
|
|
2003-05-31 18:35:21 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-06-27 21:31:46 +00:00
|
|
|
|
int drv_video_init(void)
|
2003-05-31 18:35:21 +00:00
|
|
|
|
{
|
2011-04-13 09:43:26 +00:00
|
|
|
|
if (video_bios_init())
|
2003-05-31 18:35:21 +00:00
|
|
|
|
return 1;
|
2003-06-27 21:31:46 +00:00
|
|
|
|
|
|
|
|
|
return video_init();
|
2003-05-31 18:35:21 +00:00
|
|
|
|
}
|