2
0

sysos.inc 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2001 by Free Pascal development team
  4. This file implements all the base types and limits required
  5. for a minimal POSIX compliant subset required to port the compiler
  6. to a new OS.
  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. {*****************************************************************************
  14. AmigaOS structures
  15. *****************************************************************************}
  16. {$include execd.inc}
  17. {$include timerd.inc}
  18. {$include doslibd.inc}
  19. {*****************************************************************************
  20. AmigaOS functions
  21. *****************************************************************************}
  22. {$include execf.inc}
  23. {$include doslibf.inc}
  24. {*****************************************************************************
  25. CPU specific
  26. *****************************************************************************}
  27. {$ifdef cpum68k}
  28. {$include m68kamiga.inc}
  29. {$endif}
  30. {*****************************************************************************
  31. System Dependent Structures/Consts
  32. *****************************************************************************}
  33. {$ifndef FPC_SYSTEM_HAS_STACKTOP}
  34. {$define FPC_SYSTEM_HAS_STACKTOP}
  35. function StackTop: pointer;
  36. begin
  37. StackTop:=FindTask(nil)^.tc_SPUpper;
  38. end;
  39. {$endif FPC_SYSTEM_HAS_STACKTOP}
  40. const
  41. CTRL_C = 20; { Error code on CTRL-C press }
  42. { Used for CTRL_C checking in I/O calls }
  43. procedure checkCTRLC;
  44. begin
  45. if BreakOn then begin
  46. if (SetSignal(0,0) And SIGBREAKF_CTRL_C)<>0 then begin
  47. { Clear CTRL-C signal }
  48. SetSignal(0,SIGBREAKF_CTRL_C);
  49. Halt(CTRL_C);
  50. end;
  51. end;
  52. end;
  53. { Converts a AmigaOS dos.library error code to a TP compatible error code }
  54. { Based on 1.0.x Amiga RTL }
  55. procedure dosError2InOut(errno: LongInt);
  56. begin
  57. case errno of
  58. ERROR_BAD_NUMBER,
  59. ERROR_ACTION_NOT_KNOWN,
  60. ERROR_NOT_IMPLEMENTED : InOutRes := 1;
  61. ERROR_OBJECT_NOT_FOUND : InOutRes := 2;
  62. ERROR_DIR_NOT_FOUND : InOutRes := 3;
  63. ERROR_DISK_WRITE_PROTECTED : InOutRes := 150;
  64. ERROR_OBJECT_WRONG_TYPE : InOutRes := 151;
  65. ERROR_OBJECT_EXISTS,
  66. ERROR_DELETE_PROTECTED,
  67. ERROR_WRITE_PROTECTED,
  68. ERROR_READ_PROTECTED,
  69. ERROR_OBJECT_IN_USE,
  70. ERROR_DIRECTORY_NOT_EMPTY : InOutRes := 5;
  71. ERROR_NO_MORE_ENTRIES : InOutRes := 18;
  72. ERROR_RENAME_ACROSS_DEVICES : InOutRes := 17;
  73. ERROR_DISK_FULL : InOutRes := 101;
  74. ERROR_INVALID_RESIDENT_LIBRARY : InoutRes := 153;
  75. ERROR_BAD_HUNK : InOutRes := 153;
  76. ERROR_NOT_A_DOS_DISK : InOutRes := 157;
  77. ERROR_NO_DISK,
  78. ERROR_DISK_NOT_VALIDATED,
  79. ERROR_DEVICE_NOT_MOUNTED : InOutRes := 152;
  80. ERROR_SEEK_ERROR : InOutRes := 156;
  81. ERROR_LOCK_COLLISION,
  82. ERROR_LOCK_TIMEOUT,
  83. ERROR_UNLOCK_ERROR,
  84. ERROR_INVALID_LOCK,
  85. ERROR_INVALID_COMPONENT_NAME,
  86. ERROR_BAD_STREAM_NAME,
  87. ERROR_FILE_NOT_OBJECT : InOutRes := 6;
  88. else
  89. InOutRes := errno;
  90. end;
  91. end;
  92. { Converts an Unix-like path to Amiga-like path }
  93. function PathConv(path: string): string; alias: 'PATHCONV'; [public];
  94. var tmppos: longint;
  95. begin
  96. { check for short paths }
  97. if length(path)<=2 then begin
  98. if (path='.') or (path='./') then path:='' else
  99. if path='..' then path:='/' else
  100. if path='*' then path:='#?';
  101. end else begin
  102. { convert parent directories }
  103. tmppos:=pos('../',path);
  104. while tmppos<>0 do begin
  105. { delete .. to have / as parent dir sign }
  106. delete(path,tmppos,2);
  107. tmppos:=pos('../',path);
  108. end;
  109. { convert current directories }
  110. tmppos:=pos('./',path);
  111. while tmppos<>0 do begin
  112. { delete ./ since we doesn't need to sign current directory }
  113. delete(path,tmppos,2);
  114. tmppos:=pos('./',path);
  115. end;
  116. { convert wildstar to #? }
  117. tmppos:=pos('*',path);
  118. while tmppos<>0 do begin
  119. delete(path,tmppos,1);
  120. insert('#?',path,tmppos);
  121. tmppos:=pos('*',path);
  122. end;
  123. end;
  124. PathConv:=path;
  125. end;
  126. { Converts an Unix-like path to Amiga-like path }
  127. function PathConv(const path: rawbytestring): rawbytestring; alias: 'PATHCONVRBS'; [public];
  128. var tmppos: longint;
  129. begin
  130. { check for short paths }
  131. if length(path)<=2 then begin
  132. if (path='.') or (path='./') then PathConv:='' else
  133. if path='..' then PathConv:='/' else
  134. if path='*' then PathConv:='#?'
  135. else PathConv:=path;
  136. end else begin
  137. { convert parent directories }
  138. PathConv:=path;
  139. tmppos:=pos('../',PathConv);
  140. while tmppos<>0 do begin
  141. { delete .. to have / as parent dir sign }
  142. delete(PathConv,tmppos,2);
  143. tmppos:=pos('../',PathConv);
  144. end;
  145. { convert current directories }
  146. tmppos:=pos('./',PathConv);
  147. while tmppos<>0 do begin
  148. { delete ./ since we doesn't need to sign current directory }
  149. delete(PathConv,tmppos,2);
  150. tmppos:=pos('./',PathConv);
  151. end;
  152. { convert wildstar to #? }
  153. tmppos:=pos('*',PathConv);
  154. while tmppos<>0 do begin
  155. delete(PathConv,tmppos,1);
  156. insert('#?',PathConv,tmppos);
  157. tmppos:=pos('*',PathConv);
  158. end;
  159. end;
  160. end;
  161. { Thread Init/Exit Procedure support }
  162. Type
  163. PThreadProcInfo = ^TThreadProcInfo;
  164. TThreadProcInfo = Record
  165. Next : PThreadProcInfo;
  166. Proc : TProcedure;
  167. End;
  168. const
  169. threadInitProcList :PThreadProcInfo = nil;
  170. threadExitProcList :PThreadProcInfo = nil;
  171. Procedure DoThreadProcChain(p: PThreadProcInfo);
  172. Begin
  173. while p <> nil do
  174. begin
  175. p^.proc;
  176. p:=p^.next;
  177. end;
  178. End;
  179. Procedure AddThreadProc(var procList: PThreadProcInfo; Proc: TProcedure);
  180. var
  181. P : PThreadProcInfo;
  182. Begin
  183. // the ThreadProc chain is only freed after the memory manager has
  184. // shut down, therefore native OS allocation
  185. P := AllocPooled(ASYS_heapPool,sizeof(TThreadProcInfo));
  186. P^.Next:=procList;
  187. P^.Proc:=Proc;
  188. procList:=P;
  189. End;
  190. Procedure CleanupThreadProcChain(var procList: PThreadProcInfo);
  191. var
  192. P : PThreadProcInfo;
  193. Begin
  194. while procList <> nil do
  195. begin
  196. p:=procList;
  197. procList:=procList^.next;
  198. FreePooled(ASYS_heapPool,P,sizeof(TThreadProcInfo));
  199. end;
  200. End;
  201. Procedure AddThreadInitProc(Proc: TProcedure);
  202. Begin
  203. AddThreadProc(threadInitProcList,Proc);
  204. End;
  205. Procedure AddThreadExitProc(Proc: TProcedure);
  206. Begin
  207. AddThreadProc(threadExitProcList,Proc);
  208. End;
  209. Procedure DoThreadInitProcChain;
  210. Begin
  211. DoThreadProcChain(threadInitProcList);
  212. End;
  213. Procedure DoThreadExitProcChain;
  214. Begin
  215. DoThreadProcChain(threadExitProcList);
  216. End;