2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2009 Free Software Foundation, Inc.
5 * GRUB is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * GRUB is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
20 #define GRUB_MACHO_H 1
21 #include <grub/types.h>
23 /* Multi-architecture header. Always in big-endian. */
24 struct grub_macho_fat_header
27 grub_uint32_t nfat_arch
;
32 GRUB_MACHO_CPUTYPE_IA32
= 0x00000007,
33 GRUB_MACHO_CPUTYPE_AMD64
= 0x01000007
36 #define GRUB_MACHO_FAT_MAGIC 0xcafebabe
37 #define GRUB_MACHO_FAT_EFI_MAGIC 0x0ef1fab9U
39 typedef grub_uint32_t grub_macho_cpu_type_t
;
40 typedef grub_uint32_t grub_macho_cpu_subtype_t
;
42 /* Architecture descriptor. Always in big-endian. */
43 struct grub_macho_fat_arch
45 grub_macho_cpu_type_t cputype
;
46 grub_macho_cpu_subtype_t cpusubtype
;
52 /* File header for 32-bit. Always in native-endian. */
53 struct grub_macho_header32
55 #define GRUB_MACHO_MAGIC32 0xfeedface
57 grub_macho_cpu_type_t cputype
;
58 grub_macho_cpu_subtype_t cpusubtype
;
59 grub_uint32_t filetype
;
61 grub_uint32_t sizeofcmds
;
65 /* File header for 64-bit. Always in native-endian. */
66 struct grub_macho_header64
68 #define GRUB_MACHO_MAGIC64 0xfeedfacf
70 grub_macho_cpu_type_t cputype
;
71 grub_macho_cpu_subtype_t cpusubtype
;
72 grub_uint32_t filetype
;
74 grub_uint32_t sizeofcmds
;
76 grub_uint32_t reserved
;
79 /* Common header of Mach-O commands. */
83 grub_uint32_t cmdsize
;
86 typedef grub_uint32_t grub_macho_vmprot_t
;
88 /* 32-bit segment command. */
89 struct grub_macho_segment32
91 #define GRUB_MACHO_CMD_SEGMENT32 1
93 grub_uint32_t cmdsize
;
94 grub_uint8_t segname
[16];
97 grub_uint32_t fileoff
;
98 grub_uint32_t filesize
;
99 grub_macho_vmprot_t maxprot
;
100 grub_macho_vmprot_t initprot
;
101 grub_uint32_t nsects
;
105 /* 64-bit segment command. */
106 struct grub_macho_segment64
108 #define GRUB_MACHO_CMD_SEGMENT64 0x19
110 grub_uint32_t cmdsize
;
111 grub_uint8_t segname
[16];
112 grub_uint64_t vmaddr
;
113 grub_uint64_t vmsize
;
114 grub_uint64_t fileoff
;
115 grub_uint64_t filesize
;
116 grub_macho_vmprot_t maxprot
;
117 grub_macho_vmprot_t initprot
;
118 grub_uint32_t nsects
;
122 #define GRUB_MACHO_CMD_THREAD 5
124 struct grub_macho_lzss_header
127 #define GRUB_MACHO_LZSS_MAGIC "complzss"
128 grub_uint32_t unused
;
129 grub_uint32_t uncompressed_size
;
130 grub_uint32_t compressed_size
;
133 /* Convenience union. What do we need to load to identify the file type. */
134 union grub_macho_filestart
136 struct grub_macho_fat_header fat
;
137 struct grub_macho_header32 thin32
;
138 struct grub_macho_header64 thin64
;
139 struct grub_macho_lzss_header lzss
;
142 struct grub_macho_thread32
145 grub_uint32_t cmdsize
;
146 grub_uint8_t unknown1
[48];
147 grub_uint32_t entry_point
;
148 grub_uint8_t unknown2
[20];
151 struct grub_macho_thread64
154 grub_uint32_t cmdsize
;
155 grub_uint8_t unknown1
[0x88];
156 grub_uint64_t entry_point
;
157 grub_uint8_t unknown2
[0x20];
160 #define GRUB_MACHO_LZSS_OFFSET 0x180
163 grub_decompress_lzss (grub_uint8_t
*dst
, grub_uint8_t
*dstend
,
164 grub_uint8_t
*src
, grub_uint8_t
*srcend
);