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
173 stars 13 forks source link

Where can I find the ABI for gcc-ia16 described? #58

Closed ecm-pushbx closed 4 years ago

ecm-pushbx commented 4 years ago

I only found the "Submodel Options" → "IA-16 Options" in the gcc.info file and that links to "Function Attributes" → "IA-16 Function Attributes". This lists the cdecl, stdcall, and regparmcall attributes, but it does not fully describe the ABI.

I want to convert some old programs to using NASM-assembled subfunctions instead of inline assembly. For that I want to know the exact ABI. Here's an example of what I am currently playing with:

$ cat test.asm

%include "lmacros3.mac"

    numdef FARCALL, 0
%if _FARCALL
 %define frametype far
%else
 %define frametype near
%endif

bits 16

global testfunction
testfunction:
    lframe frametype
    lframe_needonlyregistered
    lenter
    mov ax, 12345
    lleave
    lret
$ cat test3.c

#include <stdio.h>

extern unsigned int testfunction(void);

int main(int argc, char** argv) {
  int volatile a = testfunction();
  printf("Hello world! a=%04Xh a=%u\n", a, a);
  return 0;
}
$ model="-mcmodel=medium"; farcall="-D_FARCALL"; nasm -I ../lmacros/ test.asm $farcall -f elf -o test.o && ia16-elf-gcc test3.c test.o $model -Os -o test3.exe && dosemu -K "$PWD" -dumb -quiet -E "c:ldebugu test3.exe"
About to Execute : c:ldebugu test3.exe
-g
Hello world! a=3039h a=12345

Program terminated normally (0000)
-q
$ 
tkchia commented 4 years ago

Hello @ecm-pushbx,

The default calling convention, if you do not specify any options, is cdecl --- sorry I did not make that clear.

However, if you use a -mrtd or -mregparmcall option during both compilation and linking, you can effectively switch your whole program to a different calling convention. I have actually arranged to build different versions of the C library and libgcc for the different calling conventions (cdecl, stdcall, and regparmcall).

Thank you!

ecm-pushbx commented 4 years ago

My question is which registers are call-preserved and which are call-clobbered. This does not seem to be documented anywhere.

tkchia commented 4 years ago

Hello @ecm-pushbx,

OK... yes, unfortunately gcc-ia16 does not yet have a spiffy ABI document. But in brief:

I will try to find a place in the info file to stash this information.

Thank you!

ecm-pushbx commented 4 years ago

Ok, thanks! I suggest you should close this issue once you have things documented somewhere.

tkchia commented 4 years ago

Thanks @ecm-pushbx!