Ive been working on experimenting with booting GRUB using Microsoft Visual C++ 2008 and developed an easy method of allowing one to boot a PE kernel built with MSVC with GRUB. The method seems too easy to warrant a tutorial on it, so I decided to create a post describing the method in hopes that it will be helpful for other developers using MSVC.
To get it booting, all we need to do is define a multiboot structure. Here is the declaration:
Code: Select all
#pragma pack (push, 1)
/**
* Multiboot structure
*/
typedef struct _MULTIBOOT_INFO {
uint32_t magic;
uint32_t flags;
uint32_t checksum;
uint32_t headerAddr;
uint32_t loadAddr;
uint32_t loadEndAddr;
uint32_t bssEndAddr;
uint32_t entryPoint;
uint32_t modType;
uint32_t width;
uint32_t height;
uint32_t depth;
}MULTIBOOT_INFO, *PMULTIBOOT_INFO;
#pragma pack(pop,1)
Code: Select all
#pragma section(".text")
__declspec(allocate(".text"))
MULTIBOOT_INFO _MultibootInfo = {
MULTIBOOT_HEADER_MAGIC,
MULTIBOOT_HEADER_FLAGS,
CHECKSUM,
HEADER_ADDRESS,
LOADBASE,
0, //load end address
0, //bss end address
KeStartup
};
Here is the complete example:
Code: Select all
#pragma pack (push, 1)
/**
* Multiboot structure
*/
typedef struct _MULTIBOOT_INFO {
uint32_t magic;
uint32_t flags;
uint32_t checksum;
uint32_t headerAddr;
uint32_t loadAddr;
uint32_t loadEndAddr;
uint32_t bssEndAddr;
uint32_t entryPoint;
uint32_t modType;
uint32_t width;
uint32_t height;
uint32_t depth;
}MULTIBOOT_INFO, *PMULTIBOOT_INFO;
#pragma pack(pop,1)
/**
* Kernel entry
*/
void KeStartup ( PMULTIBOOT_INFO* loaderBlock ) {
__halt ();
}
//! loading address
#define LOADBASE 0x100000
//! header offset will always be this
#define ALIGN 0x400
#define HEADER_ADDRESS LOADBASE+ALIGN
#define MULTIBOOT_HEADER_MAGIC 0x1BADB002
#define MULTIBOOT_HEADER_FLAGS 0x00010003
#define STACK_SIZE 0x4000
#define CHECKSUM -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
#pragma section(".text")
__declspec(allocate(".text"))
MULTIBOOT_INFO _MultibootInfo = {
MULTIBOOT_HEADER_MAGIC,
MULTIBOOT_HEADER_FLAGS,
CHECKSUM,
HEADER_ADDRESS,
LOADBASE,
0, //load end address
0, //bss end address
KeStartup
};
*Wiki: I never used the Wiki so dont know how to add pages. Please feel free to use this content if you like.