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 | cfd3c3c | 2021-04-03 15:04:24 -0700 | [diff] [blame] | 5 | #include "multiboot.h" |
swissChili | e4f0199 | 2021-02-25 15:38:12 -0800 | [diff] [blame] | 6 | #include "paging.h" |
swissChili | 4749d02 | 2021-07-19 12:33:06 -0700 | [diff] [blame] | 7 | #include "sync.h" |
swissChili | cfd3c3c | 2021-04-03 15:04:24 -0700 | [diff] [blame] | 8 | #include "syscall.h" |
| 9 | #include "task.h" |
swissChili | defeb0d | 2021-02-18 15:28:36 -0800 | [diff] [blame] | 10 | #include "timer.h" |
swissChili | f544862 | 2021-03-08 20:17:36 -0800 | [diff] [blame] | 11 | #include "vfs.h" |
swissChili | c2e62ed | 2021-03-10 17:04:18 -0800 | [diff] [blame] | 12 | #include "vfs_initrd.h" |
swissChili | cfd3c3c | 2021-04-03 15:04:24 -0700 | [diff] [blame] | 13 | #include "vga.h" |
swissChili | 1a3f07f | 2021-04-05 20:01:55 -0700 | [diff] [blame] | 14 | #include <dri/ata_pio/ata_pio.h> |
swissChili | 4418ca5 | 2021-06-14 17:36:00 -0700 | [diff] [blame] | 15 | #include <dri/fs/ext2/ext2.h> |
swissChili | 4749d02 | 2021-07-19 12:33:06 -0700 | [diff] [blame] | 16 | #include <dri/ide/ide.h> |
| 17 | #include <dri/pci/pci.h> |
swissChili | cfd3c3c | 2021-04-03 15:04:24 -0700 | [diff] [blame] | 18 | |
| 19 | void greet() |
| 20 | { |
swissChili | 9bd74de | 2021-06-15 20:30:48 -0700 | [diff] [blame] | 21 | kprintf(DEBUG "Hello from get_task_id() = %d, get_process_id() = %d\n", |
swissChili | cfd3c3c | 2021-04-03 15:04:24 -0700 | [diff] [blame] | 22 | get_task_id(), get_process_id()); |
| 23 | } |
| 24 | |
swissChili | f01ddcc | 2021-04-04 11:31:34 -0700 | [diff] [blame] | 25 | void other_thread(size_t data) |
swissChili | cfd3c3c | 2021-04-03 15:04:24 -0700 | [diff] [blame] | 26 | { |
swissChili | 9bd74de | 2021-06-15 20:30:48 -0700 | [diff] [blame] | 27 | kprintf(DEBUG "data is 0x%x\n", data); |
swissChili | f01ddcc | 2021-04-04 11:31:34 -0700 | [diff] [blame] | 28 | greet(); |
swissChili | 9bd74de | 2021-06-15 20:30:48 -0700 | [diff] [blame] | 29 | kprintf(DEBUG "Returning from other_thread\n"); |
swissChili | f01ddcc | 2021-04-04 11:31:34 -0700 | [diff] [blame] | 30 | |
| 31 | return; |
swissChili | cfd3c3c | 2021-04-03 15:04:24 -0700 | [diff] [blame] | 32 | } |
swissChili | d813792 | 2021-02-17 15:34:07 -0800 | [diff] [blame] | 33 | |
swissChili | da23a91 | 2021-03-12 16:07:50 -0800 | [diff] [blame] | 34 | int kmain(struct multiboot_info *mboot) |
swissChili | d813792 | 2021-02-17 15:34:07 -0800 | [diff] [blame] | 35 | { |
swissChili | e0a79bb | 2021-02-22 19:54:48 -0800 | [diff] [blame] | 36 | init_paging(); |
swissChili | dc25b2b | 2021-02-23 17:07:13 -0800 | [diff] [blame] | 37 | init_vga(); |
swissChili | 0b35bf2 | 2021-02-18 12:49:40 -0800 | [diff] [blame] | 38 | init_descriptor_tables(); |
swissChili | 6422869 | 2021-03-16 08:19:23 -0700 | [diff] [blame] | 39 | init_syscall(); |
swissChili | 6c0519e | 2021-03-07 19:40:23 -0800 | [diff] [blame] | 40 | vga_clear(); |
swissChili | d813792 | 2021-02-17 15:34:07 -0800 | [diff] [blame] | 41 | |
swissChili | 825d46b | 2021-02-21 10:14:16 -0800 | [diff] [blame] | 42 | init_timer(20); |
swissChili | e4f0199 | 2021-02-25 15:38:12 -0800 | [diff] [blame] | 43 | init_allocator(); |
swissChili | 19ef418 | 2021-02-21 17:45:51 -0800 | [diff] [blame] | 44 | init_kbd(); |
swissChili | e4f0199 | 2021-02-25 15:38:12 -0800 | [diff] [blame] | 45 | |
swissChili | 6c0519e | 2021-03-07 19:40:23 -0800 | [diff] [blame] | 46 | #ifdef TEST_ALLOC |
| 47 | test_allocator(); |
| 48 | #endif |
swissChili | e4f0199 | 2021-02-25 15:38:12 -0800 | [diff] [blame] | 49 | |
swissChili | 9752ab3 | 2021-03-05 11:20:13 -0800 | [diff] [blame] | 50 | // Load initrd |
swissChili | da23a91 | 2021-03-12 16:07:50 -0800 | [diff] [blame] | 51 | struct multiboot_info mb = make_multiboot_physical(mboot); |
swissChili | 2b5acc8 | 2021-03-13 17:06:42 -0800 | [diff] [blame] | 52 | init_vfs(); |
swissChili | 9752ab3 | 2021-03-05 11:20:13 -0800 | [diff] [blame] | 53 | |
swissChili | 2b5acc8 | 2021-03-13 17:06:42 -0800 | [diff] [blame] | 54 | #ifdef INITRD |
swissChili | 9752ab3 | 2021-03-05 11:20:13 -0800 | [diff] [blame] | 55 | kassert(mb.mods_count, "No multiboot modules loaded!"); |
swissChili | 9bd74de | 2021-06-15 20:30:48 -0700 | [diff] [blame] | 56 | kprintf(DEBUG "mboot->mods_addr = %d (0x%x)\n", mb.mods_addr, mb.mods_addr); |
swissChili | da23a91 | 2021-03-12 16:07:50 -0800 | [diff] [blame] | 57 | uchar *initrd_loc = (uchar *)((uint *)mb.mods_addr)[0]; |
swissChili | 9752ab3 | 2021-03-05 11:20:13 -0800 | [diff] [blame] | 58 | |
swissChili | 9bd74de | 2021-06-15 20:30:48 -0700 | [diff] [blame] | 59 | kprintf(DEBUG "initrd is at 0x%x to 0x%x\n", initrd_loc); |
swissChili | 9752ab3 | 2021-03-05 11:20:13 -0800 | [diff] [blame] | 60 | |
swissChili | 2b5acc8 | 2021-03-13 17:06:42 -0800 | [diff] [blame] | 61 | init_initrd_vfs(initrd_loc); |
| 62 | #endif |
swissChili | da23a91 | 2021-03-12 16:07:50 -0800 | [diff] [blame] | 63 | |
swissChili | 9bd74de | 2021-06-15 20:30:48 -0700 | [diff] [blame] | 64 | kprintf(OKAY "VFS initialized\n"); |
swissChili | f544862 | 2021-03-08 20:17:36 -0800 | [diff] [blame] | 65 | |
swissChili | 9bd74de | 2021-06-15 20:30:48 -0700 | [diff] [blame] | 66 | kprintf(OKAY "Initial setup complete!\n"); |
swissChili | f544862 | 2021-03-08 20:17:36 -0800 | [diff] [blame] | 67 | |
swissChili | 2b5acc8 | 2021-03-13 17:06:42 -0800 | [diff] [blame] | 68 | #ifdef TEST_VFS_INITRD |
swissChili | 9bd74de | 2021-06-15 20:30:48 -0700 | [diff] [blame] | 69 | kprintf(INFO "fs_readdir(\"/dev/initrd\")\n"); |
swissChili | b7fe899 | 2021-03-10 16:25:47 -0800 | [diff] [blame] | 70 | |
| 71 | struct fs_dirent dirent; |
swissChili | da23a91 | 2021-03-12 16:07:50 -0800 | [diff] [blame] | 72 | for (int i = 0; fs_readdir(&root, i, &dirent); i++) |
swissChili | b7fe899 | 2021-03-10 16:25:47 -0800 | [diff] [blame] | 73 | { |
swissChili | 9bd74de | 2021-06-15 20:30:48 -0700 | [diff] [blame] | 74 | kprintf(INFO "name: %s, inode: %d\n", dirent.name, dirent.inode); |
swissChili | b7fe899 | 2021-03-10 16:25:47 -0800 | [diff] [blame] | 75 | } |
swissChili | 2b5acc8 | 2021-03-13 17:06:42 -0800 | [diff] [blame] | 76 | #endif |
swissChili | b7fe899 | 2021-03-10 16:25:47 -0800 | [diff] [blame] | 77 | |
swissChili | 402a383 | 2021-05-29 21:41:31 -0700 | [diff] [blame] | 78 | asm("sti"); |
swissChili | aed6ff3 | 2021-05-29 17:51:04 -0700 | [diff] [blame] | 79 | |
swissChili | cfd3c3c | 2021-04-03 15:04:24 -0700 | [diff] [blame] | 80 | init_tasks(); |
swissChili | 4749d02 | 2021-07-19 12:33:06 -0700 | [diff] [blame] | 81 | init_sync(); |
| 82 | |
swissChili | 5fe85a1 | 2021-05-31 08:10:27 -0700 | [diff] [blame] | 83 | pci_init(); |
| 84 | |
| 85 | // Register PCI drivers |
| 86 | ide_register(); |
| 87 | |
| 88 | pci_load(); |
| 89 | |
swissChili | e5adca5 | 2021-06-16 21:00:31 -0700 | [diff] [blame] | 90 | kprintf(OKAY "Loaded PCI device drivers\n"); |
swissChili | 9bd74de | 2021-06-15 20:30:48 -0700 | [diff] [blame] | 91 | |
swissChili | 402a383 | 2021-05-29 21:41:31 -0700 | [diff] [blame] | 92 | #ifdef TEST_THREADS |
swissChili | f01ddcc | 2021-04-04 11:31:34 -0700 | [diff] [blame] | 93 | spawn_thread(other_thread, NULL); |
swissChili | cfd3c3c | 2021-04-03 15:04:24 -0700 | [diff] [blame] | 94 | |
swissChili | f01ddcc | 2021-04-04 11:31:34 -0700 | [diff] [blame] | 95 | greet(); |
swissChili | 402a383 | 2021-05-29 21:41:31 -0700 | [diff] [blame] | 96 | #endif |
swissChili | defeb0d | 2021-02-18 15:28:36 -0800 | [diff] [blame] | 97 | |
swissChili | aed6ff3 | 2021-05-29 17:51:04 -0700 | [diff] [blame] | 98 | #ifdef TEST_PCI |
swissChili | 402a383 | 2021-05-29 21:41:31 -0700 | [diff] [blame] | 99 | pci_print_devices(); |
swissChili | 5fe85a1 | 2021-05-31 08:10:27 -0700 | [diff] [blame] | 100 | pci_print_drivers(); |
swissChili | aed6ff3 | 2021-05-29 17:51:04 -0700 | [diff] [blame] | 101 | #endif |
| 102 | |
swissChili | 4418ca5 | 2021-06-14 17:36:00 -0700 | [diff] [blame] | 103 | #ifdef TEST_ATA_PIO |
| 104 | test_ata_pio(); |
| 105 | #endif |
| 106 | |
swissChili | 9bd74de | 2021-06-15 20:30:48 -0700 | [diff] [blame] | 107 | if (ext2_valid_filesystem()) |
| 108 | { |
swissChili | b7ef65d | 2021-07-17 12:51:52 -0700 | [diff] [blame] | 109 | kprintf(OKAY "EXT2 filesystem is valid\n"); |
| 110 | ext2_mount(&root); |
swissChili | 9bd74de | 2021-06-15 20:30:48 -0700 | [diff] [blame] | 111 | } |
swissChili | b7ef65d | 2021-07-17 12:51:52 -0700 | [diff] [blame] | 112 | else |
| 113 | { |
swissChili | 4749d02 | 2021-07-19 12:33:06 -0700 | [diff] [blame] | 114 | kprintf( |
| 115 | WARN |
| 116 | "Filesystem is not a valid EXT2 format, only EXT2 is supported\n"); |
swissChili | b7ef65d | 2021-07-17 12:51:52 -0700 | [diff] [blame] | 117 | } |
swissChili | 276b8cf | 2021-07-16 13:24:42 -0700 | [diff] [blame] | 118 | |
swissChili | ef97c26 | 2021-04-04 10:20:21 -0700 | [diff] [blame] | 119 | while (true) |
swissChili | 402a383 | 2021-05-29 21:41:31 -0700 | [diff] [blame] | 120 | asm("hlt"); |
swissChili | f01ddcc | 2021-04-04 11:31:34 -0700 | [diff] [blame] | 121 | |
swissChili | d813792 | 2021-02-17 15:34:07 -0800 | [diff] [blame] | 122 | return 0xCAFEBABE; |
| 123 | } |