Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

262 lines
8.8 KiB

  1. ;/*
  2. ; * Microsoft Confidential
  3. ; * Copyright (C) Microsoft Corporation 1988 - 1991
  4. ; * All Rights Reserved.
  5. ; */
  6. /* MEMEX.C - expanded and extended memory handling functions for MEM.C.
  7. */
  8. #include "ctype.h"
  9. #include "conio.h" /* need for kbhit prototype */
  10. #include "stdio.h"
  11. #include "dos.h"
  12. #include "string.h"
  13. #include "stdlib.h"
  14. #include "msgdef.h"
  15. #include "version.h" /* MSKK02 07/18/89 */
  16. #include "mem.h"
  17. #include "xmm.h"
  18. #include "versionc.h"
  19. /*���������������������������������������������������������������������������*/
  20. void DisplayEMSDetail()
  21. {
  22. #define EMSGetHandleName 0x5300 /* get handle name function */
  23. #define EMSGetHandlePages 0x4c00 /* get handle name function */
  24. #define EMSCODE_83 0x83 /* handle not found error */
  25. #define EMSMaxHandles 256 /* max number handles */
  26. int HandleIndex; /* used to step through handles */
  27. char HandleName[9]; /* save area for handle name */
  28. unsigned long int HandleMem; /* memory associated w/handle */
  29. char TitlesPrinted = FALSE; /* flag for printing titles */
  30. HandleName[0] = NUL; /* initialize the array */
  31. Sub0_Message(NewLineMsg,STDOUT,Utility_Msg_Class);
  32. segread(&SegRegs);
  33. SegRegs.es = SegRegs.ds;
  34. for (HandleIndex = 0; HandleIndex < EMSMaxHandles; HandleIndex++)
  35. {
  36. InRegs.x.ax = EMSGetHandleName; /* get handle name */
  37. InRegs.x.dx = HandleIndex; /* handle in question */
  38. InRegs.x.di = (unsigned int) HandleName; /* point to handle name */
  39. int86x(EMS, &InRegs, &OutRegs, &SegRegs);
  40. HandleName[8] = NUL; /* make sure terminated w/nul */
  41. if (OutRegs.h.ah != EMSCODE_83)
  42. {
  43. InRegs.x.ax = EMSGetHandlePages; /* get pages assoc w/this handle */
  44. InRegs.x.dx = HandleIndex;
  45. int86x(EMS, &InRegs, &OutRegs, &SegRegs);
  46. HandleMem = OutRegs.x.bx;
  47. HandleMem *= (long) (16l*1024l);
  48. if (!TitlesPrinted)
  49. {
  50. Sub0_Message(Title3Msg,STDOUT,Utility_Msg_Class);
  51. Sub0_Message(Title4Msg,STDOUT,Utility_Msg_Class);
  52. TitlesPrinted = TRUE;
  53. }
  54. if (HandleName[0] == NUL) strcpy(HandleName," ");
  55. EMSPrint(HandleMsg,
  56. STDOUT,
  57. Utility_Msg_Class,
  58. &HandleIndex,
  59. HandleName,
  60. &HandleMem);
  61. }
  62. } /* end for (HandleIndex = 0; HandleIndex < EMSMaxHandles;HandleIndex++) */
  63. return;
  64. } /* end of DisplayEMSDetail */
  65. /*���������������������������������������������������������������������������*/
  66. void DisplayExtendedSummary()
  67. {
  68. unsigned long int EXTMemoryTot;
  69. unsigned long int XMSMemoryTot;
  70. unsigned long int HMA_In_Use;
  71. unsigned DOS_Is_High,DOS_in_ROM;
  72. InRegs.h.ah = (unsigned char) 0x52; /* Get SysVar Pointer ;an001; dms;*/
  73. intdosx(&InRegs,&OutRegs,&SegRegs); /* Invoke interrupt ;an001; dms;*/
  74. FP_SEG(SysVarsPtr) = SegRegs.es; /* put pointer in var ;an001; dms;*/
  75. FP_OFF(SysVarsPtr) = OutRegs.x.bx; /* ;an001; dms;*/
  76. if ((SysVarsPtr) -> ExtendedMemory != 0) /* extended memory? ;an001; dms;*/
  77. { /* yes ;an001; dms;*/
  78. EXTMemoryTot = (long) (SysVarsPtr) -> ExtendedMemory; /* get total EM size ;an001; dms;*/
  79. EXTMemoryTot *= (long) 1024l; /* at boot time ;an001; dms;*/
  80. Sub0_Message(NewLineMsg,STDOUT,Utility_Msg_Class); /* print blank line ;an001; dms;*/
  81. Sub1_Message(EXTMemoryMsg,STDOUT,Utility_Msg_Class,&EXTMemoryTot); /* print total EM mem ;an001; dms;*/
  82. OutRegs.x.cflag = 0; /* clear carry flag ;an001; dms;*/
  83. InRegs.x.ax = GetExtended; /* get extended mem ;an001; dms;*/
  84. /* available */
  85. int86(CASSETTE, &InRegs, &OutRegs); /* INT 15h call ;an001; dms;*/
  86. EXTMemoryTot = (unsigned long) OutRegs.x.ax * 1024l; /* returns 1K mem blocks;an001; dms;*/
  87. /* subtract out VDisk usage. Note assumption that VDisk usage doesn't
  88. * exceed 64Mb. Don't bother if there is no extended memory
  89. */
  90. if (EXTMemoryTot != 0)
  91. EXTMemoryTot -= (unsigned long) (CheckVDisk() * 1024l);
  92. Sub1_Message(EXTMemAvlMsg,STDOUT,Utility_Msg_Class,&EXTMemoryTot); /* display available ;an001; dms;*/
  93. /* if an XMS driver is present, INT 15 may return 0 as the amount
  94. * of extended memory available. In that case, call the XMS
  95. * driver to find out the amount of XMS free. Don't call XMS
  96. * unconditionally, because that will cause it to claim memory
  97. * if it has not already done so.
  98. *
  99. * However, it is possible, with the newer versions of Himem,
  100. * for XMS memory and INT 15 memory to coexist. There is no
  101. * completely reliable way to detect this situation, but we
  102. * do know that if Himem is installed, DOS is high, and INT 15
  103. * memory exists, then we are configured that way. In that case,
  104. * we can make calls to Himem without disrupting the memory environment.
  105. * Otherwise we can't.
  106. */
  107. if (XMM_Installed())
  108. {
  109. InRegs.x.ax = 0x3306; /* get DOS version info */
  110. intdos(&InRegs, &OutRegs); /* call DOS */
  111. DOS_Is_High = (OutRegs.h.dh & DOSHMA);
  112. DOS_in_ROM = (OutRegs.h.dh & DOSROM);
  113. if (DOS_Is_High || EXTMemoryTot == 0)
  114. { /* make this check only if we won't disrupt environment */
  115. /* get and display XMS memory available */
  116. XMSMemoryTot = XMM_QueryTotalFree() * 1024l;
  117. Sub1_Message(XMSMemAvlMsg,STDOUT,Utility_Msg_Class,
  118. &XMSMemoryTot);
  119. }
  120. /* get and display HMA status */
  121. /* DOS High implies HMA is in use */
  122. if (DOS_Is_High)
  123. if (DOS_in_ROM)
  124. Sub0_Message(ROMDOSMsg,STDOUT,Utility_Msg_Class);
  125. else
  126. Sub0_Message(HMADOSMsg,STDOUT,Utility_Msg_Class);
  127. /* DOS isn't, check if HMA in use, but only if we can quietly */
  128. else if (EXTMemoryTot == 0)
  129. {
  130. HMA_In_Use = XMM_RequestHMA(0xffff);
  131. if (HMA_In_Use)
  132. Sub0_Message(HMANotAvlMsg,STDOUT,Utility_Msg_Class);
  133. else
  134. {
  135. XMM_ReleaseHMA();
  136. Sub0_Message(HMAAvlMsg,STDOUT,Utility_Msg_Class);
  137. }
  138. }
  139. }
  140. }
  141. } /* end of DisplayExtendedSummary */
  142. /*���������������������������������������������������������������������������*/
  143. void DisplayEMSSummary()
  144. {
  145. unsigned long int EMSFreeMemoryTot;
  146. unsigned long int EMSAvailMemoryTot;
  147. Sub0_Message(NewLineMsg,STDOUT,Utility_Msg_Class);
  148. InRegs.x.ax = EMSGetFreePgs; /* get total number unallocated pages */
  149. int86x(EMS, &InRegs, &OutRegs, &SegRegs);
  150. EMSFreeMemoryTot = OutRegs.x.bx; /* total unallocated pages in BX */
  151. EMSFreeMemoryTot *= (long) (16l*1024l);
  152. EMSAvailMemoryTot = OutRegs.x.dx; /* total pages */
  153. EMSAvailMemoryTot *= (long) (16l*1024l);
  154. Sub1_Message(EMSTotalMemoryMsg,STDOUT,Utility_Msg_Class,&EMSAvailMemoryTot);
  155. Sub1_Message(EMSFreeMemoryMsg,STDOUT,Utility_Msg_Class,&EMSFreeMemoryTot);
  156. return;
  157. } /* end of DisplayEMSSummary */
  158. /*���������������������������������������������������������������������������*/
  159. char EMSInstalled()
  160. {
  161. unsigned int EMSStatus;
  162. unsigned int EMSVersion;
  163. char EmsName[8];
  164. void far *EmsNameP;
  165. if (EMSInstalledFlag == 2)
  166. {
  167. EMSInstalledFlag = FALSE;
  168. InRegs.h.ah = GET_VECT; /* get int 67 vector */
  169. InRegs.h.al = EMS;
  170. intdosx(&InRegs,&OutRegs,&SegRegs);
  171. /* only want to try this if vector is non-zero */
  172. if ((SegRegs.es != 0) && (OutRegs.x.bx != 0))
  173. {
  174. EmsNameP = EmsName;
  175. movedata(SegRegs.es, 0x000a, FP_SEG(EmsNameP), FP_OFF(EmsNameP), 8);
  176. if (strncmp(EmsName, "EMMXXXX0", 8))
  177. return (EMSInstalledFlag);
  178. InRegs.x.ax = EMSGetStat; /* get EMS status */
  179. int86x(EMS, &InRegs, &OutRegs, &SegRegs);
  180. EMSStatus = OutRegs.h.ah; /* EMS status returned in AH */
  181. InRegs.x.ax = EMSGetVer; /* get EMS version */
  182. int86x(EMS, &InRegs, &OutRegs, &SegRegs);
  183. EMSVersion = OutRegs.h.al; /* EMS version returned in AL */
  184. if ((EMSStatus == 0) && (EMSVersion >= DOSEMSVER))
  185. EMSInstalledFlag = TRUE;
  186. } /* end ((SegRegs.es != 0) && (OutRegs.x.bx != 0)) */
  187. } /* end if (EMSInstalledFlag == 2) */
  188. return(EMSInstalledFlag);
  189. }
  190.