what is the purpose of __ASSEMBLY__?

Slade Maurer smaurer at teja.com
Mon Jan 3 17:44:46 GMT 2005

 


Let's keep in mind that we are discussing header files specifically.
__ASSEMBLY__ allows them to be shared between C and assembly code so all
the useful data is in the same place -- as Ho Lee said.

The CPP does process typedef and #defines as Rainer Weikusat states.
However, __ASSEMBLY__ is still required to solve problems with symbols
that gas can't understand but cc1 can.

For example, this section of code from a header file uses it to solve a
problem:

#ifdef __ASSEMBLY__
#define __PAGE_OFFSET  (0xB0000000)
#else
#define __PAGE_OFFSET  (0xB0000000UL)
#endif /* __ASSEMBLY__ */

Now, what is it doing? Well, cleary the developer thought gas would
choke on casting the constant as an unsigned long for cc1 and so uses
the __ASSEMBLY__ directive to allow __PAGE_OFFSET to be handled by gas
and by cc1. More precisely, CPP would use __ASSEMBLY__ to pick the
correct __PAGE_OFFSET token. Then, it would substitute occurances in the
file(s) it is pre-processing before they are passed to the assembler or
compiler. The assembler sees 0xB0000000 and the C compiler sees
0xB0000000UL so they are both happy!

Hope this helps.

-Slade

Rainer Weikusat wrote:

>"Ho Lee" <flylist at linuxkernel.net> writes:
>   
>
>>It is useful when assembly codes and C codes share the header files.
>>Assembler can preprocess #define macros but does not recognize most of
>>C syntaxes such as typedef or function prototypes.
>>     
>>
>
>This is bullshit. 'gcc' runs .S files through the C preprocessor
>(either standlone cpp or something integrated), which means that you
>can use everything the preprocessors knows how to deal with in
>assembly sources files as long as you use gcc as a frontend. The
>assembler (gas) knows nothing about all that (and doesn't understand C
>syntax, of course).
>
>
>
>-------------------------------------------------------------------
>Subscription options: http://lists.arm.linux.org.uk/mailman/listinfo/linux-arm-kernel
>FAQ:       http://www.arm.linux.org.uk/armlinux/mlfaq.php
>Etiquette: http://www.arm.linux.org.uk/armlinux/mletiquette.php
>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值