mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-31 01:41:18 +00:00
refactor(core): rename stack related linker script symbols
[no changelog]
This commit is contained in:
parent
bdb3d486e3
commit
2671404e44
@ -41,6 +41,10 @@
|
||||
#include "zkp_context.h"
|
||||
#endif
|
||||
|
||||
// symbols defined in the linker script
|
||||
extern uint8_t _stack_section_start;
|
||||
extern uint8_t _stack_section_end;
|
||||
|
||||
int main(uint32_t cmd, void *arg) {
|
||||
if (cmd == 1) {
|
||||
systask_postmortem_t *info = (systask_postmortem_t *)arg;
|
||||
@ -57,8 +61,9 @@ int main(uint32_t cmd, void *arg) {
|
||||
printf("CORE: Preparing stack\n");
|
||||
// Stack limit should be less than real stack size, so we have a chance
|
||||
// to recover from limit hit.
|
||||
mp_stack_set_top(&_estack);
|
||||
mp_stack_set_limit((char *)&_estack - (char *)&_sstack - 1024);
|
||||
mp_stack_set_top(&_stack_section_end);
|
||||
mp_stack_set_limit((char *)&_stack_section_end -
|
||||
(char *)&_stack_section_start - 1024);
|
||||
|
||||
#if MICROPY_ENABLE_PYSTACK
|
||||
static mp_obj_t pystack[1024];
|
||||
|
@ -11,9 +11,8 @@ MEMORY {
|
||||
AUX1_RAM (wal) : ORIGIN = AUX1_RAM_START, LENGTH = AUX1_RAM_SIZE
|
||||
}
|
||||
|
||||
main_stack_base = ADDR(.stack) + SIZEOF(.stack); /* 8-byte aligned full descending stack */
|
||||
_sstack = ADDR(.stack);
|
||||
_estack = main_stack_base;
|
||||
_stack_section_start = ADDR(.stack);
|
||||
_stack_section_end = ADDR(.stack) + SIZEOF(.stack);
|
||||
|
||||
/* used by the startup code to populate variables used by the C code */
|
||||
data_lma = LOADADDR(.data);
|
||||
|
@ -11,9 +11,8 @@ MEMORY {
|
||||
AUX1_RAM (wal) : ORIGIN = AUX1_RAM_START, LENGTH = AUX1_RAM_SIZE
|
||||
}
|
||||
|
||||
main_stack_base = ADDR(.stack) + SIZEOF(.stack); /* 8-byte aligned full descending stack */
|
||||
_sstack = ADDR(.stack);
|
||||
_estack = main_stack_base;
|
||||
_stack_section_start = ADDR(.stack);
|
||||
_stack_section_end = ADDR(.stack) + SIZEOF(.stack);
|
||||
|
||||
/* used by the startup code to populate variables used by the C code */
|
||||
data_lma = LOADADDR(.data);
|
||||
|
@ -9,10 +9,9 @@ MEMORY {
|
||||
AUX2_RAM (wal) : ORIGIN = K_AUX2_RAM_START, LENGTH = K_AUX2_RAM_SIZE
|
||||
}
|
||||
|
||||
main_stack_base = ADDR(.stack) + SIZEOF(.stack); /* 8-byte aligned full descending stack */
|
||||
_sstack = ADDR(.stack);
|
||||
_estack = main_stack_base;
|
||||
_stack_size = SIZEOF(.stack);
|
||||
_stack_section_start = ADDR(.stack);
|
||||
_stack_section_end = ADDR(.stack) + SIZEOF(.stack);
|
||||
_stack_section_size = SIZEOF(.stack);
|
||||
|
||||
/* used by the startup code to populate variables used by the C code */
|
||||
data_lma = LOADADDR(.data);
|
||||
|
@ -11,9 +11,8 @@ MEMORY {
|
||||
DMABUF (wal) : ORIGIN = DMABUF_RAM_START, LENGTH = DMABUF_RAM_SIZE
|
||||
}
|
||||
|
||||
main_stack_base = ADDR(.stack) + SIZEOF(.stack); /* 8-byte aligned full descending stack */
|
||||
_sstack = ADDR(.stack);
|
||||
_estack = main_stack_base;
|
||||
_stack_section_start = ADDR(.stack);
|
||||
_stack_section_end = ADDR(.stack) + SIZEOF(.stack);
|
||||
|
||||
/* used by the startup code to populate variables used by the C code */
|
||||
data_lma = LOADADDR(.data);
|
||||
|
@ -11,9 +11,8 @@ MEMORY {
|
||||
AUX1_RAM (wal) : ORIGIN = AUX1_RAM_START, LENGTH = AUX1_RAM_SIZE
|
||||
}
|
||||
|
||||
main_stack_base = ADDR(.stack) + SIZEOF(.stack); /* 8-byte aligned full descending stack */
|
||||
_sstack = ADDR(.stack);
|
||||
_estack = main_stack_base;
|
||||
_stack_section_start = ADDR(.stack);
|
||||
_stack_section_end = ADDR(.stack) + SIZEOF(.stack);
|
||||
|
||||
/* used by the startup code to populate variables used by the C code */
|
||||
data_lma = LOADADDR(.data);
|
||||
|
@ -14,9 +14,8 @@ MEMORY {
|
||||
FB2_RAM (wal) : ORIGIN = FB2_RAM_START, LENGTH = FB2_RAM_SIZE
|
||||
}
|
||||
|
||||
main_stack_base = ADDR(.stack) + SIZEOF(.stack); /* 8-byte aligned full descending stack */
|
||||
_sstack = ADDR(.stack);
|
||||
_estack = main_stack_base;
|
||||
_stack_section_start = ADDR(.stack);
|
||||
_stack_section_end = ADDR(.stack) + SIZEOF(.stack);
|
||||
|
||||
/* used by the startup code to populate variables used by the C code */
|
||||
data_lma = LOADADDR(.data);
|
||||
|
@ -13,9 +13,8 @@ MEMORY {
|
||||
FB2_RAM (wal) : ORIGIN = FB2_RAM_START, LENGTH = FB2_RAM_SIZE
|
||||
}
|
||||
|
||||
main_stack_base = ADDR(.stack) + SIZEOF(.stack); /* 8-byte aligned full descending stack */
|
||||
_sstack = ADDR(.stack);
|
||||
_estack = main_stack_base;
|
||||
_stack_section_start = ADDR(.stack);
|
||||
_stack_section_end = ADDR(.stack) + SIZEOF(.stack);
|
||||
|
||||
/* used by the startup code to populate variables used by the C code */
|
||||
data_lma = LOADADDR(.data);
|
||||
|
@ -8,10 +8,9 @@ MEMORY {
|
||||
AUX2_RAM (wal) : ORIGIN = AUX2_RAM_START, LENGTH = AUX2_RAM_SIZE
|
||||
}
|
||||
|
||||
main_stack_base = ADDR(.stack) + SIZEOF(.stack); /* 8-byte aligned full descending stack */
|
||||
_sstack = ADDR(.stack);
|
||||
_estack = main_stack_base;
|
||||
_stack_size = SIZEOF(.stack);
|
||||
_stack_section_start = ADDR(.stack);
|
||||
_stack_section_end = ADDR(.stack) + SIZEOF(.stack);
|
||||
_stack_section_size = SIZEOF(.stack);
|
||||
|
||||
/* used by the startup code to populate variables used by the C code */
|
||||
data_lma = LOADADDR(.data);
|
||||
|
@ -12,9 +12,8 @@ MEMORY {
|
||||
FB2_RAM (wal) : ORIGIN = FB2_RAM_START, LENGTH = FB2_RAM_SIZE
|
||||
}
|
||||
|
||||
main_stack_base = ADDR(.stack) + SIZEOF(.stack); /* 8-byte aligned full descending stack */
|
||||
_sstack = ADDR(.stack);
|
||||
_estack = main_stack_base;
|
||||
_stack_section_start = ADDR(.stack);
|
||||
_stack_section_end = ADDR(.stack) + SIZEOF(.stack);
|
||||
|
||||
ustack_base = ADDR(.udata) + 512;
|
||||
_sustack = ADDR(.udata) + 256;
|
||||
|
@ -13,9 +13,8 @@ MEMORY {
|
||||
FB2_RAM (wal) : ORIGIN = FB2_RAM_START, LENGTH = FB2_RAM_SIZE
|
||||
}
|
||||
|
||||
main_stack_base = ADDR(.stack) + SIZEOF(.stack); /* 8-byte aligned full descending stack */
|
||||
_sstack = ADDR(.stack);
|
||||
_estack = main_stack_base;
|
||||
_stack_section_start = ADDR(.stack);
|
||||
_stack_section_end = ADDR(.stack) + SIZEOF(.stack);
|
||||
|
||||
/* used by the startup code to populate variables used by the C code */
|
||||
data_lma = LOADADDR(.data);
|
||||
|
@ -14,9 +14,8 @@ MEMORY {
|
||||
FB2_RAM (wal) : ORIGIN = FB2_RAM_START, LENGTH = FB2_RAM_SIZE
|
||||
}
|
||||
|
||||
main_stack_base = ADDR(.stack) + SIZEOF(.stack); /* 8-byte aligned full descending stack */
|
||||
_sstack = ADDR(.stack);
|
||||
_estack = main_stack_base;
|
||||
_stack_section_start = ADDR(.stack);
|
||||
_stack_section_end = ADDR(.stack) + SIZEOF(.stack);
|
||||
|
||||
/* used by the startup code to populate variables used by the C code */
|
||||
data_lma = LOADADDR(.data);
|
||||
|
@ -13,9 +13,8 @@ MEMORY {
|
||||
FB2_RAM (wal) : ORIGIN = FB2_RAM_START, LENGTH = FB2_RAM_SIZE
|
||||
}
|
||||
|
||||
main_stack_base = ADDR(.stack) + SIZEOF(.stack); /* 8-byte aligned full descending stack */
|
||||
_sstack = ADDR(.stack);
|
||||
_estack = main_stack_base;
|
||||
_stack_section_start = ADDR(.stack);
|
||||
_stack_section_end = ADDR(.stack) + SIZEOF(.stack);
|
||||
|
||||
/* used by the startup code to populate variables used by the C code */
|
||||
data_lma = LOADADDR(.data);
|
||||
|
@ -7,10 +7,9 @@ MEMORY {
|
||||
AUX1_RAM (wal) : ORIGIN = AUX1_RAM_START, LENGTH = AUX1_RAM_SIZE
|
||||
}
|
||||
|
||||
main_stack_base = ADDR(.stack) + SIZEOF(.stack); /* 8-byte aligned full descending stack */
|
||||
_sstack = ADDR(.stack);
|
||||
_estack = main_stack_base;
|
||||
_stack_size = SIZEOF(.stack);
|
||||
_stack_section_start = ADDR(.stack);
|
||||
_stack_section_end = ADDR(.stack) + SIZEOF(.stack);
|
||||
_stack_section_size = SIZEOF(.stack);
|
||||
|
||||
/* used by the startup code to populate variables used by the C code */
|
||||
data_lma = LOADADDR(.data);
|
||||
|
@ -12,9 +12,9 @@ MEMORY {
|
||||
FB2_RAM (wal) : ORIGIN = FB2_RAM_START, LENGTH = FB2_RAM_SIZE
|
||||
}
|
||||
|
||||
main_stack_base = ADDR(.stack) + SIZEOF(.stack); /* 8-byte aligned full descending stack */
|
||||
_sstack = ADDR(.stack);
|
||||
_estack = main_stack_base;
|
||||
_stack_section_start = ADDR(.stack);
|
||||
_stack_section_end = ADDR(.stack) + SIZEOF(.stack);
|
||||
|
||||
|
||||
ustack_base = ADDR(.udata) + 512;
|
||||
_sustack = ADDR(.udata) + 256;
|
||||
|
@ -13,9 +13,8 @@ MEMORY {
|
||||
FB2_RAM (wal) : ORIGIN = FB2_RAM_START, LENGTH = FB2_RAM_SIZE
|
||||
}
|
||||
|
||||
main_stack_base = ADDR(.stack) + SIZEOF(.stack); /* 8-byte aligned full descending stack */
|
||||
_sstack = ADDR(.stack);
|
||||
_estack = main_stack_base;
|
||||
_stack_section_start = ADDR(.stack);
|
||||
_stack_section_end = ADDR(.stack) + SIZEOF(.stack);
|
||||
|
||||
/* used by the startup code to populate variables used by the C code */
|
||||
data_lma = LOADADDR(.data);
|
||||
|
@ -20,7 +20,7 @@ default_handler:
|
||||
// Section B1.5 - ARMv7-M Architecture Reference Manual
|
||||
.section .vector_table, "a"
|
||||
vector_table:
|
||||
.word main_stack_base // defined in linker script
|
||||
.word _stack_section_end // defined in linker script
|
||||
add_handler reset_handler
|
||||
add_handler NMI_Handler
|
||||
add_handler HardFault_Handler
|
||||
@ -132,8 +132,8 @@ vector_table:
|
||||
|
||||
.section .vector_table, "a"
|
||||
vector_table:
|
||||
.word _sstack
|
||||
.word _stack_size
|
||||
.word _stack_section_start
|
||||
.word _stack_section_size
|
||||
.word reset_handler
|
||||
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
.type reset_handler, STT_FUNC
|
||||
reset_handler:
|
||||
// set the stack protection
|
||||
ldr r0, =_sstack
|
||||
ldr r0, =_stack_section_start
|
||||
add r0, r0, #128 // safety margin for the exception frame
|
||||
msr MSPLIM, r0
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
.type reset_handler, STT_FUNC
|
||||
reset_handler:
|
||||
// set the stack protection
|
||||
ldr r0, =_sstack
|
||||
ldr r0, =_stack_section_start
|
||||
add r0, r0, #128 // safety margin for the exception frame
|
||||
msr MSPLIM, r0
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
.type reset_handler, STT_FUNC
|
||||
reset_handler:
|
||||
// set the stack protection
|
||||
ldr r0, =_sstack
|
||||
ldr r0, =_stack_section_start
|
||||
add r0, r0, #128 // safety margin for the exception frame
|
||||
msr MSPLIM, r0
|
||||
|
||||
|
@ -20,7 +20,7 @@ default_handler:
|
||||
// Section B1.5 - ARMv7-M Architecture Reference Manual
|
||||
.section .vector_table, "a"
|
||||
vector_table:
|
||||
.word main_stack_base // defined in linker script
|
||||
.word _stack_section_end // defined in linker script
|
||||
add_handler reset_handler
|
||||
add_handler NMI_Handler
|
||||
add_handler HardFault_Handler
|
||||
@ -180,8 +180,8 @@ vector_table:
|
||||
|
||||
.section .vector_table, "a"
|
||||
vector_table:
|
||||
.word _sstack
|
||||
.word _stack_size
|
||||
.word _stack_section_start
|
||||
.word _stack_section_size
|
||||
.word reset_handler
|
||||
|
||||
#endif
|
||||
|
@ -55,8 +55,8 @@ typedef struct {
|
||||
} systask_scheduler_t;
|
||||
|
||||
// Kernel stack base pointer defined in linker script
|
||||
extern uint8_t _sstack;
|
||||
extern uint8_t _estack;
|
||||
extern uint8_t _stack_section_start;
|
||||
extern uint8_t _stack_section_end;
|
||||
|
||||
// Global task manager state
|
||||
static systask_scheduler_t g_systask_scheduler = {
|
||||
@ -65,7 +65,7 @@ static systask_scheduler_t g_systask_scheduler = {
|
||||
.active_task = &g_systask_scheduler.kernel_task,
|
||||
.waiting_task = &g_systask_scheduler.kernel_task,
|
||||
.kernel_task = {
|
||||
.sp_lim = (uint32_t)&_sstack,
|
||||
.sp_lim = (uint32_t)&_stack_section_start,
|
||||
}};
|
||||
|
||||
void systask_scheduler_init(systask_error_handler_t error_handler) {
|
||||
@ -77,7 +77,7 @@ void systask_scheduler_init(systask_error_handler_t error_handler) {
|
||||
scheduler->active_task = &scheduler->kernel_task;
|
||||
scheduler->waiting_task = scheduler->active_task;
|
||||
|
||||
scheduler->kernel_task.sp_lim = (uint32_t)&_sstack;
|
||||
scheduler->kernel_task.sp_lim = (uint32_t)&_stack_section_start;
|
||||
|
||||
// SVCall priority should be the lowest since it is
|
||||
// generally a blocking operation
|
||||
@ -541,7 +541,7 @@ __attribute__((naked, no_stack_protector)) void HardFault_Handler(void) {
|
||||
"MOV R0, #1 \n" // R0 = 1 (Privileged)
|
||||
"B systask_exit_fault \n" // Exit task with fault
|
||||
:
|
||||
: [estack] "i"(&_estack)
|
||||
: [estack] "i"(&_stack_section_end)
|
||||
: "memory");
|
||||
}
|
||||
|
||||
@ -565,7 +565,9 @@ __attribute__((naked, no_stack_protector)) void MemManage_Handler(void) {
|
||||
#endif
|
||||
"B systask_exit_fault \n" // Exit task with fault
|
||||
:
|
||||
: [estack] "i"(&_estack), [sstack] "i"((uint32_t)&_sstack + 256)
|
||||
: [estack] "i"(&_stack_section_end), [sstack] "i"(
|
||||
(uint32_t)&_stack_section_start +
|
||||
256)
|
||||
: "memory");
|
||||
}
|
||||
|
||||
@ -600,7 +602,7 @@ __attribute__((naked, no_stack_protector)) void UsageFault_Handler(void) {
|
||||
"MOV R0, #1 \n" // R0 = 1 (Privileged)
|
||||
"B systask_exit_fault \n" // Exit task with fault
|
||||
:
|
||||
: [estack] "i"(&_estack)
|
||||
: [estack] "i"(&_stack_section_end)
|
||||
: "memory");
|
||||
}
|
||||
|
||||
|
@ -41,6 +41,10 @@
|
||||
|
||||
#ifdef KERNEL_MODE
|
||||
|
||||
// Kernel stack base pointer defined in linker script
|
||||
extern uint8_t _stack_section_start;
|
||||
extern uint8_t _stack_section_end;
|
||||
|
||||
void system_init(systask_error_handler_t error_handler) {
|
||||
#if defined(TREZOR_MODEL_T2T1) && (!defined(BOARDLOADER))
|
||||
// Early boardloader versions on Model T initialized the CPU clock to 168MHz.
|
||||
@ -198,10 +202,10 @@ __attribute((naked, no_stack_protector)) void system_emergency_rescue(
|
||||
// Setup new stack
|
||||
// --------------------------------------------------------------
|
||||
|
||||
"LDR R0, =_estack \n" // Setup new stack
|
||||
"LDR R0, =%[estack] \n" // Setup new stack
|
||||
"MSR MSP, R0 \n" // Set MSP
|
||||
#if defined(__ARM_ARCH_8M_MAIN__) || defined(__ARM_ARCH_8M_BASE__)
|
||||
"LDR R0, =_sstack \n"
|
||||
"LDR R0, =%[sstack] \n"
|
||||
"ADD R0, R0, #256 \n" // Add safety margin
|
||||
"MSR MSPLIM, R0 \n" // Set MSPLIM
|
||||
#endif
|
||||
@ -331,7 +335,8 @@ __attribute((naked, no_stack_protector)) void system_emergency_rescue(
|
||||
"BX LR \n"
|
||||
: // no output
|
||||
: [PMINFO_SIZE] "i"(sizeof(systask_postmortem_t)),
|
||||
[STK_GUARD] "i"(&__stack_chk_guard)
|
||||
[STK_GUARD] "i"(&__stack_chk_guard), [estack] "i"(&_stack_section_end),
|
||||
[sstack] "i"((uint32_t)&_stack_section_start)
|
||||
: // no clobber
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user