1 /**
2  * \file
3  * \brief Auxiliary information for binaries
4  */
5 /*
6  * (c) 2009 Alexander Warg <warg@os.inf.tu-dresden.de>
7  *     economic rights: Technische Universität Dresden (Germany)
8  *
9  * This file is part of TUD:OS and distributed under the terms of the
10  * GNU General Public License 2.
11  * Please see the COPYING-GPL-2 file for details.
12  *
13  * As a special exception, you may use this file as part of a free software
14  * library without restriction.  Specifically, if other files instantiate
15  * templates or use macros or inline functions from this file, or you compile
16  * this file and link it with other files to produce an executable, this
17  * file does not by itself cause the resulting executable to be covered by
18  * the GNU General Public License.  This exception does not however
19  * invalidate any other reasons why the executable file might be covered by
20  * the GNU General Public License.
21  */
22 #pragma once
23 
24 #include <l4/sys/types.h>
25 
26 
27 /**
28  * \defgroup api_l4re_elf_aux L4Re ELF Auxiliary Information
29  * \ingroup api_l4re
30  * \brief API for embedding auxiliary information into
31  *        binary programs.
32  *
33  * This API allows information for the binary loader to be embedded into a
34  * binary application.  This information can be reserved areas in the virtual
35  * memory of an application and things such as the stack size to be allocated
36  * for the first application thread.
37  */
38 /*@{*/
39 
40 /**
41  * \brief Define an auxiliary vector element.
42  *
43  * This is the generic method for defining auxiliary vector elements.
44  * A more convenient way is to use L4RE_ELF_AUX_ELEM_T.
45  *
46  * Usage:
47  * \code
48  * L4RE_ELF_AUX_ELEM l4re_elf_aux_vma_t decl_name =
49  *   { L4RE_ELF_AUX_T_VMA, sizeof(l4re_elf_aux_vma_t), 0x2000, 0x4000 };
50  * \endcode
51  */
52 #define L4RE_ELF_AUX_ELEM const __attribute__((used, section(".rol4re_elf_aux"), aligned(sizeof(l4_umword_t))))
53 
54 /**
55  * \brief Define an auxiliary vector element.
56  * \param type is the data type for the element (e.g., l4re_elf_aux_vma_t)
57  * \param id is the identifier (variable name) for the declaration (the
58  *           variable is defined with \c static storage class)
59  * \param tag is the tag value for the element e.g., #L4RE_ELF_AUX_T_VMA
60  * \param val are the values to be set in the descriptor
61  *
62  * Usage:
63  * \code
64  * L4RE_ELF_AUX_ELEM_T(l4re_elf_aux_vma_t, decl_name, L4RE_ELF_AUX_T_VMA, 0x2000, 0x4000 };
65  * \endcode
66  */
67 #define L4RE_ELF_AUX_ELEM_T(type, id, tag, val...) \
68   static L4RE_ELF_AUX_ELEM type id = {tag, sizeof(type), val}
69 
70 enum
71 {
72   /**
73    * \brief Tag for an invalid element in the auxiliary vector
74    */
75   L4RE_ELF_AUX_T_NONE = 0,
76 
77   /**
78    * \brief Tag for descriptor for a reserved virtual memory area.
79    */
80   L4RE_ELF_AUX_T_VMA,
81 
82   /**
83    * \brief Tag for descriptor that defines the stack size for
84    *        the first application thread.
85    */
86   L4RE_ELF_AUX_T_STACK_SIZE,
87 
88   /**
89    * \brief Tag for descriptor that defines the stack address
90    *        for the first application thread.
91    */
92   L4RE_ELF_AUX_T_STACK_ADDR,
93 
94   /**
95    * \brief Tag for descriptor that defines the KIP address
96    *        for the binaries address space.
97    */
98   L4RE_ELF_AUX_T_KIP_ADDR,
99 };
100 
101 /**
102  * \brief Generic header for each auxiliary vector element.
103  */
104 typedef struct l4re_elf_aux_t
105 {
106   l4_umword_t type;
107   l4_umword_t length;
108 } l4re_elf_aux_t;
109 
110 /**
111  * \brief Auxiliary vector element for a reserved virtual memory area.
112  */
113 typedef struct l4re_elf_aux_vma_t
114 {
115   l4_umword_t type;
116   l4_umword_t length;
117   l4_umword_t start;
118   l4_umword_t end;
119 } l4re_elf_aux_vma_t;
120 
121 /**
122  * \brief Auxiliary vector element for a single unsigned data word.
123  */
124 typedef struct l4re_elf_aux_mword_t
125 {
126   l4_umword_t type;
127   l4_umword_t length;
128   l4_umword_t value;
129 } l4re_elf_aux_mword_t;
130 
131 /*@}*/
132