1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-03-06 10:16:07 +00:00

feat(core): reduce overhead of syscall invocation

[no changelog]
This commit is contained in:
cepetr 2025-03-03 16:33:10 +01:00 committed by cepetr
parent 19ba854c69
commit 45417bf3bd
6 changed files with 58 additions and 6 deletions

View File

@ -17,12 +17,18 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Turning off the stack protector for this file improves
// the performance of drawing operations when called frequently.
#pragma GCC optimize("no-stack-protector")
#include <gfx/gfx_bitblt.h>
#if USE_DMA2D
#include <gfx/dma2d_bitblt.h>
#endif
volatile uint64_t g_gfx_cycles;
void gfx_rgb565_fill(const gfx_bitblt_t* bb) {
#if defined(USE_DMA2D) && !defined(TREZOR_EMULATOR)
if (!dma2d_rgb565_fill(bb))

View File

@ -17,6 +17,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Turning off the stack protector for this file improves
// the performance of drawing operations when called frequently.
#pragma GCC optimize("no-stack-protector")
#ifdef KERNEL_MODE
#include <trezor_bsp.h>

View File

@ -17,6 +17,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Turning off the stack protector for this file significantly improves
// the performance of the syscall dispatching and interrupt handling.
#pragma GCC optimize("no-stack-protector")
#include <trezor_bsp.h>
#include <trezor_model.h>
#include <trezor_rtl.h>
@ -71,6 +75,19 @@ _Static_assert(NORCOW_SECTOR_SIZE == STORAGE_1_MAXSIZE, "norcow misconfigured");
_Static_assert(NORCOW_SECTOR_SIZE == STORAGE_2_MAXSIZE, "norcow misconfigured");
_Static_assert(NORCOW_SECTOR_SIZE == SIZE_64K, "norcow misconfigured");
static inline void mpu_disable(void) {
__DMB();
SCB->SHCSR &= ~SCB_SHCSR_MEMFAULTENA_Msk;
MPU->CTRL = 0;
}
static inline void mpu_enable(void) {
MPU->CTRL = LL_MPU_CTRL_HARDFAULT_NMI | MPU_CTRL_ENABLE_Msk;
SCB->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk;
__DSB();
__ISB();
}
static void mpu_init_fixed_regions(void) {
// Regions #0 to #4 are fixed for all targets
@ -178,7 +195,7 @@ void mpu_init(void) {
irq_key_t irq_key = irq_lock();
HAL_MPU_Disable();
mpu_disable();
mpu_init_fixed_regions();
@ -235,7 +252,7 @@ mpu_mode_t mpu_reconfig(mpu_mode_t mode) {
irq_key_t irq_key = irq_lock();
HAL_MPU_Disable();
mpu_disable();
// Region #5 and #6 are banked
@ -361,7 +378,7 @@ mpu_mode_t mpu_reconfig(mpu_mode_t mode) {
// clang-format on
if (mode != MPU_MODE_DISABLED) {
HAL_MPU_Enable(LL_MPU_CTRL_HARDFAULT_NMI);
mpu_enable();
}
mpu_mode_t prev_mode = drv->mode;

View File

@ -17,6 +17,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Turning off the stack protector for this file significantly improves
// the performance of the syscall dispatching and interrupt handling.
#pragma GCC optimize("no-stack-protector")
#include <trezor_bsp.h>
#include <trezor_model.h>
#include <trezor_rtl.h>
@ -175,6 +179,19 @@ mpu_driver_t g_mpu_driver = {
.mode = MPU_MODE_DISABLED,
};
static inline void mpu_disable(void) {
__DMB();
SCB->SHCSR &= ~SCB_SHCSR_MEMFAULTENA_Msk;
MPU->CTRL = 0;
}
static inline void mpu_enable(void) {
MPU->CTRL = LL_MPU_CTRL_HARDFAULT_NMI | MPU_CTRL_ENABLE_Msk;
SCB->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk;
__DSB();
__ISB();
}
static void mpu_init_fixed_regions(void) {
// Regions #0 to #5 are fixed for all targets
@ -240,7 +257,7 @@ void mpu_init(void) {
irq_key_t irq_key = irq_lock();
HAL_MPU_Disable();
mpu_disable();
mpu_set_attributes();
@ -308,7 +325,7 @@ mpu_mode_t mpu_reconfig(mpu_mode_t mode) {
irq_key_t irq_key = irq_lock();
HAL_MPU_Disable();
mpu_disable();
// Region #5 is banked
@ -394,7 +411,7 @@ mpu_mode_t mpu_reconfig(mpu_mode_t mode) {
// clang-format on
if (mode != MPU_MODE_DISABLED) {
HAL_MPU_Enable(LL_MPU_CTRL_HARDFAULT_NMI);
mpu_enable();
}
mpu_mode_t prev_mode = drv->mode;

View File

@ -17,6 +17,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Turning off the stack protector for this file improves
// the performance of syscall dispatching.
#pragma GCC optimize("no-stack-protector")
#include <trezor_model.h>
#include <sys/applet.h>

View File

@ -17,6 +17,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Turning off the stack protector for this file improves
// the performance of syscall dispatching.
#pragma GCC optimize("no-stack-protector")
#include <trezor_rtl.h>
#include <sys/systask.h>