summaryrefslogtreecommitdiff
path: root/kernel/main.c
blob: 72a66685592099d8fe126ee2023d1965fa5a0e94 (plain)
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
#include <comus/cpu.h>
#include <comus/memory.h>
#include <comus/mboot.h>
#include <comus/efi.h>
#include <comus/drivers.h>
#include <comus/drivers/acpi.h>
#include <comus/drivers/pci.h>
#include <comus/drivers/gpu.h>
#include <comus/drivers/ata.h>
#include <comus/user.h>
#include <comus/fs.h>
#include <comus/procs.h>
#include <lib.h>

void kreport(void)
{
	cpu_report();
	memory_report();
	acpi_report();
	pci_report();
	ata_report();
	gpu_report();
}

void load_init(void)
{
	struct file_system *fs;
	struct file *file;
	const char *init_vector[] = { NULL };

	if (pcb_alloc(&init_pcb))
		return;

	// get root fs
	fs = fs_get_root_file_system();
	if (fs == NULL)
		return;

	// get init bin
	if (fs->open(fs, "bin/init", O_RDONLY, &file))
		return;

	if (user_load(init_pcb, file, init_vector, kernel_mem_ctx)) {
		file->close(file);
		return;
	}

	// close file
	file->close(file);

	// schedule and dispatch init
	schedule(init_pcb);
	dispatch();
}

__attribute__((noreturn)) void main(long magic, volatile void *mboot)
{
	// initalize idt and pic
	cpu_init();

	// load multiboot information
	mboot_init(magic, mboot);

	// load efi structures
	efi_init(mboot_get_efi_hdl(), mboot_get_efi_st());

	// initalize memory
	memory_init();

	// initalize devices
	drivers_init();

	// load file systems
	fs_init();

	// initalize processes
	pcb_init();

	// report system state
	kreport();

	// load init process
	load_init();

	panic("failed to load init");
}