1eb03840aSAxel Dörfler/*
2a9ae9781SAxel Dörfler * Copyright 2003-2008, Axel D��rfler, axeld@pinc-software.de.
3fe58583dSAxel Dörfler * Distributed under the terms of the MIT License.
4fe58583dSAxel Dörfler */
5eb03840aSAxel Dörfler#ifndef BFS_ENDIAN_H
6eb03840aSAxel Dörfler#define BFS_ENDIAN_H
7eb03840aSAxel Dörfler
8eb03840aSAxel Dörfler
9c391f84bSIngo Weinhold#include "system_dependencies.h"
10eb03840aSAxel Dörfler
11eb03840aSAxel Dörfler
12eb03840aSAxel Dörfler#if !defined(BFS_LITTLE_ENDIAN_ONLY) && !defined(BFS_BIG_ENDIAN_ONLY)
13eb03840aSAxel Dörfler//	default setting; BFS is now primarily a little endian file system
14eb03840aSAxel Dörfler#	define BFS_LITTLE_ENDIAN_ONLY
15eb03840aSAxel Dörfler#endif
162522f69eSFrançois Revol#if defined(BFS_LITTLE_ENDIAN_ONLY) && defined(BFS_BIG_ENDIAN_ONLY)
172522f69eSFrançois Revol#	error Building BFS with both big and little endian is not supported.
182522f69eSFrançois Revol#endif
19eb03840aSAxel Dörfler
20eb03840aSAxel Dörfler
210686bd47SAxel Dörfler#if defined(BFS_LITTLE_ENDIAN_ONLY) && B_HOST_IS_LENDIAN \
220686bd47SAxel Dörfler	|| defined(BFS_BIG_ENDIAN_ONLY) && B_HOST_IS_BENDIAN
230686bd47SAxel Dörfler		/* host is BFS endian */
24fe58583dSAxel Dörfler#	define BFS_NATIVE_ENDIAN
250686bd47SAxel Dörfler#	define BFS_ENDIAN_TO_HOST_INT16(value) value
260686bd47SAxel Dörfler#	define BFS_ENDIAN_TO_HOST_INT32(value) value
270686bd47SAxel Dörfler#	define BFS_ENDIAN_TO_HOST_INT64(value) value
280686bd47SAxel Dörfler#	define HOST_ENDIAN_TO_BFS_INT16(value) value
290686bd47SAxel Dörfler#	define HOST_ENDIAN_TO_BFS_INT32(value) value
300686bd47SAxel Dörfler#	define HOST_ENDIAN_TO_BFS_INT64(value) value
310686bd47SAxel Dörfler#elif defined(BFS_LITTLE_ENDIAN_ONLY) && B_HOST_IS_BENDIAN \
320686bd47SAxel Dörfler	|| defined(BFS_BIG_ENDIAN_ONLY) && B_HOST_IS_LENDIAN
330686bd47SAxel Dörfler		/* host is big endian, BFS is little endian or vice versa */
340686bd47SAxel Dörfler#	define BFS_ENDIAN_TO_HOST_INT16(value) __swap_int16(value)
350686bd47SAxel Dörfler#	define BFS_ENDIAN_TO_HOST_INT32(value) __swap_int32(value)
360686bd47SAxel Dörfler#	define BFS_ENDIAN_TO_HOST_INT64(value) __swap_int64(value)
370686bd47SAxel Dörfler#	define HOST_ENDIAN_TO_BFS_INT16(value) __swap_int16(value)
380686bd47SAxel Dörfler#	define HOST_ENDIAN_TO_BFS_INT32(value) __swap_int32(value)
390686bd47SAxel Dörfler#	define HOST_ENDIAN_TO_BFS_INT64(value) __swap_int64(value)
40eb03840aSAxel Dörfler#else
41a9ae9781SAxel Dörfler	// TODO: maybe build a version that supports both, big & little endian?
42eb03840aSAxel Dörfler	//		But since that will need some kind of global data (to
43eb03840aSAxel Dörfler	//		know of what type this file system is), it's probably
44eb03840aSAxel Dörfler	//		something for the boot loader; anything else would be
45eb03840aSAxel Dörfler	//		a major pain.
46eb03840aSAxel Dörfler#endif
47eb03840aSAxel Dörfler
48eb03840aSAxel Dörfler#endif	/* BFS_ENDIAN_H */