blob: ead52322c03e2143cd57c88e78481521fb3901d5 [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"
swissChilid8137922021-02-17 15:34:07 -080011
swissChilida23a912021-03-12 16:07:50 -080012int kmain(struct multiboot_info *mboot)
swissChilid8137922021-02-17 15:34:07 -080013{
swissChilie0a79bb2021-02-22 19:54:48 -080014 init_paging();
swissChilidc25b2b2021-02-23 17:07:13 -080015 init_vga();
swissChili0b35bf22021-02-18 12:49:40 -080016 init_descriptor_tables();
swissChili6c0519e2021-03-07 19:40:23 -080017 vga_clear();
swissChilid8137922021-02-17 15:34:07 -080018
swissChili825d46b2021-02-21 10:14:16 -080019 init_timer(20);
swissChilie4f01992021-02-25 15:38:12 -080020 init_allocator();
swissChili19ef4182021-02-21 17:45:51 -080021 init_kbd();
swissChilie4f01992021-02-25 15:38:12 -080022
swissChili6c0519e2021-03-07 19:40:23 -080023#ifdef TEST_ALLOC
24 test_allocator();
25#endif
swissChilie4f01992021-02-25 15:38:12 -080026
swissChili9752ab32021-03-05 11:20:13 -080027 // Load initrd
swissChilida23a912021-03-12 16:07:50 -080028 struct multiboot_info mb = make_multiboot_physical(mboot);
swissChili2b5acc82021-03-13 17:06:42 -080029 init_vfs();
swissChili9752ab32021-03-05 11:20:13 -080030
swissChili2b5acc82021-03-13 17:06:42 -080031#ifdef INITRD
swissChili9752ab32021-03-05 11:20:13 -080032 kassert(mb.mods_count, "No multiboot modules loaded!");
33 kprintf("mboot->mods_addr = %d (0x%x)\n", mb.mods_addr, mb.mods_addr);
swissChilida23a912021-03-12 16:07:50 -080034 uchar *initrd_loc = (uchar *)((uint *)mb.mods_addr)[0];
swissChili9752ab32021-03-05 11:20:13 -080035
swissChili6c0519e2021-03-07 19:40:23 -080036 kprintf("initrd is at 0x%x to 0x%x\n", initrd_loc);
swissChili9752ab32021-03-05 11:20:13 -080037
swissChili2b5acc82021-03-13 17:06:42 -080038 init_initrd_vfs(initrd_loc);
39#endif
swissChilida23a912021-03-12 16:07:50 -080040
swissChilif5448622021-03-08 20:17:36 -080041 kprintf("VFS initialized\n");
42
43 vga_set_color(LIGHT_GREEN, BLACK);
swissChili2b5acc82021-03-13 17:06:42 -080044 kprintf("Setup complete!\n");
swissChilif5448622021-03-08 20:17:36 -080045 vga_set_color(WHITE, BLACK);
46
swissChili2b5acc82021-03-13 17:06:42 -080047#ifdef TEST_VFS_INITRD
swissChilic2e62ed2021-03-10 17:04:18 -080048 kprintf("fs_readdir(\"/dev/initrd\")\n");
swissChilib7fe8992021-03-10 16:25:47 -080049
50 struct fs_dirent dirent;
swissChilida23a912021-03-12 16:07:50 -080051 for (int i = 0; fs_readdir(&root, i, &dirent); i++)
swissChilib7fe8992021-03-10 16:25:47 -080052 {
53 kprintf("name: %s, inode: %d\n", dirent.name, dirent.inode);
54 }
swissChili2b5acc82021-03-13 17:06:42 -080055#endif
swissChilib7fe8992021-03-10 16:25:47 -080056
swissChilidefeb0d2021-02-18 15:28:36 -080057 asm volatile("sti");
58
swissChili825d46b2021-02-21 10:14:16 -080059 while (true)
60 asm volatile("hlt");
61
swissChilid8137922021-02-17 15:34:07 -080062 return 0xCAFEBABE;
63}