aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/arch/x86_64/limine.cpp
blob: 9ea2bbcde34e0c53cfff41a11edf46a43ab321aa (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
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <stdint.h>
#include <stddef.h>
#include <stdio.h>
#include <arch/x86_64/serial.h>
#include "limine.h"
#include <framebuffer.h>

namespace {
__attribute__((used, section(".requests")))
volatile LIMINE_BASE_REVISION(2);
}

namespace {
__attribute__((used, section(".requests")))
volatile limine_framebuffer_request framebuffer_request = {
    .id = LIMINE_FRAMEBUFFER_REQUEST,
    .revision = 0,
    .response = nullptr
};
}

namespace {
__attribute__((used, section(".requests_start_marker")))
volatile LIMINE_REQUESTS_START_MARKER;

__attribute__((used, section(".requests_end_marker")))
volatile LIMINE_REQUESTS_END_MARKER;
}

namespace {
void hcf() {
    asm("cli");
    for (;;) {
        asm("hlt");
    }
}
}

extern void (*__init_array[])();
extern void (*__init_array_end[])();

extern "C" void kernel_main();

extern "C" void _start() {
    if (!LIMINE_BASE_REVISION_SUPPORTED) {
        hcf();
    }

    // initialize global constructors
    for (size_t i = 0; &__init_array[i] != __init_array_end; i++) {
        __init_array[i]();
    }

    // Ensure we got a framebuffer.
    if (framebuffer_request.response == nullptr
     || framebuffer_request.response->framebuffer_count < 1) {
        hcf();
    }

    // Fetch the first framebuffer.
    limine_framebuffer *framebuffer = framebuffer_request.response->framebuffers[0];

    // Note: we assume the framebuffer model is RGB with 32-bit pixels.
    for (size_t i = 0; i < 100; i++) {
        volatile uint32_t *fb_ptr = static_cast<volatile uint32_t *>(framebuffer->address);
        fb_ptr[i * (framebuffer->pitch / 4) + i] = 0xffffff;
    }

    Framebuffer fb((uint32_t*)framebuffer->address, framebuffer->width, framebuffer->height);
    fb.drawpixel(727, 727, 0x9528fd);

    printf("video modes: %lx", framebuffer->mode_count);

    kernel_main();

    // We're done, just hang...
    hcf();
}