Trouble Booting A Multiboot PE Kernel In GRUB

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
monsterhunter445
Posts: 20
Joined: Sun Jan 02, 2011 4:46 pm

Trouble Booting A Multiboot PE Kernel In GRUB

Post 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);
	}
};
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: Trouble Booting A Multiboot PE Kernel In GRUB

Post 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.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Trouble Booting A Multiboot PE Kernel In GRUB

Post 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.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
shahadat
Posts: 19
Joined: Thu May 13, 2010 2:53 am

Re: Trouble Booting A Multiboot PE Kernel In GRUB

Post by shahadat »

Post Reply