xref: /freebsd/usr.sbin/btxld/elfh.c (revision a8445737e740901f5f2c8d24c12ef7fc8b00134e)
1 /*
2  * Copyright (c) 1998 Robert Nordier
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
18  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
19  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
20  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
21  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
23  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
24  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *
26  *	$Id:$
27  */
28 
29 #include <stddef.h>
30 #include "elfh.h"
31 
32 #define SET_ME	0xeeeeeeee    /* filled in by btxld */
33 
34 /*
35  * ELF header template.
36  */
37 const struct elfh elfhdr = {
38     {
39 	{
40 	    ELFMAG0, ELFMAG1, ELFMAG2, ELFMAG3,     /* e_ident */
41 	    ELFCLASS32, ELFDATA2LSB, EV_CURRENT, 0,
42 	    'F', 'r', 'e', 'e', 'B', 'S', 'D', 0
43 	},
44 	ET_EXEC,				    /* e_type */
45 	EM_386, 				    /* e_machine */
46 	EV_CURRENT,				    /* e_version */
47 	SET_ME, 				    /* e_entry */
48 	offsetof(struct elfh, p),		    /* e_phoff */
49 	offsetof(struct elfh, sh),		    /* e_shoff */
50 	0,					    /* e_flags */
51 	sizeof(elfhdr.e),			    /* e_ehsize */
52 	sizeof(elfhdr.p[0]),			    /* e_phentsize */
53 	sizeof(elfhdr.p) / sizeof(elfhdr.p[0]),     /* e_phnum */
54 	sizeof(elfhdr.sh[0]),			    /* e_shentsize */
55 	sizeof(elfhdr.sh) / sizeof(elfhdr.sh[0]),   /* e_shnum */
56 	1					    /* e_shstrndx */
57     },
58     {
59 	{
60 	    PT_LOAD,				    /* p_type */
61 	    sizeof(elfhdr),			    /* p_offset */
62 	    SET_ME,				    /* p_vaddr */
63 	    SET_ME,				    /* p_paddr */
64 	    SET_ME,				    /* p_filesz */
65 	    SET_ME,				    /* p_memsz */
66 	    PF_R | PF_X,			    /* p_flags */
67 	    0x1000				    /* p_align */
68 	},
69 	{
70 	    PT_LOAD,				    /* p_type */
71 	    SET_ME,				    /* p_offset */
72 	    SET_ME,				    /* p_vaddr */
73 	    SET_ME,				    /* p_paddr */
74 	    SET_ME,				    /* p_filesz */
75 	    SET_ME,				    /* p_memsz */
76 	    PF_R | PF_W,			    /* p_flags */
77 	    0x1000				    /* p_align */
78 	}
79     },
80     {
81 	{
82 	    0, SHT_NULL, 0, 0, 0, 0, SHN_UNDEF, 0, 0, 0
83 	},
84 	{
85 	    1,					    /* sh_name */
86 	    SHT_STRTAB, 			    /* sh_type */
87 	    0,					    /* sh_flags */
88 	    0,					    /* sh_addr */
89 	    offsetof(struct elfh, shstrtab),	    /* sh_offset */
90 	    sizeof(elfhdr.shstrtab),		    /* sh_size */
91 	    SHN_UNDEF,				    /* sh_link */
92 	    0,					    /* sh_info */
93 	    1,					    /* sh_addralign */
94 	    0					    /* sh_entsize */
95 	},
96 	{
97 	    0xb,				    /* sh_name */
98 	    SHT_PROGBITS,			    /* sh_type */
99 	    SHF_EXECINSTR | SHF_ALLOC,		    /* sh_flags */
100 	    SET_ME,				    /* sh_addr */
101 	    SET_ME,				    /* sh_offset */
102 	    SET_ME,				    /* sh_size */
103 	    SHN_UNDEF,				    /* sh_link */
104 	    0,					    /* sh_info */
105 	    4,					    /* sh_addralign */
106 	    0					    /* sh_entsize */
107 	},
108 	{
109 	    0x11,				    /* sh_name */
110 	    SHT_PROGBITS,			    /* sh_type */
111 	    SHF_ALLOC | SHF_WRITE,		    /* sh_flags */
112 	    SET_ME,				    /* sh_addr */
113 	    SET_ME,				    /* sh_offset */
114 	    SET_ME,				    /* sh_size */
115 	    SHN_UNDEF,				    /* sh_link */
116 	    0,					    /* sh_info */
117 	    4,					    /* sh_addralign */
118 	    0					    /* sh_entsize */
119 	}
120     },
121     "\0.shstrtab\0.text\0.data" 		    /* shstrtab */
122 };
123