kernel.ld 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* Simple linker script for the ROS kernel.
  2. See the GNU ld 'info' manual ("info ld") to learn the syntax. */
  3. /* This script needs to be invoked with -z max-page-size=0x1000. Otherwise,
  4. * ld will offset our first section to 1MB within the actual file. Multiboot
  5. * requires the header to be in the first two pages. */
  6. OUTPUT_ARCH("riscv")
  7. /*OUTPUT_FORMAT("elf64-littleriscv", "elf64-x86-64", "elf64-x86-64") */
  8. ENTRY(main)
  9. /* start the kernel at 0x110000.
  10. * That way we can use lower ram for critical structures
  11. */
  12. KERN_LOAD_ADDR = 0xffffffff80000000;
  13. SECTIONS
  14. {
  15. /* Entry Linked and loaded at 0x00100000 (includes multiboot) */
  16. . = 0x00110000;
  17. .bootstrap : {
  18. *(.boottext .bootdata)
  19. }
  20. /* Link the main kernel for the space after entry + KERN_LOAD_ADDR. We'll
  21. * still load it adjacent in physical memory */
  22. . += KERN_LOAD_ADDR;
  23. .text : AT(ADDR(.text) - KERN_LOAD_ADDR) {
  24. *(.text .stub .text.* .gnu.linkonce.t.*)
  25. }
  26. PROVIDE(etext = .); /* Define the 'etext' symbol to this value */
  27. /* Linker-made tables. Our tables (e.g. devtab) are 2^6 aligned,
  28. * independently of us aligning '.'. We align '.' to get the right start,
  29. * e.g. __devtabstart. */
  30. . = ALIGN(64);
  31. /* We shouldn't have to use PROVIDE, but if we don't, we get the wrong
  32. * value for '.'. And items with empty tables get the KLA (basically 0) */
  33. PROVIDE(__devtabstart = .);
  34. PROVIDE(devtab = .);
  35. .devtab : {
  36. *(.devtab)
  37. }
  38. PROVIDE(__devtabend = .);
  39. .rodata : {
  40. *(.rodata .rodata.* .gnu.linkonce.r.*)
  41. }
  42. /* TODO: add some debug info. i hear stabs are 32 bit only, so we'll need
  43. * to bring in some dwarves. for now, hack in the symbols to compile. */
  44. PROVIDE(__STAB_BEGIN__ = .);
  45. PROVIDE(__STAB_END__ = .);
  46. PROVIDE(__STABSTR_BEGIN__ = .);
  47. PROVIDE(__STABSTR_END__ = .);
  48. /* Adjust the address for the data segment to the next page */
  49. . = ALIGN(0x1000);
  50. /* The data segment */
  51. .data : {
  52. *(.data)
  53. }
  54. PROVIDE(edata = .);
  55. .bss : {
  56. *(.bss)
  57. *(COMMON)
  58. }
  59. PROVIDE(end = .);
  60. /DISCARD/ : {
  61. *(.eh_frame .note.GNU-stack)
  62. }
  63. }