How to make GRUB1 load a 64-bit kernel

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
martychang
Posts: 3
Joined: Fri Jul 06, 2012 2:15 am

How to make GRUB1 load a 64-bit kernel

Post 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
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: How to make GRUB1 load a 64-bit kernel

Post by Combuster »

If you only knew what problem you are supposed to solve.
"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 ]
martychang
Posts: 3
Joined: Fri Jul 06, 2012 2:15 am

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

Post 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.
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: How to make GRUB1 load a 64-bit kernel

Post 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.
"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 ]
martychang
Posts: 3
Joined: Fri Jul 06, 2012 2:15 am

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

Post 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"
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

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

Post 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.
Every good solution is obvious once you've found it.
Tosi
Member
Member
Posts: 255
Joined: Tue Jun 15, 2010 9:27 am
Location: Flyover State, United States
Contact:

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

Post 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.
Post Reply