Skip to content

Commit

Permalink
pc-tty: resize current vt to max fbcon resolution
Browse files Browse the repository at this point in the history
Current vt will now automatically resize from 80x25 to the maximum
resolution supported by current graphic mode if fbcon is enabled
(i.e. for 1280x800 and 8x16 font it will resize to 160x50)

JIRA: RTOS-925
  • Loading branch information
adamgreloch committed Oct 4, 2024
1 parent 965b289 commit 2654383
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 30 deletions.
24 changes: 18 additions & 6 deletions tty/pc-tty/ttypc.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,22 +133,34 @@ int main(void)
if ((err = mutexCreate(&ttypc_common.lock)) < 0)
return err;

/* Initialize VGA display */
if ((err = ttypc_vga_init(&ttypc_common)) < 0)
return err;

/* Initialize VTs */
for (i = 0; i < NVTS; i++) {
if ((err = ttypc_vt_init(&ttypc_common, _PAGE_SIZE, ttypc_common.vts + i)) < 0)
if ((err = ttypc_vt_init(&ttypc_common, ttypc_common.memsz, ttypc_common.vts + i)) < 0)
return err;
}

/* Initialize VGA display */
if ((err = ttypc_vga_init(&ttypc_common)) < 0)
return err;

/* Set active virtual terminal */
ttypc_common.vt = ttypc_common.vts;
ttypc_common.vt->vram = ttypc_common.vga;

if (ttypc_common.vt->fbmode == TTY_FBCON_ENABLED) {
/* Resize active virtual terminal to match fbcon maximum resolution */
ttypc_vt_resize(ttypc_common.vt, ttypc_common.fbmaxcols, ttypc_common.fbmaxrows);
}

/* Initialize cursor */
_ttypc_vga_getcursor(ttypc_common.vt);
if (ttypc_common.vt->fbmode == TTY_FBCON_DISABLED) {
/* If fbcon is not available, retrieve the cursor so we don't overwrite the tty as
* some earlier component might have written something to the text mode buffer (i.e. plo) */
_ttypc_vga_getcursor(ttypc_common.vt);
}
/* else: In case of fbcon, we don't care about the text mode buffer, because we're
* in the graphic mode already and the text mode buffer may contain garbage */

/* Set default cursor color */
_ttypc_vga_set(ttypc_common.vt, ttypc_common.vt->vram + ttypc_common.vt->cpos, FG_LIGHTGREY << 8, ttypc_common.vt->rows * ttypc_common.vt->cols - ttypc_common.vt->cpos);

