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 | e4f0199 | 2021-02-25 15:38:12 -0800 | [diff] [blame] | 5 | #include "paging.h" |
swissChili | defeb0d | 2021-02-18 15:28:36 -0800 | [diff] [blame] | 6 | #include "timer.h" |
swissChili | 825d46b | 2021-02-21 10:14:16 -0800 | [diff] [blame] | 7 | #include "vga.h" |
swissChili | 9752ab3 | 2021-03-05 11:20:13 -0800 | [diff] [blame^] | 8 | #include "multiboot.h" |
swissChili | d813792 | 2021-02-17 15:34:07 -0800 | [diff] [blame] | 9 | |
swissChili | 9752ab3 | 2021-03-05 11:20:13 -0800 | [diff] [blame^] | 10 | int kmain(struct multiboot *mboot) |
swissChili | d813792 | 2021-02-17 15:34:07 -0800 | [diff] [blame] | 11 | { |
swissChili | e0a79bb | 2021-02-22 19:54:48 -0800 | [diff] [blame] | 12 | init_paging(); |
swissChili | dc25b2b | 2021-02-23 17:07:13 -0800 | [diff] [blame] | 13 | init_vga(); |
swissChili | d3a652e | 2021-02-21 22:16:06 -0800 | [diff] [blame] | 14 | |
swissChili | d813792 | 2021-02-17 15:34:07 -0800 | [diff] [blame] | 15 | vga_clear(); |
| 16 | vga_set_color(LIGHT_BLUE, BLACK); |
| 17 | vga_write("Hello!\nWelcome to Bluejay OS\n"); |
swissChili | d813792 | 2021-02-17 15:34:07 -0800 | [diff] [blame] | 18 | vga_set_color(WHITE, BLACK); |
| 19 | |
swissChili | 0b35bf2 | 2021-02-18 12:49:40 -0800 | [diff] [blame] | 20 | init_descriptor_tables(); |
swissChili | d813792 | 2021-02-17 15:34:07 -0800 | [diff] [blame] | 21 | |
swissChili | 0b35bf2 | 2021-02-18 12:49:40 -0800 | [diff] [blame] | 22 | vga_set_color(LIGHT_GREEN, BLACK); |
| 23 | vga_write("Setup complete!\n"); |
| 24 | vga_set_color(WHITE, BLACK); |
swissChili | d813792 | 2021-02-17 15:34:07 -0800 | [diff] [blame] | 25 | |
swissChili | 825d46b | 2021-02-21 10:14:16 -0800 | [diff] [blame] | 26 | init_timer(20); |
swissChili | e4f0199 | 2021-02-25 15:38:12 -0800 | [diff] [blame] | 27 | init_allocator(); |
swissChili | 19ef418 | 2021-02-21 17:45:51 -0800 | [diff] [blame] | 28 | init_kbd(); |
swissChili | e4f0199 | 2021-02-25 15:38:12 -0800 | [diff] [blame] | 29 | |
| 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 | |
swissChili | 9752ab3 | 2021-03-05 11:20:13 -0800 | [diff] [blame^] | 53 | // 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 | |
swissChili | defeb0d | 2021-02-18 15:28:36 -0800 | [diff] [blame] | 64 | asm volatile("sti"); |
| 65 | |
swissChili | 825d46b | 2021-02-21 10:14:16 -0800 | [diff] [blame] | 66 | while (true) |
| 67 | asm volatile("hlt"); |
| 68 | |
swissChili | d813792 | 2021-02-17 15:34:07 -0800 | [diff] [blame] | 69 | return 0xCAFEBABE; |
| 70 | } |