Bug 25469

Summary: [Z80][PATCH] Add support for GBZ80, Z80N CPUs and DWARF
Product: binutils Reporter: Sergey Belyashov <sergey.belyashov>
Component: gasAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: enhancement CC: nickc
Priority: P2    
Version: unspecified   
Target Milestone: ---   
Host: Target: z80-unknown-*
Build: Last reconfirmed:
Attachments: Add support GBZ80
Complete GBZ80 support, gcsections, DWARF
Add GBZ80 and Z80N support, gcsections, and DWARF
Add support GBZ80 and Z80N
Add support GBZ80 and Z80N
Add support GBZ80, Z80N CPUs and DWARF
Add support GBZ80, Z80N and DWARF. Fix LD tests failures.
Add support GBZ80 and Z80N CPUs. Fix LD tests failures.
Add support GBZ80 and Z80N CPUs. Fix LD tests failures.

Description Sergey Belyashov 2020-01-27 12:36:05 UTC
Created attachment 12232 [details]
Add support GBZ80

This patch completes support for GameBoy Z80 CPU.
Comment 1 Sergey Belyashov 2020-01-29 09:36:07 UTC
Created attachment 12236 [details]
Complete GBZ80 support, gcsections, DWARF

Add define to enable gc-sections support (but linker warns, that --gc-sections option is ignored, I do not know why).
Add support for DWARF (enables some tests, one of which (eh5) fails).
Comment 2 Sergey Belyashov 2020-01-29 16:05:08 UTC
Created attachment 12237 [details]
Add GBZ80 and Z80N support, gcsections, and DWARF

Add support for Z80N (Z80 Next) CPU.
Comment 3 Sergey Belyashov 2020-01-30 12:01:59 UTC
Created attachment 12238 [details]
Add support GBZ80 and Z80N

