/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 1998 Robert Nordier4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14*15* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS``AS IS'' AND16* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE17* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR18* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS19* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,20* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT21* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR22* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,23* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE24* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,25* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.26*/2728#include <sys/param.h>29#include <sys/endian.h>3031#include <stddef.h>32#include "elfh.h"3334#define SET_ME 0xeeeeeeee /* filled in by btxld */3536/*37* ELF header template.38*/39const struct elfh elfhdr = {40{41{42ELFMAG0, ELFMAG1, ELFMAG2, ELFMAG3, /* e_ident */43ELFCLASS32, ELFDATA2LSB, EV_CURRENT, 0,44'F', 'r', 'e', 'e', 'B', 'S', 'D', 045},46htole16(ET_EXEC), /* e_type */47htole16(EM_386), /* e_machine */48htole32(EV_CURRENT), /* e_version */49htole32(SET_ME), /* e_entry */50htole32(offsetof(struct elfh, p)), /* e_phoff */51htole32(offsetof(struct elfh, sh)), /* e_shoff */520, /* e_flags */53htole16(sizeof(elfhdr.e)), /* e_ehsize */54htole16(sizeof(elfhdr.p[0])), /* e_phentsize */55htole16(nitems(elfhdr.p)), /* e_phnum */56htole16(sizeof(elfhdr.sh[0])), /* e_shentsize */57htole16(nitems(elfhdr.sh)), /* e_shnum */58htole16(1) /* e_shstrndx */59},60{61{62htole32(PT_LOAD), /* p_type */63htole32(sizeof(elfhdr)), /* p_offset */64htole32(SET_ME), /* p_vaddr */65htole32(SET_ME), /* p_paddr */66htole32(SET_ME), /* p_filesz */67htole32(SET_ME), /* p_memsz */68htole32(PF_R | PF_X), /* p_flags */69htole32(0x1000) /* p_align */70},71{72htole32(PT_LOAD), /* p_type */73htole32(SET_ME), /* p_offset */74htole32(SET_ME), /* p_vaddr */75htole32(SET_ME), /* p_paddr */76htole32(SET_ME), /* p_filesz */77htole32(SET_ME), /* p_memsz */78htole32(PF_R | PF_W), /* p_flags */79htole32(0x1000) /* p_align */80}81},82{83{840, htole32(SHT_NULL), 0, 0, 0, 0, htole32(SHN_UNDEF), 0, 0, 085},86{87htole32(1), /* sh_name */88htole32(SHT_STRTAB), /* sh_type */890, /* sh_flags */900, /* sh_addr */91htole32(offsetof(struct elfh, shstrtab)), /* sh_offset */92htole32(sizeof(elfhdr.shstrtab)), /* sh_size */93htole32(SHN_UNDEF), /* sh_link */940, /* sh_info */95htole32(1), /* sh_addralign */960 /* sh_entsize */97},98{99htole32(0xb), /* sh_name */100htole32(SHT_PROGBITS), /* sh_type */101htole32(SHF_EXECINSTR | SHF_ALLOC), /* sh_flags */102htole32(SET_ME), /* sh_addr */103htole32(SET_ME), /* sh_offset */104htole32(SET_ME), /* sh_size */105htole32(SHN_UNDEF), /* sh_link */1060, /* sh_info */107htole32(4), /* sh_addralign */1080 /* sh_entsize */109},110{111htole32(0x11), /* sh_name */112htole32(SHT_PROGBITS), /* sh_type */113htole32(SHF_ALLOC | SHF_WRITE), /* sh_flags */114htole32(SET_ME), /* sh_addr */115htole32(SET_ME), /* sh_offset */116htole32(SET_ME), /* sh_size */117htole32(SHN_UNDEF), /* sh_link */1180, /* sh_info */119htole32(4), /* sh_addralign */1200 /* sh_entsize */121}122},123"\0.shstrtab\0.text\0.data" /* shstrtab */124};125126127