xref: /haiku/src/add-ons/kernel/file_systems/bfs/bfs_endian.h (revision fc7456e9b1ec38c941134ed6d01c438cf289381e)
1 /*
2  * Copyright 2003-2008, Axel Dörfler, axeld@pinc-software.de.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef BFS_ENDIAN_H
6 #define BFS_ENDIAN_H
7 
8 
9 #include "system_dependencies.h"
10 
11 
12 #if !defined(BFS_LITTLE_ENDIAN_ONLY) && !defined(BFS_BIG_ENDIAN_ONLY)
13 //	default setting; BFS is now primarily a little endian file system
14 #	define BFS_LITTLE_ENDIAN_ONLY
15 #endif
16 #if defined(BFS_LITTLE_ENDIAN_ONLY) && defined(BFS_BIG_ENDIAN_ONLY)
17 #	error Building BFS with both big and little endian is not supported.
18 #endif
19 
20 
21 #if defined(BFS_LITTLE_ENDIAN_ONLY) && B_HOST_IS_LENDIAN \
22 	|| defined(BFS_BIG_ENDIAN_ONLY) && B_HOST_IS_BENDIAN
23 		/* host is BFS endian */
24 #	define BFS_NATIVE_ENDIAN
25 #	define BFS_ENDIAN_TO_HOST_INT16(value) (value)
26 #	define BFS_ENDIAN_TO_HOST_INT32(value) (value)
27 #	define BFS_ENDIAN_TO_HOST_INT64(value) (value)
28 #	define HOST_ENDIAN_TO_BFS_INT16(value) (value)
29 #	define HOST_ENDIAN_TO_BFS_INT32(value) (value)
30 #	define HOST_ENDIAN_TO_BFS_INT64(value) (value)
31 #elif defined(BFS_LITTLE_ENDIAN_ONLY) && B_HOST_IS_BENDIAN \
32 	|| defined(BFS_BIG_ENDIAN_ONLY) && B_HOST_IS_LENDIAN
33 		/* host is big endian, BFS is little endian or vice versa */
34 #	define BFS_ENDIAN_TO_HOST_INT16(value) __swap_int16(value)
35 #	define BFS_ENDIAN_TO_HOST_INT32(value) __swap_int32(value)
36 #	define BFS_ENDIAN_TO_HOST_INT64(value) __swap_int64(value)
37 #	define HOST_ENDIAN_TO_BFS_INT16(value) __swap_int16(value)
38 #	define HOST_ENDIAN_TO_BFS_INT32(value) __swap_int32(value)
39 #	define HOST_ENDIAN_TO_BFS_INT64(value) __swap_int64(value)
40 #else
41 	// TODO: maybe build a version that supports both, big & little endian?
42 	//		But since that will need some kind of global data (to
43 	//		know of what type this file system is), it's probably
44 	//		something for the boot loader; anything else would be
45 	//		a major pain.
46 #endif
47 
48 #endif	/* BFS_ENDIAN_H */
49