193490Sphk/*-
293490Sphk * Copyright (c) 2002 Poul-Henning Kamp
393490Sphk * Copyright (c) 2002 Networks Associates Technology, Inc.
493490Sphk * All rights reserved.
593490Sphk *
693490Sphk * This software was developed for the FreeBSD Project by Poul-Henning Kamp
793490Sphk * and NAI Labs, the Security Research Division of Network Associates, Inc.
893490Sphk * under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the
993490Sphk * DARPA CHATS research program.
1093490Sphk *
1193490Sphk * Redistribution and use in source and binary forms, with or without
1293490Sphk * modification, are permitted provided that the following conditions
1393490Sphk * are met:
1493490Sphk * 1. Redistributions of source code must retain the above copyright
1593490Sphk *    notice, this list of conditions and the following disclaimer.
1693490Sphk * 2. Redistributions in binary form must reproduce the above copyright
1793490Sphk *    notice, this list of conditions and the following disclaimer in the
1893490Sphk *    documentation and/or other materials provided with the distribution.
1993490Sphk * 3. The names of the authors may not be used to endorse or promote
2093490Sphk *    products derived from this software without specific prior written
2193490Sphk *    permission.
2293490Sphk *
2393490Sphk * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
2493490Sphk * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2593490Sphk * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2693490Sphk * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2793490Sphk * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2893490Sphk * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2993490Sphk * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3093490Sphk * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3193490Sphk * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3293490Sphk * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3393490Sphk * SUCH DAMAGE.
3493490Sphk *
3593490Sphk * $FreeBSD$
3693490Sphk */
3793490Sphk
3893490Sphk#ifndef _SYS_KERNELDUMP_H
3993490Sphk#define _SYS_KERNELDUMP_H
4093490Sphk
4193717Smarcel#include <machine/endian.h>
4293717Smarcel
4393717Smarcel#if BYTE_ORDER == LITTLE_ENDIAN
4493717Smarcel#define	dtoh32(x)	__bswap32(x)
4593717Smarcel#define	dtoh64(x)	__bswap64(x)
4693717Smarcel#define	htod32(x)	__bswap32(x)
4793717Smarcel#define	htod64(x)	__bswap64(x)
4893717Smarcel#elif BYTE_ORDER == BIG_ENDIAN
4993717Smarcel#define	dtoh32(x)	(x)
5093717Smarcel#define	dtoh64(x)	(x)
5193717Smarcel#define	htod32(x)	(x)
5293717Smarcel#define	htod64(x)	(x)
5393717Smarcel#endif
5493717Smarcel
5593717Smarcel/*
5693717Smarcel * All uintX_t fields are in dump byte order, which is the same as
5793717Smarcel * network byte order. Use the macros defined above to read or
5893717Smarcel * write the fields.
5993717Smarcel */
6093490Sphkstruct kerneldumpheader {
6193490Sphk	char		magic[20];
6293717Smarcel#define	KERNELDUMPMAGIC		"FreeBSD Kernel Dump"
63174920Srwatson#define	TEXTDUMPMAGIC		"FreeBSD Text Dump"
6496068Smux#define	KERNELDUMPMAGIC_CLEARED	"Cleared Kernel Dump"
6593490Sphk	char		architecture[12];
6693490Sphk	uint32_t	version;
6793717Smarcel#define	KERNELDUMPVERSION	1
6893490Sphk	uint32_t	architectureversion;
6996427Sgallatin#define	KERNELDUMP_ALPHA_VERSION	1
70190684Smarcel#define	KERNELDUMP_AMD64_VERSION	2
71190684Smarcel#define	KERNELDUMP_ARM_VERSION		1
72190684Smarcel#define	KERNELDUMP_I386_VERSION		2
73190684Smarcel#define	KERNELDUMP_IA64_VERSION		1
74214903Sgonzo#define	KERNELDUMP_MIPS_VERSION		1
75190684Smarcel#define	KERNELDUMP_POWERPC_VERSION	1
76105531Stmm#define	KERNELDUMP_SPARC64_VERSION	1
77190684Smarcel#define	KERNELDUMP_TEXT_VERSION		1
7893717Smarcel	uint64_t	dumplength;		/* excl headers */
7993717Smarcel	uint64_t	dumptime;
8093490Sphk	uint32_t	blocksize;
8193490Sphk	char		hostname[64];
8293490Sphk	char		versionstring[192];
8393490Sphk	char		panicstring[192];
8493490Sphk	uint32_t	parity;
8593490Sphk};
8693490Sphk
8793717Smarcel/*
8893717Smarcel * Parity calculation is endian insensitive.
8993717Smarcel */
9093490Sphkstatic __inline u_int32_t
9193490Sphkkerneldump_parity(struct kerneldumpheader *kdhp)
9293490Sphk{
9393490Sphk	uint32_t *up, parity;
9493490Sphk	u_int i;
9593490Sphk
9693490Sphk	up = (uint32_t *)kdhp;
9793490Sphk	parity = 0;
9893490Sphk	for (i = 0; i < sizeof *kdhp; i += sizeof *up)
9993490Sphk		parity ^= *up++;
10093490Sphk	return (parity);
10193490Sphk}
10293490Sphk
103183527Speter#ifdef _KERNEL
104183527Spetervoid mkdumpheader(struct kerneldumpheader *kdh, char *magic, uint32_t archver,
105183527Speter    uint64_t dumplen, uint32_t blksz);
106183527Speter#endif
107183527Speter
10893649Smarcel#endif /* _SYS_KERNELDUMP_H */
109