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 | cfd3c3c | 2021-04-03 15:04:24 -0700 | [diff] [blame] | 7 | #include "syscall.h" |
| 8 | #include "task.h" |
swissChili | defeb0d | 2021-02-18 15:28:36 -0800 | [diff] [blame] | 9 | #include "timer.h" |
swissChili | f544862 | 2021-03-08 20:17:36 -0800 | [diff] [blame] | 10 | #include "vfs.h" |
swissChili | c2e62ed | 2021-03-10 17:04:18 -0800 | [diff] [blame] | 11 | #include "vfs_initrd.h" |
swissChili | cfd3c3c | 2021-04-03 15:04:24 -0700 | [diff] [blame] | 12 | #include "vga.h" |
swissChili | 1a3f07f | 2021-04-05 20:01:55 -0700 | [diff] [blame] | 13 | #include <dri/ata_pio/ata_pio.h> |
swissChili | ca26848 | 2021-05-28 18:31:46 -0700 | [diff] [blame] | 14 | #include <dri/pci/pci.h> |
swissChili | cfd3c3c | 2021-04-03 15:04:24 -0700 | [diff] [blame] | 15 | |
| 16 | void greet() |
| 17 | { |
| 18 | kprintf("Hello from get_task_id() = %d, get_process_id() = %d\n", |
| 19 | get_task_id(), get_process_id()); |
| 20 | } |
| 21 | |
swissChili | f01ddcc | 2021-04-04 11:31:34 -0700 | [diff] [blame] | 22 | void other_thread(size_t data) |
swissChili | cfd3c3c | 2021-04-03 15:04:24 -0700 | [diff] [blame] | 23 | { |
swissChili | f01ddcc | 2021-04-04 11:31:34 -0700 | [diff] [blame] | 24 | kprintf("data is 0x%x\n", data); |
| 25 | greet(); |
| 26 | kprintf("Returning from other_thread\n"); |
| 27 | |
| 28 | return; |
swissChili | cfd3c3c | 2021-04-03 15:04:24 -0700 | [diff] [blame] | 29 | } |
swissChili | d813792 | 2021-02-17 15:34:07 -0800 | [diff] [blame] | 30 | |
swissChili | da23a91 | 2021-03-12 16:07:50 -0800 | [diff] [blame] | 31 | int kmain(struct multiboot_info *mboot) |
swissChili | d813792 | 2021-02-17 15:34:07 -0800 | [diff] [blame] | 32 | { |
swissChili | e0a79bb | 2021-02-22 19:54:48 -0800 | [diff] [blame] | 33 | init_paging(); |
swissChili | dc25b2b | 2021-02-23 17:07:13 -0800 | [diff] [blame] | 34 | init_vga(); |
swissChili | 0b35bf2 | 2021-02-18 12:49:40 -0800 | [diff] [blame] | 35 | init_descriptor_tables(); |
swissChili | 6422869 | 2021-03-16 08:19:23 -0700 | [diff] [blame] | 36 | init_syscall(); |
swissChili | 6c0519e | 2021-03-07 19:40:23 -0800 | [diff] [blame] | 37 | vga_clear(); |
swissChili | d813792 | 2021-02-17 15:34:07 -0800 | [diff] [blame] | 38 | |
swissChili | 825d46b | 2021-02-21 10:14:16 -0800 | [diff] [blame] | 39 | init_timer(20); |
swissChili | e4f0199 | 2021-02-25 15:38:12 -0800 | [diff] [blame] | 40 | init_allocator(); |
swissChili | 19ef418 | 2021-02-21 17:45:51 -0800 | [diff] [blame] | 41 | init_kbd(); |
swissChili | e4f0199 | 2021-02-25 15:38:12 -0800 | [diff] [blame] | 42 | |
swissChili | 6c0519e | 2021-03-07 19:40:23 -0800 | [diff] [blame] | 43 | #ifdef TEST_ALLOC |
| 44 | test_allocator(); |
| 45 | #endif |
swissChili | e4f0199 | 2021-02-25 15:38:12 -0800 | [diff] [blame] | 46 | |
swissChili | 9752ab3 | 2021-03-05 11:20:13 -0800 | [diff] [blame] | 47 | // Load initrd |
swissChili | da23a91 | 2021-03-12 16:07:50 -0800 | [diff] [blame] | 48 | struct multiboot_info mb = make_multiboot_physical(mboot); |
swissChili | 2b5acc8 | 2021-03-13 17:06:42 -0800 | [diff] [blame] | 49 | init_vfs(); |
swissChili | 9752ab3 | 2021-03-05 11:20:13 -0800 | [diff] [blame] | 50 | |
swissChili | 2b5acc8 | 2021-03-13 17:06:42 -0800 | [diff] [blame] | 51 | #ifdef INITRD |
swissChili | 9752ab3 | 2021-03-05 11:20:13 -0800 | [diff] [blame] | 52 | kassert(mb.mods_count, "No multiboot modules loaded!"); |
| 53 | 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] | 54 | uchar *initrd_loc = (uchar *)((uint *)mb.mods_addr)[0]; |
swissChili | 9752ab3 | 2021-03-05 11:20:13 -0800 | [diff] [blame] | 55 | |
swissChili | 6c0519e | 2021-03-07 19:40:23 -0800 | [diff] [blame] | 56 | kprintf("initrd is at 0x%x to 0x%x\n", initrd_loc); |
swissChili | 9752ab3 | 2021-03-05 11:20:13 -0800 | [diff] [blame] | 57 | |
swissChili | 2b5acc8 | 2021-03-13 17:06:42 -0800 | [diff] [blame] | 58 | init_initrd_vfs(initrd_loc); |
| 59 | #endif |
swissChili | da23a91 | 2021-03-12 16:07:50 -0800 | [diff] [blame] | 60 | |
swissChili | f544862 | 2021-03-08 20:17:36 -0800 | [diff] [blame] | 61 | kprintf("VFS initialized\n"); |
| 62 | |
| 63 | vga_set_color(LIGHT_GREEN, BLACK); |
swissChili | 2b5acc8 | 2021-03-13 17:06:42 -0800 | [diff] [blame] | 64 | kprintf("Setup complete!\n"); |
swissChili | f544862 | 2021-03-08 20:17:36 -0800 | [diff] [blame] | 65 | vga_set_color(WHITE, BLACK); |
| 66 | |
swissChili | 2b5acc8 | 2021-03-13 17:06:42 -0800 | [diff] [blame] | 67 | #ifdef TEST_VFS_INITRD |
swissChili | c2e62ed | 2021-03-10 17:04:18 -0800 | [diff] [blame] | 68 | kprintf("fs_readdir(\"/dev/initrd\")\n"); |
swissChili | b7fe899 | 2021-03-10 16:25:47 -0800 | [diff] [blame] | 69 | |
| 70 | struct fs_dirent dirent; |
swissChili | da23a91 | 2021-03-12 16:07:50 -0800 | [diff] [blame] | 71 | for (int i = 0; fs_readdir(&root, i, &dirent); i++) |
swissChili | b7fe899 | 2021-03-10 16:25:47 -0800 | [diff] [blame] | 72 | { |
| 73 | kprintf("name: %s, inode: %d\n", dirent.name, dirent.inode); |
| 74 | } |
swissChili | 2b5acc8 | 2021-03-13 17:06:42 -0800 | [diff] [blame] | 75 | #endif |
swissChili | b7fe899 | 2021-03-10 16:25:47 -0800 | [diff] [blame] | 76 | |
swissChili | cfd3c3c | 2021-04-03 15:04:24 -0700 | [diff] [blame] | 77 | kprintf("initializing tasks\n"); |
| 78 | init_tasks(); |
| 79 | kprintf("\ndone initializing tasks\n"); |
| 80 | |
swissChili | 1a3f07f | 2021-04-05 20:01:55 -0700 | [diff] [blame] | 81 | #ifdef TEST_THREADS |
swissChili | f01ddcc | 2021-04-04 11:31:34 -0700 | [diff] [blame] | 82 | spawn_thread(other_thread, NULL); |
swissChili | cfd3c3c | 2021-04-03 15:04:24 -0700 | [diff] [blame] | 83 | |
swissChili | f01ddcc | 2021-04-04 11:31:34 -0700 | [diff] [blame] | 84 | greet(); |
swissChili | 1a3f07f | 2021-04-05 20:01:55 -0700 | [diff] [blame] | 85 | #endif |
swissChili | defeb0d | 2021-02-18 15:28:36 -0800 | [diff] [blame] | 86 | |
swissChili | ca26848 | 2021-05-28 18:31:46 -0700 | [diff] [blame] | 87 | #ifdef TEST_ATA_PIO |
swissChili | 1a3f07f | 2021-04-05 20:01:55 -0700 | [diff] [blame] | 88 | test_ata_pio(); |
swissChili | ca26848 | 2021-05-28 18:31:46 -0700 | [diff] [blame] | 89 | #endif |
| 90 | |
swissChili | 77eb147 | 2021-05-28 21:40:00 -0700 | [diff] [blame^] | 91 | kprintf("Enumerating PCI devices:\n"); |
swissChili | ca26848 | 2021-05-28 18:31:46 -0700 | [diff] [blame] | 92 | for (int bus = 0; bus < 0xff; bus++) |
| 93 | { |
| 94 | for (int slot = 0; slot < 32; slot++) |
| 95 | { |
| 96 | for (int func = 0; func < 8; func++) |
| 97 | { |
swissChili | 9321498 | 2021-05-28 21:32:26 -0700 | [diff] [blame] | 98 | uint vendor; |
| 99 | |
| 100 | struct pci_vendor *v = pci_check_vendor(bus, slot, func, &vendor); |
| 101 | |
| 102 | if (vendor != ~0) |
swissChili | ca26848 | 2021-05-28 18:31:46 -0700 | [diff] [blame] | 103 | { |
swissChili | 77eb147 | 2021-05-28 21:40:00 -0700 | [diff] [blame^] | 104 | kprintf("%d %d %d --- 0x%x --- %s\n", bus, slot, func, vendor, v->name); |
swissChili | ca26848 | 2021-05-28 18:31:46 -0700 | [diff] [blame] | 105 | } |
| 106 | } |
| 107 | } |
| 108 | } |
swissChili | 9321498 | 2021-05-28 21:32:26 -0700 | [diff] [blame] | 109 | |
swissChili | ef97c26 | 2021-04-04 10:20:21 -0700 | [diff] [blame] | 110 | while (true) |
swissChili | 825d46b | 2021-02-21 10:14:16 -0800 | [diff] [blame] | 111 | asm volatile("hlt"); |
| 112 | |
swissChili | f01ddcc | 2021-04-04 11:31:34 -0700 | [diff] [blame] | 113 | |
swissChili | d813792 | 2021-02-17 15:34:07 -0800 | [diff] [blame] | 114 | return 0xCAFEBABE; |
| 115 | } |