From 4ba0f93efcc07747d592e3a5a6aa744665c48495 Mon Sep 17 00:00:00 2001 From: Garritt McCune Date: Sat, 9 Feb 2019 17:16:24 -0600 Subject: [PATCH] Added basic multiboot compliant bootloader dectetion, as well as learning to read the multiboot structor. --- include/buildnumber.h | 6 ++-- include/system.h | 2 +- makefile | 2 +- src/gdt.c | 3 +- src/kernel.c | 65 +++++++++++++++++++++++++++++++------------ src/start.asm | 2 ++ 6 files changed, 56 insertions(+), 24 deletions(-) diff --git a/include/buildnumber.h b/include/buildnumber.h index fa2ab55..f3657d7 100644 --- a/include/buildnumber.h +++ b/include/buildnumber.h @@ -1,9 +1,9 @@ #ifndef BUILD_NUMBER -#define BUILD_NUMBER "48" +#define BUILD_NUMBER "111" #endif #ifndef VERSION_STR -#define VERSION_STR "0.0.2.48 - Sun Jan 6 21:40:38 CST 2019" +#define VERSION_STR "0.0.2.111 - Sat Feb 9 17:10:29 CST 2019" #endif #ifndef VERSION_STR_SHORT -#define VERSION_STR_SHORT "0.0.2.48" +#define VERSION_STR_SHORT "0.0.2.111" #endif diff --git a/include/system.h b/include/system.h index d71b47c..6374e91 100644 --- a/include/system.h +++ b/include/system.h @@ -16,7 +16,7 @@ extern unsigned char inportb (unsigned short _port); extern void outportb (unsigned short _port, unsigned char _data); extern bool strcmp(char* str1, char* str2); extern void idle(); -char* int_to_string(int value, int base); +char* int_to_string(unsigned int value, int base); /* ISRS.C */ void isrs_install(); /* This defines what the stack looks like after an ISR was running */ diff --git a/makefile b/makefile index 81fe672..8940fa3 100644 --- a/makefile +++ b/makefile @@ -18,7 +18,7 @@ objects = obj/start.o \ obj/port.o run:kernel.iso - qemu-system-x86_64 -cdrom kernel.iso & + qemu-system-x86_64 -m 64M -cdrom kernel.iso & obj/%.o: src/%.c mkdir -p $(@D) diff --git a/src/gdt.c b/src/gdt.c index ed67935..202fe21 100644 --- a/src/gdt.c +++ b/src/gdt.c @@ -55,7 +55,8 @@ void gdt_install() /* Setup the GDT pointer and limit */ gp.limit = (sizeof(struct gdt_entry) * 3) - 1; gp.base = &gdt; - + //puts("GDT Reference: "); + //puts(strconcat(int_to_string(&gdt, 16), "\n")); /* Our NULL descriptor */ gdt_set_gate(0, 0, 0, 0, 0); diff --git a/src/kernel.c b/src/kernel.c index 51f748c..b61b73e 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -62,7 +62,7 @@ bool strcmp(char* str1, char* str2) } //Code reference: //http://www.strudel.org.uk/itoa/ -char* int_to_string(int value, int base) +char* int_to_string(unsigned int value, int base) { static char buf[32] = {0}; @@ -122,30 +122,58 @@ void outportb (unsigned short _port, unsigned char _data) __asm__ __volatile__ ("outb %1, %0" : : "dN" (_port), "a" (_data)); } -/* This is a very simple main() function. All it does is sit in an -* infinite loop. This will be like our 'idle' loop */ -void main() +extern void main(uint32_t multiboot_magic, const void* multiboot_structure) { /* You would add commands after here */ init_video(); + if(multiboot_magic == 0x2BADB002) + { + puts("Multiboot 1 compliant bootloader detected.\n"); + uint32_t* bootloaderName = (uint32_t*)(((size_t)multiboot_structure) + 64); + puts("Bootloader Name: "); + puts((*bootloaderName)); + puts("\n"); + } + else if (multiboot_magic == 0x36d76289) + { + puts("Multiboot 2 compliant bootloader detected.\n"); + } + else + { + puts("Unkown bootloader magic number detected:"); + puts(int_to_string(multiboot_magic, 16)); + puts("\n"); + } + puts("Bootloader structure appears to be have been loaded at memory address: 0x"); + puts(int_to_string(multiboot_structure, 16)); + puts("\n"); + uint32_t* videoBuffer = (uint32_t*)(((size_t)multiboot_structure) + 88); + puts("Framebuffer address: "); + puts(int_to_string((*videoBuffer), 16)); + puts("\n"); + puts("Video initialized.\n"); gdt_install(); puts("Global Descriptor Table initialized.\n"); - size_t heap = 10 * 1024 * 1024; - MemoryManager(heap, heap * 30 * 1024); - puts("heap: 0x"); - puts(int_to_string(heap, 16)); - - void* allocated = Malloc(2048); - puts("\nAllocated: 0x"); - puts(int_to_string(allocated, 16)); - puts("\n"); + //uint32_t* memupper = (uint32_t*)(((size_t)multiboot_structure) + 8); + //puts(int_to_string(memupper, 16)); + //size_t heap = 10 * 1024 * 1024; + //MemoryManager(heap, (*memupper)*1024 - heap - 10*1024); //second needs to be an address not size + //puts("heap: 0x"); + //puts(strconcat(int_to_string(heap, 16), "\n")); + //struct MemoryChunk* allocated = (struct MemoryChunk*) Malloc(2048); + //size_t size = allocated->Next->Size; + //if(allocated->Prev->Size) puts("Yes"); + //else puts("no"); + //puts("\nAllocated: 0x"); + //puts(int_to_string(size, 16)); + //puts("\n"); - void* al = Malloc(3096); - puts("\nAllocated: 0x"); - puts(int_to_string(al, 16)); - puts("\n"); + //void* al = Malloc(3096); + ///puts("\nAllocated: 0x"); + //puts(int_to_string(al, 16)); + //puts("\n"); idt_install(); puts("Interrupt Descriptor Table initialized.\n"); @@ -167,7 +195,8 @@ void main() puts("Compile Date "); puts(__DATE__); puts("\n"); - puts(strconcat("Hello ", "World!\n")); + //puts(strconcat("Hello ", "World!\n")); + //puts(strconcat("Concat test ", "number 2\n")); //puts(__DATE__); //puts("\n"); //puts(__TIME__); diff --git a/src/start.asm b/src/start.asm index db0d752..244ecbd 100644 --- a/src/start.asm +++ b/src/start.asm @@ -37,6 +37,8 @@ mboot: ; will insert an 'extern _main', followed by 'call _main', right ; before the 'jmp $'. stublet: + push ebx + push eax extern main call main jmp $