Skip to content

Commit bbb5070

Browse files
authored
Merge pull request #1936 from meriac/master
Enabled uVisor secure mode for K64F
2 parents ffa45c9 + fd6944f commit bbb5070

File tree

22 files changed

+516
-142
lines changed

22 files changed

+516
-142
lines changed

features/FEATURE_UVISOR/AUTHORS.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
519 Milosch Meriac
2-
420 Alessandro Angelino
3-
16 Niklas Hauser
4-
15 Jaeden Amero
1+
523 Milosch Meriac
2+
422 Alessandro Angelino
3+
17 Niklas Hauser
4+
16 Jaeden Amero
55
3 Hugo Vincent
66
3 JaredCJR
77
3 Jim Huang

features/FEATURE_UVISOR/VERSION.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v0.9.14-alpha
1+
v0.9.14-alpha-8-g1f0a4b9b181476c65d396838d61465ea5363e23b
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (c) 2016, ARM Limited, All Rights Reserved
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
6+
* not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
#ifndef __UVISOR_API_NVIC_VIRTUAL_H__
18+
#define __UVISOR_API_NVIC_VIRTUAL_H__
19+
20+
#include "api/inc/interrupts.h"
21+
22+
#define NVIC_SetPriorityGrouping __NVIC_SetPriorityGrouping
23+
#define NVIC_GetPriorityGrouping __NVIC_GetPriorityGrouping
24+
#define NVIC_EnableIRQ vIRQ_EnableIRQ
25+
#define NVIC_DisableIRQ vIRQ_DisableIRQ
26+
#define NVIC_GetPendingIRQ vIRQ_GetPendingIRQ
27+
#define NVIC_SetPendingIRQ vIRQ_SetPendingIRQ
28+
#define NVIC_ClearPendingIRQ vIRQ_ClearPendingIRQ
29+
#define NVIC_GetActive __NVIC_GetActive
30+
#define NVIC_SetPriority vIRQ_SetPriority
31+
#define NVIC_GetPriority vIRQ_GetPriority
32+
33+
#endif /* __UVISOR_API_NVIC_VIRTUAL_H__ */
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright (c) 2016, ARM Limited, All Rights Reserved
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
6+
* not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
#ifndef __UVISOR_API_VECTAB_VIRTUAL_H__
18+
#define __UVISOR_API_VECTAB_VIRTUAL_H__
19+
20+
#include "api/inc/interrupts.h"
21+
22+
#define NVIC_SetVector vIRQ_SetVector
23+
#define NVIC_GetVector vIRQ_GetVector
24+
25+
#endif /* __UVISOR_API_VECTAB_VIRTUAL_H__ */

