-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathkernel.c
More file actions
37 lines (29 loc) · 1.11 KB
/
kernel.c
File metadata and controls
37 lines (29 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <stddef.h>
#include <stdbool.h>
#include <stdint.h>
#include "multiboot.h"
// The CGA graphics device is memory-mapped. We're not going to go into a ton
// of detail here, but the basic idea is:
// | 4 bit background color | 4 bit foreground color | 8 bit ascii character |
// 24 rows of text, with 80 columns per row
volatile uint16_t* cga_memory = (volatile uint16_t*)0xb8000;
const uint32_t cga_column_count = 80;
const uint32_t cga_row_count = 24;
const uint16_t cga_white_on_black_color_code = (15 << 8);
void cga_clear_screen(void) {
// would be nice to use memset here, but remember, there is no libc available
for (uint32_t i = 0; i < cga_row_count * cga_column_count; ++i) {
cga_memory[i] = 0;
}
}
void cga_print_string(const char* string) {
for (uint32_t i = 0; *string != '\0'; ++string, ++i) {
cga_memory[i] = *string | cga_white_on_black_color_code;
}
}
void kernel_main(multiboot_info_t* multiboot_info) {
#pragma unused(multiboot_info)
cga_clear_screen();
cga_print_string("i'm a kernel");
// returning here will result in our 'hang' routine executing
}