sighnd.inc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2000 by Michael Van Canneyt,
  4. member of the Free Pascal development team.
  5. Signal handler is arch dependant due to processor to language
  6. exception conversion.
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************}
  13. function GetHandleErrorAddrFrameAddr: pointer;
  14. begin
  15. result:=@HandleErrorAddrFrame;
  16. end;
  17. {$if not(defined(CPUTHUMB)) and not(defined(CPUTHUMB2))}
  18. Procedure SignalToHandleErrorAddrFrame_ARM(Errno : longint;addr : CodePointer; frame : Pointer); nostackframe; assembler;
  19. asm
  20. {$if FPC_FULLVERSION >= 30200}
  21. .code 32
  22. {$endif}
  23. // the address is of the faulting instruction, and sigreturn will
  24. // skip it -> start with a nop
  25. nop
  26. push {r0,r1,r2,r3}
  27. bl GetHandleErrorAddrFrameAddr
  28. // overwrite last stack slot with new return address
  29. str r0, [sp,#12]
  30. // lr := addr
  31. ldr lr, [sp,#4]
  32. pop {r0,r1,r2,pc}
  33. .text
  34. end;
  35. {$endif not(defined(CPUTHUMB)) and not(defined(CPUTHUMB2))}
  36. {$if FPC_FULLVERSION >= 30200}
  37. {$if defined(CPU_HAS_THUMB))}
  38. Procedure SignalToHandleErrorAddrFrame_Thumb(Errno : longint;addr : CodePointer; frame : Pointer); nostackframe; assembler;
  39. asm
  40. .thumb_func
  41. .code 16
  42. // the address is of the faulting instruction, and sigreturn will
  43. // skip it -> start with a nop
  44. nop
  45. push {r0,r1,r2,r3}
  46. bl GetHandleErrorAddrFrameAddr
  47. // overwrite last stack slot with new return address
  48. str r0, [sp,#12]
  49. // lr := addr
  50. ldr r0, [sp,#4]
  51. mov lr, r0
  52. pop {r0,r1,r2,pc}
  53. .text
  54. {$if not(defined(CPUTHUMB)) and not(defined(CPUTHUMB2))}
  55. .code 32
  56. {$endif not(defined(CPUTHUMB)) and not(defined(CPUTHUMB2))}
  57. end;
  58. {$endif defined(CPU_HAS_THUMB))}
  59. {$endif FPC_FULLVERSION >= 30200}
  60. procedure SignalToRunerror(Sig: longint; { _a2,_a3,_a4 : dword; } SigContext: PSigInfo; uContext : PuContext); public name '_FPC_DEFAULTSIGHANDLER'; cdecl;
  61. var
  62. res : word;
  63. begin
  64. res:=0;
  65. case sig of
  66. SIGFPE :
  67. begin
  68. { don't know how to find the different causes, maybe via xer? }
  69. res := 207;
  70. SysResetFPU;
  71. end;
  72. SIGILL:
  73. {$ifdef FPC_SYSTEM_FPC_MOVE}
  74. if in_edsp_test then
  75. begin
  76. res:=0;
  77. cpu_has_edsp:=false;
  78. inc(uContext^.uc_mcontext.arm_pc,4);
  79. end
  80. else
  81. {$endif FPC_SYSTEM_FPC_MOVE}
  82. res:=216;
  83. SIGSEGV :
  84. res:=216;
  85. SIGBUS:
  86. res:=214;
  87. SIGINT:
  88. res:=217;
  89. SIGQUIT:
  90. res:=233;
  91. end;
  92. { give runtime error at the position where the signal was raised }
  93. if res<>0 then
  94. begin
  95. ucontext^.uc_mcontext.arm_r0:=res;
  96. ucontext^.uc_mcontext.arm_r1:=uContext^.uc_mcontext.arm_pc;
  97. ucontext^.uc_mcontext.arm_r2:=uContext^.uc_mcontext.arm_fp;
  98. {$if FPC_FULLVERSION >= 30200}
  99. {$if not(defined(CPUTHUMB)) and not(defined(CPUTHUMB2))}
  100. if (ucontext^.uc_mcontext.arm_cpsr and (1 shl 5))=0 then
  101. begin
  102. ucontext^.uc_mcontext.arm_pc:=ptruint(@SignalToHandleErrorAddrFrame_ARM);
  103. end
  104. else
  105. {$endif not(defined(CPUTHUMB)) and not(defined(CPUTHUMB2))}
  106. begin
  107. {$if defined(CPU_HAS_THUMB))}
  108. ucontext^.uc_mcontext.arm_pc:=ptruint(@SignalToHandleErrorAddrFrame_Thumb);
  109. {$else defined(CPU_HAS_THUMB))}
  110. halt(217);
  111. {$endif defined(CPU_HAS_THUMB))}
  112. end;
  113. {$else}
  114. ucontext^.uc_mcontext.arm_pc:=ptruint(@SignalToHandleErrorAddrFrame_ARM);
  115. {$endif}
  116. end;
  117. end;