From: joshc@linux.com (Josh Cartwright)
To: kernelnewbies@lists.kernelnewbies.org
Subject: DEFINE Macro
Date: Fri, 6 Jan 2012 09:09:25 -0500 [thread overview]
Message-ID: <20120106140925.GF14353@joshcartwright.net> (raw)
In-Reply-To: <4F066B60.5000701@zoho.com>
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).
--
joshc
next prev parent reply other threads:[~2012-01-06 14:09 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-06 3:32 DEFINE Macro Fredrick
2012-01-06 6:12 ` mypopy at gmail.com
2012-01-06 14:09 ` Josh Cartwright [this message]
2012-01-06 16:09 ` Fredrick
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120106140925.GF14353@joshcartwright.net \
--to=joshc@linux.com \
--cc=kernelnewbies@lists.kernelnewbies.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).