Fix new relocation
Add LD test for new relocation
Comment 4 Nick Clifton 2020-01-31 14:22:21 UTC
(In reply to Sergey Belyashov from comment #3)
> Created attachment 12238 [details]
> Add support GBZ80 and Z80N
> 
> Fix new relocation
> Add LD test for new relocation

I am seeing new linker testsuite failures with this patch applied. :-(

Checking Binutils in: z80-elf ... LD: 49  done
  LD REGRESSION: ld-elf/eh5    

Checking Binutils in: z80-coff ... LD: 19  done
  LD REGRESSION: ld-misc/defsym1    
  LD REGRESSION: sysroot-prefix common plain -Lpath, quoted
  LD REGRESSION: sysroot-prefix common plain -Lpath, unquoted
  LD REGRESSION: sysroot-prefix common full-path, quoted  
  LD REGRESSION: sysroot-prefix common full-path, unquoted 
  LD REGRESSION: sysroot-prefix common plain =-prefixed with
  LD REGRESSION: sysroot-prefix common plain =-prefixed with
  LD REGRESSION: sysroot-prefix common plain $SYSROOT-prefixed with
  LD REGRESSION: sysroot-prefix common plain $SYSROOT-prefixed with
  LD REGRESSION: sysroot-prefix common plain =-prefixed -Lpath,
  LD REGRESSION: sysroot-prefix common plain =-prefixed -Lpath,
  LD REGRESSION: sysroot-prefix common plain $SYSROOT-prefixed -Lpath,
  LD REGRESSION: sysroot-prefix common plain $SYSROOT-prefixed -Lpath,
  LD REGRESSION: sysroot-prefix common full-path =-prefixed without,
  LD REGRESSION: sysroot-prefix common full-path =-prefixed without,
  LD REGRESSION: sysroot-prefix common full-path $SYSROOT-prefixed without,
  LD REGRESSION: sysroot-prefix common full-path $SYSROOT-prefixed without,
  LD REGRESSION: --entry foo archive  
  LD REGRESSION: --entry foo -u foo archive

Could you investigate these please and fix/waive as appropriate.

Cheers
  Nick
Comment 5 Sergey Belyashov 2020-01-31 15:35:41 UTC
Created attachment 12242 [details]
Add support GBZ80 and Z80N

Fix COFF linker test failures

I have no idea how to fix ld-elf/eh5 test failure. It is new test which was enabled when I enable DWARF generation for Z80 target.

There is part of log:
regexp "^0+01(58|70) 0+0014 0+01(5c|74) FDE cie=0+0000 pc=.*$"
line   "00000158 00000010 00000000 CIE"

regexp "^  DW_CFA_advance_loc: 4 to .*$"
line   "  Version:               1"

regexp "^  DW_CFA_def_cfa: r0(.*) ofs 16$"
line   "  Augmentation:          "zR""

regexp "^  DW_CFA_nop$"
line   "  Code alignment factor: 1"

regexp "^  DW_CFA_nop$"
line   "  Data alignment factor: -1"

regexp "^  DW_CFA_nop$"
line   "  Return address column: 7"

regexp "^0+01(70|88) 0+0014 0+0(01c|148|15c) FDE cie=0+0(02c|030|170) pc=.*$"
line   "  Augmentation data:     0b"

regexp "^  DW_CFA_advance_loc: 4 to .*$"
line   "  DW_CFA_nop"

regexp "^  DW_CFA_def_cfa: r0(.*) ofs 16$"
line   "  DW_CFA_nop"
...
I have no expirience in DWARF. Can somebody helps me?
Comment 6 Sergey Belyashov 2020-02-04 10:00:53 UTC
Created attachment 12249 [details]
Add support GBZ80, Z80N CPUs and DWARF

Fix one test (used label name `a', which is Z80 register name)

eh5 test is still failed (it is new test, which is enabled after enabling of DWARF). I think, problem is another place. For example, elf/discard tests fails due to silence of linker (test expects warning). Linker silently succeed due to discarding of symbol which should go to discard section. I think, same bug causes failure of PR 10549 (GNU OS ABI on STB_GNU_UNIQUE). I completely do not understand what happens there.

Moreover, there are two assertion fails in four places of testsuit:
./ld-new: BFD (GNU Binutils) 2.34.50.20200127 assertion fail ../../bfd/elf.c:3550
./ld-new: BFD (GNU Binutils) 2.34.50.20200127 assertion fail ../../bfd/elf.c:3655

This change patch no regressions (at least, detectible by tests).
Comment 7 Sergey Belyashov 2020-02-04 13:40:22 UTC
Created attachment 12251 [details]
Add support GBZ80, Z80N and DWARF. Fix LD tests failures.

Fix most of LD test failures!!!

Currently only folowing tests fails:
- ld-elf/eh5 (I do not know why, and how to fix)
- ld-elf/merge (Z80 target cannot relocate cross-segment subtractions)
- ld-elf/pr22450 (.dc.a allocates 16-bit value (it is correct for Z80), but not 32 as expected)
Comment 8 Sergey Belyashov 2020-02-05 08:42:19 UTC
Created attachment 12258 [details]
Add support GBZ80 and Z80N CPUs. Fix LD tests failures.

Temporary remove DWARF support. I cannot fix eh5 test failure.

Now no more regressions will be reported.
Comment 9 Sergey Belyashov 2020-02-05 13:00:41 UTC
Created attachment 12259 [details]
Add support GBZ80 and Z80N CPUs. Fix LD tests failures.

Add commonly used aliases for GBZ80's LDI and LDD instructions.
Add forgotten GBZ80 instruction ldh a,(c)
Comment 10 Nick Clifton 2020-02-06 16:41:42 UTC
(In reply to Sergey Belyashov from comment #9)
Hi Sergey,

> Created attachment 12259 [details]

Ummm, this version appears to delete the ld/elmulparams/z80elf.em file entirely.
That cannot be right, can it ?

Cheers
  Nick
Comment 11 Sergey Belyashov 2020-02-06 16:47:59 UTC
Yes. z80.em contains all necessary.
Comment 12 Sourceware Commits 2020-02-07 14:56:37 UTC
The master branch has been updated by Nick Clifton <nickc@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=9fc0b501af78bc4a92f53ec712e1aaa123e0224c

commit 9fc0b501af78bc4a92f53ec712e1aaa123e0224c
Author: Sergey Belyashov <sergey.belyashov@gmail.com>
Date:   Fri Feb 7 14:53:46 2020 +0000

    Add support for the GBZ80 and Z80N variants of the Z80 architecture, and add DWARF debug info support to the Z80 assembler.
    
    	PR 25469
    bfd	* archures.c: Add GBZ80 and Z80N machine values.
    	* reloc.c: Add BFD_RELOC_Z80_16_BE.
    	* coff-z80.c: Add support for new reloc.
    	* coffcode.h: Add support for new machine values.
    	* cpu-z80.c: Add support for new machine names.
    	* elf32-z80.c: Add support for new reloc.
    	* bfd-in2.h: Regenerate.
    	* libbfd.h: Regenerate.
    
    binutils* readelf.c (get_machine_flags): Add support for Z80N machine
    	number.
    
    gas	* config/tc-z80.c: Add -gbz80 command line option to generate code
    	for the GameBoy Z80.  Add support for generating DWARF.
    	* config/tc-z80.h: Add support for DWARF debug information
    	generation.
    	* doc/c-z80.texi: Document new command line option.
    	* testsuite/gas/z80/gbz80_all.d: New file.
    	* testsuite/gas/z80/gbz80_all.s: New file.
    	* testsuite/gas/z80/z80.exp: Run the new tests.
    	* testsuite/gas/z80/z80n_all.d: New file.
    	* testsuite/gas/z80/z80n_all.s: New file.
    	* testsuite/gas/z80/z80n_reloc.d: New file.
    
    include	* coff/internal.h (R_IMM16BE): Define.
    	* elf/z80.h (EF_Z80_MACH_Z80N): Define.
    	(R_Z80_16_BE): New reloc.
    
    ld	* emulparams/elf32z80.sh: Use z80 emulation.
    	* emultempl/z80.em: Make generic to both COFF and ELF Z80 emulations.
    	* emultempl/z80elf.em: Delete.
    	* testsuite/ld-elf/pr22450.d: Expect to fail for the Z80.
    	* testsuite/ld-elf/sec64k.exp: Fix Z80 assembly.
    	* testsuite/ld-unique/pr21529.s: Avoid register name conflict.
    	* testsuite/ld-unique/unique.s: Likewise.
    	* testsuite/ld-unique/unique_empty.s: Likewise.
    	* testsuite/ld-unique/unique_shared.s: Likewise.
    	* testsuite/ld-unique/unique.d: Updated expected output.
    	* testsuite/ld-z80/arch_z80n.d: New file.
    	* testsuite/ld-z80/comb_arch_z80_z80n.d: New file.
    	* testsuite/ld-z80/labels.s: Add more labels.
    	* testsuite/ld-z80/relocs.s: Add more reloc tests.
    	* testsuite/ld-z80/relocs_f_z80n.d: New file
    
    opcodes	* z80-dis.c: Add support for GBZ80 opcodes.
Comment 13 Nick Clifton 2020-02-07 14:57:39 UTC
Thanks Sergey.  I have now applied your patch.