aboutsummaryrefslogtreecommitdiff
path: root/libraries
diff options
context:
space:
mode:
Diffstat (limited to 'libraries')
-rw-r--r--libraries/libprof/README.txt2
-rw-r--r--libraries/libprof/profil.c17
-rw-r--r--libraries/libtfm/Makefile34
-rw-r--r--libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F4/TARGET_CRYPTECH_ALPHA/stm32f4xx_it.c2
4 files changed, 43 insertions, 12 deletions
diff --git a/libraries/libprof/README.txt b/libraries/libprof/README.txt
index 1fe378c..f0b8ee8 100644
--- a/libraries/libprof/README.txt
+++ b/libraries/libprof/README.txt
@@ -52,7 +52,7 @@ In the OpenOCD console, enable semihosting:
In another window, start the debugger:
- $ sw/stm32/bin/debug projects/hsm/hsm
+ $ ../../bin/debug hsm
In the CLI, type `profile start`, then start the unit test or whatever
will be exercising the hsm. Afterwards, in the CLI, type `profile stop`.
diff --git a/libraries/libprof/profil.c b/libraries/libprof/profil.c
index 0654879..b0d8d55 100644
--- a/libraries/libprof/profil.c
+++ b/libraries/libprof/profil.c
@@ -25,27 +25,30 @@ static struct profinfo prof = {
PROFILE_NOT_INIT, 0, 0, 0, 0
};
-extern void set_SysTick_hook(void (*hook)(void));
-
/* sample the current program counter */
-static void SysTick_hook(void) {
- size_t pc = (size_t)((uint32_t *)__get_MSP())[8];
- if (pc >= prof.lowpc && pc < prof.highpc) {
+void profil_callback(void) {
+ if (prof.state == PROFILE_ON) {
+ /* The interrupt mechanism pushes xPSR, PC, LR, R12, and R3-R0 onto the
+ * stack, so PC is the 6th word from the top at that point. However, the
+ * normal function entry code pushes registers as well, so the stack
+ * offset right now depends on the call tree that got us here.
+ */
+ size_t pc = (size_t)((uint32_t *)__get_MSP())[6 + 6];
+ if (pc >= prof.lowpc && pc < prof.highpc) {
size_t idx = PROFIDX (pc, prof.lowpc, prof.scale);
prof.counter[idx]++;
+ }
}
}
/* Stop profiling to the profiling buffer pointed to by p. */
static int profile_off (struct profinfo *p) {
- set_SysTick_hook(NULL);
p->state = PROFILE_OFF;
return 0;
}
/* Create a timer thread and pass it a pointer P to the profiling buffer. */
static int profile_on (struct profinfo *p) {
- set_SysTick_hook(SysTick_hook);
p->state = PROFILE_ON;
return 0; /* ok */
}
diff --git a/libraries/libtfm/Makefile b/libraries/libtfm/Makefile
index 6da552d..5be45f4 100644
--- a/libraries/libtfm/Makefile
+++ b/libraries/libtfm/Makefile
@@ -10,10 +10,38 @@ BITS := 8192
HDR := ${LIBTFM_SRC}/tomsfastmath/src/headers/tfm.h
LIB := tomsfastmath/libtfm.a
-#CFLAGS += -DTFM_X86
-#CFLAGS += -DTFM_NO_ASM
+# See sw/thirdparty/libtfm/Makefile for compilation options. Note
+# that libtfm platform-specific assembly code has opinions on the
+# optimization level (and appears to be best tested with -O3).
-CFLAGS += -fPIC -Wall -W -Wshadow -I${LIBTFM_SRC}/tomsfastmath/src/headers -g3 -DFP_MAX_SIZE="(${BITS}*2+(8*DIGIT_BIT))"
+# Using $(subst...) here is a kludge. A cleaner approach might be for
+# sw/stm32/Makefile to build up the non-variant parts of CFLAGS in a
+# different variable before merging the variant and non-variant parts
+# into CFLAGS, which would give us a clean copy of the non-variant
+# parts to use when constructing our own CFLAGS. Later.
+
+# The ARM assembly code in libtfm still generates a lot of warnings of the form:
+#
+# warning: matching constraint does not allow a register [enabled by default]
+#
+# This is just a warning, the resulting library appears to work
+# correctly, and the fix appears to require a nasty intervention in
+# the guts of the libtfm assembly code, so we live with the warning
+# for now, at least until we confirm that it hasn't already been fixed
+# in a newer version of libtfm.
+
+ifdef DO_PROFILING
+# arm-none-eabi-gcc: error: -pg and -fomit-frame-pointer are incompatible
+STM32_LIBTFM_CFLAGS_OPTIMIZATION := -O3 -funroll-loops
+else
+STM32_LIBTFM_CFLAGS_OPTIMIZATION := -O3 -funroll-loops -fomit-frame-pointer
+endif
+
+CFLAGS := $(subst ${STM32_CFLAGS_OPTIMIZATION},${STM32_LIBTFM_CFLAGS_OPTIMIZATION},${CFLAGS})
+CFLAGS += -DTFM_ARM -Dasm=__asm__ -Wa,-mimplicit-it=thumb
+CFLAGS += -I${LIBTFM_SRC}/tomsfastmath/src/headers
+CFLAGS += -DFP_MAX_SIZE="(${BITS}*2+(8*DIGIT_BIT))"
+CFLAGS += -Wall -W -Wshadow
TARGETS := $(notdir ${HDR} ${LIB})
diff --git a/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F4/TARGET_CRYPTECH_ALPHA/stm32f4xx_it.c b/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F4/TARGET_CRYPTECH_ALPHA/stm32f4xx_it.c
index 4629e44..b8b6fce 100644
--- a/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F4/TARGET_CRYPTECH_ALPHA/stm32f4xx_it.c
+++ b/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F4/TARGET_CRYPTECH_ALPHA/stm32f4xx_it.c
@@ -79,7 +79,7 @@ void set_SysTick_hook(void (*hook)(void))
void SysTick_Handler(void)
{
HAL_IncTick();
- SysTick_hook();
+ HAL_SYSTICK_IRQHandler();
}
/******************************************************************************/