Page 1 of 1

linker troubles

Posted: Mon Mar 31, 2008 4:28 pm
by GLneo
hi all, OK my problems all began when I tried to compile my OS in Linux ( formally DJGPP ) after fixing the capitalization problems and Linux's lack of " _ " before functions i was ready to link but my linker started throwing crazy warnings at me so i moved things around a little in my linker script, but the kernel would no longer boot.

So, I compiled Bochs for debugging and started stepping though the booting of my OS. It made it though my boot code then jumped to my kernel at 0x00100000 witch should be the section .setup which sets up paging and jumps to .text at 0xc0000400 ( 0x00100400 physically )
the problem is my linker puts .text at 0x00100000 not .setup like it should, so it runs my kernel code w/o paging enabled ( which only runs for a few instructions before blowing up )

What I need is a linker script to put .setup first, then link .text to 0xc0000400 and put it on the file kernel.sys after .setup and at 1024bytes in to the file

here is my current linker:

Code: Select all

OUTPUT_FORMAT("binary")
ENTRY(start)
phys = 0x00100000;
virt = 0xC0000400;
SECTIONS
{
  .setup phys : AT( phys )
  {
    setup = .; _setup = .; __setup = .;
    *(.setup)
    setupend = .;
    . = ALIGN(1024);
  }
  .kernel virt : AT( ADDR(.setup) + SIZEOF(.setup) )
  {
    code = .; _code = .; __code = .;
    *(.text)
    codend = .;
    . = ALIGN(0);
  }
  .data virt : AT( ADDR(.setup) + SIZEOF(.setup) + SIZEOF(.kernel) )
  {
    data = .; _data = .; __data = .;
    *(.data)
    dataend = .;
    . = ALIGN(0);
  }
  .bss virt : AT( ADDR(.setup) + SIZEOF(.setup) + SIZEOF(.kernel) + SIZEOF(.data))
  {
    bss = .; _bss = .; __bss = .;
    *(.bss)
    bssend = .;
    . = ALIGN(0);
  }
  .rodata virt : AT( ADDR(.setup) + SIZEOF(.setup) + SIZEOF(.kernel) + SIZEOF(.data)  + SIZEOF(.bss) )
  {
    rodata = .; _rodata = .; __rodata = .;
    *(.rodata)
    rodataend = .;
    . = ALIGN(0);
  }
  setuplength = SIZEOF(.setup);
  bsslength = (bssend - bss) / 4;
  kend = .; _kend = .; __kend = .;
}
I hope someone knows what is going on

thank you

EDIT: "witch" to "which"

Posted: Mon Mar 31, 2008 4:56 pm
by lukem95
OT: "witch" should be "which"

On Topic: your linker script looks right, i dont see why it wont work

Posted: Mon Mar 31, 2008 5:15 pm
by GLneo
yeah, I don't know why ether, but .setup is not executed, .text is put first, i don't know if .setup is even included?, maybe it has something to do with assembling ( nasm ) the .setup section to the ELF format instead of COFF like in windows, anyone know of any issues with this?

Posted: Mon Mar 31, 2008 6:35 pm
by karloathian
My knowledge on linkers and the .elf format is rather limited so you'll have to bear with me a bit. The only option I see here to see what's going on is to have your linker print out a .map file ( on ld it's either -M or --print-map ) and see how the linker builds your sections.

On a side note, maybe you should keep your sections to the strict minimum , like .text , .data and .bss and have your kernel load thusly , letting the boot loader load your start function first. I'm assuming of course that your kernel enables paging on it's own of course.

Posted: Mon Mar 31, 2008 8:53 pm
by GLneo
well I need a section ( .setup ) that knows where it is to setup paging, I don't know how i could do w/o?

the map.txt show the setup is getting placed correctly so now i'm confused...

Posted: Mon Mar 31, 2008 9:10 pm
by karloathian
It could just be your booting code thats broken. If you're using GRUB for the bootloading process , you have to make sure that header is correct and fits in the following format:

Header location
.text begin
.text end and bss .begin
.bss end
Entry point of the kernel

So that when GRUB loads the Kernel it can calculate how to fit your kernel into memory and align correctly. For in depth details I'd direct you straight ot the GRUB specification.

In any way my unprofessional opinion is that either your booting code is broken or that your paging setup is screwed up