kernel.ld 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. OUTPUT_FORMAT(elf64-x86-64)
  2. MEMORY
  3. {
  4. MBR (wx) : org = 0x0e00, l = 512
  5. STAGE1 (wx) : org = 0x1000, l = 4K
  6. PHYMEM (w) : org = 0xffffff0000000000, len = 512 * 1024M
  7. PARRAY (w) : org = 0xffffff8000000000, len = 128 * 1024M
  8. KBSS (w) : org = 0xffffffffc0200000, len = 2M
  9. KIMAGE (wx) : org = 0xffffffffffc00000, len = 2M
  10. }
  11. SECTIONS
  12. {
  13. .mbr : AT(0)
  14. {
  15. KEEP(*(.mbr));
  16. . = 446;
  17. BYTE(0x00);
  18. . = 510;
  19. BYTE(0x55);
  20. BYTE(0xaa);
  21. } > MBR
  22. .stage1 : AT(LOADADDR(.mbr) + SIZEOF(.mbr))
  23. {
  24. *(.stage1)
  25. . = ALIGN(0x1000);
  26. } > STAGE1
  27. .text :
  28. AT(LOADADDR(.stage1) + SIZEOF(.stage1))
  29. {
  30. TEXT_START = .;
  31. *(.text)
  32. *(.text*)
  33. . = ALIGN(0x1000);
  34. TEXT_END = .;
  35. } > KIMAGE
  36. .rodata :
  37. AT(LOADADDR(.text) + SIZEOF(.text))
  38. {
  39. RODATA_START = .;
  40. *(.rodata)
  41. *(.rodata*)
  42. . = ALIGN(16);
  43. start_ctors = .;
  44. KEEP(*(.init_array));
  45. KEEP(*(SORT_BY_INIT_PRIORITY(.init_array*)));
  46. KEEP(*(.ctors));
  47. KEEP(*(SORT_BY_INIT_PRIORITY(.ctors*)));
  48. end_ctors = .;
  49. . = ALIGN(16);
  50. FIX_START = .;
  51. KEEP(*(.fix));
  52. FIX_END = .;
  53. . = ALIGN(16);
  54. BSS_ADDR = .;
  55. QUAD(ABSOLUTE(BSS_START));
  56. BSS_LENGTH = .;
  57. QUAD(BSS_END - BSS_START);
  58. . = ALIGN(0x1000);
  59. RODATA_END = .;
  60. } > KIMAGE
  61. .data :
  62. AT(LOADADDR(.rodata) + SIZEOF(.rodata))
  63. {
  64. DATA_START = .;
  65. *(.data)
  66. *(.data*)
  67. *(.got)
  68. *(.got.plt)
  69. . = . + 4;
  70. . = ALIGN(0x1000) - 4;
  71. LONG(KERNEL_MAGIC);
  72. DATA_END = .;
  73. KIMAGE_END = .;
  74. } > KIMAGE
  75. .bss :
  76. {
  77. BSS_START = .;
  78. *(.bss)
  79. *(.bss*)
  80. . = ALIGN(0x1000);
  81. BSS_END = .;
  82. } > KBSS
  83. KIMAGE_PAGES = (KIMAGE_END - KIMAGE_START) / 0x1000;
  84. BSS_PAGES = (BSS_END - BSS_START) / 0x1000;
  85. KERNEL_MAGIC = 0x01145140;
  86. KIMAGE_32K_COUNT = ((KIMAGE_END - KIMAGE_START) + 32 * 1024 - 1) / (32 * 1024);
  87. .eh_frame :
  88. AT(LOADADDR(.data) + SIZEOF(.data))
  89. {
  90. KEEP(*(.eh_frame*))
  91. . = ALIGN(0x1000);
  92. } > KIMAGE
  93. /* Stabs debugging sections. */
  94. .stab 0 : { *(.stab) }
  95. .stabstr 0 : { *(.stabstr) }
  96. .stab.excl 0 : { *(.stab.excl) }
  97. .stab.exclstr 0 : { *(.stab.exclstr) }
  98. .stab.index 0 : { *(.stab.index) }
  99. .stab.indexstr 0 : { *(.stab.indexstr) }
  100. .comment 0 : { *(.comment) }
  101. /* DWARF debug sections.
  102. Symbols in the DWARF debugging sections are relative to the beginning
  103. of the section so we begin them at 0. */
  104. /* DWARF 1 */
  105. .debug 0 : { *(.debug) }
  106. .line 0 : { *(.line) }
  107. /* GNU DWARF 1 extensions */
  108. .debug_srcinfo 0 : { *(.debug_srcinfo) }
  109. .debug_sfnames 0 : { *(.debug_sfnames) }
  110. /* DWARF 1.1 and DWARF 2 */
  111. .debug_aranges 0 : { *(.debug_aranges) }
  112. .debug_pubnames 0 : { *(.debug_pubnames) }
  113. /* DWARF 2 */
  114. .debug_info 0 : { *(.debug_info) }
  115. .debug_abbrev 0 : { *(.debug_abbrev) }
  116. .debug_line 0 : { *(.debug_line) }
  117. .debug_frame 0 : { *(.debug_frame) }
  118. .debug_str 0 : { *(.debug_str) }
  119. .debug_loc 0 : { *(.debug_loc) }
  120. .debug_macinfo 0 : { *(.debug_macinfo) }
  121. /* SGI/MIPS DWARF 2 extensions */
  122. .debug_weaknames 0 : { *(.debug_weaknames) }
  123. .debug_funcnames 0 : { *(.debug_funcnames) }
  124. .debug_typenames 0 : { *(.debug_typenames) }
  125. .debug_varnames 0 : { *(.debug_varnames) }
  126. /* DWARF Other */
  127. .debug_ranges 0 : { *(.debug_ranges) }
  128. .debug_line_str 0 : { *(.debug_line_str) }
  129. /* Rust stuff */
  130. /DISCARD/ :
  131. {
  132. *(.fini_array*)
  133. *(.note*)
  134. *(.dtors*)
  135. *(.debug_gdb_scripts*)
  136. }
  137. }