Trouble Booting A Multiboot PE Kernel In GRUB
Posted: Mon Jan 17, 2011 5:50 pm
Hi everyone, I am writing a kernel using the Visual C++ 2010 development environment. I already now that PE is a pain in the a** to work with but I prefer using the visual studio 2010 IDE. Any how, I got the kernel to compile in a PE executable format and I copied the kernel into the grub image and loaded the grub image in QEMU. Then the GRUB command line interface appears, and I don't know what to do next. Because the tutorial I'm following assumes I know to work with GRUB. Here is the link to the blog that contains the tutorial: http://ksrenevasan.blogspot.com/2005/10 ... using.html
kernel.h
kernel.c :
kernel.h
Code: Select all
#ifndef __kernel_h__
#define __kernel_h__
#define dd(x) \
__asm _emit (x) & 0xff \
__asm _emit (x) >> 8 & 0xff \
__asm _emit (x) >> 16 & 0xff \
__asm _emit (x) >> 24 & 0xff
#define KERNEL_STACK 0x00103fff
#define KERNEL_START 0x00101000
#define KERNEL_LENGTH 0x0000200F
// White on Black Background
#ifndef WHITE
#define WHITE 0x7;
#endif
// Blue on Black Background
#ifndef BLUE
#define BLUE 0x9;
#endif
// Entry point function prototype.
void main(unsigned long, unsigned long);
// Other prototypes.
void printstring(char* message, int color);
void stringcopy(char* destination, char* source);
#endif
Code: Select all
#include "kernel.h"
__declspec(naked) void __multiboot_entry__(void)
{
__asm {
multiboot_header:
dd(0x1BADB002) ; magic
dd(1 << 16) ; flags
dd(-(0x1BADB002 + (1 << 16))) ; checksum
dd(0x00101000) ; header_addr
dd(0x00101000) ; load_addr
dd(0x0010200F) ; load_end_addr
dd(0x0010200F) ; bss_end_addr
dd(0x00101030) ; entry_addr
dd(0x00000000) ; mode_type
dd(0x00000000) ; width
dd(0x00000000) ; height
dd(0x00000000) ; depth
kernel_entry:
mov esp, KERNEL_STACK
xor ecx, ecx
push ecx
popf
push eax
push ebx
call main
jmp $
}
}
void printstring(char* message, int color)
{
char* videomem = (char*)0x8B0000;
while(*message)
{
*videomem = *message | color;
videomem++;
message++;
if (*message == 0)
{
return;
}
}
}
void main(unsigned long magic, unsigned long addr)
{
if (magic != 0x1BADB002)
{
printstring("Error: Invalid Magic Number.", 9);
return;
}
else
{
printstring("Welcome To /AMonster OS!", 9);
}
};