Expand Down
5 changes: 3 additions & 2 deletions tty/pc-tty/ttypc.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ struct _ttypc_t {

/* VGA */
volatile void *vga; /* VGA screen memory */
uint32_t memsz; /* VGA screen memory size */
void *crtc; /* Video Display Controller (CRTC) */
unsigned color; /* Color support */

Expand Down Expand Up @@ -77,8 +78,8 @@ struct _ttypc_t {
/* Framebuffer console */
uint16_t fbw; /* Width in pixels */
uint16_t fbh; /* Height in pixels */
int16_t fbcols; /* Console columns count */
int16_t fbrows; /* Console rows count */
int16_t fbmaxcols; /* Maximum console columns count */
int16_t fbmaxrows; /* Maximum console rows count */
uint16_t fbbpp; /* Bits per pixel */
uint16_t fbpitch; /* Pitch (framebuffer line length)*/
volatile void *fbaddr; /* Framebuffer address */
Expand Down
5 changes: 2 additions & 3 deletions tty/pc-tty/ttypc_fbcon.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,8 @@ int ttypc_fbcon_init(ttypc_t *ttypc)
ttypc->fbbpp = pctl.graphmode.bpp;
ttypc->fbpitch = pctl.graphmode.pitch;

/* TODO use fbcols, fbrows to operate in higher resolutions than 80x25 in tty/vt */
ttypc->fbcols = ttypc->fbw / TTYPC_FBFONT_W;
ttypc->fbrows = ttypc->fbh / TTYPC_FBFONT_H;
ttypc->fbmaxcols = ttypc->fbw / TTYPC_FBFONT_W;
ttypc->fbmaxrows = ttypc->fbh / TTYPC_FBFONT_H;

return EOK;
}
Expand Down
22 changes: 13 additions & 9 deletions tty/pc-tty/ttypc_vga.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ void _ttypc_vga_switch(ttypc_vt_t *vt)
_ttypc_vga_read(cvt->vram, cvt->mem, cvt->rows * cvt->cols);
cvt->vram = cvt->mem;

if (vt->fbmode == TTY_FBCON_ENABLED) {
/* Resize the virtual terminal to match fbcon maximum resolution */
ttypc_vt_resize(vt, vt->ttypc->fbmaxcols, vt->ttypc->fbmaxrows);
}

mutexLock(vt->lock);
/* VT memory -> VGA memory */
vt->vram = ttypc->vga;
Expand All @@ -210,7 +215,7 @@ void _ttypc_vga_switch(ttypc_vt_t *vt)
/* Returns scrollback capacity in lines */
static unsigned int _ttypc_vga_scrollbackcapacity(ttypc_vt_t *vt)
{
return (SCRB_PAGES * (vt->cols * vt->rows + _PAGE_SIZE - 1) & ~(_PAGE_SIZE - 1)) / (vt->cols * CHR_VGA);
return (SCRB_PAGES * vt->buffsz) / (vt->cols * CHR_VGA);
}


Expand Down Expand Up @@ -368,34 +373,33 @@ void _ttypc_vga_togglecursor(ttypc_vt_t *vt, uint8_t state)
void ttypc_vga_destroy(ttypc_t *ttypc)
{
ttypc_fbcon_destroy(ttypc);
munmap((void *)ttypc->vga, _PAGE_SIZE);
munmap((void *)ttypc->vga, ttypc->memsz);
}


int ttypc_vga_init(ttypc_t *ttypc)
{
int memsz;

/* Test monitor type */
ttypc->color = inb((void *)GN_MISCOUTR) & 0x01;
ttypc->crtc = (ttypc->color) ? (void *)CRTC_COLOR : (void *)CRTC_MONO;

if (ttypc_fbcon_init(ttypc) < 0) {
/* Map video memory */
ttypc->vga = mmap(NULL, _PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_PHYSMEM | MAP_ANONYMOUS, -1, (ttypc->color) ? VGA_COLOR : VGA_MONO);
ttypc->memsz = _PAGE_SIZE;
ttypc->vga = mmap(NULL, ttypc->memsz, PROT_READ | PROT_WRITE, MAP_PHYSMEM | MAP_ANONYMOUS, -1, (ttypc->color) ? VGA_COLOR : VGA_MONO);
if (ttypc->vga == MAP_FAILED)
return -ENOMEM;

ttypc->fbaddr = NULL;
ttypc->fbcols = -1;
ttypc->fbrows = -1;
ttypc->fbmaxcols = -1;
ttypc->fbmaxrows = -1;
}
else {
/* Map general purpose memory, not video memory. If fbcon is present, then we're
* in graphics mode already, so the standard VGA_MONO/VGA_COLOR framebuffers can
* be inactive and contain garbage. */
memsz = (ttypc->fbcols * ttypc->fbrows + _PAGE_SIZE - 1) & ~(_PAGE_SIZE - 1);
ttypc->vga = mmap(NULL, memsz, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
ttypc->memsz = (ttypc->fbmaxcols * ttypc->fbmaxrows * CHR_VGA + _PAGE_SIZE - 1) & ~(_PAGE_SIZE - 1);
ttypc->vga = mmap(NULL, ttypc->memsz, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (ttypc->vga == MAP_FAILED) {
ttypc_fbcon_destroy(ttypc);
return -ENOMEM;
Expand Down
35 changes: 25 additions & 10 deletions tty/pc-tty/ttypc_vt.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <errno.h>
#include <stdint.h>
#include <string.h>
#include <signal.h>

#include <sys/mman.h>
#include <sys/threads.h>
Expand Down Expand Up @@ -711,6 +712,18 @@ static void _ttypc_vt_signaltxready(void *arg)
}


void ttypc_vt_resize(ttypc_vt_t *vt, uint8_t cols, uint8_t rows)
{
vt->tty.ws.ws_col = cols;
vt->tty.ws.ws_row = rows;
libtty_signal_pgrp(&vt->tty, SIGWINCH);

vt->cols = cols;
vt->rows = rows;
_ttypc_vtf_str(vt);
}


int ttypc_vt_init(ttypc_t *ttypc, unsigned int ttybuffsz, ttypc_vt_t *vt)
{
libtty_callbacks_t cb = {
Expand All @@ -724,39 +737,41 @@ int ttypc_vt_init(ttypc_t *ttypc, unsigned int ttybuffsz, ttypc_vt_t *vt)
if ((err = mutexCreate(&vt->lock)) < 0)
return err;

vt->mem = mmap(NULL, _PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
vt->mem = mmap(NULL, ttybuffsz, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (vt->mem == MAP_FAILED) {
resourceDestroy(vt->lock);
return -ENOMEM;
}
vt->vram = vt->mem;

if (SCRB_PAGES) {
vt->scro = mmap(NULL, _PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
vt->scro = mmap(NULL, ttybuffsz, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (vt->scro == MAP_FAILED) {
resourceDestroy(vt->lock);
munmap(vt->mem, _PAGE_SIZE);
munmap(vt->mem, ttybuffsz);
return -ENOMEM;
}
vt->scrb = mmap(NULL, SCRB_PAGES * _PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
vt->scrb = mmap(NULL, SCRB_PAGES * ttybuffsz, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (vt->scrb == MAP_FAILED) {
resourceDestroy(vt->lock);
munmap(vt->mem, _PAGE_SIZE);
munmap(vt->scro, _PAGE_SIZE);
munmap(vt->mem, ttybuffsz);
munmap(vt->scro, ttybuffsz);
return -ENOMEM;
}
}

if ((err = libtty_init(&vt->tty, &cb, ttybuffsz, TTYDEF_SPEED)) < 0) {
resourceDestroy(vt->lock);
munmap(vt->mem, _PAGE_SIZE);
munmap(vt->mem, ttybuffsz);
if (SCRB_PAGES) {
munmap(vt->scro, _PAGE_SIZE);
munmap(vt->scrb, SCRB_PAGES * _PAGE_SIZE);
munmap(vt->scro, ttybuffsz);
munmap(vt->scrb, SCRB_PAGES * ttybuffsz);
}
return err;
}

vt->buffsz = ttybuffsz;

/* Disable default libtty tab expansion */
vt->tty.term.c_oflag &= ~(XTABS);

Expand All @@ -769,7 +784,7 @@ int ttypc_vt_init(ttypc_t *ttypc, unsigned int ttybuffsz, ttypc_vt_t *vt)
/* Clear screen */
_ttypc_vga_set(vt, vt->vram, vt->attr | ' ', vt->cols * vt->rows);

vt->fbmode = ttypc->fbrows != -1 && ttypc->fbcols != -1 ? TTY_FBCON_ENABLED : TTY_FBCON_DISABLED;
vt->fbmode = ttypc->fbmaxrows != -1 && ttypc->fbmaxcols != -1 ? TTY_FBCON_ENABLED : TTY_FBCON_DISABLED;

return EOK;
}
5 changes: 5 additions & 0 deletions tty/pc-tty/ttypc_vt.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ typedef struct {
libtty_common_t tty; /* Terminal character processing (using libtty) */

uint8_t fbmode; /* Framebuffer mode: enabled (0x0) or disabled (0x1) */
uint32_t buffsz; /* Virtual terminal buffer size */

/* Synchronization */
handle_t lock; /* Access lock */
Expand Down Expand Up @@ -160,6 +161,10 @@ extern int ttypc_vt_pollstatus(ttypc_vt_t *vt);
extern int ttypc_vt_ioctl(ttypc_vt_t *vt, pid_t pid, unsigned int cmd, const void *idata, const void **odata);


/* Resizes virtual terminal */
extern void ttypc_vt_resize(ttypc_vt_t *vt, uint8_t cols, uint8_t rows);


/* Destroys virtual terminal */
extern void ttypc_vt_destroy(ttypc_vt_t *vt);

Expand Down

0 comments on commit 2654383

Please sign in to comment.