Skip to content

Commit 5a3416d

Browse files
committed
Merge pull request #9 from meriac/master
Migrate existing uVisor patches
2 parents f28588c + 6893401 commit 5a3416d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+5424
-4969
lines changed

core/uvisor-mbed-lib.lib

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://github.com/ARMmbed/uvisor-mbed-lib/#32b6df4

hal/common/retarget.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -469,21 +469,27 @@ extern "C" uint32_t __HeapLimit;
469469
#undef errno
470470
extern "C" int errno;
471471

472-
// For ARM7 only
473-
register unsigned char * stack_ptr __asm ("sp");
472+
// Stack pointer handling
473+
#ifdef __ICCARM__
474+
#define __current_sp() __get_SP()
475+
#else
476+
static inline unsigned int __current_sp(void)
477+
{
478+
register unsigned sp asm("sp");
479+
return sp;
480+
}
481+
#endif /* __ICCARM__ */
474482

475483
// Dynamic memory allocation related syscall.
476484
extern "C" caddr_t _sbrk(int incr) {
477485
static unsigned char* heap = (unsigned char*)&__end__;
478486
unsigned char* prev_heap = heap;
479487
unsigned char* new_heap = heap + incr;
480488

481-
#if defined(TARGET_ARM7)
482-
if (new_heap >= stack_ptr) {
483-
#elif defined(TARGET_CORTEX_A)
489+
#if defined(TARGET_CORTEX_A)
484490
if (new_heap >= (unsigned char*)&__HeapLimit) { /* __HeapLimit is end of heap section */
485491
#else
486-
if (new_heap >= (unsigned char*)__get_MSP()) {
492+
if (new_heap >= (unsigned char*)__current_sp()) {
487493
#endif
488494
errno = ENOMEM;
489495
return (caddr_t)-1;

hal/targets/cmsis/TARGET_Freescale/TARGET_MCU_K64F/TOOLCHAIN_GCC_ARM/K64FN1M0xxx12.ld

Lines changed: 83 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ MEMORY
77
VECTORS (rx) : ORIGIN = 0x00000000, LENGTH = 0x00000400
88
FLASH_PROTECTION (rx) : ORIGIN = 0x00000400, LENGTH = 0x00000010
99
FLASH (rx) : ORIGIN = 0x00000410, LENGTH = 0x00100000 - 0x00000410
10-
RAM (rwx) : ORIGIN = 0x1FFF0198, LENGTH = 0x00040000 - 0x00000198
10+
RAM (rwx) : ORIGIN = 0x1FFF0200, LENGTH = 0x00040000 - 0x00000200
1111
}
1212

1313
/* Linker script to place sections and symbol values. Should be used together
@@ -55,8 +55,41 @@ SECTIONS
5555
. = ALIGN(4);
5656
} > FLASH_PROTECTION
5757

58+
/* Ensure that the uVisor .bss is the first section in the public SRAM. */
59+
.uvisor.bss (NOLOAD):
60+
{
61+
. = ALIGN(32);
62+
__uvisor_bss_start = .;
63+
64+
/* uVisor main .bss (protected) */
65+
. = ALIGN(32);
66+
__uvisor_bss_main_start = .;
67+
KEEP(*(.keep.uvisor.bss.main))
68+
. = ALIGN(32);
69+
__uvisor_bss_main_end = .;
70+
71+
/* Secure boxes .bss (protected) */
72+
. = ALIGN(32);
73+
__uvisor_bss_boxes_start = .;
74+
KEEP(*(.keep.uvisor.bss.boxes))
75+
. = ALIGN(32);
76+
__uvisor_bss_boxes_end = .;
77+
78+
. = ALIGN(32);
79+
__uvisor_bss_end = .;
80+
} > RAM
81+
5882
.text :
5983
{
84+
/* uVisor code and data */
85+
/* Note: This is the location of the uVisor binary in flash. Make sure
86+
* this position correspond to the FLASH_OFFSET set in the uVisor
87+
* configuration. */
88+
. = ALIGN(4);
89+
__uvisor_main_start = .;
90+
*(.uvisor.main)
91+
__uvisor_main_end = .;
92+
6093
*(.text*)
6194

6295
KEEP(*(.init))
@@ -93,10 +126,10 @@ SECTIONS
93126
} > FLASH
94127
__exidx_end = .;
95128

96-
__etext = .;
97-
98-
.data : AT (__etext)
129+
.data :
99130
{
131+
PROVIDE( __etext = LOADADDR(.data) );
132+
100133
__data_start__ = .;
101134
*(vtable)
102135
*(.data*)
@@ -126,6 +159,44 @@ SECTIONS
126159
/* All data end */
127160
__data_end__ = .;
128161

162+
} > RAM AT>FLASH
163+
164+
/* uVisor configuration data */
165+
.uvisor.secure :
166+
{
167+
. = ALIGN(32);
168+
__uvisor_secure_start = .;
169+
170+
/* Secure boxes configuration tables (protected) */
171+
. = ALIGN(32);
172+
__uvisor_cfgtbl_start = .;
173+
KEEP(*(.keep.uvisor.cfgtbl))
174+
. = ALIGN(32);
175+
__uvisor_cfgtbl_end = .;
176+
177+
/* Pointers to the secure boxes configuration tables (protected) */
178+
/* Note: Do not add any further alignment here, as we use this pointer
179+
* table to enumerate boxes. */
180+
__uvisor_cfgtbl_ptr_start = .;
181+
KEEP(*(.keep.uvisor.cfgtbl_ptr_first))
182+
KEEP(*(.keep.uvisor.cfgtbl_ptr))
183+
__uvisor_cfgtbl_ptr_end = .;
184+
185+
. = ALIGN(32);
186+
__uvisor_secure_end = .;
187+
} >FLASH
188+
189+
/* Uninitialized memory section
190+
* The C/C++ library initialization will not touch this section. Data
191+
* written here will keep its value on reboots (assuming no power loss). */
192+
.uninitialized (NOLOAD):
193+
{
194+
. = ALIGN(32);
195+
__uninitialized_start = .;
196+
*(.uninitialized)
197+
KEEP(*(.keep.uninitialized))
198+
. = ALIGN(32);
199+
__uninitialized_end = .;
129200
} > RAM
130201

131202
.bss :
@@ -160,5 +231,13 @@ SECTIONS
160231

161232
/* Check if data + heap + stack exceeds RAM limit */
162233
ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack")
234+
235+
/* Provide physical memory boundaries for uVisor. */
236+
__uvisor_flash_start = ORIGIN(VECTORS);
237+
__uvisor_flash_offset = ORIGIN(FLASH);
238+
__uvisor_flash_end = ORIGIN(FLASH) + LENGTH(FLASH);
239+
__uvisor_sram_start = ORIGIN(RAM) - 0x200;
240+
__uvisor_sram_offset = ORIGIN(RAM);
241+
__uvisor_sram_end = ORIGIN(RAM) + LENGTH(RAM);
163242
}
164243

hal/targets/cmsis/TARGET_Freescale/TARGET_MCU_K64F/TOOLCHAIN_GCC_ARM/startup_MK64F12.S

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ disable_watchdog:
229229

230230
ldr r0, =SystemInit
231231
blx r0
232+
ldr r0, =uvisor_init
233+
blx r0
232234
ldr r0, =_start
233235
bx r0
234236
.pool

hal/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_KPSDK_CODE/drivers/interrupt/fsl_interrupt_manager.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ static inline void INT_SYS_EnableIRQ(IRQn_Type irqNumber)
8989
assert(irqNumber <= FSL_FEATURE_INTERRUPT_IRQ_MAX);
9090

9191
/* call core API to enable the IRQ*/
92-
NVIC_EnableIRQ(irqNumber);
92+
vIRQ_EnableIRQ(irqNumber);
9393
}
9494

9595
/*!
@@ -108,7 +108,7 @@ static inline void INT_SYS_DisableIRQ(IRQn_Type irqNumber)
108108
assert(irqNumber <= FSL_FEATURE_INTERRUPT_IRQ_MAX);
109109

110110
/* call core API to disable the IRQ*/
111-
NVIC_DisableIRQ(irqNumber);
111+
vIRQ_DisableIRQ(irqNumber);
112112
}
113113

114114
/*!

hal/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_MCU_K64F/device/MK64F12/fsl_bitaccess.h

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
** Copyright (c) 2014 Freescale Semiconductor, Inc.
1010
** All rights reserved.
1111
**
12+
** (C) COPYRIGHT 2015-2015 ARM Limited
13+
** ALL RIGHTS RESERVED
14+
**
1215
** Redistribution and use in source and binary forms, with or without modification,
1316
** are permitted provided that the following conditions are met:
1417
**
@@ -62,6 +65,10 @@
6265
** The declaration of clock configurations has been moved to separate header file system_MK64F12.h
6366
** Update of SystemInit() and SystemCoreClockUpdate() functions.
6467
** Module access macro module_BASES replaced by module_BASE_PTRS.
68+
** - rev. 2.6 (2015-07-30) (ARM)
69+
** Macros for bitband address calculation have been decoupled from the
70+
** actual address de-referencing in BITBAND_ACCESSxx macros;
71+
** Added fallback macros for default read/write operations
6572
**
6673
** ###################################################################
6774
*/
@@ -72,6 +79,51 @@
7279

7380
#include <stdint.h>
7481
#include <stdlib.h>
82+
#include "uvisor-lib/uvisor-lib.h"
83+
84+
/*
85+
* Fallback macros for write/read operations
86+
*/
87+
#ifndef ADDRESS_READ
88+
/* the conditional statement will be optimised away since the compiler already
89+
* knows the sizeof(type) */
90+
#define ADDRESS_READ(type, addr) \
91+
(sizeof(type) == 4 ? *((volatile uint32_t *) (addr)) : \
92+
sizeof(type) == 2 ? *((volatile uint16_t *) (addr)) : \
93+
sizeof(type) == 1 ? *((volatile uint8_t *) (addr)) : 0)
94+
#endif
95+
96+
#ifndef ADDRESS_WRITE
97+
/* the switch statement will be optimised away since the compiler already knows
98+
* the sizeof(type) */
99+
#define ADDRESS_WRITE(type, addr, val) \
100+
{ \
101+
switch(sizeof(type)) \
102+
{ \
103+
case 4: \
104+
*((volatile uint32_t *) (addr)) = (uint32_t) (val); \
105+
break; \
106+
case 2: \
107+
*((volatile uint16_t *) (addr)) = (uint16_t) (val); \
108+
break; \
109+
case 1: \
110+
*((volatile uint8_t *) (addr)) = (uint8_t ) (val); \
111+
break; \
112+
} \
113+
}
114+
#endif
115+
116+
#ifndef UNION_READ
117+
#define UNION_READ(type, addr, fieldU, fieldB) ((*((volatile type *) (addr))).fieldB)
118+
#endif
119+
120+
/*
121+
* Macros to translate a pair of regular address and bit to their bit band alias
122+
*/
123+
#define BITBAND_ADDRESS(Reg,Bit) (0x42000000u + (32u*((uint32_t)(Reg) - (uint32_t)0x40000000u)) + (4u*((uint32_t)(Bit))))
124+
#define BITBAND_ADDRESS32(Reg,Bit) ((uint32_t volatile*)BITBAND_ADDRESS(Reg,Bit))
125+
#define BITBAND_ADDRESS16(Reg,Bit) ((uint16_t volatile*)BITBAND_ADDRESS(Reg,Bit))
126+
#define BITBAND_ADDRESS8(Reg,Bit) ((uint8_t volatile*)BITBAND_ADDRESS(Reg,Bit))
75127

76128
/**
77129
* @brief Macro to access a single bit of a 32-bit peripheral register (bit band region
@@ -80,7 +132,7 @@
80132
* @param Bit Bit number to access.
81133
* @return Value of the targeted bit in the bit band region.
82134
*/
83-
#define BITBAND_ACCESS32(Reg,Bit) (*((uint32_t volatile*)(0x42000000u + (32u*((uint32_t)(Reg) - (uint32_t)0x40000000u)) + (4u*((uint32_t)(Bit))))))
135+
#define BITBAND_ACCESS32(Reg,Bit) (*BITBAND_ADDRESS32(Reg,Bit))
84136

85137
/**
86138
* @brief Macro to access a single bit of a 16-bit peripheral register (bit band region
@@ -89,7 +141,7 @@
89141
* @param Bit Bit number to access.
90142
* @return Value of the targeted bit in the bit band region.
91143
*/
92-
#define BITBAND_ACCESS16(Reg,Bit) (*((uint16_t volatile*)(0x42000000u + (32u*((uint32_t)(Reg) - (uint32_t)0x40000000u)) + (4u*((uint32_t)(Bit))))))
144+
#define BITBAND_ACCESS16(Reg,Bit) (*BITBAND_ADDRESS16(Reg,Bit))
93145

94146
/**
95147
* @brief Macro to access a single bit of an 8-bit peripheral register (bit band region
@@ -98,7 +150,7 @@
98150
* @param Bit Bit number to access.
99151
* @return Value of the targeted bit in the bit band region.
100152
*/
101-
#define BITBAND_ACCESS8(Reg,Bit) (*((uint8_t volatile*)(0x42000000u + (32u*((uint32_t)(Reg) - (uint32_t)0x40000000u)) + (4u*((uint32_t)(Bit))))))
153+
#define BITBAND_ACCESS8(Reg,Bit) (*BITBAND_ADDRESS8(Reg,Bit))
102154

103155
/*
104156
* Macros for single instance registers

0 commit comments

Comments
 (0)