Skip to content

Commit

Permalink
Merge pull request #2017 from ghaerr/console
Browse files Browse the repository at this point in the history
[kernel] Updates to console code from #1980
  • Loading branch information
ghaerr authored Sep 16, 2024
2 parents 4d2fdee + 88fe778 commit 665340a
Show file tree
Hide file tree
Showing 13 changed files with 115 additions and 113 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
23 changes: 11 additions & 12 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 @@ -95,7 +95,7 @@ static void SetDisplayPage(register Console * C)

static void PositionCursor(register Console * C)
{
int Pos;
unsigned int Pos;

Pos = C->cx + C->Width * C->cy + C->vseg_offset;
cursor_set(Pos * 2);
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
63 changes: 35 additions & 28 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 int vseg_offset; /* vram offset of vseg for this console page */
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 @@ -202,24 +201,19 @@ struct tty_ops dircon_ops = {
#ifndef CONFIG_CONSOLE_DUAL
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 @@ -264,22 +258,34 @@ void INITPROC console_init(void)
kbd_name, Width, Height, NumConsoles);
}
#else

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

void INITPROC console_init(void)
{
Console *C;
Console *C = &Con[0];
int i, j, dev;
int screens = 0;
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;
unsigned char boot_type;

C = &Con[0];
boot_crtc = peekw(0x63, 0x40);
for (i = 0; i < N_DEVICETYPES; ++i) {
if (crtc_params[i].crtc_base == boot_crtc)
boot_type = i;
}
for (i = 0; i < N_DEVICETYPES; ++i) {
dev = (i + boot_type) % N_DEVICETYPES;
if (!crtc_probe(crtc_params[dev].crtc_base)) continue;
if (!crtc_probe(crtc_params[dev].crtc_base))
continue;
screens++;
crtc_init(dev);
for (j = 0; j < crtc_params[dev].max_pages; ++j) {
Expand Down Expand Up @@ -312,9 +318,10 @@ 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, %d 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);
debug("/dev/tty%d, %s, %ux%u\n", i + 1, type_string[Con[i].type], Con[i].Width, Con[i].Height);
}
}
#endif
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
Loading

0 comments on commit 665340a

Please sign in to comment.