linux-assembly.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* C structures and gas
@ 2002-11-12  0:43 Corey Holcomb-Hockin
  2002-11-12  2:51 ` Scott Lanning
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Corey Holcomb-Hockin @ 2002-11-12  0:43 UTC (permalink / raw)
  To: linux-assembly

What is the best way to access C structures with gas assembly?  I 
haven't gotten any good ideas from looking at assembly generated from C 
code.  It looks like it keeps track of offsets and the size of 
structures on its own.  I would have a hard time keeping track of 
offsets and changing them if the structure changed.

Corey Holcomb-Hockin


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: C structures and gas
  2002-11-12  0:43 C structures and gas Corey Holcomb-Hockin
@ 2002-11-12  2:51 ` Scott Lanning
  2002-11-12  5:56 ` Randall Hyde
  2002-11-28  6:15 ` Christian Hildner
  2 siblings, 0 replies; 4+ messages in thread
From: Scott Lanning @ 2002-11-12  2:51 UTC (permalink / raw)
  To: Corey Holcomb-Hockin; +Cc: linux-assembly

On Mon, 11 Nov 2002, Corey Holcomb-Hockin wrote:
> What is the best way to access C structures with gas assembly?  I
> haven't gotten any good ideas from looking at assembly generated from C
> code.  It looks like it keeps track of offsets and the size of
> structures on its own.  I would have a hard time keeping track of
> offsets and changing them if the structure changed.

Yes. The way I did it, I use constants and "chain" them
one after another. The more constants the better (replace even
the numbers 0, 2, 4 below with constants). For example,

SIZEOF_SA = 16

SA = -SIZEOF_SA
SA_SIN_FAMILY = SA + 0
SA_SIN_PORT = SA_SIN_FAMILY + 2
# etc...

# always start the next variable declared on the stack based on
# the beginning of the previous one
SOCKET_ARGS = SA - 3*4
SOCKET_ARG0 = SOCKET_ARGS
SOCKET_ARG1 = SOCKET_ARG0 + 4
# etc..

# set STACK_TOP to the last variable
STACK_TOP = SOCKET_ARGS

# data here...

_start:
        // setup stack...
        pushl %ebp
        movl %esp, %ebp
        addl $STACK_TOP, %esp

# ...


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: C structures and gas
  2002-11-12  0:43 C structures and gas Corey Holcomb-Hockin
  2002-11-12  2:51 ` Scott Lanning
@ 2002-11-12  5:56 ` Randall Hyde
  2002-11-28  6:15 ` Christian Hildner
  2 siblings, 0 replies; 4+ messages in thread
From: Randall Hyde @ 2002-11-12  5:56 UTC (permalink / raw)
  To: Corey Holcomb-Hockin, linux-assembly

Well, the best way to do it in Gas is to use HLA and have
HLA generate the Gas code for you :-)
Seriously, though, Gas doesn't have much in the way of
abstract data typing capabilities.  If you want to move
beyond the minimal features available in Gas or NASM,
you're a prime candidate to learn assembly under HLA
(the High Level Assembler).  Not only does HLA support
records (structures), unions, and classes, but it provides
some very flexible options for controlling the alignment of
objects within the structures so that your assembly structs
can be made compatible with just about any compiler
out there (C or otherwise).
You can check out HLA at http://webster.cs.ucr.edu
Randy Hyde
----- Original Message ----- 
From: "Corey Holcomb-Hockin" <crsntlvs@ipeg.com>
To: <linux-assembly@vger.kernel.org>
Sent: Monday, November 11, 2002 4:43 PM
Subject: C structures and gas


> What is the best way to access C structures with gas assembly?  I 
> haven't gotten any good ideas from looking at assembly generated from C 
> code.  It looks like it keeps track of offsets and the size of 
> structures on its own.  I would have a hard time keeping track of 
> offsets and changing them if the structure changed.
> 
> Corey Holcomb-Hockin
> 
> -
> To unsubscribe from this list: send the line "unsubscribe linux-assembly" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: C structures and gas
  2002-11-12  0:43 C structures and gas Corey Holcomb-Hockin
  2002-11-12  2:51 ` Scott Lanning
  2002-11-12  5:56 ` Randall Hyde
@ 2002-11-28  6:15 ` Christian Hildner
  2 siblings, 0 replies; 4+ messages in thread
From: Christian Hildner @ 2002-11-28  6:15 UTC (permalink / raw)
  To: Corey Holcomb-Hockin; +Cc: linux-assembly

Corey Holcomb-Hockin schrieb:

> What is the best way to access C structures with gas assembly?  I
> haven't gotten any good ideas from looking at assembly generated from C
> code.  It looks like it keeps track of offsets and the size of
> structures on its own.  I would have a hard time keeping track of
> offsets and changing them if the structure changed.
>
> Corey Holcomb-Hockin
>

Have a look how linux does this in the ia64 tree. See
/usr/src/linux/arch/ia64/tools/print_offset.c.
There are three steps:

1. compile print_offsets
2. run print_offsets (creates offsets.h)
3. include offsets.h into *.S

Christian


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2002-11-28  6:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-11-12  0:43 C structures and gas Corey Holcomb-Hockin
2002-11-12  2:51 ` Scott Lanning
2002-11-12  5:56 ` Randall Hyde
2002-11-28  6:15 ` Christian Hildner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).