Re: DEFINE Macro

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Nice! Thanks for the explanation Josh.

-Fredrick

On 01/06/2012 06:09 AM, Josh Cartwright wrote:
> On Thu, Jan 05, 2012 at 07:32:48PM -0800, Fredrick wrote:
>> Hi,
>>
>> I am not able to understand the DEFINE macro used in
>> arch/powerpc/kernel/asm-offsets.c
>>
>> I suppose the DEFINE is present in
>> include/linux/kbuild.h
>> where it says
>> #define DEFINE(sym, val) \
>>           asm volatile("\n->" #sym " %0 " #val : : "i" (val))
>>
>> What does the above mean?
>
> This is just a trick to get the offsets of members into a generated header file
> asm-offsets.h.  The inline assembly does NOT contain valid instructions,
> and in fact, asm-offsets.c is never actually assembled into a program.
> Instead, the build process generates the assembly language output
> asm-offsets.s, and processes it with a sed script to generate
> asm-offsets.h.
>
> For example (assume offsetof(struct thread_struct, regs) is 30):
>
> 	DEFINE(PT_REGS, offsetof(struct thread_struct, regs));
>
> will generate within the assembly language output:
>
> 	->PT_REGS $30 offsetof(struct thread_struct, regs)
>
> A sed script, executed on the assembly language output will generate a
> line in include/generated/asm-offsets.h:
>
> 	#define PT_REGS 30 /* offsetof(struct thread_struct, regs) */
>
> Thats about it.  You can find the exact sed script used, and the make
> magic involved in Kbuild (see cmd_offsets).
>



_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@xxxxxxxxxxxxxxxxx
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux