summaryrefslogtreecommitdiff
path: root/kernel/arch/x86_64/linker.ld
blob: ca418bf0b0ab4a0f36a1a8a5be0837d92609409d (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
/*
 * kernel/arch/x86_64/linker.ld
 *
 * Linker script for the x86_64 kernel ELF binary.
 *
 * The kernel is loaded at 0x100000 (1 MiB) physical.
 * Once paging is set up, it will be remapped to higher-half
 * (e.g., 0xFFFFFFFF80000000 or 0xFFFF800000000000).
 *
 * For now we use identity mapping - the EFI loader loads
 * segments at their p_paddr and jumps to e_entry.
 */

ENTRY(_start)

/*
    KERNEL_PHYS_BASE - kernel base address, for x86 it's 1MiB for BIOS data
*/
KERNEL_PHYS_BASE = 0x100000;

SECTIONS
{
    . = KERNEL_PHYS_BASE;

    /* Code */
    .text ALIGN(4K) : {
        __text_start = .;
        *(.text .text.*)
        __text_end = .;
    }

    /* Read-only data */
    .rodata ALIGN(4K) : {
        __rodata_start = .;
        *(.rodata .rodata.*)
        __rodata_end = .;
    }

    /* Initialized data */
    .data ALIGN(4K) : {
        __data_start = .;
        *(.data .data.*)
        __data_end = .;
    }

    /* Uninitialized data (BSS) */
    .bss ALIGN(4K) : {
        __bss_start = .;
        *(.bss .bss.*)
        *(COMMON)
        __bss_end = .;
    }

    __kernel_end = .;

    /* Discard unnecessary sections */
    /DISCARD/ : {
        *(.comment)
        *(.note.*)
        *(.eh_frame*)
    }
}