summaryrefslogtreecommitdiff
path: root/src/nrvn.c
blob: 3fcbc4105b04915caa49f74489a8051cf858c0ca (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
87
88
89
90
91
92
93
94
95
96
97
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

#include <nrvn.h>
#include <vga.h>
#include <idt.h>
#include <pic.h>
#include <acpi.h>
#include <ps2.h>
#include <pci.h>
#include <multiboot.h>
#include <mem.h>
#include <memory.h>
#include <ahci.h>

#include <fs/gpt.h>

/* Check if the compiler thinks you are targeting the wrong operating system. */
#if defined(__linux__)
#	error "You are not using a cross-compiler, you will most certainly run into trouble"
#endif

#if !defined(__x86_64__)
#	error "nrvn needs to be compiled with a x86_64 compiler"
#endif

int oct2bin(char *str, int size) {
	int n = 0;
	while (size--) {
		n *= 8;
		n += *str - '0';
		str++;
	}
	return n;
}

void kernel_main(void) {
	vga_init();
	vga_puts("hello world\n");
	vga_puts("welcome to nirvanna\n\n");

	vga_puts("initializing interrupt tables...");
	idt_init();
	vga_puts("interrupt tables initialized\n");

	vga_puts("initializing the pic...");
	pic_init();
	vga_puts("pic initialized\n");

	vga_puts("initializing memory pages... ");
	if (paging_init()) {
		vga_puts("memory pages allocated\n");
	} else {
		vga_puts("failed to allocate memory pages\n");
	}

	vga_puts("initializing ps/2...\n");
	if (ps2_init(NULL))
		vga_puts("ps/2 initialized.\n");
	else
		vga_puts("ps/2 initialization failed.\n");

	vga_puts("initializing pci...\n");
	if (pci_init())
		vga_puts("pci initialized.\n");
	else
		vga_puts("pci initialization failed.\n");

	struct disk *disk = get_disk(0);

	struct gpt_header *gpt = read_gpt_disk(disk);
	if (!gpt)
		while (1);

	struct gpt_entry *entry = get_gpt_entry(disk, gpt, 0);
	if (!entry)
		while (1);

	char *archive = read_gpt_entry(disk, entry);
	while (!memcmp(archive + 257, "ustar", 5)) {
		int size = oct2bin(archive + 0x7c, 11);
		vga_puts(archive[156] == '0' ? "filename: " : "directory: ");
		vga_puts(archive);
		vga_puts(", size: ");
		vga_putn(size);
		vga_putc('\n');
		if (size > 0) {
			vga_puts("contents: ");
			vga_puts(archive + 512);
			vga_putc('\n');
		}
		archive += 512 + (size > 0 ? 512 : 0);
	}

	while (1);
}