i8086.inc 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2013 by the Free Pascal development team.
  4. Processor dependent implementation for the system unit for
  5. intel i8086+
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. procedure fpc_cpuinit;
  13. begin
  14. end;
  15. {$define FPC_SYSTEM_HAS_SPTR}
  16. Function Sptr : Pointer;assembler;nostackframe;
  17. asm
  18. mov ax, sp
  19. end;
  20. {$define FPC_SYSTEM_HAS_PTR}
  21. function Ptr(sel,off: LongInt):farpointer;{$ifdef SYSTEMINLINE}inline;{$endif}assembler;nostackframe;
  22. asm
  23. push bp
  24. mov bp, sp
  25. mov ax, ss:[bp + 4 + extra_param_offset] // off
  26. mov dx, ss:[bp + 8 + extra_param_offset] // sel
  27. pop bp
  28. end;
  29. {$define FPC_SYSTEM_HAS_CSEG}
  30. function CSeg: Word;{$ifdef SYSTEMINLINE}inline;{$endif}assembler;nostackframe;
  31. asm
  32. mov ax, cs
  33. end;
  34. {$define FPC_SYSTEM_HAS_DSEG}
  35. function DSeg: Word;{$ifdef SYSTEMINLINE}inline;{$endif}assembler;nostackframe;
  36. asm
  37. mov ax, ds
  38. end;
  39. {$define FPC_SYSTEM_HAS_SSEG}
  40. function SSeg: Word;{$ifdef SYSTEMINLINE}inline;{$endif}assembler;nostackframe;
  41. asm
  42. mov ax, ss
  43. end;
  44. {$define FPC_SYSTEM_HAS_GET_CALLER_ADDR}
  45. function get_caller_addr(framebp:pointer;addr:pointer=nil):pointer;nostackframe;assembler;
  46. asm
  47. push bp
  48. mov bp, sp
  49. mov ax, ss:[bp + 6 + extra_param_offset] // framebp
  50. or ax, ax
  51. jz @@Lg_a_null
  52. xchg ax, bx
  53. mov bx, [bx+2]
  54. xchg ax, bx
  55. @@Lg_a_null:
  56. pop bp
  57. end;
  58. {$define FPC_SYSTEM_HAS_GET_CALLER_FRAME}
  59. function get_caller_frame(framebp:pointer;addr:pointer=nil):pointer;nostackframe;assembler;
  60. asm
  61. push bp
  62. mov bp, sp
  63. mov ax, ss:[bp + 6 + extra_param_offset] // framebp
  64. or ax, ax
  65. jz @@Lgnf_null
  66. xchg ax, bx
  67. mov bx, [bx]
  68. xchg ax, bx
  69. @@Lgnf_null:
  70. pop bp
  71. end;
  72. {TODO: fix, use smallint?}
  73. function InterLockedDecrement (var Target: longint) : longint; assembler;
  74. asm
  75. push bp
  76. mov bp, sp
  77. mov bx, ss:[bp + 4 + extra_param_offset] // Target
  78. sub word [bx], 1
  79. sbb word [bx+2], 0
  80. mov ax, [bx]
  81. mov dx, [bx+2]
  82. pop bp
  83. end;
  84. {TODO: fix, use smallint?}
  85. function InterLockedIncrement (var Target: longint) : longint; assembler;
  86. asm
  87. push bp
  88. mov bp, sp
  89. mov bx, ss:[bp + 4 + extra_param_offset] // Target
  90. add word [bx], 1
  91. adc word [bx+2], 0
  92. mov ax, [bx]
  93. mov dx, [bx+2]
  94. pop bp
  95. end;
  96. {TODO: fix, use smallint?}
  97. function InterLockedExchange (var Target: longint;Source : longint) : longint;
  98. begin
  99. InterLockedExchange := Target;
  100. Target := Source;
  101. end;
  102. {TODO: implement}
  103. function InterLockedExchangeAdd (var Target: longint;Source : longint) : longint;
  104. begin
  105. runerror(304);
  106. end;
  107. {TODO: implement}
  108. function InterlockedCompareExchange(var Target: longint; NewValue: longint; Comperand: longint): longint;
  109. begin
  110. runerror(304);
  111. end;
  112. {****************************************************************************
  113. FPU
  114. ****************************************************************************}
  115. const
  116. { Internal constants for use in system unit }
  117. FPU_Invalid = 1;
  118. FPU_Denormal = 2;
  119. FPU_DivisionByZero = 4;
  120. FPU_Overflow = 8;
  121. FPU_Underflow = $10;
  122. FPU_StackUnderflow = $20;
  123. FPU_StackOverflow = $40;
  124. FPU_ExceptionMask = $ff;
  125. { use Default8087CW instead
  126. fpucw : word = $1300 or FPU_StackUnderflow or FPU_Underflow or FPU_Denormal;
  127. }
  128. { returns true if FPU is present }
  129. function DetectFPU: boolean;
  130. var
  131. localfpucw: word;
  132. begin
  133. asm
  134. fninit
  135. mov byte [localfpucw + 1], 0
  136. fnstcw localfpucw
  137. end;
  138. DetectFPU:=(localfpucw and $FF00)=$0300;
  139. end;
  140. {$define FPC_SYSTEM_HAS_SYSINITFPU}
  141. Procedure SysInitFPU;
  142. var
  143. { these locals are so we don't have to hack pic code in the assembler }
  144. localmxcsr: dword;
  145. localfpucw: word;
  146. begin
  147. localfpucw:=Default8087CW;
  148. asm
  149. fninit
  150. fldcw localfpucw
  151. fwait
  152. end;
  153. softfloat_exception_mask:=float_flag_underflow or float_flag_inexact or float_flag_denormal;
  154. end;
  155. {$define FPC_SYSTEM_HAS_SYSRESETFPU}
  156. Procedure SysResetFPU;
  157. var
  158. { these locals are so we don't have to hack pic code in the assembler }
  159. localmxcsr: dword;
  160. localfpucw: word;
  161. begin
  162. localfpucw:=Default8087CW;
  163. asm
  164. fninit
  165. fwait
  166. fldcw localfpucw
  167. end;
  168. softfloat_exception_flags:=0;
  169. end;