| 1 |
786 |
skrzyp |
/*==========================================================================
|
| 2 |
|
|
//
|
| 3 |
|
|
// context.S
|
| 4 |
|
|
//
|
| 5 |
|
|
// Cortex-M context switch code
|
| 6 |
|
|
//
|
| 7 |
|
|
//==========================================================================
|
| 8 |
|
|
// ####ECOSGPLCOPYRIGHTBEGIN####
|
| 9 |
|
|
// -------------------------------------------
|
| 10 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
| 11 |
|
|
// Copyright (C) 2008 Free Software Foundation, Inc.
|
| 12 |
|
|
//
|
| 13 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
| 14 |
|
|
// the terms of the GNU General Public License as published by the Free
|
| 15 |
|
|
// Software Foundation; either version 2 or (at your option) any later
|
| 16 |
|
|
// version.
|
| 17 |
|
|
//
|
| 18 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT
|
| 19 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
| 20 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
| 21 |
|
|
// for more details.
|
| 22 |
|
|
//
|
| 23 |
|
|
// You should have received a copy of the GNU General Public License
|
| 24 |
|
|
// along with eCos; if not, write to the Free Software Foundation, Inc.,
|
| 25 |
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
| 26 |
|
|
//
|
| 27 |
|
|
// As a special exception, if other files instantiate templates or use
|
| 28 |
|
|
// macros or inline functions from this file, or you compile this file
|
| 29 |
|
|
// and link it with other works to produce a work based on this file,
|
| 30 |
|
|
// this file does not by itself cause the resulting work to be covered by
|
| 31 |
|
|
// the GNU General Public License. However the source code for this file
|
| 32 |
|
|
// must still be made available in accordance with section (3) of the GNU
|
| 33 |
|
|
// General Public License v2.
|
| 34 |
|
|
//
|
| 35 |
|
|
// This exception does not invalidate any other reasons why a work based
|
| 36 |
|
|
// on this file might be covered by the GNU General Public License.
|
| 37 |
|
|
// -------------------------------------------
|
| 38 |
|
|
// ####ECOSGPLCOPYRIGHTEND####
|
| 39 |
|
|
//==========================================================================
|
| 40 |
|
|
//#####DESCRIPTIONBEGIN####
|
| 41 |
|
|
//
|
| 42 |
|
|
// Author(s): nickg
|
| 43 |
|
|
// Date: 2008-07-30
|
| 44 |
|
|
// Description: This file contains thread context switch code.
|
| 45 |
|
|
//
|
| 46 |
|
|
//####DESCRIPTIONEND####
|
| 47 |
|
|
//
|
| 48 |
|
|
//========================================================================*/
|
| 49 |
|
|
|
| 50 |
|
|
#include
|
| 51 |
|
|
#include
|
| 52 |
|
|
#include
|
| 53 |
|
|
#ifdef CYGPKG_KERNEL
|
| 54 |
|
|
#include
|
| 55 |
|
|
#endif
|
| 56 |
|
|
|
| 57 |
|
|
//==========================================================================
|
| 58 |
|
|
|
| 59 |
|
|
.syntax unified
|
| 60 |
|
|
.thumb
|
| 61 |
|
|
.text
|
| 62 |
|
|
|
| 63 |
|
|
//==========================================================================
|
| 64 |
|
|
// Context switch
|
| 65 |
|
|
//
|
| 66 |
|
|
// R0 contains a pointer to the SP of the thread to load, R1 contains
|
| 67 |
|
|
// a pointer to the SP of the current thread.
|
| 68 |
|
|
|
| 69 |
|
|
.globl hal_thread_switch_context
|
| 70 |
|
|
.thumb
|
| 71 |
|
|
.thumb_func
|
| 72 |
|
|
.type hal_thread_switch_context, %function
|
| 73 |
|
|
hal_thread_switch_context:
|
| 74 |
|
|
|
| 75 |
|
|
push {r0-r12,lr} // Push all savable register
|
| 76 |
|
|
mov r2,#2 // Set state type == thread
|
| 77 |
|
|
mrs r3,basepri // Get priority base register
|
| 78 |
|
|
mov r4,sp // Get SP (for info only)
|
| 79 |
|
|
push {r2-r4} // Push them
|
| 80 |
|
|
|
| 81 |
|
|
str sp,[r1] // Save SP
|
| 82 |
|
|
|
| 83 |
|
|
// Fall through
|
| 84 |
|
|
|
| 85 |
|
|
//--------------------------------------------------------------------------
|
| 86 |
|
|
// Load context
|
| 87 |
|
|
//
|
| 88 |
|
|
// This is used to load a thread context, abandoning the current one. This
|
| 89 |
|
|
// function is also the second half of hal_thread_switch_context.
|
| 90 |
|
|
|
| 91 |
|
|
.globl hal_thread_load_context
|
| 92 |
|
|
.thumb
|
| 93 |
|
|
.thumb_func
|
| 94 |
|
|
.type hal_thread_load_context, %function
|
| 95 |
|
|
hal_thread_load_context:
|
| 96 |
|
|
|
| 97 |
|
|
ldr sp,[r0] // Load SP
|
| 98 |
|
|
pop {r2-r4} // Pop type, basepri and SP (discarded)
|
| 99 |
|
|
msr basepri,r3 // Set BASEPRI
|
| 100 |
|
|
pop {r0-r12,pc} // Pop all register and return
|
| 101 |
|
|
|
| 102 |
|
|
//==========================================================================
|
| 103 |
|
|
// HAL longjmp, setjmp implementations
|
| 104 |
|
|
//
|
| 105 |
|
|
// hal_setjmp saves only to callee save registers R4-14
|
| 106 |
|
|
// and LR into buffer supplied in r0[arg0].
|
| 107 |
|
|
|
| 108 |
|
|
.globl hal_setjmp
|
| 109 |
|
|
.thumb
|
| 110 |
|
|
.thumb_func
|
| 111 |
|
|
.type hal_setjmp, %function
|
| 112 |
|
|
hal_setjmp:
|
| 113 |
|
|
mov r3,sp
|
| 114 |
|
|
stmea r0,{r3-r12,r14}
|
| 115 |
|
|
mov r0,#0
|
| 116 |
|
|
bx lr
|
| 117 |
|
|
|
| 118 |
|
|
// hal_longjmp loads state from r0[arg0] and returns
|
| 119 |
|
|
|
| 120 |
|
|
.globl hal_longjmp
|
| 121 |
|
|
.thumb
|
| 122 |
|
|
.thumb_func
|
| 123 |
|
|
.type hal_longjmp, %function
|
| 124 |
|
|
hal_longjmp:
|
| 125 |
|
|
ldmfd r0,{r3-r12,r14}
|
| 126 |
|
|
mov sp,r3
|
| 127 |
|
|
mov r0,r1 // return [arg1]
|
| 128 |
|
|
bx lr
|
| 129 |
|
|
|
| 130 |
|
|
//==========================================================================
|
| 131 |
|
|
// EOF context.S
|