blob: 5c047687fa6db263a883b26668b8eca0f5fd3dec [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"
swissChilie4f01992021-02-25 15:38:12 -08005#include "paging.h"
swissChilidefeb0d2021-02-18 15:28:36 -08006#include "timer.h"
swissChili825d46b2021-02-21 10:14:16 -08007#include "vga.h"
swissChili9752ab32021-03-05 11:20:13 -08008#include "multiboot.h"
swissChilid8137922021-02-17 15:34:07 -08009
swissChili9752ab32021-03-05 11:20:13 -080010int kmain(struct multiboot *mboot)
swissChilid8137922021-02-17 15:34:07 -080011{
swissChilie0a79bb2021-02-22 19:54:48 -080012 init_paging();
swissChilidc25b2b2021-02-23 17:07:13 -080013 init_vga();
swissChilid3a652e2021-02-21 22:16:06 -080014
swissChilid8137922021-02-17 15:34:07 -080015 vga_clear();
16 vga_set_color(LIGHT_BLUE, BLACK);
17 vga_write("Hello!\nWelcome to Bluejay OS\n");
swissChilid8137922021-02-17 15:34:07 -080018 vga_set_color(WHITE, BLACK);
19
swissChili0b35bf22021-02-18 12:49:40 -080020 init_descriptor_tables();
swissChilid8137922021-02-17 15:34:07 -080021
swissChili0b35bf22021-02-18 12:49:40 -080022 vga_set_color(LIGHT_GREEN, BLACK);
23 vga_write("Setup complete!\n");
24 vga_set_color(WHITE, BLACK);
swissChilid8137922021-02-17 15:34:07 -080025
swissChili825d46b2021-02-21 10:14:16 -080026 init_timer(20);
swissChilie4f01992021-02-25 15:38:12 -080027 init_allocator();
swissChili19ef4182021-02-21 17:45:51 -080028 init_kbd();
swissChilie4f01992021-02-25 15:38:12 -080029
30 // Test allocator
31
32 int *one = malloc(sizeof(int));
33 int *two = malloc(sizeof(int));
34
35 *one = 1;
36 *two = 2;
37
38 int *array = malloc(sizeof(int[12]));
39
40 for (int i = 0; i < 12; i++)
41 array[i] = i;
42
43 kprintf("Allocated one, two, array[3] = %d, %d, %d\n", *one, *two,
44 array[3]);
45 kprintf("[%x, %x, %x]\n", one, two, array);
46
47 kprintf("Freeing two\n");
48 free(two);
49 int *four = malloc(sizeof(int));
50 *four = 4;
51 kprintf("Allocated four = %d (%x)\n", *four, four);
52
swissChili9752ab32021-03-05 11:20:13 -080053 // Load initrd
54 struct multiboot mb = make_multiboot_physical(mboot);
55
56 kassert(mb.mods_count, "No multiboot modules loaded!");
57 kprintf("mboot->mods_addr = %d (0x%x)\n", mb.mods_addr, mb.mods_addr);
58 uint *initrd_loc = mb.mods_addr[0],
59 *initrd_end = mboot->mods_addr[1];
60
61 kprintf("initrd is at 0x%x to 0x%x\n", initrd_loc, initrd_end);
62
63
swissChilidefeb0d2021-02-18 15:28:36 -080064 asm volatile("sti");
65
swissChili825d46b2021-02-21 10:14:16 -080066 while (true)
67 asm volatile("hlt");
68
swissChilid8137922021-02-17 15:34:07 -080069 return 0xCAFEBABE;
70}