swissChili | e4f0199 | 2021-02-25 15:38:12 -0800 | [diff] [blame] | 1 | #include "alloc.h" |
swissChili | d813792 | 2021-02-17 15:34:07 -0800 | [diff] [blame] | 2 | #include "descriptor_tables.h" |
swissChili | 825d46b | 2021-02-21 10:14:16 -0800 | [diff] [blame] | 3 | #include "io.h" |
| 4 | #include "log.h" |
swissChili | e4f0199 | 2021-02-25 15:38:12 -0800 | [diff] [blame] | 5 | #include "paging.h" |
swissChili | defeb0d | 2021-02-18 15:28:36 -0800 | [diff] [blame] | 6 | #include "timer.h" |
swissChili | 825d46b | 2021-02-21 10:14:16 -0800 | [diff] [blame] | 7 | #include "vga.h" |
swissChili | f544862 | 2021-03-08 20:17:36 -0800 | [diff] [blame] | 8 | #include "vfs.h" |
swissChili | c2e62ed | 2021-03-10 17:04:18 -0800 | [diff] [blame] | 9 | #include "vfs_initrd.h" |
swissChili | 9752ab3 | 2021-03-05 11:20:13 -0800 | [diff] [blame] | 10 | #include "multiboot.h" |
swissChili | d813792 | 2021-02-17 15:34:07 -0800 | [diff] [blame] | 11 | |
swissChili | da23a91 | 2021-03-12 16:07:50 -0800 | [diff] [blame] | 12 | int kmain(struct multiboot_info *mboot) |
swissChili | d813792 | 2021-02-17 15:34:07 -0800 | [diff] [blame] | 13 | { |
swissChili | e0a79bb | 2021-02-22 19:54:48 -0800 | [diff] [blame] | 14 | init_paging(); |
swissChili | dc25b2b | 2021-02-23 17:07:13 -0800 | [diff] [blame] | 15 | init_vga(); |
swissChili | 0b35bf2 | 2021-02-18 12:49:40 -0800 | [diff] [blame] | 16 | init_descriptor_tables(); |
swissChili | 6c0519e | 2021-03-07 19:40:23 -0800 | [diff] [blame] | 17 | vga_clear(); |
swissChili | d813792 | 2021-02-17 15:34:07 -0800 | [diff] [blame] | 18 | |
swissChili | 825d46b | 2021-02-21 10:14:16 -0800 | [diff] [blame] | 19 | init_timer(20); |
swissChili | e4f0199 | 2021-02-25 15:38:12 -0800 | [diff] [blame] | 20 | init_allocator(); |
swissChili | 19ef418 | 2021-02-21 17:45:51 -0800 | [diff] [blame] | 21 | init_kbd(); |
swissChili | e4f0199 | 2021-02-25 15:38:12 -0800 | [diff] [blame] | 22 | |
swissChili | 6c0519e | 2021-03-07 19:40:23 -0800 | [diff] [blame] | 23 | #ifdef TEST_ALLOC |
| 24 | test_allocator(); |
| 25 | #endif |
swissChili | e4f0199 | 2021-02-25 15:38:12 -0800 | [diff] [blame] | 26 | |
swissChili | 9752ab3 | 2021-03-05 11:20:13 -0800 | [diff] [blame] | 27 | // Load initrd |
swissChili | da23a91 | 2021-03-12 16:07:50 -0800 | [diff] [blame] | 28 | struct multiboot_info mb = make_multiboot_physical(mboot); |
swissChili | 2b5acc8 | 2021-03-13 17:06:42 -0800 | [diff] [blame] | 29 | init_vfs(); |
swissChili | 9752ab3 | 2021-03-05 11:20:13 -0800 | [diff] [blame] | 30 | |
swissChili | 2b5acc8 | 2021-03-13 17:06:42 -0800 | [diff] [blame] | 31 | #ifdef INITRD |
swissChili | 9752ab3 | 2021-03-05 11:20:13 -0800 | [diff] [blame] | 32 | kassert(mb.mods_count, "No multiboot modules loaded!"); |
| 33 | kprintf("mboot->mods_addr = %d (0x%x)\n", mb.mods_addr, mb.mods_addr); |
swissChili | da23a91 | 2021-03-12 16:07:50 -0800 | [diff] [blame] | 34 | uchar *initrd_loc = (uchar *)((uint *)mb.mods_addr)[0]; |
swissChili | 9752ab3 | 2021-03-05 11:20:13 -0800 | [diff] [blame] | 35 | |
swissChili | 6c0519e | 2021-03-07 19:40:23 -0800 | [diff] [blame] | 36 | kprintf("initrd is at 0x%x to 0x%x\n", initrd_loc); |
swissChili | 9752ab3 | 2021-03-05 11:20:13 -0800 | [diff] [blame] | 37 | |
swissChili | 2b5acc8 | 2021-03-13 17:06:42 -0800 | [diff] [blame] | 38 | init_initrd_vfs(initrd_loc); |
| 39 | #endif |
swissChili | da23a91 | 2021-03-12 16:07:50 -0800 | [diff] [blame] | 40 | |
swissChili | f544862 | 2021-03-08 20:17:36 -0800 | [diff] [blame] | 41 | kprintf("VFS initialized\n"); |
| 42 | |
| 43 | vga_set_color(LIGHT_GREEN, BLACK); |
swissChili | 2b5acc8 | 2021-03-13 17:06:42 -0800 | [diff] [blame] | 44 | kprintf("Setup complete!\n"); |
swissChili | f544862 | 2021-03-08 20:17:36 -0800 | [diff] [blame] | 45 | vga_set_color(WHITE, BLACK); |
| 46 | |
swissChili | 2b5acc8 | 2021-03-13 17:06:42 -0800 | [diff] [blame] | 47 | #ifdef TEST_VFS_INITRD |
swissChili | c2e62ed | 2021-03-10 17:04:18 -0800 | [diff] [blame] | 48 | kprintf("fs_readdir(\"/dev/initrd\")\n"); |
swissChili | b7fe899 | 2021-03-10 16:25:47 -0800 | [diff] [blame] | 49 | |
| 50 | struct fs_dirent dirent; |
swissChili | da23a91 | 2021-03-12 16:07:50 -0800 | [diff] [blame] | 51 | for (int i = 0; fs_readdir(&root, i, &dirent); i++) |
swissChili | b7fe899 | 2021-03-10 16:25:47 -0800 | [diff] [blame] | 52 | { |
| 53 | kprintf("name: %s, inode: %d\n", dirent.name, dirent.inode); |
| 54 | } |
swissChili | 2b5acc8 | 2021-03-13 17:06:42 -0800 | [diff] [blame] | 55 | #endif |
swissChili | b7fe899 | 2021-03-10 16:25:47 -0800 | [diff] [blame] | 56 | |
swissChili | defeb0d | 2021-02-18 15:28:36 -0800 | [diff] [blame] | 57 | asm volatile("sti"); |
| 58 | |
swissChili | 825d46b | 2021-02-21 10:14:16 -0800 | [diff] [blame] | 59 | while (true) |
| 60 | asm volatile("hlt"); |
| 61 | |
swissChili | d813792 | 2021-02-17 15:34:07 -0800 | [diff] [blame] | 62 | return 0xCAFEBABE; |
| 63 | } |