|
| 1 | +OUTPUT_FORMAT("elf32-littlearm") |
| 2 | +ENTRY(_boot) |
| 3 | + |
| 4 | +/* |
| 5 | + * PROVIDE() is used here so that users can override default values. |
| 6 | + * This is intended to give developers the option to use this Rust |
| 7 | + * target even if the default values in this linker script aren't |
| 8 | + * suitable for their needs. |
| 9 | + * |
| 10 | + * For example: `-C link-arg=--defsym=__stack_length=8M` could |
| 11 | + * be used to increase the stack size above the value set in this |
| 12 | + * file. |
| 13 | + */ |
| 14 | + |
| 15 | +PROVIDE(__vcodesig_magic = 0x35585658); /* XVX5 */ |
| 16 | +PROVIDE(__vcodesig_type = 0); /* V5_SIG_TYPE_USER */ |
| 17 | +PROVIDE(__vcodesig_owner = 2); /* V5_SIG_OWNER_PARTNER */ |
| 18 | +PROVIDE(__vcodesig_options = 0); /* none (0) */ |
| 19 | + |
| 20 | +PROVIDE(__user_ram_start = 0x03800000); |
| 21 | +PROVIDE(__user_ram_length = 48M); |
| 22 | +PROVIDE(__user_ram_end = __user_ram_start + __user_ram_length); /* 0x8000000 */ |
| 23 | + |
| 24 | +PROVIDE(__code_signature_length = 0x20); |
| 25 | + |
| 26 | +PROVIDE(__stack_length = 4M); |
| 27 | +PROVIDE(__heap_end = __user_ram_end - __stack_length); |
| 28 | +PROVIDE(__user_length = __heap_start - __user_ram_start); |
| 29 | + |
| 30 | +MEMORY { |
| 31 | + USER_RAM (RWX) : ORIGIN = __user_ram_start, LENGTH = __user_ram_length |
| 32 | +} |
| 33 | + |
| 34 | +SECTIONS { |
| 35 | + /* |
| 36 | + * VEXos expects program binaries to have a 32-byte header called a "code signature" |
| 37 | + * at their start which tells the OS that we are a valid program and configures some |
| 38 | + * miscellaneous startup behavior. |
| 39 | + */ |
| 40 | + .code_signature : { |
| 41 | + LONG(__vcodesig_magic) |
| 42 | + LONG(__vcodesig_type) |
| 43 | + LONG(__vcodesig_owner) |
| 44 | + LONG(__vcodesig_options) |
| 45 | + |
| 46 | + FILL(0) |
| 47 | + . = __user_ram_start + __code_signature_length; |
| 48 | + } > USER_RAM |
| 49 | + |
| 50 | + /* |
| 51 | + * Executable program instructions. |
| 52 | + */ |
| 53 | + .text : { |
| 54 | + /* _boot routine (entry point from VEXos, must be at 0x03800020) */ |
| 55 | + *(.boot) |
| 56 | + |
| 57 | + /* The rest of the program. */ |
| 58 | + *(.text .text.*) |
| 59 | + } > USER_RAM |
| 60 | + |
| 61 | + /* |
| 62 | + * Global/uninitialized/static/constant data sections. |
| 63 | + */ |
| 64 | + .rodata : { |
| 65 | + *(.rodata .rodata1 .rodata.*) |
| 66 | + *(.srodata .srodata.*) |
| 67 | + } > USER_RAM |
| 68 | + |
| 69 | + /* |
| 70 | + * ARM Stack Unwinding Sections |
| 71 | + * |
| 72 | + * These sections are added by the compiler in some cases to facilitate stack unwinding. |
| 73 | + * __eh_frame_start and similar symbols are used by libunwind. |
| 74 | + */ |
| 75 | + |
| 76 | + .except_ordered : { |
| 77 | + PROVIDE(__extab_start = .); |
| 78 | + *(.gcc_except_table *.gcc_except_table.*) |
| 79 | + *(.ARM.extab*) |
| 80 | + PROVIDE(__extab_end = .); |
| 81 | + } > USER_RAM |
| 82 | + |
| 83 | + .eh_frame_hdr : { |
| 84 | + /* see https://github.com/llvm/llvm-project/blob/main/libunwind/src/AddressSpace.hpp#L78 */ |
| 85 | + PROVIDE(__eh_frame_hdr_start = .); |
| 86 | + KEEP(*(.eh_frame_hdr)) |
| 87 | + PROVIDE(__eh_frame_hdr_end = .); |
| 88 | + } > USER_RAM |
| 89 | + |
| 90 | + .eh_frame : { |
| 91 | + PROVIDE(__eh_frame_start = .); |
| 92 | + KEEP(*(.eh_frame)) |
| 93 | + PROVIDE(__eh_frame_end = .); |
| 94 | + } > USER_RAM |
| 95 | + |
| 96 | + .except_unordered : { |
| 97 | + PROVIDE(__exidx_start = .); |
| 98 | + *(.ARM.exidx*) |
| 99 | + PROVIDE(__exidx_end = .); |
| 100 | + } > USER_RAM |
| 101 | + |
| 102 | + /* -- Data intended to be mutable at runtime begins here. -- */ |
| 103 | + |
| 104 | + .data : { |
| 105 | + *(.data .data1 .data.*) |
| 106 | + *(.sdata .sdata.* .sdata2.*) |
| 107 | + } > USER_RAM |
| 108 | + |
| 109 | + /* -- End of loadable sections - anything beyond this point shouldn't go in the binary uploaded to the device. -- */ |
| 110 | + |
| 111 | + .bss (NOLOAD) : { |
| 112 | + __bss_start = .; |
| 113 | + *(.sbss*) |
| 114 | + *(.bss .bss.*) |
| 115 | + |
| 116 | + /* Align the heap */ |
| 117 | + . = ALIGN(8); |
| 118 | + __bss_end = .; |
| 119 | + } > USER_RAM |
| 120 | + |
| 121 | + /* |
| 122 | + * Active memory sections for the stack/heap. |
| 123 | + * |
| 124 | + * Because these are (NOLOAD), they will not influence the final size of the binary. |
| 125 | + */ |
| 126 | + .heap (NOLOAD) : { |
| 127 | + __heap_start = .; |
| 128 | + . = __heap_end; |
| 129 | + } > USER_RAM |
| 130 | + |
| 131 | + .stack (NOLOAD) : ALIGN(8) { |
| 132 | + __stack_bottom = .; |
| 133 | + . += __stack_length; |
| 134 | + __stack_top = .; |
| 135 | + } > USER_RAM |
| 136 | + |
| 137 | + /* |
| 138 | + * `.ARM.attributes` contains arch metadata for compatibility purposes, but we |
| 139 | + * only target one hardware configuration, meaning it'd just take up space. |
| 140 | + */ |
| 141 | + /DISCARD/ : { |
| 142 | + *(.ARM.attributes*) |
| 143 | + } |
| 144 | +} |
0 commit comments