Advertisement
Guest User

Untitled

a guest
Apr 15th, 2022
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 71.37 KB | None | 0 0
  1. Only in c:\ACPI\ACPI_SP1\Base\busdrv\acpi/driver/amlinew: MSG00001.bin
  2. Only in c:\ACPI\ACPI_SP1\Base\busdrv\acpi/driver/amlinew: acpilog.h
  3. Only in c:\ACPI\ACPI_SP1\Base\busdrv\acpi/driver/amlinew: acpilog.rc
  4. diff --strip-trailing-cr -ur ./driver/amlinew/amlipriv.h "c:\\ACPI\\ACPI_SP1\\Base\\busdrv\\acpi/driver/amlinew/amlipriv.h"
  5. --- ./driver/amlinew/amlipriv.h 2002-09-02 18:22:22.000000000 +0500
  6. +++ "c:\\ACPI\\ACPI_SP1\\Base\\busdrv\\acpi/driver/amlinew/amlipriv.h" 2022-04-16 06:47:51.856445300 +0500
  7. @@ -285,6 +285,7 @@
  8. #define AMLISTA_CONTINUE 0x00008003
  9. #define AMLISTA_PENDING 0x00008004
  10. #define AMLISTA_TIMEOUT 0x00008005
  11. +#define AMLISTA_CONTINUEOP 0x00008006
  12.  
  13. // Global AMLI flags
  14. #define AMLIF_LOCKED 0x00000001
  15. @@ -331,6 +332,7 @@
  16. #define ARGOBJ_BASICDATA 'D' //INTDATA,STRDATA,BUFFDATA
  17. #define ARGOBJ_COMPLEXDATA 'C' //BUFFDATA,PKGDATA
  18. #define ARGOBJ_REFERENCE 'R' //OBJALIAS,DATAALIAS,BUFFFIELD
  19. +#define ARGOBJ_STRBUFDATA 'T' //OBJTYPE_STRDATA/OBJTYPE_BUFFDATA
  20.  
  21. #define MAX_BYTE 0xff
  22. #define MAX_WORD 0xffff
  23. @@ -368,7 +370,8 @@
  24. /*** Type and Structure definitions
  25. */
  26.  
  27. -typedef NTSTATUS (LOCAL *PFNOP)(PFRAME, PPNSOBJ);
  28. +//typedef NTSTATUS (LOCAL *PFNOP)(PFRAME, PPNSOBJ);
  29. +typedef NTSTATUS (LOCAL *PFNOP)(PCTXT, PTERM);
  30.  
  31. typedef struct _amlterm
  32. {
  33. diff --strip-trailing-cr -ur ./driver/amlinew/amlitest.c "c:\\ACPI\\ACPI_SP1\\Base\\busdrv\\acpi/driver/amlinew/amlitest.c"
  34. --- ./driver/amlinew/amlitest.c 2002-09-02 18:22:22.000000000 +0500
  35. +++ "c:\\ACPI\\ACPI_SP1\\Base\\busdrv\\acpi/driver/amlinew/amlitest.c" 2022-04-16 06:47:51.870117100 +0500
  36. @@ -52,22 +52,24 @@
  37. PCCHAR DebugMessage,
  38. ...)
  39. {
  40. + int index;
  41. va_list ap;
  42. va_start(ap, DebugMessage);
  43.  
  44. -
  45. if(DebugPrintLevel & AmliTestDebugFlags)
  46. - {
  47. -
  48. -
  49. -
  50. - if(_vsnprintf(AmliTestDebugBuffer,
  51. + {
  52. + index = _vsnprintf(AmliTestDebugBuffer,
  53. 200,
  54. DebugMessage,
  55. - ap) == -1)
  56. + ap);
  57. + // SP3
  58. + if(index == -1)
  59. {
  60. - AmliTestDebugBuffer[199] = '\0';
  61. + AmliTestDebugBuffer[0] = '\0';
  62. + } else {
  63. + AmliTestDebugBuffer[index] = '\0';
  64. }
  65. + // SP3
  66.  
  67. DbgPrint(AmliTestDebugBuffer);
  68. }
  69. diff --strip-trailing-cr -ur ./driver/amlinew/data.c "c:\\ACPI\\ACPI_SP1\\Base\\busdrv\\acpi/driver/amlinew/data.c"
  70. --- ./driver/amlinew/data.c 2002-09-02 18:22:22.000000000 +0500
  71. +++ "c:\\ACPI\\ACPI_SP1\\Base\\busdrv\\acpi/driver/amlinew/data.c" 2022-04-16 06:47:51.880859300 +0500
  72. @@ -188,6 +188,23 @@
  73. atToBCD = {"ToBCD", OP_TOBCD, "CS", C2, 0, NULL, 0, ExprOp1},
  74. atWait = {"Wait", OP_WAIT, "SC", C2, 0, NULL, 0, Wait},
  75. atXOr = {"XOr", OP_XOR, "CCS", C2, 0, NULL, 0, ExprOp2},
  76. +
  77. + // ACPI 2.0
  78. + atToBuffer = {"ToBuffer", OP_TOBUFFER, "CS", C2, 0, NULL, 0, ToBuffer},
  79. + atToDecString = {"ToDecimalString", OP_TODECSTRING, "CS", C2, 0, NULL, 0, ToDecimalString},
  80. + atToHexString = {"ToHexString", OP_TOHEXSTRING, "CS", C2, 0, NULL, 0, ToHexString},
  81. + atToInteger = {"ToInteger", OP_TOINTEGER, "CS", C2, 0, NULL, 0, ToInteger},
  82. + atQWordField = {"CreateQWordField", OP_QWORDFIELD, "CCN", OB, 0, NULL, 0, CreateQWordField},
  83. + atConcatRes = {"ConcatenateResTemplate", OP_CONCATRESTMPL, "CCS", C2, 0, NULL, 0, ConcatenateResTemplate},
  84. + atMod = {"Mod", OP_MOD, "CCS", C2, 0, NULL, 0, ExprOp2},
  85. + atToString = {"ToString", OP_TOSTRING, "CCS", C2, 0, NULL, 0, ToString},
  86. + atCopyObject = {"CopyObject", OP_COPYOBJECT, "CS", C2, 0, NULL, 0, CopyObject},
  87. + atMid = {"Mid", OP_MID, "CCCS", C2, 0, NULL, 0, MidString},
  88. + atContinue = {"Continue", OP_CONTINUE, NULL, C1, 0, NULL, 0, Continue},
  89. + atTimer = {"Timer", OP_TIMER , NULL, C2, 0, NULL, 0, Timer},
  90. + // OP_QWORD=0xE - see atDataObj
  91. +
  92. +
  93. //
  94. // Misc. Opcodes
  95. //
  96. @@ -206,7 +223,7 @@
  97. //0x08 0x09 0x0a 0x0b
  98. &atName, NULL, &atDataObj, &atDataObj,
  99. //0x0c 0x0d 0x0e 0x0f
  100. - &atDataObj, &atString, NULL, NULL,
  101. + &atDataObj, &atString, &atDataObj, NULL,
  102. //0x10 0x11 0x12 0x13
  103. &atScope, &atBuffer, &atPackage, NULL,
  104. //0x14 0x15 0x16 0x17
  105. @@ -266,19 +283,19 @@
  106. //0x80 0x81 0x82 0x83
  107. &atNot, &atFindSetLBit, &atFindSetRBit, &atDerefOf,
  108. //0x84 0x85 0x86 0x87
  109. - NULL, NULL, &atNotify, &atSizeOf,
  110. + &atConcatRes, &atMod, &atNotify, &atSizeOf,
  111. //0x88 0x89 0x8a 0x8b
  112. &atIndex, &atMatch, &atDWordField, &atWordField,
  113. //0x8c 0x8d 0x8e 0x8f
  114. - &atByteField, &atBitField, &atObjType, NULL,
  115. + &atByteField, &atBitField, &atObjType, &atQWordField,
  116. //0x90 0x91 0x92 0x93
  117. &atLAnd, &atLOr, &atLNot, &atLEq,
  118. //0x94 0x95 0x96 0x97
  119. - &atLG, &atLL, NULL, NULL,
  120. + &atLG, &atLL, &atToBuffer, &atToDecString,
  121. //0x98 0x99 0x9a 0x9b
  122. - NULL, NULL, NULL, NULL,
  123. + &atToHexString, &atToInteger, NULL, NULL,
  124. //0x9c 0x9d 0x9e 0x9f
  125. - NULL, NULL, NULL, NULL,
  126. + &atToString, &atCopyObject, &atMid, &atContinue,
  127. //0xa0 0xa1 0xa2 0xa3
  128. &atIf, &atElse, &atWhile, &atNOP,
  129. //0xa4 0xa5 0xa6 0xa7
  130. @@ -349,6 +366,7 @@
  131. EXOP_REVISION, &atDataObj,
  132. EXOP_DEBUG, &atDebugObj,
  133. EXOP_FATAL, &atFatal,
  134. + EXOP_TIMER, &atTimer,
  135. EXOP_OPREGION, &atOpRegion,
  136. EXOP_FIELD, &atField,
  137. EXOP_DEVICE, &atDevice,
  138. diff --strip-trailing-cr -ur ./driver/amlinew/misc.c "c:\\ACPI\\ACPI_SP1\\Base\\busdrv\\acpi/driver/amlinew/misc.c"
  139. --- ./driver/amlinew/misc.c 2002-09-02 18:22:22.000000000 +0500
  140. +++ "c:\\ACPI\\ACPI_SP1\\Base\\busdrv\\acpi/driver/amlinew/misc.c" 2022-04-16 06:47:51.891601500 +0500
  141. @@ -1327,6 +1327,17 @@
  142. }
  143. break;
  144.  
  145. + case ARGOBJ_STRBUFDATA:
  146. + if ((pArgs[i].dwDataType != OBJTYPE_STRDATA) &&
  147. + (pArgs[i].dwDataType != OBJTYPE_BUFFDATA))
  148. + {
  149. + rc = AMLI_LOGERR(AMLIERR_UNEXPECTED_OBJTYPE,
  150. + ("ValidateArgTypes: expected Arg%d to be type str/buff (Type=%s)",
  151. + i,
  152. + GetObjectTypeName(pArgs[i].dwDataType)));
  153. + }
  154. + break;
  155. +
  156. default:
  157. rc = AMLI_LOGERR(AMLIERR_ASSERT_FAILED,
  158. ("ValidateArgTypes: internal error (invalid type - %c)",
  159. diff --strip-trailing-cr -ur ./driver/amlinew/object.c "c:\\ACPI\\ACPI_SP1\\Base\\busdrv\\acpi/driver/amlinew/object.c"
  160. --- ./driver/amlinew/object.c 2002-09-02 18:22:22.000000000 +0500
  161. +++ "c:\\ACPI\\ACPI_SP1\\Base\\busdrv\\acpi/driver/amlinew/object.c" 2022-04-16 06:47:51.904296800 +0500
  162. @@ -300,7 +300,7 @@
  163. ENTER(3, ("ReadField(pctxt=%x,pdataObj=%x,FieldDesc=%x,pdataResult=%x)\n",
  164. pctxt, pdataObj, pfd, pdataResult));
  165.  
  166. - if ((pfd->dwFieldFlags & ACCTYPE_MASK) <= ACCTYPE_DWORD)
  167. + if ((pfd->dwFieldFlags & ACCTYPE_MASK) <= ACCTYPE_QWORD)
  168. {
  169. PUCHAR pb;
  170. ULONG dwcb;
  171. @@ -309,11 +309,11 @@
  172. {
  173. case OBJTYPE_UNKNOWN:
  174. if (!(pfd->dwFieldFlags & FDF_BUFFER_TYPE) &&
  175. - (pfd->dwNumBits <= sizeof(ULONG)*8))
  176. + (pfd->dwNumBits <= sizeof(ULONG64)*8)) // dwNumBits = 64 for QWORD field
  177. {
  178. pdataResult->dwDataType = OBJTYPE_INTDATA;
  179. pb = (PUCHAR)&pdataResult->uipDataValue;
  180. - dwcb = sizeof(ULONG);
  181. + dwcb = sizeof(ULONG); // ULONG64 ACPI 2.0
  182. }
  183. else
  184. {
  185. @@ -341,7 +341,7 @@
  186.  
  187. case OBJTYPE_INTDATA:
  188. pb = (PUCHAR)&pdataResult->uipDataValue;
  189. - dwcb = sizeof(ULONG);
  190. + dwcb = sizeof(ULONG); // acpi 2.0: sizeof(ULONG64)
  191. break;
  192.  
  193. case OBJTYPE_STRDATA:
  194. @@ -410,14 +410,14 @@
  195. ENTER(3, ("WriteField(pctxt=%x,pdataObj=%x,FieldDesc=%x,pdataSrc=%x)\n",
  196. pctxt, pdataObj, pfd, pdataSrc));
  197.  
  198. - if ((pfd->dwFieldFlags & ACCTYPE_MASK) <= ACCTYPE_DWORD)
  199. + if ((pfd->dwFieldFlags & ACCTYPE_MASK) <= ACCTYPE_QWORD)
  200. {
  201. PWRFIELDLOOP pwfl;
  202.  
  203. switch (pdataSrc->dwDataType)
  204. {
  205. case OBJTYPE_INTDATA:
  206. - dwBuffSize = MIN(sizeof(ULONG), dwDataInc);
  207. + dwBuffSize = MIN(sizeof(ULONG), dwDataInc); // ULONG64 for Integer64
  208. pbBuff = (PUCHAR)&pdataSrc->uipDataValue;
  209. break;
  210.  
  211. diff --strip-trailing-cr -ur ./driver/amlinew/parser.c "c:\\ACPI\\ACPI_SP1\\Base\\busdrv\\acpi/driver/amlinew/parser.c"
  212. --- ./driver/amlinew/parser.c 2002-09-02 18:22:22.000000000 +0500
  213. +++ "c:\\ACPI\\ACPI_SP1\\Base\\busdrv\\acpi/driver/amlinew/parser.c" 2022-04-16 06:47:51.915039000 +0500
  214. @@ -30,7 +30,9 @@
  215. NTSTATUS LOCAL ParseScope(PCTXT pctxt, PSCOPE pscope, NTSTATUS rc)
  216. {
  217. TRACENAME("PARSESCOPE")
  218. - ULONG dwStage = ((rc == STATUS_SUCCESS) || (rc == AMLISTA_BREAK))?
  219. + ULONG dwStage = ((rc == STATUS_SUCCESS) ||
  220. + (rc == AMLISTA_BREAK) ||
  221. + (rc == AMLISTA_CONTINUEOP))?
  222. (pscope->FrameHdr.dwfFrame & FRAMEF_STAGE_MASK): 2;
  223.  
  224. ENTER(2, ("ParseScope(Stage=%d,pctxt=%p,pbOp=%p,pscope=%p,rc=%x)\n",
  225. @@ -67,9 +69,24 @@
  226. if (rc == AMLISTA_BREAK)
  227. {
  228. pctxt->pbOp = pscope->pbOpEnd;
  229. - rc = STATUS_SUCCESS;
  230. - }
  231. - else
  232. +
  233. + // SP3
  234. + pscope->pbOpRet = pscope->pbOpEnd;
  235. + if (pscope->FrameHdr.dwfFrame & CALLF_ACQ_MUTEX) { // test byte ptr [esi+0Ah], 2
  236. + rc = STATUS_SUCCESS;
  237. + }
  238. + // SP3
  239. + } else
  240. + if (rc == AMLISTA_CONTINUEOP)
  241. + {
  242. + pctxt->pbOp = pscope->pbOpEnd;
  243. +
  244. + // SP3
  245. + if (pscope->FrameHdr.dwfFrame & CALLF_ACQ_MUTEX) { // test byte ptr [esi+0Ah], 2
  246. + rc = STATUS_SUCCESS;
  247. + }
  248. + // SP3
  249. + } else
  250. {
  251. while (pctxt->pbOp < pscope->pbOpEnd)
  252. {
  253. @@ -113,7 +130,23 @@
  254. if (rc == AMLISTA_BREAK)
  255. {
  256. pctxt->pbOp = pscope->pbOpEnd;
  257. - rc = STATUS_SUCCESS;
  258. +
  259. + // SP3
  260. + pscope->pbOpRet = pscope->pbOpEnd;
  261. + if (pscope->FrameHdr.dwfFrame & CALLF_ACQ_MUTEX) { // test byte ptr [esi+0Ah], 2
  262. + rc = STATUS_SUCCESS;
  263. + }
  264. + // SP3
  265. + }
  266. + else if (rc == AMLISTA_CONTINUEOP)
  267. + {
  268. + pctxt->pbOp = pscope->pbOpEnd;
  269. +
  270. + // SP3
  271. + if (pscope->FrameHdr.dwfFrame & CALLF_ACQ_MUTEX) { // test byte ptr [esi+0Ah], 2
  272. + rc = STATUS_SUCCESS;
  273. + }
  274. + // SP3
  275. }
  276. else if ((rc == AMLISTA_PENDING) ||
  277. (&pscope->FrameHdr !=
  278. @@ -1311,6 +1344,18 @@
  279. #ifdef DEBUGGER
  280. if (gDebugger.dwfDebugger &
  281. (DBGF_AMLTRACE_ON | DBGF_STEP_MODES))
  282. + {
  283. + PRINTF("0x%x", pdataResult->uipDataValue);
  284. + }
  285. + #endif
  286. + break;
  287. +
  288. + case OP_QWORD:
  289. + MEMCPY(&pdataResult->uipDataValue, *ppbOp, sizeof(ULONG)); // ignores high 4 bytes
  290. + (*ppbOp) += sizeof(ULONG64);
  291. + #ifdef DEBUGGER
  292. + if (gDebugger.dwfDebugger &
  293. + (DBGF_AMLTRACE_ON | DBGF_STEP_MODES))
  294. {
  295. PRINTF("0x%x", pdataResult->uipDataValue);
  296. }
  297. diff --strip-trailing-cr -ur ./driver/amlinew/proto.h "c:\\ACPI\\ACPI_SP1\\Base\\busdrv\\acpi/driver/amlinew/proto.h"
  298. --- ./driver/amlinew/proto.h 2002-09-02 18:22:22.000000000 +0500
  299. +++ "c:\\ACPI\\ACPI_SP1\\Base\\busdrv\\acpi/driver/amlinew/proto.h" 2022-04-16 06:47:51.925781200 +0500
  300. @@ -150,6 +150,20 @@
  301. BOOLEAN LOCAL MatchData(ULONG dwPkgData, ULONG dwOp, ULONG dwData);
  302. NTSTATUS LOCAL OSInterface(PCTXT pctxt, PTERM pterm);
  303.  
  304. +// ACPI 2.0
  305. +NTSTATUS LOCAL ToInteger(PCTXT pctxt, PTERM pterm);
  306. +NTSTATUS LOCAL ToHexString(PCTXT pctxt, PTERM pterm);
  307. +NTSTATUS LOCAL ToDecimalString(PCTXT pctxt, PTERM pterm);
  308. +NTSTATUS LOCAL ToBuffer(PCTXT pctxt, PTERM pterm);
  309. +NTSTATUS LOCAL CreateQWordField(PCTXT pctxt, PTERM pterm);
  310. +NTSTATUS LOCAL ConcatenateResTemplate(PCTXT pctxt, PTERM pterm);
  311. +NTSTATUS LOCAL Mod(PCTXT pctxt, PTERM pterm);
  312. +NTSTATUS LOCAL ToString(PCTXT pctxt, PTERM pterm);
  313. +NTSTATUS LOCAL CopyObject(PCTXT pctxt, PTERM pterm);
  314. +NTSTATUS LOCAL MidString(PCTXT pctxt, PTERM pterm);
  315. +NTSTATUS LOCAL Continue(PCTXT pctxt, PTERM pterm);
  316. +NTSTATUS LOCAL Timer(PCTXT pctxt, PTERM pterm);
  317. +
  318. //object.c
  319. NTSTATUS LOCAL ReadObject(PCTXT pctxt, POBJDATA pdataObj, POBJDATA pdataResult);
  320. NTSTATUS LOCAL WriteObject(PCTXT pctxt, POBJDATA pdataObj, POBJDATA pdataSrc);
  321. diff --strip-trailing-cr -ur ./driver/amlinew/type1op.c "c:\\ACPI\\ACPI_SP1\\Base\\busdrv\\acpi/driver/amlinew/type1op.c"
  322. --- ./driver/amlinew/type1op.c 2002-09-02 18:22:22.000000000 +0500
  323. +++ "c:\\ACPI\\ACPI_SP1\\Base\\busdrv\\acpi/driver/amlinew/type1op.c" 2022-04-16 06:47:51.935546800 +0500
  324. @@ -581,6 +581,11 @@
  325. rc = PushScope(pctxt, pctxt->pbOp, pterm->pbOpEnd, pterm->pbOpTerm,
  326. pctxt->pnsScope, pctxt->powner, pctxt->pheapCurrent,
  327. pterm->pdataResult);
  328. + // SP3
  329. + if (!rc) {
  330. + ((PFRAMEHDR)pctxt->LocalHeap.pbHeapEnd)->dwfFrame |= CALLF_ACQ_MUTEX;
  331. + }
  332. + // SP3
  333. }
  334. }
  335.  
  336. diff --strip-trailing-cr -ur ./driver/amlinew/type2op.c "c:\\ACPI\\ACPI_SP1\\Base\\busdrv\\acpi/driver/amlinew/type2op.c"
  337. --- ./driver/amlinew/type2op.c 2002-09-02 18:22:22.000000000 +0500
  338. +++ "c:\\ACPI\\ACPI_SP1\\Base\\busdrv\\acpi/driver/amlinew/type2op.c" 2022-04-16 06:47:51.953125000 +0500
  339. @@ -9,6 +9,11 @@
  340.  
  341. #include "pch.h"
  342.  
  343. +_CRTIMP unsigned __int64 __cdecl _strtoui64(
  344. + const char * _String,
  345. + char ** _EndPtr,
  346. + int _Radix);
  347. +
  348. #ifdef LOCKABLE_PRAGMA
  349. #pragma ACPI_LOCKABLE_DATA
  350. #pragma ACPI_LOCKABLE_CODE
  351. @@ -28,6 +33,7 @@
  352.  
  353. NTSTATUS LOCAL Buffer(PCTXT pctxt, PTERM pterm)
  354. {
  355. + USHORT* wIOBuf;
  356. TRACENAME("BUFFER")
  357. NTSTATUS rc = STATUS_SUCCESS;
  358. ULONG dwInitSize = (ULONG)(pterm->pbOpEnd - pctxt->pbOp);
  359. @@ -73,6 +79,34 @@
  360. pterm->pdataResult->dwDataLen);
  361. MEMCPY(pterm->pdataResult->pbDataBuff, pctxt->pbOp, dwInitSize);
  362. pctxt->pbOp = pterm->pbOpEnd;
  363. +
  364. + /* IOTRAPS range 0xFF00-0xFFFF vs VGA (10-bit decode!) conflict workaround
  365. + Device (IOTR)
  366. + {
  367. + ...
  368. + Name (BUF0, ResourceTemplate ()
  369. + {
  370. + IO (Decode16,
  371. + 0x0000, // Range Minimum
  372. + 0x0000, // Range Maximum
  373. + 0x01, // Alignment
  374. + 0xFF, // Length > 1
  375. + _Y21)
  376. + }) binary: 11 0D 0A _47 01 00 00 00 00 01 FF 79 00_
  377. + ...
  378. + }
  379. + */
  380. +
  381. + if (dwInitSize == 10) {
  382. + wIOBuf = (USHORT*) pterm->pdataResult->pbDataBuff;
  383. + if (wIOBuf[0] == 0x0147 &&
  384. + wIOBuf[1] == 0x0000 &&
  385. + wIOBuf[2] == 0x0000 &&
  386. + wIOBuf[3] == 0xFF01 &&
  387. + wIOBuf[4] == 0x0079 ) {
  388. + pterm->pdataResult->pbDataBuff[7] = 1; // limit range to one adress
  389. + }
  390. + }
  391. }
  392. }
  393.  
  394. @@ -704,6 +738,15 @@
  395. pterm->pdataArgs[1].uipDataValue;
  396. EXIT(2, ("XOr=%x (Result=%x)\n",
  397. rc, pterm->pdataResult->uipDataValue));
  398. + case OP_MOD:
  399. + ENTER(2, ("Mod(Value1=%x,Value2=%x)\n",
  400. + pterm->pdataArgs[0].uipDataValue,
  401. + pterm->pdataArgs[1].uipDataValue));
  402. + pterm->pdataResult->uipDataValue =
  403. + pterm->pdataArgs[0].uipDataValue %
  404. + pterm->pdataArgs[1].uipDataValue;
  405. + EXIT(2, ("Mod=%x (Result=%x)\n",
  406. + rc, pterm->pdataResult->uipDataValue));
  407. }
  408.  
  409. rc = WriteObject(pctxt, pdata, pterm->pdataResult);
  410. @@ -1528,10 +1571,12 @@
  411. char Win2000[] = "Windows 2000";
  412. char Win2001[] = "Windows 2001";
  413. char Win2001SP1[] = "Windows 2001 SP1";
  414. + char Win2001SP2[] = "Windows 2001 SP2";
  415. char* SupportedOSList[] = {
  416. Win2000,
  417. Win2001,
  418. - Win2001SP1
  419. + Win2001SP1,
  420. + Win2001SP2
  421. };
  422. ULONG ListSize = sizeof(SupportedOSList) / sizeof(char*);
  423. ULONG i = 0;
  424. @@ -1558,8 +1603,7 @@
  425. // 0 == Windows 2000
  426. // 1 == Windows 2001
  427. // 2 == Windows 2001 SP1
  428. - // .
  429. - // .
  430. + // 3 == Windows 2001 SP2
  431. //
  432. if(gdwHighestOSVerQueried < i)
  433. {
  434. @@ -1577,3 +1621,837 @@
  435. } //OSInterface
  436.  
  437.  
  438. +
  439. +///////////////////////////////////////////////
  440. +// ACPI 2.0
  441. +
  442. +
  443. +NTSTATUS LOCAL ConvertToInteger(POBJDATA In, POBJDATA Out) {
  444. + ULONG dwDataLen;
  445. + OBJDATA data;
  446. +
  447. + MEMZERO(&data, sizeof(data));
  448. + data.dwDataType = OBJTYPE_INTDATA;
  449. + switch (In->dwDataType) {
  450. + case OBJTYPE_INTDATA:
  451. + data.dwDataValue = In->dwDataValue;
  452. +
  453. + FreeDataBuffs(Out, 1);
  454. + MEMCPY(Out, &data, sizeof(data));
  455. + return STATUS_SUCCESS;
  456. + break;
  457. + case OBJTYPE_STRDATA:
  458. + data.dwDataValue = StrToUL((PSZ)In->pbDataBuff, NULL, 0);
  459. +
  460. + FreeDataBuffs(Out, 1);
  461. + MEMCPY(Out, &data, sizeof(data));
  462. + return STATUS_SUCCESS;
  463. + break;
  464. + case OBJTYPE_BUFFDATA:
  465. + dwDataLen = In->dwDataLen;
  466. + if (dwDataLen > 4) // 8 - int64
  467. + dwDataLen = 4;
  468. + MEMCPY(&data.dwDataValue, In->pbDataBuff, dwDataLen);
  469. +
  470. + FreeDataBuffs(Out, 1);
  471. + MEMCPY(Out, &data, sizeof(data));
  472. + return STATUS_SUCCESS;
  473. + break;
  474. + default:
  475. + return AMLIERR_UNEXPECTED_OBJTYPE;
  476. + break;
  477. + }
  478. +}
  479. +
  480. +
  481. +NTSTATUS LOCAL ToInteger(PCTXT pctxt, PTERM pterm)
  482. +{
  483. + NTSTATUS rc = STATUS_SUCCESS;
  484. + POBJDATA pdata;
  485. + TRACENAME("TOINTEGER")
  486. + ENTER(2, ("ToInteger(pctxt=%x,pbOp=%x,pterm=%x)\n", pctxt, pctxt->pbOp, pterm));
  487. +
  488. + if (((rc = ValidateArgTypes(pterm->pdataArgs, "D")) == STATUS_SUCCESS) &&
  489. + ((rc = ValidateTarget(&pterm->pdataArgs[1], OBJTYPE_DATAOBJ, &pdata)) == STATUS_SUCCESS)) {
  490. + if ((rc = ConvertToInteger(pterm->pdataArgs, pterm->pdataResult)) == STATUS_SUCCESS)
  491. + rc = WriteObject(pctxt, pdata, pterm->pdataResult);
  492. + }
  493. +
  494. + EXIT(2, ("ToInteger=%x (Result=%x)\n", rc, pterm->pdataResult));
  495. + return rc;
  496. +}
  497. +
  498. +
  499. +char HTOALookupTable[]="0123456789ABCDEF";
  500. +
  501. +
  502. +NTSTATUS LOCAL ToHexString(PCTXT pctxt, PTERM pterm)
  503. +{
  504. + NTSTATUS rc = STATUS_SUCCESS;
  505. + POBJDATA pdata;
  506. + int StrLen;
  507. + POBJDATA In = pterm->pdataArgs;
  508. + POBJDATA Out = pterm->pdataResult;
  509. + ULONG int32;
  510. + ULONG SrcIdx;
  511. + int i;
  512. + UCHAR pair;
  513. + TRACENAME("TOHEXSTRING")
  514. + ENTER(2, ("ToHexString(pctxt=%x,pbOp=%x,pterm=%x)\n", pctxt, pctxt->pbOp, pterm));
  515. +
  516. + if (((rc = ValidateArgTypes(pterm->pdataArgs, "D")) == STATUS_SUCCESS) &&
  517. + ((rc = ValidateTarget(&pterm->pdataArgs[1], OBJTYPE_DATAOBJ, &pdata)) == STATUS_SUCCESS)) {
  518. + StrLen = 2;
  519. + Out->dwDataType = OBJTYPE_STRDATA;
  520. + switch (In->dwDataType) {
  521. + case OBJTYPE_INTDATA:
  522. + int32 = In->dwDataValue;
  523. + do {
  524. + int32 >>= 4;
  525. + ++StrLen;
  526. + } while (int32);
  527. +
  528. + Out->dwDataLen = StrLen + 1;
  529. + Out->pbDataBuff = (PUCHAR) NEWSDOBJ(gpheapGlobal, Out->dwDataLen);
  530. +
  531. + if (Out->pbDataBuff == NULL) {
  532. + rc = AMLI_LOGERR(AMLIERR_OUT_OF_MEM,
  533. + ("ToHexString: failed to allocate target buffer"));
  534. + } else {
  535. + Out->pbDataBuff[0] = '0';
  536. + Out->pbDataBuff[1] = 'x';
  537. + int32 = In->dwDataValue;
  538. + for (i = StrLen - 1; i >= 2; --i) {
  539. + Out->pbDataBuff[i] = HTOALookupTable[int32 & 0xF];
  540. + int32 >>= 4;
  541. + }
  542. +
  543. + Out->pbDataBuff[Out->dwDataLen - 1] = '\0'; // ending zero
  544. + rc = WriteObject(pctxt, pdata, pterm->pdataResult);
  545. + }
  546. + break;
  547. + case OBJTYPE_STRDATA:
  548. + Out->dwDataLen = In->dwDataLen;
  549. + Out->pbDataBuff = (PUCHAR) NEWSDOBJ(gpheapGlobal, Out->dwDataLen);
  550. +
  551. + if (Out->pbDataBuff == NULL) {
  552. + rc = AMLI_LOGERR(AMLIERR_OUT_OF_MEM,
  553. + ("ToHexString: failed to allocate target buffer"));
  554. + } else {
  555. + MEMCPY(Out->pbDataBuff, In->pbDataBuff, Out->dwDataLen);
  556. + rc = WriteObject(pctxt, pdata, pterm->pdataResult);
  557. + }
  558. + break;
  559. + case OBJTYPE_BUFFDATA:
  560. + Out->dwDataLen = 5 * In->dwDataLen;
  561. + Out->pbDataBuff = (PUCHAR) NEWSDOBJ(gpheapGlobal, Out->dwDataLen);
  562. +
  563. + if (Out->pbDataBuff == NULL) {
  564. + rc = AMLI_LOGERR(AMLIERR_OUT_OF_MEM,
  565. + ("ToHexString: failed to allocate target buffer"));
  566. + } else {
  567. + i = 0;
  568. + if (In->dwDataLen) {
  569. + for (SrcIdx = 0; SrcIdx < In->dwDataLen; SrcIdx++) {
  570. + Out->pbDataBuff[i] = '0';
  571. + Out->pbDataBuff[i+1] = 'x';
  572. + pair = In->pbDataBuff[SrcIdx];
  573. + Out->pbDataBuff[i+2] = HTOALookupTable[pair >> 4];
  574. + Out->pbDataBuff[i+3] = HTOALookupTable[pair & 0xF];
  575. + Out->pbDataBuff[i+4] = ',';
  576. + i += 5;
  577. + }
  578. + }
  579. +
  580. + Out->pbDataBuff[Out->dwDataLen - 1] = '\0'; // ending zero
  581. + rc = WriteObject(pctxt, pdata, pterm->pdataResult);
  582. + }
  583. + break;
  584. + default:
  585. + rc = AMLI_LOGERR(AMLIERR_FATAL,
  586. + ("ToHexString: invalid arg0 type"));
  587. + break;
  588. + }
  589. + }
  590. +
  591. + EXIT(2, ("ToHexString=%x (Result=%x)\n", rc, pterm->pdataResult));
  592. + return rc;
  593. +}
  594. +
  595. +
  596. +NTSTATUS LOCAL ConvertToBuffer(POBJDATA In, POBJDATA Out) {
  597. + OBJDATA data;
  598. + int Len;
  599. + int i;
  600. + ULONG int32;
  601. + NTSTATUS rc = STATUS_SUCCESS;
  602. +
  603. + MEMZERO(&data, sizeof(data));
  604. + data.dwDataType = OBJTYPE_BUFFDATA;
  605. + switch (In->dwDataType) {
  606. + case OBJTYPE_INTDATA:
  607. + int32 = In->dwDataValue;
  608. + Len = 4;
  609. +
  610. + data.dwDataLen = Len;
  611. + data.pbDataBuff = (PUCHAR) NEWSDOBJ(gpheapGlobal, Len);
  612. + if (data.pbDataBuff == NULL) {
  613. + rc = AMLIERR_OUT_OF_MEM;
  614. + } else {
  615. + for (i = 0; i < Len; i++) {
  616. + data.pbDataBuff[i] = (UCHAR) int32;
  617. + int32 >>= 8;
  618. + }
  619. +
  620. + FreeDataBuffs(Out, 1);
  621. + MEMCPY(Out, &data, sizeof(data));
  622. + }
  623. + break;
  624. + case OBJTYPE_STRDATA:
  625. + case OBJTYPE_BUFFDATA:
  626. + Len = In->dwDataLen;
  627. + data.dwDataLen = Len;
  628. +
  629. + data.pbDataBuff = (PUCHAR) NEWSDOBJ(gpheapGlobal, Len);
  630. + if (data.pbDataBuff == NULL) {
  631. + rc = AMLIERR_OUT_OF_MEM;
  632. + } else {
  633. + MEMCPY(data.pbDataBuff, In->pbDataBuff, Len);
  634. +
  635. + FreeDataBuffs(Out, 1);
  636. + MEMCPY(Out, &data, sizeof(data));
  637. + }
  638. + break;
  639. + default:
  640. + rc = AMLIERR_UNEXPECTED_OBJTYPE;
  641. + break;
  642. + }
  643. +
  644. + return rc;
  645. +}
  646. +
  647. +
  648. +NTSTATUS LOCAL ToBuffer(PCTXT pctxt, PTERM pterm)
  649. +{
  650. + NTSTATUS rc = STATUS_SUCCESS;
  651. + POBJDATA pdata;
  652. + TRACENAME("TOBUFFER")
  653. + ENTER(2, ("ToBuffer(pctxt=%x,pbOp=%x,pterm=%x)\n", pctxt, pctxt->pbOp, pterm));
  654. +
  655. + if (((rc = ValidateArgTypes(pterm->pdataArgs, "D")) == STATUS_SUCCESS) &&
  656. + ((rc = ValidateTarget(&pterm->pdataArgs[1], OBJTYPE_DATAOBJ, &pdata)) == STATUS_SUCCESS)) {
  657. + if ((rc = ConvertToBuffer(pterm->pdataArgs, pterm->pdataResult)) == STATUS_SUCCESS)
  658. + rc = WriteObject(pctxt, pdata, pterm->pdataResult);
  659. + }
  660. +
  661. + EXIT(2, ("ToBuffer=%x (Result=%x)\n", rc, pterm->pdataResult));
  662. + return rc;
  663. +}
  664. +
  665. +
  666. +NTSTATUS LOCAL ToDecimalString(PCTXT pctxt, PTERM pterm)
  667. +{
  668. + NTSTATUS rc = STATUS_SUCCESS;
  669. + POBJDATA pdata;
  670. + POBJDATA In = pterm->pdataArgs;
  671. + POBJDATA Out = pterm->pdataResult;
  672. + ULONG int32;
  673. + ULONG StrLen;
  674. + int SrcBufLen;
  675. + ULONG SrcIdx;
  676. + int i;
  677. + int j;
  678. + UCHAR number;
  679. + TRACENAME("TODECSTRING")
  680. + ENTER(2, ("ToDecimalString(pctxt=%x,pbOp=%x,pterm=%x)\n", pctxt, pctxt->pbOp, pterm));
  681. +
  682. + if (((rc = ValidateArgTypes(pterm->pdataArgs, "D")) == STATUS_SUCCESS) &&
  683. + ((rc = ValidateTarget(&pterm->pdataArgs[1], OBJTYPE_DATAOBJ, &pdata)) == STATUS_SUCCESS)) {
  684. + Out->dwDataType = OBJTYPE_STRDATA;
  685. + switch (In->dwDataType) {
  686. + case OBJTYPE_INTDATA:
  687. + int32 = In->dwDataValue;
  688. + StrLen = 0;
  689. + do {
  690. + int32 /= 10;
  691. + ++StrLen;
  692. + } while (int32);
  693. +
  694. + Out->dwDataLen = StrLen + 1;
  695. + Out->pbDataBuff = (PUCHAR) NEWSDOBJ(gpheapGlobal, Out->dwDataLen);
  696. +
  697. + if (Out->pbDataBuff == NULL) {
  698. + rc = AMLI_LOGERR(AMLIERR_OUT_OF_MEM,
  699. + ("ToDecimalString: failed to allocate target buffer"));
  700. + } else {
  701. + int32 = In->dwDataValue;
  702. + if (StrLen >= 1) {
  703. + for (i = StrLen - 1; i >= 0; --i) {
  704. + Out->pbDataBuff[i] = HTOALookupTable[int32 % 10];
  705. + int32 /= 10;
  706. + }
  707. + }
  708. +
  709. + Out->pbDataBuff[Out->dwDataLen - 1] = '\0'; // ending zero
  710. + rc = WriteObject(pctxt, pdata, pterm->pdataResult);
  711. + }
  712. + break;
  713. + case OBJTYPE_STRDATA:
  714. + Out->dwDataLen = In->dwDataLen;
  715. + Out->pbDataBuff = (PUCHAR) NEWSDOBJ(gpheapGlobal, Out->dwDataLen);
  716. +
  717. + if (Out->pbDataBuff == NULL) {
  718. + rc = AMLI_LOGERR(AMLIERR_OUT_OF_MEM,
  719. + ("ToDecimalString: failed to allocate target buffer"));
  720. + } else {
  721. + MEMCPY(Out->pbDataBuff, In->pbDataBuff, Out->dwDataLen);
  722. + rc = WriteObject(pctxt, pdata, pterm->pdataResult);
  723. + }
  724. + break;
  725. + case OBJTYPE_BUFFDATA:
  726. + SrcBufLen = In->dwDataLen;
  727. + StrLen = SrcBufLen - 1;
  728. + if (SrcBufLen) {
  729. + for (i = 0; i < SrcBufLen; i++) {
  730. + number = In->pbDataBuff[i];
  731. + if (number >= 10) {
  732. + if (number >= 100)
  733. + StrLen += 3;
  734. + else
  735. + StrLen += 2;
  736. + } else {
  737. + StrLen++;
  738. + }
  739. + }
  740. + }
  741. +
  742. + Out->dwDataLen = StrLen + 1;
  743. + Out->pbDataBuff = (PUCHAR) NEWSDOBJ(gpheapGlobal, Out->dwDataLen);
  744. +
  745. + if (Out->pbDataBuff == NULL) {
  746. + rc = AMLI_LOGERR(AMLIERR_OUT_OF_MEM,
  747. + ("ToDecimalString: failed to allocate target buffer"));
  748. + } else {
  749. + j = 0; // result buffer index
  750. + for ( SrcIdx = 0; SrcIdx < In->dwDataLen; SrcIdx++ ) {
  751. + number = In->pbDataBuff[SrcIdx];
  752. + if (number >= 10) {
  753. + if (number >= 100)
  754. + Out->pbDataBuff[j++] = HTOALookupTable[(number / 100) % 10]; // 2xx
  755. +
  756. + Out->pbDataBuff[j++] = HTOALookupTable[(number / 10) % 10]; // x2x
  757. + Out->pbDataBuff[j++] = HTOALookupTable[number % 10]; // xx2
  758. + } else {
  759. + Out->pbDataBuff[j++] = HTOALookupTable[number];
  760. + }
  761. + Out->pbDataBuff[j++] = ',';
  762. + }
  763. +
  764. + Out->pbDataBuff[Out->dwDataLen - 1] = '\0'; // ending zero
  765. + rc = WriteObject(pctxt, pdata, pterm->pdataResult);
  766. + }
  767. + break;
  768. + default:
  769. + rc = AMLI_LOGERR(AMLIERR_FATAL,
  770. + ("ToDecimalString: invalid arg0 type"));
  771. + break;
  772. + }
  773. + }
  774. +
  775. + EXIT(2, ("ToDecimalString=%x (Result=%x)\n", rc, pterm->pdataResult));
  776. + return rc;
  777. +}
  778. +
  779. +
  780. +NTSTATUS LOCAL CreateQWordField(PCTXT pctxt, PTERM pterm)
  781. +{
  782. + TRACENAME("CREATEQWORDFIELD")
  783. + NTSTATUS rc = STATUS_SUCCESS;
  784. + PBUFFFIELDOBJ pbf;
  785. + ENTER(2, ("CreateQWordField(pctxt=%x,pbOp=%x,pterm=%x)\n",
  786. + pctxt, pctxt->pbOp, pterm));
  787. +
  788. + if ((rc = CreateXField(pctxt, pterm, &pterm->pdataArgs[2], &pbf)) ==
  789. + STATUS_SUCCESS)
  790. + {
  791. + pbf->FieldDesc.dwByteOffset = (ULONG)pterm->pdataArgs[1].uipDataValue;
  792. + pbf->FieldDesc.dwStartBitPos = 0;
  793. + pbf->FieldDesc.dwNumBits = 8*sizeof(ULONG); // 8*sizeof(ULONG64) ACPI 2.0
  794. + pbf->FieldDesc.dwFieldFlags = ACCTYPE_DWORD; // ACCTYPE_QWORD ACPI 2.0
  795. + }
  796. +
  797. + EXIT(2, ("CreateQWordField=%x (pnsObj=%x)\n", rc, pterm->pnsObj));
  798. + return rc;
  799. +}
  800. +
  801. +
  802. +UCHAR LOCAL ComputeDataChkSum(UCHAR *Buffer, int Len) {
  803. + UCHAR checksum = 0;
  804. +
  805. + for ( ; Len; --Len ) {
  806. + checksum += *Buffer;
  807. + Buffer++;
  808. + }
  809. +
  810. + return -(checksum);
  811. +}
  812. +
  813. +
  814. +NTSTATUS LOCAL ConcatenateResTemplate(PCTXT pctxt, PTERM pterm)
  815. +{
  816. + NTSTATUS rc = STATUS_SUCCESS;
  817. + POBJDATA pdata;
  818. + POBJDATA In = pterm->pdataArgs;
  819. + POBJDATA Out = pterm->pdataResult;
  820. + ULONG i,j;
  821. + ULONG NewLength;
  822. + TRACENAME("CONCATENATERESTEMPLATE")
  823. + ENTER(2, ("ConcatenateResTemplate(pctxt=%x,pbOp=%x,pterm=%x)\n", pctxt, pctxt->pbOp, pterm));
  824. +
  825. + if (((rc = ValidateArgTypes(pterm->pdataArgs, "BB")) == STATUS_SUCCESS) &&
  826. + ((rc = ValidateTarget(&pterm->pdataArgs[2], OBJTYPE_DATAOBJ, &pdata)) == STATUS_SUCCESS)) {
  827. + if (In[0].dwDataLen <= 1 || In[1].dwDataLen <= 1 ) {
  828. + rc = AMLI_LOGERR(AMLIERR_FATAL,
  829. + ("ConcatenateResTemplate: arg0 or arg1 has length <= 1"));
  830. + } else {
  831. + Out->dwDataType = OBJTYPE_BUFFDATA;
  832. + NewLength = In[0].dwDataLen + In[1].dwDataLen - 2;
  833. + Out->dwDataLen = NewLength;
  834. +
  835. + Out->pbDataBuff = (PUCHAR) NEWSDOBJ(gpheapGlobal, NewLength);
  836. + if (Out->pbDataBuff == NULL) {
  837. + rc = AMLI_LOGERR(AMLIERR_OUT_OF_MEM,
  838. + ("ConcatenateResTemplate: failed to allocate target buffer"));
  839. + } else {
  840. + j = 0;
  841. +
  842. + i = 0;
  843. + if (In[0].dwDataLen != 2) {
  844. + do {
  845. + Out->pbDataBuff[j++] = In[0].pbDataBuff[i++];
  846. + } while (i < In[0].dwDataLen - 2);
  847. + }
  848. +
  849. + i = 0;
  850. + if (In[1].dwDataLen != 2) {
  851. + do {
  852. + Out->pbDataBuff[j++] = In[1].pbDataBuff[i++];
  853. + } while (i < In[1].dwDataLen - 2);
  854. + }
  855. +
  856. + Out->pbDataBuff[j++] = 0x79; //EndTag
  857. + Out->pbDataBuff[j] = ComputeDataChkSum(Out->pbDataBuff, NewLength - 1);
  858. + rc = WriteObject(pctxt, pdata, pterm->pdataResult);
  859. + }
  860. +
  861. + }
  862. + }
  863. +
  864. + EXIT(2, ("ConcatenateResTemplate=%x (Result=%x)\n", rc, pterm->pdataResult));
  865. + return rc;
  866. +}
  867. +
  868. +
  869. +size_t LOCAL strnlen(const char *Str, size_t MaxCount)
  870. +{
  871. + size_t result;
  872. +
  873. + for (result = 0; result < MaxCount; ++Str) {
  874. + if (!*Str)
  875. + break;
  876. +
  877. + result++;
  878. + }
  879. + return result;
  880. +}
  881. +
  882. +
  883. +#define STRSAFE_MAX_CCH 2147483647
  884. +
  885. +// ntstrsafe.c
  886. +NTSTATUS RtlStringVPrintfWorkerA(char* pszDest, size_t cchDest, const char* pszFormat, va_list argList)
  887. +{
  888. + NTSTATUS status = STATUS_SUCCESS;
  889. +
  890. + if (cchDest == 0)
  891. + {
  892. + // can not null terminate a zero-byte dest buffer
  893. + status = STATUS_INVALID_PARAMETER;
  894. + }
  895. + else
  896. + {
  897. + int iRet;
  898. + size_t cchMax;
  899. +
  900. + // leave the last space for the null terminator
  901. + cchMax = cchDest - 1;
  902. +
  903. + iRet = _vsnprintf(pszDest, cchMax, pszFormat, argList);
  904. +
  905. + if ((iRet < 0) || (((size_t)iRet) > cchMax))
  906. + {
  907. + // need to null terminate the string
  908. + pszDest += cchMax;
  909. + *pszDest = '\0';
  910. +
  911. + // we have truncated pszDest
  912. + status = STATUS_BUFFER_OVERFLOW;
  913. + }
  914. + else if (((size_t)iRet) == cchMax)
  915. + {
  916. + // need to null terminate the string
  917. + pszDest += cchMax;
  918. + *pszDest = '\0';
  919. + }
  920. + }
  921. +
  922. + return status;
  923. +}
  924. +
  925. +
  926. +// ntstrsafe.c
  927. +NTSTATUS RtlStringCchPrintfA(char* pszDest, size_t cchDest, const char* pszFormat, ...)
  928. +{
  929. + NTSTATUS status;
  930. +
  931. + if (cchDest > STRSAFE_MAX_CCH)
  932. + {
  933. + status = STATUS_INVALID_PARAMETER;
  934. + }
  935. + else
  936. + {
  937. + va_list argList;
  938. +
  939. + va_start(argList, pszFormat);
  940. +
  941. + status = RtlStringVPrintfWorkerA(pszDest, cchDest, pszFormat, argList);
  942. +
  943. + va_end(argList);
  944. + }
  945. +
  946. + return status;
  947. +}
  948. +
  949. +
  950. +NTSTATUS LOCAL ConvertToString(POBJDATA In, ULONG MaxLen, POBJDATA Out)
  951. +{
  952. + NTSTATUS rc = STATUS_SUCCESS;
  953. + ULONG StrLen = MaxLen;
  954. + char TmpBuf[9]; // 17 ACPI 2.0
  955. + OBJDATA data;
  956. + ULONG BufLen;
  957. + ULONG InStrLen;
  958. +
  959. + MEMZERO(&TmpBuf, sizeof(TmpBuf));
  960. + MEMZERO(&data, sizeof(data));
  961. + data.dwDataType = OBJTYPE_STRDATA;
  962. +
  963. + switch (In->dwDataType) {
  964. + case OBJTYPE_INTDATA:
  965. + BufLen = 9;
  966. + RtlStringCchPrintfA(TmpBuf, 9, "%x", In->dwDataValue);
  967. + if (!MaxLen || MaxLen >= BufLen)
  968. + StrLen = strnlen(TmpBuf, BufLen);
  969. + data.dwDataLen = StrLen + 1;
  970. +
  971. + data.pbDataBuff = (PUCHAR) NEWSDOBJ(gpheapGlobal, data.dwDataLen);
  972. + if (data.pbDataBuff == NULL) {
  973. + rc = STATUS_INSUFFICIENT_RESOURCES;
  974. + } else {
  975. + MEMCPY(data.pbDataBuff, TmpBuf, data.dwDataLen);
  976. + data.pbDataBuff[data.dwDataLen - 1] = '\0'; // ending zero
  977. + FreeDataBuffs(Out, 1);
  978. + MEMCPY(Out, &data, sizeof(data));
  979. + }
  980. + break;
  981. + case OBJTYPE_STRDATA:
  982. + if (MaxLen > In->dwDataLen - 1)
  983. + rc = STATUS_ACPI_FATAL;
  984. + else {
  985. + if (!MaxLen)
  986. + StrLen = In->dwDataLen - 1;
  987. + data.dwDataLen = StrLen + 1;
  988. +
  989. + data.pbDataBuff = (PUCHAR) NEWSDOBJ(gpheapGlobal, data.dwDataLen);
  990. + if (data.pbDataBuff == NULL) {
  991. + rc = STATUS_INSUFFICIENT_RESOURCES;
  992. + } else {
  993. + MEMCPY(data.pbDataBuff, In->pbDataBuff, data.dwDataLen);
  994. + data.pbDataBuff[data.dwDataLen - 1] = '\0'; // ending zero
  995. + FreeDataBuffs(Out, 1);
  996. + MEMCPY(Out, &data, sizeof(data));
  997. + }
  998. + }
  999. + break;
  1000. + case OBJTYPE_BUFFDATA:
  1001. + InStrLen = In->dwDataLen;
  1002. + if (InStrLen >= 201)
  1003. + InStrLen = 201;
  1004. + if (!MaxLen) {
  1005. + StrLen = strnlen((PCHAR)In->pbDataBuff, InStrLen);
  1006. + if (StrLen == InStrLen)
  1007. + return STATUS_INVALID_BUFFER_SIZE;
  1008. + } else {
  1009. + if (MaxLen > InStrLen || MaxLen > 200)
  1010. + return STATUS_ACPI_FATAL;
  1011. + }
  1012. +
  1013. + data.dwDataLen = StrLen + 1;
  1014. + data.pbDataBuff = (PUCHAR) NEWSDOBJ(gpheapGlobal, data.dwDataLen);
  1015. + if (data.pbDataBuff == NULL) {
  1016. + rc = STATUS_INSUFFICIENT_RESOURCES;
  1017. + } else {
  1018. + MEMCPY(data.pbDataBuff, In->pbDataBuff, data.dwDataLen - 1);
  1019. + data.pbDataBuff[data.dwDataLen - 1] = '\0'; // ending zero
  1020. + FreeDataBuffs(Out, 1);
  1021. + MEMCPY(Out, &data, sizeof(data));
  1022. + }
  1023. + break;
  1024. + default:
  1025. + rc = STATUS_ACPI_INVALID_OBJTYPE;
  1026. + }
  1027. +
  1028. + return rc;
  1029. +}
  1030. +
  1031. +
  1032. +NTSTATUS LOCAL ToString(PCTXT pctxt, PTERM pterm)
  1033. +{
  1034. + NTSTATUS rc = STATUS_SUCCESS;
  1035. + POBJDATA pdata;
  1036. + ULONG MaxLen;
  1037. + TRACENAME("TOSTRING")
  1038. + ENTER(2, ("ToString(pctxt=%x,pbOp=%x,pterm=%x)\n", pctxt, pctxt->pbOp, pterm));
  1039. +
  1040. + if ( pterm->icArgs == 2 &&
  1041. + ((rc = ValidateArgTypes(pterm->pdataArgs, "B")) == STATUS_SUCCESS) &&
  1042. + ((rc = ValidateTarget(&pterm->pdataArgs[1], OBJTYPE_DATA, &pdata)) == STATUS_SUCCESS) ) {
  1043. + rc = ConvertToString(pterm->pdataArgs, 0, pterm->pdataResult);
  1044. +
  1045. + switch (rc) {
  1046. + case STATUS_INSUFFICIENT_RESOURCES:
  1047. + rc = AMLI_LOGERR(AMLIERR_OUT_OF_MEM,
  1048. + ("ToString: failed to allocate target buffer"));
  1049. + break;
  1050. + case STATUS_INVALID_BUFFER_SIZE:
  1051. + rc = AMLI_LOGERR(AMLIERR_FATAL,
  1052. + ("ToString: buffer length exceeds maximum value"));
  1053. + break;
  1054. + case STATUS_ACPI_FATAL:
  1055. + rc = AMLI_LOGERR(AMLIERR_FATAL,
  1056. + ("ToString: length specified exceeds input buffer length or maximum value"));
  1057. + break;
  1058. + }
  1059. + } else
  1060. + if ( pterm->icArgs == 3 &&
  1061. + ((rc = ValidateArgTypes(pterm->pdataArgs, "BI")) == STATUS_SUCCESS) &&
  1062. + ((rc = ValidateTarget(&pterm->pdataArgs[2], OBJTYPE_DATA, &pdata)) == STATUS_SUCCESS) ) {
  1063. + MaxLen = pterm->pdataArgs[1].dwDataValue;
  1064. + if (MaxLen != 0 &&
  1065. + MaxLen != 0xFFFFFFFF) {
  1066. + rc = ConvertToString(pterm->pdataArgs, MaxLen, pterm->pdataResult);
  1067. + } else {
  1068. + rc = ConvertToString(pterm->pdataArgs, 0, pterm->pdataResult);
  1069. + }
  1070. +
  1071. + switch (rc) {
  1072. + case STATUS_INSUFFICIENT_RESOURCES:
  1073. + rc = AMLI_LOGERR(AMLIERR_OUT_OF_MEM,
  1074. + ("ToString: failed to allocate target buffer"));
  1075. + break;
  1076. + case STATUS_INVALID_BUFFER_SIZE:
  1077. + rc = AMLI_LOGERR(AMLIERR_FATAL,
  1078. + ("ToString: buffer length exceeds maximum value"));
  1079. + break;
  1080. + case STATUS_ACPI_FATAL:
  1081. + rc = AMLI_LOGERR(AMLIERR_FATAL,
  1082. + ("ToString: length specified exceeds input buffer length or maximum value"));
  1083. + break;
  1084. + }
  1085. + } else {
  1086. + rc = AMLI_LOGERR(AMLIERR_FATAL,
  1087. + ("ToString: invalid # of arguments: %x", pterm->icArgs));
  1088. + }
  1089. +
  1090. + EXIT(2, ("ToString=%x (Result=%x)\n", rc, pterm->pdataResult));
  1091. + return rc;
  1092. +}
  1093. +
  1094. +
  1095. +NTSTATUS LOCAL CopyObject(PCTXT pctxt, PTERM pterm)
  1096. +{
  1097. + NTSTATUS rc = STATUS_SUCCESS;
  1098. + POBJDATA In = pterm->pdataArgs;
  1099. + POBJDATA Out = pterm->pdataResult;
  1100. + POBJDATA pdata;
  1101. + BOOLEAN bWrite;
  1102. + TRACENAME("COPYOBJECT")
  1103. + ENTER(2, ("CopyObject(pctxt=%x,pbOp=%x,pterm=%x)\n", pctxt, pctxt->pbOp, pterm));
  1104. +
  1105. + bWrite = FALSE;
  1106. + rc = ValidateTarget(&pterm->pdataArgs[1], 0, &pdata);
  1107. + if (rc) {
  1108. + rc = AMLI_LOGERR(AMLIERR_OUT_OF_MEM,
  1109. + ("CopyObject: failed because target object is not a supername"));
  1110. + } else {
  1111. + if (MatchObjType(pdata->dwDataType, OBJTYPE_DATAFIELD)) {
  1112. + if (In->dwDataType != OBJTYPE_INTDATA &&
  1113. + In->dwDataType != OBJTYPE_BUFFDATA)
  1114. + {
  1115. + rc = AMLI_LOGERR(AMLIERR_FATAL,
  1116. + ("CopyObject: Only Integer and Buffer data can be copied to a Field unit or Buffer Field"));
  1117. + goto Exit;
  1118. + }
  1119. + bWrite = TRUE;
  1120. + }
  1121. +
  1122. + MoveObjData(Out, In);
  1123. + if (bWrite)
  1124. + rc = WriteObject(pctxt, pdata, Out);
  1125. + else
  1126. + rc = DupObjData(gpheapGlobal, pdata, Out);
  1127. +
  1128. + if (rc) {
  1129. + AMLI_LOGERR(rc,
  1130. + ("CopyObject: failed to duplicate objdata"));
  1131. + }
  1132. + }
  1133. +
  1134. +Exit:
  1135. + EXIT(2, ("CopyObject=%x (type=%s,value=%I64x,buff=%x,len=%x)\n",
  1136. + rc,
  1137. + GetObjectTypeName(In->dwDataType),
  1138. + In->dwDataValue,
  1139. + In->pbDataBuff,
  1140. + In->dwDataLen));
  1141. + return rc;
  1142. +}
  1143. +
  1144. +
  1145. +NTSTATUS LOCAL MidString(PCTXT pctxt, PTERM pterm)
  1146. +{
  1147. + NTSTATUS rc = STATUS_SUCCESS;
  1148. + POBJDATA In = pterm->pdataArgs;
  1149. + POBJDATA Out = pterm->pdataResult;
  1150. + POBJDATA pdata;
  1151. + ULONG DataLen, NewLength;
  1152. + ULONG MidIndex, MidSize;
  1153. + ULONG i,j;
  1154. + TRACENAME("MID")
  1155. + ENTER(2, ("MidString(pctxt=%x,pbOp=%x,pterm=%x)\n", pctxt, pctxt->pbOp, pterm));
  1156. +
  1157. + if (((rc = ValidateArgTypes(pterm->pdataArgs, "TII")) == STATUS_SUCCESS) &&
  1158. + ((rc = ValidateTarget(&pterm->pdataArgs[3], OBJTYPE_DATAOBJ, &pdata)) == STATUS_SUCCESS)) {
  1159. + if (In->dwDataType > OBJTYPE_BUFFDATA) {
  1160. + rc = AMLI_LOGERR(AMLIERR_FATAL,
  1161. + ("Mid: invalid arg0 type"));
  1162. + } else {
  1163. + Out->dwDataType = In->dwDataType;
  1164. + DataLen = In->dwDataLen;
  1165. + MidIndex = In[1].dwDataValue;
  1166. + MidSize = In[2].dwDataValue;
  1167. + if (MidIndex < DataLen) {
  1168. + NewLength = MidSize;
  1169. +
  1170. + if (Out->dwDataType == OBJTYPE_STRDATA) {
  1171. + DataLen--; // exclude ending zero
  1172. + if ((MidIndex + MidSize) > DataLen)
  1173. + NewLength = DataLen - MidIndex;
  1174. +
  1175. + Out->pbDataBuff = (PUCHAR) NEWSDOBJ(gpheapGlobal, NewLength + 1);
  1176. + if (Out->pbDataBuff == NULL) {
  1177. + rc = AMLI_LOGERR(AMLIERR_OUT_OF_MEM,
  1178. + ("Mid: failed to allocate target string"));
  1179. + } else {
  1180. + Out->dwDataLen = NewLength + 1;
  1181. + Out->pbDataBuff[Out->dwDataLen - 1] = '\0'; // ending zero
  1182. + }
  1183. + } else {
  1184. + if ( Out->dwDataType != OBJTYPE_BUFFDATA ) {
  1185. + rc = AMLI_LOGERR(AMLIERR_OUT_OF_MEM,
  1186. + ("Mid: pterm->pdataResult->dwDataType != OBJTYPE_BUFFDATA"));
  1187. + } else {
  1188. + if ((MidIndex + MidSize) > DataLen)
  1189. + NewLength = DataLen - MidIndex;
  1190. +
  1191. + Out->pbDataBuff = (PUCHAR) NEWSDOBJ(gpheapGlobal, NewLength);
  1192. + if (Out->pbDataBuff == NULL) {
  1193. + rc = AMLI_LOGERR(AMLIERR_OUT_OF_MEM,
  1194. + ("Mid: failed to allocate target string"));
  1195. + } else {
  1196. + Out->dwDataLen = NewLength;
  1197. + }
  1198. + }
  1199. + }
  1200. +
  1201. + if (!rc) {
  1202. + i = MidIndex;
  1203. + j = 0;
  1204. + if (NewLength) {
  1205. + do {
  1206. + Out->pbDataBuff[j++] = In->pbDataBuff[i++];
  1207. + } while (j < NewLength);
  1208. + }
  1209. +
  1210. + rc = WriteObject(pctxt, pdata, pterm->pdataResult);
  1211. + }
  1212. + } else { // MidIndex >= DataLen, set len = 0
  1213. + if (In->dwDataType == OBJTYPE_STRDATA) {
  1214. + Out->pbDataBuff = (PUCHAR) NEWSDOBJ(gpheapGlobal, 1);
  1215. + if (Out->pbDataBuff == NULL) {
  1216. + rc = AMLI_LOGERR(AMLIERR_OUT_OF_MEM,
  1217. + ("Mid: failed to allocate target string"));
  1218. + } else {
  1219. + Out->pbDataBuff[0] = '\0'; // ending zero
  1220. + Out->dwDataLen = 1;
  1221. +
  1222. + rc = WriteObject(pctxt, pdata, pterm->pdataResult);
  1223. + }
  1224. + }
  1225. + }
  1226. + }
  1227. + }
  1228. +
  1229. + EXIT(2, ("MidString=%x (Result=%x)\n", rc, pterm->pdataResult));
  1230. + return rc;
  1231. +}
  1232. +
  1233. +
  1234. +NTSTATUS LOCAL Continue(PCTXT pctxt, PTERM pterm)
  1235. +{
  1236. + TRACENAME("CONTINUE")
  1237. + ENTER(2, ("Continue(pctxt=%x,pbOp=%x,pterm=%x)\n", pctxt, pctxt->pbOp, pterm));
  1238. +
  1239. + ;
  1240. +
  1241. + EXIT(2, ("Continue=%x\n", AMLISTA_CONTINUEOP));
  1242. + return AMLISTA_CONTINUEOP;
  1243. +}
  1244. +
  1245. +
  1246. +NTSTATUS LOCAL Timer(PCTXT pctxt, PTERM pterm)
  1247. +{
  1248. + TRACENAME("TIMER")
  1249. + ENTER(2, ("Timer(pctxt=%x,pbOp=%x,pterm=%x, Querying for %s)\n",
  1250. + pctxt,
  1251. + pctxt->pbOp,
  1252. + pterm,
  1253. + pterm->pdataArgs->pbDataBuff));
  1254. +
  1255. + pterm->pdataResult->dwDataType = 1;
  1256. + pterm->pdataResult->dwDataValue = (ULONG)KeQueryInterruptTime();
  1257. +
  1258. + EXIT(2, ("Timer=%x (pnsObj=%x)\n", 0, pterm->pnsObj));
  1259. + return AMLIERR_NONE;
  1260. +}
  1261. +
  1262. +
  1263. + /*
  1264. + __asm {
  1265. + L1: jmp L1
  1266. + }
  1267. + */
  1268. +
  1269. +
  1270. +// ACPI 2.0
  1271. +///////////////////////////////////////////////
  1272. \ No newline at end of file
  1273. diff --strip-trailing-cr -ur ./driver/inc/aml.h "c:\\ACPI\\ACPI_SP1\\Base\\busdrv\\acpi/driver/inc/aml.h"
  1274. --- ./driver/inc/aml.h 2002-09-02 18:22:22.000000000 +0500
  1275. +++ "c:\\ACPI\\ACPI_SP1\\Base\\busdrv\\acpi/driver/inc/aml.h" 2022-04-16 06:47:51.964843700 +0500
  1276. @@ -90,6 +90,23 @@
  1277. #define OP_LEQ 0x93
  1278. #define OP_LG 0x94
  1279. #define OP_LL 0x95
  1280. +
  1281. +// Win7 ACPI 2.0
  1282. +#define OP_QWORD 0x0e
  1283. +#define OP_CONCATRESTMPL 0x84
  1284. +#define OP_MOD 0x85
  1285. +#define OP_QWORDFIELD 0x8f
  1286. +#define OP_TOBUFFER 0x96
  1287. +#define OP_TODECSTRING 0x97
  1288. +#define OP_TOHEXSTRING 0x98
  1289. +#define OP_TOINTEGER 0x99
  1290. +#define OP_TOSTRING 0x9c
  1291. +#define OP_COPYOBJECT 0x9d
  1292. +#define OP_MID 0x9e
  1293. +#define OP_CONTINUE 0x9f
  1294. +#define EXOP_TIMER 0x33
  1295. +#define OP_TIMER EXOP(EXOP_TIMER) // 5B33
  1296. +
  1297. #define OP_IF 0xa0
  1298. #define OP_ELSE 0xa1
  1299. #define OP_WHILE 0xa2
  1300. @@ -173,12 +190,12 @@
  1301. #define UPDATERULE_WRITEASZEROS 0x40 //WriteAsZeros
  1302. #define ACCATTRIB_MASK 0xff00
  1303.  
  1304. +
  1305. //
  1306. -// Returns 1, 2 or 4 for BYTE, WORD or DWORD respectively and returns 1 for
  1307. -// any other sizes.
  1308. -//
  1309. +// Returns 1, 2 or 4 for BYTE, WORD or DWORD respectively and returns 1 for any other sizes.
  1310. +// ACPI 2.0: return 8 for QWORD
  1311. #define ACCSIZE(f) (((((f) & ACCTYPE_MASK) >= ACCTYPE_BYTE) && \
  1312. - (((f) & ACCTYPE_MASK) <= ACCTYPE_DWORD))? \
  1313. + (((f) & ACCTYPE_MASK) <= ACCTYPE_QWORD))? \
  1314. (1 << (((f) & ACCTYPE_MASK) - 1)): 1)
  1315.  
  1316. /*** Operation region space
  1317. diff --strip-trailing-cr -ur ./driver/nt/acpiosnt.rc "c:\\ACPI\\ACPI_SP1\\Base\\busdrv\\acpi/driver/nt/acpiosnt.rc"
  1318. --- ./driver/nt/acpiosnt.rc 2002-09-02 18:22:22.000000000 +0500
  1319. +++ "c:\\ACPI\\ACPI_SP1\\Base\\busdrv\\acpi/driver/nt/acpiosnt.rc" 2022-04-16 06:47:51.973632800 +0500
  1320. @@ -1,9 +1,12 @@
  1321. #include <windows.h>
  1322. #include <ntverp.h>
  1323.  
  1324. +#define VER_FILEVERSION 5,1,2600,7777
  1325. +#define VER_FILEVERSION_STR "5,1,2600,7777"
  1326. +
  1327. #define VER_FILETYPE VFT_DRV
  1328. #define VER_FILESUBTYPE VFT2_DRV_SYSTEM
  1329. -#define VER_FILEDESCRIPTION_STR "ACPI Driver for NT"
  1330. +#define VER_FILEDESCRIPTION_STR "ACPI 2.0 Driver for NT"
  1331. #define VER_INTERNALNAME_STR "ACPI.sys"
  1332. #define VER_ORIGINALFILENAME_STR "ACPI.sys"
  1333.  
  1334. diff --strip-trailing-cr -ur ./driver/nt/buildsrc.c "c:\\ACPI\\ACPI_SP1\\Base\\busdrv\\acpi/driver/nt/buildsrc.c"
  1335. --- ./driver/nt/buildsrc.c 2002-09-02 18:22:22.000000000 +0500
  1336. +++ "c:\\ACPI\\ACPI_SP1\\Base\\busdrv\\acpi/driver/nt/buildsrc.c" 2022-04-14 04:20:49.132812500 +0500
  1337. @@ -399,7 +399,7 @@
  1338. {
  1339. PACPI_BUILD_REQUEST buildRequest = (PACPI_BUILD_REQUEST) Context;
  1340. ULONG nextWorkDone = buildRequest->NextWorkDone;
  1341. -
  1342. + ULONG ParentName;
  1343. //
  1344. // Device what state we should transition to next
  1345. //
  1346. @@ -413,10 +413,12 @@
  1347. //
  1348. // Death
  1349. //
  1350. +
  1351. + ParentName = AcpiObject ? (AcpiObject->pnsParent ? AcpiObject->pnsParent->dwNameSeg : 0) : 0 ;
  1352. KeBugCheckEx(
  1353. ACPI_BIOS_ERROR,
  1354. ACPI_FAILED_MUST_SUCCEED_METHOD,
  1355. - (ULONG_PTR) AcpiObject,
  1356. + (ULONG_PTR) ParentName,
  1357. Status,
  1358. (AcpiObject ? AcpiObject->dwNameSeg : 0)
  1359. );
  1360. diff --strip-trailing-cr -ur ./driver/nt/debug.c "c:\\ACPI\\ACPI_SP1\\Base\\busdrv\\acpi/driver/nt/debug.c"
  1361. --- ./driver/nt/debug.c 2002-09-02 18:22:24.000000000 +0500
  1362. +++ "c:\\ACPI\\ACPI_SP1\\Base\\busdrv\\acpi/driver/nt/debug.c" 2022-04-16 06:47:51.983398400 +0500
  1363. @@ -80,6 +80,18 @@
  1364. {
  1365. KeBugCheckEx (ACPI_DRIVER_INTERNAL, 0x1, Bugcode, 0, 0);
  1366. }
  1367. +
  1368. +// SP3
  1369. +VOID
  1370. +_ACPIInternalErrorEx(
  1371. + IN ULONG Bugcode0,
  1372. + IN ULONG_PTR Bugcode1,
  1373. + IN ULONG_PTR Bugcode2
  1374. + )
  1375. +{
  1376. + KeBugCheckEx (ACPI_DRIVER_INTERNAL, 0x2, Bugcode0, Bugcode1, Bugcode2);
  1377. +}
  1378. +// SP3
  1379. #if DBG
  1380. VOID
  1381. diff --strip-trailing-cr -ur ./driver/nt/debug.h "c:\\ACPI\\ACPI_SP1\\Base\\busdrv\\acpi/driver/nt/debug.h"
  1382. --- ./driver/nt/debug.h 2002-09-02 18:22:24.000000000 +0500
  1383. +++ "c:\\ACPI\\ACPI_SP1\\Base\\busdrv\\acpi/driver/nt/debug.h" 2022-04-16 06:47:51.993164000 +0500
  1384. @@ -53,6 +53,15 @@
  1385. IN ULONG Bugcode
  1386. );
  1387.  
  1388. + // SP3
  1389. + VOID
  1390. + _ACPIInternalErrorEx(
  1391. + IN ULONG Bugcode0,
  1392. + IN ULONG_PTR Bugcode1,
  1393. + IN ULONG_PTR Bugcode2
  1394. + );
  1395. + // SP3
  1396. +
  1397. #if DBG
  1398. VOID
  1399. ACPIDebugResourceDescriptor(
  1400. diff --strip-trailing-cr -ur ./driver/nt/devpower.c "c:\\ACPI\\ACPI_SP1\\Base\\busdrv\\acpi/driver/nt/devpower.c"
  1401. --- ./driver/nt/devpower.c 2002-09-02 18:22:24.000000000 +0500
  1402. +++ "c:\\ACPI\\ACPI_SP1\\Base\\busdrv\\acpi/driver/nt/devpower.c" 2022-04-16 06:47:52.005859300 +0500
  1403. @@ -4712,7 +4712,7 @@
  1404. } // ACPIDevicePowerProcessPhase2SystemSubPhase3
  1405. NTSTATUS
  1406. -ACPIDevicePowerProcessPhase3(
  1407. +ACPIDevicePowerProcessPhase3_SP1(
  1408. VOID
  1409. )
  1410. /*++
  1411. @@ -5058,6 +5058,215 @@
  1412. return (returnPending ? STATUS_PENDING : STATUS_SUCCESS);
  1413.  
  1414. } // ACPIPowerProcessPhase3
  1415. +
  1416. +
  1417. +#ifdef _X86_
  1418. +// SP3
  1419. +__declspec(naked) NTSTATUS
  1420. +ACPIDevicePowerProcessPhase3(
  1421. + VOID
  1422. + )
  1423. +{
  1424. + __asm {
  1425. + mov edi, edi
  1426. + push ebp
  1427. + mov ebp, esp
  1428. + sub esp, 18h
  1429. + push ebx
  1430. + push esi
  1431. + mov ebx, offset AcpiPowerLock
  1432. + push edi
  1433. + mov ecx, ebx
  1434. + mov byte ptr [ebp-1], 0
  1435. + call dword ptr [KefAcquireSpinLockAtDpcLevel]
  1436. + mov esi, dword ptr [AcpiPowerNodeList+0] ;Flink
  1437. + mov eax, offset AcpiPowerNodeList
  1438. + cmp esi, eax
  1439. + jz loc_1535A
  1440. + jmp short loc_15250
  1441. +loc_1524D:
  1442. + mov esi, [ebp-0Ch]
  1443. +loc_15250:
  1444. + mov eax, [esi]
  1445. + mov [ebp-0Ch], eax
  1446. + mov eax, [esi+8]
  1447. + and eax, 2
  1448. + xor ecx, ecx
  1449. + or eax, ecx
  1450. + jz loc_1534C
  1451. + push 3
  1452. + push 4
  1453. + lea ecx, [esi+28h]
  1454. + pop edx
  1455. + call dword ptr [InterlockedCompareExchange]
  1456. + cmp eax, 3
  1457. + jnz loc_1534C
  1458. + and dword ptr [ebp-8], 0
  1459. + lea eax, [esi+20h]
  1460. + mov edi, [eax]
  1461. + jmp short loc_152C6
  1462. +loc_15287:
  1463. + lea eax, [edi-18h]
  1464. + mov edi, [edi]
  1465. + mov [ebp-14h], eax
  1466. + mov eax, [eax+14h]
  1467. + push 0
  1468. + lea ecx, [eax+0F0h]
  1469. + xor edx, edx
  1470. + mov [ebp-10h], eax
  1471. + call dword ptr [InterlockedCompareExchange]
  1472. + mov ecx, [ebp-10h]
  1473. + mov edx, [ecx+0ECh]
  1474. + mov ecx, [ebp-14h]
  1475. + cmp edx, [ecx+0Ch]
  1476. + jz short loc_152C0
  1477. + test eax, eax
  1478. + jz short loc_152C3
  1479. + cmp byte ptr [ecx+10h], 0
  1480. + jz short loc_152C3
  1481. +
  1482. +loc_152C0:
  1483. + inc dword ptr [ebp-8]
  1484. +
  1485. +loc_152C3:
  1486. + lea eax, [esi+20h]
  1487. +
  1488. +loc_152C6:
  1489. + cmp edi, eax
  1490. + jnz short loc_15287
  1491. + mov edx, [ebp-8]
  1492. + lea ecx, [esi+10h]
  1493. + call dword ptr [InterlockedExchange]
  1494. + mov eax, [esi+0Ch]
  1495. + mov ecx, [esi+8]
  1496. + mov [ebp-14h], eax
  1497. + mov eax, ecx
  1498. + and eax, 440h
  1499. + xor edx, edx
  1500. + or eax, edx
  1501. + jnz short loc_1534C
  1502. + and ecx, 220h
  1503. + xor eax, eax
  1504. + xor edi, edi
  1505. + or ecx, eax
  1506. + jnz short loc_152FF
  1507. + cmp [ebp-8], edi
  1508. + jz short loc_1534C
  1509. +
  1510. +loc_152FF:
  1511. + xor edx, edx
  1512. + push 4
  1513. + inc edx
  1514. + lea ecx, [esi+28h]
  1515. + call dword ptr [InterlockedCompareExchange]
  1516. + mov ecx, ebx
  1517. + call dword ptr [KefReleaseSpinLockFromDpcLevel]
  1518. + push esi
  1519. + push offset ACPIDeviceCompletePhase3On
  1520. + push edi
  1521. + push edi
  1522. + push edi
  1523. + push dword ptr [esi+2Ch]
  1524. + call AMLIAsyncEvalObject
  1525. + add esp, 18h
  1526. + cmp eax, 103h
  1527. + jz short loc_15340
  1528. + push esi
  1529. + push edi
  1530. + push eax
  1531. + push dword ptr [esi+2Ch]
  1532. + call ACPIDeviceCompletePhase3On
  1533. + add esp, 10h
  1534. + jmp short loc_15344
  1535. +
  1536. +
  1537. +loc_15340:
  1538. + mov byte ptr [ebp-1], 1
  1539. +
  1540. +loc_15344:
  1541. + mov ecx, ebx
  1542. + call dword ptr [KefAcquireSpinLockAtDpcLevel]
  1543. +
  1544. +loc_1534C:
  1545. + mov eax, offset AcpiPowerNodeList
  1546. + cmp [ebp-0Ch], eax
  1547. + jnz loc_1524D
  1548. +
  1549. +loc_1535A:
  1550. + mov edi, dword ptr [AcpiPowerNodeList+4] ; Blink
  1551. + cmp edi, eax
  1552. + jz short loc_153DC
  1553. +
  1554. +loc_15364:
  1555. + mov esi, edi
  1556. + mov eax, [esi+8]
  1557. + mov edi, [edi+4]
  1558. + and eax, 2
  1559. + xor ecx, ecx
  1560. + or eax, ecx
  1561. + jz short loc_153D4
  1562. + xor edx, edx
  1563. + push 4
  1564. + lea ecx, [esi+28h]
  1565. + inc edx
  1566. + call dword ptr [InterlockedCompareExchange]
  1567. + cmp eax, 4
  1568. + jz short loc_15392
  1569. + test eax, eax
  1570. + jz short loc_153D4
  1571. + mov byte ptr [ebp-1], 1
  1572. + jmp short loc_153D4
  1573. +
  1574. +loc_15392:
  1575. + mov ecx, ebx
  1576. + call dword ptr [KefReleaseSpinLockFromDpcLevel]
  1577. + push esi
  1578. + push offset ACPIDeviceCompletePhase3Off
  1579. + xor eax, eax
  1580. + push eax
  1581. + push eax
  1582. + push eax
  1583. + push dword ptr [esi+30h]
  1584. + call AMLIAsyncEvalObject
  1585. + add esp, 18h
  1586. + cmp eax, 103h
  1587. + jz short loc_153C8
  1588. + push esi
  1589. + push 0
  1590. + push eax
  1591. + push dword ptr [esi+30h]
  1592. + call ACPIDeviceCompletePhase3Off
  1593. + add esp, 10h
  1594. + jmp short loc_153CC
  1595. +
  1596. +loc_153C8:
  1597. + mov byte ptr [ebp-1], 1
  1598. +
  1599. +loc_153CC:
  1600. + mov ecx, ebx
  1601. + call dword ptr [KefAcquireSpinLockAtDpcLevel]
  1602. +
  1603. +loc_153D4:
  1604. + cmp edi, offset AcpiPowerNodeList
  1605. + jnz short loc_15364
  1606. +
  1607. +loc_153DC:
  1608. + mov ecx, ebx
  1609. + call dword ptr [KefReleaseSpinLockFromDpcLevel]
  1610. + mov al, [ebp-1]
  1611. + neg al
  1612. + pop edi
  1613. + pop esi
  1614. + pop ebx
  1615. + sbb eax, eax
  1616. + and eax, 103h
  1617. + _emit 0xc9 ; "leave" opcode
  1618. + ret
  1619. + }
  1620. +}
  1621. +// SP3
  1622. +#endif
  1623. +
  1624. NTSTATUS
  1625. ACPIDevicePowerProcessPhase4(
  1626. diff --strip-trailing-cr -ur ./driver/nt/internal.c "c:\\ACPI\\ACPI_SP1\\Base\\busdrv\\acpi/driver/nt/internal.c"
  1627. --- ./driver/nt/internal.c 2002-09-02 18:22:24.000000000 +0500
  1628. +++ "c:\\ACPI\\ACPI_SP1\\Base\\busdrv\\acpi/driver/nt/internal.c" 2022-04-16 06:47:52.018554600 +0500
  1629. @@ -304,6 +304,15 @@
  1630. //
  1631. deviceExtension = DeviceObject->DeviceExtension;
  1632.  
  1633. + // SP3
  1634. + if ( deviceExtension &&
  1635. + deviceExtension->Signature != '_SGP' ) {
  1636. + _ACPIInternalErrorEx(0x00090147,
  1637. + (ULONG_PTR)DeviceObject,
  1638. + (ULONG_PTR)deviceExtension);
  1639. + }
  1640. + // SP3
  1641. +
  1642. #if 0
  1643. //
  1644. // Is this a surprise removed device extension?
  1645. diff --strip-trailing-cr -ur ./driver/nt/interupt.c "c:\\ACPI\\ACPI_SP1\\Base\\busdrv\\acpi/driver/nt/interupt.c"
  1646. --- ./driver/nt/interupt.c 2002-09-02 18:22:24.000000000 +0500
  1647. +++ "c:\\ACPI\\ACPI_SP1\\Base\\busdrv\\acpi/driver/nt/interupt.c" 2022-04-16 06:47:52.028320300 +0500
  1648. @@ -711,11 +711,14 @@
  1649. // behind our back. The way that we can correct this problem is by
  1650. // forcing a check of the GPEs...
  1651. //
  1652. - if (!IntStatus) {
  1653. +
  1654. + // SP3
  1655. + if ( !(AcpiOverrideAttributes & 0x0100) && !IntStatus ) { // test byte ptr _AcpiOverrideAttributes+1, 1
  1656.  
  1657. IntStatus |= PM1_GPE_PENDING;
  1658.  
  1659. }
  1660. + // SP3
  1661.  
  1662. //
  1663. // Are any status bits set for events which are handled at ISR time?
  1664. diff --strip-trailing-cr -ur ./driver/nt/irqarb.c "c:\\ACPI\\ACPI_SP1\\Base\\busdrv\\acpi/driver/nt/irqarb.c"
  1665. --- ./driver/nt/irqarb.c 2002-09-02 18:22:24.000000000 +0500
  1666. +++ "c:\\ACPI\\ACPI_SP1\\Base\\busdrv\\acpi/driver/nt/irqarb.c" 2022-04-16 06:47:01.192382800 +0500
  1667. @@ -39,7 +39,8 @@
  1668. extern LONG ArbDebugLevel;
  1669.  
  1670. #define DEBUG_PRINT(Level, Message) \
  1671. - if (ArbDebugLevel >= Level) DbgPrint Message
  1672. + DbgPrint Message
  1673. +
  1674. #else
  1675. #define DEBUG_PRINT(Level, Message)
  1676. #endif
  1677. @@ -3509,6 +3510,22 @@
  1678. }
  1679. }
  1680.  
  1681. + // BSOD 0x7E(c0000005, ...) AcpiArbCrackPRT() two workarounds:
  1682. + // 1) pci.sys presence check
  1683. + // 2) not PCI device type check
  1684. + if (0) {
  1685. + if (!PciInterfacesInstantiated) {
  1686. + return STATUS_NOT_FOUND;
  1687. + }
  1688. + } else {
  1689. + if (Pdo->DriverObject == AcpiDriverObject) {
  1690. + status = ACPIInternalIsPci(Pdo);
  1691. + if (NT_SUCCESS(status))
  1692. + if ( (((PDEVICE_EXTENSION)Pdo->DeviceExtension)->Flags & DEV_CAP_PCI_DEVICE) == 0 )
  1693. + return STATUS_NOT_FOUND;
  1694. + }
  1695. + }
  1696. +
  1697. ASSERT(PciInterfacesInstantiated);
  1698.  
  1699. *LinkNode = NULL;
  1700. @@ -4970,16 +4987,18 @@
  1701. }
  1702.  
  1703. } else {
  1704. + if (0) { // BSOD 0xA5 (0x10006, ...) workaround, missing _DIS method for "PNP0C0F" (PCI Interrupt Link Devices)
  1705.  
  1706. - //
  1707. - // Link nodes must be disablable.
  1708. - //
  1709. + //
  1710. + // Link nodes must be disablable.
  1711. + //
  1712.  
  1713. - KeBugCheckEx(ACPI_BIOS_ERROR,
  1714. - ACPI_LINK_NODE_CANNOT_BE_DISABLED,
  1715. - (ULONG_PTR)context->RootDevice,
  1716. - 0,
  1717. - 0);
  1718. + KeBugCheckEx(ACPI_BIOS_ERROR,
  1719. + ACPI_LINK_NODE_CANNOT_BE_DISABLED,
  1720. + (ULONG_PTR)context->RootDevice,
  1721. + 0,
  1722. + 0);
  1723. + }
  1724. }
  1725. }
  1726. }
  1727. diff --strip-trailing-cr -ur ./driver/nt/irqarb.h "c:\\ACPI\\ACPI_SP1\\Base\\busdrv\\acpi/driver/nt/irqarb.h"
  1728. --- ./driver/nt/irqarb.h 2002-09-02 18:22:24.000000000 +0500
  1729. +++ "c:\\ACPI\\ACPI_SP1\\Base\\busdrv\\acpi/driver/nt/irqarb.h" 2022-04-09 05:05:41.876953100 +0500
  1730. @@ -99,7 +99,8 @@
  1731. extern ACPI_ARBITER AcpiArbiter;
  1732. extern BOOLEAN PciInterfacesInstantiated;
  1733.  
  1734. -#define PCI_PNP_ID "PNP0A03"
  1735. +#define PCI_PNP_ID "PNP0A03"
  1736. +#define PCIE_PNP_ID "PNP0A08"
  1737. #define LINK_NODE_PNP_ID "PNP0C0F"
  1738.  
  1739. // Prototypes for stuff used by msi.c
  1740. diff --strip-trailing-cr -ur ./driver/nt/osnotify.c "c:\\ACPI\\ACPI_SP1\\Base\\busdrv\\acpi/driver/nt/osnotify.c"
  1741. --- ./driver/nt/osnotify.c 2002-09-02 18:22:24.000000000 +0500
  1742. +++ "c:\\ACPI\\ACPI_SP1\\Base\\busdrv\\acpi/driver/nt/osnotify.c" 2022-04-16 06:47:52.056640600 +0500
  1743. @@ -723,7 +723,7 @@
  1744. NTSTATUS
  1745. EXPORT
  1746. -OSNotifyDeviceCheck(
  1747. +OSNotifyDeviceCheck_SP1(
  1748. IN PNSOBJ AcpiObject
  1749. )
  1750. /*++
  1751. @@ -827,6 +827,91 @@
  1752. //
  1753. return STATUS_SUCCESS;
  1754. }
  1755. +
  1756. +
  1757. +#ifdef _X86_
  1758. +// SP3
  1759. +__declspec(naked) NTSTATUS
  1760. +EXPORT
  1761. +OSNotifyDeviceCheck(
  1762. + IN PNSOBJ AcpiObject
  1763. + )
  1764. +{
  1765. +__asm {
  1766. + mov edi, edi
  1767. + push ebp
  1768. + mov ebp, esp
  1769. + push [ebp+8]
  1770. + call ACPIDockIsDockDevice
  1771. + test al, al
  1772. + jz short loc_1C94F
  1773. + pop ebp
  1774. + jmp OSNotifyDeviceEject
  1775. +
  1776. +loc_1C94F:
  1777. + push ebx
  1778. + push esi
  1779. + mov esi, offset AcpiDeviceTreeLock
  1780. + mov ecx, esi
  1781. + call dword ptr [KfAcquireSpinLock]
  1782. + mov ecx, [ebp+8]
  1783. + mov bl, al
  1784. + xor edx, edx
  1785. +
  1786. +loc_1C965:
  1787. + mov eax, [ecx+30h]
  1788. + cmp eax, edx
  1789. + mov ecx, [ecx+8]
  1790. + jz short loc_1C97E
  1791. + cmp dword ptr [eax+8], '_SGP'
  1792. + jz short loc_1C97A
  1793. + xor eax, eax
  1794. +
  1795. +loc_1C97A:
  1796. + cmp eax, edx
  1797. + jnz short loc_1C986
  1798. +
  1799. +loc_1C97E:
  1800. + cmp ecx, edx
  1801. + jnz short loc_1C965
  1802. + cmp eax, edx
  1803. + jz short loc_1C9B0
  1804. +
  1805. +loc_1C986:
  1806. + mov ecx, [eax+13Ch]
  1807. + jmp short loc_1C99D
  1808. +
  1809. +loc_1C98E:
  1810. + mov eax, [ecx]
  1811. + and eax, 8
  1812. + or eax, edx
  1813. + jz short loc_1C9A3
  1814. + mov ecx, [ecx+13Ch]
  1815. +
  1816. +loc_1C99D:
  1817. + cmp ecx, edx
  1818. + jnz short loc_1C98E
  1819. + jmp short loc_1C9B0
  1820. +
  1821. +loc_1C9A3:
  1822. + push edx
  1823. + push dword ptr [ecx+138h]
  1824. + call dword ptr [IoInvalidateDeviceRelations]
  1825. +
  1826. +loc_1C9B0:
  1827. + mov ecx, esi
  1828. + mov dl, bl
  1829. + call dword ptr [KfReleaseSpinLock]
  1830. + pop esi
  1831. + xor eax, eax
  1832. + pop ebx
  1833. + pop ebp
  1834. + ret
  1835. +}
  1836. +}
  1837. +// SP3
  1838. +#endif
  1839. +
  1840. NTSTATUS
  1841. EXPORT
  1842. diff --strip-trailing-cr -ur ./driver/nt/pciopregion.c "c:\\ACPI\\ACPI_SP1\\Base\\busdrv\\acpi/driver/nt/pciopregion.c"
  1843. --- ./driver/nt/pciopregion.c 2002-09-02 18:22:24.000000000 +0500
  1844. +++ "c:\\ACPI\\ACPI_SP1\\Base\\busdrv\\acpi/driver/nt/pciopregion.c" 2022-04-09 05:06:57.275390600 +0500
  1845. @@ -1119,7 +1119,10 @@
  1846.  
  1847. pciConfig = (PPCI_COMMON_CONFIG)buffer;
  1848.  
  1849. - if (pciConfig->HeaderType != PCI_BRIDGE_TYPE) {
  1850. + // SP3
  1851. + if ((PCI_CONFIGURATION_TYPE(pciConfig) != PCI_BRIDGE_TYPE) &&
  1852. + (PCI_CONFIGURATION_TYPE(pciConfig) != PCI_CARDBUS_BRIDGE_TYPE)) {
  1853. + // SP3
  1854.  
  1855. //
  1856. // Make a guess that the bus number was 0.
  1857. @@ -1388,7 +1391,8 @@
  1858.  
  1859. if (state->Hid) {
  1860.  
  1861. - if (strstr(state->Hid, PCI_PNP_ID)) {
  1862. + if (strstr(state->Hid, PCI_PNP_ID) ||
  1863. + strstr(state->Hid, PCIE_PNP_ID)) {
  1864. //
  1865. // Was PCI.
  1866. //
  1867. @@ -1432,7 +1436,8 @@
  1868.  
  1869. if (state->Cid) {
  1870.  
  1871. - if (strstr(state->Cid, PCI_PNP_ID)) {
  1872. + if (strstr(state->Cid, PCI_PNP_ID) ||
  1873. + strstr(state->Cid, PCIE_PNP_ID)) {
  1874. //
  1875. // Was PCI.
  1876. //
  1877. @@ -1669,7 +1674,8 @@
  1878.  
  1879. if (state->Hid) {
  1880.  
  1881. - if (strstr(state->Hid, PCI_PNP_ID)) {
  1882. + if (strstr(state->Hid, PCI_PNP_ID) ||
  1883. + strstr(state->Hid, PCIE_PNP_ID)) {
  1884. //
  1885. // Was PCI.
  1886. //
  1887. @@ -1711,7 +1717,8 @@
  1888.  
  1889. if (state->Cid) {
  1890.  
  1891. - if (strstr(state->Cid, PCI_PNP_ID)) {
  1892. + if (strstr(state->Cid, PCI_PNP_ID) ||
  1893. + strstr(state->Cid, PCIE_PNP_ID)) {
  1894. //
  1895. // Was PCI.
  1896. //
  1897. diff --strip-trailing-cr -ur ./driver/nt/rangesup.c "c:\\ACPI\\ACPI_SP1\\Base\\busdrv\\acpi/driver/nt/rangesup.c"
  1898. --- ./driver/nt/rangesup.c 2002-09-02 18:22:24.000000000 +0500
  1899. +++ "c:\\ACPI\\ACPI_SP1\\Base\\busdrv\\acpi/driver/nt/rangesup.c" 2022-04-16 06:47:52.079101500 +0500
  1900. @@ -2311,9 +2311,11 @@
  1901. //
  1902. // Do we errors?
  1903. //
  1904. - if (bugCheck) {
  1905.  
  1906. - ACPIPrint( (
  1907. + if (0) { // BSOD 0xA5 (0x02, ...) workaround, ACPI vs E820 mem ranges conflict
  1908. + //if (bugCheck) {
  1909. +
  1910. + ACPIPrint( (
  1911. ACPI_PRINT_CRITICAL,
  1912. "ACPI:\n"
  1913. "ACPI: FATAL BIOS ERROR - Need new BIOS to fix PCI problems\n"
  1914. diff --strip-trailing-cr -ur ./driver/nt/root.c "c:\\ACPI\\ACPI_SP1\\Base\\busdrv\\acpi/driver/nt/root.c"
  1915. --- ./driver/nt/root.c 2002-09-02 18:22:24.000000000 +0500
  1916. +++ "c:\\ACPI\\ACPI_SP1\\Base\\busdrv\\acpi/driver/nt/root.c" 2022-04-16 06:47:52.089843700 +0500
  1917. @@ -142,8 +142,10 @@
  1918. --*/
  1919. {
  1920. PKEVENT event = (PKEVENT) Context;
  1921. -#if DBG
  1922. + // SP3
  1923. PDEVICE_EXTENSION deviceExtension = ACPIInternalGetDeviceExtension(DeviceObject);
  1924. + // SP3
  1925. +#if DBG
  1926. PIO_STACK_LOCATION irpStack = IoGetCurrentIrpStackLocation( Irp );
  1927.  
  1928. if (deviceExtension != NULL) {
  1929. diff --strip-trailing-cr -ur ./driver/nt/wake.c "c:\\ACPI\\ACPI_SP1\\Base\\busdrv\\acpi/driver/nt/wake.c"
  1930. --- ./driver/nt/wake.c 2002-09-02 18:22:26.000000000 +0500
  1931. +++ "c:\\ACPI\\ACPI_SP1\\Base\\busdrv\\acpi/driver/nt/wake.c" 2022-04-16 06:47:52.100585900 +0500
  1932. @@ -475,11 +475,6 @@
  1933. PNSOBJ pswObject = NULL;
  1934.  
  1935. //
  1936. - // Acquire the Spinlock
  1937. - //
  1938. - KeAcquireSpinLock( &AcpiPowerLock, &oldIrql );
  1939. -
  1940. - //
  1941. // Update the number of references on the device
  1942. //
  1943. if (Enable) {
  1944. @@ -595,6 +590,13 @@
  1945. pswContext->DeviceExtension = DeviceExtension;
  1946. pswContext->Count = 1;
  1947.  
  1948. + // SP3
  1949. + //
  1950. + // Acquire the Spinlock
  1951. + //
  1952. + KeAcquireSpinLock( &AcpiPowerLock, &oldIrql );
  1953. + // SP3
  1954. +
  1955. //
  1956. // Check to see if we are simply going to queue the context up, or
  1957. // call the interpreter
  1958. @@ -699,11 +701,6 @@
  1959. ACPIWakeEnableDisableAsyncExit:
  1960.  
  1961. //
  1962. - // Release the lock
  1963. - //
  1964. - KeReleaseSpinLock( &AcpiPowerLock, oldIrql );
  1965. -
  1966. - //
  1967. // What happened
  1968. //
  1969. ACPIDevPrint( (
  1970.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement