From 968ea605d84059b8428a75f7a914f6dd597350de Mon Sep 17 00:00:00 2001 From: Jarkko Toivanen Date: Wed, 14 Jun 2023 20:06:27 +0300 Subject: [PATCH] Stuff. And thing. Yeaaaaah! --- Makefile | 18 ++++++++++++------ kernel.c | 42 ++++++++++++++++++++++++------------------ start32.asm | 2 +- 3 files changed, 37 insertions(+), 25 deletions(-) diff --git a/Makefile b/Makefile index 4237984..a7b0e50 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ all: kernel-i386.elf clean: - rm *.o *.elf + -@rm *.o *.elf 2> /dev/null || true start32.o: start32.asm fasm start32.asm @@ -12,12 +12,18 @@ vga.o: vga.c kernel-i386.elf: kernel.o start32.o vga.o tcc -m32 -nostdlib -Wl,-Ttext,0x100000 start32.o kernel.o vga.o -o kernel-i386.elf -qemu: kernel-i386.elf - qemu-system-i386 -kernel kernel-i386.elf +qemu-multiboot: kernel-i386.elf + qemu-system-i386 -kernel kernel-i386.elf -serial file:CON +qemu-image: kernel-i386.elf mount + cp kernel-i386.elf mnt/ + sync + qemu-system-i386 koalemos.img mount: koalemos.img mnt/ - sudo mount -o loop,offset=1048576,umask=177,dmask=222 koalemos.img mnt/ + @if ! mountpoint -q "mnt/"; then \ + sudo mount -o loop,offset=1048576,umask=177,dmask=222,uid=$(shell id -u),gid=$(shell id -g) koalemos.img mnt/; \ + fi; umount: - sudo umount mnt + @sudo umount mnt mnt/: - mkdir mnt + @mkdir mnt diff --git a/kernel.c b/kernel.c index 245bd08..f917e01 100644 --- a/kernel.c +++ b/kernel.c @@ -41,7 +41,7 @@ void kmain (unsigned int mbootmagick, multiboot_info_t* mbootinfo) { //outb(0x3D5, 0x20); //cls(); - vga_init(VGA_COLOR_GREY, VGA_COLOR_BLACK); + vga_init(VGA_COLOR_BLACK, VGA_COLOR_GRAY); vga_write_line("=== KoalemOS ==="); vga_write("Checking multiboot loader: "); @@ -51,26 +51,32 @@ void kmain (unsigned int mbootmagick, multiboot_info_t* mbootinfo) { vga_write_color("INVALID MAGIC", VGA_COLOR_BLACK, VGA_COLOR_RED); return; } - vga_write((char *)mbootinfo->boot_loader_name); + 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: 0x"); - vga_write(itoa(mbootinfo->vbe_mode, 16)); - vga_write(": "); - switch (mbootinfo->vbe_mode) { - case MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED: - vga_write("Indexed"); - break; - case MULTIBOOT_FRAMEBUFFER_TYPE_RGB: - vga_write("RGB"); - break; - case MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT: - vga_write("EGA TEXT"); - break; - default: - vga_write_color("UNKNOWN", VGA_COLOR_BLACK, VGA_COLOR_RED); - return; + 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 = '!'; } diff --git a/start32.asm b/start32.asm index c4d9e3a..4d80e11 100644 --- a/start32.asm +++ b/start32.asm @@ -21,7 +21,7 @@ MULTIBOOT_CHECKSUM equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAG ; dd 0 ; video mode_type (0:fb, 1:txt) (set flags[2]!) ; dd 1024 ; video width ; dd 768 ; video height -; dd 32 ; video depth +; dd 24 ; video depth section '.bss' writable align 16 stack_bottom: