1/* 2 * Copyright (c) 2020, 2021 Antony Pavlov <antonynpavlov@gmail.com> 3 * 4 * based on include/arch/sparc/linker.ld 5 * 6 * SPDX-License-Identifier: Apache-2.0 7 */ 8 9/** 10 * @file 11 * @brief Linker command/script file for the MIPS platform 12 */ 13 14#include <zephyr/linker/sections.h> 15#include <zephyr/linker/linker-defs.h> 16#include <zephyr/linker/linker-tool.h> 17 18#define ROMABLE_REGION RAM 19#define RAMABLE_REGION RAM 20 21#define _VECTOR_SECTION_NAME vector 22#define _EXCEPTION_SECTION_NAME exceptions 23#define _RESET_SECTION_NAME reset 24 25MEMORY 26{ 27 RAM (rwx) : ORIGIN = CONFIG_SRAM_BASE_ADDRESS, LENGTH = KB(CONFIG_SRAM_SIZE) 28 /* Used by and documented in include/linker/intlist.ld */ 29 IDT_LIST (wx) : ORIGIN = 0xFFFFF7FF, LENGTH = 2K 30} 31 32REGION_ALIAS("REGION_TEXT", RAM); 33REGION_ALIAS("REGION_RODATA", RAM); 34REGION_ALIAS("REGION_DATA_VMA", RAM); 35REGION_ALIAS("REGION_DATA_LMA", RAM); 36REGION_ALIAS("REGION_BSS", RAM); 37 38ENTRY(CONFIG_KERNEL_ENTRY) 39 40PROVIDE (__memory_base = CONFIG_SRAM_BASE_ADDRESS); 41PROVIDE (__memory_size = CONFIG_SRAM_SIZE * 1024); 42PROVIDE (__stack = CONFIG_SRAM_BASE_ADDRESS + (CONFIG_SRAM_SIZE - 1) * 1024); 43 44SECTIONS 45{ 46 47#include <zephyr/linker/rel-sections.ld> 48 49#ifdef CONFIG_LLEXT 50#include <zephyr/linker/llext-sections.ld> 51#endif 52 53 SECTION_PROLOGUE(_VECTOR_SECTION_NAME,,) 54 { 55 . = ALIGN(0x1000); 56 KEEP(*(.vectors.*)) 57 } GROUP_LINK_IN(ROMABLE_REGION) 58 59 SECTION_PROLOGUE(_RESET_SECTION_NAME,,) 60 { 61 . = ALIGN(0x10); 62 KEEP(*(.reset.*)) 63 } GROUP_LINK_IN(ROMABLE_REGION) 64 65 SECTION_PROLOGUE(_EXCEPTION_SECTION_NAME,,) 66 { 67 . = ALIGN(0x10); 68 KEEP(*(".exception.entry.*")) 69 *(".exception.other.*") 70 } GROUP_LINK_IN(ROMABLE_REGION) 71 72 SECTION_PROLOGUE(_TEXT_SECTION_NAME,,) 73 { 74 . = ALIGN(4); 75 76 *(.text) 77 *(".text.*") 78 } GROUP_LINK_IN(REGION_TEXT) 79 80 __rodata_region_start = .; 81#include <zephyr/linker/common-rom.ld> 82/* Located in generated directory. This file is populated by calling 83 * zephyr_linker_sources(ROM_SECTIONS ...). Useful for grouping iterable RO structs. 84 */ 85#include <snippets-rom-sections.ld> 86#include <zephyr/linker/thread-local-storage.ld> 87 88 SECTION_PROLOGUE(_RODATA_SECTION_NAME,,) 89 { 90 . = ALIGN(8); 91 *(.rodata) 92 *(.rodata.*) 93 *(.gnu.linkonce.r.*) 94 *(.rodata1) 95 96/* Located in generated directory. This file is populated by the 97 * zephyr_linker_sources() Cmake function. 98 */ 99#include <snippets-rodata.ld> 100 101 } GROUP_LINK_IN(REGION_RODATA) 102 103#include <zephyr/linker/cplusplus-rom.ld> 104 __rodata_region_end = .; 105 106 SECTION_PROLOGUE(.plt,,) 107 { 108 *(.plt) 109 } 110 111 SECTION_PROLOGUE(.iplt,,) 112 { 113 *(.iplt) 114 } 115 116 SECTION_DATA_PROLOGUE(_DATA_SECTION_NAME,,) 117 { 118 . = ALIGN(8); 119 _image_ram_start = .; 120 __data_ram_start = .; 121 122 *(.data) 123 *(.data.*) 124 *(.gnu.linkonce.d.*) 125 *(.sdata) 126 *(.sdata.*) 127 . = ALIGN(8); 128 SORT(CONSTRUCTORS) 129 130/* Located in generated directory. This file is populated by the 131 * zephyr_linker_sources() Cmake function. 132 */ 133#include <snippets-rwdata.ld> 134 135 } GROUP_DATA_LINK_IN(REGION_DATA_VMA, REGION_DATA_LMA) 136 137#include <zephyr/linker/common-ram.ld> 138 139/* Located in generated directory. This file is populated by the 140 * zephyr_linker_sources() Cmake function. 141 */ 142#include <snippets-ram-sections.ld> 143 144/* Located in generated directory. This file is populated by the 145 * zephyr_linker_sources() Cmake function. 146 */ 147#include <snippets-data-sections.ld> 148 149 __data_ram_end = .; 150 151 SECTION_DATA_PROLOGUE(_BSS_SECTION_NAME,(NOLOAD),) 152 { 153 /* 154 * For performance, BSS section is assumed to be 4 byte aligned and 155 * a multiple of 4 bytes 156 */ 157 . = ALIGN(4); 158 __bss_start = .; 159 *(.dynbss) 160 *(.sbss) 161 *(.sbss.*) 162 *(.bss) 163 *(.bss.*) 164 *(.gnu.linkonce.b.*) 165 *(.scommon) 166 COMMON_SYMBOLS 167 /* 168 * As memory is cleared in words only, it is simpler to ensure the BSS 169 * section ends on a 4 byte boundary. This wastes a maximum of 3 bytes. 170 */ 171 __bss_end = ALIGN(4); 172 } GROUP_LINK_IN(REGION_BSS) 173 174 SECTION_PROLOGUE(_NOINIT_SECTION_NAME,(NOLOAD),) 175 { 176 /* 177 * This section is used for non-initialized objects that 178 * will not be cleared during the boot process. 179 */ 180 *(.noinit) 181 *(.noinit.*) 182 183/* Located in generated directory. This file is populated by the 184 * zephyr_linker_sources() Cmake function. 185 */ 186#include <snippets-noinit.ld> 187 188 } GROUP_LINK_IN(REGION_BSS) 189 190#include <zephyr/linker/cplusplus-ram.ld> 191 192/* Located in generated directory. This file is populated by the 193 * zephyr_linker_sources() Cmake function. 194 */ 195#include <snippets-sections.ld> 196 197#include <zephyr/linker/ram-end.ld> 198 199 GROUP_END(RAMABLE_REGION) 200 201#include <zephyr/linker/debug-sections.ld> 202 203 .mdebug.abi32 : { 204 KEEP(*(.mdebug.abi32)) 205 } 206 207 SECTION_PROLOGUE(.gnu.attributes, 0,) 208 { 209 KEEP(*(.gnu.attributes)) 210 } 211 212 /DISCARD/ : { 213 *(.MIPS.abiflags) 214 *(.pdr) 215 *(.reginfo) 216 } 217} 218