Grub+elf-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.
eL JeDi

Grub+elf-kernel

Post by eL JeDi »

Hi,

Well, after the few problems i have with the loader on diferents PCs I choose use grub.

My problem is when boot with the FD, i get this message:

kernel /boot/kernel.elf
   [Multiboot-elf, <0x20:0x240:0x0>

Error 28: Selected item cannot fit into memory

Here is my kernel header:

mboot:
   dd MULTIBOOT_HEADER_MAGIC
   dd MULTIBOOT_HEADER_FLAGS
   dd MULTIBOOT_CHECKSUM

and this on a .inc file:


MULTIBOOT_PAGE_ALIGN   equ 1<<0
MULTIBOOT_MEMORY_INFO   equ 1<<1
MULTIBOOT_AOUT_KLUDGE   equ 1<<16
MULTIBOOT_HEADER_MAGIC   equ 0x1BADB002
MULTIBOOT_HEADER_FLAGS   equ MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO | MULTIBOOT_AOUT_KLUDGE
MULTIBOOT_CHECKSUM   equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS).

the linker script here is:

# Simple way to compile & put on a floppy


OUTPUT_FORMAT("elf32-i386")
ENTRY(start)
virt = 0xC0000000; /* 3 gig */
phys = 0x100000; /* 1 meg */
SECTIONS
{ .text virt : AT(phys)
{ code = .;
*(.text)
. = ALIGN(4096); }
.data : AT(phys + (data - code))
{ data = .;
*(.data)
. = ALIGN(4096); }
.bss : AT(phys + (bss - code))
{ bss = .;
*(.bss)
*(COMMON)
. = ALIGN(4096); }
end = .; }

nasm -f aout common.asm -o common.o
nasm -f aout isr.asm -o isr.o
gcc -c kk.c -o kk.o
ld -T link.ld -N --oformat=elf32-i386 common.o isr.o kk.o -o kernel.elf

dd if=kernel.elf seek=237 of=/dev/fd0


Any idea??

thanks
jrfritz

Re:Grub+elf-kernel

Post by jrfritz »

THATS EXACTLY WHAT HAPPENS TO ME!
eL JeDi

Re:Grub+elf-kernel

Post by eL JeDi »

well, we're in a trouble!!!!! ;D :P
Guest

Re:Grub+elf-kernel

Post by Guest »

ive got sumting like:

%include "grub.inc" ; needed for the multiboot header

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Multiboot header for GRUB bootloader. This must be in the first 8K
; of the kernel file. We use the aout kludge so it works with ELF,
; DJGPP COFF, Win32 PE, or other formats.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; these are in the linker script file
EXTERN code, bss, end

ALIGN 4
mboot:
   dd MULTIBOOT_HEADER_MAGIC
   dd MULTIBOOT_HEADER_FLAGS
   dd MULTIBOOT_CHECKSUM
; aout kludge. These must be PHYSICAL addresses
   dd mboot
   dd code
   dd bss
   dd end
   dd start

the grub.inc file is:

MULTIBOOT_PAGE_ALIGN   equ 1<<0
MULTIBOOT_MEMORY_INFO   equ 1<<1
MULTIBOOT_AOUT_KLUDGE   equ 1<<16
MULTIBOOT_HEADER_MAGIC   equ 0x1BADB002
MULTIBOOT_HEADER_FLAGS   equ MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO | MULTIBOOT_AOUT_KLUDGE
MULTIBOOT_CHECKSUM   equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)

i think u are missin the aout kludge.

ias i develop on win98 and use coff file format and produce binary for the kernel this mite not work but im not sure cuz i havent tested it with elf.
if it does work den let me no so i mite think about using elf as a format for my kernel.
jrfritz

Re:Grub+elf-kernel

Post by jrfritz »

User avatar
df
Member
Member
Posts: 1076
Joined: Fri Oct 22, 2004 11:00 pm
Contact:

Re:Grub+elf-kernel

Post by df »

Guest wrote: i think u are missin the aout kludge.

ias i develop on win98 and use coff file format and produce binary for the kernel this mite not work but im not sure cuz i havent tested it with elf.
if it does work den let me no so i mite think about using elf as a format for my kernel.
aout kludge not needed on ELF files.
-- Stu --
Chris Giese

Re:Grub+elf-kernel

Post by Chris Giese »

I think this error happens because the ".rodata" section(s) are not included in the linker script.

You can change the linker script to merge these sections with the code:

...
.text virt : AT(phys)
{ code = .;
*(.text)
*(.rodata*)
. = ALIGN(4096); }
...

GCC 3.x make several ".rodata" sections -- that's why the ".rodata" line has a second wildcard character (*) in it.
DarylD

Re:Grub+elf-kernel

Post by DarylD »

Yes, I was having this problem early on too. Its definately relating to linker scripts.

Daryl.
jrfritz

Re:Grub+elf-kernel

Post by jrfritz »

Wow, Chris Giese was here! :o
Xeon

Re:Grub+elf-kernel

Post by Xeon »

Change '.text virt' to '.text phys' and it should work. ;-)
eL JeDi

Re:Grub+elf-kernel

Post by eL JeDi »

I made the fix in the script, thanks Chris and xeon.

Now grub doen't show any error message, and load the kernel, but it resets the PC. I spended one week on try to fix it, but i can't.

Here is my new link script:

OUTPUT_FORMAT("elf32-i386")
ENTRY(start)
virt = 0xC0000000; /* 3 gig */
phys = 0x102000; /* 1 meg */
SECTIONS
{
.text phys : AT(phys)
{
code = .;
*(.text)
*(.rodata*)
. = ALIGN(4096);
}
.data : AT(phys + (data - code))
{
data = .;
*(.data)
. = ALIGN(4096);
}
.bss : AT(phys + (bss - code))
{
bss = .;
*(.bss)
*(COMMON)
. = ALIGN(4096);
}
end = .;
}

and my the asm part of my kernel.

Can anyone help me?
eL JeDi

Re:Grub+elf-kernel

Post by eL JeDi »

[attachment deleted by admin]
eL JeDi

Re:Grub+elf-kernel

Post by eL JeDi »

could it be my GTD?

Iv'e tried only load kernel asm. And even not all... but it resets too.

Thanks
K.J.

Re:Grub+elf-kernel

Post by K.J. »

Why such a complicated linker script? All you should need is something simple like this:

Code: Select all

OUTPUT_FORMAT("elf32-i386")
ENTRY(start)
SECTIONS
{
  .text  0x100000 : {
    *(.text)
  }
  .data  : {
    *(.data)
  }
  .bss  :
  {                
    *(.bss)
  }
}
K.J.
jrfritz

Re:Grub+elf-kernel

Post by jrfritz »

But that doesn't work.... ;)
Post Reply