Page 1 of 1

Trouble Booting A Multiboot PE Kernel In GRUB

Posted: Mon Jan 17, 2011 5:50 pm
by monsterhunter445
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

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
kernel.c :

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);
	}
};

Re: Trouble Booting A Multiboot PE Kernel In GRUB

Posted: Mon Jan 17, 2011 10:03 pm
by neon
Hello,
monsterhunter445 wrote: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.
Dont choose the file format based only on the environment that you prefer working in. The executable format to choose should be solely dependent on the features that you would like your loader to support.

Also, PE isnt hard if you know how to parse it correctly.
monsterhunter445 wrote:Because the tutorial I'm following assumes I know to work with GRUB.
If you are going to be using a bootloader, I would recommend learning how to use that bootloader. Please see the Wiki article on GRUB

Alternatively, you may find this post helpful with supporting GRUB using MSVC.

Re: Trouble Booting A Multiboot PE Kernel In GRUB

Posted: Tue Jan 18, 2011 3:21 am
by Combuster
And it is possible to use the more standard tools (GCC Cross-Compiler) for the build while still using VS as your text editor.

Re: Trouble Booting A Multiboot PE Kernel In GRUB

Posted: Tue Jan 18, 2011 10:51 am
by shahadat