xref: /linux/arch/riscv/kernel/vmlinux-xip.lds.S (revision c532de5a67a70f8533d495f8f2aaa9a0491c3ad0)
1/* SPDX-License-Identifier: GPL-2.0-only */
2/*
3 * Copyright (C) 2012 Regents of the University of California
4 * Copyright (C) 2017 SiFive
5 * Copyright (C) 2020 Vitaly Wool, Konsulko AB
6 */
7
8#include <asm/pgtable.h>
9#define LOAD_OFFSET KERNEL_LINK_ADDR
10/* No __ro_after_init data in the .rodata section - which will always be ro */
11#define RO_AFTER_INIT_DATA
12
13#include <asm/vmlinux.lds.h>
14#include <asm/page.h>
15#include <asm/cache.h>
16#include <asm/thread_info.h>
17#include <asm/set_memory.h>
18
19OUTPUT_ARCH(riscv)
20ENTRY(_start)
21
22jiffies = jiffies_64;
23
24SECTIONS
25{
26	/* Beginning of code and text segment */
27	. = LOAD_OFFSET;
28	_xiprom = .;
29	_start = .;
30	HEAD_TEXT_SECTION
31	INIT_TEXT_SECTION(PAGE_SIZE)
32	/* we have to discard exit text and such at runtime, not link time */
33	__exittext_begin = .;
34	.exit.text :
35	{
36		EXIT_TEXT
37	}
38	__exittext_end = .;
39
40	.text : {
41		_text = .;
42		_stext = .;
43		TEXT_TEXT
44		SCHED_TEXT
45		LOCK_TEXT
46		KPROBES_TEXT
47		ENTRY_TEXT
48		IRQENTRY_TEXT
49		SOFTIRQENTRY_TEXT
50		_etext = .;
51	}
52	RO_DATA(L1_CACHE_BYTES)
53	.srodata : {
54		*(.srodata*)
55	}
56	.init.rodata : {
57		INIT_SETUP(16)
58		INIT_CALLS
59		CON_INITCALL
60		INIT_RAM_FS
61	}
62	_exiprom = .;			/* End of XIP ROM area */
63
64
65/*
66 * From this point, stuff is considered writable and will be copied to RAM
67 */
68	__data_loc = ALIGN(PAGE_SIZE);		/* location in file */
69	. = ALIGN(SECTION_ALIGN);		/* location in memory */
70
71#undef LOAD_OFFSET
72#define LOAD_OFFSET (KERNEL_LINK_ADDR + _sdata - __data_loc)
73
74	_sdata = .;			/* Start of data section */
75	_data = .;
76	RW_DATA(L1_CACHE_BYTES, PAGE_SIZE, THREAD_SIZE)
77	_edata = .;
78	__start_ro_after_init = .;
79	.data.ro_after_init : AT(ADDR(.data.ro_after_init) - LOAD_OFFSET) {
80		*(.data..ro_after_init)
81	}
82	__end_ro_after_init = .;
83
84	. = ALIGN(PAGE_SIZE);
85	__init_begin = .;
86	.init.data : {
87		INIT_DATA
88	}
89	.exit.data : {
90		EXIT_DATA
91	}
92	. = ALIGN(8);
93	__soc_early_init_table : {
94		__soc_early_init_table_start = .;
95		KEEP(*(__soc_early_init_table))
96		__soc_early_init_table_end = .;
97	}
98	__soc_builtin_dtb_table : {
99		__soc_builtin_dtb_table_start = .;
100		KEEP(*(__soc_builtin_dtb_table))
101		__soc_builtin_dtb_table_end = .;
102	}
103
104	__init_end = .;
105
106	. = ALIGN(16);
107	.xip.traps : {
108		__xip_traps_start = .;
109		*(.xip.traps)
110		__xip_traps_end = .;
111	}
112
113	. = ALIGN(PAGE_SIZE);
114	.sdata : {
115		__global_pointer$ = . + 0x800;
116		*(.sdata*)
117		*(.sbss*)
118	}
119
120	BSS_SECTION(PAGE_SIZE, PAGE_SIZE, 0)
121
122	PERCPU_SECTION(L1_CACHE_BYTES)
123
124	.rel.dyn : AT(ADDR(.rel.dyn) - LOAD_OFFSET) {
125		*(.rel.dyn*)
126	}
127
128	/*
129	 * End of copied data. We need a dummy section to get its LMA.
130	 * Also located before final ALIGN() as trailing padding is not stored
131	 * in the resulting binary file and useless to copy.
132	 */
133	.data.endmark : AT(ADDR(.data.endmark) - LOAD_OFFSET) { }
134	_edata_loc = LOADADDR(.data.endmark);
135
136	. = ALIGN(PAGE_SIZE);
137	_end = .;
138
139	STABS_DEBUG
140	DWARF_DEBUG
141
142	DISCARDS
143}
144