Bug 21565 - Z80: Incorrect linkage of call instructions
Summary: Z80: Incorrect linkage of call instructions
Status: RESOLVED INVALID
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.28
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-06-11 19:14 UTC by Thomas
Modified: 2020-02-19 14:16 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
Here is the file used for testing (56 bytes, text/x-asm)
2017-06-11 19:14 UTC, Thomas
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas 2017-06-11 19:14:30 UTC
Created attachment 10092 [details]
Here is the file used for testing

For the z80-unknown-coff target ld produces a wrong output for call instructions, I'm sure it happens in ld because the object file generated by as does not have the error. This produces wrong executable code from well written z80 source code.

As an example:

start:
	ld A, 0
	add A, 5
	sub 4
	call loop
loop:
	jr loop

after assembling it with "z80-unknown-coff-as a.asm -o a.o -z80" and disassembling it with "z80-unknown-coff-objdump a.o -d" the output is the following:

a.o:     file format coff-z80


Disassembly of section .text:

00000000 <start>:
   0:	3e 00       	ld a,0x00
   2:	c6 05       	add a,0x05
   4:	d6 04       	sub 0x04
   6:	cd 09 00    	call 0x0009

00000009 <loop>:
   9:	18 fe       	jr 0x0009

which does not have any errors at all, but after linking it I got the following output:
    3E 00 C6 05 D6 04 CD 09 01 18 FE

instead of:
    3E 00 C6 05 D6 04 CD 09 00 18 FE

which is the correct output I should get.
Comment 1 Sergey Belyashov 2019-12-04 15:29:41 UTC
It is correct. Default linker script (*.ld file) contains 0x100 offset for .text. So produces binary should be loaded at address 0x100. It is done for CP/M compatibility (it is described by comment in the *.ld script). You may create your own linker script and place code in any location.
Comment 2 Sergey Belyashov 2020-02-17 18:39:06 UTC
Please close the bug as invalid.
Comment 3 Nick Clifton 2020-02-19 14:16:26 UTC
closing