Console Subsystem

The Console Subsystem is made up of

  • the console drivers, providing console devices

  • the implementation of the subsystem itself, providing means for managing consoles

The Console Subsystem is implemented in os/drivers/console/console.c.

This very simple subsystem allocates new consoles, provides them with the registered default backend operations, and calls con_be_open() on console initialization.

Initialization

This subsystem is initialized by calling

void console_init(void)

Initialize the console subsystem.

Initialize the vga text console backend and the basic console frontend. These are the only backends and frontends currently provided by tomOSii. It is therefore reasonable to have this initialization hard-coded.

Furthermore, the initial basic console is allocated and registered to printk.

Note

Find better ways to initialize backends and frontends, once more than one (backend) is implemented and can be selected.

^ Back to top.

Registering Default Backend Operations

Default backend operations to be used with newly allocated consoles are registered by calling

void console_register_default_backend_operations(const console_backend_operations_t *cb_ops)

Register the default backend operations for newly allocated consoles.

This function is intended to be called by the console backend implementation when it is being initialized.

Note

Currently, only a single set of backend operations can be registered. Registering another set of backend operations will overwrite the previously registered operations.

Note

Find better ways of registering backend operations, once more backends are implemented and can be selected.

^ Back to top.

Allocating a Console

A new console is allocated by calling

console_t *console_alloc(void)

Allocate, initialize and return a new console.

The returned console’s backend operations (console_t::cb_ops) will point to a previously registered set of operations, if any. The console operations (console_t::con_ops) will be provided by the actual console (frontend) implementation.

This function is intended to be called from the console frontend’s initialization function.

^ Back to top.

Datatypes Provided by the Subsystem

Console Data Structure

The data structure keeping track of console-related data

struct console_t

Console state and operations (backend and frontend).

Tracks the state, e.g., cursor x and y position, and stores the operations provided of and required for a (virtual) console. The former operations (con_ops) will be implemented by a console frontend and provided to higher-level system components. The latter deal with the hardware: operations (cb_ops) have to be implemented by a console backend.

Public Members

const console_operations_tconsole_operations_t *con_ops

The operations provided by a console frontend.

const console_backend_operations_tconsole_backend_operations_t *cb_ops

The operations provided by a console backend.

unsigned int pos_x

The column for new strings to be printed.

unsigned int pos_y

The row for new strings to be printed.

unsigned int width

The number of columns the backend provides.

unsigned int height

The number of rows the backend provides.

uint8_t default_attribute

The default attribute to use for characters.

^ Back to top.

Console Operations

The interface between higher-level system components and the console frontend.

struct console_operations_t

Callbacks provided by higher level console abstractions.

These callbacks provide other parts of the system with means of, e.g., writing text to a console. The callbacks have to be implemented by the respective console frontend. They can be used, for instance, in printk to output text to the screen.

This data structure and the callbacks defined in it are based on from the Linux kernel (as of 6.17.5). They are adapted and simplified and may long have diverged in order to make tomOSii a prototypical teaching operating system.

Public Members

void (*write)(console_t *console, const char *string, unsigned int count)

Write count characters from string to console.

^ Back to top.

Console Backend Operations

The interface between console frontend and backend.

struct console_backend_operations_t

Callbacks provided by console backends.

These callbacks provide a higher-level console frontend with access to lower-level hardware via a common interface. The callbacks have to be implemented by a console backend, e.g., the vga text console.

This data structure and the callbacks defined in it are based on from the Linux kernel (as of 6.17.5). They are adapted and simplified and may have long diverged in order to make tomOSii a prototypical teaching operating system.

Public Members

void (*con_be_open)(console_t *con)

Open the backend, initialize the required fields in con.

void (*con_be_putc)(console_t *con, uint16_t ca, unsigned int y, unsigned int x)

Emit one character with attributes ca to [x, y].

void (*con_be_clear)(console_t *con, unsigned int y, unsigned int x, size_t count)

Erase count characters starting at [x, y].

void (*con_be_cursor)(console_t *con, unsigned int y, unsigned int x, bool enable)

Set the cursor’s [x, y] position and enabled state.

void (*con_be_scroll)(console_t *con, unsigned int top, unsigned int bottom, con_scroll_t dir, unsigned int lines)

scroll the console from top (inclusive) to bottom (exclusive) in direction dir by lines.

^ Back to top.

Console Backend Scroll Directions

The direction for console scrolling has its own type to avoid magic numbers:

enum con_scroll_t

Determine the direction of scrolling the console’s content.

Values:

enumerator CON_SCROLL_DOWN
enumerator CON_SCROLL_UP