How to set an absolute load and start address for binary?

1 post / 0 new
hypex
hypex's picture
Offline
Last seen: 3 months 3 weeks ago
Joined: 2011-09-09 16:20
How to set an absolute load and start address for binary?

Hi guys. ­So I've been experimenting with creating a CFE binary to run things from the CFE firmware. As it turns out, externally it identifies as CFE, but internally CFE uses OpenFirmware.

To run on CFE you just create a standard OS binary but it must be loaded to $200000 and start within this area. So I found some example code from the openbios project. I adapted the ofclient example so it compiled on OS4. 

I made up a makefile that I had working at some stage but somewhere along the line it broke. Now when I load the binary it has a start and entry address of zero! This isn't right and even the binary looks to be set correctly. It doesn't crash but it does hang CFE. My current makefile as follows.

  1. PROGRAM := ofclient
  2. OBJECTS := of1275.o of1275_io.o ofclient.o
  3. CC := gcc
  4. CFLAGS := -mpowerpc -fpic -fno-builtin-strlen -fno-builtin-exit -Os
  5. LDFLAGS := -melf32ppc -N -e _start -g -Ttext 0x200000
  6.  
  7. $(PROGRAM): $(OBJECTS)
  8. $(LD) $(LDFLAGS) -Map $(PROGRAM).map -o $(PROGRAM) $(OBJECTS)

Output of relevant info from objdump.

  1. ofclient: file format elf32-amigaos
  2. ofclient
  3. architecture: powerpc:common, flags 0x00000012:
  4. EXEC_P, HAS_SYMS
  5. start address 0x00200c30
  6.  
  7. Program Header:
  8. LOAD off 0x00000054 vaddr 0x00200000 paddr 0x00200000 align 2**2
  9. filesz 0x000010a8 memsz 0x0000130c flags rwx
  10.  
  11. Sections:
  12. Idx Name Size VMA LMA File off Algn
  13. 0 .text 00000e9c 00200000 00200000 00000054 2**2
  14. CONTENTS, ALLOC, LOAD, CODE
  15. 1 .rodata 00000160 00200e9c 00200e9c 00000ef0 2**2
  16. CONTENTS, ALLOC, LOAD, READONLY, DATA
  17. 2 .data 00000002 00200ffc 00200ffc 00001050 2**1
  18. CONTENTS, ALLOC, LOAD, DATA
  19. 3 .got 000000a8 00201000 00201000 00001054 2**2
  20. CONTENTS, ALLOC, LOAD, CODE
  21. 4 .bss 00000264 002010a8 002010a8 000010fc 2**2
  22. ALLOC
  23. 5 .comment 00000081 00000000 00000000 000010fc 2**0
  24. CONTENTS, READONLY
  25. SYMBOL TABLE:
  26. 00200000 l d .text 00000000 .text
  27. 00200e9c l d .rodata 00000000 .rodata
  28. 00200ffc l d .data 00000000 .data
  29. 00201000 l d .got 00000000 .got
  30. 002010a8 l d .bss 00000000 .bss
  31. 00000000 l d .comment 00000000 .comment
  32. 00000000 l df *ABS* 00000000 of1275.c
  33. 00000000 l df *ABS* 00000000 of1275_io.c
  34. 00000000 l df *ABS* 00000000 ofclient.c
  35. 0020109c l O .got 00000000 .hidden _GLOBAL_OFFSET_TABLE_
  36. 00200c30 g F .text 00000054 _start
  37. 0020130c g *ABS* 00000000 __end
  38. 00200e00 g F .text 0000009c main
  39. 002010a8 g *ABS* 00000000 _edata
  40. 0020130c g *ABS* 00000000 _end

Comparison with amigaboot.of that works.

  1. architecture: powerpc:common, flags 0x00000012:
  2. EXEC_P, HAS_SYMS
  3. start address 0x00200000
  4.  
  5. Program Header:
  6. LOAD off 0x00000054 vaddr 0x00200000 paddr 0x00200000 align 2**2
  7. filesz 0x0000f060 memsz 0x0000f060 flags rwx
  8.  
  9. Sections:
  10. Idx Name Size VMA LMA File off Algn
  11. 0 .text 0000c0ec 00200000 00200000 00000054 2**2
  12. CONTENTS, ALLOC, LOAD, READONLY, CODE
  13. 1 .rodata 00001048 0020d000 0020d000 0000d054 2**2
  14. CONTENTS, ALLOC, LOAD, READONLY, DATA
  15. 2 .data 00000058 0020f000 0020f000 0000f054 2**2
  16. CONTENTS, ALLOC, LOAD, DATA
  17. 3 .got2 00000008 0020f058 0020f058 0000f0ac 2**0
  18. CONTENTS, ALLOC, LOAD, DATA
  19. SYMBOL TABLE:
  20. 00200000 l d .text 00000000 .text
  21. 0020d000 l d .rodata 00000000 .rodata
  22. 0020f000 l d .data 00000000 .data
  23. 0020f058 l d .got2 00000000 .got2
  24. 002039d8 g F .text 0000015c _start

As you can see there isn't much difference. What would cause it to think the start and load address is zero? And despite having this working what do I need to get it to load at $200000 like I said? I suspect I need a linker script but I didn't need one before. It's kind of annoying when a simle thing like an absolute startign address is complicated to specify. I've read GCC doesn't like to even put the _start routine right at the start and objects must appear in certain order with certain options.