having grub load with different virtual address?

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
proxy

having grub load with different virtual address?

Post by proxy »

Hi all, I am currently using grub to load my kernel at 1meg, I was wondering if it was possible to have grub load the kernel with a different virtual address (say 0xc0000000) but if i try having my linker use that as it's base address it get an error in grub, somthing along the lines of the binary cannot fit in memory.

I noticed that the Linux kernel is linked at 0xc0000000 and obviously boots just fine. Anyone have any experience with this?

proxy
frank

Re:having grub load with different virtual address?

Post by frank »


(say 0xc0000000)
Grub can not load at that high addresses.
See: http://www.openbg.net/sto/os/xml/grub.html
proxy

Re:having grub load with different virtual address?

Post by proxy »

but in code listing 11 they have an example where virtual address is aexactly where i want it!...so what do i need to do? other OSes seem to do it...

proxy
bkilgore

Re:having grub load with different virtual address?

Post by bkilgore »

Did you follow the code listing 11 sample closely? You have to make sure you specify both the virtual address and the physical address.

Code: Select all

OUTPUT_FORMAT("elf32-i386")
ENTRY(entry)
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 = .; 
}
Make sure you have the line

Code: Select all

.text virt : AT(phys)
that specifies that you want the virtual address to be 'virt' (or 0xC0000000) but the physical address to load to to be 'phys' (or 0x100000). Grub doesn't have anything to do with the virtual address, that should all be handled by your kernel while initially mapping your kernel into the virtual address space. Grub only takes the physical address from the .elf file and loads the code there.
proxy

Re:having grub load with different virtual address?

Post by proxy »

yea, i noticed i originally had a typo in my link script, it now loads :)

Next step I have to have my initial setup code provide enough of a GDT to make the system think 0xc0000000 is 1 MEG :P while i setup the rest of the system i suppose :)

proxy
Post Reply