blob: fb15b2ab12e36e9945a3d90be551a65bf9c178d1 [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
Jeff Johnson32d95a32012-09-10 13:15:23 -07002 * Copyright (c) 2012, The Linux Foundation. All rights reserved.
Jeff Johnson295189b2012-06-20 16:38:30 -07003 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20 */
21
22#if !defined( __WLAN_QCT_PACK_ALIGN_H )
23#define __WLAN_QCT_PACK_ALIGN_H
24
25/**=========================================================================
26
27 \file wlan_pack_align.h
28
29 \brief pack and align primitives
30
31 Definitions for platform independent means of packing and aligning
32 data structures
33
34 Copyright 2009 (c) Qualcomm, Incorporated. All Rights Reserved.
35
36 Qualcomm Confidential and Proprietary.
37
38 ========================================================================*/
39
40/*
41
42 Place the macro WPT_PACK_START above a structure declaration to pack. We
43 are not going to allow modifying the pack size because pack size cannot be
44 specified in AMSS and GNU. Place the macro WPT_PACK_END below a structure
45 declaration to stop the pack. This requirement is necessitated by Windows
46 which need pragma based prolog and epilog.
47
48 Pack-size > 1-byte is not supported since gcc and arm do not support that.
49
50 Here are some examples
51
52 1. Pack-size 1-byte foo_t across all platforms
53
54 WPT_PACK_START
55 typedef WPT_PACK_PRE struct foo_s { ... } WPT_PACK_POST foo_t;
56 WPT_PACK_END
57
58 2. 2-byte alignment for foo_t across all platforms
59
60 typedef WPT_ALIGN_PRE(2) struct foo_s { ... } WPT_ALIGN_POST(2) foo_t;
61
62 3. Pack-size 1-byte and 2-byte alignment for foo_t across all platforms
63
64 WPT_PACK_START
65 typedef WPT_PACK_PRE WPT_ALIGN_PRE(2) struct foo_s { ... } WPT_ALIGN_POST(2) WPT_PACK_POST foo_t;
66 WPT_PACK_END
67
68*/
69
70#if defined __GNUC__
71
72 #define WPT_PACK_START
73 #define WPT_PACK_END
74
75 #define WPT_PACK_PRE
76 #define WPT_PACK_POST __attribute__((__packed__))
77
78 #define WPT_ALIGN_PRE(__value)
79 #define WPT_ALIGN_POST(__value) __attribute__((__aligned__(__value)))
80
81#elif defined __arm
82
83 #define WPT_PACK_START
84 #define WPT_PACK_END
85
86 #define WPT_PACK_PRE __packed
87 #define WPT_PACK_POST
88
89 #define WPT_ALIGN_PRE(__value) __align(__value)
90 #define WPT_ALIGN_POST(__value)
91
92#elif defined _MSC_VER
93
94 #define WPT_PACK_START __pragma (pack(push,1))
95 #define WPT_PACK_END __pragma (pack(pop))
96
97 #define WPT_PACK_PRE
98 #define WPT_PACK_POST
99
100 #define WPT_ALIGN_PRE(__value) __declspec(align(__value))
101 #define WPT_ALIGN_POST(__value)
102
103#else
104
105 #error Unsupported compiler!!!
106
107#endif
108
109#endif // __WLAN_QCT_PACK_ALIGN_H