help-grub
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Booting a new 64-bit OS with grub 0.97


From: Diogo F. S. Ramos
Subject: Re: Booting a new 64-bit OS with grub 0.97
Date: Sat, 18 Jul 2009 13:07:14 -0300

On Sat, Jul 18, 2009 at 2:15 AM, Michael Evans<address@hidden> wrote:
> x86_64 Linux is loaded by grub on many computers every day.  -However- I
> believe virtually every last one of those systems starts out in the 32 bit
> compatibility mode.  I then believe something in the initial stages of the
> kernel switches the cpu from 32 bit to 64 bit mode.  In fact, it's probably
> literally starting out in the digitally stone-age x86 'real mode'.

I am taking a small step now and I am trying just to boot the files -
multiboot.h, boot.S and kernel.c - from the examples of the Multiboot
Specificacion version 0.6.95
<http://www.gnu.org/software/grub/manual/multiboot/multiboot.html>.

To the original boot.S compile in a 64-bit environment I did some small changes:

--- boot.S      2009-07-18 12:50:25.000000000 -0300
+++ boot.S.orig 2009-07-18 12:49:14.000000000 -0300
@@ -16,7 +16,7 @@
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */

 #define ASM     1
-#include "multiboot.h"
+#include <multiboot.h>

         .text

@@ -54,21 +54,19 @@
         movl    $(stack + STACK_SIZE), %esp

         /* Reset EFLAGS. */
-        pushq   $0
+        pushl   $0
         popf

         /* Push the pointer to the Multiboot information structure. */
-        movsxd %ebx, %rbx
-        pushq   %rbx
+        pushl   %ebx
         /* Push the magic value. */
-        movsxd %ebx, %rax
-        pushq   %rax
+        pushl   %eax

         /* Now enter the C main function... */
         call    EXT_C(cmain)

         /* Halt. */
-        pushq   $halt_message
+        pushl   $halt_message
         call    EXT_C(printf)

 loop:   hlt

And to compile, I am using this ld script:

ENTRY(start)

SECTIONS {

        /* GRUB leave us at 1MB of memory */
        . = 0x100000;

        .text : {
                *(.text)
        }

        .data ALIGN(0x1000) : {
                *(.data)
        }

        .bss ALIGN(0x1000) : {
                *(COMMON)
                *(.bss)
        }
}


The ld script is the same I use to compile the sources for the 32-bit
architecture (for which I use -m32 and -melf_i386 flags).

When I compile it for 32-bit and try it in qemu everything goes ok but
not to 64-bit.

Some things bugs me. For example, the specifications say that I need
to push ebx and eax but I can't do that in 64-bit so I convert the
registers to 64-bit and push the 64-bit version. I don't know if I can
do that but I figure that this could only cause a problem for someone
in the kernel that would try to see if the variable sent to it
contains the magic number.

> Grub also chainloads other bootloaders like the ntloader (by reference of
> the partition it lives in).  If your kernel can run on your native platform
> without a bootloader installed, and grub can also run on that same platform,
> it's probably possible to chainload it in failing anything else.

Actually, because the OS is being written from scratch the original
author made it multiboot compliant from the very beginning. So grub is
its bootloader. There is not any other mechanism that would load it

-- 
Diogo F. S. Ramos




reply via email to

[Prev in Thread] Current Thread [Next in Thread]