1. system.map分析

 

2.__setup(str, fn)

路径:linux-3.10.x\include\linux\init.h

源码如下

 

/*
* Only for really core code. See moduleparam.h for the normal way.
*
* Force the alignment so the compiler doesn't space elements of the
* obs_kernel_param "array" too far apart in .init.setup.
*/
#define __setup_param(str, unique_id, fn, early) \
static const char __setup_str_##unique_id[] __initconst \
__aligned(1) = str; \
static struct obs_kernel_param __setup_##unique_id \
__used __section(.init.setup) \
__attribute__((aligned((sizeof(long))))) \
= { __setup_str_##unique_id, fn, early }

#define __setup(str, fn) \
__setup_param(str, fn, fn, 0)

 

其中obs_kernel_param如下:

struct obs_kernel_param {
const char *str;
int (*setup_func)(char *);
int early;
};

 

 

 

3.__setup("console=", console_setup)

路径:\linux-3.10.x\kernel\printk.c

展开如下:

 

#define __setup_param("console=", console_setup, console_setup, 0)      \
static const char __setup_str_##console_setup[] __initconst \
__aligned(1) = "console="; \
static struct obs_kernel_param __setup_##console_setup \
__used __section(.init.setup) \ //使用.init.setup保存相应的数据
__attribute__((aligned((sizeof(long))))) \
= { __setup_str_##console_setup, console_setup, 0 }

#define __setup("console=", console_setup) \
__setup_param("console=", console_setup, console_setup, 0) //使用.init.setup保存相应的数据
__attribute__((aligned((sizeof(long))))) \
= { __setup_str_##console_setup, console_setup, 0 }

#define __setup("console=", console_setup) \
__setup_param("console=", console_setup, console_setup, 0)

所以struct obs_kernel_param为

 

 

struct obs_kernel_param {
const char *str=“console”
int (*setup_func)(char *)=console_setup
int early=0
};

 

所以最终会生成__setup_console_setup结构体地址,我们可以通过查看system.map表看到

 

c04373e0 T __setup_start
c04373ec t __setup_init_setup
c04373f8 t __setup_loglevel
c0437404 t __setup_quiet_kernel
......
c0437560 t __setup_console_setup //注意这里
......
c0437788 T __setup_end

 

 

至此,__setup("console=", console_setup)关系已分析完!