Added basic multiboot compliant bootloader dectetion, as well as learning to read the multiboot structor.

This commit is contained in:
2019-02-09 17:16:24 -06:00
parent 657b716f77
commit 4ba0f93efc
6 changed files with 56 additions and 24 deletions
+3 -3
View File
@@ -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
+1 -1
View File
@@ -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 */
+1 -1
View File
@@ -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)
+2 -1
View File
@@ -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);
+47 -18
View File
@@ -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__);
+2
View File
@@ -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 $