This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Assembly code parametriaztion


"Piotr Wyderski" <piotr dot wyderski at hoga dot pl> writes:

> There is very vexing lack of feature in GCC. I need to pass
> some parameters to "free-standing" assembly code (by
> free-standing I mean code placed outside any function).
> This feature is widely used by most low-level code, for
> example by Linux; interrupt/exception handlers, page tables,
> stack management etc. are usually defined this way. It's hard
> to move such code to a separate assembly file, because it
> increases redundancy (every used constant must be defined
> twice: the first time inside a C(++) header and the second time
> inside an assembly header/source file) and obliges the programmer

You can do it basically two ways (both are used in the linux kernel):

- Make your include files assembler clean, usually with moderate
use of #ifdef __ASSEMBLY__ and include them in the assembly
files. This works well for #define, but not for things like structure
offsets.

- For structure offsets or complicated expression have a separate file
  that includes the include files does something like:

	asm volatile("-- #define struct_field %0" :: "i" (offsetof(struct structure, field)));

  Compile this program with -S, then run a small postprocessor over
  the assembly file that just filters out everything behind --
  Put that into an include file and use it from your assembly.
  
  Nice thing is that it also works fine for cross compiling.
  Only tricky thing is that you have to get the dependencies right
  in the Makefile, otherwise there can be subtle failures with -j
  compilation.

-Andi


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]