Skip to content

Commit

Permalink
[kernel] Updates to console code from #1980
Browse files Browse the repository at this point in the history
  • Loading branch information
ghaerr committed Sep 16, 2024
1 parent 4d2fdee commit 3ca8ff3
Show file tree
Hide file tree
Showing 13 changed files with 92 additions and 96 deletions.
1 change: 1 addition & 0 deletions elks/arch/i86/defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ CONFIG_CONSOLE_DIRECT=y
# CONFIG_CONSOLE_BIOS is not set
# CONFIG_CONSOLE_HEADLESS is not set
CONFIG_KEYBOARD_SCANCODE=y
# CONFIG_CONSOLE_DUAL is not set
# CONFIG_CONSOLE_SERIAL is not set
CONFIG_EMUL_ANSI=y
# CONFIG_KEYMAP_BE is not set
Expand Down
2 changes: 1 addition & 1 deletion elks/arch/i86/drivers/char/config.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ mainmenu_option next_comment
Headless CONFIG_CONSOLE_HEADLESS" Direct
if [ "$CONFIG_CONSOLE_DIRECT" = "y" ]; then
bool ' Scancode keyboard driver' CONFIG_KEYBOARD_SCANCODE y
bool ' Dual-screen console support' CONFIG_CONSOLE_DUAL n
bool ' Dual-screen console support' CONFIG_CONSOLE_DUAL n
fi
bool 'Serial Console' CONFIG_CONSOLE_SERIAL n
if [[ "$CONFIG_CONSOLE_DIRECT" = "y" || "$CONFIG_CONSOLE_BIOS" = "y" ]]; then
Expand Down
2 changes: 1 addition & 1 deletion elks/arch/i86/drivers/char/conio-pc98-asm.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* conio functions for PC-98 */

/* put character on text vram */
void early_putchar(int c);
/*void early_putchar(int c);*/

/* get character data from keyboard */
int bios_getchar(void);
Expand Down
2 changes: 1 addition & 1 deletion elks/arch/i86/drivers/char/conio-pc98.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

#include <linuxmt/config.h>
#include <linuxmt/types.h>
#include <linuxmt/kernel.h>
#include "conio-pc98-asm.h"

void conio_init()
Expand Down
11 changes: 5 additions & 6 deletions elks/arch/i86/drivers/char/console-bios.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,14 @@ struct console;
typedef struct console Console;

struct console {
int Width, Height;
int cx, cy; /* cursor position */
void (*fsm)(Console *, int);
unsigned char display;
unsigned char attr; /* current attribute */
unsigned char XN; /* delayed newline on column 80 */
unsigned char color; /* fg/bg attr */
void (*fsm)(Console *, int);
int pageno; /* video ram page # */
unsigned short Width;
unsigned short Height;
#ifdef CONFIG_EMUL_ANSI
int savex, savey; /* saved cursor position */
unsigned char *parmptr; /* ptr to params */
Expand Down Expand Up @@ -90,9 +89,10 @@ static void PositionCursor(register Console * C)
bios_setcursor (x, y, p);
}

