Advertisement
Guest User

Untitled

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