troubles with paging

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
kiwipresse
Member
Member
Posts: 25
Joined: Sun Nov 04, 2007 7:41 am

troubles with paging

Post by kiwipresse »

Hi,

I had no problems with paging unless I tried to switch to a higher half kernel.

I want to implement as much as possible in C (I'm a poor assembly programmer) so I thought I should do it like this:

1. create a section starting at 0x100000 and link my init functions to it
2. the functions should then find some memory and do the final paging initialization
3. when everything is fine jump to the real kernel entry

Unfortunately GRUB throws an error message: error 28 selected item cannot fit into memory.

Here are some helpful information:

Code: Select all

c0105000 A __end
00100000 T _start
00100022 T early_init
c0100000 T init
0010001f t loop
00100010 t multiboot_entry
00100004 t multiboot_header
c0101000 B stack
00100000 T start
_start is the function which is called by GRUB, _start then calls early_init.

linker script:

Code: Select all

ENTRY(start)
OUTPUT_FORMAT(elf32-i386)
SECTIONS
{
  . = 0x100000;

  .early_init_text :
  {
    *(.early_init_text)
  }

  . = 0xC0100000;

  .text :
  {
    *(.text)
    . = ALIGN(0x1000);
  }

  .data ALIGN(0x1000) :
  {
    *(.data)
    *(.rodata)
    . = ALIGN(0x1000);
  }

  .bss :
  {
    *(.bss)
    . = ALIGN(0x1000);
  }

  __end = .;
}
I hope someone can help me :cry:
User avatar
xyjamepa
Member
Member
Posts: 397
Joined: Fri Sep 29, 2006 8:59 am

Post by xyjamepa »

I think you should take a look at this

Good luck..
The man who follows the crowd will usually get no further than the crowd.
The man who walks alone is likely to find himself in places
no one has ever been before.
User avatar
fontknocker
Posts: 16
Joined: Mon Dec 11, 2006 1:49 am
Location: Canberra, Australia

Post by fontknocker »

The load addresses are wrong in your linker script. For a higher half kernel you need to specify your physical load addresses for your kernel, like so:

Code: Select all

    .text ALIGN(0x1000) : AT(ADDR(.text) - virt)
    {
        *(.text)
    }
The AT() component is the physical load address of the section (where it'll be in physical memory). If you don't specify the load address the linker will make the load address match your location counter. Your location counter will be in the 3GB mark (since you did a ". += 0xC0000000" earlier). Do an "objdump -h" on your kernel image and you'll see what I mean - the values in the LMA (Load Memory Address) column will be in the 3GB range).

Since your sections are at the 3GB mark and you don't have 3GB of memory in the virtual machine GRUB will say it won't fit in memory.

There's good information on the syntax of AT() in the GNU LD documentation.
kiwipresse
Member
Member
Posts: 25
Joined: Sun Nov 04, 2007 7:41 am

Post by kiwipresse »

Thanks fontknocker for your full description!

Now the LMA is somewhere above 0x100000 and GRUB loads without any complaints. ld documentation indeed is a really good resource!
Post Reply