Page 1 of 1

Higher half kernel grub error 28: selected item cannot fit..

Posted: Wed Jun 19, 2013 5:51 am
by F30FC7
Hello all,

I'm working on my first kernel and hoping to construct a higher-half multiboot kernel (32-bit) having followed JamesM's kernel tutorials.

I have a link script that looks like this (taken from the wiki page, with adjustment):

Code: Select all

OUTPUT_FORMAT(elf32-i386)
ENTRY(start)
KERNEL_MBOOT = 0x400;
KERNEL_VMA        = 0xC0000000;
KERNEL_LMA_OFFSET = 0xBFF00000;

PHDRS
{
    headers PT_PHDR PHDRS ;
    mboot PT_LOAD FILEHDR ;
    text PT_LOAD FILEHDR ;
    data PT_LOAD ;
}

SECTIONS
{
  . = KERNEL_MBOOT;

  .mboot : AT(KERNEL_VMA - KERNEL_LMA_OFFSET)
  {
     *(.mboot)
  } : mboot

  . = KERNEL_VMA;

  .text : AT(ADDR(.text)+ADDR(.mboot) - KERNEL_LMA_OFFSET)
  {
    code = .; _code = .; __code = .;*/
    *(.text)
    *(.rodata*)
  } : text

  .data ALIGN (0x1000) : AT(ADDR(.data) - KERNEL_LMA_OFFSET)
  {
     data = .; _data = .; __data = .;
     *(.data)
     *(.rodata)
  } : data

  .bss : AT(ADDR(.bss) - KERNEL_LMA_OFFSET)
  {
    bss = .; _bss = .; __bss = .;
    *(.bss)
    *(COMMON)
    ebss = .;
  } : data

  end = .; _end = .; __end = .;
}
which gives me the following output from objdump -h:

Code: Select all

file format elf32-i386

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .mboot        0000000c  00000400  00100000  00000400  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  1 .text         0000002e  c0000000  00100400  00001000  2**4
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  2 .data         00000001  c0001000  00101000  00002000  2**12
                  CONTENTS, ALLOC, LOAD, DATA
  3 .bss          00004000  c0001020  00101020  00002001  2**5
                  ALLOC
Which is as far as I can see correct. The low VMA of the mboot section is less than ideal, but since this only contains the multiboot header and the LMA is 1MB, if I understand things right this is okay.

When I boot my kernel using JamesM's grub floppy, I end up with an "error 28: selected item cannot fit into memory". Incidentally, if I set my kernel to load at an LMA less than 1MB by adjusting KERNEL_LMA_OFFSET, I produce an error 7: cannot load below 1MB error as you'd expect.

My makefile runs mbchk, which reports:

Code: Select all

kernel: The Multiboot header is found at the offset 1024.
kernel: Page alignment is turned on.
kernel: Memory information is turned on.
kernel: Address fields is turned off.
kernel: All checks passed.
So I'm at a bit of a loss as to where I have gone wrong. Is there something I am missing?

If it helps, I am running my kernel under bochs (as available in Fedora 18) using the bochsrc from JamesM's tutorials.

Thanks for your help, A

Re: Higher half kernel grub error 28: selected item cannot f

Posted: Wed Jun 19, 2013 6:44 am
by Combuster
It probably helps if you don't try asking GRUB to jump to an entry point > 3GB

Re: Higher half kernel grub error 28: selected item cannot f

Posted: Wed Jun 19, 2013 7:17 am
by F30FC7
Ah yes, I forgot to mention that. In my boot.s assembler, I've set start like so:

Code: Select all

; setting up entry point for linker
start equ (start_vma - 0xBFF00000)

; entry point
start_vma:
    ; ...
Which gives me:

Code: Select all

objdump -x kernel | grep "start"
start address 0x00100000
c0000000 g       .text	00000000 start_vma
00100000 g       .text	00000000 start
Is that right, or have I missed the point? I borrowed this example from the higher half bare bones: http://wiki.osdev.org/Higher_Half_bare_bones

Thanks, A