]> begriffs open source - freertos/blob - portable/GCC/IA32_flat/ISR_Support.h
Update SMP branch readme for port migration (#999)
[freertos] / portable / GCC / IA32_flat / ISR_Support.h
1 /*
2  * FreeRTOS SMP Kernel V202110.00
3  * Copyright (C) 2020 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of
6  * this software and associated documentation files (the "Software"), to deal in
7  * the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9  * the Software, and to permit persons to whom the Software is furnished to do so,
10  * subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * https://www.FreeRTOS.org
23  * https://github.com/FreeRTOS
24  *
25  * 1 tab == 4 spaces!
26  */
27
28         .extern ulTopOfSystemStack
29         .extern ulInterruptNesting
30
31 /*-----------------------------------------------------------*/
32
33 .macro portFREERTOS_INTERRUPT_ENTRY
34
35         /* Save general purpose registers. */
36         pusha
37
38         /* If ulInterruptNesting is zero the rest of the task context will need
39         saving and a stack switch might be required. */
40         movl    ulInterruptNesting, %eax
41         test    %eax, %eax
42         jne             2f
43
44         /* Interrupts are not nested, so save the rest of the task context. */
45         .if configSUPPORT_FPU == 1
46
47                 /* If the task has a buffer allocated to save the FPU context then
48                 save the FPU context now. */
49                 movl    pucPortTaskFPUContextBuffer, %eax
50                 test    %eax, %eax
51                 je              1f
52                 fnsave  ( %eax ) /* Save FLOP context into ucTempFPUBuffer array. */
53                 fwait
54
55                 1:
56                 /* Save the address of the FPU context, if any. */
57                 push    pucPortTaskFPUContextBuffer
58
59         .endif /* configSUPPORT_FPU */
60
61         /* Find the TCB. */
62         movl    pxCurrentTCB, %eax
63
64         /* Stack location is first item in the TCB. */
65         movl    %esp, (%eax)
66
67         /* Switch stacks. */
68         movl    ulTopOfSystemStack, %esp
69         movl    %esp, %ebp
70
71         2:
72         /* Increment nesting count. */
73         add     $1, ulInterruptNesting
74
75 .endm
76 /*-----------------------------------------------------------*/
77
78 .macro portINTERRUPT_EPILOGUE
79
80         cli
81         sub             $1, ulInterruptNesting
82
83         /* If the nesting has unwound to zero. */
84         movl    ulInterruptNesting, %eax
85         test    %eax, %eax
86         jne             2f
87
88         /* If a yield was requested then select a new TCB now. */
89         movl    ulPortYieldPending, %eax
90         test    %eax, %eax
91         je              1f
92         movl    $0, ulPortYieldPending
93         call    vTaskSwitchContext
94
95         1:
96         /* Stack location is first item in the TCB. */
97         movl    pxCurrentTCB, %eax
98         movl    (%eax), %esp
99
100         .if configSUPPORT_FPU == 1
101
102                 /* Restore address of task's FPU context buffer. */
103                 pop     pucPortTaskFPUContextBuffer
104
105                 /* If the task has a buffer allocated in which its FPU context is saved,
106                 then restore it now. */
107                 movl    pucPortTaskFPUContextBuffer, %eax
108                 test    %eax, %eax
109                 je              1f
110                 frstor  ( %eax )
111                 1:
112         .endif
113
114         2:
115         popa
116
117 .endm
118 /*-----------------------------------------------------------*/
119
120 .macro portFREERTOS_INTERRUPT_EXIT
121
122         portINTERRUPT_EPILOGUE
123         /* EOI. */
124         movl    $0x00, (0xFEE000B0)
125         iret
126
127 .endm