longjmp.c 1.8 KB

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