blob: 868268180c6cfaa320a06a0777da70c273c81e3d [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"
swissChili1a3f07f2021-04-05 20:01:55 -070013#include <dri/ata_pio/ata_pio.h>
swissChilica268482021-05-28 18:31:46 -070014#include <dri/pci/pci.h>
swissChilicfd3c3c2021-04-03 15:04:24 -070015
16void greet()
17{
18 kprintf("Hello from get_task_id() = %d, get_process_id() = %d\n",
19 get_task_id(), get_process_id());
20}
21
swissChilif01ddcc2021-04-04 11:31:34 -070022void other_thread(size_t data)
swissChilicfd3c3c2021-04-03 15:04:24 -070023{
swissChilif01ddcc2021-04-04 11:31:34 -070024 kprintf("data is 0x%x\n", data);
25 greet();
26 kprintf("Returning from other_thread\n");
27
28 return;
swissChilicfd3c3c2021-04-03 15:04:24 -070029}
swissChilid8137922021-02-17 15:34:07 -080030
swissChilida23a912021-03-12 16:07:50 -080031int kmain(struct multiboot_info *mboot)
swissChilid8137922021-02-17 15:34:07 -080032{
swissChilie0a79bb2021-02-22 19:54:48 -080033 init_paging();
swissChilidc25b2b2021-02-23 17:07:13 -080034 init_vga();
swissChili0b35bf22021-02-18 12:49:40 -080035 init_descriptor_tables();
swissChili64228692021-03-16 08:19:23 -070036 init_syscall();
swissChili6c0519e2021-03-07 19:40:23 -080037 vga_clear();
swissChilid8137922021-02-17 15:34:07 -080038
swissChili825d46b2021-02-21 10:14:16 -080039 init_timer(20);
swissChilie4f01992021-02-25 15:38:12 -080040 init_allocator();
swissChili19ef4182021-02-21 17:45:51 -080041 init_kbd();
swissChilie4f01992021-02-25 15:38:12 -080042
swissChili6c0519e2021-03-07 19:40:23 -080043#ifdef TEST_ALLOC
44 test_allocator();
45#endif
swissChilie4f01992021-02-25 15:38:12 -080046
swissChili9752ab32021-03-05 11:20:13 -080047 // Load initrd
swissChilida23a912021-03-12 16:07:50 -080048 struct multiboot_info mb = make_multiboot_physical(mboot);
swissChili2b5acc82021-03-13 17:06:42 -080049 init_vfs();
swissChili9752ab32021-03-05 11:20:13 -080050
swissChili2b5acc82021-03-13 17:06:42 -080051#ifdef INITRD
swissChili9752ab32021-03-05 11:20:13 -080052 kassert(mb.mods_count, "No multiboot modules loaded!");
53 kprintf("mboot->mods_addr = %d (0x%x)\n", mb.mods_addr, mb.mods_addr);
swissChilida23a912021-03-12 16:07:50 -080054 uchar *initrd_loc = (uchar *)((uint *)mb.mods_addr)[0];
swissChili9752ab32021-03-05 11:20:13 -080055
swissChili6c0519e2021-03-07 19:40:23 -080056 kprintf("initrd is at 0x%x to 0x%x\n", initrd_loc);
swissChili9752ab32021-03-05 11:20:13 -080057
swissChili2b5acc82021-03-13 17:06:42 -080058 init_initrd_vfs(initrd_loc);
59#endif
swissChilida23a912021-03-12 16:07:50 -080060
swissChilif5448622021-03-08 20:17:36 -080061 kprintf("VFS initialized\n");
62
63 vga_set_color(LIGHT_GREEN, BLACK);
swissChili2b5acc82021-03-13 17:06:42 -080064 kprintf("Setup complete!\n");
swissChilif5448622021-03-08 20:17:36 -080065 vga_set_color(WHITE, BLACK);
66
swissChili2b5acc82021-03-13 17:06:42 -080067#ifdef TEST_VFS_INITRD
swissChilic2e62ed2021-03-10 17:04:18 -080068 kprintf("fs_readdir(\"/dev/initrd\")\n");
swissChilib7fe8992021-03-10 16:25:47 -080069
70 struct fs_dirent dirent;
swissChilida23a912021-03-12 16:07:50 -080071 for (int i = 0; fs_readdir(&root, i, &dirent); i++)
swissChilib7fe8992021-03-10 16:25:47 -080072 {
73 kprintf("name: %s, inode: %d\n", dirent.name, dirent.inode);
74 }
swissChili2b5acc82021-03-13 17:06:42 -080075#endif
swissChilib7fe8992021-03-10 16:25:47 -080076
swissChilicfd3c3c2021-04-03 15:04:24 -070077 kprintf("initializing tasks\n");
78 init_tasks();
79 kprintf("\ndone initializing tasks\n");
swissChilica268482021-05-28 18:31:46 -070080 asm volatile("sti");
swissChilicfd3c3c2021-04-03 15:04:24 -070081
swissChili1a3f07f2021-04-05 20:01:55 -070082#ifdef TEST_THREADS
swissChilif01ddcc2021-04-04 11:31:34 -070083 spawn_thread(other_thread, NULL);
swissChilicfd3c3c2021-04-03 15:04:24 -070084
swissChilif01ddcc2021-04-04 11:31:34 -070085 greet();
swissChili1a3f07f2021-04-05 20:01:55 -070086#endif
swissChilidefeb0d2021-02-18 15:28:36 -080087
swissChilica268482021-05-28 18:31:46 -070088#ifdef TEST_ATA_PIO
swissChili1a3f07f2021-04-05 20:01:55 -070089 test_ata_pio();
swissChilica268482021-05-28 18:31:46 -070090#endif
91
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 {
98 struct pci_vendor *v = pci_check_vendor(bus, slot, func, NULL);
99 if (v)
100 {
101 kprintf("%s\n", v->name);
102 }
103 }
104 }
105 }
swissChili172fd632021-04-04 19:02:36 -0700106
swissChilief97c262021-04-04 10:20:21 -0700107 while (true)
swissChili825d46b2021-02-21 10:14:16 -0800108 asm volatile("hlt");
109
swissChilif01ddcc2021-04-04 11:31:34 -0700110
swissChilid8137922021-02-17 15:34:07 -0800111 return 0xCAFEBABE;
112}