Pinned to some recent date

Committer:
Simon Cooksey
Date:
Thu Nov 17 16:43:53 2016 +0000
Revision:
0:fb7af294d5d9
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Simon Cooksey 0:fb7af294d5d9 1 /**************************************************************************//**
Simon Cooksey 0:fb7af294d5d9 2 * @file core_cmSecureAccess.h
Simon Cooksey 0:fb7af294d5d9 3 * @brief CMSIS Cortex-M Core Secure Access Header File
Simon Cooksey 0:fb7af294d5d9 4 * @version XXX
Simon Cooksey 0:fb7af294d5d9 5 * @date 10. June 2016
Simon Cooksey 0:fb7af294d5d9 6 *
Simon Cooksey 0:fb7af294d5d9 7 * @note
Simon Cooksey 0:fb7af294d5d9 8 *
Simon Cooksey 0:fb7af294d5d9 9 ******************************************************************************/
Simon Cooksey 0:fb7af294d5d9 10 /* Copyright (c) 2016 ARM LIMITED
Simon Cooksey 0:fb7af294d5d9 11
Simon Cooksey 0:fb7af294d5d9 12 All rights reserved.
Simon Cooksey 0:fb7af294d5d9 13 Redistribution and use in source and binary forms, with or without
Simon Cooksey 0:fb7af294d5d9 14 modification, are permitted provided that the following conditions are met:
Simon Cooksey 0:fb7af294d5d9 15 - Redistributions of source code must retain the above copyright
Simon Cooksey 0:fb7af294d5d9 16 notice, this list of conditions and the following disclaimer.
Simon Cooksey 0:fb7af294d5d9 17 - Redistributions in binary form must reproduce the above copyright
Simon Cooksey 0:fb7af294d5d9 18 notice, this list of conditions and the following disclaimer in the
Simon Cooksey 0:fb7af294d5d9 19 documentation and/or other materials provided with the distribution.
Simon Cooksey 0:fb7af294d5d9 20 - Neither the name of ARM nor the names of its contributors may be used
Simon Cooksey 0:fb7af294d5d9 21 to endorse or promote products derived from this software without
Simon Cooksey 0:fb7af294d5d9 22 specific prior written permission.
Simon Cooksey 0:fb7af294d5d9 23 *
Simon Cooksey 0:fb7af294d5d9 24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Simon Cooksey 0:fb7af294d5d9 25 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Simon Cooksey 0:fb7af294d5d9 26 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Simon Cooksey 0:fb7af294d5d9 27 ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
Simon Cooksey 0:fb7af294d5d9 28 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
Simon Cooksey 0:fb7af294d5d9 29 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
Simon Cooksey 0:fb7af294d5d9 30 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
Simon Cooksey 0:fb7af294d5d9 31 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
Simon Cooksey 0:fb7af294d5d9 32 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
Simon Cooksey 0:fb7af294d5d9 33 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
Simon Cooksey 0:fb7af294d5d9 34 POSSIBILITY OF SUCH DAMAGE.
Simon Cooksey 0:fb7af294d5d9 35 ---------------------------------------------------------------------------*/
Simon Cooksey 0:fb7af294d5d9 36
Simon Cooksey 0:fb7af294d5d9 37
Simon Cooksey 0:fb7af294d5d9 38 #ifndef __CORE_CM_SECURE_ACCESS_H
Simon Cooksey 0:fb7af294d5d9 39 #define __CORE_CM_SECURE_ACCESS_H
Simon Cooksey 0:fb7af294d5d9 40
Simon Cooksey 0:fb7af294d5d9 41
Simon Cooksey 0:fb7af294d5d9 42 /* ########################### Core Secure Access ########################### */
Simon Cooksey 0:fb7af294d5d9 43
Simon Cooksey 0:fb7af294d5d9 44 #ifdef FEATURE_UVISOR
Simon Cooksey 0:fb7af294d5d9 45 #include "uvisor-lib.h"
Simon Cooksey 0:fb7af294d5d9 46
Simon Cooksey 0:fb7af294d5d9 47 /* Secure uVisor implementation. */
Simon Cooksey 0:fb7af294d5d9 48
Simon Cooksey 0:fb7af294d5d9 49 /** Set the value at the target address.
Simon Cooksey 0:fb7af294d5d9 50 *
Simon Cooksey 0:fb7af294d5d9 51 * Equivalent to: `*address = value`.
Simon Cooksey 0:fb7af294d5d9 52 * @param address[in] Target address
Simon Cooksey 0:fb7af294d5d9 53 * @param value[in] Value to write at the address location.
Simon Cooksey 0:fb7af294d5d9 54 */
Simon Cooksey 0:fb7af294d5d9 55 #define SECURE_WRITE(address, value) \
Simon Cooksey 0:fb7af294d5d9 56 uvisor_write(main, UVISOR_RGW_SHARED, address, value, UVISOR_RGW_OP_WRITE, 0xFFFFFFFFUL)
Simon Cooksey 0:fb7af294d5d9 57
Simon Cooksey 0:fb7af294d5d9 58 /** Get the value at the target address.
Simon Cooksey 0:fb7af294d5d9 59 *
Simon Cooksey 0:fb7af294d5d9 60 * @param address[in] Target address
Simon Cooksey 0:fb7af294d5d9 61 * @returns The value `*address`.
Simon Cooksey 0:fb7af294d5d9 62 */
Simon Cooksey 0:fb7af294d5d9 63 #define SECURE_READ(address) \
Simon Cooksey 0:fb7af294d5d9 64 uvisor_read(main, UVISOR_RGW_SHARED, address, UVISOR_RGW_OP_READ, 0xFFFFFFFFUL)
Simon Cooksey 0:fb7af294d5d9 65
Simon Cooksey 0:fb7af294d5d9 66 /** Get the selected bits at the target address.
Simon Cooksey 0:fb7af294d5d9 67 *
Simon Cooksey 0:fb7af294d5d9 68 * @param address[in] Target address
Simon Cooksey 0:fb7af294d5d9 69 * @param mask[in] Bits to select out of the target address
Simon Cooksey 0:fb7af294d5d9 70 * @returns The value `*address & mask`.
Simon Cooksey 0:fb7af294d5d9 71 */
Simon Cooksey 0:fb7af294d5d9 72 #define SECURE_BITS_GET(address, mask) \
Simon Cooksey 0:fb7af294d5d9 73 UVISOR_BITS_GET(main, UVISOR_RGW_SHARED, address, mask)
Simon Cooksey 0:fb7af294d5d9 74
Simon Cooksey 0:fb7af294d5d9 75 /** Check the selected bits at the target address.
Simon Cooksey 0:fb7af294d5d9 76 *
Simon Cooksey 0:fb7af294d5d9 77 * @param address[in] Address at which to check the bits
Simon Cooksey 0:fb7af294d5d9 78 * @param mask[in] Bits to select out of the target address
Simon Cooksey 0:fb7af294d5d9 79 * @returns The value `((*address & mask) == mask)`.
Simon Cooksey 0:fb7af294d5d9 80 */
Simon Cooksey 0:fb7af294d5d9 81 #define SECURE_BITS_CHECK(address, mask) \
Simon Cooksey 0:fb7af294d5d9 82 UVISOR_BITS_CHECK(main, UVISOR_RGW_SHARED, address, mask)
Simon Cooksey 0:fb7af294d5d9 83
Simon Cooksey 0:fb7af294d5d9 84 /** Set the selected bits to 1 at the target address.
Simon Cooksey 0:fb7af294d5d9 85 *
Simon Cooksey 0:fb7af294d5d9 86 * Equivalent to: `*address |= mask`.
Simon Cooksey 0:fb7af294d5d9 87 * @param address[in] Target address
Simon Cooksey 0:fb7af294d5d9 88 * @param mask[in] Bits to select out of the target address
Simon Cooksey 0:fb7af294d5d9 89 */
Simon Cooksey 0:fb7af294d5d9 90 #define SECURE_BITS_SET(address, mask) \
Simon Cooksey 0:fb7af294d5d9 91 UVISOR_BITS_SET(main, UVISOR_RGW_SHARED, address, mask)
Simon Cooksey 0:fb7af294d5d9 92
Simon Cooksey 0:fb7af294d5d9 93 /** Clear the selected bits at the target address.
Simon Cooksey 0:fb7af294d5d9 94 *
Simon Cooksey 0:fb7af294d5d9 95 * Equivalent to: `*address &= ~mask`.
Simon Cooksey 0:fb7af294d5d9 96 * @param address[in] Target address
Simon Cooksey 0:fb7af294d5d9 97 * @param mask[in] Bits to select out of the target address
Simon Cooksey 0:fb7af294d5d9 98 */
Simon Cooksey 0:fb7af294d5d9 99 #define SECURE_BITS_CLEAR(address, mask) \
Simon Cooksey 0:fb7af294d5d9 100 UVISOR_BITS_CLEAR(main, UVISOR_RGW_SHARED, address, mask)
Simon Cooksey 0:fb7af294d5d9 101
Simon Cooksey 0:fb7af294d5d9 102 /** Set the selected bits at the target address to the given value.
Simon Cooksey 0:fb7af294d5d9 103 *
Simon Cooksey 0:fb7af294d5d9 104 * Equivalent to: `*address = (*address & ~mask) | (value & mask)`.
Simon Cooksey 0:fb7af294d5d9 105 * @param address[in] Target address
Simon Cooksey 0:fb7af294d5d9 106 * @param mask[in] Bits to select out of the target address
Simon Cooksey 0:fb7af294d5d9 107 * @param value[in] Value to write at the address location. Note: The value
Simon Cooksey 0:fb7af294d5d9 108 * must be already shifted to the correct bit position
Simon Cooksey 0:fb7af294d5d9 109 */
Simon Cooksey 0:fb7af294d5d9 110 #define SECURE_BITS_SET_VALUE(address, mask, value) \
Simon Cooksey 0:fb7af294d5d9 111 UVISOR_BITS_SET_VALUE(main, UVISOR_RGW_SHARED, address, mask, value)
Simon Cooksey 0:fb7af294d5d9 112
Simon Cooksey 0:fb7af294d5d9 113 /** Toggle the selected bits at the target address.
Simon Cooksey 0:fb7af294d5d9 114 *
Simon Cooksey 0:fb7af294d5d9 115 * Equivalent to: `*address ^= mask`.
Simon Cooksey 0:fb7af294d5d9 116 * @param address[in] Target address
Simon Cooksey 0:fb7af294d5d9 117 * @param mask[in] Bits to select out of the target address
Simon Cooksey 0:fb7af294d5d9 118 */
Simon Cooksey 0:fb7af294d5d9 119 #define SECURE_BITS_TOGGLE(address, mask) \
Simon Cooksey 0:fb7af294d5d9 120 UVISOR_BITS_TOGGLE(main, UVISOR_RGW_SHARED, address, mask)
Simon Cooksey 0:fb7af294d5d9 121
Simon Cooksey 0:fb7af294d5d9 122 #else
Simon Cooksey 0:fb7af294d5d9 123
Simon Cooksey 0:fb7af294d5d9 124 /* Insecure fallback implementation. */
Simon Cooksey 0:fb7af294d5d9 125
Simon Cooksey 0:fb7af294d5d9 126 /** Set the value at the target address.
Simon Cooksey 0:fb7af294d5d9 127 *
Simon Cooksey 0:fb7af294d5d9 128 * Equivalent to: `*address = value`.
Simon Cooksey 0:fb7af294d5d9 129 * @param address[in] Target address
Simon Cooksey 0:fb7af294d5d9 130 * @param value[in] Value to write at the address location.
Simon Cooksey 0:fb7af294d5d9 131 */
Simon Cooksey 0:fb7af294d5d9 132 #define SECURE_WRITE(address, value) \
Simon Cooksey 0:fb7af294d5d9 133 *(address) = (value)
Simon Cooksey 0:fb7af294d5d9 134
Simon Cooksey 0:fb7af294d5d9 135 /** Get the value at the target address.
Simon Cooksey 0:fb7af294d5d9 136 *
Simon Cooksey 0:fb7af294d5d9 137 * @param address[in] Target address
Simon Cooksey 0:fb7af294d5d9 138 * @returns The value `*address`.
Simon Cooksey 0:fb7af294d5d9 139 */
Simon Cooksey 0:fb7af294d5d9 140 #define SECURE_READ(address) \
Simon Cooksey 0:fb7af294d5d9 141 (*(address))
Simon Cooksey 0:fb7af294d5d9 142
Simon Cooksey 0:fb7af294d5d9 143 /** Get the selected bits at the target address.
Simon Cooksey 0:fb7af294d5d9 144 *
Simon Cooksey 0:fb7af294d5d9 145 * @param address[in] Target address
Simon Cooksey 0:fb7af294d5d9 146 * @param mask[in] Bits to select out of the target address
Simon Cooksey 0:fb7af294d5d9 147 * @returns The value `*address & mask`.
Simon Cooksey 0:fb7af294d5d9 148 */
Simon Cooksey 0:fb7af294d5d9 149 #define SECURE_BITS_GET(address, mask) \
Simon Cooksey 0:fb7af294d5d9 150 (*(address) & (mask))
Simon Cooksey 0:fb7af294d5d9 151
Simon Cooksey 0:fb7af294d5d9 152 /** Check the selected bits at the target address.
Simon Cooksey 0:fb7af294d5d9 153 *
Simon Cooksey 0:fb7af294d5d9 154 * @param address[in] Address at which to check the bits
Simon Cooksey 0:fb7af294d5d9 155 * @param mask[in] Bits to select out of the target address
Simon Cooksey 0:fb7af294d5d9 156 * @returns The value `((*address & mask) == mask)`.
Simon Cooksey 0:fb7af294d5d9 157 */
Simon Cooksey 0:fb7af294d5d9 158 #define SECURE_BITS_CHECK(address, mask) \
Simon Cooksey 0:fb7af294d5d9 159 ((*(address) & (mask)) == (mask))
Simon Cooksey 0:fb7af294d5d9 160
Simon Cooksey 0:fb7af294d5d9 161 /** Set the selected bits to 1 at the target address.
Simon Cooksey 0:fb7af294d5d9 162 *
Simon Cooksey 0:fb7af294d5d9 163 * Equivalent to: `*address |= mask`.
Simon Cooksey 0:fb7af294d5d9 164 * @param address[in] Target address
Simon Cooksey 0:fb7af294d5d9 165 * @param mask[in] Bits to select out of the target address
Simon Cooksey 0:fb7af294d5d9 166 */
Simon Cooksey 0:fb7af294d5d9 167 #define SECURE_BITS_SET(address, mask) \
Simon Cooksey 0:fb7af294d5d9 168 *(address) |= (mask)
Simon Cooksey 0:fb7af294d5d9 169
Simon Cooksey 0:fb7af294d5d9 170 /** Clear the selected bits at the target address.
Simon Cooksey 0:fb7af294d5d9 171 *
Simon Cooksey 0:fb7af294d5d9 172 * Equivalent to: `*address &= ~mask`.
Simon Cooksey 0:fb7af294d5d9 173 * @param address[in] Target address
Simon Cooksey 0:fb7af294d5d9 174 * @param mask[in] Bits to select out of the target address
Simon Cooksey 0:fb7af294d5d9 175 */
Simon Cooksey 0:fb7af294d5d9 176 #define SECURE_BITS_CLEAR(address, mask) \
Simon Cooksey 0:fb7af294d5d9 177 *(address) &= ~(mask)
Simon Cooksey 0:fb7af294d5d9 178
Simon Cooksey 0:fb7af294d5d9 179 /** Set the selected bits at the target address to the given value.
Simon Cooksey 0:fb7af294d5d9 180 *
Simon Cooksey 0:fb7af294d5d9 181 * Equivalent to: `*address = (*address & ~mask) | (value & mask)`.
Simon Cooksey 0:fb7af294d5d9 182 * @param address[in] Target address
Simon Cooksey 0:fb7af294d5d9 183 * @param mask[in] Bits to select out of the target address
Simon Cooksey 0:fb7af294d5d9 184 * @param value[in] Value to write at the address location. Note: The value
Simon Cooksey 0:fb7af294d5d9 185 * must be already shifted to the correct bit position
Simon Cooksey 0:fb7af294d5d9 186 */
Simon Cooksey 0:fb7af294d5d9 187 #define SECURE_BITS_SET_VALUE(address, mask, value) \
Simon Cooksey 0:fb7af294d5d9 188 *(address) = (*(address) & ~(mask)) | ((value) & (mask))
Simon Cooksey 0:fb7af294d5d9 189
Simon Cooksey 0:fb7af294d5d9 190 /** Toggle the selected bits at the target address.
Simon Cooksey 0:fb7af294d5d9 191 *
Simon Cooksey 0:fb7af294d5d9 192 * Equivalent to: `*address ^= mask`.
Simon Cooksey 0:fb7af294d5d9 193 * @param address[in] Target address
Simon Cooksey 0:fb7af294d5d9 194 * @param mask[in] Bits to select out of the target address
Simon Cooksey 0:fb7af294d5d9 195 */
Simon Cooksey 0:fb7af294d5d9 196 #define SECURE_BITS_TOGGLE(address, mask) \
Simon Cooksey 0:fb7af294d5d9 197 *(address) ^= (mask)
Simon Cooksey 0:fb7af294d5d9 198
Simon Cooksey 0:fb7af294d5d9 199 #endif
Simon Cooksey 0:fb7af294d5d9 200
Simon Cooksey 0:fb7af294d5d9 201 #endif /* __CORE_CM_SECURE_ACCESS_H */