kernel/kernel.c

107 lines
4.7 KiB
C

#include "multiboot.h"
#include "vga.h"
#include "serial.h"
#include "xtoa.h"
static inline void outb(unsigned short port, unsigned char val) {
asm volatile ("outb %0, %1" : : "a"(val), "Nd"(port) : "memory");
}
static inline unsigned char inb(unsigned short port) {
unsigned char ret;
asm volatile("inb %1, %0" : "=a"(ret) : "Nd"(port) : "memory");
return ret;
}
void kmain (unsigned int mbootmagick, multiboot_info_t* mbootinfo) {
// Cursor disabling
outb(0x3D4, 0x0A);
outb(0x3D5, 0x20);
//cls();
vga_init(VGA_COLOR_BLACK, VGA_COLOR_GRAY);
vga_write_line("=== KoalemOS ===");
if (serial_init() > 0) {
vga_write_line_color("Serial initialization failed", VGA_COLOR_BLACK,
VGA_COLOR_ORANGE);
} else {
vga_write_line("\nInitialized serial.");
serial_write_string("\n=== KoalemOS ===\n");
}
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));
serial_write_string("\nMultiboot flags: ");
serial_write_string(itoa(mbootinfo->flags, 2));
// Check videomode
if (mbootinfo->flags & MULTIBOOT_INFO_VBE_INFO) {
vga_write("\nVBE Mode: 0x");
vga_write(itoa(mbootinfo->vbe_mode, 16));
serial_write_string("\nVBE Mode: 0x");
serial_write_string(itoa(mbootinfo->vbe_mode, 16));
}
if (mbootinfo->flags & MULTIBOOT_INFO_FRAMEBUFFER_INFO) {
vga_write("\nFramebuffer: ");
serial_write_string("\nFramebuffer: ");
vga_write("address: 0x");
serial_write_string("\n Address: 0x");
vga_write(ultoa(mbootinfo->framebuffer_addr, 16));
serial_write_string(ultoa(mbootinfo->framebuffer_addr, 16));
serial_write_string("\n Dimensions: ");
serial_write_string(itoa(mbootinfo->framebuffer_width, 10));
serial_write_string("X");
serial_write_string(itoa(mbootinfo->framebuffer_height, 10));
serial_write_string("x");
serial_write_string(itoa(mbootinfo->framebuffer_bpp, 10));
serial_write_string("\n Pitch: ");
serial_write_string(itoa(mbootinfo->framebuffer_pitch, 10));
serial_write_string("\n RPos:");
serial_write_string(itoa(mbootinfo->framebuffer_red_field_position, 10));
serial_write_string("\n GPos:");
serial_write_string(itoa(mbootinfo->framebuffer_green_field_position, 10));
serial_write_string("\n BPos:");
serial_write_string(itoa(mbootinfo->framebuffer_blue_field_position, 10));
unsigned long *vmem;
int i;
for (i = 0; i < mbootinfo->framebuffer_height; i++) {
vmem = mbootinfo->framebuffer_addr + i*mbootinfo->framebuffer_pitch + i*(mbootinfo->framebuffer_bpp/8);
*vmem = 0xff<<mbootinfo->framebuffer_red_field_position;((char *)vmem)+=mbootinfo->framebuffer_bpp/8;
*vmem = 0xff<<mbootinfo->framebuffer_red_field_position;((char *)vmem)+=mbootinfo->framebuffer_bpp/8;
*vmem = 0xff<<mbootinfo->framebuffer_red_field_position;((char *)vmem)+=mbootinfo->framebuffer_bpp/8;
*vmem = 0xff<<mbootinfo->framebuffer_red_field_position;((char *)vmem)+=mbootinfo->framebuffer_bpp/8;
*vmem = 0xff<<mbootinfo->framebuffer_green_field_position;((char *)vmem)+=mbootinfo->framebuffer_bpp/8;
*vmem = 0xff<<mbootinfo->framebuffer_green_field_position;((char *)vmem)+=mbootinfo->framebuffer_bpp/8;
*vmem = 0xff<<mbootinfo->framebuffer_green_field_position;((char *)vmem)+=mbootinfo->framebuffer_bpp/8;
*vmem = 0xff<<mbootinfo->framebuffer_green_field_position;((char *)vmem)+=mbootinfo->framebuffer_bpp/8;
*vmem = 0xff<<mbootinfo->framebuffer_blue_field_position;((char *)vmem)+=mbootinfo->framebuffer_bpp/8;
*vmem = 0xff<<mbootinfo->framebuffer_blue_field_position;((char *)vmem)+=mbootinfo->framebuffer_bpp/8;
*vmem = 0xff<<mbootinfo->framebuffer_blue_field_position;((char *)vmem)+=mbootinfo->framebuffer_bpp/8;
*vmem = 0xff<<mbootinfo->framebuffer_blue_field_position;((char *)vmem)+=mbootinfo->framebuffer_bpp/8;
}
} else {
vga_write_color("\nVideo info not available", VGA_COLOR_BLACK, VGA_COLOR_RED);
serial_write_string("\nVideo info not available");
return;
}
vga_write_line("\nExecution finished, halting...");
serial_write_string("\nExecution finished, halting...");
}