Definition of common macro tag in Linuxi386 + source code

Source: Internet
Author: User
The definition of common macro tag in Linuxi386 + Source Code-Linux general technology-Linux programming and kernel information. The following is a detailed description. These macros include _ init, _ initdata, _ initfunc (), asmlinkage, ENTRY (), and FASTCALL. They are defined mainly in Include \ linux \ linkage. h and include \ asm-i386 \ Init. h and some other. h files.

1) _ init location: include \ asm-i386 \ Init. h

Definition: # define _ init _ attribute _ (_ section _ (". text. init ")))

Note: This identifier is put together with the function declaration, indicating that the gcc compiler needs to put this function during compilation. text. init section, which is released after kernel initialization.

Example: asmlinkage void _ init start_kernel (void ){...}

2) _ initdata

Location: include \ asm-i386 \ Init. h

Definition: # define _ initdata _ attribute _ (_ section _ (". data. init ")))

Note: This identifier is put together with the variable declaration, indicating that the gcc compiler needs to place this variable during compilation. data. init section, which is released after kernel initialization.

Example: static struct kernel_param raw_params [] _ initdata = {....}

3) _ initfunc ()

Location: include \ asm-i386 \ Init. h

Definition: # define _ initfunc (_ arginit )\

_ Arginit _ init ;\

_ Arginit

Note: This macro is used to define a _ init function.

Example: _ initfunc (void mem_init (unsigned long start_mem, unsigned long e

Nd_mem )){....}

4) asmlinkage

Location: Include \ linux \ linkage. h

Definition: # define asmlinkage CPP_ASMLINKAGE _ attribute _ (regparm (0 )))

Note: The flag is put together with the function declaration, which tells the gcc compiler that the function does not need to pass parameters through any registers. The parameters are only transmitted through stacks.

Example: asmlinkage void _ init start_kernel (void ){...}

5) ENTRY ()

Location: Include \ linux \ linkage. h

Definition: # define ENTRY (name )\

. Globl SYMBOL_NAME (name );\

ALIGN ;\

SYMBOL_NAME_LABEL (name)

Note: declare the name as global, alignment, and define it as a label.

Example: ENTRY (swapper_pg_dir)

. Long 0x00102007

. Fill _ USER_PGD_PTRS-1

/* Default: 767 entries */

. Long 0x00102007

/* Default: 255 entries */

. Fill _ KERNEL_PGD_PTRS-1

Equivalent

. Globl swapper_pg_dir

. Align 16, 0x90

/* If iworkflow + */

Swapper_pg_dir:

. Long 0x00102007

. Fill _ USER_PGD_PTRS-1

/* Default: 767 entries */

. Long 0x00102007

/* Default: 255 entries */

. Fill _ KERNEL_PGD_PTRS-1

6) FASTCALL ()

Location: Include \ linux \ kernel. h

Definition: # define FASTCALL (x) x _ attribute _ (regparm (3 )))

Note: This identifier is put together with the function declaration. The attribute declaration with regparm (3) tells the gcc compiler that this function can pass up to three parameters through registers, the three registers are EAX, EDX, and ECX in sequence. More parameters are passed through the stack. In this way, some inbound and outbound stack operations can be reduced, so calling is faster.

Example: extern void FASTCALL (_ switch_to (struct task_struct * prev, struct t

Ask_struct * next ));

In this example, prev is passed through eax and next through edx. ()

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.