Making stuff work again

This commit is contained in:
Jarkko Toivanen 2023-06-22 02:13:20 +03:00
parent 086eba4ea4
commit e472492ee3
Signed by: jt
GPG key ID: 9151B109B73ECAD5
2 changed files with 57 additions and 56 deletions

View file

@ -6,12 +6,13 @@ build/start32.o: build/ src/start32.asm
fasm src/start32.asm build/start32.o fasm src/start32.asm build/start32.o
build/kernel-i386.elf: build/start32.o build/kernel-i386.elf: build/start32.o
tcc -m32 -nostdlib -Wl,-Ttext,0x100000 -o build/kernel-i386.elf src/*.c build/start32.o tcc -m32 -nostdlib -Wl,-Ttext,0x100000 -o build/kernel-i386.elf src/*.c build/start32.o
image: build/kernel-i386.elf mount
cp build/kernel-i386.elf mnt/
sync
qemu-multiboot: build/kernel-i386.elf qemu-multiboot: build/kernel-i386.elf
qemu-system-i386 -kernel build/kernel-i386.elf -serial stdio qemu-system-i386 -kernel build/kernel-i386.elf -serial stdio
qemu-image: build/kernel-i386.elf mount qemu-image: image
cp build/kernel-i386.elf mnt/
sync
qemu-system-i386 koalemos.img -serial stdio qemu-system-i386 koalemos.img -serial stdio
mount: koalemos.img mnt/ mount: koalemos.img mnt/

View file

@ -4,72 +4,72 @@
#include "xtoa.h" #include "xtoa.h"
static inline void outb(unsigned short port, unsigned char val) { static inline void outb(unsigned short port, unsigned char val) {
asm volatile ("outb %0, %1" : : "a"(val), "Nd"(port) : "memory"); asm volatile ("outb %0, %1" : : "a"(val), "Nd"(port) : "memory");
} }
static inline unsigned char inb(unsigned short port) { static inline unsigned char inb(unsigned short port) {
unsigned char ret; unsigned char ret;
asm volatile("inb %1, %0" : "=a"(ret) : "Nd"(port) : "memory"); asm volatile("inb %1, %0" : "=a"(ret) : "Nd"(port) : "memory");
return ret; return ret;
} }
void kmain (unsigned int mbootmagick, multiboot_info_t* mbootinfo) { void kmain (unsigned int mbootmagick, multiboot_info_t* mbootinfo) {
// Cursor disabling // Cursor disabling
outb(0x3D4, 0x0A); outb(0x3D4, 0x0A);
outb(0x3D5, 0x20); outb(0x3D5, 0x20);
int serial_initialized = serial_init(); int serial_initialized = serial_init();
serial_write_string("\n=== KoalemOS ===\n"); serial_write_string("\n=== KoalemOS ===\n");
// Check multiboot header // Check multiboot header
if (mbootmagick != MULTIBOOT_BOOTLOADER_MAGIC) { if (mbootmagick != MULTIBOOT_BOOTLOADER_MAGIC) {
return; return;
} }
serial_write_string("\nMultiboot flags: "); serial_write_string("\nMultiboot flags: ");
serial_write_string(itoa(mbootinfo->flags, 2)); serial_write_string(itoa(mbootinfo->flags, 2));
serial_write_string("\nMultiboot flags: "); // Check videomode
serial_write_string(itoa(mbootinfo->flags, 2)); if (mbootinfo->flags & MULTIBOOT_INFO_VBE_INFO) {
serial_write_string("\nVBE Mode: 0x");
serial_write_string(itoa(mbootinfo->vbe_mode, 16));
}
// Check videomode if (!(mbootinfo->flags & MULTIBOOT_INFO_FRAMEBUFFER_INFO)) {
if (mbootinfo->flags & MULTIBOOT_INFO_VBE_INFO) { serial_write_string("\nVideo info not available");
serial_write_string("\nVBE Mode: 0x"); return;
serial_write_string(itoa(mbootinfo->vbe_mode, 16)); }
}
if (!(mbootinfo->flags & MULTIBOOT_INFO_FRAMEBUFFER_INFO)) { serial_write_string("\nFramebuffer: ");
serial_write_string("\nVideo info not available"); serial_write_string("\n Address: 0x");
return; serial_write_string(ultoa(mbootinfo->framebuffer_addr, 16));
}
serial_write_string("\nFramebuffer: "); serial_write_string("\n Dimensions: ");
serial_write_string("\n Address: 0x"); serial_write_string(itoa(mbootinfo->framebuffer_width, 10));
serial_write_string(ultoa(mbootinfo->framebuffer_addr, 16)); 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));
serial_write_string("\n Dimensions: "); initfb(mbootinfo->framebuffer_addr, mbootinfo->framebuffer_width, mbootinfo->framebuffer_height, mbootinfo->framebuffer_bpp, mbootinfo->framebuffer_pitch, mbootinfo->framebuffer_red_field_position, mbootinfo->framebuffer_green_field_position, mbootinfo->framebuffer_blue_field_position);
serial_write_string(itoa(mbootinfo->framebuffer_width, 10)); int x, y, i;
serial_write_string("X"); unsigned char c = 0;
serial_write_string(itoa(mbootinfo->framebuffer_height, 10)); for(;;) {
serial_write_string("x"); for(y=0;y<768;y++) {
serial_write_string(itoa(mbootinfo->framebuffer_bpp, 10)); for(x=0;x<1024;x++) {
serial_write_string("\n Pitch: "); putpixel(x, y, c, c, c, 0xff);
serial_write_string(itoa(mbootinfo->framebuffer_pitch, 10)); }
serial_write_string("\n RPos:"); }
serial_write_string(itoa(mbootinfo->framebuffer_red_field_position, 10)); c+=4;
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));
initfb(mbootinfo->framebuffer_addr, mbootinfo->framebuffer_width, mbootinfo->framebuffer_height, mbootinfo->framebuffer_bpp, mbootinfo->framebuffer_pitch, mbootinfo->framebuffer_red_field_position, mbootinfo->framebuffer_green_field_position, mbootinfo->framebuffer_blue_field_position); serial_write_string("\nExecution finished, halting...");
int x, y;
for (y=0; y<mbootinfo->framebuffer_height;y++) {
for (x=0; x<mbootinfo->framebuffer_width;x++) {
putpixel(x, y, 0, 255*x/mbootinfo->framebuffer_width, 255*y/mbootinfo->framebuffer_height, 0xff);
}
}
serial_write_string("\nExecution finished, halting...");
} }