1/* 2 Copyright (c) 2001-2006 by Tensilica Inc. 3 4 Permission is hereby granted, free of charge, to any person obtaining 5 a copy of this software and associated documentation files (the 6 "Software"), to deal in the Software without restriction, including 7 without limitation the rights to use, copy, modify, merge, publish, 8 distribute, sublicense, and/or sell copies of the Software, and to 9 permit persons to whom the Software is furnished to do so, subject to 10 the following conditions: 11 12 The above copyright notice and this permission notice shall be included 13 in all copies or substantial portions of the Software. 14 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22*/ 23 24/* 25 This file contains a modified version of the original Xtensa longjmp implementation. 26 In this modified version, setting WINDOWSTART = 1 << WINDOWBASE is done inside a critical section. 27 This is necessary because after a FreeRTOS context switch in IDF, the values of WINDOWBASE and WINDOWSTART 28 are not guaranteed to be the same as before the context switch. 29*/ 30 31#include <xtensa/corebits.h> 32 33/* 34 Replacement of the first instructions of void longjmp (jmp_buf env, int val) 35*/ 36 37 .align 4 38 .literal_position 39 .global __wrap_longjmp 40 .type __wrap_longjmp, @function 41__wrap_longjmp: 42 entry sp, 16 43 44 /* Deactivate interrupts in order to modify WINDOWBASE and WINDOWSTART. */ 45 rsr a7, PS /* to be restored after SPILL_ALL_WINDOWS */ 46 movi a5, PS_EXCM /* PS_INTLEVEL_MASK */ 47 or a5, a7, a5 /* get the current INTLEVEL */ 48 wsr a5, PS 49 50 /* Invalidate all but the current window; 51 set WindowStart to (1 << WindowBase). */ 52 rsr a5, WINDOWBASE 53 movi a4, 1 54 ssl a5 55 sll a4, a4 56 wsr a4, WINDOWSTART 57 rsync 58 59 /* Activate interrupts again after modifying WINDOWBASE and WINDOWSTART. */ 60 wsr a7, PS 61 62 /* Jump back to original longjmp implementation. 63 The jump target is the instrucion 64 l32i a0, a2, 64 65 of the original code. Hence, the original code's entry instruction and windowstart modification are left 66 out. 67 */ 68 movi a0, __real_longjmp + 20 69 jx a0 70 71 .size __wrap_longjmp, . - __wrap_longjmp 72