Page 1 of 1

How to make GRUB1 load a 64-bit kernel

Posted: Fri Jul 06, 2012 2:33 am
by martychang
Hello Everone:

I've started to develop an OS.I'm developing a 64-bit OS.Using GRUB1 for loader.It seems that GRUB1 do not support flt64 files so I have to link 64-bit code to elf32. However the wayes on google don't work.I have on idea how to do it now. Can who show me how to do it?


PS:I'm really no a good writer in English. Forgive me.

the asm code

kernel.asm

Code: Select all

[org 0x100000]
[BITS 64]
[global _start]

start:
hlt
linker.ld

Code: Select all

OUTPUT_FORMAT(elf32-i386)
OUTPUT_ARCH(i386:x86-64)
ENTRY(start)
SECTIONS
{

    .text 0x100000 :
    {
        code = .; _code = .; __code = .;
        *(.text)
        . = ALIGN(4096);
    }

    .data :
    {
        data = .; _data = .; __data = .;
        *(.data)
        *(.rodata)
        . = ALIGN(4096);
    }

    .bss :
    {
        bss = .; _bss = .; __bss = .;
        *(.bss)
        . = ALIGN(4096);
    }

    end = .; _end = .; __end = .;
}
nasm -f elf64 -o kernel.o kernel.asm
ld -T linker.ld -o kernel.bin kernel.o -m elf_i386

NASM version 2.09.10
GNU ld (GNU Binutils for Ubuntu) 2.22

Re: How to make GRUB1 load a 64-bit kernel

Posted: Fri Jul 06, 2012 3:51 am
by Combuster
If you only knew what problem you are supposed to solve.

Re: How to make GRUB1 load a 64-bit kernel

Posted: Fri Jul 06, 2012 5:43 am
by martychang
If you only knew what problem you are supposed to solve.
I've using that page's way, but it does't work.
Also I'm using RGUB1. the page uses GRUB2.

Re: How to make GRUB1 load a 64-bit kernel

Posted: Fri Jul 06, 2012 5:50 am
by Combuster
the page uses GRUB2.
That is so wrong that it qualifies as "learn to read". Go learn the language properly first - the alternative is looking stupid instead of succeeding.

Re: How to make GRUB1 load a 64-bit kernel

Posted: Fri Jul 06, 2012 6:03 am
by martychang
sorry, I didn't see it. My English is really bad.
But that still didn't sove the question "How to link 64-bit code into an ELF32 file"

Re: How to make GRUB1 load a 64-bit kernel

Posted: Fri Jul 06, 2012 6:24 am
by Solar
Reading help: This here does answer the question, just not the way you expected:

You don't have to, GRUB can load the 32-bit and the 64-bit part seperately for you.

Re: How to make GRUB1 load a 64-bit kernel

Posted: Mon Jul 16, 2012 6:34 pm
by Tosi
Two ways I can think of easily:
1. Have GRUB load a 32-bit kernel that sets up the environment and jumps to the real 64-bit kernel which is loaded as a separate module by GRUB.
2. Paste the 32-bit and 64-bit kernel together using a tool like cat and have GRUB load the resulting big executable. You will probably have to parse the headers of whatever executable file format you're using to setup the 64-bit part.