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