AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
fb.c
Go to the documentation of this file.
1
9
10#include <core/system.h>
11#include <core/string.h>
12#include <console/earlycon.h>
13#include <cpu/io.h>
14#include <mm/vm.h>
15
16#include "font.h"
17
21 fb_rows = 25, fb_cols = 80, fb_size;
22
23static struct vm_entry fb_vmr = {
24 .base = ARCH_EARLYFB_BASE,
25};
26
27static char *vmem = (char *) ARCH_EARLYFB_BASE;
28static char *cursor = (char *) ARCH_EARLYFB_BASE;
29
41{
43 fb_scanline = scanline;
44 fb_yres = yres;
45 fb_xres = xres;
46 fb_depth = depth;
47 fb_size = yres * scanline; /* scanline is already in bytes */
48}
49
56{
57 /* fb_putc() only draws 32-bit pixels */
58 return fb_paddr && fb_size && fb_depth == 32;
59}
60
62static void earlycon_fb_scroll(int n)
63{
64 size_t size = n * 16 * fb_scanline;
65 memmove(vmem, vmem + size, fb_size - size); /* the ranges overlap */
66 memset(vmem + fb_size - size, 0, size);
67}
68
70static void fb_putc(int row, int col, char c)
71{
72 cursor = vmem + row * 16 * fb_scanline + col * 8 * fb_depth / 8;
73
74 char *base = cursor;
75
76 for (int i = 0; i < 16; ++i) {
77 for (int j = 0; j < 8; ++j) {
78 char b = 0;
79
80 if (font_8x16[(unsigned) c * 16 + i] & (1 << (7 - j)))
81 b = 0xA0;
82
83 cursor[0] = b;
84 cursor[1] = b;
85 cursor[2] = b;
86 cursor[3] = b;
87
88 cursor += 4;
89 }
90
91 cursor += fb_scanline - 8 * 4;
92 }
93}
94
98static int earlycon_fb_putc(char c)
99{
100 if (!fb_init)
101 return -1;
102
103 if ((unsigned) c < 128) {
104 if (c == '\n') {
105 fb_col = 0;
106 fb_row++;
107
108 if (fb_row >= fb_rows) {
110 fb_row = fb_rows - 1;
111 }
112 return 1;
113 }
114
115 fb_putc(fb_row, fb_col, c);
116 ++fb_col;
117
118 if (fb_col >= fb_cols) {
119 fb_col = 0;
120 fb_row++;
121
122 if (fb_row >= fb_rows) {
124 fb_row = fb_rows - 1;
125 }
126 }
127
128 return 1;
129 }
130
131 return 0;
132}
133
135static int earlycon_fb_puts(char *s)
136{
137 while (*s)
138 earlycon_fb_putc(*s++);
139
140 return 0;
141}
142
145static void earlycon_fb_init()
146{
149 /* Cached, as it has always been: uncached memory is slow to read,
150 * and scrolling reads it; write-combining would need the PAT set
151 * up. */
153
155 fb_init = 1;
156
157 fb_cols = fb_xres / 8;
158 fb_rows = fb_yres / 16;
159}
160
162 .init = earlycon_fb_init,
163 .putc = earlycon_fb_putc,
164 .puts = earlycon_fb_puts,
165};
static char * cursor
Definition fb.c:28
static void earlycon_fb_scroll(int n)
Scrolls the screen up by n lines of text, clearing the bottom.
Definition fb.c:62
static uint32_t fb_cols
Definition fb.c:21
static uint32_t fb_row
Definition fb.c:20
static int earlycon_fb_putc(char c)
Writes a character at the cursor, scrolling when it goes past the last line.
Definition fb.c:98
static uint32_t fb_xres
Definition fb.c:19
static void fb_putc(int row, int col, char c)
Draws a character at a row and a column of text.
Definition fb.c:70
static void earlycon_fb_init()
Maps the framebuffer in the kernel's address space, and sizes the text screen from its resolution.
Definition fb.c:145
static uint32_t fb_col
Definition fb.c:20
static uint32_t fb_depth
Definition fb.c:19
static uint32_t fb_rows
Definition fb.c:21
static int earlycon_fb_puts(char *s)
Writes a string.
Definition fb.c:135
static uint32_t fb_size
Definition fb.c:21
static uintptr_t fb_init
Definition fb.c:18
static uint32_t fb_yres
Definition fb.c:19
static uintptr_t fb_paddr
Definition fb.c:18
static uint32_t fb_scanline
Definition fb.c:20
static struct vm_entry fb_vmr
Definition fb.c:23
void earlycon_fb_register(uintptr_t paddr, uint32_t scanline, uint32_t yres, uint32_t xres, uint32_t depth)
Registers the boot loader's framebuffer, for the early console.
Definition fb.c:40
#define ARCH_EARLYFB_BASE
Definition mm.h:45
8x16 font, the characters of code page 437 in order: generated by mkfont.py from unscii-16 by Viznut ...
const unsigned char font_8x16[256 *16]
Definition font.h:7
int earlycon_fb_available(void)
Says whether the boot loader's framebuffer can be the early console.
Definition fb.c:55
struct earlycon earlycon_fb
Definition fb.c:161
void * memmove(void *dst, const void *src, size_t n)
Copies n bytes; dst and src may overlap.
Definition libc.c:34
void * memset(void *dst, int c, size_t n)
Sets n bytes to c.
Definition libc.c:23
__SIZE_TYPE__ uintptr_t
Definition stddef.h:12
unsigned int uint32_t
Definition stddef.h:22
An early console's operations.
Definition earlycon.h:11
A mapping (map entry): a range of an address space, its permissions, and where its pages come from.
Definition vm.h:66
uint32_t flags
its permissions and flags (VM_*)
Definition vm.h:78
paddr_t paddr
physical memory to map all at once (vm_map()), or 0 for pages that come in on page faults
Definition vm.h:69
vaddr_t base
where the mapping starts in its address space
Definition vm.h:72
size_t size
its size
Definition vm.h:75
An arena: a range, and its segments.
Definition vmem.h:41
int vm_map(struct vm_space *vm_space, struct vm_entry *vm_entry)
Maps a map entry's whole range at once: its physical memory (paddr), or new pages of memory if it has...
Definition vmm.c:29
struct vm_space kvm_space
Definition vmm.c:17
#define VM_KRW
kernel read/write
Definition vm.h:49