80 lines
2.2 KiB
C
80 lines
2.2 KiB
C
#include "multiboot.h"
|
|
#include "vga.h"
|
|
|
|
static inline void outb(unsigned short port, unsigned char val) {
|
|
asm volatile ("outb %0, %1" : : "a"(val), "Nd"(port) : "memory");
|
|
}
|
|
|
|
char* itoa(int value, int base) {
|
|
char* result;
|
|
|
|
// check that the base if valid
|
|
if (base < 2 || base > 36) { *result = '\0'; return result; }
|
|
|
|
char* ptr = result, *ptr1 = result, tmp_char;
|
|
int tmp_value;
|
|
|
|
do {
|
|
tmp_value = value;
|
|
value /= base;
|
|
*ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz" [35 + (tmp_value - value * base)];
|
|
} while ( value );
|
|
|
|
// Apply negative sign
|
|
if (tmp_value < 0) *ptr++ = '-';
|
|
*ptr-- = '\0';
|
|
while(ptr1 < ptr) {
|
|
tmp_char = *ptr;
|
|
*ptr--= *ptr1;
|
|
*ptr1++ = tmp_char;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
void kmain (unsigned int mbootmagick, multiboot_info_t* mbootinfo) {
|
|
|
|
// Cursor disabling
|
|
// TODO: outb function
|
|
//outb(0x3D4, 0x0A);
|
|
//outb(0x3D5, 0x20);
|
|
|
|
//cls();
|
|
vga_init(VGA_COLOR_BLACK, VGA_COLOR_GRAY);
|
|
|
|
vga_write_line("=== KoalemOS ===");
|
|
vga_write("Checking multiboot loader: ");
|
|
|
|
// Check multiboot header
|
|
if (mbootmagick != MULTIBOOT_BOOTLOADER_MAGIC) {
|
|
vga_write_color("INVALID MAGIC", VGA_COLOR_BLACK, VGA_COLOR_RED);
|
|
return;
|
|
}
|
|
if (mbootinfo->flags & MULTIBOOT_INFO_BOOT_LOADER_NAME)
|
|
vga_write((char *)mbootinfo->boot_loader_name);
|
|
else
|
|
vga_write_color("Unknown", VGA_COLOR_BLACK, VGA_COLOR_ORANGE);
|
|
|
|
vga_write("\nMultiboot flags: ");
|
|
vga_write(itoa(mbootinfo->flags, 2));
|
|
|
|
// Check videomode
|
|
vga_write("\nVideomode: ");
|
|
|
|
if (mbootinfo->flags & MULTIBOOT_INFO_VBE_INFO) {
|
|
vga_write("VBE 0x");
|
|
vga_write(itoa(mbootinfo->vbe_mode, 16));
|
|
} else if (mbootinfo->flags & MULTIBOOT_INFO_FRAMEBUFFER_INFO) {
|
|
vga_write("Framebuffer");
|
|
vga_write("\nVideo address: 0x");
|
|
vga_write(itoa(mbootinfo->framebuffer_addr, 16));
|
|
unsigned long long *vmem = &mbootinfo->framebuffer_addr;
|
|
*vmem = 0xff00ff;
|
|
|
|
} else {
|
|
vga_write_color("Not available", VGA_COLOR_BLACK, VGA_COLOR_RED);
|
|
return;
|
|
}
|
|
|
|
vga_write_line("\nExecution finished, halting...");
|
|
*(unsigned char *)0xb8000 = '!';
|
|
}
|