diff options
| author | Richard Qin <richard.qin.x@gmail.com> | 2026-04-22 18:11:52 +0800 |
|---|---|---|
| committer | Richard Qin <richard.qin.x@gmail.com> | 2026-04-22 18:11:52 +0800 |
| commit | 12cbc1c0cac64f99b3784554eb540b20f33e9f23 (patch) | |
| tree | 0875b9c69a3d3f32c43cabc3d91051c3e461c8f0 /na/include | |
| parent | 3b7d014ad6d5f25de705447e832d7b13b884604e (diff) | |
| download | lume-12cbc1c0cac64f99b3784554eb540b20f33e9f23.tar.gz lume-12cbc1c0cac64f99b3784554eb540b20f33e9f23.tar.xz | |
feat: add linker script and common macros for RISC-V architecture
Diffstat (limited to 'na/include')
| -rw-r--r-- | na/include/lume/lumeos.lds.h | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/na/include/lume/lumeos.lds.h b/na/include/lume/lumeos.lds.h new file mode 100644 index 0000000..b4a8f42 --- /dev/null +++ b/na/include/lume/lumeos.lds.h @@ -0,0 +1,74 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* Copyright (C) 2026 Richard Qin */ + +/* + * Common Linker Script Macros (Machine-Independent) + * + * Shared section definitions that every architecture must emit. + * Architecture-specific lumeos.lds.S files #include this header + * and use these macros to avoid duplicating common boilerplate. + * + * Modeled after Linux include/asm-generic/vmlinux.lds.h + * Reference: docs/specs/linker_and_entry.md + */ + +#ifndef _LUME_LUMEOS_LDS_H +#define _LUME_LUMEOS_LDS_H + +/* ===== Text Section: executable code ===== */ +#define TEXT_SECTION \ + .text : AT(ADDR(.text) - PAGE_OFFSET) { \ + _stext = .; \ + *(.text .text.*) \ + _etext = .; \ + } = 0 + +/* ===== Read-Only Data + C++ init_array ===== */ +#define RODATA_SECTION \ + .rodata : AT(ADDR(.rodata) - PAGE_OFFSET) { \ + _srodata = .; \ + *(.rodata .rodata.*) \ + INIT_ARRAY \ + _erodata = .; \ + } + +/* ===== C++ Global Constructor Table ===== */ +#define INIT_ARRAY \ + . = ALIGN(8); \ + __init_array_start = .; \ + KEEP(*(.init_array .init_array.*)) \ + __init_array_end = .; + +/* ===== Initialized Read-Write Data ===== */ +#define DATA_SECTION \ + .data : AT(ADDR(.data) - PAGE_OFFSET) { \ + _sdata = .; \ + *(.data .data.*) \ + ARCH_DATA_EXTRA \ + _edata = .; \ + } + +/* ===== BSS: Uninitialized Data ===== */ +#define BSS_SECTION \ + .bss : AT(ADDR(.bss) - PAGE_OFFSET) { \ + _sbss = .; \ + *(.bss .bss.*) \ + *(.sbss .sbss.*) \ + ARCH_BSS_EXTRA \ + _ebss = .; \ + } + +/* ===== Discard Unwanted Sections ===== */ +#define DISCARDS \ + /DISCARD/ : { \ + *(.eh_frame .eh_frame_hdr) \ + *(.note .note.*) \ + *(.comment) \ + } + +/* ===== Kernel Image Boundary ===== */ +#define KERNEL_END \ + . = ALIGN(4096); \ + _kernel_end = .; + +#endif /* _LUME_LUMEOS_LDS_H */ |
