blob: 1aebed672cc70ec99b61a77dbca591c17f6d449a [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"
swissChilicfd3c3c2021-04-03 15:04:24 -07005#include "multiboot.h"
swissChilie4f01992021-02-25 15:38:12 -08006#include "paging.h"
swissChilicfd3c3c2021-04-03 15:04:24 -07007#include "syscall.h"
8#include "task.h"
swissChilidefeb0d2021-02-18 15:28:36 -08009#include "timer.h"
swissChilif5448622021-03-08 20:17:36 -080010#include "vfs.h"
swissChilic2e62ed2021-03-10 17:04:18 -080011#include "vfs_initrd.h"
swissChilicfd3c3c2021-04-03 15:04:24 -070012#include "vga.h"
13
14void greet()
15{
16 kprintf("Hello from get_task_id() = %d, get_process_id() = %d\n",
17 get_task_id(), get_process_id());
18}
19
20void other_thread()
21{
22 greet();
23 kprintf("Other thread returning...\n");
24 switch_task();
25
26 while (true)
27 asm volatile("hlt");
28}
swissChilid8137922021-02-17 15:34:07 -080029
swissChilida23a912021-03-12 16:07:50 -080030int kmain(struct multiboot_info *mboot)
swissChilid8137922021-02-17 15:34:07 -080031{
swissChilie0a79bb2021-02-22 19:54:48 -080032 init_paging();
swissChilidc25b2b2021-02-23 17:07:13 -080033 init_vga();
swissChili0b35bf22021-02-18 12:49:40 -080034 init_descriptor_tables();
swissChili64228692021-03-16 08:19:23 -070035 init_syscall();
swissChili6c0519e2021-03-07 19:40:23 -080036 vga_clear();
swissChilid8137922021-02-17 15:34:07 -080037
swissChili825d46b2021-02-21 10:14:16 -080038 init_timer(20);
swissChilie4f01992021-02-25 15:38:12 -080039 init_allocator();
swissChili19ef4182021-02-21 17:45:51 -080040 init_kbd();
swissChilie4f01992021-02-25 15:38:12 -080041
swissChili6c0519e2021-03-07 19:40:23 -080042#ifdef TEST_ALLOC
43 test_allocator();
44#endif
swissChilie4f01992021-02-25 15:38:12 -080045
swissChili9752ab32021-03-05 11:20:13 -080046 // Load initrd
swissChilida23a912021-03-12 16:07:50 -080047 struct multiboot_info mb = make_multiboot_physical(mboot);
swissChili2b5acc82021-03-13 17:06:42 -080048 init_vfs();
swissChili9752ab32021-03-05 11:20:13 -080049
swissChili2b5acc82021-03-13 17:06:42 -080050#ifdef INITRD
swissChili9752ab32021-03-05 11:20:13 -080051 kassert(mb.mods_count, "No multiboot modules loaded!");
52 kprintf("mboot->mods_addr = %d (0x%x)\n", mb.mods_addr, mb.mods_addr);
swissChilida23a912021-03-12 16:07:50 -080053 uchar *initrd_loc = (uchar *)((uint *)mb.mods_addr)[0];
swissChili9752ab32021-03-05 11:20:13 -080054
swissChili6c0519e2021-03-07 19:40:23 -080055 kprintf("initrd is at 0x%x to 0x%x\n", initrd_loc);
swissChili9752ab32021-03-05 11:20:13 -080056
swissChili2b5acc82021-03-13 17:06:42 -080057 init_initrd_vfs(initrd_loc);
58#endif
swissChilida23a912021-03-12 16:07:50 -080059
swissChilif5448622021-03-08 20:17:36 -080060 kprintf("VFS initialized\n");
61
62 vga_set_color(LIGHT_GREEN, BLACK);
swissChili2b5acc82021-03-13 17:06:42 -080063 kprintf("Setup complete!\n");
swissChilif5448622021-03-08 20:17:36 -080064 vga_set_color(WHITE, BLACK);
65
swissChili2b5acc82021-03-13 17:06:42 -080066#ifdef TEST_VFS_INITRD
swissChilic2e62ed2021-03-10 17:04:18 -080067 kprintf("fs_readdir(\"/dev/initrd\")\n");
swissChilib7fe8992021-03-10 16:25:47 -080068
69 struct fs_dirent dirent;
swissChilida23a912021-03-12 16:07:50 -080070 for (int i = 0; fs_readdir(&root, i, &dirent); i++)
swissChilib7fe8992021-03-10 16:25:47 -080071 {
72 kprintf("name: %s, inode: %d\n", dirent.name, dirent.inode);
73 }
swissChili2b5acc82021-03-13 17:06:42 -080074#endif
swissChilib7fe8992021-03-10 16:25:47 -080075
swissChilicfd3c3c2021-04-03 15:04:24 -070076 kprintf("initializing tasks\n");
77 init_tasks();
78 kprintf("\ndone initializing tasks\n");
79
80 greet();
swissChilic496cd72021-04-04 09:58:38 -070081 kprintf("other_thread = 0x%x\n", &other_thread);
swissChilicfd3c3c2021-04-03 15:04:24 -070082 spawn_thread(other_thread);
83 kprintf("thread spawned\n");
swissChili7be32742021-04-03 21:17:24 -070084
swissChilicfd3c3c2021-04-03 15:04:24 -070085 switch_task();
86 kprintf("Back in main thread\n");
87
swissChilidefeb0d2021-02-18 15:28:36 -080088 asm volatile("sti");
89
swissChili825d46b2021-02-21 10:14:16 -080090 while (true)
91 asm volatile("hlt");
92
swissChilid8137922021-02-17 15:34:07 -080093 return 0xCAFEBABE;
94}