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]

Assembly code parametriaztion


Hello.

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
to keep the contents of these files synchronized. GCC allows to
insert small parametrized assembly code _inside_ functions, but
not outside. It's not always possible to surround such code
with an auxilary function (to allow parametrization), because
it is unclear how the stack frame looks like. I made a simple
workaround (USED is for __attribute__((used))):

#define __EMIT(Name,Value,Line) static USED VOID __emit_const##Line()
{         \

\
    __asm__ __volatile__("*/\n\t.equ " #Name ",%c0 \n\t/*" : : "i"(Value));
\
}

#define __EMIT_AUX(Name,Value,Line) asm("/*"); __EMIT(Name,Value,Line)
asm("*/")

#define EMIT(Name,Value) __EMIT_AUX(Name,Value,__LINE__)


// Example code


namespace X {

    enum { a = 3};
}


EMIT(m_GDT,99);        // here I define m_GDT = 99
EMIT(x,X::a);                // and x = X::a = 3

asm("\tmovl $m_GDT,%eax\n\twbinvd\n");    // Free-standing code, m_GDT const
is used


G++3.2 generates the following code:


 .file "events.cpp"
#APP
 /*
#NO_APP
 .text
 .align 2
 .p2align 2,,3
 .type _Z14__emit_const20v,@function
_Z14__emit_const20v:
#APP
 */
 .equ m_GDT,99
 /*
#NO_APP
 ret
.Lfe1:
 .size _Z14__emit_const20v,.Lfe1-_Z14__emit_const20v
#APP
 */

  movl $m_GDT,%eax
  wbinvd


This way makes use of the internal code representation (to comment
out the unwanded part of code), which is obviously SICK! But this
way works and is quite comfortable to the user. Could you please
do one of the following things:

1. Make the "naked" attribute always enabled (currently it's
ARM or AVR-speciffic, don't remember...). This would
allow to remove unwanted stack frames. The same applies
to the "interrupt" attribute.

2. Unify the free-standing assembly parameter passing with
inlined assembly -- the programmer would be able to write

asm("    movl %0,%eax\n" : : "i"(156)); outside of a function.

3. Provide another mechanism for this purpose, i.e. to
pass some parameters or -- at least -- define a constant
within such code.

It would be nice to implement one of above mechanisms
in the current version of GCC. I need this feature very
much, so -- as a low-level programmer -- I can help the
GCC team to implement it properly. I see there was some
changes in the version 3.1, so I think it's necessary to finish
this process and fix the remaining inline assembly-related
problems in 3.2/3.3. Allowing only parameterless assembly
code is not a bug of course, however it's a big misfeature.

    Best regards
    Piotr Wyderski




Serwis www.logo.hoga.pl - sciągaj bajery na telefony
Nokia, Siemens, Alcatel, Ericsson, Motorola,Samsung
------------------------------------------------------------
Promocja!!! rabat 40 % na zakup mks_vir 2003 dla klientów Connect , którzy
posiadaja kupony rabatowe.



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