m3dev

cortex m3 debug tools -- superceded by mdebug
git clone http://frotz.net/git/m3dev.git
Log | Files | Refs | README | LICENSE

context.S (1378B)


      1 /* context.S
      2  *
      3  * Copyright 2011 Brian Swetland <swetland@frotz.net>
      4  * 
      5  * Licensed under the Apache License, Version 2.0 (the "License");
      6  * you may not use this file except in compliance with the License.
      7  * You may obtain a copy of the License at
      8  *
      9  *     http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  * Unless required by applicable law or agreed to in writing, software
     12  * distributed under the License is distributed on an "AS IS" BASIS,
     13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  * See the License for the specific language governing permissions and
     15  * limitations under the License.
     16  */
     17 
     18 .syntax unified
     19 
     20 .global context_init
     21 .global handle_m3_svc
     22 .global handle_m3_pendsv
     23 
     24 /* context_init(void (*entry)(void), u32 new_psp, u32_new_msp); 
     25  * - setup stack pointers
     26  * - switch to PSP, remaining in Priv mode
     27  * - jump to entrypoint
     28  */
     29 context_init:
     30 	msr PSP, r1
     31 	msr MSP, r2
     32 	mrs r3, CONTROL
     33 	orr r3, r3, #2
     34 	msr CONTROL, r3
     35 	bx r0
     36 	b .
     37 
     38 handle_m3_pendsv:
     39 	/* obtain pointer to global state */
     40 	ldr r12, =(CONFIG_STACKTOP - 0x10)
     41 	/* safely make current_thread = next_thread */
     42 	cpsid i
     43 	ldr r1, [r12, #4]
     44 	ldr r0, [r12, #0]
     45 	str r1, [r12, #0]
     46 	cpsie i
     47 	/* save previous thread state */
     48 	mrs r2, psp
     49 	stmdb r2!, {r4-r11}
     50 	str r2, [r0, #0]
     51 	/* restore new thread state */
     52 	ldr r3, [r1, #0]
     53 	ldmia r3!, {r4-r11}
     54 	msr psp, r3
     55 	bx lr
     56