ld question

Programming, for all ages and all languages.
Post Reply
User avatar
yemista
Member
Member
Posts: 299
Joined: Fri Dec 26, 2008 12:31 pm
Location: Boston
Contact:

ld question

Post by yemista »

Hello, how can I get ld to generate a part of the code starting at 0x00000000, and immediatley after, generate code starting at 0x00100000, but not have it fill in any of the space in between? The reason is because the first part starts when the boot loader jumps to 0x00100000, but the boot loader sets up a code segment and data segment with base 0x00100000, so that code needs to think its at 0x00000000 to work properly, and then the first part reloads the gdt with cs and ds having base 0x00100000, and jumps to the actual kernel. This is why the first part needs to think its at 0x00000000 and the second part think its at 0x00100000, and they need to be immediatley after one another. With my linker script, the code is generated with the right offsets, but the gap between 0x00000000 and 0x00100000 is filled with garbage. Is there any way to get ld not to do that? I didnt see any switch in the man pages for this.

linker script:

Code: Select all

SECTIONS
{
   . = 0x00000000
   .text1 : { cr0.o }
   .data1 : {cr0.o }
   . = 0x00100000;
   .text : { *(.o) }
   .rodata : { *(.o) }
   .data : { *(.o) }
   .bss : { *(.o) }
}
User avatar
xenos
Member
Member
Posts: 1118
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: ld question

Post by xenos »

IMHO you need to define two sections, one starting at 0x00000000 and one starting at 0x00100000, by setting the LMA as described here:
http://sourceware.org/binutils/docs-2.1 ... n-LMA.html
.text1 and .data1 go into the first section (AT 0x00000000), everything else goes into the second section (AT 0x00100000).
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
Post Reply