miniOS
x86_64 hobby kernel with SMP, VFS, and POSIX process model
Loading...
Searching...
No Matches
console.h
Go to the documentation of this file.
1// MIT License
2//
3// Copyright (c) 2026 Christian Spoo
4//
5// Permission is hereby granted, free of charge, to any person obtaining a copy
6// of this software and associated documentation files (the "Software"), to deal
7// in the Software without restriction, including without limitation the rights
8// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9// copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in all
13// copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21// SOFTWARE.
22
34
35#ifndef _MINIOS_DRIVERS_CONSOLE_H_
36#define _MINIOS_DRIVERS_CONSOLE_H_
37
38/* Text attributes. */
39#define TEXT_STATIC 0
40#define TEXT_BLINKING 1
41
42/* Foreground and background colors. */
43#define TEXT_BLACK 0 /* 0000 */
44#define TEXT_BLUE 1 /* 0001 */
45#define TEXT_GREEN 2 /* 0010 */
46#define TEXT_CYAN 3 /* 0011 */
47#define TEXT_RED 4 /* 0100 */
48#define TEXT_MAGENTA 5 /* 0101 */
49#define TEXT_BROWN 6 /* 0110 */
50#define TEXT_LIGHT_GRAY 7 /* 0111 */
51
52/* Foreground-only colors. */
53#define TEXT_DARK_GRAY 8 /* 1000 */
54#define TEXT_LIGHT_BLUE 9 /* 1001 */
55#define TEXT_LIGHT_GREEN 10 /* 1010 */
56#define TEXT_LIGHT_CYAN 11 /* 1011 */
57#define TEXT_LIGHT_RED 12 /* 1100 */
58#define TEXT_LIGHT_MAGENTA 13 /* 1101 */
59#define TEXT_YELLOW 14 /* 1110 */
60#define TEXT_WHITE 15 /* 1111 */
61
62// Console text attributes
63#define TEXT_ATTR(textcolor, bgcolor, blinking) ((blinking << 7) | (bgcolor << 4) | textcolor)
64
65/* Light gray text on a black background. */
66#define DEFAULT_TEXT_ATTR (TEXT_ATTR(TEXT_LIGHT_GRAY, TEXT_BLACK, TEXT_STATIC))
67
68/* ------------------------------------------------------------------ */
69/* Screen geometry */
70/* ------------------------------------------------------------------ */
71#define SCREEN_ROWS 25 /* VGA text mode rows */
72#define SCREEN_COLS 80 /* VGA text mode columns */
73
74/* ------------------------------------------------------------------ */
75/* VGA CRT controller I/O ports (for hardware cursor) */
76/* ------------------------------------------------------------------ */
77#define VGA_CURSOR_PORT_IDX 0x3D4 /* CRT index register */
78#define VGA_CURSOR_PORT_DATA 0x3D5 /* CRT data register */
79#define VGA_CUR_START_REG 0x0A /* cursor start scanline register */
80#define VGA_CUR_HIGH_REG 0x0E /* cursor high byte register */
81#define VGA_CUR_LOW_REG 0x0F /* cursor low byte register */
82#define VGA_CUR_DISABLE (1 << 5) /* bit 5 of start register disables cursor */
83#define VGA_CUR_END_REG 0x0B /* cursor end scanline register */
84#define VGA_CUR_START_LINE 14 /* underline style: start scanline */
85#define VGA_CUR_END_LINE 15 /* underline style: end scanline */
86
87/* ------------------------------------------------------------------ */
88/* COM1 serial port (16550 UART) */
89/* ------------------------------------------------------------------ */
90#define COM1_PORT 0x3F8 /* COM1 base I/O port */
91#define COM_LSR_OFFSET 5 /* Line Status Register offset from COM1_PORT */
92#define COM_LSR_THRE 0x20 /* Transmitter Holding Register Empty (TX ready) */
93
101void console_init(void);
102
109void console_clear(void);
110
118void console_putchar(char c);
119
127void console_puts(char *s);
128
135void console_show_cursor(void);
136
143void console_hide_cursor(void);
144
146
147#endif
void console_hide_cursor(void)
Sets VGA_CUR_DISABLE (bit 5) in CRT register 0x0A, making the hardware cursor invisible....
Definition console.c:35
void console_puts(char *s)
Iterates over @s until the null terminator, calling console_putchar() for each character.
Definition console.c:47
void console_clear(void)
Fills all 80x25 cells with DEFAULT_TEXT_ATTR space characters and calls vt_clear() to reset the VT pa...
Definition console.c:27
void console_putchar(char c)
Handles newline, carriage return, backspace, and scrolling via the VT core.
Definition console.c:31
void console_show_cursor(void)
Writes scanline range VGA_CUR_START_LINE..VGA_CUR_END_LINE to CRT registers 0x0A and 0x0B,...
Definition console.c:39
void console_init(void)
Sets cursor position to (0,0), initialises the 16550 UART at COM1_PORT (0x3F8) to 9600 baud 8N1,...
Definition console.c:43