longjmp.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Copyright (C) 2002-2003, George Thanos <george.thanos@gdt.gr>
  3. * Yannis Mitsos <yannis.mitsos@gdt.gr>
  4. * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
  5. *
  6. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  7. */
  8. #include <syscall.h>
  9. #include <setjmp.h>
  10. #include <stdio.h>
  11. #include <signal.h>
  12. #define __NR_e1newSP 224
  13. static __inline__ _syscall1(int, e1newSP, unsigned long, SavedSP )
  14. unsigned long jmpbuf_ptr;
  15. void longjmp(jmp_buf state, int value )
  16. {
  17. if(!value)
  18. state->__jmpbuf->ReturnValue = 1;
  19. else
  20. state->__jmpbuf->ReturnValue = value;
  21. jmpbuf_ptr = (unsigned long)state;
  22. e1newSP(state->__jmpbuf->SavedSP);
  23. #define _state_ ((struct __jmp_buf_tag*)jmpbuf_ptr)
  24. __asm__ __volatile__("mov L0, %0\n\t"
  25. "mov L1, %1\n\t"
  26. "mov L2, %2\n\t"
  27. "mov G3, %3\n\t"
  28. "mov G4, %4\n\t"
  29. "ret PC, L1\n\t"
  30. :/*no output*/
  31. :"l"(_state_->__jmpbuf->ReturnValue),
  32. "l"(_state_->__jmpbuf->SavedPC),
  33. "l"(_state_->__jmpbuf->SavedSR),
  34. "l"(_state_->__jmpbuf->G3),
  35. "l"(_state_->__jmpbuf->G4)
  36. :"%G3", "%G4", "%L0", "%L1" );
  37. #undef _state_
  38. }
  39. void siglongjmp(sigjmp_buf state, int value )
  40. {
  41. if( state->__mask_was_saved )
  42. sigprocmask(SIG_SETMASK, &state->__saved_mask, NULL);
  43. if(!value)
  44. state->__jmpbuf->ReturnValue = 1;
  45. else
  46. state->__jmpbuf->ReturnValue = value;
  47. jmpbuf_ptr = (unsigned long)state;
  48. e1newSP(state->__jmpbuf->SavedSP);
  49. #define _state_ ((struct __jmp_buf_tag*)jmpbuf_ptr)
  50. __asm__ __volatile__("mov L0, %0\n\t"
  51. "mov L1, %1\n\t"
  52. "mov L2, %2\n\t"
  53. "mov G3, %3\n\t"
  54. "mov G4, %4\n\t"
  55. "ret PC, L1\n\t"
  56. :/*no output*/
  57. :"l"(_state_->__jmpbuf->ReturnValue),
  58. "l"(_state_->__jmpbuf->SavedPC),
  59. "l"(_state_->__jmpbuf->SavedSR),
  60. "l"(_state_->__jmpbuf->G3),
  61. "l"(_state_->__jmpbuf->G4)
  62. :"%G3", "%G4", "%L0", "%L1" );
  63. #undef _state_
  64. }