summaryrefslogtreecommitdiff
path: root/src/boot.c
blob: 00afae2157c9ab677064f95b23a0737f8c2f4b5a (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include "aplos.h"

#define LIMINE_API_REVISION 3
#include "../external/limine/limine.h"

#define LIMINE(sec) \
	__attribute__((used, section(sec))) \
	static volatile
#define REQUEST LIMINE(".limine_requests")

static void bootmain(void);

REQUEST LIMINE_BASE_REVISION(3)

REQUEST struct limine_framebuffer_request framebuffer_request = {
	.id = LIMINE_FRAMEBUFFER_REQUEST,
	.revision = 0
};

REQUEST struct limine_memmap_request memmap_request = {
	.id = LIMINE_MEMMAP_REQUEST,
	.revision = 0
};

REQUEST struct limine_paging_mode_request paging_request = {
	.id = LIMINE_PAGING_MODE_REQUEST,
	.revision = 1,
	.mode = LIMINE_PAGING_MODE_X86_64_4LVL,
	.min_mode = LIMINE_PAGING_MODE_X86_64_4LVL,
	.max_mode = LIMINE_PAGING_MODE_X86_64_4LVL
};

REQUEST struct limine_mp_request mp_request = {
	.id = LIMINE_MP_REQUEST,
	.revision = 0
};

REQUEST struct limine_entry_point_request entry_point_request = {
	.id = LIMINE_ENTRY_POINT_REQUEST,
	.revision = 0,
	.entry = bootmain
};

REQUEST struct limine_hhdm_request hhdm_request = {
	.id = LIMINE_HHDM_REQUEST,
	.revision = 0
};

REQUEST struct limine_rsdp_request rsdp_request = {
	.id = LIMINE_RSDP_REQUEST,
	.revision = 0
};

LIMINE(".limine_requests_start") LIMINE_REQUESTS_START_MARKER
LIMINE(".limine_requests_end") LIMINE_REQUESTS_END_MARKER

uint64_t
cpu_count(void)
{
	return mp_request.response->cpu_count;
}

uint8_t
boot_apic_id(void)
{
	return mp_request.response->bsp_lapic_id;
}

static void
bootmain(void)
{
	struct boot_info info;

	assert(LIMINE_BASE_REVISION_SUPPORTED);
	assert(framebuffer_request.response);
	assert(memmap_request.response);
	assert(paging_request.response);
	assert(mp_request.response);
	assert(hhdm_request.response);
	assert(rsdp_request.response);

	assert(framebuffer_request.response->framebuffer_count >= 1);

	struct limine_framebuffer *framebuffer = framebuffer_request.response->framebuffers[0];

	info.framebuffer.addr = framebuffer->address;
	info.framebuffer.width = framebuffer->width;
	info.framebuffer.height = framebuffer->height;
	info.framebuffer.pitch = framebuffer->pitch;

	struct memmap memmaps[memmap_request.response->entry_count];
	info.memmap_count = 0;

	struct memmap *m = memmaps;
	for(uint64_t i = 0; i < memmap_request.response->entry_count; i++){
		struct limine_memmap_entry *e = memmap_request.response->entries[i];
		switch(e->type){
		case LIMINE_MEMMAP_USABLE:
			m->start = e->base;
			m->size = e->length;
			m++;
			info.memmap_count++;
		}
	}
	info.memmaps = memmaps;
	info.physbase = hhdm_request.response->offset;
	info.rsdp = rsdp_request.response->address;

	main(&info);
	halt();
}