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    SECTION_PROLOGUE(_VECTOR_SECTION_NAME,,)
50    {
51		. = ALIGN(0x1000);
52		KEEP(*(.vectors.*))
53    } GROUP_LINK_IN(ROMABLE_REGION)
54
55    SECTION_PROLOGUE(_RESET_SECTION_NAME,,)
56    {
57		. = ALIGN(0x10);
58		KEEP(*(.reset.*))
59    } GROUP_LINK_IN(ROMABLE_REGION)
60
61    SECTION_PROLOGUE(_EXCEPTION_SECTION_NAME,,)
62    {
63		. = ALIGN(0x10);
64		 KEEP(*(".exception.entry.*"))
65		 *(".exception.other.*")
66    } GROUP_LINK_IN(ROMABLE_REGION)
67
68    SECTION_PROLOGUE(_TEXT_SECTION_NAME,,)
69	{
70		. = ALIGN(4);
71
72		*(.text)
73		*(".text.*")
74	} GROUP_LINK_IN(REGION_TEXT)
75
76    __rodata_region_start = .;
77#include <zephyr/linker/common-rom.ld>
78#include <zephyr/linker/thread-local-storage.ld>
79
80    SECTION_PROLOGUE(_RODATA_SECTION_NAME,,)
81	{
82		 . = ALIGN(8);
83		 *(.rodata)
84		 *(.rodata.*)
85		 *(.gnu.linkonce.r.*)
86		 *(.rodata1)
87
88/* Located in generated directory. This file is populated by the
89 * zephyr_linker_sources() Cmake function.
90 */
91#include <snippets-rodata.ld>
92
93	} GROUP_LINK_IN(REGION_RODATA)
94
95#include <zephyr/linker/cplusplus-rom.ld>
96    __rodata_region_end = .;
97
98    SECTION_PROLOGUE(.plt,,)
99	{
100		*(.plt)
101	}
102
103    SECTION_PROLOGUE(.iplt,,)
104	{
105		*(.iplt)
106	}
107
108    SECTION_DATA_PROLOGUE(_DATA_SECTION_NAME,,)
109	{
110		 . = ALIGN(8);
111		 _image_ram_start = .;
112		 __data_ram_start = .;
113
114		 *(.data)
115		 *(.data.*)
116		 *(.gnu.linkonce.d.*)
117		 *(.sdata)
118		 *(.sdata.*)
119		 . = ALIGN(8);
120		SORT(CONSTRUCTORS)
121
122/* Located in generated directory. This file is populated by the
123 * zephyr_linker_sources() Cmake function.
124 */
125#include <snippets-rwdata.ld>
126
127	} GROUP_DATA_LINK_IN(REGION_DATA_VMA, REGION_DATA_LMA)
128
129#include <zephyr/linker/common-ram.ld>
130
131/* Located in generated directory. This file is populated by the
132 * zephyr_linker_sources() Cmake function.
133 */
134#include <snippets-ram-sections.ld>
135
136/* Located in generated directory. This file is populated by the
137 * zephyr_linker_sources() Cmake function.
138 */
139#include <snippets-data-sections.ld>
140
141    __data_ram_end = .;
142
143    SECTION_DATA_PROLOGUE(_BSS_SECTION_NAME,(NOLOAD),)
144	{
145		/*
146		 * For performance, BSS section is assumed to be 4 byte aligned and
147		 * a multiple of 4 bytes
148		 */
149		 . = ALIGN(4);
150		 __bss_start = .;
151		 *(.dynbss)
152		 *(.sbss)
153		 *(.sbss.*)
154		 *(.bss)
155		 *(.bss.*)
156		 *(.gnu.linkonce.b.*)
157		 *(.scommon)
158		 COMMON_SYMBOLS
159		 /*
160		  * As memory is cleared in words only, it is simpler to ensure the BSS
161		  * section ends on a 4 byte boundary. This wastes a maximum of 3 bytes.
162		  */
163		  __bss_end = ALIGN(4);
164	}  GROUP_LINK_IN(REGION_BSS)
165
166    SECTION_PROLOGUE(_NOINIT_SECTION_NAME,(NOLOAD),)
167	{
168		/*
169		 * This section is used for non-initialized objects that
170		 * will not be cleared during the boot process.
171		 */
172		 *(.noinit)
173		 *(.noinit.*)
174
175/* Located in generated directory. This file is populated by the
176 * zephyr_linker_sources() Cmake function.
177 */
178#include <snippets-noinit.ld>
179
180	} GROUP_LINK_IN(REGION_BSS)
181
182#include <zephyr/linker/cplusplus-ram.ld>
183
184/* Located in generated directory. This file is populated by the
185 * zephyr_linker_sources() Cmake function.
186 */
187#include <snippets-sections.ld>
188
189#include <zephyr/linker/ram-end.ld>
190
191    GROUP_END(RAMABLE_REGION)
192
193#include <zephyr/linker/debug-sections.ld>
194
195	.mdebug.abi32 : {
196		KEEP(*(.mdebug.abi32))
197	}
198
199    SECTION_PROLOGUE(.gnu.attributes, 0,)
200	{
201		KEEP(*(.gnu.attributes))
202	}
203
204	/DISCARD/ : {
205		*(.MIPS.abiflags)
206		*(.pdr)
207		*(.reginfo)
208	}
209}
210