]> begriffs open source - freertos/blob - portable/IAR/ARM_CM33/secure/secure_context_port_asm.s
Associate secure context with task handle
[freertos] / portable / IAR / ARM_CM33 / secure / secure_context_port_asm.s
1 /*\r
2  * FreeRTOS Kernel <DEVELOPMENT BRANCH>\r
3  * Copyright (C) 2021 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\r
5  * SPDX-License-Identifier: MIT\r
6  *\r
7  * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
8  * this software and associated documentation files (the "Software"), to deal in\r
9  * the Software without restriction, including without limitation the rights to\r
10  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
11  * the Software, and to permit persons to whom the Software is furnished to do so,\r
12  * subject to the following conditions:\r
13  *\r
14  * The above copyright notice and this permission notice shall be included in all\r
15  * copies or substantial portions of the Software.\r
16  *\r
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
19  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
20  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
21  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
22  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
23  *\r
24  * https://www.FreeRTOS.org\r
25  * https://github.com/FreeRTOS\r
26  *\r
27  */\r
28 \r
29     SECTION .text:CODE:NOROOT(2)\r
30     THUMB\r
31 \r
32 /* Including FreeRTOSConfig.h here will cause build errors if the header file\r
33 contains code not understood by the assembler - for example the 'extern' keyword.\r
34 To avoid errors place any such code inside a #ifdef __ICCARM__/#endif block so\r
35 the code is included in C files but excluded by the preprocessor in assembly\r
36 files (__ICCARM__ is defined by the IAR C compiler but not by the IAR assembler. */\r
37 #include "FreeRTOSConfig.h"\r
38 \r
39     PUBLIC SecureContext_LoadContextAsm\r
40     PUBLIC SecureContext_SaveContextAsm\r
41 /*-----------------------------------------------------------*/\r
42 \r
43 SecureContext_LoadContextAsm:\r
44     /* pxSecureContext value is in r0. */\r
45     mrs r1, ipsr                        /* r1 = IPSR. */\r
46     cbz r1, load_ctx_therad_mode        /* Do nothing if the processor is running in the Thread Mode. */\r
47     ldmia r0!, {r1, r2}                 /* r1 = pxSecureContext->pucCurrentStackPointer, r2 = pxSecureContext->pucStackLimit. */\r
48 \r
49 #if ( configENABLE_MPU == 1 )\r
50     ldmia r1!, {r3}                     /* Read CONTROL register value from task's stack. r3 = CONTROL. */\r
51     msr control, r3                     /* CONTROL = r3. */\r
52 #endif /* configENABLE_MPU */\r
53 \r
54     msr psplim, r2                      /* PSPLIM = r2. */\r
55     msr psp, r1                         /* PSP = r1. */\r
56 \r
57     load_ctx_therad_mode:\r
58         bx lr\r
59 /*-----------------------------------------------------------*/\r
60 \r
61 SecureContext_SaveContextAsm:\r
62     /* pxSecureContext value is in r0. */\r
63     mrs r1, ipsr                        /* r1 = IPSR. */\r
64     cbz r1, save_ctx_therad_mode        /* Do nothing if the processor is running in the Thread Mode. */\r
65     mrs r1, psp                         /* r1 = PSP. */\r
66 \r
67 #if ( configENABLE_FPU == 1 )\r
68     vstmdb r1!, {s0}                    /* Trigger the defferred stacking of FPU registers. */\r
69     vldmia r1!, {s0}                    /* Nullify the effect of the pervious statement. */\r
70 #endif /* configENABLE_FPU */\r
71 \r
72 #if ( configENABLE_MPU == 1 )\r
73     mrs r2, control                     /* r2 = CONTROL. */\r
74     stmdb r1!, {r2}                     /* Store CONTROL value on the stack. */\r
75 #endif /* configENABLE_MPU */\r
76 \r
77     str r1, [r0]                        /* Save the top of stack in context. pxSecureContext->pucCurrentStackPointer = r1. */\r
78     movs r1, #0                         /* r1 = securecontextNO_STACK. */\r
79     msr psplim, r1                      /* PSPLIM = securecontextNO_STACK. */\r
80     msr psp, r1                         /* PSP = securecontextNO_STACK i.e. No stack for thread mode until next task's context is loaded. */\r
81 \r
82     save_ctx_therad_mode:\r
83         bx lr\r
84 /*-----------------------------------------------------------*/\r
85 \r
86     END\r