Added basic multiboot compliant bootloader dectetion, as well as learning to read the multiboot structor.
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
#ifndef BUILD_NUMBER
|
#ifndef BUILD_NUMBER
|
||||||
#define BUILD_NUMBER "48"
|
#define BUILD_NUMBER "111"
|
||||||
#endif
|
#endif
|
||||||
#ifndef VERSION_STR
|
#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
|
#endif
|
||||||
#ifndef VERSION_STR_SHORT
|
#ifndef VERSION_STR_SHORT
|
||||||
#define VERSION_STR_SHORT "0.0.2.48"
|
#define VERSION_STR_SHORT "0.0.2.111"
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+1
-1
@@ -16,7 +16,7 @@ extern unsigned char inportb (unsigned short _port);
|
|||||||
extern void outportb (unsigned short _port, unsigned char _data);
|
extern void outportb (unsigned short _port, unsigned char _data);
|
||||||
extern bool strcmp(char* str1, char* str2);
|
extern bool strcmp(char* str1, char* str2);
|
||||||
extern void idle();
|
extern void idle();
|
||||||
char* int_to_string(int value, int base);
|
char* int_to_string(unsigned int value, int base);
|
||||||
/* ISRS.C */
|
/* ISRS.C */
|
||||||
void isrs_install();
|
void isrs_install();
|
||||||
/* This defines what the stack looks like after an ISR was running */
|
/* This defines what the stack looks like after an ISR was running */
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ objects = obj/start.o \
|
|||||||
obj/port.o
|
obj/port.o
|
||||||
|
|
||||||
run:kernel.iso
|
run:kernel.iso
|
||||||
qemu-system-x86_64 -cdrom kernel.iso &
|
qemu-system-x86_64 -m 64M -cdrom kernel.iso &
|
||||||
|
|
||||||
obj/%.o: src/%.c
|
obj/%.o: src/%.c
|
||||||
mkdir -p $(@D)
|
mkdir -p $(@D)
|
||||||
|
|||||||
@@ -55,7 +55,8 @@ void gdt_install()
|
|||||||
/* Setup the GDT pointer and limit */
|
/* Setup the GDT pointer and limit */
|
||||||
gp.limit = (sizeof(struct gdt_entry) * 3) - 1;
|
gp.limit = (sizeof(struct gdt_entry) * 3) - 1;
|
||||||
gp.base = &gdt;
|
gp.base = &gdt;
|
||||||
|
//puts("GDT Reference: ");
|
||||||
|
//puts(strconcat(int_to_string(&gdt, 16), "\n"));
|
||||||
/* Our NULL descriptor */
|
/* Our NULL descriptor */
|
||||||
gdt_set_gate(0, 0, 0, 0, 0);
|
gdt_set_gate(0, 0, 0, 0, 0);
|
||||||
|
|
||||||
|
|||||||
+47
-18
@@ -62,7 +62,7 @@ bool strcmp(char* str1, char* str2)
|
|||||||
}
|
}
|
||||||
//Code reference:
|
//Code reference:
|
||||||
//http://www.strudel.org.uk/itoa/
|
//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};
|
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));
|
__asm__ __volatile__ ("outb %1, %0" : : "dN" (_port), "a" (_data));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This is a very simple main() function. All it does is sit in an
|
extern void main(uint32_t multiboot_magic, const void* multiboot_structure)
|
||||||
* infinite loop. This will be like our 'idle' loop */
|
|
||||||
void main()
|
|
||||||
{
|
{
|
||||||
/* You would add commands after here */
|
/* You would add commands after here */
|
||||||
init_video();
|
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");
|
puts("Video initialized.\n");
|
||||||
gdt_install();
|
gdt_install();
|
||||||
puts("Global Descriptor Table initialized.\n");
|
puts("Global Descriptor Table initialized.\n");
|
||||||
|
|
||||||
size_t heap = 10 * 1024 * 1024;
|
//uint32_t* memupper = (uint32_t*)(((size_t)multiboot_structure) + 8);
|
||||||
MemoryManager(heap, heap * 30 * 1024);
|
//puts(int_to_string(memupper, 16));
|
||||||
puts("heap: 0x");
|
//size_t heap = 10 * 1024 * 1024;
|
||||||
puts(int_to_string(heap, 16));
|
//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* allocated = Malloc(2048);
|
//void* al = Malloc(3096);
|
||||||
puts("\nAllocated: 0x");
|
///puts("\nAllocated: 0x");
|
||||||
puts(int_to_string(allocated, 16));
|
//puts(int_to_string(al, 16));
|
||||||
puts("\n");
|
//puts("\n");
|
||||||
|
|
||||||
void* al = Malloc(3096);
|
|
||||||
puts("\nAllocated: 0x");
|
|
||||||
puts(int_to_string(al, 16));
|
|
||||||
puts("\n");
|
|
||||||
|
|
||||||
idt_install();
|
idt_install();
|
||||||
puts("Interrupt Descriptor Table initialized.\n");
|
puts("Interrupt Descriptor Table initialized.\n");
|
||||||
@@ -167,7 +195,8 @@ void main()
|
|||||||
puts("Compile Date ");
|
puts("Compile Date ");
|
||||||
puts(__DATE__);
|
puts(__DATE__);
|
||||||
puts("\n");
|
puts("\n");
|
||||||
puts(strconcat("Hello ", "World!\n"));
|
//puts(strconcat("Hello ", "World!\n"));
|
||||||
|
//puts(strconcat("Concat test ", "number 2\n"));
|
||||||
//puts(__DATE__);
|
//puts(__DATE__);
|
||||||
//puts("\n");
|
//puts("\n");
|
||||||
//puts(__TIME__);
|
//puts(__TIME__);
|
||||||
|
|||||||
@@ -37,6 +37,8 @@ mboot:
|
|||||||
; will insert an 'extern _main', followed by 'call _main', right
|
; will insert an 'extern _main', followed by 'call _main', right
|
||||||
; before the 'jmp $'.
|
; before the 'jmp $'.
|
||||||
stublet:
|
stublet:
|
||||||
|
push ebx
|
||||||
|
push eax
|
||||||
extern main
|
extern main
|
||||||
call main
|
call main
|
||||||
jmp $
|
jmp $
|
||||||
|
|||||||
Reference in New Issue
Block a user