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 | d813792 | 2021-02-17 15:34:07 -0800 | [diff] [blame] | 8 | |
swissChili | 0b35bf2 | 2021-02-18 12:49:40 -0800 | [diff] [blame] | 9 | int kmain(void *mboot) |
swissChili | d813792 | 2021-02-17 15:34:07 -0800 | [diff] [blame] | 10 | { |
swissChili | e0a79bb | 2021-02-22 19:54:48 -0800 | [diff] [blame] | 11 | init_paging(); |
swissChili | dc25b2b | 2021-02-23 17:07:13 -0800 | [diff] [blame] | 12 | init_vga(); |
swissChili | d3a652e | 2021-02-21 22:16:06 -0800 | [diff] [blame] | 13 | |
swissChili | d813792 | 2021-02-17 15:34:07 -0800 | [diff] [blame] | 14 | vga_clear(); |
| 15 | vga_set_color(LIGHT_BLUE, BLACK); |
| 16 | vga_write("Hello!\nWelcome to Bluejay OS\n"); |
swissChili | d813792 | 2021-02-17 15:34:07 -0800 | [diff] [blame] | 17 | vga_set_color(WHITE, BLACK); |
| 18 | |
swissChili | 0b35bf2 | 2021-02-18 12:49:40 -0800 | [diff] [blame] | 19 | init_descriptor_tables(); |
swissChili | d813792 | 2021-02-17 15:34:07 -0800 | [diff] [blame] | 20 | |
swissChili | 0b35bf2 | 2021-02-18 12:49:40 -0800 | [diff] [blame] | 21 | vga_set_color(LIGHT_GREEN, BLACK); |
| 22 | vga_write("Setup complete!\n"); |
| 23 | vga_set_color(WHITE, BLACK); |
swissChili | d813792 | 2021-02-17 15:34:07 -0800 | [diff] [blame] | 24 | |
swissChili | 825d46b | 2021-02-21 10:14:16 -0800 | [diff] [blame] | 25 | init_timer(20); |
swissChili | e4f0199 | 2021-02-25 15:38:12 -0800 | [diff] [blame] | 26 | init_allocator(); |
swissChili | 19ef418 | 2021-02-21 17:45:51 -0800 | [diff] [blame] | 27 | init_kbd(); |
swissChili | e4f0199 | 2021-02-25 15:38:12 -0800 | [diff] [blame] | 28 | |
| 29 | // Test allocator |
| 30 | |
| 31 | int *one = malloc(sizeof(int)); |
| 32 | int *two = malloc(sizeof(int)); |
| 33 | |
| 34 | *one = 1; |
| 35 | *two = 2; |
| 36 | |
| 37 | int *array = malloc(sizeof(int[12])); |
| 38 | |
| 39 | for (int i = 0; i < 12; i++) |
| 40 | array[i] = i; |
| 41 | |
| 42 | kprintf("Allocated one, two, array[3] = %d, %d, %d\n", *one, *two, |
| 43 | array[3]); |
| 44 | kprintf("[%x, %x, %x]\n", one, two, array); |
| 45 | |
| 46 | kprintf("Freeing two\n"); |
| 47 | free(two); |
| 48 | int *four = malloc(sizeof(int)); |
| 49 | *four = 4; |
| 50 | kprintf("Allocated four = %d (%x)\n", *four, four); |
| 51 | |
swissChili | defeb0d | 2021-02-18 15:28:36 -0800 | [diff] [blame] | 52 | asm volatile("sti"); |
| 53 | |
swissChili | 825d46b | 2021-02-21 10:14:16 -0800 | [diff] [blame] | 54 | while (true) |
| 55 | asm volatile("hlt"); |
| 56 | |
swissChili | d813792 | 2021-02-17 15:34:07 -0800 | [diff] [blame] | 57 | return 0xCAFEBABE; |
| 58 | } |