The role of __SET_UP during the Linux kernel boot process!

Source: Internet
Author: User

__SET_UP is a macro

#define__setup (str, fn) \__setup_param (str, FN, FN,0)#define__setup_param (str, unique_id, FN, early)Static Char__setup_str_# #unique_id [] __initdata =str; Static structobs_kernel_param __setup_# #unique_id __attribute_used__ __attribute__ (__section__ ( ". Init.setup")) __attribute__ ((Aligned (sizeof(Long)))))            ={__setup_str_# #unique_id, FN, early}structObs_kernel_param {Const Char*str; int(*setup_func) (Char*); intearly;};#define__init __attribute__ ((__section__ (". Init.text")))#define__initdata __attribute__ ((__section__ (". Init.data")))#define__exitdata __attribute__ ((__section__ (". Exit.data")))

Example:

Static int__init Init_setup (Char*str) {unsignedinti; Execute_command=str;  for(i =1; i < Max_init_args; i++) Argv_init[i]=NULL; return 1;} __setup ("init=", init_setup);//converted to    Static Char__setup_str_init_setup[] __attribute__ (__section__ (". Init.data"))) ="init="; Static structobs_kernel_param __setup_init_setup __attribute_used__ __attribute__ (__section__ ( ". Init.setup")) __attribute__ ((Aligned (sizeof(Long)))))            = {__setup_str_init_setup, init_setup,0}
 /*vmlinux.lds in the. Init section
{
...
__setup_start =.;
* (. Init.setup)
__setup_end =.;
...
}*/
Static int__init Obsolete_checksetup (Char*line)/*Handle obsolete-style Parameters*/{ structObs_kernel_param *p; intHad_early_param =0; P=__setup_start; / * From the beginning of the. Init.setup section * / Do { intn = strlen (p->str); / * Calculates the length of the string in the. Init.setup * /if(!STRNCMP (line, p->str, n)) { if(p->early) {/ * Here is the early property of 0 * //*already done in Parse_early_param? * (Needs exact match on param part). * Keep iterating, as we can have early * params and __setups of same names 8 (*/ if(Line[n] = =' /'|| Line[n] = ='=') Had_early_param=1; } Else if(!p->Setup_func) {PRINTK (kern_warning"Parameter%s is obsolete," "ignored\n", p->str); return 1; } Else if(P->setup_func (line +N)) /* Call parameters in the corresponding function, the parameter is offset n (initialization is the length of the parameter) after the string */ return 1; } P++; / * Continue processing until the end * /} while(P <__setup_end); returnHad_early_param;}
Static int__init Init_setup (Char*str) {unsignedinti; Execute_command=str; /** In case LILO was going to boot us with default command line, * it prepends "Auto" before the whole cmdline W     Hich makes * The shell think it should execute a script with such name. * So we ignore all arguments entered _before_ init= ... [MJ]*/     for(i =1; i < Max_init_args; i++) Argv_init[i]=NULL; return 1;}//The function is to pass "=" behind to the Execute_command. //For example, INIT=/LINUXRC is set to execute_command=& "/LINUXRC" is not correct that is the structure of the STR parameter offset n address
Static intNoinline Init_post (void){        ...    if(Ramdisk_execute_command) {run_init_process (Ramdisk_execute_command); PRINTK (kern_warning"Failed to execute%s\n", Ramdisk_execute_command); }        ...    if(Execute_command) {run_init_process (Execute_command); PRINTK (kern_warning"Failed to execute%s. Attempting"                    "defaults...\n", Execute_command); } run_init_process ("/sbin/init"); Run_init_process ("/etc/init"); Run_init_process ("/bin/init"); Run_init_process ("/bin/sh"); Panic ("No Init found. Try passing init= option to kernel.");} 

The role of __SET_UP during the Linux kernel boot process!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.