sysos.inc 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 2001 by Free Pascal development team
  5. This file implements all the base types and limits required
  6. for a minimal POSIX compliant subset required to port the compiler
  7. to a new OS.
  8. See the file COPYING.FPC, included in this distribution,
  9. for details about the copyright.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. **********************************************************************}
  14. const
  15. carryflag = 1;
  16. type
  17. tseginfo=packed record
  18. offset : pointer;
  19. segment : word;
  20. end;
  21. var
  22. old_int00 : tseginfo;cvar;
  23. old_int75 : tseginfo;cvar;
  24. {$asmmode ATT}
  25. {*****************************************************************************
  26. Go32 Helpers
  27. *****************************************************************************}
  28. function far_strlen(selector : word;linear_address : longint) : longint;assembler;
  29. asm
  30. movl linear_address,%edx
  31. movl %edx,%ecx
  32. movw selector,%gs
  33. .Larg19:
  34. movb %gs:(%edx),%al
  35. testb %al,%al
  36. je .Larg20
  37. incl %edx
  38. jmp .Larg19
  39. .Larg20:
  40. movl %edx,%eax
  41. subl %ecx,%eax
  42. end;
  43. function tb : longint;
  44. begin
  45. tb:=go32_info_block.linear_address_of_transfer_buffer;
  46. end;
  47. function tb_segment : longint;
  48. begin
  49. tb_segment:=go32_info_block.linear_address_of_transfer_buffer shr 4;
  50. end;
  51. function tb_offset : longint;
  52. begin
  53. tb_offset:=go32_info_block.linear_address_of_transfer_buffer and $f;
  54. end;
  55. function tb_size : longint;
  56. begin
  57. tb_size:=go32_info_block.size_of_transfer_buffer;
  58. end;
  59. function dos_selector : word;
  60. begin
  61. dos_selector:=go32_info_block.selector_for_linear_memory;
  62. end;
  63. function get_ds : word;assembler;
  64. asm
  65. movw %ds,%ax
  66. end;
  67. function get_cs : word;assembler;
  68. asm
  69. movw %cs,%ax
  70. end;
  71. procedure sysseg_move(sseg : word;source : longint;dseg : word;dest : longint;count : longint);
  72. begin
  73. if count=0 then
  74. exit;
  75. if (sseg<>dseg) or ((sseg=dseg) and (source>dest)) then
  76. asm
  77. pushl %esi
  78. pushl %edi
  79. pushw %es
  80. pushw %ds
  81. cld
  82. movl count,%ecx
  83. movl source,%esi
  84. movl dest,%edi
  85. movw dseg,%ax
  86. movw %ax,%es
  87. movw sseg,%ax
  88. movw %ax,%ds
  89. movl %ecx,%eax
  90. shrl $2,%ecx
  91. rep
  92. movsl
  93. movl %eax,%ecx
  94. andl $3,%ecx
  95. rep
  96. movsb
  97. popw %ds
  98. popw %es
  99. popl %edi
  100. popl %esi
  101. end
  102. else if (source<dest) then
  103. { copy backward for overlapping }
  104. asm
  105. pushl %esi
  106. pushl %edi
  107. pushw %es
  108. pushw %ds
  109. std
  110. movl count,%ecx
  111. movl source,%esi
  112. movl dest,%edi
  113. movw dseg,%ax
  114. movw %ax,%es
  115. movw sseg,%ax
  116. movw %ax,%ds
  117. addl %ecx,%esi
  118. addl %ecx,%edi
  119. movl %ecx,%eax
  120. andl $3,%ecx
  121. orl %ecx,%ecx
  122. jz .LSEG_MOVE1
  123. { calculate esi and edi}
  124. decl %esi
  125. decl %edi
  126. rep
  127. movsb
  128. incl %esi
  129. incl %edi
  130. .LSEG_MOVE1:
  131. subl $4,%esi
  132. subl $4,%edi
  133. movl %eax,%ecx
  134. shrl $2,%ecx
  135. rep
  136. movsl
  137. cld
  138. popw %ds
  139. popw %es
  140. popl %edi
  141. popl %esi
  142. end;
  143. end;
  144. function strcopy(dest,source : pchar) : pchar;assembler;
  145. var
  146. saveeax,saveesi,saveedi : longint;
  147. asm
  148. movl %edi,saveedi
  149. movl %esi,saveesi
  150. {$ifdef REGCALL}
  151. movl %eax,saveeax
  152. movl %edx,%edi
  153. {$else}
  154. movl source,%edi
  155. {$endif}
  156. testl %edi,%edi
  157. jz .LStrCopyDone
  158. leal 3(%edi),%ecx
  159. andl $-4,%ecx
  160. movl %edi,%esi
  161. subl %edi,%ecx
  162. {$ifdef REGCALL}
  163. movl %eax,%edi
  164. {$else}
  165. movl dest,%edi
  166. {$endif}
  167. jz .LStrCopyAligned
  168. .LStrCopyAlignLoop:
  169. movb (%esi),%al
  170. incl %edi
  171. incl %esi
  172. testb %al,%al
  173. movb %al,-1(%edi)
  174. jz .LStrCopyDone
  175. decl %ecx
  176. jnz .LStrCopyAlignLoop
  177. .balign 16
  178. .LStrCopyAligned:
  179. movl (%esi),%eax
  180. movl %eax,%edx
  181. leal 0x0fefefeff(%eax),%ecx
  182. notl %edx
  183. addl $4,%esi
  184. andl %edx,%ecx
  185. andl $0x080808080,%ecx
  186. jnz .LStrCopyEndFound
  187. movl %eax,(%edi)
  188. addl $4,%edi
  189. jmp .LStrCopyAligned
  190. .LStrCopyEndFound:
  191. testl $0x0ff,%eax
  192. jz .LStrCopyByte
  193. testl $0x0ff00,%eax
  194. jz .LStrCopyWord
  195. testl $0x0ff0000,%eax
  196. jz .LStrCopy3Bytes
  197. movl %eax,(%edi)
  198. jmp .LStrCopyDone
  199. .LStrCopy3Bytes:
  200. xorb %dl,%dl
  201. movw %ax,(%edi)
  202. movb %dl,2(%edi)
  203. jmp .LStrCopyDone
  204. .LStrCopyWord:
  205. movw %ax,(%edi)
  206. jmp .LStrCopyDone
  207. .LStrCopyByte:
  208. movb %al,(%edi)
  209. .LStrCopyDone:
  210. {$ifdef REGCALL}
  211. movl saveeax,%eax
  212. {$else}
  213. movl dest,%eax
  214. {$endif}
  215. movl saveedi,%edi
  216. movl saveesi,%esi
  217. end;
  218. procedure syscopytodos(addr : longint; len : longint);
  219. begin
  220. if len > tb_size then
  221. HandleError(217);
  222. sysseg_move(get_ds,addr,dos_selector,tb,len);
  223. end;
  224. procedure syscopyfromdos(addr : longint; len : longint);
  225. begin
  226. if len > tb_size then
  227. HandleError(217);
  228. sysseg_move(dos_selector,tb,get_ds,addr,len);
  229. end;
  230. procedure sysrealintr(intnr : word;var regs : trealregs);
  231. begin
  232. regs.realsp:=0;
  233. regs.realss:=0;
  234. asm
  235. pushl %ebx
  236. pushl %edi
  237. movw intnr,%bx
  238. xorl %ecx,%ecx
  239. movl regs,%edi
  240. movw $0x300,%ax
  241. int $0x31
  242. popl %edi
  243. popl %ebx
  244. end;
  245. end;
  246. procedure set_pm_interrupt(vector : byte;const intaddr : tseginfo);
  247. begin
  248. asm
  249. pushl %ebx
  250. movl intaddr,%eax
  251. movl (%eax),%edx
  252. movw 4(%eax),%cx
  253. movl $0x205,%eax
  254. movb vector,%bl
  255. int $0x31
  256. popl %ebx
  257. end;
  258. end;
  259. procedure get_pm_interrupt(vector : byte;var intaddr : tseginfo);
  260. begin
  261. asm
  262. pushl %ebx
  263. movb vector,%bl
  264. movl $0x204,%eax
  265. int $0x31
  266. movl intaddr,%eax
  267. movl %edx,(%eax)
  268. movw %cx,4(%eax)
  269. popl %ebx
  270. end;
  271. end;
  272. procedure getinoutres(def : word);
  273. var
  274. regs : trealregs;
  275. begin
  276. regs.realeax:=$5900;
  277. regs.realebx:=$0;
  278. sysrealintr($21,regs);
  279. InOutRes:=lo(regs.realeax);
  280. case InOutRes of
  281. 19 : InOutRes:=150;
  282. 21 : InOutRes:=152;
  283. 32 : InOutRes:=5;
  284. end;
  285. if InOutRes=0 then
  286. InOutRes:=Def;
  287. end;
  288. {
  289. $Log$
  290. Revision 1.1 2005-02-06 16:57:18 peter
  291. * threads for go32v2,os,emx,netware
  292. Revision 1.1 2005/02/06 13:06:20 peter
  293. * moved file and dir functions to sysfile/sysdir
  294. * win32 thread in systemunit
  295. }