Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 1 | /* |
Kiet Lam | aa8e15a | 2014-02-11 23:30:06 -0800 | [diff] [blame^] | 2 | * Copyright (c) 2012-2013 Qualcomm Atheros, Inc. |
| 3 | * All Rights Reserved. |
| 4 | * Qualcomm Atheros Confidential and Proprietary. |
Gopichand Nakkala | 92f07d8 | 2013-01-08 21:16:34 -0800 | [diff] [blame] | 5 | */ |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 6 | #if !defined( __WLAN_QCT_PACK_ALIGN_H ) |
| 7 | #define __WLAN_QCT_PACK_ALIGN_H |
| 8 | |
| 9 | /**========================================================================= |
| 10 | |
| 11 | \file wlan_pack_align.h |
| 12 | |
| 13 | \brief pack and align primitives |
| 14 | |
| 15 | Definitions for platform independent means of packing and aligning |
| 16 | data structures |
| 17 | |
| 18 | Copyright 2009 (c) Qualcomm, Incorporated. All Rights Reserved. |
| 19 | |
| 20 | Qualcomm Confidential and Proprietary. |
| 21 | |
| 22 | ========================================================================*/ |
| 23 | |
| 24 | /* |
| 25 | |
| 26 | Place the macro WPT_PACK_START above a structure declaration to pack. We |
| 27 | are not going to allow modifying the pack size because pack size cannot be |
| 28 | specified in AMSS and GNU. Place the macro WPT_PACK_END below a structure |
| 29 | declaration to stop the pack. This requirement is necessitated by Windows |
| 30 | which need pragma based prolog and epilog. |
| 31 | |
| 32 | Pack-size > 1-byte is not supported since gcc and arm do not support that. |
| 33 | |
| 34 | Here are some examples |
| 35 | |
| 36 | 1. Pack-size 1-byte foo_t across all platforms |
| 37 | |
| 38 | WPT_PACK_START |
| 39 | typedef WPT_PACK_PRE struct foo_s { ... } WPT_PACK_POST foo_t; |
| 40 | WPT_PACK_END |
| 41 | |
| 42 | 2. 2-byte alignment for foo_t across all platforms |
| 43 | |
| 44 | typedef WPT_ALIGN_PRE(2) struct foo_s { ... } WPT_ALIGN_POST(2) foo_t; |
| 45 | |
| 46 | 3. Pack-size 1-byte and 2-byte alignment for foo_t across all platforms |
| 47 | |
| 48 | WPT_PACK_START |
| 49 | typedef WPT_PACK_PRE WPT_ALIGN_PRE(2) struct foo_s { ... } WPT_ALIGN_POST(2) WPT_PACK_POST foo_t; |
| 50 | WPT_PACK_END |
| 51 | |
| 52 | */ |
| 53 | |
| 54 | #if defined __GNUC__ |
| 55 | |
| 56 | #define WPT_PACK_START |
| 57 | #define WPT_PACK_END |
| 58 | |
| 59 | #define WPT_PACK_PRE |
| 60 | #define WPT_PACK_POST __attribute__((__packed__)) |
| 61 | |
| 62 | #define WPT_ALIGN_PRE(__value) |
| 63 | #define WPT_ALIGN_POST(__value) __attribute__((__aligned__(__value))) |
| 64 | |
| 65 | #elif defined __arm |
| 66 | |
| 67 | #define WPT_PACK_START |
| 68 | #define WPT_PACK_END |
| 69 | |
| 70 | #define WPT_PACK_PRE __packed |
| 71 | #define WPT_PACK_POST |
| 72 | |
| 73 | #define WPT_ALIGN_PRE(__value) __align(__value) |
| 74 | #define WPT_ALIGN_POST(__value) |
| 75 | |
| 76 | #elif defined _MSC_VER |
| 77 | |
Madan Mohan Koyyalamudi | a53c4dc | 2012-11-13 10:35:42 -0800 | [diff] [blame] | 78 | #define WPT_PACK_START __pragma(pack(push,1)) |
| 79 | #define WPT_PACK_END __pragma(pack(pop)) |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 80 | |
| 81 | #define WPT_PACK_PRE |
| 82 | #define WPT_PACK_POST |
| 83 | |
| 84 | #define WPT_ALIGN_PRE(__value) __declspec(align(__value)) |
| 85 | #define WPT_ALIGN_POST(__value) |
| 86 | |
| 87 | #else |
| 88 | |
| 89 | #error Unsupported compiler!!! |
| 90 | |
| 91 | #endif |
| 92 | |
| 93 | #endif // __WLAN_QCT_PACK_ALIGN_H |