2023-06-14 05:13:21 +03:00
|
|
|
#include "multiboot.h"
|
2023-06-13 09:45:04 +03:00
|
|
|
#include "vga.h"
|
2023-06-15 03:06:27 +03:00
|
|
|
#include "serial.h"
|
2023-06-15 06:40:38 +03:00
|
|
|
#include "xtoa.h"
|
2023-06-13 09:45:04 +03:00
|
|
|
|
2023-06-14 20:49:23 +03:00
|
|
|
static inline void outb(unsigned short port, unsigned char val) {
|
2023-06-14 06:19:50 +03:00
|
|
|
asm volatile ("outb %0, %1" : : "a"(val), "Nd"(port) : "memory");
|
|
|
|
}
|
2023-06-15 03:06:27 +03:00
|
|
|
static inline unsigned char inb(unsigned short port) {
|
|
|
|
unsigned char ret;
|
|
|
|
asm volatile("inb %1, %0" : "=a"(ret) : "Nd"(port) : "memory");
|
|
|
|
return ret;
|
|
|
|
}
|
2023-06-14 06:19:50 +03:00
|
|
|
|
2023-06-14 05:13:21 +03:00
|
|
|
void kmain (unsigned int mbootmagick, multiboot_info_t* mbootinfo) {
|
2023-06-13 09:45:04 +03:00
|
|
|
|
|
|
|
// Cursor disabling
|
2023-06-14 20:49:47 +03:00
|
|
|
outb(0x3D4, 0x0A);
|
|
|
|
outb(0x3D5, 0x20);
|
2023-06-13 09:45:04 +03:00
|
|
|
|
|
|
|
//cls();
|
2023-06-14 20:06:27 +03:00
|
|
|
vga_init(VGA_COLOR_BLACK, VGA_COLOR_GRAY);
|
2023-06-13 09:45:04 +03:00
|
|
|
|
|
|
|
vga_write_line("=== KoalemOS ===");
|
2023-06-15 03:06:27 +03:00
|
|
|
|
|
|
|
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");
|
|
|
|
}
|
2023-06-14 05:13:21 +03:00
|
|
|
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;
|
|
|
|
}
|
2023-06-14 20:06:27 +03:00
|
|
|
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));
|
2023-06-14 05:13:21 +03:00
|
|
|
|
2023-06-15 03:06:27 +03:00
|
|
|
serial_write_string("\nMultiboot flags: ");
|
|
|
|
serial_write_string(itoa(mbootinfo->flags, 2));
|
2023-06-14 20:06:27 +03:00
|
|
|
|
2023-06-15 03:06:27 +03:00
|
|
|
// Check videomode
|
2023-06-14 20:06:27 +03:00
|
|
|
if (mbootinfo->flags & MULTIBOOT_INFO_VBE_INFO) {
|
2023-06-15 03:06:27 +03:00
|
|
|
vga_write("\nVBE Mode: 0x");
|
2023-06-14 20:06:27 +03:00
|
|
|
vga_write(itoa(mbootinfo->vbe_mode, 16));
|
2023-06-15 03:06:27 +03:00
|
|
|
serial_write_string("\nVBE Mode: 0x");
|
|
|
|
serial_write_string(itoa(mbootinfo->vbe_mode, 16));
|
|
|
|
}
|
|
|
|
if (mbootinfo->flags & MULTIBOOT_INFO_FRAMEBUFFER_INFO) {
|
|
|
|
vga_write("\nFramebuffer: ");
|
|
|
|
vga_write("address: 0x");
|
2023-06-16 03:57:09 +03:00
|
|
|
vga_write(ultoa(mbootinfo->framebuffer_addr, 16));
|
2023-06-15 03:06:27 +03:00
|
|
|
serial_write_string("\nFramebuffer: ");
|
|
|
|
serial_write_string("address: 0x");
|
2023-06-16 03:57:09 +03:00
|
|
|
serial_write_string(ultoa(mbootinfo->framebuffer_addr, 16));
|
2023-06-15 06:40:38 +03:00
|
|
|
unsigned long *vmem = mbootinfo->framebuffer_addr;
|
2023-06-14 20:06:27 +03:00
|
|
|
*vmem = 0xff00ff;
|
|
|
|
|
|
|
|
} else {
|
2023-06-15 03:09:41 +03:00
|
|
|
vga_write_color("\nVideo info not available", VGA_COLOR_BLACK, VGA_COLOR_RED);
|
|
|
|
serial_write_string("\nVideo info not available");
|
2023-06-14 20:06:27 +03:00
|
|
|
return;
|
2023-06-14 05:13:21 +03:00
|
|
|
}
|
|
|
|
vga_write_line("\nExecution finished, halting...");
|
2023-06-12 11:46:47 +03:00
|
|
|
}
|