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/leon.h> 27#include <asm-leon/leonstack.h> 28#include <asm-leon/contextswitch.h> 29#include <asm-leon/winmacros.h> 30 31/* This asm code relies on the following offsets (setjmp.h): 32#define THREAD_JB_SP 0 33#define THREAD_JB_PC 1 34#define THREAD_JB_PSR 8 35#define THREAD_JB_WIM 9 */ 36 37 /* Number of register windows */ 38 .global _nwindows_min1, _nwindows 39 40 .text 41 .global _switch_to 42_switch_to: 43 44#ifndef _FLAT 45 !mov %o0,%i0 /* propagate env on restore */ 46 !mov %o1,%i1 /* propagate val on restore */ 47 !restore 48 mov %o0,%g7 49 mov %o1,%g3 /* former %%i1 (val) */ 50 51 sethi %hi(_nwindows_min1), %g4 /* flush registers */ 52 ld [%g4+%lo(_nwindows_min1)], %g4 531: save %sp, -SF_REGS_SZ, %sp !NWINDOWS-1 times 54 sub %g4,1,%g4 55 cmp %g0,%g4 56 bne 1b 57 nop 58#else 59 mov %o0,%g7 60 mov %o1,%g3 /* former %%i1 (val) */ 61 RW_STORE(sp) 62#endif 63 64 ldd [%g7+THREAD_JB_PSR*4], %g4 /* load psr,wim */ 65 wr %g4, 0x20, %psr 66 nop 67 nop 68 nop 69 ldd [%g7 +THREAD_JB_SP*4], %sp /* load sp, pc to jump to */ 70 wr %g5, 0x0, %wim 71 72 RW_LOAD(sp) /* restore window */ 73 wr %g4, 0x00, %psr 74 nop 75 nop 76 nop 77 78 jmp %o7 + 8 /* success */ 79 mov %g3, %o0 /* return %%g3 */ 80 81 82 83 .text 84 .global thread_setjmp, _do_thread_setjmp 85thread_setjmp: 86 87#ifdef _FLAT 88 RW_STORE(sp) /* store window */ 89#endif 90 91! RW_STORE(sp) /* store window for _FLAT and normal, SWITCH_TO_STACK in pthread need this*/ 92 93 mov %psr,%o2 94#ifndef _SOFT_FLOAT 95 set 0x1000,%o3 96 andn %o2,%o3,%o2 !disable fpu 97#endif 98 std %sp,[%o0] !THREAD_JB_SP 99 st %o2,[%o0+(8*4)] !THREAD_JB_PSR 100 ba _do_thread_setjmp 101 nop 102