tkchia / gcc-ia16

Fork of Lambertsen & Jenner (& al.)'s IA-16 (Intel 16-bit x86) port of GNU compilers ― added far pointers & more • use https://github.com/tkchia/build-ia16 to build • Ubuntu binaries at https://launchpad.net/%7Etkchia/+archive/ubuntu/build-ia16/ • DJGPP/MS-DOS binaries at https://gitlab.com/tkchia/build-ia16/-/releases • mirror of https://gitlab.com/tkchia/gcc-ia16
GNU General Public License v2.0
179 stars 13 forks source link

[Feature request] Indicate relocations in assembler listing #106

Open ecm-pushbx opened 2 years ago

ecm-pushbx commented 2 years ago

This is an example assembly listing file output using gcc-ia16 with appropriate parameters: (Copied from my other issue earlier today.)

$ cat hello.c

#include "stdio.h"

void main(void) {
        printf("Hello world!\n");
}
$ ia16-elf-gcc -o hello.com hello.c -g -Wa,-anlhd=hello.lst,-L -masm=intel
cc1: warning: target system does not support debug output
$ cat hello.lst
   1                            .arch i8086,jumps
   2                            .code16
   3                            .intel_syntax noprefix
   4                    #NO_APP
   5                            .section        .rodata
   6                    .LC0:
   7 0000 48656C6C              .string "Hello world!"
   7      6F20776F
   7      726C6421
   7      00
   8                            .text
   9                            .global main
  11                    main:
  12 0000 55                    push    bp
  13 0001 89E5                  mov     bp,     sp
  14 0003 B80000                mov     ax,     offset .LC0
  15 0006 50                    push    ax
  16 0007 16                    push    ss
  17 0008 1F                    pop     ds
  18 0009 E8FEFF                call    puts
  19 000c 83C402                add     sp,     2
  20 000f 90                    nop
  21 0010 5D                    pop     bp
  22 0011 16                    push    ss
  23 0012 1F                    pop     ds
  24 0013 C3                    ret
  26                            .ident  "GCC: (GNU) 6.3.0"
$

This is how NASM's -f bin output format indicates relocations in the listing, note the square brackets:

$ cat bye.asm

        cpu 8086
        org 256
start:
        mov dx, message
        mov ah, 09h
        int 21h
        mov ax, 4C00h
        int 21h

message:
        db "Goodbye world!",13,10,36
$ nasm bye.asm -o bye.com -l bye.lst
$ cat bye.lst
     1
     2                                          cpu 8086
     3                                          org 256
     4                                  start:
     5 00000000 BA[0C00]                        mov dx, message
     6 00000003 B409                            mov ah, 09h
     7 00000005 CD21                            int 21h
     8 00000007 B8004C                          mov ax, 4C00h
     9 0000000A CD21                            int 21h
    10
    11                                  message:
    12 0000000C 476F6F646279652077-             db "Goodbye world!",13,10,36
    12 00000015 6F726C64210D0A24
$

I want the square brackets so as to help my trace listing program to identify the current instruction. Here's the logic (sorry for unreadable perl code) to skip over bytes sent from the debugger if they appear to match up to listing file opcode bytes enclosed in square brackets.

ecm-pushbx commented 2 years ago

This point seems like it generates the opcode dump in gas: https://github.com/tkchia/binutils-ia16/blob/1d7535fd03bdddf979d63fcd0072aa68129971fc/gas/listing.c#L762