setjmp.e 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #
  2. mes 2,EM_WSIZE,EM_PSIZE
  3. ;
  4. ; layout of a setjmp buffer:
  5. ;
  6. ; -----------------
  7. ; | signal mask | (only for Berkeley 4.[2-])
  8. ; -----------------
  9. ; | |
  10. ; | GTO descriptor |
  11. ; | (SP, LB, PC) |
  12. ; | |
  13. ; -----------------
  14. ;
  15. ; setjmp saves the signalmask, PC, SP, and LB of caller, and creates a
  16. ; GTO descriptor from this.
  17. ; The big problem here is how to get the return address, i.e. the PC of
  18. ; the caller; This problem is solved by the front-end, which must pass
  19. ; it as an extra parameter to setjmp.
  20. ; a GTO descriptor must be in the global data area
  21. gtobuf
  22. bss 3*EM_PSIZE,0,0
  23. inp $fill_ret_area
  24. exp $setjmp
  25. pro $setjmp,0
  26. #ifdef __BSD4_2
  27. ; save mask of currently blocked signals.
  28. ; longjmp must restore this mask
  29. loc 0
  30. cal $sigblock
  31. asp EM_WSIZE
  32. lfr EM_WSIZE
  33. lal 0
  34. loi EM_PSIZE
  35. stf 3*EM_PSIZE
  36. #endif
  37. ; create GTO descriptor for longjmp
  38. lxl 0
  39. dch ; Local Base of caller
  40. lxa 0 ; Stackpointer of caller
  41. lal EM_PSIZE
  42. loi EM_PSIZE ; Return address of caller
  43. lal 0
  44. loi EM_PSIZE ; address of jmpbuf
  45. sti 3*EM_PSIZE ; LB, SP, and PC stored in jmpbuf
  46. loc 0
  47. ret EM_WSIZE ; setjmp must return 0
  48. end 0
  49. pro $fill_ret_area,0
  50. ; put argument in function result area
  51. lol 0
  52. ret EM_WSIZE
  53. end 0
  54. exp $longjmp
  55. pro $longjmp,?
  56. #ifdef __BSD4_2
  57. ; restore signal mask
  58. lal 0
  59. loi EM_PSIZE
  60. lof 3*EM_PSIZE
  61. cal $sigsetmask
  62. asp EM_WSIZE
  63. lfr EM_WSIZE
  64. asp EM_WSIZE
  65. #endif
  66. lal 0
  67. loi EM_PSIZE ; address of jmpbuf
  68. lae gtobuf
  69. blm 3*EM_PSIZE ; fill GTO descriptor from jmpbuf
  70. lol EM_PSIZE ; second parameter of longjmp: the return value
  71. dup EM_WSIZE
  72. zne *3
  73. ; of course, longjmp may not return 0!
  74. asp EM_WSIZE
  75. loc 1
  76. 3
  77. ; put return value in function result area
  78. cal $fill_ret_area
  79. asp EM_WSIZE
  80. gto gtobuf ; there we go ...
  81. ; ASP and GTO do not damage function result area
  82. end 0