FreeBSD/Linux Kernel Cross Reference
sys/sys/bootblock.h
1 /* $NetBSD: bootblock.h,v 1.24.2.1 2004/04/28 05:57:19 jmc Exp $ */
2
3 /*-
4 * Copyright (c) 2002-2004 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the NetBSD
18 * Foundation, Inc. and its contributors.
19 * 4. Neither the name of The NetBSD Foundation nor the names of its
20 * contributors may be used to endorse or promote products derived
21 * from this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
24 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
27 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 */
35 /*-
36 * Copyright (C) 1993 Allen K. Briggs, Chris P. Caputo,
37 * Michael L. Finch, Bradley A. Grantham, and
38 * Lawrence A. Kesteloot
39 * All rights reserved.
40 *
41 * Redistribution and use in source and binary forms, with or without
42 * modification, are permitted provided that the following conditions
43 * are met:
44 * 1. Redistributions of source code must retain the above copyright
45 * notice, this list of conditions and the following disclaimer.
46 * 2. Redistributions in binary form must reproduce the above copyright
47 * notice, this list of conditions and the following disclaimer in the
48 * documentation and/or other materials provided with the distribution.
49 * 3. All advertising materials mentioning features or use of this software
50 * must display the following acknowledgement:
51 * This product includes software developed by the Alice Group.
52 * 4. The names of the Alice Group or any of its members may not be used
53 * to endorse or promote products derived from this software without
54 * specific prior written permission.
55 *
56 * THIS SOFTWARE IS PROVIDED BY THE ALICE GROUP ``AS IS'' AND ANY EXPRESS OR
57 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
58 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
59 * IN NO EVENT SHALL THE ALICE GROUP BE LIABLE FOR ANY DIRECT, INDIRECT,
60 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
61 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
62 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
63 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
64 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
65 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
66 *
67 */
68 /*
69 * Copyright (c) 1994, 1999 Christopher G. Demetriou
70 * All rights reserved.
71 *
72 * Redistribution and use in source and binary forms, with or without
73 * modification, are permitted provided that the following conditions
74 * are met:
75 * 1. Redistributions of source code must retain the above copyright
76 * notice, this list of conditions and the following disclaimer.
77 * 2. Redistributions in binary form must reproduce the above copyright
78 * notice, this list of conditions and the following disclaimer in the
79 * documentation and/or other materials provided with the distribution.
80 * 3. All advertising materials mentioning features or use of this software
81 * must display the following acknowledgement:
82 * This product includes software developed by Christopher G. Demetriou
83 * for the NetBSD Project.
84 * 4. The name of the author may not be used to endorse or promote products
85 * derived from this software without specific prior written permission
86 *
87 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
88 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
89 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
90 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
91 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
92 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
93 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
94 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
95 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
96 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
97 */
98 /*
99 * Copyright (c) 1994 Rolf Grossmann
100 * All rights reserved.
101 *
102 * Redistribution and use in source and binary forms, with or without
103 * modification, are permitted provided that the following conditions
104 * are met:
105 * 1. Redistributions of source code must retain the above copyright
106 * notice, this list of conditions and the following disclaimer.
107 * 2. Redistributions in binary form must reproduce the above copyright
108 * notice, this list of conditions and the following disclaimer in the
109 * documentation and/or other materials provided with the distribution.
110 * 3. All advertising materials mentioning features or use of this software
111 * must display the following acknowledgement:
112 * This product includes software developed by Rolf Grossmann.
113 * 4. The name of the author may not be used to endorse or promote products
114 * derived from this software without specific prior written permission
115 *
116 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
117 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
118 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
119 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
120 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
121 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
122 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
123 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
124 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
125 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
126 */
127
128 #ifndef _SYS_BOOTBLOCK_H
129 #define _SYS_BOOTBLOCK_H
130
131 #if !defined(__ASSEMBLER__)
132 #if defined(_KERNEL) || defined(_STANDALONE)
133 #include <sys/stdint.h>
134 #else
135 #include <stdint.h>
136 #endif
137 #endif /* !defined(__ASSEMBLER__) */
138
139 /* ------------------------------------------
140 * MBR (Master Boot Record) --
141 * definitions for systems that use MBRs
142 */
143
144 /*
145 * Layout of boot records:
146 *
147 * Byte range Use Description
148 * ---------- --- -----------
149 *
150 * 0 - 2 FMP JMP xxx, NOP
151 * 3 - 10 FP OEM Name
152 *
153 * 11 - 61 FMP FAT12/16 BPB
154 * Whilst not strictly necessary for MBR,
155 * GRUB reserves this area
156 *
157 * 11 - 89 P FAT32 BPB
158 * (are we ever going to boot off this?)
159 *
160 *
161 * 62 - 217 FMP Boot code
162 *
163 * 90 - 217 P FAT32 boot code
164 *
165 * 218 - 223 M Win95b/98/me "drive time"
166 * http://www.geocities.com/thestarman3/asm/mbr/95BMEMBR.htm#MYST
167 * only changed if all 6 bytes are 0
168 *
169 * 224 - 436 FMP boot code (continued)
170 *
171 * 437 - 439 M WinNT/2K/XP MBR "boot language"
172 * http://www.geocities.com/thestarman3/asm/mbr/Win2kmbr.htm
173 * not needed by us
174 *
175 * 400 - 439 MP NetBSD: mbr_bootsel
176 *
177 * 440 - 443 M WinNT/2K/XP Drive Serial Number (NT DSN)
178 * http://www.geocities.com/thestarman3/asm/mbr/Win2kmbr.htm
179 *
180 * 444 - 445 FMP bootcode or unused
181 * NetBSD: mbr_bootsel_magic
182 *
183 * 446 - 509 M partition table
184 *
185 * 510 - 511 FMP magic number (0xAA55)
186 *
187 * Use:
188 * ----
189 * F Floppy boot sector
190 * M Master Boot Record
191 * P Partition Boot record
192 *
193 */
194
195 /*
196 * MBR (Master Boot Record)
197 */
198 #define MBR_BBSECTOR 0 /* MBR relative sector # */
199 #define MBR_BPB_OFFSET 11 /* offsetof(mbr_sector, mbr_bpb) */
200 #define MBR_BOOTCODE_OFFSET 90 /* offsetof(mbr_sector, mbr_bootcode) */
201 #define MBR_BS_OFFSET 400 /* offsetof(mbr_sector, mbr_bootsel) */
202 #define MBR_BS_OLD_OFFSET 404 /* where mbr_bootsel used to be */
203 #define MBR_DSN_OFFSET 440 /* offsetof(mbr_sector, mbr_dsn) */
204 #define MBR_BS_MAGIC_OFFSET 444 /* offsetof(mbr_sector, mbr_bootsel_magic) */
205 #define MBR_PART_OFFSET 446 /* offsetof(mbr_sector, mbr_part[0]) */
206 #define MBR_MAGIC_OFFSET 510 /* offsetof(mbr_sector, mbr_magic) */
207 #define MBR_MAGIC 0xaa55 /* MBR magic number */
208 #define MBR_BS_MAGIC 0xb5e1 /* mbr_bootsel magic number */
209 #define MBR_PART_COUNT 4 /* Number of partitions in MBR */
210 #define MBR_BS_PARTNAMESIZE 8 /* Size of name mbr_bootsel nametab */
211 /* (excluding trailing NUL) */
212
213 /* values for mbr_partition.mbrp_flag */
214 #define MBR_PFLAG_ACTIVE 0x80 /* The active partition */
215
216 /* values for mbr_partition.mbrp_type */
217 #define MBR_PTYPE_FAT12 0x01 /* 12-bit FAT */
218 #define MBR_PTYPE_FAT16S 0x04 /* 16-bit FAT, less than 32M */
219 #define MBR_PTYPE_EXT 0x05 /* extended partition */
220 #define MBR_PTYPE_FAT16B 0x06 /* 16-bit FAT, more than 32M */
221 #define MBR_PTYPE_NTFS 0x07 /* OS/2 HPFS, NTFS, QNX2, Adv. UNIX */
222 #define MBR_PTYPE_FAT32 0x0b /* 32-bit FAT */
223 #define MBR_PTYPE_FAT32L 0x0c /* 32-bit FAT, LBA-mapped */
224 #define MBR_PTYPE_FAT16L 0x0e /* 16-bit FAT, LBA-mapped */
225 #define MBR_PTYPE_EXT_LBA 0x0f /* extended partition, LBA-mapped */
226 #define MBR_PTYPE_ONTRACK 0x54
227 #define MBR_PTYPE_LNXSWAP 0x82 /* Linux swap or Solaris */
228 #define MBR_PTYPE_LNXEXT2 0x83 /* Linux native */
229 #define MBR_PTYPE_EXT_LNX 0x85 /* Linux extended partition */
230 #define MBR_PTYPE_NTFSVOL 0x87 /* NTFS volume set or HPFS mirrored */
231 #define MBR_PTYPE_PREP 0x41 /* PReP */
232 #define MBR_PTYPE_386BSD 0xa5 /* 386BSD partition type */
233 #define MBR_PTYPE_APPLEUFS 0xa8 /* Apple UFS */
234 #define MBR_PTYPE_NETBSD 0xa9 /* NetBSD partition type */
235 #define MBR_PTYPE_OPENBSD 0xa6 /* OpenBSD partition type */
236
237 #define MBR_PSECT(s) ((s) & 0x3f)
238 #define MBR_PCYL(c, s) ((c) + (((s) & 0xc0) << 2))
239
240 #define MBR_IS_EXTENDED(x) ((x) == MBR_PTYPE_EXT || \
241 (x) == MBR_PTYPE_EXT_LBA || \
242 (x) == MBR_PTYPE_EXT_LNX)
243
244 /* values for mbr_bootsel.mbrbs_flags */
245 #define MBR_BS_ACTIVE 0x01 /* Bootselector active (or code present) */
246 #define MBR_BS_EXTINT13 0x02 /* Set by fdisk if LBA needed (deprecated) */
247 #define MBR_BS_READ_LBA 0x04 /* Force LBA reads (deprecated) */
248 #define MBR_BS_EXTLBA 0x08 /* Extended ptn capable (LBA reads) */
249 /* This is always set, the bootsel is located using the magic number... */
250 #define MBR_BS_NEWMBR 0x80 /* New bootsel at offset 440 */
251
252 #if !defined(__ASSEMBLER__) /* { */
253
254 /*
255 * (x86) BIOS Parameter Block for FAT12
256 */
257 struct mbr_bpbFAT12 {
258 uint16_t bpbBytesPerSec; /* bytes per sector */
259 uint8_t bpbSecPerClust; /* sectors per cluster */
260 uint16_t bpbResSectors; /* number of reserved sectors */
261 uint8_t bpbFATs; /* number of FATs */
262 uint16_t bpbRootDirEnts; /* number of root directory entries */
263 uint16_t bpbSectors; /* total number of sectors */
264 uint8_t bpbMedia; /* media descriptor */
265 uint16_t bpbFATsecs; /* number of sectors per FAT */
266 uint16_t bpbSecPerTrack; /* sectors per track */
267 uint16_t bpbHeads; /* number of heads */
268 uint16_t bpbHiddenSecs; /* # of hidden sectors */
269 } __attribute__((__packed__));
270
271 /*
272 * (x86) BIOS Parameter Block for FAT16
273 */
274 struct mbr_bpbFAT16 {
275 uint16_t bpbBytesPerSec; /* bytes per sector */
276 uint8_t bpbSecPerClust; /* sectors per cluster */
277 uint16_t bpbResSectors; /* number of reserved sectors */
278 uint8_t bpbFATs; /* number of FATs */
279 uint16_t bpbRootDirEnts; /* number of root directory entries */
280 uint16_t bpbSectors; /* total number of sectors */
281 uint8_t bpbMedia; /* media descriptor */
282 uint16_t bpbFATsecs; /* number of sectors per FAT */
283 uint16_t bpbSecPerTrack; /* sectors per track */
284 uint16_t bpbHeads; /* number of heads */
285 uint32_t bpbHiddenSecs; /* # of hidden sectors */
286 uint32_t bpbHugeSectors; /* # of sectors if bpbSectors == 0 */
287 uint8_t bsDrvNum; /* Int 0x13 drive number (e.g. 0x80) */
288 uint8_t bsReserved1; /* Reserved; set to 0 */
289 uint8_t bsBootSig; /* 0x29 if next 3 fields are present */
290 uint8_t bsVolID[4]; /* Volume serial number */
291 uint8_t bsVolLab[11]; /* Volume label */
292 uint8_t bsFileSysType[8];
293 /* "FAT12 ", "FAT16 ", "FAT " */
294 } __attribute__((__packed__));
295
296 /*
297 * (x86) BIOS Parameter Block for FAT32
298 */
299 struct mbr_bpbFAT32 {
300 uint16_t bpbBytesPerSec; /* bytes per sector */
301 uint8_t bpbSecPerClust; /* sectors per cluster */
302 uint16_t bpbResSectors; /* number of reserved sectors */
303 uint8_t bpbFATs; /* number of FATs */
304 uint16_t bpbRootDirEnts; /* number of root directory entries */
305 uint16_t bpbSectors; /* total number of sectors */
306 uint8_t bpbMedia; /* media descriptor */
307 uint16_t bpbFATsecs; /* number of sectors per FAT */
308 uint16_t bpbSecPerTrack; /* sectors per track */
309 uint16_t bpbHeads; /* number of heads */
310 uint32_t bpbHiddenSecs; /* # of hidden sectors */
311 uint32_t bpbHugeSectors; /* # of sectors if bpbSectors == 0 */
312 uint32_t bpbBigFATsecs; /* like bpbFATsecs for FAT32 */
313 uint16_t bpbExtFlags; /* extended flags: */
314 #define MBR_FAT32_FATNUM 0x0F /* mask for numbering active FAT */
315 #define MBR_FAT32_FATMIRROR 0x80 /* FAT is mirrored (as previously) */
316 uint16_t bpbFSVers; /* filesystem version */
317 #define MBR_FAT32_FSVERS 0 /* currently only 0 is understood */
318 uint32_t bpbRootClust; /* start cluster for root directory */
319 uint16_t bpbFSInfo; /* filesystem info structure sector */
320 uint16_t bpbBackup; /* backup boot sector */
321 uint8_t bsReserved[12]; /* Reserved for future expansion */
322 uint8_t bsDrvNum; /* Int 0x13 drive number (e.g. 0x80) */
323 uint8_t bsReserved1; /* Reserved; set to 0 */
324 uint8_t bsBootSig; /* 0x29 if next 3 fields are present */
325 uint8_t bsVolID[4]; /* Volume serial number */
326 uint8_t bsVolLab[11]; /* Volume label */
327 uint8_t bsFileSysType[8]; /* "FAT32 " */
328 } __attribute__((__packed__));
329
330 /*
331 * (x86) MBR boot selector
332 */
333 struct mbr_bootsel {
334 uint8_t mbrbs_defkey;
335 uint8_t mbrbs_flags;
336 uint16_t mbrbs_timeo;
337 uint8_t mbrbs_nametab[MBR_PART_COUNT][MBR_BS_PARTNAMESIZE + 1];
338 } __attribute__((__packed__));
339
340 /*
341 * MBR partition
342 */
343 struct mbr_partition {
344 uint8_t mbrp_flag; /* MBR partition flags */
345 uint8_t mbrp_shd; /* Starting head */
346 uint8_t mbrp_ssect; /* Starting sector */
347 uint8_t mbrp_scyl; /* Starting cylinder */
348 uint8_t mbrp_type; /* Partition type (see below) */
349 uint8_t mbrp_ehd; /* End head */
350 uint8_t mbrp_esect; /* End sector */
351 uint8_t mbrp_ecyl; /* End cylinder */
352 uint32_t mbrp_start; /* Absolute starting sector number */
353 uint32_t mbrp_size; /* Partition size in sectors */
354 } __attribute__((__packed__));
355
356 int xlat_mbr_fstype(int); /* in sys/lib/libkern/xlat_mbr_fstype.c */
357
358 /*
359 * MBR boot sector.
360 * This is used by both the MBR (Master Boot Record) in sector 0 of the disk
361 * and the PBR (Partition Boot Record) in sector 0 of an MBR partition.
362 */
363 struct mbr_sector {
364 /* Jump instruction to boot code. */
365 /* Usually 0xE9nnnn or 0xEBnn90 */
366 uint8_t mbr_jmpboot[3];
367 /* OEM name and version */
368 uint8_t mbr_oemname[8];
369 union { /* BIOS Parameter Block */
370 struct mbr_bpbFAT12 bpb12;
371 struct mbr_bpbFAT16 bpb16;
372 struct mbr_bpbFAT32 bpb32;
373 } mbr_bpb;
374 /* Boot code */
375 uint8_t mbr_bootcode[310];
376 /* Config for /usr/mdec/mbr_bootsel */
377 struct mbr_bootsel mbr_bootsel;
378 /* NT Drive Serial Number */
379 uint32_t mbr_dsn;
380 /* mbr_bootsel magic */
381 uint16_t mbr_bootsel_magic;
382 /* MBR partition table */
383 struct mbr_partition mbr_parts[MBR_PART_COUNT];
384 /* MBR magic (0xaa55) */
385 uint16_t mbr_magic;
386 } __attribute__((__packed__));
387
388 #endif /* !defined(__ASSEMBLER__) */ /* } */
389
390
391 /* ------------------------------------------
392 * shared --
393 * definitions shared by many platforms
394 */
395
396 #if !defined(__ASSEMBLER__) /* { */
397
398 /* Maximum # of blocks in bbi_block_table, each bbi_block_size long */
399 #define SHARED_BBINFO_MAXBLOCKS 118 /* so sizeof(shared_bbinfo) == 512 */
400
401 struct shared_bbinfo {
402 uint8_t bbi_magic[32];
403 int32_t bbi_block_size;
404 int32_t bbi_block_count;
405 int32_t bbi_block_table[SHARED_BBINFO_MAXBLOCKS];
406 };
407
408 /* ------------------------------------------
409 * alpha --
410 * Alpha (disk, but also tape) Boot Block.
411 *
412 * See Section (III) 3.6.1 of the Alpha Architecture Reference Manual.
413 */
414
415 struct alpha_boot_block {
416 uint64_t bb_data[63]; /* data (disklabel, also as below) */
417 uint64_t bb_cksum; /* checksum of the boot block,
418 * taken as uint64_t's
419 */
420 };
421 #define bb_secsize bb_data[60] /* secondary size (blocks) */
422 #define bb_secstart bb_data[61] /* secondary start (blocks) */
423 #define bb_flags bb_data[62] /* unknown flags (set to zero) */
424
425 #define ALPHA_BOOT_BLOCK_OFFSET 0 /* offset of boot block. */
426 #define ALPHA_BOOT_BLOCK_BLOCKSIZE 512 /* block size for sector
427 * size/start, and for boot
428 * block itself.
429 */
430
431 #define ALPHA_BOOT_BLOCK_CKSUM(bb,cksum) \
432 do { \
433 const struct alpha_boot_block *_bb = (bb); \
434 uint64_t _cksum; \
435 int _i; \
436 \
437 _cksum = 0; \
438 for (_i = 0; \
439 _i < (sizeof _bb->bb_data / sizeof _bb->bb_data[0]); \
440 _i++) \
441 _cksum += _bb->bb_data[_i]; \
442 *(cksum) = _cksum; \
443 } while (/*CONSTCOND*/ 0)
444
445 /* ------------------------------------------
446 * apple --
447 * Apple computers boot block related information
448 */
449
450 /*
451 * Driver Descriptor Map, from Inside Macintosh: Devices, SCSI Manager
452 * pp 12-13. The driver descriptor map always resides on physical block 0.
453 */
454 struct apple_drvr_descriptor {
455 uint32_t descBlock; /* first block of driver */
456 uint16_t descSize; /* driver size in blocks */
457 uint16_t descType; /* system type */
458 };
459
460 /*
461 * system types; Apple reserves 0-15
462 */
463 #define APPLE_DRVR_TYPE_MACINTOSH 1
464
465 #define APPLE_DRVR_MAP_MAGIC 0x4552
466 #define APPLE_DRVR_MAP_MAX_DESCRIPTORS 61
467
468 struct apple_drvr_map {
469 uint16_t sbSig; /* map signature */
470 uint16_t sbBlockSize; /* block size of device */
471 uint32_t sbBlkCount; /* number of blocks on device */
472 uint16_t sbDevType; /* (used internally by ROM) */
473 uint16_t sbDevID; /* (used internally by ROM) */
474 uint32_t sbData; /* (used internally by ROM) */
475 uint16_t sbDrvrCount; /* number of driver descriptors */
476 struct apple_drvr_descriptor sb_dd[APPLE_DRVR_MAP_MAX_DESCRIPTORS];
477 uint16_t pad[3];
478 } __attribute__((__packed__));
479
480 /*
481 * Partition map structure from Inside Macintosh: Devices, SCSI Manager
482 * pp. 13-14. The partition map always begins on physical block 1.
483 *
484 * With the exception of block 0, all blocks on the disk must belong to
485 * exactly one partition. The partition map itself belongs to a partition
486 * of type `APPLE_PARTITION_MAP', and is not limited in size by anything
487 * other than available disk space. The partition map is not necessarily
488 * the first partition listed.
489 */
490 #define APPLE_PART_MAP_ENTRY_MAGIC 0x504d
491
492 struct apple_part_map_entry {
493 uint16_t pmSig; /* partition signature */
494 uint16_t pmSigPad; /* (reserved) */
495 uint32_t pmMapBlkCnt; /* number of blocks in partition map */
496 uint32_t pmPyPartStart; /* first physical block of partition */
497 uint32_t pmPartBlkCnt; /* number of blocks in partition */
498 uint8_t pmPartName[32]; /* partition name */
499 uint8_t pmPartType[32]; /* partition type */
500 uint32_t pmLgDataStart; /* first logical block of data area */
501 uint32_t pmDataCnt; /* number of blocks in data area */
502 uint32_t pmPartStatus; /* partition status information */
503 uint32_t pmLgBootStart; /* first logical block of boot code */
504 uint32_t pmBootSize; /* size of boot code, in bytes */
505 uint32_t pmBootLoad; /* boot code load address */
506 uint32_t pmBootLoad2; /* (reserved) */
507 uint32_t pmBootEntry; /* boot code entry point */
508 uint32_t pmBootEntry2; /* (reserved) */
509 uint32_t pmBootCksum; /* boot code checksum */
510 int8_t pmProcessor[16]; /* processor type (e.g. "68020") */
511 uint8_t pmBootArgs[128]; /* A/UX boot arguments */
512 uint8_t pad[248]; /* pad to end of block */
513 };
514
515 #define APPLE_PART_TYPE_DRIVER "APPLE_DRIVER"
516 #define APPLE_PART_TYPE_DRIVER43 "APPLE_DRIVER43"
517 #define APPLE_PART_TYPE_DRIVERATA "APPLE_DRIVER_ATA"
518 #define APPLE_PART_TYPE_DRIVERIOKIT "APPLE_DRIVER_IOKIT"
519 #define APPLE_PART_TYPE_FWDRIVER "APPLE_FWDRIVER"
520 #define APPLE_PART_TYPE_FWB_COMPONENT "FWB DRIVER COMPONENTS"
521 #define APPLE_PART_TYPE_FREE "APPLE_FREE"
522 #define APPLE_PART_TYPE_MAC "APPLE_HFS"
523 #define APPLE_PART_TYPE_NETBSD "NETBSD"
524 #define APPLE_PART_TYPE_NBSD_PPCBOOT "NETBSD/MACPPC"
525 #define APPLE_PART_TYPE_NBSD_68KBOOT "NETBSD/MAC68K"
526 #define APPLE_PART_TYPE_PATCHES "APPLE_PATCHES"
527 #define APPLE_PART_TYPE_PARTMAP "APPLE_PARTITION_MAP"
528 #define APPLE_PART_TYPE_PATCHES "APPLE_PATCHES"
529 #define APPLE_PART_TYPE_SCRATCH "APPLE_SCRATCH"
530 #define APPLE_PART_TYPE_UNIX "APPLE_UNIX_SVR2"
531
532 /*
533 * "pmBootArgs" for APPLE_UNIX_SVR2 partition.
534 * NetBSD/mac68k only uses Magic, Cluster, Type, and Flags.
535 */
536 struct apple_blockzeroblock {
537 uint32_t bzbMagic;
538 uint8_t bzbCluster;
539 uint8_t bzbType;
540 uint16_t bzbBadBlockInode;
541 uint16_t bzbFlags;
542 uint16_t bzbReserved;
543 uint32_t bzbCreationTime;
544 uint32_t bzbMountTime;
545 uint32_t bzbUMountTime;
546 };
547
548 #define APPLE_BZB_MAGIC 0xABADBABE
549 #define APPLE_BZB_TYPEFS 1
550 #define APPLE_BZB_TYPESWAP 3
551 #define APPLE_BZB_ROOTFS 0x8000
552 #define APPLE_BZB_USRFS 0x4000
553
554 /* ------------------------------------------
555 * hp300
556 *
557 */
558
559 /* volume header for "LIF" format volumes */
560
561 struct hp300_lifvol {
562 int16_t vol_id;
563 char vol_label[6];
564 int32_t vol_addr;
565 int16_t vol_oct;
566 int16_t vol_dummy;
567 int32_t vol_dirsize;
568 int16_t vol_version;
569 int16_t vol_zero;
570 int32_t vol_huh1;
571 int32_t vol_huh2;
572 int32_t vol_length;
573 };
574
575 /* LIF directory entry format */
576
577 struct hp300_lifdir {
578 char dir_name[10];
579 int16_t dir_type;
580 int32_t dir_addr;
581 int32_t dir_length;
582 char dir_toc[6];
583 int16_t dir_flag;
584 int32_t dir_exec;
585 };
586
587 /* load header for boot rom */
588 struct hp300_load {
589 int32_t address;
590 int32_t count;
591 };
592
593 #define HP300_VOL_ID -32768
594 #define HP300_VOL_OCT 4096
595 #define HP300_DIR_TYPE -5822
596 #define HP300_DIR_FLAG 0x8001 /* dont ask me! */
597 #define HP300_SECTSIZE 256
598
599 /* ------------------------------------------
600 * x86
601 *
602 */
603
604 /*
605 * Parameters for NetBSD /boot written to start of pbr code by installboot
606 */
607
608 struct x86_boot_params {
609 uint32_t bp_length; /* length of patchable data */
610 uint32_t bp_flags;
611 uint32_t bp_timeout; /* boot timeout in seconds */
612 uint32_t bp_consdev;
613 uint32_t bp_conspeed;
614 uint8_t bp_password[16]; /* md5 hash of password */
615 char bp_keymap[16]; /* keyboard traslation map */
616 };
617
618 #endif /* !defined(__ASSEMBLER__) */ /* } */
619
620 #define X86_BOOT_MAGIC(n) ('x' << 24 | 0x86b << 12 | 'm' << 4 | (n))
621 #define X86_BOOT_MAGIC_1 X86_BOOT_MAGIC(1) /* pbr.S */
622 #define X86_BOOT_MAGIC_2 X86_BOOT_MAGIC(2) /* bootxx.S */
623 #define X86_BOOT_MAGIC_PXE X86_BOOT_MAGIC(3) /* start_pxe.S */
624
625 /* values for bp_flags */
626 #define X86_BP_FLAGS_RESET_VIDEO 1
627 #define X86_BP_FLAGS_PASSWORD 2
628
629 /* values for bp_consdev */
630 #define X86_BP_CONSDEV_PC 0
631 #define X86_BP_CONSDEV_COM0 1
632 #define X86_BP_CONSDEV_COM1 2
633 #define X86_BP_CONSDEV_COM2 3
634 #define X86_BP_CONSDEV_COM3 4
635 #define X86_BP_CONSDEV_COM0KBD 5
636 #define X86_BP_CONSDEV_COM1KBD 6
637 #define X86_BP_CONSDEV_COM2KBD 7
638 #define X86_BP_CONSDEV_COM3KBD 8
639
640 #if !defined(__ASSEMBLER__) /* { */
641
642 /* ------------------------------------------
643 * macppc
644 */
645
646 #define MACPPC_BOOT_BLOCK_OFFSET 2048
647 #define MACPPC_BOOT_BLOCK_BLOCKSIZE 512
648 #define MACPPC_BOOT_BLOCK_MAX_SIZE 2048 /* XXX: could be up to 6144 */
649 /* Magic string -- 32 bytes long (including the NUL) */
650 #define MACPPC_BBINFO_MAGIC "NetBSD/macppc bootxx 20020515"
651
652 /* ------------------------------------------
653 * news68k, newsmips
654 */
655
656 #define NEWS_BOOT_BLOCK_LABELOFFSET 64 /* XXX from <machine/disklabel.h> */
657 #define NEWS_BOOT_BLOCK_OFFSET 0
658 #define NEWS_BOOT_BLOCK_BLOCKSIZE 512
659 #define NEWS_BOOT_BLOCK_MAX_SIZE (512 * 16)
660
661 /* Magic string -- 32 bytes long (including the NUL) */
662 #define NEWS68K_BBINFO_MAGIC "NetBSD/news68k bootxx 20020518"
663 #define NEWSMIPS_BBINFO_MAGIC "NetBSD/newsmips bootxx 20020518"
664
665 /* ------------------------------------------
666 * next68k
667 */
668
669 #define NEXT68K_LABEL_MAXPARTITIONS 8 /* number of partitions in next68k_disklabel */
670 #define NEXT68K_LABEL_CPULBLLEN 24
671 #define NEXT68K_LABEL_MAXDNMLEN 24
672 #define NEXT68K_LABEL_MAXTYPLEN 24
673 #define NEXT68K_LABEL_MAXBFLEN 24
674 #define NEXT68K_LABEL_MAXHNLEN 32
675 #define NEXT68K_LABEL_MAXMPTLEN 16
676 #define NEXT68K_LABEL_MAXFSTLEN 8
677 #define NEXT68K_LABEL_NBAD 1670 /* sized to make label ~= 8KB */
678
679 struct next68k_partition {
680 int32_t cp_offset; /* starting sector */
681 int32_t cp_size; /* number of sectors in partition */
682 int16_t cp_bsize; /* block size in bytes */
683 int16_t cp_fsize; /* filesystem basic fragment size */
684 char cp_opt; /* optimization type: 's'pace/'t'ime */
685 char cp_pad1;
686 int16_t cp_cpg; /* filesystem cylinders per group */
687 int16_t cp_density; /* bytes per inode density */
688 int8_t cp_minfree; /* minfree (%) */
689 int8_t cp_newfs; /* run newfs during init */
690 char cp_mountpt[NEXT68K_LABEL_MAXMPTLEN];
691 /* default/standard mount point */
692 int8_t cp_automnt; /* auto-mount when inserted */
693 char cp_type[NEXT68K_LABEL_MAXFSTLEN]; /* file system type name */
694 char cp_pad2;
695 } __attribute__ ((packed));
696
697 /* The disklabel the way it is on the disk */
698 struct next68k_disklabel {
699 int32_t cd_version; /* label version */
700 int32_t cd_label_blkno; /* block # of this label */
701 int32_t cd_size; /* size of media area (sectors) */
702 char cd_label[NEXT68K_LABEL_CPULBLLEN]; /* disk name (label) */
703 uint32_t cd_flags; /* flags */
704 uint32_t cd_tag; /* volume tag */
705 char cd_name[NEXT68K_LABEL_MAXDNMLEN]; /* drive (hardware) name */
706 char cd_type[NEXT68K_LABEL_MAXTYPLEN]; /* drive type */
707 int32_t cd_secsize; /* # of bytes per sector */
708 int32_t cd_ntracks; /* # of tracks per cylinder */
709 int32_t cd_nsectors; /* # of data sectors per track */
710 int32_t cd_ncylinders; /* # of data cylinders per unit */
711 int32_t cd_rpm; /* rotational speed */
712 int16_t cd_front; /* # of sectors in "front porch" */
713 int16_t cd_back; /* # of sectors in "back porch" */
714 int16_t cd_ngroups; /* # of alt groups */
715 int16_t cd_ag_size; /* alt group size (sectors) */
716 int16_t cd_ag_alts; /* alternate sectors / alt group */
717 int16_t cd_ag_off; /* sector offset to first alternate */
718 int32_t cd_boot_blkno[2]; /* boot program locations */
719 char cd_kernel[NEXT68K_LABEL_MAXBFLEN]; /* default kernel name */
720 char cd_hostname[NEXT68K_LABEL_MAXHNLEN];
721 /* host name (usu. where disk was labeled) */
722 char cd_rootpartition; /* root partition letter e.g. 'a' */
723 char cd_rwpartition; /* r/w partition letter e.g. 'b' */
724 struct next68k_partition cd_partitions[NEXT68K_LABEL_MAXPARTITIONS];
725
726 union {
727 uint16_t CD_v3_checksum; /* label version 3 checksum */
728 int32_t CD_bad[NEXT68K_LABEL_NBAD];
729 /* block number that is bad */
730 } cd_un;
731 uint16_t cd_checksum; /* label version 1 or 2 checksum */
732 } __attribute__ ((packed));
733
734 #define NEXT68K_LABEL_cd_checksum cd_checksum
735 #define NEXT68K_LABEL_cd_v3_checksum cd_un.CD_v3_checksum
736 #define NEXT68K_LABEL_cd_bad cd_un.CD_bad
737
738 #define NEXT68K_LABEL_SECTOR 0 /* sector containing label */
739 #define NEXT68K_LABEL_OFFSET 0 /* offset of label in sector */
740 #define NEXT68K_LABEL_SIZE 8192 /* size of label */
741 #define NEXT68K_LABEL_CD_V1 0x4e655854 /* version #1: "NeXT" */
742 #define NEXT68K_LABEL_CD_V2 0x646c5632 /* version #2: "dlV2" */
743 #define NEXT68K_LABEL_CD_V3 0x646c5633 /* version #3: "dlV3" */
744 #define NEXT68K_LABEL_DEFAULTFRONTPORCH (160 * 2)
745 #define NEXT68K_LABEL_DEFAULTBOOT0_1 (32 * 2)
746 #define NEXT68K_LABEL_DEFAULTBOOT0_2 (96 * 2)
747
748 /* ------------------------------------------
749 * pmax --
750 * PMAX (DECstation / MIPS) boot block information
751 */
752
753 /*
754 * If mode is 0, there is just one sequence of blocks and one Dec_BootMap
755 * is used. If mode is 1, there are multiple sequences of blocks
756 * and multiple Dec_BootMaps are used, the last with numBlocks = 0.
757 */
758 struct pmax_boot_map {
759 int32_t num_blocks; /* Number of blocks to read. */
760 int32_t start_block; /* Starting block on disk. */
761 };
762
763 /*
764 * This is the structure of a disk or tape boot block. The boot_map
765 * can either be a single boot count and start block (contiguous mode)
766 * or a list of up to 61 (to fill a 512 byte sector) block count and
767 * start block pairs. Under NetBSD, contiguous mode is always used.
768 */
769 struct pmax_boot_block {
770 uint8_t pad[8];
771 int32_t magic; /* PMAX_BOOT_MAGIC */
772 int32_t mode; /* Mode for boot info. */
773 uint32_t load_addr; /* Address to start loading. */
774 uint32_t exec_addr; /* Address to start execing. */
775 struct pmax_boot_map map[61]; /* boot program section(s). */
776 } __attribute__((__packed__));
777
778 #define PMAX_BOOT_MAGIC 0x0002757a
779 #define PMAX_BOOTMODE_CONTIGUOUS 0
780 #define PMAX_BOOTMODE_SCATTERED 1
781
782 #define PMAX_BOOT_BLOCK_OFFSET 0
783 #define PMAX_BOOT_BLOCK_BLOCKSIZE 512
784
785
786 /* ------------------------------------------
787 * sparc
788 */
789
790 #define SPARC_BOOT_BLOCK_OFFSET 512
791 #define SPARC_BOOT_BLOCK_BLOCKSIZE 512
792 #define SPARC_BOOT_BLOCK_MAX_SIZE (512 * 15)
793 /* Magic string -- 32 bytes long (including the NUL) */
794 #define SPARC_BBINFO_MAGIC "NetBSD/sparc bootxx 20020515"
795
796
797 /* ------------------------------------------
798 * sparc64
799 */
800
801 #define SPARC64_BOOT_BLOCK_OFFSET 512
802 #define SPARC64_BOOT_BLOCK_BLOCKSIZE 512
803 #define SPARC64_BOOT_BLOCK_MAX_SIZE (512 * 15)
804
805
806 /* ------------------------------------------
807 * sun68k (sun2, sun3)
808 */
809
810 #define SUN68K_BOOT_BLOCK_OFFSET 512
811 #define SUN68K_BOOT_BLOCK_BLOCKSIZE 512
812 #define SUN68K_BOOT_BLOCK_MAX_SIZE (512 * 15)
813 /* Magic string -- 32 bytes long (including the NUL) */
814 #define SUN68K_BBINFO_MAGIC "NetBSD/sun68k bootxx 20020515"
815
816
817 /* ------------------------------------------
818 * vax --
819 * VAX boot block information
820 */
821
822 struct vax_boot_block {
823 /* Note that these don't overlap any of the pmax boot block */
824 uint8_t pad0[2];
825 uint8_t bb_id_offset; /* offset in words to id (magic1)*/
826 uint8_t bb_mbone; /* must be one */
827 uint16_t bb_lbn_hi; /* lbn (hi word) of bootstrap */
828 uint16_t bb_lbn_low; /* lbn (low word) of bootstrap */
829 uint8_t pad1[332];
830
831 /* The rest of these fields are identification area and describe
832 * the secondary block for uVAX VMB.
833 */
834 uint8_t bb_magic1; /* magic number */
835 uint8_t bb_mbz1; /* must be zero */
836 uint8_t bb_pad1; /* any value */
837 uint8_t bb_sum1; /* ~(magic1 + mbz1 + pad1) */
838
839 uint8_t bb_mbz2; /* must be zero */
840 uint8_t bb_volinfo; /* volinfo */
841 uint8_t bb_pad2a; /* any value */
842 uint8_t bb_pad2b; /* any value */
843
844 uint32_t bb_size; /* size in blocks of bootstrap */
845 uint32_t bb_load; /* load offset to bootstrap */
846 uint32_t bb_entry; /* byte offset in bootstrap */
847 uint32_t bb_sum3; /* sum of previous 3 fields */
848
849 /* The rest is unused.
850 */
851 uint8_t pad2[148];
852 } __attribute__((__packed__));
853
854 #define VAX_BOOT_MAGIC1 0x18 /* size of BB info? */
855 #define VAX_BOOT_VOLINFO_NONE 0x00 /* no special info */
856 #define VAX_BOOT_VOLINFO_SS 0x01 /* single sided */
857 #define VAX_BOOT_VOLINFO_DS 0x81 /* double sided */
858
859 #define VAX_BOOT_SIZE 15 /* 15 blocks */
860 #define VAX_BOOT_LOAD 0 /* no load offset */
861 #define VAX_BOOT_ENTRY 0x200 /* one block in */
862
863 #define VAX_BOOT_BLOCK_OFFSET 0
864 #define VAX_BOOT_BLOCK_BLOCKSIZE 512
865
866
867 /* ------------------------------------------
868 * x68k
869 */
870
871 #define X68K_BOOT_BLOCK_OFFSET 0
872 #define X68K_BOOT_BLOCK_BLOCKSIZE 512
873 #define X68K_BOOT_BLOCK_MAX_SIZE (512 * 16)
874 /* Magic string -- 32 bytes long (including the NUL) */
875 #define X68K_BBINFO_MAGIC "NetBSD/x68k bootxx 20020601"
876
877 #endif /* !defined(__ASSEMBLER__) */ /* } */
878
879 #endif /* !_SYS_BOOTBLOCK_H */
Cache object: 6891555694f97d11ee4ec38de66c639a
|