Official mbed Real Time Operating System based on the RTX implementation of the CMSIS-RTOS API open standard.

Dependents:   denki-yohou_b TestY201 Network-RTOS NTPClient_HelloWorld ... more

Deprecated

This is the mbed 2 rtos library. mbed OS 5 integrates the mbed library with mbed-rtos. With this, we have provided thread safety for all mbed APIs. If you'd like to learn about using mbed OS 5, please see the docs.

Committer:
mbed_official
Date:
Wed Jul 01 08:15:48 2015 +0100
Revision:
86:58c3b7759abf
Parent:
rtx/TARGET_CORTEX_M/TARGET_M3/TOOLCHAIN_GCC/HAL_CM3.s@68:d3d0e710b443
Child:
112:53ace74b190c
Synchronized with git revision 7766e75dd858812cd79aedb3080349715f55dd56

Full URL: https://github.com/mbedmicro/mbed/commit/7766e75dd858812cd79aedb3080349715f55dd56/

GCC asm updates

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 49:77c8e4604045 1 /*----------------------------------------------------------------------------
mbed_official 49:77c8e4604045 2 * RL-ARM - RTX
mbed_official 49:77c8e4604045 3 *----------------------------------------------------------------------------
mbed_official 49:77c8e4604045 4 * Name: HAL_CM3.S
mbed_official 49:77c8e4604045 5 * Purpose: Hardware Abstraction Layer for Cortex-M3
mbed_official 49:77c8e4604045 6 * Rev.: V4.60
mbed_official 49:77c8e4604045 7 *----------------------------------------------------------------------------
mbed_official 49:77c8e4604045 8 *
mbed_official 49:77c8e4604045 9 * Copyright (c) 1999-2009 KEIL, 2009-2012 ARM Germany GmbH
mbed_official 49:77c8e4604045 10 * All rights reserved.
mbed_official 49:77c8e4604045 11 * Redistribution and use in source and binary forms, with or without
mbed_official 49:77c8e4604045 12 * modification, are permitted provided that the following conditions are met:
mbed_official 49:77c8e4604045 13 * - Redistributions of source code must retain the above copyright
mbed_official 49:77c8e4604045 14 * notice, this list of conditions and the following disclaimer.
mbed_official 49:77c8e4604045 15 * - Redistributions in binary form must reproduce the above copyright
mbed_official 49:77c8e4604045 16 * notice, this list of conditions and the following disclaimer in the
mbed_official 49:77c8e4604045 17 * documentation and/or other materials provided with the distribution.
mbed_official 68:d3d0e710b443 18 * - Neither the name of ARM nor the names of its contributors may be used
mbed_official 68:d3d0e710b443 19 * to endorse or promote products derived from this software without
mbed_official 49:77c8e4604045 20 * specific prior written permission.
mbed_official 49:77c8e4604045 21 *
mbed_official 68:d3d0e710b443 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 68:d3d0e710b443 23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 49:77c8e4604045 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
mbed_official 49:77c8e4604045 25 * ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
mbed_official 49:77c8e4604045 26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
mbed_official 68:d3d0e710b443 27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
mbed_official 68:d3d0e710b443 28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
mbed_official 68:d3d0e710b443 29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
mbed_official 68:d3d0e710b443 30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
mbed_official 49:77c8e4604045 31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
mbed_official 49:77c8e4604045 32 * POSSIBILITY OF SUCH DAMAGE.
mbed_official 49:77c8e4604045 33 *---------------------------------------------------------------------------*/
mbed_official 49:77c8e4604045 34
mbed_official 49:77c8e4604045 35 .file "HAL_CM3.S"
mbed_official 49:77c8e4604045 36 .syntax unified
mbed_official 49:77c8e4604045 37
mbed_official 59:28712e303960 38 .equ TCB_TSTACK, 40
mbed_official 49:77c8e4604045 39
mbed_official 49:77c8e4604045 40
mbed_official 49:77c8e4604045 41 /*----------------------------------------------------------------------------
mbed_official 49:77c8e4604045 42 * Functions
mbed_official 49:77c8e4604045 43 *---------------------------------------------------------------------------*/
mbed_official 49:77c8e4604045 44
mbed_official 49:77c8e4604045 45 .thumb
mbed_official 49:77c8e4604045 46
mbed_official 49:77c8e4604045 47 .section ".text"
mbed_official 49:77c8e4604045 48 .align 2
mbed_official 49:77c8e4604045 49
mbed_official 49:77c8e4604045 50
mbed_official 49:77c8e4604045 51 /*--------------------------- rt_set_PSP ------------------------------------*/
mbed_official 49:77c8e4604045 52
mbed_official 49:77c8e4604045 53 # void rt_set_PSP (U32 stack);
mbed_official 49:77c8e4604045 54
mbed_official 49:77c8e4604045 55 .thumb_func
mbed_official 49:77c8e4604045 56 .type rt_set_PSP, %function
mbed_official 49:77c8e4604045 57 .global rt_set_PSP
mbed_official 49:77c8e4604045 58 rt_set_PSP:
mbed_official 49:77c8e4604045 59 .fnstart
mbed_official 49:77c8e4604045 60 .cantunwind
mbed_official 49:77c8e4604045 61
mbed_official 49:77c8e4604045 62 MSR PSP,R0
mbed_official 49:77c8e4604045 63 BX LR
mbed_official 49:77c8e4604045 64
mbed_official 49:77c8e4604045 65 .fnend
mbed_official 49:77c8e4604045 66 .size rt_set_PSP, .-rt_set_PSP
mbed_official 49:77c8e4604045 67
mbed_official 49:77c8e4604045 68
mbed_official 49:77c8e4604045 69 /*--------------------------- rt_get_PSP ------------------------------------*/
mbed_official 49:77c8e4604045 70
mbed_official 49:77c8e4604045 71 # U32 rt_get_PSP (void);
mbed_official 49:77c8e4604045 72
mbed_official 49:77c8e4604045 73 .thumb_func
mbed_official 49:77c8e4604045 74 .type rt_get_PSP, %function
mbed_official 49:77c8e4604045 75 .global rt_get_PSP
mbed_official 49:77c8e4604045 76 rt_get_PSP:
mbed_official 49:77c8e4604045 77 .fnstart
mbed_official 49:77c8e4604045 78 .cantunwind
mbed_official 49:77c8e4604045 79
mbed_official 49:77c8e4604045 80 MRS R0,PSP
mbed_official 49:77c8e4604045 81 BX LR
mbed_official 49:77c8e4604045 82
mbed_official 49:77c8e4604045 83 .fnend
mbed_official 49:77c8e4604045 84 .size rt_get_PSP, .-rt_get_PSP
mbed_official 49:77c8e4604045 85
mbed_official 49:77c8e4604045 86
mbed_official 49:77c8e4604045 87 /*--------------------------- os_set_env ------------------------------------*/
mbed_official 49:77c8e4604045 88
mbed_official 49:77c8e4604045 89 # void os_set_env (void);
mbed_official 49:77c8e4604045 90 /* Switch to Unprivileged/Privileged Thread mode, use PSP. */
mbed_official 49:77c8e4604045 91
mbed_official 49:77c8e4604045 92 .thumb_func
mbed_official 49:77c8e4604045 93 .type os_set_env, %function
mbed_official 49:77c8e4604045 94 .global os_set_env
mbed_official 49:77c8e4604045 95 os_set_env:
mbed_official 49:77c8e4604045 96 .fnstart
mbed_official 49:77c8e4604045 97 .cantunwind
mbed_official 49:77c8e4604045 98
mbed_official 49:77c8e4604045 99 MOV R0,SP /* PSP = MSP */
mbed_official 49:77c8e4604045 100 MSR PSP,R0
mbed_official 49:77c8e4604045 101 LDR R0,=os_flags
mbed_official 49:77c8e4604045 102 LDRB R0,[R0]
mbed_official 49:77c8e4604045 103 LSLS R0,#31
mbed_official 49:77c8e4604045 104 ITE NE
mbed_official 49:77c8e4604045 105 MOVNE R0,#0x02 /* Privileged Thread mode, use PSP */
mbed_official 49:77c8e4604045 106 MOVEQ R0,#0x03 /* Unprivileged Thread mode, use PSP */
mbed_official 49:77c8e4604045 107 MSR CONTROL,R0
mbed_official 49:77c8e4604045 108 BX LR
mbed_official 49:77c8e4604045 109
mbed_official 49:77c8e4604045 110 .fnend
mbed_official 49:77c8e4604045 111 .size os_set_env, .-os_set_env
mbed_official 49:77c8e4604045 112
mbed_official 49:77c8e4604045 113
mbed_official 49:77c8e4604045 114 /*--------------------------- _alloc_box ------------------------------------*/
mbed_official 49:77c8e4604045 115
mbed_official 49:77c8e4604045 116 # void *_alloc_box (void *box_mem);
mbed_official 49:77c8e4604045 117 /* Function wrapper for Unprivileged/Privileged mode. */
mbed_official 49:77c8e4604045 118
mbed_official 49:77c8e4604045 119 .thumb_func
mbed_official 49:77c8e4604045 120 .type _alloc_box, %function
mbed_official 49:77c8e4604045 121 .global _alloc_box
mbed_official 49:77c8e4604045 122 _alloc_box:
mbed_official 49:77c8e4604045 123 .fnstart
mbed_official 49:77c8e4604045 124 .cantunwind
mbed_official 49:77c8e4604045 125
mbed_official 49:77c8e4604045 126 LDR R12,=rt_alloc_box
mbed_official 49:77c8e4604045 127 MRS R3,IPSR
mbed_official 49:77c8e4604045 128 LSLS R3,#24
mbed_official 49:77c8e4604045 129 IT NE
mbed_official 49:77c8e4604045 130 BXNE R12
mbed_official 49:77c8e4604045 131 MRS R3,CONTROL
mbed_official 49:77c8e4604045 132 LSLS R3,#31
mbed_official 49:77c8e4604045 133 IT EQ
mbed_official 49:77c8e4604045 134 BXEQ R12
mbed_official 49:77c8e4604045 135 SVC 0
mbed_official 49:77c8e4604045 136 BX LR
mbed_official 49:77c8e4604045 137
mbed_official 49:77c8e4604045 138 .fnend
mbed_official 49:77c8e4604045 139 .size _alloc_box, .-_alloc_box
mbed_official 49:77c8e4604045 140
mbed_official 49:77c8e4604045 141
mbed_official 49:77c8e4604045 142 /*--------------------------- _free_box -------------------------------------*/
mbed_official 49:77c8e4604045 143
mbed_official 49:77c8e4604045 144 # int _free_box (void *box_mem, void *box);
mbed_official 49:77c8e4604045 145 /* Function wrapper for Unprivileged/Privileged mode. */
mbed_official 49:77c8e4604045 146
mbed_official 49:77c8e4604045 147 .thumb_func
mbed_official 49:77c8e4604045 148 .type _free_box, %function
mbed_official 49:77c8e4604045 149 .global _free_box
mbed_official 49:77c8e4604045 150 _free_box:
mbed_official 49:77c8e4604045 151 .fnstart
mbed_official 49:77c8e4604045 152 .cantunwind
mbed_official 49:77c8e4604045 153
mbed_official 49:77c8e4604045 154 LDR R12,=rt_free_box
mbed_official 49:77c8e4604045 155 MRS R3,IPSR
mbed_official 49:77c8e4604045 156 LSLS R3,#24
mbed_official 49:77c8e4604045 157 IT NE
mbed_official 49:77c8e4604045 158 BXNE R12
mbed_official 49:77c8e4604045 159 MRS R3,CONTROL
mbed_official 49:77c8e4604045 160 LSLS R3,#31
mbed_official 49:77c8e4604045 161 IT EQ
mbed_official 49:77c8e4604045 162 BXEQ R12
mbed_official 49:77c8e4604045 163 SVC 0
mbed_official 49:77c8e4604045 164 BX LR
mbed_official 49:77c8e4604045 165
mbed_official 49:77c8e4604045 166 .fnend
mbed_official 49:77c8e4604045 167 .size _free_box, .-_free_box
mbed_official 49:77c8e4604045 168
mbed_official 49:77c8e4604045 169
mbed_official 49:77c8e4604045 170 /*-------------------------- SVC_Handler ------------------------------------*/
mbed_official 49:77c8e4604045 171
mbed_official 49:77c8e4604045 172 # void SVC_Handler (void);
mbed_official 49:77c8e4604045 173
mbed_official 49:77c8e4604045 174 .thumb_func
mbed_official 49:77c8e4604045 175 .type SVC_Handler, %function
mbed_official 49:77c8e4604045 176 .global SVC_Handler
mbed_official 49:77c8e4604045 177 SVC_Handler:
mbed_official 49:77c8e4604045 178 .fnstart
mbed_official 49:77c8e4604045 179 .cantunwind
mbed_official 49:77c8e4604045 180
mbed_official 49:77c8e4604045 181 MRS R0,PSP /* Read PSP */
mbed_official 49:77c8e4604045 182 LDR R1,[R0,#24] /* Read Saved PC from Stack */
mbed_official 49:77c8e4604045 183 LDRB R1,[R1,#-2] /* Load SVC Number */
mbed_official 49:77c8e4604045 184 CBNZ R1,SVC_User
mbed_official 49:77c8e4604045 185
mbed_official 49:77c8e4604045 186 LDM R0,{R0-R3,R12} /* Read R0-R3,R12 from stack */
mbed_official 49:77c8e4604045 187 BLX R12 /* Call SVC Function */
mbed_official 49:77c8e4604045 188
mbed_official 49:77c8e4604045 189 MRS R12,PSP /* Read PSP */
mbed_official 49:77c8e4604045 190 STM R12,{R0-R2} /* Store return values */
mbed_official 49:77c8e4604045 191
mbed_official 49:77c8e4604045 192 LDR R3,=os_tsk
mbed_official 49:77c8e4604045 193 LDM R3,{R1,R2} /* os_tsk.run, os_tsk.new */
mbed_official 49:77c8e4604045 194 CMP R1,R2
mbed_official 49:77c8e4604045 195 BEQ SVC_Exit /* no task switch */
mbed_official 49:77c8e4604045 196
mbed_official 49:77c8e4604045 197 CBZ R1,SVC_Next /* Runtask deleted? */
mbed_official 49:77c8e4604045 198 STMDB R12!,{R4-R11} /* Save Old context */
mbed_official 49:77c8e4604045 199 STR R12,[R1,#TCB_TSTACK] /* Update os_tsk.run->tsk_stack */
mbed_official 49:77c8e4604045 200
mbed_official 49:77c8e4604045 201 PUSH {R2,R3}
mbed_official 49:77c8e4604045 202 BL rt_stk_check /* Check for Stack overflow */
mbed_official 49:77c8e4604045 203 POP {R2,R3}
mbed_official 49:77c8e4604045 204
mbed_official 49:77c8e4604045 205 SVC_Next:
mbed_official 49:77c8e4604045 206 STR R2,[R3] /* os_tsk.run = os_tsk.new */
mbed_official 49:77c8e4604045 207
mbed_official 49:77c8e4604045 208 LDR R12,[R2,#TCB_TSTACK] /* os_tsk.new->tsk_stack */
mbed_official 49:77c8e4604045 209 LDMIA R12!,{R4-R11} /* Restore New Context */
mbed_official 49:77c8e4604045 210 MSR PSP,R12 /* Write PSP */
mbed_official 49:77c8e4604045 211
mbed_official 49:77c8e4604045 212 SVC_Exit:
mbed_official 49:77c8e4604045 213 MVN LR,#~0xFFFFFFFD /* set EXC_RETURN value */
mbed_official 49:77c8e4604045 214 BX LR
mbed_official 49:77c8e4604045 215
mbed_official 49:77c8e4604045 216 /*------------------- User SVC ------------------------------*/
mbed_official 49:77c8e4604045 217
mbed_official 49:77c8e4604045 218 SVC_User:
mbed_official 49:77c8e4604045 219 PUSH {R4,LR} /* Save Registers */
mbed_official 49:77c8e4604045 220 LDR R2,=SVC_Count
mbed_official 49:77c8e4604045 221 LDR R2,[R2]
mbed_official 49:77c8e4604045 222 CMP R1,R2
mbed_official 49:77c8e4604045 223 BHI SVC_Done /* Overflow */
mbed_official 49:77c8e4604045 224
mbed_official 49:77c8e4604045 225 LDR R4,=SVC_Table-4
mbed_official 49:77c8e4604045 226 LDR R4,[R4,R1,LSL #2] /* Load SVC Function Address */
mbed_official 49:77c8e4604045 227
mbed_official 49:77c8e4604045 228 LDM R0,{R0-R3,R12} /* Read R0-R3,R12 from stack */
mbed_official 49:77c8e4604045 229 BLX R4 /* Call SVC Function */
mbed_official 49:77c8e4604045 230
mbed_official 49:77c8e4604045 231 MRS R12,PSP
mbed_official 49:77c8e4604045 232 STM R12,{R0-R3} /* Function return values */
mbed_official 49:77c8e4604045 233 SVC_Done:
mbed_official 49:77c8e4604045 234 POP {R4,PC} /* RETI */
mbed_official 49:77c8e4604045 235
mbed_official 49:77c8e4604045 236 .fnend
mbed_official 49:77c8e4604045 237 .size SVC_Handler, .-SVC_Handler
mbed_official 68:d3d0e710b443 238
mbed_official 49:77c8e4604045 239
mbed_official 49:77c8e4604045 240 /*-------------------------- PendSV_Handler ---------------------------------*/
mbed_official 49:77c8e4604045 241
mbed_official 49:77c8e4604045 242 # void PendSV_Handler (void);
mbed_official 49:77c8e4604045 243
mbed_official 49:77c8e4604045 244 .thumb_func
mbed_official 49:77c8e4604045 245 .type PendSV_Handler, %function
mbed_official 49:77c8e4604045 246 .global PendSV_Handler
mbed_official 49:77c8e4604045 247 .global Sys_Switch
mbed_official 49:77c8e4604045 248 PendSV_Handler:
mbed_official 49:77c8e4604045 249 .fnstart
mbed_official 49:77c8e4604045 250 .cantunwind
mbed_official 49:77c8e4604045 251
mbed_official 49:77c8e4604045 252 BL rt_pop_req
mbed_official 49:77c8e4604045 253
mbed_official 49:77c8e4604045 254 Sys_Switch:
mbed_official 49:77c8e4604045 255 LDR R3,=os_tsk
mbed_official 49:77c8e4604045 256 LDM R3,{R1,R2} /* os_tsk.run, os_tsk.new */
mbed_official 49:77c8e4604045 257 CMP R1,R2
mbed_official 49:77c8e4604045 258 BEQ Sys_Exit
mbed_official 49:77c8e4604045 259
mbed_official 49:77c8e4604045 260 MRS R12,PSP /* Read PSP */
mbed_official 49:77c8e4604045 261 STMDB R12!,{R4-R11} /* Save Old context */
mbed_official 49:77c8e4604045 262 STR R12,[R1,#TCB_TSTACK] /* Update os_tsk.run->tsk_stack */
mbed_official 49:77c8e4604045 263
mbed_official 49:77c8e4604045 264 PUSH {R2,R3}
mbed_official 49:77c8e4604045 265 BL rt_stk_check /* Check for Stack overflow */
mbed_official 49:77c8e4604045 266 POP {R2,R3}
mbed_official 49:77c8e4604045 267
mbed_official 49:77c8e4604045 268 STR R2,[R3] /* os_tsk.run = os_tsk.new */
mbed_official 49:77c8e4604045 269
mbed_official 49:77c8e4604045 270 LDR R12,[R2,#TCB_TSTACK] /* os_tsk.new->tsk_stack */
mbed_official 49:77c8e4604045 271 LDMIA R12!,{R4-R11} /* Restore New Context */
mbed_official 49:77c8e4604045 272 MSR PSP,R12 /* Write PSP */
mbed_official 49:77c8e4604045 273
mbed_official 49:77c8e4604045 274 Sys_Exit:
mbed_official 49:77c8e4604045 275 MVN LR,#~0xFFFFFFFD /* set EXC_RETURN value */
mbed_official 49:77c8e4604045 276 BX LR /* Return to Thread Mode */
mbed_official 49:77c8e4604045 277
mbed_official 49:77c8e4604045 278 .fnend
mbed_official 49:77c8e4604045 279 .size PendSV_Handler, .-PendSV_Handler
mbed_official 49:77c8e4604045 280
mbed_official 49:77c8e4604045 281
mbed_official 49:77c8e4604045 282 /*-------------------------- SysTick_Handler --------------------------------*/
mbed_official 49:77c8e4604045 283
mbed_official 49:77c8e4604045 284 # void SysTick_Handler (void);
mbed_official 49:77c8e4604045 285
mbed_official 49:77c8e4604045 286 .thumb_func
mbed_official 49:77c8e4604045 287 .type SysTick_Handler, %function
mbed_official 49:77c8e4604045 288 .global SysTick_Handler
mbed_official 49:77c8e4604045 289 SysTick_Handler:
mbed_official 49:77c8e4604045 290 .fnstart
mbed_official 49:77c8e4604045 291 .cantunwind
mbed_official 49:77c8e4604045 292
mbed_official 49:77c8e4604045 293 BL rt_systick
mbed_official 49:77c8e4604045 294 B Sys_Switch
mbed_official 49:77c8e4604045 295
mbed_official 49:77c8e4604045 296 .fnend
mbed_official 49:77c8e4604045 297 .size SysTick_Handler, .-SysTick_Handler
mbed_official 49:77c8e4604045 298
mbed_official 49:77c8e4604045 299
mbed_official 49:77c8e4604045 300 /*-------------------------- OS_Tick_Handler --------------------------------*/
mbed_official 49:77c8e4604045 301
mbed_official 49:77c8e4604045 302 # void OS_Tick_Handler (void);
mbed_official 49:77c8e4604045 303
mbed_official 49:77c8e4604045 304 .thumb_func
mbed_official 49:77c8e4604045 305 .type OS_Tick_Handler, %function
mbed_official 49:77c8e4604045 306 .global OS_Tick_Handler
mbed_official 49:77c8e4604045 307 OS_Tick_Handler:
mbed_official 49:77c8e4604045 308 .fnstart
mbed_official 49:77c8e4604045 309 .cantunwind
mbed_official 49:77c8e4604045 310
mbed_official 49:77c8e4604045 311 BL os_tick_irqack
mbed_official 49:77c8e4604045 312 BL rt_systick
mbed_official 49:77c8e4604045 313 B Sys_Switch
mbed_official 49:77c8e4604045 314
mbed_official 49:77c8e4604045 315 .fnend
mbed_official 49:77c8e4604045 316 .size OS_Tick_Handler, .-OS_Tick_Handler
mbed_official 49:77c8e4604045 317
mbed_official 49:77c8e4604045 318
mbed_official 49:77c8e4604045 319 .end
mbed_official 49:77c8e4604045 320
mbed_official 49:77c8e4604045 321 /*----------------------------------------------------------------------------
mbed_official 49:77c8e4604045 322 * end of file
mbed_official 49:77c8e4604045 323 *---------------------------------------------------------------------------*/