sysheap.inc 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. Heap Management
  15. *****************************************************************************}
  16. {$ifdef DEBUG_TINY_HEAP}
  17. { Internal structure used by MSDOS }
  18. type
  19. MCB = packed record
  20. sig : char;
  21. psp : word;
  22. paragraphs : word;
  23. res : array [0..2] of char;
  24. exename : array [0..7] of char;
  25. end;
  26. PMCB = ^MCB;
  27. {$endif def DEBUG_TINY_HEAP}
  28. function SysOSAlloc (size: ptruint): pointer;
  29. var
  30. regs : Registers;
  31. nb_para : longint;
  32. {$ifdef DEBUG_TINY_HEAP}
  33. p : pmcb;
  34. i : byte;
  35. {$endif def DEBUG_TINY_HEAP}
  36. begin
  37. {$ifdef DEBUG_TINY_HEAP}
  38. writeln('SysOSAlloc called size=',size);
  39. {$endif}
  40. {$if defined(FPC_X86_DATA_FAR) or defined(FPC_X86_DATA_HUGE)}
  41. regs.ax:=$4800;
  42. nb_para:=size div 16;
  43. if nb_para > $ffff then
  44. begin
  45. {$ifdef DEBUG_TINY_HEAP}
  46. writeln('SysOSAlloc size too big = ',size);
  47. {$endif}
  48. result:=nil;
  49. end
  50. else
  51. begin
  52. regs.bx:=nb_para;
  53. msdos(regs);
  54. if (regs.Flags and fCarry) <> 0 then
  55. begin
  56. {$ifdef DEBUG_TINY_HEAP}
  57. writeln('SysOSAlloc failed, err = ',regs.AX);
  58. {$endif}
  59. { Do not set InOutRes if ReturnNilIfGrowHeapFails is set }
  60. if not ReturnNilIfGrowHeapFails then
  61. GetInOutRes(regs.AX);
  62. Result := nil;
  63. end
  64. else
  65. begin
  66. result:=ptr(regs.ax,0);
  67. {$ifdef DEBUG_TINY_HEAP}
  68. writeln('SysOSAlloc returned= $',hexstr(regs.ax,4),':$0');
  69. p:=ptr(regs.ax-1,0);
  70. writeln('Possibly prev MCB: at ',hexstr(p));
  71. writeln(' sig=',p^.sig);
  72. writeln(' psp=$',hexstr(p^.psp,4));
  73. writeln(' paragraphs=',p^.paragraphs);
  74. if (p^.exename[0]<>#0) then
  75. begin
  76. write(' name=');
  77. for i:=0 to 7 do
  78. if ord(p^.exename[i])>31 then
  79. write(p^.exename[i]);
  80. writeln;
  81. end;
  82. p:=ptr(regs.ax+p^.paragraphs,0);
  83. writeln('Possibly next MCB: at ',hexstr(p));
  84. writeln(' sig=',p^.sig);
  85. writeln(' psp=$',hexstr(p^.psp,4));
  86. writeln(' paragraphs=',p^.paragraphs);
  87. if (p^.exename[0]<>#0) then
  88. begin
  89. write(' name=');
  90. for i:=0 to 7 do
  91. if ord(p^.exename[i])>31 then
  92. write(p^.exename[i]);
  93. writeln;
  94. end;
  95. {$endif}
  96. end;
  97. end;
  98. {$else not DATA_FAR}
  99. {$ifdef DEBUG_TINY_HEAP}
  100. writeln('SysOSAlloc cannot be used in small data models');
  101. {$endif}
  102. Result := nil;
  103. {$endif not DATA_FAR}
  104. end;
  105. procedure SysOSFree(p: pointer; size: ptruint);
  106. begin
  107. end;