xref: /netbsd/sys/sys/bootblock.h (revision c4a72b64)
1 /*	$NetBSD: bootblock.h,v 1.11 2002/11/02 07:35:07 perry Exp $	*/
2 
3 /*-
4  * Copyright (c) 2002 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 #ifndef _SYS_BOOTBLOCK_H
100 #define	_SYS_BOOTBLOCK_H
101 
102 #ifdef _KERNEL
103 #include <sys/stdint.h>
104 #else
105 #include <stdint.h>
106 #endif
107 
108 /* ------------------------------------------
109  * shared --
110  *	definintions shared by many platforms
111  */
112 
113 	/* Maximum # of blocks in bbi_block_table, each bbi_block_size long */
114 #define	SHARED_BBINFO_MAXBLOCKS	118	/* so sizeof(shared_bbinfo) == 512 */
115 
116 struct shared_bbinfo {
117 	uint8_t bbi_magic[32];
118 	int32_t bbi_block_size;
119 	int32_t bbi_block_count;
120 	int32_t bbi_block_table[SHARED_BBINFO_MAXBLOCKS];
121 };
122 
123 
124 /* ------------------------------------------
125  * alpha --
126  *	Alpha (disk, but also tape) Boot Block.
127  *
128  *	See Section (III) 3.6.1 of the Alpha Architecture Reference Manual.
129  */
130 
131 struct alpha_boot_block {
132 	uint64_t bb_data[63];		/* data (disklabel, also as below) */
133 	uint64_t bb_cksum;		/* checksum of the boot block,
134 					 * taken as uint64_t's
135 					 */
136 };
137 #define	bb_secsize	bb_data[60]	/* secondary size (blocks) */
138 #define	bb_secstart	bb_data[61]	/* secondary start (blocks) */
139 #define	bb_flags	bb_data[62]	/* unknown flags (set to zero) */
140 
141 #define	ALPHA_BOOT_BLOCK_OFFSET		0	/* offset of boot block. */
142 #define	ALPHA_BOOT_BLOCK_BLOCKSIZE	512	/* block size for sector
143 						 * size/start, and for boot
144 						 * block itself.
145 						 */
146 
147 #define	ALPHA_BOOT_BLOCK_CKSUM(bb,cksum)				\
148 	do {								\
149 		const struct alpha_boot_block *_bb = (bb);		\
150 		uint64_t _cksum;					\
151 		int _i;							\
152 									\
153 		_cksum = 0;						\
154 		for (_i = 0;						\
155 		    _i < (sizeof _bb->bb_data / sizeof _bb->bb_data[0]); \
156 		    _i++)						\
157 			_cksum += _bb->bb_data[_i];			\
158 		*(cksum) = _cksum;					\
159 	} while (/*CONSTCOND*/ 0)
160 
161 /* ------------------------------------------
162  * apple --
163  *	Apple computers boot block related information
164  */
165 
166 /*
167  *	Driver Descriptor Map, from Inside Macintosh: Devices, SCSI Manager
168  *	pp 12-13.  The driver descriptor map always resides on physical block 0.
169  */
170 struct apple_drvr_descriptor {
171 	uint32_t	descBlock;	/* first block of driver */
172 	uint16_t	descSize;	/* driver size in blocks */
173 	uint16_t	descType;	/* system type */
174 };
175 
176 /*
177  *	system types; Apple reserves 0-15
178  */
179 #define	APPLE_DRVR_TYPE_MACINTOSH	1
180 
181 #define	APPLE_DRVR_MAP_MAGIC		0x4552
182 #define	APPLE_DRVR_MAP_MAX_DESCRIPTORS	61
183 
184 struct apple_drvr_map {
185 	uint16_t	sbSig;		/* map signature */
186 	uint16_t	sbBlockSize;	/* block size of device */
187 	uint32_t	sbBlkCount;	/* number of blocks on device */
188 	uint16_t	sbDevType;	/* (used internally by ROM) */
189 	uint16_t	sbDevID;	/* (used internally by ROM) */
190 	uint32_t	sbData;		/* (used internally by ROM) */
191 	uint16_t	sbDrvrCount;	/* number of driver descriptors */
192 	struct apple_drvr_descriptor sb_dd[APPLE_DRVR_MAP_MAX_DESCRIPTORS];
193 	uint16_t	pad[3];
194 } __attribute__ ((packed));
195 
196 /*
197  *	Partition map structure from Inside Macintosh: Devices, SCSI Manager
198  *	pp. 13-14.  The partition map always begins on physical block 1.
199  *
200  *	With the exception of block 0, all blocks on the disk must belong to
201  *	exactly one partition.  The partition map itself belongs to a partition
202  *	of type `APPLE_PARTITION_MAP', and is not limited in size by anything
203  *	other than available disk space.  The partition map is not necessarily
204  *	the first partition listed.
205  */
206 #define	APPLE_PART_MAP_ENTRY_MAGIC	0x504d
207 
208 struct apple_part_map_entry {
209 	uint16_t	pmSig;		/* partition signature */
210 	uint16_t	pmSigPad;	/* (reserved) */
211 	uint32_t	pmMapBlkCnt;	/* number of blocks in partition map */
212 	uint32_t	pmPyPartStart;	/* first physical block of partition */
213 	uint32_t	pmPartBlkCnt;	/* number of blocks in partition */
214 	uint8_t		pmPartName[32];	/* partition name */
215 	uint8_t		pmPartType[32];	/* partition type */
216 	uint32_t	pmLgDataStart;	/* first logical block of data area */
217 	uint32_t	pmDataCnt;	/* number of blocks in data area */
218 	uint32_t	pmPartStatus;	/* partition status information */
219 	uint32_t	pmLgBootStart;	/* first logical block of boot code */
220 	uint32_t	pmBootSize;	/* size of boot code, in bytes */
221 	uint32_t	pmBootLoad;	/* boot code load address */
222 	uint32_t	pmBootLoad2;	/* (reserved) */
223 	uint32_t	pmBootEntry;	/* boot code entry point */
224 	uint32_t	pmBootEntry2;	/* (reserved) */
225 	uint32_t	pmBootCksum;	/* boot code checksum */
226 	int8_t		pmProcessor[16]; /* processor type (e.g. "68020") */
227 	uint8_t		pmBootArgs[128]; /* A/UX boot arguments */
228 	uint8_t		pad[248];	/* pad to end of block */
229 };
230 
231 #define	APPLE_PART_TYPE_DRIVER		"APPLE_DRIVER"
232 #define	APPLE_PART_TYPE_DRIVER43	"APPLE_DRIVER43"
233 #define	APPLE_PART_TYPE_DRIVERATA	"APPLE_DRIVER_ATA"
234 #define	APPLE_PART_TYPE_DRIVERIOKIT	"APPLE_DRIVER_IOKIT"
235 #define	APPLE_PART_TYPE_FWDRIVER	"APPLE_FWDRIVER"
236 #define	APPLE_PART_TYPE_FWB_COMPONENT	"FWB DRIVER COMPONENTS"
237 #define	APPLE_PART_TYPE_FREE		"APPLE_FREE"
238 #define	APPLE_PART_TYPE_MAC		"APPLE_HFS"
239 #define	APPLE_PART_TYPE_NETBSD		"NETBSD"
240 #define	APPLE_PART_TYPE_NBSD_PPCBOOT	"NETBSD/MACPPC"
241 #define	APPLE_PART_TYPE_NBSD_68KBOOT	"NETBSD/MAC68K"
242 #define	APPLE_PART_TYPE_PATCHES		"APPLE_PATCHES"
243 #define	APPLE_PART_TYPE_PARTMAP		"APPLE_PARTITION_MAP"
244 #define	APPLE_PART_TYPE_PATCHES		"APPLE_PATCHES"
245 #define	APPLE_PART_TYPE_SCRATCH		"APPLE_SCRATCH"
246 #define	APPLE_PART_TYPE_UNIX		"APPLE_UNIX_SVR2"
247 
248 
249 /* ------------------------------------------
250  * macppc
251  */
252 
253 #define	MACPPC_BOOT_BLOCK_OFFSET	2048
254 #define	MACPPC_BOOT_BLOCK_BLOCKSIZE	512
255 #define	MACPPC_BOOT_BLOCK_MAX_SIZE	2048	/* XXX: could be up to 6144 */
256 	/* Magic string -- 32 bytes long (including the NUL) */
257 #define	MACPPC_BBINFO_MAGIC		"NetBSD/macppc bootxx   20020515"
258 
259 /* ------------------------------------------
260  * news68k, newsmips
261  */
262 
263 #define	NEWS_BOOT_BLOCK_LABELOFFSET	64 /* XXX from <machine/disklabel.h> */
264 #define	NEWS_BOOT_BLOCK_OFFSET		0
265 #define	NEWS_BOOT_BLOCK_BLOCKSIZE	512
266 #define	NEWS_BOOT_BLOCK_MAX_SIZE	(512 * 16)
267 
268 	/* Magic string -- 32 bytes long (including the NUL) */
269 #define	NEWS68K_BBINFO_MAGIC		"NetBSD/news68k bootxx  20020518"
270 #define	NEWSMIPS_BBINFO_MAGIC		"NetBSD/newsmips bootxx 20020518"
271 
272 /* ------------------------------------------
273  * pmax --
274  *	PMAX (DECstation / MIPS) boot block information
275  */
276 
277 /*
278  * If mode is 0, there is just one sequence of blocks and one Dec_BootMap
279  * is used.  If mode is 1, there are multiple sequences of blocks
280  * and multiple Dec_BootMaps are used, the last with numBlocks = 0.
281  */
282 struct pmax_boot_map {
283 	int32_t	num_blocks;		/* Number of blocks to read. */
284 	int32_t	start_block;		/* Starting block on disk. */
285 };
286 
287 /*
288  * This is the structure of a disk or tape boot block.  The boot_map
289  * can either be a single boot count and start block (contiguous mode)
290  * or a list of up to 61 (to fill a 512 byte sector) block count and
291  * start block pairs.  Under NetBSD, contiguous mode is always used.
292  */
293 struct pmax_boot_block {
294 	uint8_t		pad[8];
295 	int32_t		magic;			/* PMAX_BOOT_MAGIC */
296 	int32_t		mode;			/* Mode for boot info. */
297 	uint32_t	load_addr;		/* Address to start loading. */
298 	uint32_t	exec_addr;		/* Address to start execing. */
299 	struct		pmax_boot_map map[61];	/* boot program section(s). */
300 } __attribute__((__packed__));
301 
302 #define	PMAX_BOOT_MAGIC			0x0002757a
303 #define	PMAX_BOOTMODE_CONTIGUOUS	0
304 #define	PMAX_BOOTMODE_SCATTERED		1
305 
306 #define	PMAX_BOOT_BLOCK_OFFSET		0
307 #define	PMAX_BOOT_BLOCK_BLOCKSIZE	512
308 
309 
310 /* ------------------------------------------
311  * sparc
312  */
313 
314 #define	SPARC_BOOT_BLOCK_OFFSET		512
315 #define	SPARC_BOOT_BLOCK_BLOCKSIZE	512
316 #define	SPARC_BOOT_BLOCK_MAX_SIZE	(512 * 15)
317 	/* Magic string -- 32 bytes long (including the NUL) */
318 #define	SPARC_BBINFO_MAGIC		"NetBSD/sparc bootxx    20020515"
319 
320 
321 /* ------------------------------------------
322  * sparc64
323  */
324 
325 #define	SPARC64_BOOT_BLOCK_OFFSET	512
326 #define	SPARC64_BOOT_BLOCK_BLOCKSIZE	512
327 #define	SPARC64_BOOT_BLOCK_MAX_SIZE	(512 * 15)
328 
329 
330 /* ------------------------------------------
331  * sun68k (sun2, sun3)
332  */
333 
334 #define	SUN68K_BOOT_BLOCK_OFFSET	512
335 #define	SUN68K_BOOT_BLOCK_BLOCKSIZE	512
336 #define	SUN68K_BOOT_BLOCK_MAX_SIZE	(512 * 15)
337 	/* Magic string -- 32 bytes long (including the NUL) */
338 #define	SUN68K_BBINFO_MAGIC		"NetBSD/sun68k bootxx   20020515"
339 
340 
341 /* ------------------------------------------
342  * vax --
343  *	VAX boot block information
344  */
345 
346 struct vax_boot_block {
347 /* Note that these don't overlap any of the pmax boot block */
348 	uint8_t		pad0[2];
349 	uint8_t		bb_id_offset;	/* offset in words to id (magic1)*/
350 	uint8_t		bb_mbone;	/* must be one */
351 	uint16_t	bb_lbn_hi;	/* lbn (hi word) of bootstrap */
352 	uint16_t	bb_lbn_low;	/* lbn (low word) of bootstrap */
353 	uint8_t		pad1[332];
354 
355 	/* The rest of these fields are identification area and describe
356 	 * the secondary block for uVAX VMB.
357 	 */
358 	uint8_t		bb_magic1;	/* magic number */
359 	uint8_t		bb_mbz1;	/* must be zero */
360 	uint8_t		bb_pad1;	/* any value */
361 	uint8_t		bb_sum1;	/* ~(magic1 + mbz1 + pad1) */
362 
363 	uint8_t		bb_mbz2;	/* must be zero */
364 	uint8_t		bb_volinfo;	/* volinfo */
365 	uint8_t		bb_pad2a;	/* any value */
366 	uint8_t		bb_pad2b;	/* any value */
367 
368 	uint32_t	bb_size;	/* size in blocks of bootstrap */
369 	uint32_t	bb_load;	/* load offset to bootstrap */
370 	uint32_t	bb_entry;	/* byte offset in bootstrap */
371 	uint32_t	bb_sum3;	/* sum of previous 3 fields */
372 
373 	/* The rest is unused.
374 	 */
375 	uint8_t		pad2[148];
376 } __attribute__((__packed__));
377 
378 #define	VAX_BOOT_MAGIC1			0x18	/* size of BB info? */
379 #define	VAX_BOOT_VOLINFO_NONE		0x00	/* no special info */
380 #define	VAX_BOOT_VOLINFO_SS		0x01	/* single sided */
381 #define	VAX_BOOT_VOLINFO_DS		0x81	/* double sided */
382 
383 #define	VAX_BOOT_SIZE			15	/* 15 blocks */
384 #define	VAX_BOOT_LOAD			0	/* no load offset */
385 #define	VAX_BOOT_ENTRY			0x200	/* one block in */
386 
387 #define	VAX_BOOT_BLOCK_OFFSET		0
388 #define	VAX_BOOT_BLOCK_BLOCKSIZE	512
389 
390 
391 /* ------------------------------------------
392  * x68k
393  */
394 
395 #define X68K_BOOT_BLOCK_OFFSET		0
396 #define X68K_BOOT_BLOCK_BLOCKSIZE	512
397 #define X68K_BOOT_BLOCK_MAX_SIZE	(512 * 16)
398 	/* Magic string -- 32 bytes long (including the NUL) */
399 #define X68K_BBINFO_MAGIC		"NetBSD/x68k bootxx     20020601"
400 
401 #endif	/* !_SYS_BOOTBLOCK_H */
402