[z80-coff-ld] how can I use ld for creating an exe from z80-coff-as ?

jseb gmane2010@finiderire.com
Thu Feb 23 14:48:00 GMT 2012


> .org doesn't do what you think it does.  gas isn't an absolute
> assembler, but instead produces relocatable object files.  .org just
> adds space to make the offset from the start of the current section
> equal to its argument.

Ok, i did what you've said, and deleted .org argument in source file.
I've also named sections, with :
  «.stub» for the header.
  «.mycode» for the real code, which should be loaded at 0xC000


    1               	.section .stub
    2 0000 FE        	    db $fe
    3 0001 0000 1B00 	    dw debut,fin,debut
    3      0000
    4               	
    5               	; don't use .ORG directive
    6               	; .ORG $C000
    7               	
    8               	.section .mycode
    9               	;
   10               	debut:
   11 0000 210D 00   	 LD HL,LABEL
   12 0003 7E        	AFF: LD A,(HL)
   13 0004 23        	 INC HL
   14 0005 A7        	 AND A
   15 0006 C8        	 RET Z
   16 0007 CDA2 00   	 CALL $A2 ; HFDA4 ;CHPUT
   17               	;
   18 000a 18F7      	 JR AFF
   19 000c C9        	 RET
   20 000d 4865 6C6C 	LABEL: DEFB "Hello World",13,10,0
   20      6F20 576F
   20      726C 640D
   20      0A00
   21               	fin:
   22               	 END


And then, i've written this script:

OUTPUT_FORMAT(binary)
SECTIONS
      {
        .stub 0xC000 - 7 : { *(.stub) }
        .code : { *(.mycode) }

      }

Using this, i got correct output, working in emulator
00000000  fe 00 c0 1b c0 00 c0 21  0d c0 7e 23 a7 c8 cd a2
   |.......!..~#....|
00000010  00 18 f7 c9 48 65 6c 6c  6f 20 57 6f 72 6c 64 0d
   |....Hello World.|
00000020  0a 00

You see the stub at the beginning:
  FE   (magic)
  00C0 (start adress of code: 0xC000)
  1BC0 (end address: 0xC0B1)
  00C0 (entry point, same as start)

And then,code following with correct relocation for execution at 0xC000.

The ld script is not very nice (the magic number «7»), but i couldn't 
manage to do better.
I you have a suggestion, it will be welcome.

Thank you for helping.



More information about the Binutils mailing list