|
ginnOS
The reference: libc, the libraries and the kernel
|
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. | |
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.
| #define CONSOLE_VGA_WIDTH 80u |
| #define CONSOLE_VGA_HEIGHT 25u |
| 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).
| void console_lock_release | ( | uint32_t | flags | ) |
release the console lock that console_lock_acquire() took.
| flags | the value console_lock_acquire() returned. |
| 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.
| boot | boot information (carries the framebuffer description). |
| void console_putchar | ( | char | c | ) |
write a single character to the console.
safe from any context, including interrupt handlers.
| c | the character to write |
| void console_write | ( | const char * | str | ) |
write a null-terminated string to the console.
safe from any context.
| str | the string to write |
| 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.
| buf | bytes to write (need not be null-terminated). |
| len | number of bytes. |
| 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.