static void PositionCursorGet (int * x, int * y)
static void PositionCursorGet(int * x, int * y)
{
byte_t col, row;

bios_getcursor (&col, &row);
*x = col;
*y = row;
Expand Down Expand Up @@ -174,10 +174,9 @@ struct tty_ops bioscon_ops = {

void INITPROC console_init(void)
{
Console *C;
Console *C = &Con[0];
int i;

C = Con;
C->Width = SETUP_VID_COLS;
C->Height = SETUP_VID_LINES;

Expand Down
21 changes: 10 additions & 11 deletions elks/arch/i86/drivers/char/console-direct-pc98.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ struct console;
typedef struct console Console;

struct console {
int Width, Height;
int cx, cy; /* cursor position */
void (*fsm)(Console *, int);
unsigned char display;
unsigned char unused;
unsigned char attr; /* current attribute */
unsigned char XN; /* delayed newline on column 80 */
void (*fsm)(Console *, int);
unsigned int vseg; /* vram for this console page */
int vseg_offset; /* vram offset of vseg for this console page */
unsigned short Width;
unsigned short Height;
unsigned int vseg_offset; /* vram offset of vseg for this console page */
#ifdef CONFIG_EMUL_ANSI
int savex, savey; /* saved cursor position */
unsigned char *parmptr; /* ptr to params */
Expand Down Expand Up @@ -144,7 +144,7 @@ static void VideoWrite(register Console * C, int c)

static void ClearRange(register Console * C, int x, int y, int xx, int yy)
{
register __u16 *vp;
__u16 *vp;
word_t attr;

attr = (C->attr == A_DEFAULT) ? A98_DEFAULT : conv_pcattr(C->attr);
Expand All @@ -163,8 +163,8 @@ static void ClearRange(register Console * C, int x, int y, int xx, int yy)
static void ScrollUp(register Console * C, int y)
{
__u16 *vp;
unsigned short MaxRow = C->Height - 1;
unsigned short MaxCol = C->Width - 1;
int MaxRow = C->Height - 1;
int MaxCol = C->Width - 1;

vp = (__u16 *)((__u16)(y * C->Width) << 1);
if ((unsigned int)y < MaxRow) {
Expand All @@ -178,8 +178,8 @@ static void ScrollUp(register Console * C, int y)
static void ScrollDown(register Console * C, int y)
{
__u16 *vp;
unsigned short MaxRow = C->Height - 1;
unsigned short MaxCol = C->Width - 1;
int MaxRow = C->Height - 1;
int MaxCol = C->Width - 1;
int yy = MaxRow;

vp = (__u16 *)((__u16)(yy * C->Width) << 1);
Expand Down Expand Up @@ -221,7 +221,7 @@ struct tty_ops dircon_ops = {

void INITPROC console_init(void)
{
Console *C;
Console *C = &Con[0];
int i;
unsigned PageSizeW;

Expand All @@ -233,7 +233,6 @@ void INITPROC console_init(void)
AttributeSeg = 0xE200;
}

C = Con;
C->Width = 80;
C->Height = 25;

Expand Down
45 changes: 25 additions & 20 deletions elks/arch/i86/drivers/char/console-direct.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,15 @@ struct console;
typedef struct console Console;

struct console {
int Width, Height;
int cx, cy; /* cursor position */
void (*fsm)(Console *, int);
unsigned char display;
unsigned char type;
unsigned char attr; /* current attribute */
unsigned char XN; /* delayed newline on column 80 */
void (*fsm)(Console *, int);
unsigned int vseg; /* vram for this console page */
int vseg_offset; /* vram offset of vseg for this console page */
unsigned short Width;
unsigned short Height;
unsigned short crtc_base; /* 6845 CRTC base I/O address */
#ifdef CONFIG_EMUL_ANSI
int savex, savey; /* saved cursor position */
Expand All @@ -77,8 +76,8 @@ static Console *Visible[MAX_DISPLAYS];
static Console Con[MAX_CONSOLES];
static int NumConsoles;

unsigned int VideoSeg = 0xb800;
int Current_VCminor;
unsigned VideoSeg;
int kraw;

#ifdef CONFIG_EMUL_ANSI
Expand Down Expand Up @@ -128,7 +127,7 @@ static void VideoWrite(register Console * C, int c)

static void ClearRange(register Console * C, int x, int y, int x2, int y2)
{
register int vp;
int vp;

x2 = x2 - x + 1;
vp = (x + y * C->Width) << 1;
Expand All @@ -143,9 +142,9 @@ static void ClearRange(register Console * C, int x, int y, int x2, int y2)

static void ScrollUp(register Console * C, int y)
{
register int vp;
unsigned short MaxRow = C->Height - 1;
unsigned short MaxCol = C->Width - 1;
int vp;
int MaxRow = C->Height - 1;
int MaxCol = C->Width - 1;

vp = y * (C->Width << 1);
if ((unsigned int)y < MaxRow)
Expand All @@ -157,7 +156,7 @@ static void ScrollUp(register Console * C, int y)
#ifdef CONFIG_EMUL_ANSI
static void ScrollDown(register Console * C, int y)
{
register int vp;
int vp;
int yy = C->Height - 1;

vp = yy * (C->Width << 1);
Expand Down Expand Up @@ -200,26 +199,31 @@ struct tty_ops dircon_ops = {
};

#ifndef CONFIG_CONSOLE_DUAL

#ifdef DEBUG
static const char *type_string[] = {
"MDA",
"CGA",
"EGA",
"VGA",
};
#endif

void INITPROC console_init(void)
{
Console *C;
unsigned char output_type;
unsigned short boot_crtc;
Console *C = &Con[0];
int i;
int Width, Height;
unsigned int PageSizeW;

output_type = OT_EGA;
C = &Con[0];
unsigned short boot_crtc;
unsigned char output_type = OT_EGA;

Width = peekb(0x4a, 0x40); /* BIOS data segment */

/* Trust this. Cga does not support peeking at 0x40:0x84. */
Height = 25;
boot_crtc = peekw(0x63, 0x40);
PageSizeW = ((unsigned int)peekw(0x4C, 0x40) >> 1);

VideoSeg = 0xb800;
NumConsoles = MAX_CONSOLES - 1;
if (peekb(0x49, 0x40) == 7) {
VideoSeg = 0xB000;
Expand Down Expand Up @@ -266,17 +270,17 @@ void INITPROC console_init(void)
#else
void INITPROC console_init(void)
{
Console *C;
Console *C = &Con[0];
int i, j, dev;
unsigned short boot_crtc;
unsigned char boot_type;
unsigned char screens = 0;
unsigned char cur_display = 0;

boot_crtc = peekw(0x63, 0x40);
for (i = 0; i < N_DEVICETYPES; ++i)
if (crtc_params[i].crtc_base == boot_crtc) boot_type = i;

C = &Con[0];
for (i = 0; i < N_DEVICETYPES; ++i) {
dev = (i + boot_type) % N_DEVICETYPES;
if (!crtc_probe(crtc_params[dev].crtc_base)) continue;
Expand Down Expand Up @@ -312,7 +316,8 @@ void INITPROC console_init(void)
VideoSeg = Visible[0]->vseg;

kbd_init();
printk("Direct console %s kbd"TERM_TYPE"(%d screens, %i consoles)\n", kbd_name, screens, NumConsoles);
printk("Direct console %s kbd"TERM_TYPE"(%d screens, %i consoles)\n",
kbd_name, screens, NumConsoles);
for (i = 0; i < NumConsoles; ++i) {
debug("/dev/tty%i, %s, %ux%u\n", i + 1, type_string[Con[i].type], Con[i].Width, Con[i].Height);
}
Expand Down
21 changes: 11 additions & 10 deletions elks/arch/i86/drivers/char/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void Console_conout(dev_t dev, int Ch)

void Console_conin(unsigned char Key)
{
register struct tty *ttyp = &ttys[Current_VCminor];
struct tty *ttyp = &ttys[Current_VCminor];

if (!tty_intcheck(ttyp, Key))
chq_addch(&ttyp->inq, Key);
Expand All @@ -32,9 +32,9 @@ void Console_conin(unsigned char Key)
#ifdef CONFIG_EMUL_ANSI
static void Console_gotoxy(register Console * C, int x, int y)
{
register int xp = x;
unsigned short MaxRow = C->Height - 1;
unsigned short MaxCol = C->Width - 1;
int xp = x;
int MaxRow = C->Height - 1;
int MaxCol = C->Width - 1;

C->cx = (xp >= MaxCol) ? MaxCol : (xp < 0) ? 0 : xp;
xp = y;
Expand Down Expand Up @@ -82,8 +82,8 @@ static unsigned char ega_color[16] = { 0, 4, 2, 6, 1, 5, 3, 7,
static void AnsiCmd(register Console * C, int c)
{
int n;
unsigned short MaxRow = C->Height - 1;
unsigned short MaxCol = C->Width - 1;
int MaxRow = C->Height - 1;
int MaxCol = C->Width - 1;

/* ANSI param gathering and processing */
if (C->parmptr < &C->params[MAXPARMS - 1])
Expand Down Expand Up @@ -254,8 +254,9 @@ static void esc_char(register Console * C, int c)
/* Normal character processing */
static void std_char(register Console * C, int c)
{
unsigned short MaxRow = C->Height - 1;
unsigned short MaxCol = C->Width - 1;
int MaxRow = C->Height - 1;
int MaxCol = C->Width - 1;

switch(c) {
case BEL:
bell();
Expand Down Expand Up @@ -319,7 +320,7 @@ static void std_char(register Console * C, int c)

static int Console_ioctl(struct tty *tty, int cmd, char *arg)
{
register Console *C = &Con[tty->minor];
Console *C = &Con[tty->minor];

switch (cmd) {
case DCGET_GRAPH:
Expand Down Expand Up @@ -367,7 +368,7 @@ static int Console_ioctl(struct tty *tty, int cmd, char *arg)

static int Console_write(register struct tty *tty)
{
register Console *C = &Con[tty->minor];
Console *C = &Con[tty->minor];
int cnt = 0;

while ((tty->outq.len > 0) && !glock) {
Expand Down
30 changes: 25 additions & 5 deletions elks/arch/i86/drivers/char/crtc-6845.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,27 @@
#define CRTC_CSEL 0x5
#define CRTC_STAT 0x6

struct hw_params crtc_params[N_DEVICETYPES] = {
{ 80, 25, 0x3B4, 0xB000, 0x1000, 2000, 1, 16, /* MDA */
{
0x61, 0x50, 0x52, 0x0F,
0x19, 0x06, 0x19, 0x19,
0x02, 0x0D, 0x0B, 0x0C,
0x00, 0x00, 0x00, 0x00,
}
},
{ 80, 25, 0x3D4, 0xB800, 0x4000, 2000, 3, 16, /* CGA */
{
/* CO80 */
0x71, 0x50, 0x5A, 0x0A,
0x1F, 0x06, 0x19, 0x1C,
0x02, 0x07, 0x06, 0x07,
0x00, 0x00, 0x00, 0x00,
}
}
/* EGA (TODO) */
};

/* Check to see if this CRTC is present */
int INITPROC crtc_probe(unsigned short crtc_base)
{
Expand All @@ -42,10 +63,11 @@ int INITPROC crtc_probe(unsigned short crtc_base)
return 1;
}

int INITPROC crtc_init(unsigned int t)
void INITPROC crtc_init(int dev)
{
int i;
struct hw_params *p = &crtc_params[t];
struct hw_params *p = &crtc_params[dev];

/* Set 80x25 mode, video off */
outb(0x01, p->crtc_base + CRTC_MODE);
/* Program CRTC regs */
Expand All @@ -60,10 +82,8 @@ int INITPROC crtc_init(unsigned int t)
for (i = 0; i < p->vseg_bytes; i += 2)
if (peekw(i, p->vseg_base) != 0x5555) return 1;
for (i = 0; i < p->vseg_bytes; i += 2)
pokew(i, p->vseg_base, 0x7 << 8 | ' ');
pokew(i, p->vseg_base, 0x07 << 8 | ' ');

/* Enable video */
outb(0x09, p->crtc_base + CRTC_MODE);
return 0;
}

Loading

0 comments on commit 3ca8ff3

Please sign in to comment.