141 lines
3.7 KiB
Plaintext
141 lines
3.7 KiB
Plaintext
/* Tell the linker that we want an x86_64 ELF64 output file */
|
|
OUTPUT_FORMAT(elf64-x86-64)
|
|
OUTPUT_ARCH(i386:x86-64)
|
|
|
|
/* Entry points */
|
|
ENTRY(start)
|
|
|
|
/* Define the program headers we want in our final kernel executable */
|
|
PHDRS
|
|
{
|
|
boot PT_LOAD FLAGS((1 << 0) | (1 << 2)) ; /* Execute + Read */
|
|
text PT_LOAD FLAGS((1 << 0) | (1 << 2)) ; /* Execute + Read */
|
|
rodata PT_LOAD FLAGS((1 << 2)) ; /* Read only */
|
|
data PT_LOAD FLAGS((1 << 1) | (1 << 2)) ; /* Write + Read */
|
|
}
|
|
|
|
/* The kernel is linked to run at -2GB (KERNEL_BASE) */
|
|
KERNEL_BASE = 0xFFFFFFFF80000000;
|
|
|
|
SECTIONS
|
|
{
|
|
/* For BIOS boot, start at 1MB physical */
|
|
. = 1M;
|
|
|
|
.boot : {
|
|
/* BIOS boot sections */
|
|
KEEP(*(.multiboot)) /* Multiboot header */
|
|
*(.boottext) /* BIOS boot code */
|
|
*(.boottext.*)
|
|
|
|
/* UEFI boot sections */
|
|
KEEP(*(.pe_header)) /* PE/COFF header for UEFI */
|
|
*(.efi.header) /* EFI header */
|
|
. = ALIGN(4K);
|
|
*(.efi.text) /* UEFI boot code */
|
|
*(.efi.text.*)
|
|
*(.efi.data) /* UEFI data */
|
|
*(.efi.data.*)
|
|
} :boot
|
|
|
|
/* Switch to higher half for kernel proper */
|
|
. += KERNEL_BASE;
|
|
|
|
/* Code section */
|
|
.text : AT(ADDR(.text) - KERNEL_BASE) {
|
|
_text_start = .;
|
|
*(.text)
|
|
*(.text.*)
|
|
. = ALIGN(4K);
|
|
_text_end = .;
|
|
} :text
|
|
|
|
/* Read-only data */
|
|
.rodata : AT(ADDR(.rodata) - KERNEL_BASE) {
|
|
_rodata_start = .;
|
|
*(.rodata)
|
|
*(.rodata.*)
|
|
. = ALIGN(4K);
|
|
_rodata_end = .;
|
|
} :rodata
|
|
|
|
/* Read-write data (initialized) */
|
|
.data : AT(ADDR(.data) - KERNEL_BASE) {
|
|
_data_start = .;
|
|
*(.data)
|
|
*(.data.*)
|
|
*(.got)
|
|
*(.got.*)
|
|
. = ALIGN(4K);
|
|
_data_end = .;
|
|
} :data
|
|
|
|
/* Read-write data (uninitialized) */
|
|
.bss : AT(ADDR(.bss) - KERNEL_BASE) {
|
|
_bss_start = .;
|
|
*(COMMON)
|
|
*(.bss)
|
|
*(.bss.*)
|
|
. = ALIGN(4K);
|
|
_bss_end = .;
|
|
} :data
|
|
|
|
/* Page-aligned data structures */
|
|
.padata ALIGN(4K) : AT(ADDR(.padata) - KERNEL_BASE) {
|
|
*(.padata)
|
|
} :data
|
|
|
|
/* Initial stack space */
|
|
.stack ALIGN(4K) : AT(ADDR(.stack) - KERNEL_BASE) {
|
|
*(.stack)
|
|
} :data
|
|
|
|
/* Thread-local storage */
|
|
.tdata ALIGN(4K) : AT(ADDR(.tdata) - KERNEL_BASE) {
|
|
_tdata_start = .;
|
|
*(.tdata)
|
|
*(.tdata.*)
|
|
. = ALIGN(4K);
|
|
_tdata_end = .;
|
|
} :data
|
|
|
|
.tbss ALIGN(4K) : AT(ADDR(.tbss) - KERNEL_BASE) {
|
|
_tbss_start = .;
|
|
*(.tbss)
|
|
*(.tbss.*)
|
|
. = ALIGN(4K);
|
|
_tbss_end = .;
|
|
} :data
|
|
|
|
/* Debugging information */
|
|
.debug_info 0 : { *(.debug_info) }
|
|
.debug_abbrev 0 : { *(.debug_abbrev) }
|
|
.debug_aranges 0 : { *(.debug_aranges) }
|
|
.debug_ranges 0 : { *(.debug_ranges) }
|
|
.debug_line 0 : { *(.debug_line) }
|
|
.debug_str 0 : { *(.debug_str) }
|
|
.debug_loc 0 : { *(.debug_loc) }
|
|
|
|
/* Discard unused sections */
|
|
/DISCARD/ : {
|
|
*(.eh_frame)
|
|
*(.note.*)
|
|
*(.comment)
|
|
}
|
|
}
|
|
|
|
/* Symbols needed by both BIOS and UEFI boot code */
|
|
PROVIDE(_kernel_start = ADDR(.boot));
|
|
PROVIDE(_kernel_end = ADDR(.tbss) + SIZEOF(.tbss));
|
|
PROVIDE(_kernel_physical_end = ADDR(.tbss) - KERNEL_BASE + SIZEOF(.tbss));
|
|
PROVIDE(_kernel_virtual_base = KERNEL_BASE);
|
|
|
|
/* UEFI-specific symbols */
|
|
PROVIDE(_efi_start = ADDR(.boot));
|
|
PROVIDE(_efi_text_start = ADDR(.efi.text));
|
|
PROVIDE(_efi_text_end = ADDR(.efi.text) + SIZEOF(.efi.text));
|
|
|
|
/* BIOS-specific symbols */
|
|
PROVIDE(_multiboot_start = ADDR(.multiboot));
|
|
PROVIDE(_boottext_start = ADDR(.boottext));
|