|From:||Dr. Dov Bulka|
|Subject:||Re: Help-grub Digest, Vol 22, Issue 5|
|Date:||Thu, 12 Nov 2009 11:33:55 -0800 (PST)|
|At the risk of answering my own qusestion... Here's what I did to run the example kernel from Grub2, as a 64-bit image. Maybe somebofy will find this useful.|
There's an example OS kernel that ships with the Grub Legacy tarball, in the docs directory. Grub2 will run that example okay if you compile it as an ELF32 image. I wanted to test Grub2 with an ELF64 image of the example kernel, and that required a few minor, but important changes.
If you compile the example kernel on a "x86_64" platform, you'll get an ELF64 image with 64-bit executable code. The problem is, when Grub jumps to the entry point of the OS, the machine is in 32-bit mode and cannot execute code that was compiled for 64-bit.
The key is to create 32-bit entry point code and stuff it into an ELF64 image.
The example kernel comes in three files: boot.S, kernel.c and multiboot.h. The following changes are required:
If you want to automate this stuff with a script, start by creating a file called "dot_code32" that contains two lines, the first of which is the string ".code32" The second line is blank.
Then do the following in a script:
cat dot_code32 boot.S > boot32.S
gcc -c boot32.S
gcc -S -m32 -nostdlib kernel.c
cat dot_code32 kernel.s > kernel32.s
gcc -c kernel32.s
gcc -o kernel64 -nostdlib kernel32.o boot32.o
Now you got an ELF64 executable called "kernel64" that runs 32-bit code at the entry point. Grub2 will bootload this one without a problem.
--- On Wed, 11/11/09, address@hidden <address@hidden> wrote:
|[Prev in Thread]||Current Thread||[Next in Thread]|