【问题标题】:Is this any kind of macro in linux kernel code?这是linux内核代码中的任何一种宏吗?
【发布时间】:2012-03-26 16:48:29
【问题描述】:

我在 linux 内核代码 http://gitorious.org/pandroid/kernel-omap/blobs/5ed7607d45b300a37dd13ad1c79adea56f6687ce/arch/arm/mach-omap2/board-omap4panda.c 中发现了这个

MACHINE_START(OMAP4_PANDA, "OMAP4430 Panda Board")
    .phys_io    = 0x48000000,
    .io_pg_offst    = ((0xfa000000) >> 18) & 0xfffc,
    .boot_params    = 0x80000100,
    .map_io     = omap_panda_map_io,
    .init_irq   = omap_panda_init_irq,
    .init_machine   = omap_panda_init,
    .timer      = &omap_timer,
MACHINE_END

我不明白这是什么..?这是宏还是结构还是什么..???

定义说

/*
 * Set of macros to define architecture features.  This is built into
 * a table by the linker.
 */
#define MACHINE_START(_type,_name)          \
static const struct machine_desc __mach_desc_##_type    \
 __used                         \
 __attribute__((__section__(".arch.info.init"))) = {    \
    .nr     = MACH_TYPE_##_type,        \
    .name       = _name,

#define MACHINE_END             \
};

#endif

但我不明白它是如何工作的?

【问题讨论】:

  • 搜索“#define MACHINE_START”需要多长时间?
  • @Damien_The_Unbeliever “大约 19,100 个结果(0.30 秒)”;-))
  • 您应该学习如何获取源代码的预处理形式。将编译命令中的gcc替换为gcc -C -E,即可在stdout上得到预处理后的表单。

标签: c linux linux-kernel


【解决方案1】:

designated structure initialization 是一个 GNU GCC 扩展,如果您习惯于 ANSI C 编译器,它看起来有点奇怪。这与雄心勃勃的宏相结合,使它在许多方面看起来像一门外语。扩展源代码为:

static const struct machine_desc __mach_desc_OMAP4_PANDA
 __used  __attribute__((__section__(".arch.info.init"))) = {
    .nr     = MACH_TYPE_OMAP4_PANDA,
    .name         = "OMAP4430 Panda Board",
    .phys_io      = 0x48000000,
    .io_pg_offst  = ((0xfa000000) >> 18) & 0xfffc,
    .boot_params  = 0x80000100,
    .map_io       = omap_panda_map_io,
    .init_irq     = omap_panda_init_irq,
    .init_machine = omap_panda_init,
    .timer        = &omap_timer,
};

【讨论】:

    【解决方案2】:

    MACHINE_START

    定义为预处理器宏: arch/arm/include/asm/mach/arch.h, line 67

    MACHINE_END

    定义为预处理器宏: arch/arm/include/asm/mach/arch.h, line 74

    我将此站点用于 Linux 内核参考 http://lxr.free-electrons.com/

    【讨论】:

      【解决方案3】:

      这是一个初始化结构对象的指定初始化器。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-11-23
        • 1970-01-01
        • 1970-01-01
        • 2014-05-07
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多