[444] | 1 | /* |
---|
| 2 | * Copyright (c) 2011 Aeroflex Gaisler |
---|
| 3 | * |
---|
| 4 | * BSD license: |
---|
| 5 | * |
---|
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
---|
| 7 | * of this software and associated documentation files (the "Software"), to deal |
---|
| 8 | * in the Software without restriction, including without limitation the rights |
---|
| 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
---|
| 10 | * copies of the Software, and to permit persons to whom the Software is |
---|
| 11 | * furnished to do so, subject to the following conditions: |
---|
| 12 | * |
---|
| 13 | * The above copyright notice and this permission notice shall be included in |
---|
| 14 | * all copies or substantial portions of the Software. |
---|
| 15 | * |
---|
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
---|
| 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
---|
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
---|
| 22 | * THE SOFTWARE. |
---|
| 23 | */ |
---|
| 24 | |
---|
| 25 | |
---|
| 26 | #include <asm-leon/elfmacro.h> |
---|
| 27 | #include <asm-leon/leon.h> |
---|
| 28 | #include <asm-leon/leonstack.h> |
---|
| 29 | #include <asm-leon/contextswitch.h> |
---|
| 30 | #include <asm-leon/winmacros.h> |
---|
| 31 | #include <asm-leon/leonbare_kernel.h> |
---|
| 32 | |
---|
| 33 | FUNC_EXPORT(_leonbare_kernel_switchto) |
---|
| 34 | FUNC_EXPORT(_leonbare_Stop) |
---|
| 35 | |
---|
| 36 | FUNC_IMPORT(leonbare_disable_traps) |
---|
| 37 | |
---|
| 38 | .text |
---|
| 39 | |
---|
| 40 | /* unsigned int _leonbare_kernel_switchto(struct leonbare_thread_ctx *thread,struct leonbare_thread_ctx *thread) */ |
---|
| 41 | FUNC_BEGIN(_leonbare_kernel_switchto) |
---|
| 42 | |
---|
| 43 | /* =================================*/ |
---|
| 44 | /* save context */ |
---|
| 45 | /* =================================*/ |
---|
| 46 | |
---|
| 47 | mov %o0, %g1 |
---|
| 48 | mov %o1, %g2 |
---|
| 49 | mov %o7, %g3 |
---|
| 50 | rd %psr, %g4 /* psr.cwp should stay same because irq path rely on it. */ |
---|
| 51 | |
---|
| 52 | call leonbare_disable_traps /* psr in %o0, modify %o0, %o1, %o7 */ |
---|
| 53 | nop |
---|
| 54 | |
---|
| 55 | set TACODE_IRQCALL_FLUSH,%o1 |
---|
| 56 | ta TACODE_IRQCALL |
---|
| 57 | |
---|
| 58 | st %g4, [%g1 + LEONBARE_THREAD_CTX_STACK_PSR] /* psr */ |
---|
| 59 | set LEONBARE_THREAD_CTX_MAGIC,%g4 |
---|
| 60 | st %g4, [%g1 + LEONBARE_THREAD_CTX_STACK_MAGIC] |
---|
| 61 | |
---|
| 62 | mov %g3, %o7 ! restore %o7 |
---|
| 63 | |
---|
| 64 | LEONBARE_THREAD_CTX_STORE_INS(g1) |
---|
| 65 | LEONBARE_THREAD_CTX_STORE_LOCALS(g1) |
---|
| 66 | LEONBARE_THREAD_CTX_STORE_OUTS(g1) |
---|
| 67 | |
---|
| 68 | /* =================================*/ |
---|
| 69 | /* restore context */ |
---|
| 70 | /* =================================*/ |
---|
| 71 | |
---|
| 72 | /* check valid context stack area */ |
---|
| 73 | ld [%g2 + LEONBARE_THREAD_CTX_STACK_MAGIC], %o1 |
---|
| 74 | set LEONBARE_THREAD_CTX_MAGIC,%o2 |
---|
| 75 | cmp %o1, %o2 |
---|
| 76 | beq 1f |
---|
| 77 | nop |
---|
| 78 | |
---|
| 79 | /* stop all */ |
---|
| 80 | ta 0x0 |
---|
| 81 | |
---|
| 82 | 1: |
---|
| 83 | /* get psr */ |
---|
| 84 | ld [%g2 + LEONBARE_THREAD_CTX_STACK_PSR],%g1 /* psr.cwp should stay same because irq path rely on it. */ |
---|
| 85 | set SPARC_PSR_EF_MASK,%g3 ! clear ef bit |
---|
| 86 | andn %g1, %g3, %g1 |
---|
| 87 | |
---|
| 88 | wr %g0,%wim |
---|
| 89 | nop; nop; nop; |
---|
| 90 | |
---|
| 91 | andn %g1, SPARC_PSR_ET_MASK, %g3 ! disable traps, up to PSR_EF imm andn ok |
---|
| 92 | wr %g3, %psr |
---|
| 93 | nop; nop; nop; |
---|
| 94 | |
---|
| 95 | LEONBARE_THREAD_CTX_LOAD_INS(g2) |
---|
| 96 | LEONBARE_THREAD_CTX_LOAD_LOCALS(g2) |
---|
| 97 | LEONBARE_THREAD_CTX_LOAD_OUTS(g2) |
---|
| 98 | |
---|
| 99 | SET_WIM_CWPMIN1(g1,o1,o2,o3,o4) ! calc wim from psr_cwp so that next restore traps |
---|
| 100 | |
---|
| 101 | wr %g1,%psr |
---|
| 102 | nop; nop; nop; |
---|
| 103 | |
---|
| 104 | retl |
---|
| 105 | nop |
---|
| 106 | |
---|
| 107 | FUNC_END(_leonbare_kernel_switchto) |
---|
| 108 | |
---|
| 109 | |
---|
| 110 | FUNC_BEGIN(_leonbare_Stop) |
---|
| 111 | ta 0x0 |
---|
| 112 | FUNC_END(_leonbare_Stop) |
---|