www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/09/23/03:03:14

To: djgpp AT sun DOT soe DOT clarkson DOT edu
Xref: news.cygnus.com cygnus.djgpp:2093
Newsgroups: cygnus.djgpp
Path: news.cygnus.com!nntp.cygnus.com!sac
From: sac AT cygnus DOT com (Steve Chamberlain)
Subject: Re: Using GCC for Windows apps/DLL's
Sender: news AT cygnus DOT com
Nntp-Posting-Host: rtl.cygnus.com
Organization: Cygnus Support
References: <940922101933 DOT 20e01f88 DOT cygnus DOT djgpp AT FAXCSL DOT DCRT DOT NIH DOT GOV>
Distribution: cygnus
Date: Fri, 23 Sep 1994 05:04:05 GMT
Lines: 91

First the good news:

I've used go32 gcc to generate win32s object files and successfully run
a hello world.

Then not quite so good news:

It took was one quick tweak to gas, some work in gcc and a bit of glue.

Gas needed some changing to gas to get the relocs looking the way that
Microsoft's linker expected them. 

Gcc was a bit harder, but Chris Tate (FIXER AT FAXCSL DOT DCRT DOT NIH DOT GOV) is
not quite correct when he says

> It turns out that making gcc understand Pascal calling conventions is
> *very* hard.  ..


It is quite simple to make GCC generate a Pascal calling convention.
Most of the work can be done by changing the definition of
RETURN_POPS_ARGS in gcc/config/i386.h.  The trick is to make gcc
understand Pascal and C calling conventions at the same time.

To cope with mixing PASCAL and non PASCAL calling conventions in the
same file, I added an 'attribute' keyword in my gcc and looked for
that when generating the calls - so you can do something like:

#define PASCAL __attribute__ ((pascal))

and then declare functions like this:

int foo (int a, int b) PASCAL ;

(I didn't change the parser so you could put the attribute in the same
place as Microsoft expects the PASCAL keyword).

You can change the order in which arguments are pushed by defining or
undefining the name ARGS_GROW_DOWNWARD.

This is where it started to get tricky.  My initial goal was to get
hello world appearing in a win32s screen, some of the library routines
I needed to call had PASCAL calling conventions, others did not.
That's simple - the 'attribute' springs to the rescue.  But others
seemed to need their args passed left to right, and some right to
left!  That can't be fixed in GCC without a non-trivial hack.

I wrote a load of glue functions which just inverted their argument
lists, so I could type in examples from the book and get them to work.

Then came callbacks - Windows really likes to call functions in your
code, but it would pass the args in the wrong order - so I had to
provide more glue routines.  To register your callback, you'd provide
windows with a pointer to the glue routine.  When windows calls the
glue routine, the glue would reverse the args and then call the
routine you wanted to call in the first place.  Perhaps I could
have eased the pain by changing the GCC default arg order the other
way around.

This was beginning to gross me out (and I'm famous at Cygnus for my
tolerance for crap code).  Also, it's really hard to debug in this
environment, especially for a windows innocent like me.  The final
blow was that I actually had to get some work done, so for now it's on
hold.


So to summerize:

Yes it's possible.  No, you don't want to do it (yet).  Sooner or
later some programming guru/stud will either fix GCC to allow two
different arg orders in the same prog, or write all the (thousands)
of glue routines.

Note that Rainer Schnitker (rainer AT mathematik DOT uni-bielefeld DOT de) has
gone most of the way here already - rsxwin and rsxwdk are good
foundations (and he has a program which reads windows header files and
writes glue).  If I'd spent that spare time polishing his code rather
than joy-riding in GCC, maybe it would be finished now.


Steve









- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019