OUTPUT_FORMAT(elf32-i386)
ENTRY(_start)

PHDRS
{
    text_s2   PT_LOAD    FLAGS(0x05);
    rodata_s2 PT_LOAD    FLAGS(0x04);
    data_s2   PT_LOAD    FLAGS(0x06);
    text_s3   PT_LOAD    FLAGS(0x05);
    rodata_s3 PT_LOAD    FLAGS(0x04);
    data_s3   PT_LOAD    FLAGS(0x06);
}

SECTIONS
{
    . = 0xf000;

    .text.stage2 : {
        *(.entry)
        *(.realmode)
        *.s2.o(.text .text.*)
    } :text_s2

    .rodata.stage2 : {
        *.s2.o(.rodata .rodata.*)

        build_id_s2 = .;
        KEEP(*build-id.s2.o(*))

#ifdef LINKER_STAGE2ONLY
        /* stage2 missing symbols overrides */
        stage2_map = .;
        stage3_common = .;
        build_id_s3 = .;
        full_map = .;
        getchar = .;
        menu = .;
        booting_from_editor = .;
        flanterm_write = .;
        term_backend = .;
        term_fallback = .;
        term_notready = .;
        terms = .;
        terms_i = .;
        usec_at_bootloader_entry = .;
        serial_out = .;
        stage3_addr = .;
#else
#ifdef LINKER_NOS2MAP
        stage2_map = .;
#else
        *(.stage2_map)
#endif
#endif
    } :rodata_s2

    .data.stage2 : {
        s2_data_begin = .;
        *.s2.o(.data .data.*)
        s2_data_end = .;
    } :data_s2

    .no_unwind.stage2 : {
        *.s2.o(.no_unwind)
    } :data_s2

#ifndef LINKER_STAGE2ONLY
    .text.stage3 : {
        stage3_addr = .;
        *(.text .text.*)
    } :text_s3

    .rodata.stage3 : {
        *(.rodata .rodata.*)

        build_id_s3 = .;
        KEEP(*build-id.s3.o(*))

#ifdef LINKER_NOMAP
        full_map = .;
#else
        *(.full_map)
#endif
    } :rodata_s3

    .data.stage3 : {
        data_begin = .;
        *(.data .data.*)
        data_end = .;
    } :data_s3

    .no_unwind.stage3 : {
        *(.no_unwind)
    } :data_s3
#endif

    .note.gnu.build-id : {
        *(.note.gnu.build-id)
        limine_bios_sys_size = . - 0xf000;
    } :data_s3

    .bss : {
        bss_begin = .;
        *(.bss .bss.*)
        *(COMMON)
        bss_end = .;
    } :data_s3

    /DISCARD/ : {
        *(.eh_frame*)
        *(.note .note.*)
    }
}