features/FEATURE_UVISOR/includes/uvisor/api/inc/register_gateway.h

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,17 @@
6060
*
6161
* @param box_name[in] The name of the source box as decalred in
6262
* `UVISOR_BOX_CONFIG`.
63+
* @param shared[in] Whether the gateway can be shared with other boxes or
64+
* not. Two values are available: UVISOR_RGW_SHARED,
65+
* UVISOR_RGW_EXCLUSIVE.
6366
* @param addr[in] The address for the data access.
6467
* @param operation[in] The operation to perform at the address for the read. It
6568
* is chosen among the `UVISOR_RGW_OP_*` macros.
66-
* @param shared[in] True if the gateway can be performed by any box. In this
67-
* case, the box_name field does not guarantee exclusivity.
6869
* @param mask[in] The mask to apply for the read operation.
6970
* @returns The value read from address using the operation and mask provided
7071
* (or their respective defaults if they have not been provided).
7172
*/
72-
#define uvisor_read(box_name, addr, op, shared, msk) \
73+
#define uvisor_read(box_name, shared, addr, op, msk) \
7374
({ \
7475
/* Instanstiate the gateway. This gets resolved at link-time. */ \
7576
__attribute__((aligned(4))) static TRegisterGateway const register_gateway = { \
@@ -106,15 +107,16 @@
106107
*
107108
* @param box_name[in] The name of the source box as decalred in
108109
* `UVISOR_BOX_CONFIG`.
110+
* @param shared[in] Whether the gateway can be shared with other boxes or
111+
* not. Two values are available: UVISOR_RGW_SHARED,
112+
* UVISOR_RGW_EXCLUSIVE.
109113
* @param addr[in] The address for the data access.
110114
* @param val[in] The value to write at address.
111115
* @param operation[in] The operation to perform at the address for the read. It
112116
* is chosen among the `UVISOR_RGW_OP_*` macros.
113-
* @param shared[in] True if the gateway can be performed by any box. In this
114-
* case, the box_name field does not guarantee exclusivity.
115117
* @param mask[in] The mask to apply for the write operation.
116118
*/
117-
#define uvisor_write(box_name, addr, val, op, shared, msk) \
119+
#define uvisor_write(box_name, shared, addr, val, op, msk) \
118120
{ \
119121
/* Instanstiate the gateway. This gets resolved at link-time. */ \
120122
__attribute__((aligned(4))) static TRegisterGateway const register_gateway = { \
@@ -143,77 +145,95 @@
143145
/** Get the selected bits at the target address.
144146
* @param box_name[in] Box name as defined by the uVisor box configuration
145147
* macro `UVISOR_BOX_CONFIG`
148+
* @param shared[in] Whether the gateway can be shared with other boxes or
149+
* not. Two values are available: UVISOR_RGW_SHARED,
150+
* UVISOR_RGW_EXCLUSIVE.
146151
* @param address[in] Target address
147152
* @param mask[in] Bits to select out of the target address
148153
* @returns The value `*address & mask`.
149154
*/
150-
#define UVISOR_BITS_GET(box_name, address, mask) \
155+
#define UVISOR_BITS_GET(box_name, shared, address, mask) \
151156
/* Register gateway implementation:
152157
* *address & mask */ \
153-
uvisor_read(box_name, address, UVISOR_RGW_OP_READ_AND, false, mask)
158+
uvisor_read(box_name, shared, address, UVISOR_RGW_OP_READ_AND, mask)
154159

155160
/** Check the selected bits at the target address.
156161
* @param box_name[in] Box name as defined by the uVisor box configuration
157162
* macro `UVISOR_BOX_CONFIG`
163+
* @param shared[in] Whether the gateway can be shared with other boxes or
164+
* not. Two values are available: UVISOR_RGW_SHARED,
165+
* UVISOR_RGW_EXCLUSIVE.
158166
* @param address[in] Address at which to check the bits
159167
* @param mask[in] Bits to select out of the target address
160-
* @returns The value `(bool) (*address & mask) == mask)`.
168+
* @returns The value `((*address & mask) == mask)`.
161169
*/
162-
#define UVISOR_BITS_CHECK(box_name, address, mask) \
163-
((bool) (UVISOR_BITS_GET(box_name, address, mask) == mask))
170+
#define UVISOR_BITS_CHECK(box_name, shared, address, mask) \
171+
((UVISOR_BITS_GET(box_name, shared, address, mask)) == (mask))
164172

165173
/** Set the selected bits to 1 at the target address.
166174
*
167175
* Equivalent to: `*address |= mask`.
168176
* @param box_name[in] Box name as defined by the uVisor box configuration
169177
* macro `UVISOR_BOX_CONFIG`
178+
* @param shared[in] Whether the gateway can be shared with other boxes or
179+
* not. Two values are available: UVISOR_RGW_SHARED,
180+
* UVISOR_RGW_EXCLUSIVE.
170181
* @param address[in] Target address
171182
* @param mask[in] Bits to select out of the target address
172183
*/
173-
#define UVISOR_BITS_SET(box_name, address, mask) \
184+
#define UVISOR_BITS_SET(box_name, shared, address, mask) \
174185
/* Register gateway implementation:
175186
* *address |= (mask & mask) */ \
176-
uvisor_write(box_name, address, mask, UVISOR_RGW_OP_WRITE_OR, false, mask)
187+
uvisor_write(box_name, shared, address, mask, UVISOR_RGW_OP_WRITE_OR, mask)
177188

178189
/** Clear the selected bits at the target address.
179190
*
180191
* Equivalent to: `*address &= ~mask`.
181192
* @param box_name[in] Box name as defined by the uVisor box configuration
182193
* macro `UVISOR_BOX_CONFIG`
194+
* @param shared[in] Whether the gateway can be shared with other boxes or
195+
* not. Two values are available: UVISOR_RGW_SHARED,
196+
* UVISOR_RGW_EXCLUSIVE.
183197
* @param address[in] Target address
184198
* @param mask[in] Bits to select out of the target address
185199
*/
186-
#define UVISOR_BITS_CLEAR(box_name, address, mask) \
200+
#define UVISOR_BITS_CLEAR(box_name, shared, address, mask) \
187201
/* Register gateway implementation:
188202
* *address &= (0x00000000 | ~mask) */ \
189-
uvisor_write(box_name, address, 0x00000000, UVISOR_RGW_OP_WRITE_AND, false, mask)
203+
uvisor_write(box_name, shared, address, 0x00000000, UVISOR_RGW_OP_WRITE_AND, mask)
190204

191205
/** Set the selected bits at the target address to the given value.
192206
*
193207
* Equivalent to: `*address = (*address & ~mask) | (value & mask)`.
194208
* @param box_name[in] Box name as defined by the uVisor box configuration
195209
* macro `UVISOR_BOX_CONFIG`
210+
* @param shared[in] Whether the gateway can be shared with other boxes or
211+
* not. Two values are available: UVISOR_RGW_SHARED,
212+
* UVISOR_RGW_EXCLUSIVE.
196213
* @param address[in] Target address
197214
* @param mask[in] Bits to select out of the target address
198215
* @param value[in] Value to write at the address location. Note: The value
199216
* must be already shifted to the correct bit position
200217
*/
201-
#define UVISOR_BITS_SET_VALUE(box_name, address, mask, value) \
218+
#define UVISOR_BITS_SET_VALUE(box_name, shared, address, mask, value) \
202219
/* Register gateway implementation:
203220
* *address = (*address & ~mask) | (value & mask) */ \
204-
uvisor_write(box_name, address, value, UVISOR_RGW_OP_WRITE_REPLACE, false, mask)
221+
uvisor_write(box_name, shared, address, value, UVISOR_RGW_OP_WRITE_REPLACE, mask)
205222

206223
/** Toggle the selected bits at the target address.
207224
*
208225
* Equivalent to: `*address ^= mask`.
209226
* @param box_name[in] Box name as defined by the uVisor box configuration
210227
* macro `UVISOR_BOX_CONFIG`
228+
* @param shared[in] Whether the gateway can be shared with other boxes or
229+
* not. Two values are available: UVISOR_RGW_SHARED,
230+
* UVISOR_RGW_EXCLUSIVE.
211231
* @param address[in] Target address
212232
* @param mask[in] Bits to select out of the target address
213233
*/
214-
#define UVISOR_BITS_TOGGLE(box_name, address, mask) \
234+
#define UVISOR_BITS_TOGGLE(box_name, shared, address, mask) \
215235
/* Register gateway implementation:
216236
* *address ^= (0xFFFFFFFF & mask) */ \
217-
uvisor_write(box_name, address, 0xFFFFFFFF, UVISOR_RGW_OP_WRITE_XOR, false, mask)
237+
uvisor_write(box_name, shared, address, 0xFFFFFFFF, UVISOR_RGW_OP_WRITE_XOR, mask)
218238

219239
#endif /* __UVISOR_API_REGISTER_GATEWAY_H__ */

features/FEATURE_UVISOR/includes/uvisor/api/inc/register_gateway_exports.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ typedef struct {
7979
(((uint16_t) (width) << __UVISOR_RGW_OP_WIDTH_POS) & __UVISOR_RGW_OP_WIDTH_MASK) | \
8080
(((uint16_t) (shared) << __UVISOR_RGW_OP_SHARED_POS) & __UVISOR_RGW_OP_SHARED_MASK)))
8181

82+
/** Register gateway operation - Shared */
83+
#define UVISOR_RGW_SHARED 1
84+
#define UVISOR_RGW_EXCLUSIVE 0
85+
8286
/** Register gateway operation - Type */
8387
#define UVISOR_RGW_OP_READ 0 /**< value = *address */
8488
#define UVISOR_RGW_OP_READ_AND 1 /**< value = *address & mask */

hal/common/critical.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,14 @@ void core_util_critical_section_enter()
5353
are enabled, then something has gone badly wrong thus assert an error.
5454
*/
5555
MBED_ASSERT(interrupt_enable_counter < UINT32_MAX);
56+
// FIXME
57+
#ifndef FEATURE_UVISOR
5658
if (interrupt_enable_counter > 0) {
5759
MBED_ASSERT(interrupts_disabled & 0x1);
5860
}
61+
#else
62+
#warning "core_util_critical_section_enter needs fixing to work from unprivileged code"
63+
#endif /* FEATURE_UVISOR */
5964
interrupt_enable_counter++;
6065
}
6166

@@ -64,9 +69,14 @@ void core_util_critical_section_exit()
6469
/* If critical_section_enter has not previously been called, do nothing */
6570
if (interrupt_enable_counter) {
6671

72+
// FIXME
73+
#ifndef FEATURE_UVISOR
6774
uint32_t interrupts_disabled = get_interrupts_disabled(); /* get the current interrupt disabled state */
6875

6976
MBED_ASSERT(interrupts_disabled & 0x1); /* Interrupts must be disabled on invoking an exit from a critical section */
77+
#else
78+
#warning "core_util_critical_section_exit needs fixing to work from unprivileged code"
79+
#endif /* FEATURE_UVISOR */
7080

7181
interrupt_enable_counter--;
7282

hal/targets/cmsis/TARGET_Freescale/TARGET_K64F/TOOLCHAIN_GCC_ARM/MK64FN1M0xxx12.ld

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,11 @@ SECTIONS
9090
} > m_flash_config
9191

9292
/* The program code and other data goes into internal flash */
93-
.text :
93+
/* Note: The uVisor expects this section at a fixed location, as specified by
94+
* the porting process configuration parameter: FLASH_OFFSET. */
95+
__UVISOR_TEXT_OFFSET = 0x410;
96+
__UVISOR_TEXT_START = ORIGIN(m_interrupts) + __UVISOR_TEXT_OFFSET;
97+
.text __UVISOR_TEXT_START :
9498
{
9599
/* uVisor code and data */
96100
. = ALIGN(4);
@@ -200,7 +204,7 @@ SECTIONS
200204
__UVISOR_BSS_START = ORIGIN(m_data) + __UVISOR_SRAM_OFFSET;
201205
ASSERT(__interrupts_ram_end__ <= __UVISOR_BSS_START,
202206
"The ISR relocation region overlaps with the uVisor BSS section.")
203-
.uvisor.bss (NOLOAD):
207+
.uvisor.bss __UVISOR_BSS_START (NOLOAD):
204208
{
205209
. = ALIGN(32);
206210
__uvisor_bss_start = .;

hal/targets/cmsis/TARGET_Freescale/TARGET_K64F/cmsis_nvic.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@
3232

3333
extern void InstallIRQHandler(IRQn_Type irq, uint32_t irqHandler);
3434

35-
void NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) {
35+
void __NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) {
3636
InstallIRQHandler(IRQn, vector);
3737
}
3838

39-
uint32_t NVIC_GetVector(IRQn_Type IRQn) {
39+
uint32_t __NVIC_GetVector(IRQn_Type IRQn) {
4040
uint32_t *vectors = (uint32_t*)SCB->VTOR;
4141
return vectors[IRQn + 16];
4242
}

hal/targets/cmsis/TARGET_Freescale/TARGET_K64F/cmsis_nvic.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
extern "C" {
4242
#endif
4343

44-
void NVIC_SetVector(IRQn_Type IRQn, uint32_t vector);
45-
uint32_t NVIC_GetVector(IRQn_Type IRQn);
44+
void __NVIC_SetVector(IRQn_Type IRQn, uint32_t vector);
45+
uint32_t __NVIC_GetVector(IRQn_Type IRQn);
4646

4747
#ifdef __cplusplus
4848
}

0 commit comments

Comments
 (0)