mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-12 18:49:07 +00:00
Put persistent variables at end of stack
Two variables of the bootloader are persistent: - __stack_chk_guard is used by interrupt handlers - system_millis is used by timer interrupt and service routines Note that currently __stack_chk_guard is shared between unprivileged firmware and bootloader. If we get more variables later it may make sense to make a section for this.
This commit is contained in:
parent
ed7a8bfa6c
commit
be64864efc
@ -18,5 +18,8 @@ INCLUDE libopencm3_stm32f2.ld
|
||||
|
||||
_ram_start = ORIGIN(ram);
|
||||
_ram_end = ORIGIN(ram) + LENGTH(ram);
|
||||
_stack = _ram_end - 8;
|
||||
__stack_chk_guard = _ram_end - 8;
|
||||
system_millis = _ram_end - 4;
|
||||
|
||||
_data_size = SIZEOF(.data);
|
||||
|
@ -18,5 +18,8 @@ INCLUDE libopencm3_stm32f2.ld
|
||||
|
||||
_ram_start = ORIGIN(ram);
|
||||
_ram_end = ORIGIN(ram) + LENGTH(ram);
|
||||
_stack = _ram_end - 8;
|
||||
__stack_chk_guard = _ram_end - 8;
|
||||
system_millis = _ram_end - 4;
|
||||
|
||||
_data_size = SIZEOF(.data);
|
||||
|
2
setup.c
2
setup.c
@ -29,8 +29,6 @@
|
||||
#include "layout.h"
|
||||
#include "util.h"
|
||||
|
||||
uint32_t __stack_chk_guard;
|
||||
|
||||
static inline void __attribute__((noreturn)) fault_handler(const char *line1) {
|
||||
layoutDialog(&bmp_icon_error, NULL, NULL, NULL, line1, "detected.", NULL, "Please unplug", "the device.", NULL);
|
||||
for (;;) {} // loop forever
|
||||
|
2
timer.c
2
timer.c
@ -25,7 +25,7 @@
|
||||
#include <libopencm3/cm3/vector.h>
|
||||
|
||||
/* 1 tick = 1 ms */
|
||||
volatile uint32_t system_millis;
|
||||
extern volatile uint32_t system_millis;
|
||||
|
||||
/*
|
||||
* Initialise the Cortex-M3 SysTick timer
|
||||
|
7
util.h
7
util.h
@ -48,6 +48,7 @@ extern void __attribute__((noreturn)) shutdown(void);
|
||||
#if !EMULATOR
|
||||
// defined in memory.ld
|
||||
extern uint8_t _ram_start[], _ram_end[];
|
||||
extern uint8_t _stack[];
|
||||
|
||||
// defined in startup.s
|
||||
extern void memset_reg(void *start, void *stop, uint32_t val);
|
||||
@ -59,13 +60,13 @@ static inline void __attribute__((noreturn)) jump_to_firmware(const vector_table
|
||||
{
|
||||
if (FW_SIGNED == trust) { // trusted signed firmware
|
||||
SCB_VTOR = (uint32_t)vector_table; // * relocate vector table
|
||||
// Set stack pointer
|
||||
__asm__ volatile("msr msp, %0" :: "r" (vector_table->initial_sp_value));
|
||||
} else { // untrusted firmware
|
||||
mpu_config(); // * configure MPU
|
||||
__asm__ volatile("msr msp, %0" :: "r" (_stack));
|
||||
}
|
||||
|
||||
// Set stack pointer
|
||||
__asm__ volatile("msr msp, %0" :: "r" (vector_table->initial_sp_value));
|
||||
|
||||
// Jump to address
|
||||
vector_table->reset();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user