Skip to content

Commit 49b5a55

Browse files
committed
VGA framebuffer & console driver cleanup
- Remove direct malloc from drivers (use only resources) - Put state in a struct - Define the number of columns explicitly now
1 parent b7f1eea commit 49b5a55

File tree

6 files changed

+273
-252
lines changed

6 files changed

+273
-252
lines changed

src/arch/x86/hal/console.c

+25-48
Original file line numberDiff line numberDiff line change
@@ -10,45 +10,24 @@
1010
#include <sys/resource.h>
1111
#include <sys/device.h>
1212

13-
// x86 VGA
13+
// x86 VGA
1414
static resource_t vga_resource = {
15-
.name = "vga",
16-
.flags = RESOURCE_META,
17-
.start = 0xA0000,
18-
.end = 0xBFFFF
19-
};
20-
21-
static resource_t framebuffer = {
22-
.name = "framebuffer",
23-
.flags = RESOURCE_MEM
24-
};
25-
26-
static resource_t attribute_control = {
27-
.name = "attribute_control",
28-
.start = 0x3C0,
29-
.end = 0x3C1,
30-
.flags = RESOURCE_IO | RESOURCE_IO_INDEXED | RESOURCE_WIDTH_8
31-
};
32-
33-
static resource_t sequencer = {
34-
.name = "sequencer",
35-
.start = 0x3C4,
36-
.end = 0x3C5,
37-
.flags = RESOURCE_IO | RESOURCE_IO_INDEXED | RESOURCE_WIDTH_8
15+
.name = "vga",
16+
.start = 0xA0000,
17+
.end = 0xBFFFF,
18+
.flags = RESOURCE_META
3819
};
3920

40-
static resource_t graphics = {
41-
.name = "graphics",
42-
.start = 0x3CE,
43-
.end = 0x3CF,
44-
.flags = RESOURCE_IO | RESOURCE_IO_INDEXED | RESOURCE_WIDTH_8
21+
static resource_t vga_control = {
22+
.name = "control_base",
23+
.start = 0x3C0,
24+
.end = 0x3DF,
25+
.flags = RESOURCE_IO | RESOURCE_WIDTH_8 | RESOURCE_IO_INDEXED
4526
};
4627

47-
static resource_t crtc = {
48-
.name = "crtc",
49-
.start = 0x3D4,
50-
.end = 0x3D5,
51-
.flags = RESOURCE_IO | RESOURCE_IO_INDEXED | RESOURCE_WIDTH_8
28+
static resource_t vga_framebuffer = {
29+
.name = "framebuffer",
30+
.flags = RESOURCE_MEM
5231
};
5332

5433
static device_t vga_device = {
@@ -58,15 +37,15 @@ static device_t vga_device = {
5837

5938
static device_t vga_console_device = {
6039
.name = "vga_console",
61-
.access = &framebuffer
40+
.access = &vga_framebuffer
6241
};
6342

6443
// x86 COM1
6544
static resource_t com1 = {
66-
.name = "COM1",
67-
.start = 0x3F8,
68-
.end = 0x3FF,
69-
.flags = RESOURCE_IO | RESOURCE_WIDTH_8
45+
.name = "COM1",
46+
.start = 0x3F8,
47+
.end = 0x3FF,
48+
.flags = RESOURCE_IO | RESOURCE_WIDTH_8
7049
};
7150

7251
static device_t serial_console_device = {
@@ -79,27 +58,25 @@ static int console_init()
7958
int vgaRet, serialRet;
8059
// Serial Baudrate
8160
uint32_t baudrate = 115200;
82-
// Bios video mode 3h, 8 tall font, 80 lines of text.
83-
uint32_t vga_config[] = {0x3, 8, 80};
61+
// Bios video mode 3h, 8 tall font, 50 lines, 80 columns of text.
62+
uint32_t vga_config[] = {0x3, 8, 50, 80};
8463

8564
// VGA Console First
8665
resource_register(&vga_resource, NULL);
87-
resource_register(&framebuffer, &vga_resource);
88-
resource_register(&attribute_control, &vga_resource);
89-
resource_register(&sequencer, &vga_resource);
90-
resource_register(&graphics, &vga_resource);
91-
resource_register(&crtc, &vga_resource);
66+
resource_register(&vga_control, &vga_resource);
67+
resource_register(&vga_framebuffer, &vga_resource);
68+
9269
vgaRet = device_register(&vga_device, base_device(), "display/vga");
9370
vgaRet |= device_register(&vga_console_device, &vga_device, "console/vga");
9471
vgaRet |= device_init(&vga_device, &vga_config);
9572
vgaRet |= device_init(&vga_console_device, &vga_config[2]);
9673

9774
// Serial Console Next
9875
resource_register(&com1, NULL);
99-
serialRet = device_register(&serial_console_device, base_device(),
76+
serialRet = device_register(&serial_console_device, base_device(),
10077
"console/serial/16550");
10178
serialRet |= device_init(&serial_console_device, &baudrate);
102-
79+
10380
// If either console succeeds, we succeed
10481
return (vgaRet && serialRet);
10582
}

src/core/main.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,9 @@ static void log_status(int status, const char *name, const char *text) {
187187
return; // No logging enabled
188188
}
189189
if (status == 0) {
190-
printf("[\033[32m OK \033[0m] ");
190+
printf("[\033[32m OK \033[0m] ");
191191
} else {
192-
printf("[\033[31mFAIL\033[0m] ");
192+
printf("[\033[31mFAILED\033[0m] ");
193193
}
194194
printf("%s %s\n", text, name);
195195
#ifdef HOSTED

src/drivers/console/include/vga.h

+21
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,25 @@
1919
#define VGA_C_LIGHTBROWN 14
2020
#define VGA_C_WHITE 15
2121

22+
#define DEFAULT_BG_COLOR VGA_C_BLUE
23+
#define DEFAULT_FG_COLOR VGA_C_LIGHTGRAY
24+
25+
typedef struct {
26+
char escape_buf[4];
27+
int escape_buf_idx;
28+
int escape_nums[4];
29+
int escape_num_idx;
30+
uint8_t cursor_y;
31+
uint8_t cursor_x;
32+
33+
device_t *dev;
34+
resource_t *framebuffer;
35+
uint16_t max_rows;
36+
uint16_t max_cols;
37+
int bg_color;
38+
int fg_color;
39+
int bold;
40+
int in_escape;
41+
} vga_console_state_t;
42+
2243
#endif

0 commit comments

Comments
 (0)