AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
vga.c
Go to the documentation of this file.
1
6
7#include <core/system.h>
8#include <core/string.h>
9#include <console/earlycon.h>
10#include <cpu/io.h>
11#include <mm/mm.h>
12
13static char *vga_start = (char *) VMA(0xB8000);
14static char *vga = (char *) VMA(0xB8000);
15
17 .addr = 0x3D4,
18 .type = IOADDR_PORT,
19};
20
21#define VGA_COLS 80
22#define VGA_ROWS 25
23#define VGA_SIZE (2 * VGA_COLS * VGA_ROWS)
24
27static void earlycon_vga_scroll(int n)
28{
29 memmove(vga_start, vga_start + 160 * n, 160 * (VGA_ROWS - n));
30 vga = vga_start + 160 * (VGA_ROWS - n);
31
32 int i;
33 for (i = 0; i < VGA_COLS * n; ++i) {
34 vga[2 * i + 0] = '\0';
35 vga[2 * i + 1] = 0x07;
36 }
37}
38
41static int earlycon_vga_putc(char c)
42{
43 if (c) {
44 if (c == '\n')
45 vga = vga_start + (vga - vga_start) / 160 * 160 + 160;
46 else {
47 *vga = c;
48 vga += 2;
49 }
50
51 /* wrapped past the last line */
52 if (vga - vga_start >= VGA_SIZE)
54
55 return 1;
56 }
57
58 return 0;
59}
60
62static int earlycon_vga_puts(char *s)
63{
64 char *_s = s;
65
66 while (*s)
68
69 return (int)(s - _s);
70}
71
73static void earlycon_vga_init()
74{
75 io_out8(&vga_ioaddr, 0x00, 0x0F);
76 io_out8(&vga_ioaddr, 0x01, 0xFF);
77 io_out8(&vga_ioaddr, 0x00, 0x0E);
78 io_out8(&vga_ioaddr, 0x01, 0xFF);
79
80 unsigned i;
81 for (i = 0; i < 80*25; ++i)
82 vga_start[2*i] = 0;
83}
84
86 .init = earlycon_vga_init,
87 .putc = earlycon_vga_putc,
88 .puts = earlycon_vga_puts,
89};
static void io_out8(struct ioaddr *io, uintptr_t off, uint8_t val)
Writes an 8-, 16- or 32-bit register.
Definition io.h:44
#define VMA(obj)
Definition mm.h:36
static int earlycon_vga_puts(char *s)
Writes a string, and returns how many characters it wrote.
Definition vga.c:62
static char * vga_start
Definition vga.c:13
static int earlycon_vga_putc(char c)
Writes a character at the cursor, scrolling when it goes past the last line.
Definition vga.c:41
static void earlycon_vga_scroll(int n)
Scrolls the screen up by n lines, clearing the lines at the bottom.
Definition vga.c:27
#define VGA_ROWS
Definition vga.c:22
static char * vga
Definition vga.c:14
#define VGA_SIZE
Definition vga.c:23
struct ioaddr vga_ioaddr
Definition vga.c:16
#define VGA_COLS
Definition vga.c:21
static void earlycon_vga_init()
Hides the hardware cursor, and clears the screen.
Definition vga.c:73
#define IOADDR_PORT
Definition io.h:89
struct earlycon earlycon_vga
Definition vga.c:85
void * memmove(void *dst, const void *src, size_t n)
Copies n bytes; dst and src may overlap.
Definition libc.c:34
An early console's operations.
Definition earlycon.h:11
Where a device's registers are.
Definition io.h:95