The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
console.c File Reference

the system console: a tty over either the framebuffer or VGA text. More...

#include "console.h"
#include "fb_console.h"
#include "kernel/tty/tty.h"
#include "kernel/device/device.h"
#include "kernel/sync/mutex.h"
#include "kernel/sync/spinlock.h"
#include "drivers/video/vga/vga.h"
#include "drivers/video/fb/fb.h"
#include "common/string.h"

Macros

#define CONSOLE_VGA_WIDTH   80u
#define CONSOLE_VGA_HEIGHT   25u

Functions

uint32_t console_lock_acquire (void)
 take the console lock, unless a panic is printing.
void console_lock_release (uint32_t flags)
 release the console lock that console_lock_acquire() took.
void console_initialize (const boot_info_t *boot)
 initialize the console driver.
void console_putchar (char c)
 write a single character to the console.
void console_write (const char *str)
 write a null-terminated string to the console.
void console_write_bytes (const char *buf, uint32_t len)
 write a buffer to the console as one update: the whole buffer is drawn, then the caret is placed and the display flushed once.
void console_panic_mode (void)
 stop locking the console: a panic is printing and the CPU will halt, so nothing else runs, and the panic may have hit while the lock was held.
void console_size (uint32_t *rows, uint32_t *cols)
 the size of the console in character cells.

Detailed Description

the system console: a tty over either the framebuffer or VGA text.

console_* is a thin facade. output bytes go through a global tty_t (the terminal state machine in kernel/tty/tty.c), which draws onto whichever backend was selected at init: the framebuffer (JetBrains Mono) when the bootloader set a graphics mode, or the legacy VGA text buffer otherwise. every existing caller (kernel printf, klog, the write syscall) is unchanged.

locking: the tty state (escape parser, cursor, colours, batch depth) and the backend are guarded by console_lock, a spinlock taken around each character, so kernel printf from any context (an IRQ handler included) never sees a half-updated terminal, and interrupts stay masked for one glyph (or one scroll) at a time, never a whole write. writes from processes also hold write_mutex for their whole length, so two processes' output (and their escape sequences) don't interleave.

Macro Definition Documentation

◆ CONSOLE_VGA_WIDTH

#define CONSOLE_VGA_WIDTH   80u

◆ CONSOLE_VGA_HEIGHT

#define CONSOLE_VGA_HEIGHT   25u

Function Documentation

◆ console_lock_acquire()

uint32_t console_lock_acquire ( void )

take the console lock, unless a panic is printing.

the console is the kernel's drawer on the framebuffer, so a change of the screen mode holds it too (as Linux changes the mode with console_lock held).

Returns
the interrupt state for console_lock_release().

◆ console_lock_release()

void console_lock_release ( uint32_t flags)

release the console lock that console_lock_acquire() took.

Parameters
flagsthe value console_lock_acquire() returned.

◆ console_initialize()

void console_initialize ( const boot_info_t * boot)

initialize the console driver.

chooses the framebuffer backend when the bootloader provided a graphics-mode framebuffer, otherwise the VGA text backend. must be called before any other console functions are used.

Parameters
bootboot information (carries the framebuffer description).

◆ console_putchar()

void console_putchar ( char c)

write a single character to the console.

safe from any context, including interrupt handlers.

Parameters
cthe character to write

◆ console_write()

void console_write ( const char * str)

write a null-terminated string to the console.

safe from any context.

Parameters
strthe string to write

◆ console_write_bytes()

void console_write_bytes ( const char * buf,
uint32_t len )

write a buffer to the console as one update: the whole buffer is drawn, then the caret is placed and the display flushed once.

translates
to \r
. this is the write syscall's path to the terminal. process context only: it may sleep until another process's write has finished.

Parameters
bufbytes to write (need not be null-terminated).
lennumber of bytes.

◆ console_panic_mode()

void console_panic_mode ( void )

stop locking the console: a panic is printing and the CPU will halt, so nothing else runs, and the panic may have hit while the lock was held.

◆ console_size()

void console_size ( uint32_t * rows,
uint32_t * cols )

the size of the console in character cells.

Parameters
rowsreceives the number of rows.
colsreceives the number of columns.