blob: 22d4a353ec9414faf1210ca3c3d4b278f1ef5fe8 [file] [log] [blame]
swissChilie4f01992021-02-25 15:38:12 -08001#include "alloc.h"
swissChilid8137922021-02-17 15:34:07 -08002#include "descriptor_tables.h"
swissChili825d46b2021-02-21 10:14:16 -08003#include "io.h"
4#include "log.h"
swissChilie4f01992021-02-25 15:38:12 -08005#include "paging.h"
swissChilidefeb0d2021-02-18 15:28:36 -08006#include "timer.h"
swissChili825d46b2021-02-21 10:14:16 -08007#include "vga.h"
swissChilif5448622021-03-08 20:17:36 -08008#include "vfs.h"
swissChilic2e62ed2021-03-10 17:04:18 -08009#include "vfs_initrd.h"
swissChili9752ab32021-03-05 11:20:13 -080010#include "multiboot.h"
swissChili64228692021-03-16 08:19:23 -070011#include "syscall.h"
swissChilid8137922021-02-17 15:34:07 -080012
swissChilida23a912021-03-12 16:07:50 -080013int kmain(struct multiboot_info *mboot)
swissChilid8137922021-02-17 15:34:07 -080014{
swissChilie0a79bb2021-02-22 19:54:48 -080015 init_paging();
swissChilidc25b2b2021-02-23 17:07:13 -080016 init_vga();
swissChili0b35bf22021-02-18 12:49:40 -080017 init_descriptor_tables();
swissChili64228692021-03-16 08:19:23 -070018 init_syscall();
swissChili6c0519e2021-03-07 19:40:23 -080019 vga_clear();
swissChilid8137922021-02-17 15:34:07 -080020
swissChili825d46b2021-02-21 10:14:16 -080021 init_timer(20);
swissChilie4f01992021-02-25 15:38:12 -080022 init_allocator();
swissChili19ef4182021-02-21 17:45:51 -080023 init_kbd();
swissChilie4f01992021-02-25 15:38:12 -080024
swissChili6c0519e2021-03-07 19:40:23 -080025#ifdef TEST_ALLOC
26 test_allocator();
27#endif
swissChilie4f01992021-02-25 15:38:12 -080028
swissChili9752ab32021-03-05 11:20:13 -080029 // Load initrd
swissChilida23a912021-03-12 16:07:50 -080030 struct multiboot_info mb = make_multiboot_physical(mboot);
swissChili2b5acc82021-03-13 17:06:42 -080031 init_vfs();
swissChili9752ab32021-03-05 11:20:13 -080032
swissChili2b5acc82021-03-13 17:06:42 -080033#ifdef INITRD
swissChili9752ab32021-03-05 11:20:13 -080034 kassert(mb.mods_count, "No multiboot modules loaded!");
35 kprintf("mboot->mods_addr = %d (0x%x)\n", mb.mods_addr, mb.mods_addr);
swissChilida23a912021-03-12 16:07:50 -080036 uchar *initrd_loc = (uchar *)((uint *)mb.mods_addr)[0];
swissChili9752ab32021-03-05 11:20:13 -080037
swissChili6c0519e2021-03-07 19:40:23 -080038 kprintf("initrd is at 0x%x to 0x%x\n", initrd_loc);
swissChili9752ab32021-03-05 11:20:13 -080039
swissChili2b5acc82021-03-13 17:06:42 -080040 init_initrd_vfs(initrd_loc);
41#endif
swissChilida23a912021-03-12 16:07:50 -080042
swissChilif5448622021-03-08 20:17:36 -080043 kprintf("VFS initialized\n");
44
45 vga_set_color(LIGHT_GREEN, BLACK);
swissChili2b5acc82021-03-13 17:06:42 -080046 kprintf("Setup complete!\n");
swissChilif5448622021-03-08 20:17:36 -080047 vga_set_color(WHITE, BLACK);
48
swissChili2b5acc82021-03-13 17:06:42 -080049#ifdef TEST_VFS_INITRD
swissChilic2e62ed2021-03-10 17:04:18 -080050 kprintf("fs_readdir(\"/dev/initrd\")\n");
swissChilib7fe8992021-03-10 16:25:47 -080051
52 struct fs_dirent dirent;
swissChilida23a912021-03-12 16:07:50 -080053 for (int i = 0; fs_readdir(&root, i, &dirent); i++)
swissChilib7fe8992021-03-10 16:25:47 -080054 {
55 kprintf("name: %s, inode: %d\n", dirent.name, dirent.inode);
56 }
swissChili2b5acc82021-03-13 17:06:42 -080057#endif
swissChilib7fe8992021-03-10 16:25:47 -080058
swissChilidefeb0d2021-02-18 15:28:36 -080059 asm volatile("sti");
60
swissChili825d46b2021-02-21 10:14:16 -080061 while (true)
62 asm volatile("hlt");
63
swissChilid8137922021-02-17 15:34:07 -080064 return 0xCAFEBABE;
65}