Initial import from FreeBSD RELENG_4:
[dragonfly.git] / usr.sbin / btxld / elfh.c
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  * $FreeBSD: src/usr.sbin/btxld/elfh.c,v 1.3 2000/01/04 14:10:36 marcel Exp $
27  */
28
29 #include <sys/types.h>
30
31 #include <stddef.h>
32 #include "elfh.h"
33
34 #define SET_ME  0xeeeeeeee    /* filled in by btxld */
35
36 /*
37  * ELF header template.
38  */
39 const struct elfh elfhdr = {
40     {
41         {
42             ELFMAG0, ELFMAG1, ELFMAG2, ELFMAG3,     /* e_ident */
43             ELFCLASS32, ELFDATA2LSB, EV_CURRENT, 0,
44             'F', 'r', 'e', 'e', 'B', 'S', 'D', 0
45         },
46         ET_EXEC,                                    /* e_type */
47         EM_386,                                     /* e_machine */
48         EV_CURRENT,                                 /* e_version */
49         SET_ME,                                     /* e_entry */
50         offsetof(struct elfh, p),                   /* e_phoff */
51         offsetof(struct elfh, sh),                  /* e_shoff */
52         0,                                          /* e_flags */
53         sizeof(elfhdr.e),                           /* e_ehsize */
54         sizeof(elfhdr.p[0]),                        /* e_phentsize */
55         sizeof(elfhdr.p) / sizeof(elfhdr.p[0]),     /* e_phnum */
56         sizeof(elfhdr.sh[0]),                       /* e_shentsize */
57         sizeof(elfhdr.sh) / sizeof(elfhdr.sh[0]),   /* e_shnum */
58         1                                           /* e_shstrndx */
59     },
60     {
61         {
62             PT_LOAD,                                /* p_type */
63             sizeof(elfhdr),                         /* p_offset */
64             SET_ME,                                 /* p_vaddr */
65             SET_ME,                                 /* p_paddr */
66             SET_ME,                                 /* p_filesz */
67             SET_ME,                                 /* p_memsz */
68             PF_R | PF_X,                            /* p_flags */
69             0x1000                                  /* p_align */
70         },
71         {
72             PT_LOAD,                                /* p_type */
73             SET_ME,                                 /* p_offset */
74             SET_ME,                                 /* p_vaddr */
75             SET_ME,                                 /* p_paddr */
76             SET_ME,                                 /* p_filesz */
77             SET_ME,                                 /* p_memsz */
78             PF_R | PF_W,                            /* p_flags */
79             0x1000                                  /* p_align */
80         }
81     },
82     {
83         {
84             0, SHT_NULL, 0, 0, 0, 0, SHN_UNDEF, 0, 0, 0
85         },
86         {
87             1,                                      /* sh_name */
88             SHT_STRTAB,                             /* sh_type */
89             0,                                      /* sh_flags */
90             0,                                      /* sh_addr */
91             offsetof(struct elfh, shstrtab),        /* sh_offset */
92             sizeof(elfhdr.shstrtab),                /* sh_size */
93             SHN_UNDEF,                              /* sh_link */
94             0,                                      /* sh_info */
95             1,                                      /* sh_addralign */
96             0                                       /* sh_entsize */
97         },
98         {
99             0xb,                                    /* sh_name */
100             SHT_PROGBITS,                           /* sh_type */
101             SHF_EXECINSTR | SHF_ALLOC,              /* sh_flags */
102             SET_ME,                                 /* sh_addr */
103             SET_ME,                                 /* sh_offset */
104             SET_ME,                                 /* sh_size */
105             SHN_UNDEF,                              /* sh_link */
106             0,                                      /* sh_info */
107             4,                                      /* sh_addralign */
108             0                                       /* sh_entsize */
109         },
110         {
111             0x11,                                   /* sh_name */
112             SHT_PROGBITS,                           /* sh_type */
113             SHF_ALLOC | SHF_WRITE,                  /* sh_flags */
114             SET_ME,                                 /* sh_addr */
115             SET_ME,                                 /* sh_offset */
116             SET_ME,                                 /* sh_size */
117             SHN_UNDEF,                              /* sh_link */
118             0,                                      /* sh_info */
119             4,                                      /* sh_addralign */
120             0                                       /* sh_entsize */
121         }
122     },
123     "\0.shstrtab\0.text\0.data"                     /* shstrtab */
124 };