1/* libunwind - a platform-independent unwind library 2 Copyright (C) 2021 Zhaofeng Li 3 4This file is part of libunwind. 5 6Permission is hereby granted, free of charge, to any person obtaining 7a copy of this software and associated documentation files (the 8"Software"), to deal in the Software without restriction, including 9without limitation the rights to use, copy, modify, merge, publish, 10distribute, sublicense, and/or sell copies of the Software, and to 11permit persons to whom the Software is furnished to do so, subject to 12the following conditions: 13 14The above copyright notice and this permission notice shall be 15included in all copies or substantial portions of the Software. 16 17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 24 25#include "offsets.h" 26#include "asm.h" 27 28#define REG(X) (UC_MCONTEXT_REGS_OFF + SZREG * X)(a0) 29#define FREG(X) (UC_MCONTEXT_REGS_OFF + SZREG * 32 + SZFREG * X)(a0) 30 31 .text 32 .global _Uriscv_getcontext 33 .type _Uriscv_getcontext, @function 34_Uriscv_getcontext: 35 .cfi_startproc 36 37 STORE ra, REG(0) 38 STORE ra, REG(1) 39 STORE sp, REG(2) 40 STORE s0, REG(8) 41 STORE s1, REG(9) 42 STORE x0, REG(10) /* Write 0 to a0 */ 43 STORE a1, REG(11) 44 STORE a2, REG(12) 45 STORE a3, REG(13) 46 STORE a4, REG(14) 47 STORE a5, REG(15) 48 STORE a6, REG(16) 49 STORE a7, REG(17) 50 STORE s2, REG(18) 51 STORE s3, REG(19) 52 STORE s4, REG(20) 53 STORE s5, REG(21) 54 STORE s6, REG(22) 55 STORE s7, REG(23) 56 STORE s8, REG(24) 57 STORE s9, REG(25) 58 STORE s10, REG(26) 59 STORE s11, REG(27) 60 61#ifdef STORE_FP 62 /* The FCSR is always 32-bits and comes after all registers */ 63 frcsr a1 64 sw a1, FREG(32) 65 66 STORE_FP fs0, FREG(8) 67 STORE_FP fs1, FREG(9) 68 STORE_FP fs2, FREG(18) 69 STORE_FP fs3, FREG(19) 70 STORE_FP fs4, FREG(20) 71 STORE_FP fs5, FREG(21) 72 STORE_FP fs6, FREG(22) 73 STORE_FP fs7, FREG(23) 74 STORE_FP fs8, FREG(24) 75 STORE_FP fs9, FREG(25) 76 STORE_FP fs10, FREG(26) 77 STORE_FP fs11, FREG(27) 78#endif 79 80 li a0, 0 81 ret 82 83 .cfi_endproc 84 .size _Uriscv_getcontext, . - _Uriscv_getcontext 85 86 /* We do not need executable stack. */ 87 .section .note.GNU-stack,"",@progbits 88