亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 8531 | 回復(fù): 7
打印 上一主題 下一主題

2.6 內(nèi)核中宏定義 #define DEFINE(sym, val)的問題 ? [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2006-02-17 16:35 |只看該作者 |倒序?yàn)g覽
linux2.6.14.3 內(nèi)核中有如下宏定義,

  1. #define DEFINE(sym, val) \
  2.         asm volatile("\n->" #sym " %0 " #val : : "i" (val))
復(fù)制代碼

沒弄清它的用法,于是用如下函數(shù)做了一下試驗(yàn),所得結(jié)果更是讓人不解。
宏定義中從"\n->"中的"-"開始的后續(xù)部分被編譯器忽略。gcc提示為
Warning: rest of line ignored; first character is '-.
(采用如下格式編譯:gcc -o tf tf.c)
程序打印結(jié)果為:0。

  1. /*tf.c*/
  2. #include "stdio.h"
  3. #define DEFINE(sym,val) \
  4.         asm volatile("\n->" #sym " %0 " #val : :"i" (val))

  5. int main(int argc,char* agrv[])
  6. {
  7.         int Ti=0;
  8.         DEFINE(Ti,8);
  9.         printf("\n The value of Ti is:%d\n",Ti);
  10.         return ;       
  11. }
復(fù)制代碼

[ 本帖最后由 albcamus 于 2006-2-17 18:07 編輯 ]

論壇徽章:
0
2 [報(bào)告]
發(fā)表于 2006-02-17 22:48 |只看該作者
#define DEFINE(sym,val) \
        asm volatile("\n->" #sym " %0 " #val : :"i" (val))


這段代碼顯然不符合gcc內(nèi)嵌匯編的格式,不能拿來直接用的!->”是用于sed的標(biāo)識符,編譯內(nèi)核時會替換掉“->”。

[ 本帖最后由 richardhesidu 于 2006-2-18 14:44 編輯 ]

論壇徽章:
0
3 [報(bào)告]
發(fā)表于 2006-02-18 18:18 |只看該作者
這段代碼在redhat上編譯都通不過。
我估計(jì)這段代碼的意思是:
asm volatile("\n->" #sym " %0 " #val : :"i" (val))     =    #define  sym  val

只不過這里是動態(tài)的定義。只需要傳一個sym和val進(jìn)來,就可以幫你完成#define  sym  val的功能

[ 本帖最后由 normalnotebook 于 2006-2-18 18:20 編輯 ]

論壇徽章:
0
4 [報(bào)告]
發(fā)表于 2006-02-19 17:49 |只看該作者
那個宏定義在asm-offsets.c中,這個.c文件根本就不是用來編譯運(yùn)行的,只是在編譯內(nèi)核的時候,用它生成一個asm-offsets.s文件,然后使用一個腳本將這個asm-offsets.s再轉(zhuǎn)換為asm-offsets.h。這個頭文件遵循匯編語法,用來被匯編文件include的。
詳見下面的東東:
http://marc.theaimsgroup.com/?l= ... 19616028442&w=2

[ 本帖最后由 藍(lán)白725 于 2006-2-19 17:55 編輯 ]

論壇徽章:
0
5 [報(bào)告]
發(fā)表于 2006-02-19 18:01 |只看該作者
原帖由 藍(lán)白725 于 2006-2-19 17:49 發(fā)表
那個宏定義在asm-offsets.c中,這個.c文件根本就不是用來編譯運(yùn)行的,只是在編譯內(nèi)核的時候,用它生成一個asm-offsets.s文件,然后使用一個腳本將這個asm-offsets.s再轉(zhuǎn)換為asm-offsets.h。這個頭文件遵循匯編語法 ...


呵呵就為這個回復(fù),這個貼設(shè)為保留!
順便把藍(lán)白兄的鏈接轉(zhuǎn)過來:

[prev in list] [next in list] [prev in thread] [next in thread]

List:       linux-kernel
Subject:    [RFC] Standard way of generating assembler offsets
From:       Keith Owens <kaos () ocs ! com ! au>
Date:       2001-10-04 11:47:08
[Download message RAW]

Almost every architecture generates Assembler values to map the offsets
of fields in C structures, about the only exception is i386 and that is
because its offsets are hard coded into entry.S.  Every arch has done
it differently, none of them have got it exactly right.

As part of kbuild 2.5 I am standardizing on one method for generating
Assembler offsets.  This change is required for kbuild 2.5 but it can
be added to 2.4 without disturbing the current kbuild, I want to do
this gradually now instead of a single massive change in kernel 2.5.  I
will be issuing per architecture changes for generating Assembler
offsets against 2.4.

The kbuild 2.5 method for generating Assembler offsets satisfies these
requirements:

* No manual intervention required.  Many architectures rely on users
  running make dep after changing config options that affect the
  Assembler offsets.  If the user forgets to run make dep then the C
  and Assembler code is out of sync - totally unacceptable.  This is
  completely fixed in kbuild 2.5; I cannot do a complete fix in kbuild
  2.4 but it is still better than the existing manual system.

* Standard name for the related files.  There are 6+ different names
  for the files used to generate Assembler offsets, kbuild 2.5 uses
  asm-offsets.[csh] on all architectures.

* Allows for multiple parallel compiles from the same source tree.
  Writing the generated asm-offsets.h to include/asm is not an option,
  it prevents concurrent compiles.

* The method must work in native and cross compile mode and give
  exactly the same results.  Some 2.4 code only works in native mode,
  some architectures have different methods for native and cross
  compile with different output formats.  Yeuch!

* Standard scripts for generating the output.  Every arch does it
  differently in 2.4, standards are good!

* Correct dependency trees.  Because 2.4 make dep does not scan .S
  files, there is little or no dependency information.  Even if the
  offsets are regenerated, the affected Assembler code does not always
  get rebuilt.  kbuild 2.5 handles dependencies for Assembler as well
  as C; I cannot get kbuild 2.4 perfect but I can improve on the
  existing (or non-existent) 2.4 dependencies.

All architectures will define arch/$(ARCH)/asm-offsets.c.  This has a
standard prologue for the macros that convert offsets to Assembler,
followed by arch specific field references.

arch/$(ARCH)/asm-offsets.s is generated from arch/$(ARCH)/asm-offsets.c
using standard rules, although kbuild 2.4 needs some tweaking.

arch/$(ARCH)/asm-offsets.h is generated from arch/$(ARCH)/asm-offsets.s
by a semi-standard script.  Most of the script is common to all
architectures but the precise format of the Assembler output is arch
specific.

The final result is included in *only* the Assembler programs that need
it, as #include "asm-offsets.h" with -I arch/$(ARCH) in the relevant
Makefiles.  Hard coding relative paths in source files is a pet hate,
use #include "localname.h" and -I instead.  Including the generated
file in C code is not allowed, it severly pollutes the dependency
chain, to the extent that any config change can force a complete
recompile, unacceptable.


Example from i386:

arch/i386/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;
}

asm-offsets.s to asm-offsets.h.

# Convert raw asm offsets into something that can be included as
# assembler definitions.  It converts
#   -> symbol $value source
# into
#   symbol = value /* 0xvalue source */

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("%-20s = %3d\t/* 0x%x\t%s */\n", sym, val, val, $0)
  }
'
echo '#endif'

Generated arch/i386/asm-offsets.h

#ifndef __ASM_OFFSETS_H__
#define __ASM_OFFSETS_H__
/*
* DO NOT MODIFY
*
* This file was generated by arch/i386/Makefile.in.
*
*/

state                =   0      /* 0x0     offsetof(struct task_struct, state) */
flags                =   4      /* 0x4     offsetof(struct task_struct, flags) */
sigpending           =   8      /* 0x8     offsetof(struct task_struct, sigpending) */
addr_limit           =  12      /* 0xc     offsetof(struct task_struct, addr_limit) */
exec_domain          =  16      /* 0x10    offsetof(struct task_struct, exec_domain) */
need_resched         =  20      /* 0x14    offsetof(struct task_struct, need_resched) */
tsk_ptrace           =  24      /* 0x18    offsetof(struct task_struct, ptrace) */
processor            =  52      /* 0x34    offsetof(struct task_struct, processor) */

ENOSYS               =  38      /* 0x26    ENOSYS */
#endif


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[prev in list] [next in list] [prev in thread] [next in thread]


Configure | About MARC | Support MARC | Got a list to add? | Sponsored by 10East and KoreLogic

論壇徽章:
0
6 [報(bào)告]
發(fā)表于 2006-02-19 21:15 |只看該作者
學(xué)習(xí)學(xué)習(xí)

論壇徽章:
0
7 [報(bào)告]
發(fā)表于 2009-02-06 02:13 |只看該作者
tian a

論壇徽章:
1
天蝎座
日期:2013-12-06 18:23:58
8 [報(bào)告]
發(fā)表于 2011-06-13 09:58 |只看該作者
博大精深的內(nèi)核啊,好喜歡!
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP