Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. /*
  2. This script is supposed to build an ELF with 2 headers/memory regions.
  3. 1. A RX region starting at address 0, containing .text, .rodata
  4. and the initial values for the .data section.
  5. 2. An empty 128KB RW region starting at address 0x10000 (for .data, .bss and .ram)
  6.  
  7. Observed output:
  8. 2 ELF headers.
  9. - The first contains .text and .rodata
  10. - The second contains .data, .bss and .ram
  11.  
  12. data_load_start has the correct value but the actual data aren't included
  13. in the 1st (ROM) region/header.
  14.  
  15. readelf output:
  16.  
  17. Program Headers:
  18. Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
  19. LOAD 0x000000 0x00000000 0x00000000 0x01c4c 0x01c4c R E 0x1000
  20. LOAD 0x002000 0x00010000 0x00001c4c 0x00040 0x20000 RW 0x1000
  21.  
  22. What I expected is:
  23. - The PhysAddr of the 2nd header should be 0 and FileSiz should be 0.
  24. - The FileSiz and MemSiz of the 1st header should be 0x01c4c + 0x00040 = 0x01c8c
  25. */
  26.  
  27. OUTPUT_ARCH("riscv")
  28.  
  29. ENTRY(_start)
  30.  
  31. entry_point = 0x200;
  32. rom_size = 65536; /* 64k ROM */
  33. ram_size = 131072; /* 128k RAM */
  34. ram_origin = rom_size; /* start immediatelly after the ROM */
  35.  
  36. MEMORY
  37. {
  38. ROM (rx): ORIGIN = entry_point, LENGTH = rom_size - entry_point
  39. RAM (rw): ORIGIN = ram_origin, LENGTH = ram_size
  40. }
  41.  
  42. SECTIONS
  43. {
  44. /* ROM */
  45. . = ORIGIN(ROM);
  46. .text : {
  47. *(.text*)
  48. } > ROM
  49.  
  50. .rodata : {
  51. *(.rodata*)
  52. rodata_end = .;
  53. } > ROM
  54.  
  55. /* RAM */
  56. .data : AT(rodata_end) {
  57. data_load_start = LOADADDR(.data);
  58. data_start = .;
  59. *(.data*)
  60. data_end = .;
  61. } > RAM
  62.  
  63. .bss : {
  64. *(.bss*)
  65. *(COMMON)
  66. } > RAM
  67.  
  68. .ram : {
  69. . = ALIGN(16);
  70. __heap_start = .;
  71. /* TODO: I don't know why I need to subtract 32 but if I don't .ram section doesn't fit in RAM region :| */
  72. /* Probably due to alignment? */
  73. . += ram_size - SIZEOF(.data) - SIZEOF(.bss) - 32;
  74. __stack_top = .;
  75. } > RAM
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement