Linux驱动修炼之道-驱动中一些常见的宏


本文档讲解一下驱动中常用的宏,下边一个一个来说,先声明我使用的内核是Linux2.6.30.4。
Linux在arch/$(ARCH)/kernel/vmlinux.lds中定义了.init段,当内核启动完毕,这个段中的内存会被释放掉供其他使用,vmlinux.lds部分内容如下:

  1. OUTPUT_ARCH(arm)    
  2. ENTRY(stext)    
  3. jiffies = jiffies_64;    
  4. SECTIONS    
  5. {    
  6.  . = 0xC0000000 + 0x00008000;    
  7.  .text.head : {    
  8.   _stext = .;    
  9.   _sinittext = .;    
  10.   *(.text.head)    
  11.  }    
  12.  .init : { /* Init code and data        */    
  13.    *(.init.text) *(.cpuinit.text) *(.meminit.text)    
  14.   _einittext = .;    
  15.   __proc_info_begin = .;    
  16.    *(.proc.info.init)    
  17.   __proc_info_end = .;    
  18.   __arch_info_begin = .;    
  19.    *(.arch.info.init)    
  20.   __arch_info_end = .;    
  21.   __tagtable_begin = .;    
  22.    *(.taglist.init)    
  23.   __tagtable_end = .;    
  24.   . = ALIGN(16);    
  25.   __setup_start = .;    
  26.    *(.init.setup)    
  27.   __setup_end = .;    
  28.   __early_begin = .;    
  29.    *(.early_param.init)    
  30.   __early_end = .;    
  31.   __initcall_start = .;    
  32.    *(.initcallearly.init) __early_initcall_end = .; *(.initcall0.init) *(.initcall0s.init) *(.initcall1.init) *(.initcall1s.init) *(.initcall2.init) *(.initcall2s.init) *(.initcall3.init) *(.initcall3s.init) *(.initcall4.init) *(.initcall4s.init) *(.initcall5.init) *(.initcall5s.init) *(.initcallrootfs.init) *(.initcall6.init) *(.initcall6s.init) *(.initcall7.init) *(.initcall7s.init)    
  33.   __initcall_end = .;    
  34.   __con_initcall_start = .;    
  35.    *(.con_initcall.init)    
  36.   __con_initcall_end = .;    
  37.   __security_initcall_start = .;    
  38.    *(.security_initcall.init)    
  39.   __security_initcall_end = .;    
  40.   . = ALIGN(32);    
  41.   __initramfs_start = .;    
  42.    usr/built-in.o(.init.ramfs)    
  43.   __initramfs_end = .;    
  44.   . = ALIGN(4096);    
  45.   __per_cpu_load = .;    
  46.   __per_cpu_start = .;    
  47.    *(.data.percpu.page_aligned)    
  48.    *(.data.percpu)    
  49.    *(.data.percpu.shared_aligned)    
  50.   __per_cpu_end = .;    
  51.   __init_begin = _stext;    
  52.   *(.init.data) *(.cpuinit.data) *(.cpuinit.rodata) *(.meminit.data) *(.meminit.rodata)    
  53.   . = ALIGN(4096);    
  54.   __init_end = .;    
  55.  }    
  56.  /DISCARD/ : { /* Exit code and data        */    
  57.   *(.exit.text) *(.cpuexit.text) *(.memexit.text)    
  58.   *(.exit.data) *(.cpuexit.data) *(.cpuexit.rodata) *(.memexit.data) *(.memexit.rodata)    
  59.   *(.exitcall.exit)    
  60.   *(.ARM.exidx.exit.text)    
  61.   *(.ARM.extab.exit.text)    
  62.  }    
  63.  .text : { /* Real text segment     */    
  64.   _text = .; /* Text and read-only data */    
  65.    __exception_text_start = .;    
  66.    *(.exception.text)    
  67.    __exception_text_end = .;    
  68.    . = ALIGN(8); *(.text.hot) *(.text) *(.ref.text) *(.devinit.text) *(.devexit.text) *(.text.unlikely)    
  69.    . = ALIGN(8); __sched_text_start = .; *(.sched.text) __sched_text_end = .;    
  70.    . = ALIGN(8); __lock_text_start = .; *(.spinlock.text) __lock_text_end = .;    
  71.    . = ALIGN(8); __kprobes_text_start = .; *(.kprobes.text) __kprobes_text_end = .;    
  72.    *(.fixup)    
  73.    *(.gnu.warning)    
  74.    *(.rodata)    
  75.    *(.rodata.*)    
  76.    *(.glue_7)    
  77.    *(.glue_7t)    
  78.   *(.got) /* Global offset table        */    
  79.  }    
  80.  . = ALIGN((4096)); .rodata : AT(ADDR(.rodata) - 0) { __start_rodata = .; *(.rodata) *(.rodata.*) *(__vermagic) *(__markers_strings) *(__tracepoints_strings) } .rodata1 : AT(ADDR(.rodata1) - 0) { *(.rodata1) } .pci_fixup : AT(ADDR(.pci_fixup) - 0) { __start_pci_fixups_early = .; *(.pci_fixup_early) __end_pci_fixups_early = .; __start_pci_fixups_header = .; *(.pci_fixup_header) __end_pci_fixups_header = .; __start_pci_fixups_final = .; *(.pci_fixup_final) __end_pci_fixups_final = .; __start_pci_fixups_enable = .; *(.pci_fixup_enable) __end_pci_fixups_enable = .; __start_pci_fixups_resume = .; *(.pci_fixup_resume) __end_pci_fixups_resume = .; __start_pci_fixups_resume_early = .; *(.pci_fixup_resume_early) __end_pci_fixups_resume_early = .; __start_pci_fixups_suspend = .; *(.pci_fixup_suspend) __end_pci_fixups_suspend = .; } .builtin_fw : AT(ADDR(.builtin_fw) - 0) { __start_builtin_fw = .; *(.builtin_fw) __end_builtin_fw = .; } .rio_route : AT(ADDR(.rio_route) - 0) { __start_rio_route_ops = .; *(.rio_route_ops) __end_rio_route_ops = .; } __ksymtab : AT(ADDR(__ksymtab) - 0) { __start___ksymtab = .; *(__ksymtab) __stop___ksymtab = .; } __ksymtab_gpl : AT(ADDR(__ksymtab_gpl) - 0) { __start___ksymtab_gpl = .; *(__ksymtab_gpl) __stop___ksymtab_gpl = .; } __ksymtab_unused : AT(ADDR(__ksymtab_unused) - 0) { __start___ksymtab_unused = .; *(__ksymtab_unused) __stop___ksymtab_unused = .; } __ksymtab_unused_gpl : AT(ADDR(__ksymtab_unused_gpl) - 0) { __start___ksymtab_unused_gpl = .; *(__ksymtab_unused_gpl) __stop___ksymtab_unused_gpl = .; } __ksymtab_gpl_future : AT(ADDR(__ksymtab_gpl_future) - 0) { __start___ksymtab_gpl_future = .; *(__ksymtab_gpl_future) __stop___ksymtab_gpl_future = .; } __kcrctab : AT(ADDR(__kcrctab) - 0) { __start___kcrctab = .; *(__kcrctab) __stop___kcrctab = .; } __kcrctab_gpl : AT(ADDR(__kcrctab_gpl) - 0) { __start___kcrctab_gpl = .; *(__kcrctab_gpl) __stop___kcrctab_gpl = .; } __kcrctab_unused : AT(ADDR(__kcrctab_unused) - 0) { __start___kcrctab_unused = .; *(__kcrctab_unused) __stop___kcrctab_unused = .; } __kcrctab_unused_gpl : AT(ADDR(__kcrctab_unused_gpl) - 0) { __start___kcrctab_unused_gpl = .; *(__kcrctab_unused_gpl) __stop___kcrctab_unused_gpl = .; } __kcrctab_gpl_future : AT(ADDR(__kcrctab_gpl_future) - 0) { __start___kcrctab_gpl_future = .; *(__kcrctab_gpl_future) __stop___kcrctab_gpl_future = .; } __ksymtab_strings : AT(ADDR(__ksymtab_strings) - 0) { *(__ksymtab_strings) } __init_rodata : AT(ADDR(__init_rodata) - 0) { *(.ref.rodata) *(.devinit.rodata) *(.devexit.rodata) } __param : AT(ADDR(__param) - 0) { __start___param = .; *(__param) __stop___param = .; . = ALIGN((4096)); __end_rodata = .; } . = ALIGN((4096));    
  81.  _etext = .; /* End of text and rodata section */    
  82.  /*   
  83.      * Stack unwinding tables   
  84.      */    
  85.  . = ALIGN(8);    
  86.  .ARM.unwind_idx : {    
  87.   __start_unwind_idx = .;    
  88.   *(.ARM.exidx*)    
  89.   __stop_unwind_idx = .;    
  90.  }    
  91.  .ARM.unwind_tab : {    
  92.   __start_unwind_tab = .;    
  93.   *(.ARM.extab*)    
  94.   __stop_unwind_tab = .;    
  95.  }    
  96.  . = ALIGN(8192);    
  97.  __data_loc = .;    
  98.  .data : AT(__data_loc) {    
  99.   _data = .; /* address in memory */    
  100.   /*   
  101.          * first, the init task union, aligned   
  102.          * to an 8192 byte boundary.   
  103.          */    
  104.   *(.data.init_task)    
  105.   . = ALIGN(4096);    
  106.   __nosave_begin = .;    
  107.   *(.data.nosave)    
  108.   . = ALIGN(4096);    
  109.   __nosave_end = .;    
  110.   /*   
  111.          * then the cacheline aligned data   
  112.          */    
  113.   . = ALIGN(32);    
  114.   *(.data.cacheline_aligned)    
  115.   /*   
  116.          * The exception fixup table (might need resorting at runtime)   
  117.          */    
  118.   . = ALIGN(32);    
  119.   __start___ex_table = .;    
  120.   *(__ex_table)    
  121.   __stop___ex_table = .;    
  122.   /*   
  123.          * and the usual data section   
  124.          */    
  125.   *(.data) *(.ref.data) *(.devinit.data) *(.devexit.data) . = ALIGN(8); __start___markers = .; *(__markers) __stop___markers = .; . = ALIGN(32); __start___tracepoints = .; *(__tracepoints) __stop___tracepoints = .; . = ALIGN(8); __start___verbose = .; *(__verbose) __stop___verbose = .;    
  126.   CONSTRUCTORS    
  127.   _edata = .;    
  128.  }    
  129.  _edata_loc = __data_loc + SIZEOF(.data);    
  130.  .bss : {    
  131.   __bss_start = .; /* BSS               */    
  132.   *(.bss)    
  133.   *(COMMON)    
  134.   _end = .;    
  135.  }    
  136.      /* Stabs debugging sections.   */    
  137.  .stab 0 : { *(.stab) }    
  138.  .stabstr 0 : { *(.stabstr) }    
  139.  .stab.excl 0 : { *(.stab.excl) }    
  140.  .stab.exclstr 0 : { *(.stab.exclstr) }    
  141.  .stab.index 0 : { *(.stab.index) }    
  142.  .stab.indexstr 0 : { *(.stab.indexstr) }    
  143.  .comment 0 : { *(.comment) }    
  144. }    
  145. /*   
  146.  * These must never be empty   
  147.  * If you have to comment these two assert statements out, your   
  148.  * binutils is too old (for other reasons as well)   
  149.  */    
  150. ASSERT((__proc_info_end - __proc_info_begin), "missing CPU support")    
  151. ASSERT((__arch_info_end - __arch_info_begin), "no machine record defined")  
  • 1
  • 2
  • 下一页

相关内容