Advertisement
Guest User

Untitled

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