kernel.ld 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. KERN_LOAD_ADDR = 0xffffffff00000000;
  10. SECTIONS
  11. {
  12. /* Entry Linked and loaded at 0x81810000 */
  13. . = 0x81810000;
  14. .bootstrap : {
  15. *(.boottext .bootdata)
  16. }
  17. /* Link the main kernel for the space after entry + KERN_LOAD_ADDR. We'll
  18. * still load it adjacent in physical memory */
  19. . += KERN_LOAD_ADDR;
  20. .text : AT(ADDR(.text) - KERN_LOAD_ADDR) {
  21. *(.text .stub .text.* .gnu.linkonce.t.*)
  22. }
  23. PROVIDE(etext = .); /* Define the 'etext' symbol to this value */
  24. /* Linker-made tables. Our tables (e.g. devtab) are 2^6 aligned,
  25. * independently of us aligning '.'. We align '.' to get the right start,
  26. * e.g. __devtabstart. */
  27. . = ALIGN(64);
  28. /* We shouldn't have to use PROVIDE, but if we don't, we get the wrong
  29. * value for '.'. And items with empty tables get the KLA (basically 0) */
  30. PROVIDE(__devtabstart = .);
  31. PROVIDE(devtab = .);
  32. .devtab : {
  33. *(.devtab)
  34. }
  35. PROVIDE(__devtabend = .);
  36. .rodata : {
  37. *(.rodata .rodata.* .gnu.linkonce.r.*)
  38. }
  39. /* TODO: add some debug info. i hear stabs are 32 bit only, so we'll need
  40. * to bring in some dwarves. for now, hack in the symbols to compile. */
  41. PROVIDE(__STAB_BEGIN__ = .);
  42. PROVIDE(__STAB_END__ = .);
  43. PROVIDE(__STABSTR_BEGIN__ = .);
  44. PROVIDE(__STABSTR_END__ = .);
  45. /* Adjust the address for the data segment to the next page */
  46. . = ALIGN(0x1000);
  47. /* The data segment */
  48. .data : {
  49. *(.data)
  50. }
  51. PROVIDE(edata = .);
  52. .bss : {
  53. *(.bss)
  54. *(COMMON)
  55. }
  56. PROVIDE(end = .);
  57. /DISCARD/ : {
  58. *(.eh_frame .note.GNU-stack)
  59. }
  60. }