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
;
28 } __attribute__ ((packed
));
29 #define GRUB_MACHO_FAT_MAGIC 0xcafebabe
31 typedef grub_uint32_t grub_macho_cpu_type_t
;
32 typedef grub_uint32_t grub_macho_cpu_subtype_t
;
34 /* Architecture descriptor. Always in big-endian. */
35 struct grub_macho_fat_arch
37 grub_macho_cpu_type_t cputype
;
38 grub_macho_cpu_subtype_t cpusubtype
;
42 } __attribute__ ((packed
));
44 /* File header for 32-bit. Always in native-endian. */
45 struct grub_macho_header32
47 #define GRUB_MACHO_MAGIC32 0xfeedface
49 grub_macho_cpu_type_t cputype
;
50 grub_macho_cpu_subtype_t cpusubtype
;
51 grub_uint32_t filetype
;
53 grub_uint32_t sizeofcmds
;
55 } __attribute__ ((packed
));
57 /* File header for 64-bit. Always in native-endian. */
58 struct grub_macho_header64
60 #define GRUB_MACHO_MAGIC64 0xfeedfacf
62 grub_macho_cpu_type_t cputype
;
63 grub_macho_cpu_subtype_t cpusubtype
;
64 grub_uint32_t filetype
;
66 grub_uint32_t sizeofcmds
;
68 grub_uint32_t reserved
;
69 } __attribute__ ((packed
));
71 /* Common header of Mach-O commands. */
75 grub_uint32_t cmdsize
;
76 } __attribute__ ((packed
));
78 typedef grub_uint32_t grub_macho_vmprot_t
;
80 /* 32-bit segment command. */
81 struct grub_macho_segment32
83 #define GRUB_MACHO_CMD_SEGMENT32 1
85 grub_uint32_t cmdsize
;
86 grub_uint8_t segname
[16];
89 grub_uint32_t fileoff
;
90 grub_uint32_t filesize
;
91 grub_macho_vmprot_t maxprot
;
92 grub_macho_vmprot_t initprot
;
95 } __attribute__ ((packed
));
97 /* 64-bit segment command. */
98 struct grub_macho_segment64
100 #define GRUB_MACHO_CMD_SEGMENT64 0x19
102 grub_uint32_t cmdsize
;
103 grub_uint8_t segname
[16];
104 grub_uint64_t vmaddr
;
105 grub_uint64_t vmsize
;
106 grub_uint64_t fileoff
;
107 grub_uint64_t filesize
;
108 grub_macho_vmprot_t maxprot
;
109 grub_macho_vmprot_t initprot
;
110 grub_uint32_t nsects
;
112 } __attribute__ ((packed
));
114 #define GRUB_MACHO_CMD_THREAD 5
116 struct grub_macho_lzss_header
119 #define GRUB_MACHO_LZSS_MAGIC "complzss"
120 grub_uint32_t unused
;
121 grub_uint32_t uncompressed_size
;
122 grub_uint32_t compressed_size
;
125 /* Convenience union. What do we need to load to identify the file type. */
126 union grub_macho_filestart
128 struct grub_macho_fat_header fat
;
129 struct grub_macho_header32 thin32
;
130 struct grub_macho_header64 thin64
;
131 struct grub_macho_lzss_header lzss
;
132 } __attribute__ ((packed
));
134 #define GRUB_MACHO_LZSS_OFFSET 0x180
137 grub_decompress_lzss (grub_uint8_t
*dst
, grub_uint8_t
*dstend
,
138 grub_uint8_t
*src
, grub_uint8_t
*srcend
);