Add implicitly sized versions of the K instructions
[nasm.git] / output / macho.h
blob538c531e29929a9e7cfb538a0bfd27913c4e2bf9
1 /* ----------------------------------------------------------------------- *
3 * Copyright 1996-2018 The NASM Authors - All Rights Reserved
4 * See the file AUTHORS included with the NASM distribution for
5 * the specific copyright holders.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following
9 * conditions are met:
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 * ----------------------------------------------------------------------- */
34 #ifndef OUTPUT_MACHO_H
35 #define OUTPUT_MACHO_H
37 #include "compiler.h"
39 /* Magics */
40 #define MH_MAGIC 0xfeedface
41 #define MH_MAGIC_64 0xfeedfacf
43 /* File types */
44 #define MH_OBJECT 0x1
46 /* CPUs */
47 #define CPU_ARCH_MASK 0xff000000
48 #define CPU_ARCH_ABI64 0x01000000
49 #define CPU_TYPE_X86 7
50 #define CPU_TYPE_I386 CPU_TYPE_X86
51 #define CPU_TYPE_X86_64 (CPU_TYPE_X86 | CPU_ARCH_ABI64)
53 #define CPU_SUBTYPE_MASK 0xff000000
54 #define CPU_SUBTYPE_I386_ALL 3
56 /* Header flags */
57 #define MH_SUBSECTIONS_VIA_SYMBOLS 0x00002000
59 /* Load commands */
60 #define LC_SEGMENT 0x1
61 #define LC_SEGMENT_64 0x19
62 #define LC_SYMTAB 0x2
64 /* Symbol type bits */
65 #define N_STAB 0xe0
66 #define N_PEXT 0x10
67 #define N_TYPE 0x0e
68 #define N_EXT 0x01
70 /* To mask with N_TYPE */
71 #define N_UNDF 0x00
72 #define N_ABS 0x02
73 #define N_INDR 0x0a
74 #define N_PBUD 0x0c
75 #define N_SECT 0x0e
77 /* Section ordinals */
78 #define NO_SECT 0x00
79 #define MAX_SECT 0xff
81 /* Section bits */
82 #define SECTION_TYPE 0x000000ff
83 #define SECTION_ATTRIBUTES 0xffffff00
84 #define SECTION_ATTRIBUTES_USR 0xff000000
85 #define SECTION_ATTRIBUTES_SYS 0x00ffff00
87 #define S_REGULAR 0x00
88 #define S_ZEROFILL 0x01
89 #define S_CSTRING_LITERALS 0x02
90 #define S_4BYTE_LITERALS 0x03
91 #define S_8BYTE_LITERALS 0x04
92 #define S_LITERAL_POINTERS 0x05
93 #define S_NON_LAZY_SYMBOL_POINTERS 0x06
94 #define S_LAZY_SYMBOL_POINTERS 0x07
95 #define S_SYMBOL_STUBS 0x08
96 #define S_MOD_INIT_FUNC_POINTERS 0x09
97 #define S_MOD_TERM_FUNC_POINTERS 0x0a
98 #define S_COALESCED 0x0b
99 #define S_GB_ZEROFILL 0x0c
100 #define S_INTERPOSING 0x0d
101 #define S_16BYTE_LITERALS 0x0e
102 #define S_DTRACE_DOF 0x0f
103 #define S_LAZY_DYLIB_SYMBOL_POINTERS 0x10
104 #define S_THREAD_LOCAL_REGULAR 0x11
105 #define S_THREAD_LOCAL_ZEROFILL 0x12
106 #define S_THREAD_LOCAL_VARIABLES 0x13
107 #define S_THREAD_LOCAL_VARIABLE_POINTERS 0x14
108 #define S_THREAD_LOCAL_INIT_FUNCTION_POINTERS 0x15
110 #define S_ATTR_PURE_INSTRUCTIONS 0x80000000
111 #define S_ATTR_NO_TOC 0x40000000
112 #define S_ATTR_STRIP_STATIC_SYMS 0x20000000
113 #define S_ATTR_NO_DEAD_STRIP 0x10000000
114 #define S_ATTR_LIVE_SUPPORT 0x08000000
115 #define S_ATTR_SELF_MODIFYING_CODE 0x04000000
116 #define S_ATTR_DEBUG 0x02000000
118 #define S_ATTR_SOME_INSTRUCTIONS 0x00000400
119 #define S_ATTR_EXT_RELOC 0x00000200
120 #define S_ATTR_LOC_RELOC 0x00000100
121 #define INDIRECT_SYMBOL_LOCAL 0x80000000
122 #define INDIRECT_SYMBOL_ABS 0x40000000
124 /* Relocation info type */
125 #define GENERIC_RELOC_VANILLA 0
126 #define GENERIC_RELOC_PAIR 1
127 #define GENERIC_RELOC_SECTDIFF 2
128 #define GENERIC_RELOC_PB_LA_PTR 3
129 #define GENERIC_RELOC_LOCAL_SECTDIFF 4
130 #define GENERIC_RELOC_TLV 5
132 #define X86_64_RELOC_UNSIGNED 0
133 #define X86_64_RELOC_SIGNED 1
134 #define X86_64_RELOC_BRANCH 2
135 #define X86_64_RELOC_GOT_LOAD 3
136 #define X86_64_RELOC_GOT 4
137 #define X86_64_RELOC_SUBTRACTOR 5
138 #define X86_64_RELOC_SIGNED_1 6
139 #define X86_64_RELOC_SIGNED_2 7
140 #define X86_64_RELOC_SIGNED_4 8
141 #define X86_64_RELOC_TLV 9
143 /* Relocation info */
144 #define R_ABS 0
145 #define R_SCATTERED 0x80000000
147 /* VM permission constants */
148 #define VM_PROT_NONE 0x00
149 #define VM_PROT_READ 0x01
150 #define VM_PROT_WRITE 0x02
151 #define VM_PROT_EXECUTE 0x04
153 typedef struct {
154 uint32_t magic;
155 uint32_t cputype;
156 uint32_t cpusubtype;
157 uint32_t filetype;
158 uint32_t ncmds;
159 uint32_t sizeofcmds;
160 uint32_t flags;
161 } macho_header_t;
163 typedef struct {
164 uint32_t magic;
165 uint32_t cputype;
166 uint32_t cpusubtype;
167 uint32_t filetype;
168 uint32_t ncmds;
169 uint32_t sizeofcmds;
170 uint32_t flags;
171 uint32_t reserved;
172 } macho_header_64_t;
174 typedef struct {
175 uint32_t cmd;
176 uint32_t cmdsize;
177 } macho_load_command_t;
179 typedef struct {
180 uint32_t cmd;
181 uint32_t cmdsize;
182 char segname[16];
183 uint32_t vmaddr;
184 uint32_t vmsize;
185 uint32_t fileoff;
186 uint32_t filesize;
187 uint32_t maxprot;
188 uint32_t initprot;
189 uint32_t nsects;
190 uint32_t flags;
191 } macho_segment_command_t;
193 typedef struct {
194 uint32_t cmd;
195 uint32_t cmdsize;
196 char segname[16];
197 uint64_t vmaddr;
198 uint64_t vmsize;
199 uint64_t fileoff;
200 uint64_t filesize;
201 uint32_t maxprot;
202 uint32_t initprot;
203 uint32_t nsects;
204 uint32_t flags;
205 } macho_segment_command_64_t;
207 typedef struct {
208 char sectname[16];
209 char segname[16];
210 uint32_t addr;
211 uint32_t size;
212 uint32_t offset;
213 uint32_t align;
214 uint32_t reloff;
215 uint32_t nreloc;
216 uint32_t flags;
217 uint32_t reserved1;
218 uint32_t reserved2;
219 } macho_section_t;
221 typedef struct {
222 char sectname[16];
223 char segname[16];
224 uint64_t addr;
225 uint64_t size;
226 uint32_t offset;
227 uint32_t align;
228 uint32_t reloff;
229 uint32_t nreloc;
230 uint32_t flags;
231 uint32_t reserved1;
232 uint32_t reserved2;
233 uint32_t reserved3;
234 } macho_section_64_t;
236 typedef struct {
237 uint32_t cmd;
238 uint32_t cmdsize;
239 uint32_t symoff;
240 uint32_t nsyms;
241 uint32_t stroff;
242 uint32_t strsize;
243 } macho_symtab_command_t;
245 typedef struct {
246 int32_t r_address;
247 union {
248 struct {
249 uint32_t r_symbolnum: 24,
250 r_pcrel: 1,
251 r_length: 2,
252 r_extern: 1,
253 r_type: 4;
254 } s;
255 uint32_t r_raw;
256 } u;
257 } macho_relocation_info_t;
259 typedef struct nlist_base {
260 uint32_t n_strx;
261 uint8_t n_type;
262 uint8_t n_sect;
263 uint16_t n_desc;
264 } macho_nlist_base_t;
266 typedef struct nlist {
267 uint32_t n_strx;
268 uint8_t n_type;
269 uint8_t n_sect;
270 int16_t n_desc;
271 uint32_t n_value;
272 } macho_nlist_t;
274 typedef struct {
275 uint32_t n_strx;
276 uint8_t n_type;
277 uint8_t n_sect;
278 uint16_t n_desc;
279 uint64_t n_value;
280 } macho_nlist_64_t;
282 #endif /* OUTPUT_MACHO_H */