AquilaOS documentation
How it works, and its code
Toggle main menu visibility
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
13
static
char
*
vga_start
= (
char
*)
VMA
(0xB8000);
14
static
char
*
vga
= (
char
*)
VMA
(0xB8000);
15
16
struct
ioaddr
vga_ioaddr
= {
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
27
static
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
41
static
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
)
53
earlycon_vga_scroll
(1);
54
55
return
1;
56
}
57
58
return
0;
59
}
60
62
static
int
earlycon_vga_puts
(
char
*s)
63
{
64
char
*_s = s;
65
66
while
(*s)
67
earlycon_vga_putc
(*s++);
68
69
return
(
int
)(s - _s);
70
}
71
73
static
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
85
struct
earlycon
earlycon_vga
= {
86
.init =
earlycon_vga_init
,
87
.putc =
earlycon_vga_putc
,
88
.puts =
earlycon_vga_puts
,
89
};
io_out8
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
VMA
#define VMA(obj)
Definition
mm.h:36
earlycon_vga_puts
static int earlycon_vga_puts(char *s)
Writes a string, and returns how many characters it wrote.
Definition
vga.c:62
vga_start
static char * vga_start
Definition
vga.c:13
earlycon_vga_putc
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
earlycon_vga_scroll
static void earlycon_vga_scroll(int n)
Scrolls the screen up by n lines, clearing the lines at the bottom.
Definition
vga.c:27
VGA_ROWS
#define VGA_ROWS
Definition
vga.c:22
vga
static char * vga
Definition
vga.c:14
VGA_SIZE
#define VGA_SIZE
Definition
vga.c:23
vga_ioaddr
struct ioaddr vga_ioaddr
Definition
vga.c:16
VGA_COLS
#define VGA_COLS
Definition
vga.c:21
earlycon_vga_init
static void earlycon_vga_init()
Hides the hardware cursor, and clears the screen.
Definition
vga.c:73
IOADDR_PORT
#define IOADDR_PORT
Definition
io.h:89
earlycon.h
earlycon_vga
struct earlycon earlycon_vga
Definition
vga.c:85
system.h
io.h
mm.h
memmove
void * memmove(void *dst, const void *src, size_t n)
Copies n bytes; dst and src may overlap.
Definition
libc.c:34
string.h
earlycon
An early console's operations.
Definition
earlycon.h:11
ioaddr
Where a device's registers are.
Definition
io.h:95
kernel
arch
i386
earlycon
vga.c
Generated by
1.18.0