From: Keith Owens <kaos@ocs.com.au>
To: linux-ia64@vger.kernel.org
Subject: Re: [Linux-ia64] Offsets from C struct into assembler
Date: Mon, 28 Jan 2002 12:16:28 +0000 [thread overview]
Message-ID: <marc-linux-ia64-105590698805941@msgid-missing> (raw)
In-Reply-To: <marc-linux-ia64-105590698805940@msgid-missing>
On Mon, 28 Jan 2002 09:56:27 +0100,
Christian Hildner <christian.hildner@hob.de> wrote:
>Does anyone know how to bring offsets from a C structure into pure
>assembly code (not inline-asm)?
>I want to do something like:
>
>struct abc {
> ...
> long varx;
> ...
> }
>
>add rx=offset(varx),ry // get address of variable
>ld8 rx=[rx] // get variable varx
>
>with ry being the base address of the structure abc and offset_varx
>beeing compiled from struct abc.
This is the standard method used by linux kernel build in 2.5 kernels.
== asm-offsets.c
/*
* Generate definitions needed by assembly language modules.
* This code generates raw asm output which is post-processed to extract
* and format the required data.
*/
#include <linux/types.h>
#include <linux/stddef.h>
#include <linux/sched.h>
/* Use marker if you need to separate the values later */
#define DEFINE(sym, val, marker) \
asm volatile("\n-> " #sym " %0 " #val " " #marker : : "i" (val))
#define BLANK() asm volatile("\n->" : : )
int
main(void)
{
DEFINE(state, offsetof(struct task_struct, state),);
DEFINE(flags, offsetof(struct task_struct, flags),);
DEFINE(sigpending, offsetof(struct task_struct, sigpending),);
DEFINE(addr_limit, offsetof(struct task_struct, addr_limit),);
DEFINE(exec_domain, offsetof(struct task_struct, exec_domain),);
DEFINE(need_resched, offsetof(struct task_struct, need_resched),);
DEFINE(tsk_ptrace, offsetof(struct task_struct, ptrace),);
DEFINE(processor, offsetof(struct task_struct, processor),);
BLANK();
DEFINE(ENOSYS, ENOSYS,);
return 0;
}
== Compile 'gcc asm-offsets.c -S -o asm-offsets.s' then
# Convert raw asm offsets into something that can be included as
# assembler definitions. It converts
# -> symbol $value source
# into
# #define symbol value /* 0xvalue source */
(set -e;
(echo "#ifndef __ASM_OFFSETS_H__";
echo "#define __ASM_OFFSETS_H__";
echo "/*";
echo " * DO NOT MODIFY";
echo " *";
echo " * This file was generated by arch/${ARCH}/Makefile.in.";
echo " *";
echo " */";
echo "";
awk "/^->\$/{printf(\"\\n\");}
/^-> /{
sym = \$2;
val = \$3;
sub(/^\\\$/, \"\", val);
\$1 = \"\";
\$2 = \"\";
\$3 = \"\";
printf(\"#define %-40s %5d\\t\\t\\t/* 0x%x\\t%s */\\n\",
sym, val, val, \$0)
}";
echo "";
echo "#endif";
) < asm-offsets.s > asm-offsets.h)
asm-offsets.h contains #define statements for each DEFINE in
asm-offsets.c.
next prev parent reply other threads:[~2002-01-28 12:16 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-01-28 8:56 [Linux-ia64] Offsets from C struct into assembler Christian Hildner
2002-01-28 12:16 ` Keith Owens [this message]
2002-01-28 15:11 ` n0ano
2002-01-28 20:59 ` Keith Owens
2002-01-28 21:15 ` David Mosberger
2002-01-29 7:06 ` Christian Hildner
2002-01-29 8:39 ` David Mosberger
2002-01-29 9:36 ` Andreas Schwab
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=marc-linux-ia64-105590698805941@msgid-missing \
--to=kaos@ocs.com.au \
--cc=linux-ia64@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.