diff options
Diffstat (limited to '')
| -rw-r--r-- | kernel/kernel.c | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/kernel/kernel.c b/kernel/kernel.c new file mode 100644 index 0000000..335cfe4 --- /dev/null +++ b/kernel/kernel.c @@ -0,0 +1,131 @@ + +#include <stdint.h> +#include "kprintf.h" +#include "gdt.h" +#include "idt.h" +#include "acpi.h" + +#include "asm_inline.h" + +typedef struct _OSDATA +{ + uint32_t Magic; // magic number to check + + uint32_t FBWidth; // with of the framebuffer + uint32_t FBHeight; // height + uint32_t PixelSize; // size of each pixel(an rgb pixel might have a bigger size) + void * FBAddr; // address of the linear framebuffer + + void * MEMMap; // pointer to the system memory map + + void * RAMDisk; // pointer to a ramdisk loaded from the hdd + + void* RSDP; +} OSDATA; + +typedef struct _Pixel +{ + uint8_t B; + uint8_t G; + uint8_t R; + uint8_t Z; +} Pixel; + +void early_serial_init() +{ + outb(COM1 + 1, 0x00); + outb(COM1 + 3, 0x80); + outb(COM1 + 0, 0x03); + outb(COM1 + 1, 0x00); + outb(COM1 + 3, 0x03); + outb(COM1 + 2, 0xC7); + outb(COM1 + 4, 0x0B); +} + +int kmain(void * osdata) +{ + early_serial_init(); + + fldcw(0x37F); + + kprintf("\n\n\n"); + kprintf("=====================\n"); + kprintf(" OrnitorrincOS\n"); + kprintf("=====================\n"); + kprintf("\n\n\n"); + // kprintf("Hello from the kernel\n"); + // kprintf("This is a %d complex %x test: %X\n", 1234, 1234, 1234); + + uint32_t regs[4] = {0}; + char* str = (char*)regs; + uint32_t rax, rbx, rcx, rdx; + cpuid(0, 0, &rax, &rbx, &rcx, &rdx); + regs[0] = rbx; + regs[1] = rdx; + regs[2] = rcx; + kprintf("CPU: %s\n", str); + + OSDATA* data = (OSDATA*)osdata; + + Pixel* fb = data->FBAddr; + + // kprintf("FB Address: %p\n", fb); + + { + int i = 0; + int j = 0; + + for(i = 0; i < 256; ++i) + { + for(j = 0; j < 256; ++j) + { + Pixel p; + p.R = 0; + p.G = 255; + p.B = 0; + p.Z = 255; + fb[j + 800*i] = p; // original: 1024 but 800 seems to work better(maybe we are not setting the display mode correctly + } + } + } + + // kprintf("image finished\n"); + + kprintf("\n"); + kprintf("=> Initializing GDT\n"); + + cli(); + + init_gdt(); + + kprintf("=> GDT initialized\n"); + + kprintf("\n"); + + kprintf("=> Initializing IDT\n"); + + init_idt(); + + kprintf("=> IDT initialized\n"); + + sti(); + + kprintf("=> Interrupts reenabled\n"); + + char* test_value = (char*)0xFFFFFFFF00000000; + // *test_value = 'B'; + + XSDP* xsdt = (XSDP*)data->RSDP; + + kprintf("\n"); + + init_acpi(xsdt); + + while(1) {}; + + kprintf("KERNEL FINISHED\n"); + + hlt(); + + return 0; +} |
