target_arch_sigtramp.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. * RISC-V sigcode
  3. *
  4. * Copyright (c) 2019 Mark Corbin
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef TARGET_ARCH_SIGTRAMP_H
  20. #define TARGET_ARCH_SIGTRAMP_H
  21. /* Compare with sigcode() in riscv/riscv/locore.S */
  22. static inline abi_long setup_sigtramp(abi_ulong offset, unsigned sigf_uc,
  23. unsigned sys_sigreturn)
  24. {
  25. uint32_t sys_exit = TARGET_FREEBSD_NR_exit;
  26. uint32_t sigtramp_code[] = {
  27. /*1*/ const_le32(0x00010513), /*mv a0, sp*/
  28. /*2*/ const_le32(0x00050513 + (sigf_uc << 20)), /*addi a0,a0,sigf_uc*/
  29. /*3*/ const_le32(0x00000293 + (sys_sigreturn << 20)),/*li t0,sys_sigreturn*/
  30. /*4*/ const_le32(0x00000073), /*ecall*/
  31. /*5*/ const_le32(0x00000293 + (sys_exit << 20)), /*li t0,sys_exit*/
  32. /*6*/ const_le32(0x00000073), /*ecall*/
  33. /*7*/ const_le32(0xFF1FF06F) /*b -16*/
  34. };
  35. return memcpy_to_target(offset, sigtramp_code, TARGET_SZSIGCODE);
  36. }
  37. #endif /* TARGET_ARCH_SIGTRAMP_H */