Mercurial > ecos
comparison packages/hal/cortexm/arch/current/src/context.S @ 2580:07fc475e1c28
Add Cortex-M architecture HAL, STM32 variant and STM3210E platform HALs.
Add STM32 serial driver and on-chip flash driver.
Fix some compile problems with dlmalloc.
See the various ChangeLogs for details.
| author | nickg |
|---|---|
| date | Mon, 03 Nov 2008 14:53:50 +0000 |
| parents | |
| children | 74dbf4c3f2e1 |
comparison
equal
deleted
inserted
replaced
| 2579:23e894d966a8 | 2580:07fc475e1c28 |
|---|---|
| 1 /*========================================================================== | |
| 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 eCosCentric Limited. | |
| 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 version. | |
| 16 // | |
| 17 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY | |
| 18 // WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 19 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 20 // for more details. | |
| 21 // | |
| 22 // You should have received a copy of the GNU General Public License along | |
| 23 // with eCos; if not, write to the Free Software Foundation, Inc., | |
| 24 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. | |
| 25 // | |
| 26 // As a special exception, if other files instantiate templates or use macros | |
| 27 // or inline functions from this file, or you compile this file and link it | |
| 28 // with other works to produce a work based on this file, this file does not | |
| 29 // by itself cause the resulting work to be covered by the GNU General Public | |
| 30 // License. However the source code for this file must still be made available | |
| 31 // in accordance with section (3) of the GNU General Public License. | |
| 32 // | |
| 33 // This exception does not invalidate any other reasons why a work based on | |
| 34 // this file might be covered by the GNU General Public License. | |
| 35 // ------------------------------------------- | |
| 36 //####ECOSGPLCOPYRIGHTEND#### | |
| 37 //========================================================================== | |
| 38 //#####DESCRIPTIONBEGIN#### | |
| 39 // | |
| 40 // Author(s): nickg | |
| 41 // Date: 2008-07-30 | |
| 42 // Description: This file contains thread context switch code. | |
| 43 // | |
| 44 //####DESCRIPTIONEND#### | |
| 45 // | |
| 46 //========================================================================*/ | |
| 47 | |
| 48 #include <pkgconf/system.h> | |
| 49 #include <pkgconf/hal.h> | |
| 50 #include <pkgconf/hal_cortexm.h> | |
| 51 #ifdef CYGPKG_KERNEL | |
| 52 #include <pkgconf/kernel.h> | |
| 53 #endif | |
| 54 | |
| 55 //========================================================================== | |
| 56 | |
| 57 .syntax unified | |
| 58 .thumb | |
| 59 .text | |
| 60 | |
| 61 //========================================================================== | |
| 62 // Context switch | |
| 63 // | |
| 64 // R0 contains a pointer to the SP of the thread to load, R1 contains | |
| 65 // a pointer to the SP of the current thread. | |
| 66 | |
| 67 .globl hal_thread_switch_context | |
| 68 .thumb | |
| 69 .thumb_func | |
| 70 .type hal_thread_switch_context, %function | |
| 71 hal_thread_switch_context: | |
| 72 | |
| 73 push {r0-r12,lr} // Push all savable register | |
| 74 mov r2,#2 // Set state type == thread | |
| 75 mrs r3,basepri // Get priority base register | |
| 76 mov r4,sp // Get SP (for info only) | |
| 77 push {r2-r4} // Push them | |
| 78 | |
| 79 str sp,[r1] // Save SP | |
| 80 | |
| 81 // Fall through | |
| 82 | |
| 83 //-------------------------------------------------------------------------- | |
| 84 // Load context | |
| 85 // | |
| 86 // This is used to load a thread context, abandoning the current one. This | |
| 87 // function is also the second half of hal_thread_switch_context. | |
| 88 | |
| 89 .globl hal_thread_load_context | |
| 90 .thumb | |
| 91 .thumb_func | |
| 92 .type hal_thread_load_context, %function | |
| 93 hal_thread_load_context: | |
| 94 | |
| 95 ldr sp,[r0] // Load SP | |
| 96 pop {r2-r4} // Pop type, basepri and SP (discarded) | |
| 97 msr basepri,r3 // Set BASEPRI | |
| 98 pop {r0-r12,pc} // Pop all register and return | |
| 99 | |
| 100 //========================================================================== | |
| 101 // HAL longjmp, setjmp implementations | |
| 102 // | |
| 103 // hal_setjmp saves only to callee save registers R4-14 | |
| 104 // and LR into buffer supplied in r0[arg0]. | |
| 105 | |
| 106 .globl hal_setjmp | |
| 107 .thumb | |
| 108 .thumb_func | |
| 109 .type hal_setjmp, %function | |
| 110 hal_setjmp: | |
| 111 mov r3,sp | |
| 112 stmea r0,{r3-r12,r14} | |
| 113 mov r0,#0 | |
| 114 bx lr | |
| 115 | |
| 116 // hal_longjmp loads state from r0[arg0] and returns | |
| 117 | |
| 118 .globl hal_longjmp | |
| 119 .thumb | |
| 120 .thumb_func | |
| 121 .type hal_longjmp, %function | |
| 122 hal_longjmp: | |
| 123 ldmfd r0,{r3-r12,r14} | |
| 124 mov sp,r3 | |
| 125 mov r0,r1 // return [arg1] | |
| 126 bx lr | |
| 127 | |
| 128 //========================================================================== | |
| 129 // EOF context.S |
