blob: b973b41019186c1062481f6e9540354a48e54ae6 [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>
swissChili5fe85a12021-05-31 08:10:27 -070015#include <dri/ide/ide.h>
swissChilicfd3c3c2021-04-03 15:04:24 -070016
17void greet()
18{
19 kprintf("Hello from get_task_id() = %d, get_process_id() = %d\n",
20 get_task_id(), get_process_id());
21}
22
swissChilif01ddcc2021-04-04 11:31:34 -070023void other_thread(size_t data)
swissChilicfd3c3c2021-04-03 15:04:24 -070024{
swissChilif01ddcc2021-04-04 11:31:34 -070025 kprintf("data is 0x%x\n", data);
26 greet();
27 kprintf("Returning from other_thread\n");
28
29 return;
swissChilicfd3c3c2021-04-03 15:04:24 -070030}
swissChilid8137922021-02-17 15:34:07 -080031
swissChilida23a912021-03-12 16:07:50 -080032int kmain(struct multiboot_info *mboot)
swissChilid8137922021-02-17 15:34:07 -080033{
swissChilie0a79bb2021-02-22 19:54:48 -080034 init_paging();
swissChilidc25b2b2021-02-23 17:07:13 -080035 init_vga();
swissChili0b35bf22021-02-18 12:49:40 -080036 init_descriptor_tables();
swissChili64228692021-03-16 08:19:23 -070037 init_syscall();
swissChili6c0519e2021-03-07 19:40:23 -080038 vga_clear();
swissChilid8137922021-02-17 15:34:07 -080039
swissChili825d46b2021-02-21 10:14:16 -080040 init_timer(20);
swissChilie4f01992021-02-25 15:38:12 -080041 init_allocator();
swissChili19ef4182021-02-21 17:45:51 -080042 init_kbd();
swissChilie4f01992021-02-25 15:38:12 -080043
swissChili6c0519e2021-03-07 19:40:23 -080044#ifdef TEST_ALLOC
45 test_allocator();
46#endif
swissChilie4f01992021-02-25 15:38:12 -080047
swissChili9752ab32021-03-05 11:20:13 -080048 // Load initrd
swissChilida23a912021-03-12 16:07:50 -080049 struct multiboot_info mb = make_multiboot_physical(mboot);
swissChili2b5acc82021-03-13 17:06:42 -080050 init_vfs();
swissChili9752ab32021-03-05 11:20:13 -080051
swissChili2b5acc82021-03-13 17:06:42 -080052#ifdef INITRD
swissChili9752ab32021-03-05 11:20:13 -080053 kassert(mb.mods_count, "No multiboot modules loaded!");
54 kprintf("mboot->mods_addr = %d (0x%x)\n", mb.mods_addr, mb.mods_addr);
swissChilida23a912021-03-12 16:07:50 -080055 uchar *initrd_loc = (uchar *)((uint *)mb.mods_addr)[0];
swissChili9752ab32021-03-05 11:20:13 -080056
swissChili6c0519e2021-03-07 19:40:23 -080057 kprintf("initrd is at 0x%x to 0x%x\n", initrd_loc);
swissChili9752ab32021-03-05 11:20:13 -080058
swissChili2b5acc82021-03-13 17:06:42 -080059 init_initrd_vfs(initrd_loc);
60#endif
swissChilida23a912021-03-12 16:07:50 -080061
swissChilif5448622021-03-08 20:17:36 -080062 kprintf("VFS initialized\n");
63
64 vga_set_color(LIGHT_GREEN, BLACK);
swissChili2b5acc82021-03-13 17:06:42 -080065 kprintf("Setup complete!\n");
swissChilif5448622021-03-08 20:17:36 -080066 vga_set_color(WHITE, BLACK);
67
swissChili2b5acc82021-03-13 17:06:42 -080068#ifdef TEST_VFS_INITRD
swissChilic2e62ed2021-03-10 17:04:18 -080069 kprintf("fs_readdir(\"/dev/initrd\")\n");
swissChilib7fe8992021-03-10 16:25:47 -080070
71 struct fs_dirent dirent;
swissChilida23a912021-03-12 16:07:50 -080072 for (int i = 0; fs_readdir(&root, i, &dirent); i++)
swissChilib7fe8992021-03-10 16:25:47 -080073 {
74 kprintf("name: %s, inode: %d\n", dirent.name, dirent.inode);
75 }
swissChili2b5acc82021-03-13 17:06:42 -080076#endif
swissChilib7fe8992021-03-10 16:25:47 -080077
swissChili402a3832021-05-29 21:41:31 -070078 asm("sti");
swissChiliaed6ff32021-05-29 17:51:04 -070079
swissChilicfd3c3c2021-04-03 15:04:24 -070080 kprintf("initializing tasks\n");
81 init_tasks();
82 kprintf("\ndone initializing tasks\n");
83
swissChili5fe85a12021-05-31 08:10:27 -070084 pci_init();
85
86 // Register PCI drivers
87 ide_register();
88
89 pci_load();
90
swissChili402a3832021-05-29 21:41:31 -070091#ifdef TEST_THREADS
swissChilif01ddcc2021-04-04 11:31:34 -070092 spawn_thread(other_thread, NULL);
swissChilicfd3c3c2021-04-03 15:04:24 -070093
swissChilif01ddcc2021-04-04 11:31:34 -070094 greet();
swissChili402a3832021-05-29 21:41:31 -070095#endif
swissChilidefeb0d2021-02-18 15:28:36 -080096
swissChilica268482021-05-28 18:31:46 -070097#ifdef TEST_ATA_PIO
swissChili1a3f07f2021-04-05 20:01:55 -070098 test_ata_pio();
swissChilica268482021-05-28 18:31:46 -070099#endif
100
swissChiliaed6ff32021-05-29 17:51:04 -0700101#ifdef TEST_PCI
swissChili402a3832021-05-29 21:41:31 -0700102 pci_print_devices();
swissChili5fe85a12021-05-31 08:10:27 -0700103 pci_print_drivers();
swissChiliaed6ff32021-05-29 17:51:04 -0700104#endif
105
swissChilief97c262021-04-04 10:20:21 -0700106 while (true)
swissChili402a3832021-05-29 21:41:31 -0700107 asm("hlt");
swissChilif01ddcc2021-04-04 11:31:34 -0700108
swissChilid8137922021-02-17 15:34:07 -0800109 return 0xCAFEBABE;
110}