interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / native / boot / image.ld

114 lines · 4843 bytes Raw Blame History
1/* image.ld -- AIENOS C kernel image layout. Linked position independent at
2 * address 0 (ImageBase 0); the PE32+ header for UEFI is emitted here as data,
3 * so file offset == RVA (FileAlignment == SectionAlignment == 4 KiB). The
4 * entry stub applies the R_AARCH64_RELATIVE relocations itself (efi_entry.S),
5 * so the PE base-relocation directory holds one no-op block only: it tells
6 * the firmware the image may be loaded anywhere.
7 *
8 * [0x0000 .head] DOS stub + PE32+ header, padded to 4 KiB
9 * [.text] code (our tables: RX)
10 * [.rodata ...] rodata, relocs, GOT (our tables: RO, XN)
11 * [.data .bss] data, bss (our tables: RW, XN)
12 */
13OUTPUT_FORMAT("elf64-littleaarch64")
14OUTPUT_ARCH(aarch64)
15ENTRY(_start)
16
17SECTIONS
18{
19 . = 0;
20 __image_base = .;
21 .head : {
22 /* IMAGE_DOS_HEADER: "MZ", e_lfanew = 0x40 */
23 SHORT(0x5a4d) . = 0x3c; LONG(0x40)
24 /* PE signature */
25 LONG(0x00004550)
26 /* IMAGE_FILE_HEADER */
27 SHORT(0xaa64) /* Machine: ARM64 */
28 SHORT(2) /* NumberOfSections */
29 LONG(0) LONG(0) LONG(0) /* TimeDateStamp, symbol table, symbols */
30 SHORT(240) /* SizeOfOptionalHeader */
31 SHORT(0x0226) /* EXECUTABLE | LINE_NUMS_STRIPPED | LARGE_ADDRESS | DEBUG_STRIPPED */
32 /* IMAGE_OPTIONAL_HEADER64 */
33 SHORT(0x020b) /* PE32+ */
34 BYTE(2) BYTE(42) /* linker version (binutils 2.42, informational) */
35 LONG(__text_end - __text_start) /* SizeOfCode */
36 LONG(__data_file_end - __data_start) /* SizeOfInitializedData */
37 LONG(__image_end - __data_file_end) /* SizeOfUninitializedData */
38 LONG(_start) /* AddressOfEntryPoint (RVA) */
39 LONG(__text_start) /* BaseOfCode */
40 QUAD(0) /* ImageBase */
41 LONG(0x1000) LONG(0x1000) /* SectionAlignment, FileAlignment */
42 SHORT(0) SHORT(0) SHORT(0) SHORT(0) SHORT(0) SHORT(0) /* OS, image, subsystem versions */
43 LONG(0) /* Win32VersionValue */
44 LONG(__image_end) /* SizeOfImage */
45 LONG(__text_start) /* SizeOfHeaders */
46 LONG(0) /* CheckSum */
47 SHORT(10) /* Subsystem: EFI application */
48 SHORT(0) /* DllCharacteristics */
49 QUAD(0) QUAD(0) QUAD(0) QUAD(0) /* stack/heap reserve/commit */
50 LONG(0) /* LoaderFlags */
51 LONG(16) /* NumberOfRvaAndSizes */
52 QUAD(0) QUAD(0) QUAD(0) QUAD(0) QUAD(0) /* export, import, resource, exception, security */
53 LONG(__pe_reloc) LONG(12) /* base relocation directory */
54 QUAD(0) QUAD(0) QUAD(0) QUAD(0) QUAD(0) QUAD(0) QUAD(0) QUAD(0) QUAD(0) QUAD(0)
55 /* section table: .text */
56 BYTE(0x2e) BYTE(0x74) BYTE(0x65) BYTE(0x78) BYTE(0x74) BYTE(0) BYTE(0) BYTE(0)
57 LONG(__text_end - __text_start) LONG(__text_start)
58 LONG(__text_end - __text_start) LONG(__text_start)
59 LONG(0) LONG(0) SHORT(0) SHORT(0)
60 LONG(0x60000020) /* CODE | EXECUTE | READ */
61 /* section table: .data (rodata, relocs, data; bss as VirtualSize tail) */
62 BYTE(0x2e) BYTE(0x64) BYTE(0x61) BYTE(0x74) BYTE(0x61) BYTE(0) BYTE(0) BYTE(0)
63 LONG(__image_end - __data_start) LONG(__data_start)
64 LONG(__data_file_end - __data_start) LONG(__data_start)
65 LONG(0) LONG(0) SHORT(0) SHORT(0)
66 LONG(0xc0000040) /* INITIALIZED_DATA | READ | WRITE */
67 . = ALIGN(4096);
68 }
69
70 . = ALIGN(4096);
71 __text_start = .;
72 .text : { KEEP(*(.text.entry)) *(.text .text.*) }
73 . = ALIGN(4096);
74 __text_end = .;
75
76 __data_start = .;
77 __ro_start = .;
78 .rodata : {
79 *(.rodata .rodata.*)
80 . = ALIGN(4);
81 /* One base-relocation block with only IMAGE_REL_BASED_ABSOLUTE (no-op)
82 * entries: valid, relocatable, nothing for the firmware to patch. */
83 __pe_reloc = .;
84 LONG(0) LONG(12) SHORT(0) SHORT(0)
85 }
86 . = ALIGN(8);
87 .rela.dyn : { __rela_start = .; *(.rela .rela.*) __rela_end = .; }
88 .dynamic : { *(.dynamic) }
89 .dynsym : { *(.dynsym) }
90 .dynstr : { *(.dynstr) }
91 .hash : { *(.hash) }
92 .gnu.hash : { *(.gnu.hash) }
93 .data.rel.ro : { *(.data.rel.ro .data.rel.ro.*) }
94 .got : { *(.got) *(.got.plt) }
95 . = ALIGN(4096);
96 __ro_end = .;
97
98 __rw_start = .;
99 .data : {
100 *(.data .data.*)
101 . = ALIGN(4096);
102 }
103 __data_file_end = .;
104 .bss (NOLOAD) : ALIGN(16) {
105 __bss_start = .;
106 *(.bss .bss.*) *(COMMON)
107 . = ALIGN(16);
108 __bss_end = .;
109 }
110 . = ALIGN(4096);
111 __image_end = .;
112
113 /DISCARD/ : { *(.interp) *(.comment) *(.note*) *(.eh_frame*) *(.plt) }
114}