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