blob: ca5218ffa7a5276b12428e65bb6a10d3c6541cb9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
/* Copyright (C) 2026 Richard Qin */
/*
* RISC-V Kernel Linker Script Template
*
* This is a C-preprocessed linker script (.lds.S). The build system
* runs it through CPP to produce the final vmlinux.lds which is
* passed to the linker.
*
* Architecture-specific definitions:
* - OUTPUT_ARCH, ENTRY
* - PAGE_OFFSET, BASE_ADDRESS, PHYS_BASE
* - .head.text placement
* - GP anchor (__global_pointer$ for RISC-V medany)
* - early_pgdir and boot stacks in .bss
*
* Common section macros come from include/lume/vmlinux.lds.h
*
* Reference: docs/specs/linker_and_entry.md
*/
#include <lume/lumeos.lds.h>
/* ===== RISC-V Architecture Constants ===== */
OUTPUT_ARCH(riscv)
PAGE_OFFSET = 0xFFFFFFC000000000;
BASE_ADDRESS = 0xFFFFFFC080200000;
PHYS_BASE = 0x80200000;
ENTRY(_start)
/* ===== RISC-V: GP anchor in .data (medany model) ===== */
#define ARCH_DATA_EXTRA \
. = ALIGN(16); \
PROVIDE(__global_pointer$ = . + 0x800); \
*(.sdata .sdata.*)
/* ===== RISC-V: early page table + per-CPU boot stacks in .bss ===== */
#define ARCH_BSS_EXTRA \
/* Early page table: 4KB aligned, used by entry.S before VMM */ \
. = ALIGN(4096); \
early_pgdir = .; \
. += 4096; \
/* Per-CPU boot stacks: 8KB per CPU, max 8 CPUs */ \
. = ALIGN(4096); \
boot_stack = .; \
. += 8192 * 8; \
boot_stack_top = .;
/* ===== Layout ===== */
SECTIONS {
. = BASE_ADDRESS;
/* .head.text: Image Header (must be at byte 0 of the kernel image) */
.head.text : AT(PHYS_BASE) {
_start = .;
KEEP(*(.head.text))
}
TEXT_SECTION
. = ALIGN(4096);
RODATA_SECTION
. = ALIGN(4096);
RELOC_SECTION
. = ALIGN(4096);
DATA_SECTION
. = ALIGN(4096);
/* End of file-backed image (BSS follows as NOBITS) */
__lume_image_end = .;
BSS_SECTION
KERNEL_END
DISCARDS
}
|