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/pgtable.h>
16#include <asm/cache.h>
17#include <asm/thread_info.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	.exit.text :
34	{
35		EXIT_TEXT
36	}
37
38	.text : {
39		_text = .;
40		_stext = .;
41		TEXT_TEXT
42		SCHED_TEXT
43		CPUIDLE_TEXT
44		LOCK_TEXT
45		KPROBES_TEXT
46		ENTRY_TEXT
47		IRQENTRY_TEXT
48		SOFTIRQENTRY_TEXT
49		*(.fixup)
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(16);		/* location in file */
69	. = LOAD_OFFSET + XIP_OFFSET;	/* location in memory */
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	PERCPU_SECTION(L1_CACHE_BYTES)
101
102	. = ALIGN(PAGE_SIZE);
103	__init_end = .;
104
105	.sdata : {
106		__global_pointer$ = . + 0x800;
107		*(.sdata*)
108		*(.sbss*)
109	}
110
111	BSS_SECTION(PAGE_SIZE, PAGE_SIZE, 0)
112	EXCEPTION_TABLE(0x10)
113
114	.rel.dyn : AT(ADDR(.rel.dyn) - LOAD_OFFSET) {
115		*(.rel.dyn*)
116	}
117
118	/*
119	 * End of copied data. We need a dummy section to get its LMA.
120	 * Also located before final ALIGN() as trailing padding is not stored
121	 * in the resulting binary file and useless to copy.
122	 */
123	.data.endmark : AT(ADDR(.data.endmark) - LOAD_OFFSET) { }
124	_edata_loc = LOADADDR(.data.endmark);
125
126	. = ALIGN(PAGE_SIZE);
127	_end = .;
128
129	STABS_DEBUG
130	DWARF_DEBUG
131
132	DISCARDS
133}
134