aboutsummaryrefslogtreecommitdiff
path: root/src/kernel/system.c
blob: 3b3cf95dbfcb89c8e40100902d8855a345bc3099 (plain) (blame)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <kernel/timer/timer.h>
#include <kernel/io/io.h>
#include <kernel/graphics/vesa.h>
#include <kernel/lib/lib.h>

char *vga_buffer = (char *) 0x500;

void vga_log(char *msg, int line) {
    uint16_t *terminal_buffer = (uint16_t *) 0xB8000;
    for (size_t i = 0; i < strlen(msg); i++)
        terminal_buffer[line * 80 + i] = (uint16_t) msg[i] | (uint16_t) 0x700;
    strcpy(msg, "\n");
    memcpy(vga_buffer, msg, sizeof(msg));
}

void kernel_time() {
    vesa_draw_string("\n");
    vesa_draw_string("[");
    vesa_draw_number((int) get_time());
    vesa_draw_string("] ");
}

void log(char *msg) {
    vesa_set_color(vesa_dark_white);
    kernel_time();
    vesa_draw_string(msg);
    vesa_set_color(default_text_color);
}

void info(char *msg) {
    vesa_set_color(vesa_blue);
    kernel_time();
    vesa_draw_string("INFORMATION: ");
    vesa_draw_string(msg);
    vesa_set_color(default_text_color);
}

void warn(char *msg) {
    vesa_set_color(vesa_dark_yellow);
    kernel_time();
    vesa_draw_string("WARNING: ");
    vesa_draw_string(msg);
    vesa_set_color(default_text_color);
}

void panic(char *msg) {
    asm volatile ("cli");
    vesa_set_color(vesa_dark_red);
    kernel_time();
    serial_write("\nPANIC: ");
    serial_write(msg);
    serial_write(" - System halted!\n");
    vesa_draw_string("PANIC: ");
    vesa_draw_string(msg);
    vesa_draw_string(" - System halted!\n");
    loop:
    asm volatile ("hlt");
    goto loop;
}

void assert(int x) {
    if (x == 0) {
        panic("Assertion failed");
    }
}