Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 1 | /* |
Kiet Lam | 1ed83fc | 2014-02-19 01:15:45 -0800 | [diff] [blame] | 2 | * Copyright (c) 2012-2013 The Linux Foundation. All rights reserved. |
| 3 | * |
| 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. |
Gopichand Nakkala | 92f07d8 | 2013-01-08 21:16:34 -0800 | [diff] [blame] | 20 | */ |
Kiet Lam | 1ed83fc | 2014-02-19 01:15:45 -0800 | [diff] [blame] | 21 | |
| 22 | /* |
| 23 | * This file was originally distributed by Qualcomm Atheros, Inc. |
| 24 | * under proprietary terms before Copyright ownership was assigned |
| 25 | * to the Linux Foundation. |
| 26 | */ |
| 27 | |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 28 | #if !defined( __VOS_PACK_ALIGN_H ) |
| 29 | #define __VOS_PACK_ALIGN_H |
| 30 | |
| 31 | /**========================================================================= |
| 32 | |
| 33 | \file vos_pack_align.h |
| 34 | |
| 35 | \brief virtual Operating System Servies (vOS) pack and align primitives |
| 36 | |
| 37 | Definitions for platform independent means of packing and aligning |
| 38 | data structures |
| 39 | |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 40 | |
| 41 | ========================================================================*/ |
| 42 | |
| 43 | /* |
| 44 | |
| 45 | Place the macro VOS_PACK_START above a structure declaration to pack. We |
| 46 | are not going to allow modifying the pack size because pack size cannot be |
| 47 | specified in AMSS and GNU. Place the macro VOS_PACK_END below a structure |
| 48 | declaration to stop the pack. This requirement is necessitated by Windows |
| 49 | which need pragma based prolog and epilog. |
| 50 | |
| 51 | Pack-size > 1-byte is not supported since gcc and arm do not support that. |
| 52 | |
| 53 | Here are some examples |
| 54 | |
| 55 | 1. Pack-size 1-byte foo_t across all platforms |
| 56 | |
| 57 | VOS_PACK_START |
| 58 | typedef VOS_PACK_PRE struct foo_s { ... } VOS_PACK_POST foo_t; |
| 59 | VOS_PACK_END |
| 60 | |
| 61 | 2. 2-byte alignment for foo_t across all platforms |
| 62 | |
| 63 | typedef VOS_ALIGN_PRE(2) struct foo_s { ... } VOS_ALIGN_POST(2) foo_t; |
| 64 | |
| 65 | 3. Pack-size 1-byte and 2-byte alignment for foo_t across all platforms |
| 66 | |
| 67 | VOS_PACK_START |
| 68 | typedef VOS_PACK_PRE VOS_ALIGN_PRE(2) struct foo_s { ... } VOS_ALIGN_POST(2) VOS_PACK_POST foo_t; |
| 69 | VOS_PACK_END |
| 70 | |
| 71 | */ |
| 72 | |
| 73 | #if defined __GNUC__ |
| 74 | |
| 75 | #define VOS_PACK_START |
| 76 | #define VOS_PACK_END |
| 77 | |
| 78 | #define VOS_PACK_PRE |
| 79 | #define VOS_PACK_POST __attribute__((__packed__)) |
| 80 | |
| 81 | #define VOS_ALIGN_PRE(__value) |
| 82 | #define VOS_ALIGN_POST(__value) __attribute__((__aligned__(__value))) |
| 83 | |
| 84 | #elif defined __arm |
| 85 | |
| 86 | #define VOS_PACK_START |
| 87 | #define VOS_PACK_END |
| 88 | |
| 89 | #define VOS_PACK_PRE __packed |
| 90 | #define VOS_PACK_POST |
| 91 | |
| 92 | #define VOS_ALIGN_PRE(__value) __align(__value) |
| 93 | #define VOS_ALIGN_POST(__value) |
| 94 | |
| 95 | #elif defined _MSC_VER |
| 96 | |
Madan Mohan Koyyalamudi | a53c4dc | 2012-11-13 10:35:42 -0800 | [diff] [blame] | 97 | #define VOS_PACK_START __pragma(pack(push,1)) |
| 98 | #define VOS_PACK_END __pragma(pack(pop)) |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 99 | |
| 100 | #define VOS_PACK_PRE |
| 101 | #define VOS_PACK_POST |
| 102 | |
| 103 | #define VOS_ALIGN_PRE(__value) __declspec(align(__value)) |
| 104 | #define VOS_ALIGN_POST(__value) |
| 105 | |
| 106 | #else |
| 107 | |
| 108 | #error Unsupported compiler!!! |
| 109 | |
| 110 | #endif |
| 111 | |
| 112 | #endif // __VOSS_PACK_ALIGN_H |