Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2291 lines
70 KiB

  1. /*** amli.c - AML Debugger functions
  2. *
  3. * This module contains all the debug functions.
  4. *
  5. * Copyright (c) 1996,2001 Microsoft Corporation
  6. * Author: Michael Tsang (MikeTs)
  7. * Created 08/14/96
  8. *
  9. * MODIFICATION HISTORY
  10. * hanumany 5/10/01 Ported to handle 64bit debugging.
  11. *
  12. */
  13. #include "precomp.h"
  14. #include "amlikd.h"
  15. /*** Macros
  16. */
  17. #define ReadAtAddress(A,V,S) { ULONG _r; \
  18. if (!ReadMemory((A), &(V), (S), &_r ) || (_r < (S))) { \
  19. dprintf("Can't Read Memory at %08p\n", (A)); \
  20. rc = DBGERR_CMD_FAILED; \
  21. } \
  22. }
  23. #define WriteAtAddress(A,V,S) { ULONG _r; \
  24. if (!WriteMemory( (A), &(V), (S), &_r ) || (_r < (S))) {\
  25. dprintf("Can't Write Memory at %p\n", (A)); \
  26. rc = DBGERR_CMD_FAILED; \
  27. } \
  28. }
  29. /*** Local data
  30. */
  31. char gcszTokenSeps[] = " \t\n";
  32. ULONG dwfDebuggerON = 0, dwfDebuggerOFF = 0;
  33. ULONG dwfAMLIInitON = 0, dwfAMLIInitOFF = 0;
  34. ULONG dwCmdArg = 0;
  35. CMDARG ArgsHelp[] =
  36. {
  37. NULL, AT_ACTION, 0, NULL, 0, AMLIDbgHelp,
  38. NULL, AT_END, 0, NULL, 0, NULL
  39. };
  40. CMDARG ArgsDNS[] =
  41. {
  42. "s", AT_ENABLE, 0, &dwCmdArg, DNSF_RECURSE, NULL,
  43. NULL, AT_ACTION, 0, NULL, 0, AMLIDbgDNS,
  44. NULL, AT_END, 0, NULL, 0, NULL
  45. };
  46. CMDARG ArgsFind[] =
  47. {
  48. NULL, AT_ACTION, 0, NULL, 0, AMLIDbgFind,
  49. NULL, AT_END, 0, NULL, 0, NULL
  50. };
  51. DBGCMD DbgCmds[] =
  52. {
  53. "?", 0, ArgsHelp, AMLIDbgHelp,
  54. "debugger", 0, NULL, AMLIDbgDebugger,
  55. "dns", 0, ArgsDNS, AMLIDbgDNS,
  56. "find", 0, ArgsFind, AMLIDbgFind,
  57. NULL, 0, NULL, NULL
  58. };
  59. PSZ pszSwitchChars = "-/";
  60. PSZ pszOptionSeps = "=:";
  61. ASLTERM TermTable[] =
  62. {
  63. "DefinitionBlock", CD, 0, OP_NONE, NULL, NULL, OL|CL|LL|AF|AV,
  64. "Include", CD, 0, OP_NONE, NULL, NULL, AF,
  65. "External", CD, 0, OP_NONE, NULL, "uX", AF,
  66. // Short Objects
  67. "Zero", CN, 0, OP_ZERO, NULL, NULL, 0,
  68. "One", CN, 0, OP_ONE, NULL, NULL, 0,
  69. "Ones", CN, 0, OP_ONES, NULL, NULL, 0,
  70. "Revision", CN, 0, OP_REVISION, NULL, NULL, 0,
  71. "Arg0", SN, 0, OP_ARG0, NULL, NULL, 0,
  72. "Arg1", SN, 0, OP_ARG1, NULL, NULL, 0,
  73. "Arg2", SN, 0, OP_ARG2, NULL, NULL, 0,
  74. "Arg3", SN, 0, OP_ARG3, NULL, NULL, 0,
  75. "Arg4", SN, 0, OP_ARG4, NULL, NULL, 0,
  76. "Arg5", SN, 0, OP_ARG5, NULL, NULL, 0,
  77. "Arg6", SN, 0, OP_ARG6, NULL, NULL, 0,
  78. "Local0", SN, 0, OP_LOCAL0, NULL, NULL, 0,
  79. "Local1", SN, 0, OP_LOCAL1, NULL, NULL, 0,
  80. "Local2", SN, 0, OP_LOCAL2, NULL, NULL, 0,
  81. "Local3", SN, 0, OP_LOCAL3, NULL, NULL, 0,
  82. "Local4", SN, 0, OP_LOCAL4, NULL, NULL, 0,
  83. "Local5", SN, 0, OP_LOCAL5, NULL, NULL, 0,
  84. "Local6", SN, 0, OP_LOCAL6, NULL, NULL, 0,
  85. "Local7", SN, 0, OP_LOCAL7, NULL, NULL, 0,
  86. "Debug", SN, 0, OP_DEBUG, NULL, NULL, 0,
  87. // Named Terms
  88. "Alias", NS, 0, OP_ALIAS, "NN", "Ua", 0,
  89. "Name", NS, 0, OP_NAME, "NO", "u", 0,
  90. "Scope", NS, 0, OP_SCOPE, "N", "S", OL|LN|CC,
  91. // Data Objects
  92. "Buffer", DO, 0, OP_BUFFER, "C", "U", DL|LN,
  93. "Package", DO, 0, OP_PACKAGE, "B", NULL, PL|LN,
  94. "EISAID", DO, 0, OP_DWORD, NULL,NULL, AF,
  95. // Argument Keywords
  96. "AnyAcc", KW, AANY, OP_NONE, NULL, "A", 0,
  97. "ByteAcc", KW, AB, OP_NONE, NULL, "A", 0,
  98. "WordAcc", KW, AW, OP_NONE, NULL, "A", 0,
  99. "DWordAcc", KW, ADW, OP_NONE, NULL, "A", 0,
  100. "BlockAcc", KW, ABLK, OP_NONE, NULL, "A", 0,
  101. "SMBSendRecvAcc", KW, ASSR, OP_NONE, NULL, "A", 0,
  102. "SMBQuickAcc", KW, ASQ, OP_NONE, NULL, "A", 0,
  103. "Lock", KW, LK, OP_NONE, NULL, "B", 0,
  104. "NoLock", KW, NOLK, OP_NONE, NULL, "B", 0,
  105. "Preserve", KW, PSRV, OP_NONE, NULL, "C", 0,
  106. "WriteAsOnes", KW, WA1S, OP_NONE, NULL, "C", 0,
  107. "WriteAsZeros", KW, WA0S, OP_NONE, NULL, "C", 0,
  108. "SystemMemory", KW, MEM, OP_NONE, NULL, "D", 0,
  109. "SystemIO", KW, IO, OP_NONE, NULL, "D", 0,
  110. "PCI_Config", KW, CFG, OP_NONE, NULL, "D", 0,
  111. "EmbeddedControl", KW, EC, OP_NONE, NULL, "D", 0,
  112. "SMBus", KW, SMB, OP_NONE, NULL, "D", 0,
  113. "Serialized", KW, SER, OP_NONE, NULL, "E", 0,
  114. "NotSerialized", KW, NOSER,OP_NONE, NULL, "E", 0,
  115. "MTR", KW, OMTR, OP_NONE, NULL, "F", 0,
  116. "MEQ", KW, OMEQ, OP_NONE, NULL, "F", 0,
  117. "MLE", KW, OMLE, OP_NONE, NULL, "F", 0,
  118. "MLT", KW, OMLT, OP_NONE, NULL, "F", 0,
  119. "MGE", KW, OMGE, OP_NONE, NULL, "F", 0,
  120. "MGT", KW, OMGT, OP_NONE, NULL, "F", 0,
  121. "Edge", KW, _HE, OP_NONE, NULL, "G", 0,
  122. "Level", KW, _LL, OP_NONE, NULL, "G", 0,
  123. "ActiveHigh", KW, _HE, OP_NONE, NULL, "H", 0,
  124. "ActiveLow", KW, _LL, OP_NONE, NULL, "H", 0,
  125. "Shared", KW, _SHR, OP_NONE, NULL, "I", 0,
  126. "Exclusive", KW, _EXC, OP_NONE, NULL, "I", 0,
  127. "Compatibility", KW, COMP, OP_NONE, NULL, "J", 0,
  128. "TypeA", KW, TYPA, OP_NONE, NULL, "J", 0,
  129. "TypeB", KW, TYPB, OP_NONE, NULL, "J", 0,
  130. "TypeF", KW, TYPF, OP_NONE, NULL, "J", 0,
  131. "BusMaster", KW, BM, OP_NONE, NULL, "K", 0,
  132. "NotBusMaster", KW, NOBM, OP_NONE, NULL, "K", 0,
  133. "Transfer8", KW, X8, OP_NONE, NULL, "L", 0,
  134. "Transfer8_16", KW, X816, OP_NONE, NULL, "L", 0,
  135. "Transfer16", KW, X16, OP_NONE, NULL, "L", 0,
  136. "Decode16", KW, DC16, OP_NONE, NULL, "M", 0,
  137. "Decode10", KW, DC10, OP_NONE, NULL, "M", 0,
  138. "ReadWrite", KW, _RW, OP_NONE, NULL, "N", 0,
  139. "ReadOnly", KW, _ROM, OP_NONE, NULL, "N", 0,
  140. "ResourceConsumer",KW, RCS, OP_NONE, NULL, "O", 0,
  141. "ResourceProducer",KW, RPD, OP_NONE, NULL, "O", 0,
  142. "SubDecode", KW, BSD, OP_NONE, NULL, "P", 0,
  143. "PosDecode", KW, BPD, OP_NONE, NULL, "P", 0,
  144. "MinFixed", KW, MIF, OP_NONE, NULL, "Q", 0,
  145. "MinNotFixed", KW, NMIF, OP_NONE, NULL, "Q", 0,
  146. "MaxFixed", KW, MAF, OP_NONE, NULL, "R", 0,
  147. "MaxNotFixed", KW, NMAF, OP_NONE, NULL, "R", 0,
  148. "Cacheable", KW, CACH, OP_NONE, NULL, "S", 0,
  149. "WriteCombining", KW, WRCB, OP_NONE, NULL, "S", 0,
  150. "Prefetchable", KW, PREF, OP_NONE, NULL, "S", 0,
  151. "NonCacheable", KW, NCAC, OP_NONE, NULL, "S", 0,
  152. "ISAOnlyRanges", KW, ISA, OP_NONE, NULL, "T", 0,
  153. "NonISAOnlyRanges",KW, NISA, OP_NONE, NULL, "T", 0,
  154. "EntireRange", KW, ERNG, OP_NONE, NULL, "T", 0,
  155. "ExtEdge", KW, ($HGH | $EDG), OP_NONE, NULL, "U", 0,
  156. "ExtLevel", KW, ($LOW | $LVL), OP_NONE, NULL, "U", 0,
  157. "ExtActiveHigh", KW, ($HGH | $EDG), OP_NONE, NULL, "V", 0,
  158. "ExtActiveLow", KW, ($LOW | $LVL), OP_NONE, NULL, "V", 0,
  159. "ExtShared", KW, $SHR, OP_NONE, NULL, "W", 0,
  160. "ExtExclusive", KW, $EXC, OP_NONE, NULL, "W", 0,
  161. "UnknownObj", KW, UNK, OP_NONE, NULL, "X", 0,
  162. "IntObj", KW, INT, OP_NONE, NULL, "X", 0,
  163. "StrObj", KW, STR, OP_NONE, NULL, "X", 0,
  164. "BuffObj", KW, BUF, OP_NONE, NULL, "X", 0,
  165. "PkgObj", KW, PKG, OP_NONE, NULL, "X", 0,
  166. "FieldUnitObj", KW, FDU, OP_NONE, NULL, "X", 0,
  167. "DeviceObj", KW, DEV, OP_NONE, NULL, "X", 0,
  168. "EventObj", KW, EVT, OP_NONE, NULL, "X", 0,
  169. "MethodObj", KW, MET, OP_NONE, NULL, "X", 0,
  170. "MutexObj", KW, MUT, OP_NONE, NULL, "X", 0,
  171. "OpRegionObj", KW, OPR, OP_NONE, NULL, "X", 0,
  172. "PowerResObj", KW, PWR, OP_NONE, NULL, "X", 0,
  173. "ThermalZoneObj", KW, THM, OP_NONE, NULL, "X", 0,
  174. "BuffFieldObj", KW, BFD, OP_NONE, NULL, "X", 0,
  175. "DDBHandleObj", KW, DDB, OP_NONE, NULL, "X", 0,
  176. // Field Macros
  177. "Offset", FM, 0, OP_NONE, NULL, NULL, 0,
  178. "AccessAs", FM, 0, 0x01, NULL, "A" , AF,
  179. // Named Object Creators
  180. "BankField", NO, 0, OP_BANKFIELD, "NNCKkk","OFUABC", FL|FM|LN|AF,
  181. "CreateBitField", NO, 0, OP_BITFIELD, "CCN", "UUb", 0,
  182. "CreateByteField", NO, 0, OP_BYTEFIELD, "CCN", "UUb", 0,
  183. "CreateDWordField",NO, 0, OP_DWORDFIELD, "CCN", "UUb", 0,
  184. "CreateField", NO, 0, OP_CREATEFIELD,"CCCN", "UUUb", 0,
  185. "CreateWordField", NO, 0, OP_WORDFIELD, "CCN", "UUb", 0,
  186. "Device", NO, 0, OP_DEVICE, "N", "d", OL|LN|CC,
  187. "Event", NO, 0, OP_EVENT, "N", "e", 0,
  188. "Field", NO, 0, OP_FIELD, "NKkk", "OABC", FL|FM|LN|AF,
  189. "IndexField", NO, 0, OP_IDXFIELD, "NNKkk", "FFABC", FL|FM|LN|AF,
  190. "Method", NO, 0, OP_METHOD, "NKk", "m!E", CL|OL|LN|AF|CC|SK,
  191. "Mutex", NO, 0, OP_MUTEX, "NB", "x", 0,
  192. "OperationRegion", NO, 0, OP_OPREGION, "NKCC", "oDUU", AF,
  193. "PowerResource", NO, 0, OP_POWERRES, "NBW", "p", OL|LN|CC,
  194. "Processor", NO, 0, OP_PROCESSOR, "NBDB", "c", OL|LN|CC,
  195. "ThermalZone", NO, 0, OP_THERMALZONE,"N", "t", OL|LN|CC,
  196. // Type 1 Opcode Terms
  197. "Break", C1, 0, OP_BREAK, NULL, NULL, 0,
  198. "BreakPoint", C1, 0, OP_BREAKPOINT, NULL, NULL, 0,
  199. "Else", C1, 0, OP_ELSE, NULL, NULL, AF|CL|OL|LN,
  200. "Fatal", C1, 0, OP_FATAL, "BDC", " U",0,
  201. "If", C1, 0, OP_IF, "C", "U", CL|OL|LN,
  202. "Load", C1, 0, OP_LOAD, "NS", "UU", 0,
  203. "Noop", C1, 0, OP_NOP, NULL, NULL, 0,
  204. "Notify", C1, 0, OP_NOTIFY, "SC", "UU", 0,
  205. "Release", C1, 0, OP_RELEASE, "S", "X", 0,
  206. "Reset", C1, 0, OP_RESET, "S", "E", 0,
  207. "Return", C1, 0, OP_RETURN, "C", "U", 0,
  208. "Signal", C1, 0, OP_SIGNAL, "S", "E", 0,
  209. "Sleep", C1, 0, OP_SLEEP, "C", "U", 0,
  210. "Stall", C1, 0, OP_STALL, "C", "U", 0,
  211. "Unload", C1, 0, OP_UNLOAD, "S", "U", 0,
  212. "While", C1, 0, OP_WHILE, "C", "U", CL|OL|LN,
  213. // Type 2 Opcode Terms
  214. "Acquire", C2, 0, OP_ACQUIRE, "SW", "X", 0,
  215. "Add", C2, 0, OP_ADD, "CCS", "UUU",0,
  216. "And", C2, 0, OP_AND, "CCS", "UUU",0,
  217. "Concatenate", C2, 0, OP_CONCAT, "CCS", "UUU",0,
  218. "CondRefOf", C2, 0, OP_CONDREFOF, "SS", "UU", 0,
  219. "Decrement", C2, 0, OP_DECREMENT, "S", "U", 0,
  220. "DerefOf", C2, 0, OP_DEREFOF, "C", "U", 0,
  221. "Divide", C2, 0, OP_DIVIDE, "CCSS", "UUUU",0,
  222. "FindSetLeftBit", C2, 0, OP_FINDSETLBIT, "CS", "UU", 0,
  223. "FindSetRightBit", C2, 0, OP_FINDSETRBIT, "CS", "UU", 0,
  224. "FromBCD", C2, 0, OP_FROMBCD, "CS", "UU", 0,
  225. "Increment", C2, 0, OP_INCREMENT, "S", "U", 0,
  226. "Index", C2, 0, OP_INDEX, "CCS", "UUU",0,
  227. "LAnd", C2, 0, OP_LAND, "CC", "UU", 0,
  228. "LEqual", C2, 0, OP_LEQ, "CC", "UU", 0,
  229. "LGreater", C2, 0, OP_LG, "CC", "UU", 0,
  230. "LGreaterEqual", C2, 0, OP_LGEQ, "CC", "UU", 0,
  231. "LLess", C2, 0, OP_LL, "CC", "UU", 0,
  232. "LLessEqual", C2, 0, OP_LLEQ, "CC", "UU", 0,
  233. "LNot", C2, 0, OP_LNOT, "C", "U", 0,
  234. "LNotEqual", C2, 0, OP_LNOTEQ, "CC", "UU", 0,
  235. "LOr", C2, 0, OP_LOR, "CC", "UU", 0,
  236. "Match", C2, 0, OP_MATCH, "CKCKCC", "UFUFUU",AF,
  237. "Multiply", C2, 0, OP_MULTIPLY, "CCS", "UUU",0,
  238. "NAnd", C2, 0, OP_NAND, "CCS", "UUU",0,
  239. "NOr", C2, 0, OP_NOR, "CCS", "UUU",0,
  240. "Not", C2, 0, OP_NOT, "CS", "UU", 0,
  241. "ObjectType", C2, 0, OP_OBJTYPE, "S", "U", 0,
  242. "Or", C2, 0, OP_OR, "CCS", "UUU",0,
  243. "RefOf", C2, 0, OP_REFOF, "S", "U", 0,
  244. "ShiftLeft", C2, 0, OP_SHIFTL, "CCS", "UUU",0,
  245. "ShiftRight", C2, 0, OP_SHIFTR, "CCS", "UUU",0,
  246. "SizeOf", C2, 0, OP_SIZEOF, "S", "U", 0,
  247. "Store", C2, 0, OP_STORE, "CS", "UU", 0,
  248. "Subtract", C2, 0, OP_SUBTRACT, "CCS", "UUU",0,
  249. "ToBCD", C2, 0, OP_TOBCD, "CS", "UU", 0,
  250. "Wait", C2, 0, OP_WAIT, "SC", "E", 0,
  251. "XOr", C2, 0, OP_XOR, "CCS", "UUU",0,
  252. NULL, 0, 0, OP_NONE, NULL, NULL, 0
  253. };
  254. UCHAR OpClassTable[256] =
  255. { //0x00 0x01 0x02 0x03
  256. CONSTOBJ, CONSTOBJ, INVALID, INVALID,
  257. //0x04 0x05 0x06 0x07
  258. INVALID, INVALID, CODEOBJ, INVALID,
  259. //0x08 0x09 0x0a 0x0b
  260. CODEOBJ, INVALID, DATAOBJ, DATAOBJ,
  261. //0x0c 0x0d 0x0e 0x0f
  262. DATAOBJ, DATAOBJ, INVALID, INVALID,
  263. //0x10 0x11 0x12 0x13
  264. CODEOBJ, CODEOBJ, CODEOBJ, INVALID,
  265. //0x14 0x15 0x16 0x17
  266. CODEOBJ, INVALID, INVALID, INVALID,
  267. //0x18 0x19 0x1a 0x1b
  268. INVALID, INVALID, INVALID, INVALID,
  269. //0x1c 0x1d 0x1e 0x1f
  270. INVALID, INVALID, INVALID, INVALID,
  271. //0x20 0x21 0x22 0x23
  272. INVALID, INVALID, INVALID, INVALID,
  273. //0x24 0x25 0x26 0x27
  274. INVALID, INVALID, INVALID, INVALID,
  275. //0x28 0x29 0x2a 0x2b
  276. INVALID, INVALID, INVALID, INVALID,
  277. //0x2c 0x2d 0x2e 0x2f
  278. INVALID, INVALID, NAMEOBJ, NAMEOBJ,
  279. //0x30 0x31 0x32 0x33
  280. INVALID, INVALID, INVALID, INVALID,
  281. //0x34 0x35 0x36 0x37
  282. INVALID, INVALID, INVALID, INVALID,
  283. //0x38 0x39 0x3a 0x3b
  284. INVALID, INVALID, INVALID, INVALID,
  285. //0x3c 0x3d 0x3e 0x3f
  286. INVALID, INVALID, INVALID, INVALID,
  287. //0x40 0x41 0x42 0x43
  288. INVALID, NAMEOBJ, NAMEOBJ, NAMEOBJ,
  289. //0x44 0x45 0x46 0x47
  290. NAMEOBJ, NAMEOBJ, NAMEOBJ, NAMEOBJ,
  291. //0x48 0x49 0x4a 0x4b
  292. NAMEOBJ, NAMEOBJ, NAMEOBJ, NAMEOBJ,
  293. //0x4c 0x4d 0x4e 0x4f
  294. NAMEOBJ, NAMEOBJ, NAMEOBJ, NAMEOBJ,
  295. //0x50 0x51 0x52 0x53
  296. NAMEOBJ, NAMEOBJ, NAMEOBJ, NAMEOBJ,
  297. //0x54 0x55 0x56 0x57
  298. NAMEOBJ, NAMEOBJ, NAMEOBJ, NAMEOBJ,
  299. //0x58 0x59 0x5a 0x5b
  300. NAMEOBJ, NAMEOBJ, NAMEOBJ, INVALID,
  301. //0x5c 0x5d 0x5e 0x5f
  302. NAMEOBJ, INVALID, NAMEOBJ, NAMEOBJ,
  303. //0x60 0x61 0x62 0x63
  304. LOCALOBJ, LOCALOBJ, LOCALOBJ, LOCALOBJ,
  305. //0x64 0x65 0x66 0x67
  306. LOCALOBJ, LOCALOBJ, LOCALOBJ, LOCALOBJ,
  307. //0x68 0x69 0x6a 0x6b
  308. ARGOBJ, ARGOBJ, ARGOBJ, ARGOBJ,
  309. //0x6c 0x6d 0x6e 0x6f
  310. ARGOBJ, ARGOBJ, ARGOBJ, INVALID,
  311. //0x70 0x71 0x72 0x73
  312. CODEOBJ, CODEOBJ, CODEOBJ, CODEOBJ,
  313. //0x74 0x75 0x76 0x77
  314. CODEOBJ, CODEOBJ, CODEOBJ, CODEOBJ,
  315. //0x78 0x79 0x7a 0x7b
  316. CODEOBJ, CODEOBJ, CODEOBJ, CODEOBJ,
  317. //0x7c 0x7d 0x7e 0x7f
  318. CODEOBJ, CODEOBJ, CODEOBJ, CODEOBJ,
  319. //0x80 0x81 0x82 0x83
  320. CODEOBJ, CODEOBJ, CODEOBJ, CODEOBJ,
  321. //0x84 0x85 0x86 0x87
  322. INVALID, INVALID, CODEOBJ, CODEOBJ,
  323. //0x88 0x89 0x8a 0x8b
  324. CODEOBJ, CODEOBJ, CODEOBJ, CODEOBJ,
  325. //0x8c 0x8d 0x8e 0x8f
  326. CODEOBJ, CODEOBJ, CODEOBJ, INVALID,
  327. //0x90 0x91 0x92 0x93
  328. CODEOBJ, CODEOBJ, CODEOBJ, CODEOBJ,
  329. //0x94 0x95 0x96 0x97
  330. CODEOBJ, CODEOBJ, INVALID, INVALID,
  331. //0x98 0x99 0x9a 0x9b
  332. INVALID, INVALID, INVALID, INVALID,
  333. //0x9c 0x9d 0x9e 0x9f
  334. INVALID, INVALID, INVALID, INVALID,
  335. //0xa0 0xa1 0xa2 0xa3
  336. CODEOBJ, CODEOBJ, CODEOBJ, CODEOBJ,
  337. //0xa4 0xa5 0xa6 0xa7
  338. CODEOBJ, CODEOBJ, INVALID, INVALID,
  339. //0xa8 0xa9 0xaa 0xab
  340. INVALID, INVALID, INVALID, INVALID,
  341. //0xac 0xad 0xae 0xaf
  342. INVALID, INVALID, INVALID, INVALID,
  343. //0xb0 0xb1 0xb2 0xb3
  344. INVALID, INVALID, INVALID, INVALID,
  345. //0xb4 0xb5 0xb6 0xb7
  346. INVALID, INVALID, INVALID, INVALID,
  347. //0xb8 0xb9 0xba 0xbb
  348. INVALID, INVALID, INVALID, INVALID,
  349. //0xbc 0xbd 0xbe 0xbf
  350. INVALID, INVALID, INVALID, INVALID,
  351. //0xc0 0xc1 0xc2 0xc3
  352. INVALID, INVALID, INVALID, INVALID,
  353. //0xc4 0xc5 0xc6 0xc7
  354. INVALID, INVALID, INVALID, INVALID,
  355. //0xc8 0xc9 0xca 0xcb
  356. INVALID, INVALID, INVALID, INVALID,
  357. //0xcc 0xcd 0xce 0xcf
  358. CODEOBJ, INVALID, INVALID, INVALID,
  359. //0xd0 0xd1 0xd2 0xd3
  360. INVALID, INVALID, INVALID, INVALID,
  361. //0xd4 0xd5 0xd6 0xd7
  362. INVALID, INVALID, INVALID, INVALID,
  363. //0xd8 0xd9 0xda 0xdb
  364. INVALID, INVALID, INVALID, INVALID,
  365. //0xdc 0xdd 0xde 0xdf
  366. INVALID, INVALID, INVALID, INVALID,
  367. //0xe0 0xe1 0xe2 0xe3
  368. INVALID, INVALID, INVALID, INVALID,
  369. //0xe4 0xe5 0xe6 0xe7
  370. INVALID, INVALID, INVALID, INVALID,
  371. //0xe8 0xe9 0xea 0xeb
  372. INVALID, INVALID, INVALID, INVALID,
  373. //0xec 0xed 0xee 0xef
  374. INVALID, INVALID, INVALID, INVALID,
  375. //0xf0 0xf1 0xf2 0xf3
  376. INVALID, INVALID, INVALID, INVALID,
  377. //0xf4 0xf5 0xf6 0xf7
  378. INVALID, INVALID, INVALID, INVALID,
  379. //0xf8 0xf9 0xfa 0xfb
  380. INVALID, INVALID, INVALID, INVALID,
  381. //0xfc 0xfd 0xfe 0xff
  382. INVALID, INVALID, INVALID, CONSTOBJ
  383. };
  384. OPMAP ExOpClassTable[] =
  385. {
  386. EXOP_MUTEX, CODEOBJ,
  387. EXOP_EVENT, CODEOBJ,
  388. EXOP_CONDREFOF, CODEOBJ,
  389. EXOP_CREATEFIELD, CODEOBJ,
  390. EXOP_LOAD, CODEOBJ,
  391. EXOP_STALL, CODEOBJ,
  392. EXOP_SLEEP, CODEOBJ,
  393. EXOP_ACQUIRE, CODEOBJ,
  394. EXOP_SIGNAL, CODEOBJ,
  395. EXOP_WAIT, CODEOBJ,
  396. EXOP_RESET, CODEOBJ,
  397. EXOP_RELEASE, CODEOBJ,
  398. EXOP_FROMBCD, CODEOBJ,
  399. EXOP_TOBCD, CODEOBJ,
  400. EXOP_UNLOAD, CODEOBJ,
  401. EXOP_REVISION, CODEOBJ,
  402. EXOP_DEBUG, CODEOBJ,
  403. EXOP_FATAL, CODEOBJ,
  404. EXOP_OPREGION, CODEOBJ,
  405. EXOP_FIELD, CODEOBJ,
  406. EXOP_DEVICE, CODEOBJ,
  407. EXOP_PROCESSOR, CODEOBJ,
  408. EXOP_POWERRES, CODEOBJ,
  409. EXOP_THERMALZONE, CODEOBJ,
  410. EXOP_IDXFIELD, CODEOBJ,
  411. EXOP_BANKFIELD, CODEOBJ,
  412. 0, 0
  413. };
  414. /*** END Local data
  415. */
  416. DECLARE_API( amli )
  417. /*++
  418. Routine Description:
  419. Invoke AMLI debugger
  420. Arguments:
  421. None
  422. Return Value:
  423. None
  424. --*/
  425. {
  426. if ((args == NULL) || (*args == '\0'))
  427. {
  428. dprintf("Usage: amli <cmd> [arguments ...]\n"
  429. "where <cmd> is one of the following:\n");
  430. AMLIDbgHelp(NULL, NULL, 0, 0);
  431. dprintf("\n");
  432. }
  433. else
  434. {
  435. AMLIDbgExecuteCmd((PSZ)args);
  436. dprintf("\n");
  437. }
  438. return S_OK;
  439. }
  440. /***EP AMLIDbgExecuteCmd - Parse and execute a debugger command
  441. *
  442. * ENTRY
  443. * pszCmd -> command string
  444. *
  445. * EXIT
  446. * None
  447. */
  448. VOID STDCALL AMLIDbgExecuteCmd(PSZ pszCmd)
  449. {
  450. PSZ psz;
  451. int i;
  452. ULONG dwNumArgs = 0, dwNonSWArgs = 0;
  453. if ((psz = strtok(pszCmd, gcszTokenSeps)) != NULL)
  454. {
  455. for (i = 0; DbgCmds[i].pszCmd != NULL; i++)
  456. {
  457. if (strcmp(psz, DbgCmds[i].pszCmd) == 0)
  458. {
  459. if ((DbgCmds[i].pArgTable == NULL) ||
  460. (DbgParseArgs(DbgCmds[i].pArgTable,
  461. &dwNumArgs,
  462. &dwNonSWArgs,
  463. gcszTokenSeps) == ARGERR_NONE))
  464. {
  465. ASSERT(DbgCmds[i].pfnCmd != NULL);
  466. DbgCmds[i].pfnCmd(NULL, NULL, dwNumArgs, dwNonSWArgs);
  467. }
  468. break;
  469. }
  470. }
  471. }
  472. else
  473. {
  474. DBG_ERROR(("invalid command \"%s\"", pszCmd));
  475. }
  476. } //AMLIDbgExecuteCmd
  477. /***LP AMLIDbgHelp - help
  478. *
  479. * ENTRY
  480. * pArg -> argument type entry
  481. * pszArg -> argument string
  482. * dwArgNum - argument number
  483. * dwNonSWArgs - number of non-switch arguments
  484. *
  485. * EXIT-SUCCESS
  486. * returns DBGERR_NONE
  487. * EXIT-FAILURE
  488. * returns negative error code
  489. */
  490. LONG LOCAL AMLIDbgHelp(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  491. ULONG dwNonSWArgs)
  492. {
  493. LONG rc = DBGERR_NONE;
  494. DEREF(pArg);
  495. DEREF(dwNonSWArgs);
  496. //
  497. // User typed ? <cmd>
  498. //
  499. if (pszArg != NULL)
  500. {
  501. if (strcmp(pszArg, "?") == 0)
  502. {
  503. dprintf("\nHelp:\n");
  504. dprintf("Usage: ? [<Cmd>]\n");
  505. dprintf("<Cmd> - command to get help on\n");
  506. }
  507. else if (strcmp(pszArg, "debugger") == 0)
  508. {
  509. dprintf("\nRequest entering AMLI debugger:\n");
  510. dprintf("Usage: debugger\n");
  511. }
  512. else if (strcmp(pszArg, "dns") == 0)
  513. {
  514. dprintf("\nDump Name Space Object:\n");
  515. dprintf("Usage: dns [[/s] [<NameStr> | <Addr>]]\n");
  516. dprintf("s - recursively dump the name space subtree\n");
  517. dprintf("<NameStr> - name space path (dump whole name space if absent)\n");
  518. dprintf("<Addr> - specify address of the name space object\n");
  519. }
  520. else if (strcmp(pszArg, "find") == 0)
  521. {
  522. dprintf("\nFind NameSpace Object:\n");
  523. dprintf("Usage: find <NameSeg>\n");
  524. dprintf("<NameSeg> - Name of the NameSpace object without path\n");
  525. }
  526. else
  527. {
  528. DBG_ERROR(("invalid help command - %s", pszArg));
  529. rc = DBGERR_INVALID_CMD;
  530. }
  531. }
  532. //
  533. // User typed just a "?" without any arguments
  534. //
  535. else if (dwArgNum == 0)
  536. {
  537. dprintf("\n");
  538. dprintf("Help - ? [<Cmd>]\n");
  539. dprintf("Request entering debugger- debugger\n");
  540. dprintf("Dump Name Space Object - dns [[/s] [<NameStr> | <Addr>]]\n");
  541. dprintf("Find NameSpace Object - find <NameSeg>\n");
  542. }
  543. return rc;
  544. } //AMLIDbgHelp
  545. /***LP AMLIDbgDebugger - Request entering debugger
  546. *
  547. * ENTRY
  548. * pArg -> argument type entry
  549. * pszArg -> argument string
  550. * dwArgNum - argument number
  551. * dwNonSWArgs - number of non-switch arguments
  552. *
  553. * EXIT-SUCCESS
  554. * returns DBGERR_NONE
  555. * EXIT-FAILURE
  556. * returns negative error code
  557. */
  558. LONG LOCAL AMLIDbgDebugger(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  559. ULONG dwNonSWArgs)
  560. {
  561. LONG rc = DBGERR_NONE;
  562. ULONG64 Address = 0;
  563. DWORD dwfDebugger = 0;
  564. ULONG Offset = 0;
  565. DEREF(pArg);
  566. DEREF(dwArgNum);
  567. DEREF(dwNonSWArgs);
  568. if (pszArg == NULL)
  569. {
  570. Address = GetExpression("ACPI!gDebugger");
  571. InitTypeRead(Address, ACPI!_dbgr);
  572. if(Address != 0)
  573. {
  574. dwfDebugger = (ULONG)ReadField(dwfDebugger);
  575. dwfDebugger |= DBGF_DEBUGGER_REQ;
  576. GetFieldOffset("ACPI!_dbgr", "dwfDebugger", &Offset);
  577. Address = Address + (ULONG64)Offset;
  578. WriteAtAddress(Address, dwfDebugger, sizeof(dwfDebugger));
  579. if(rc != DBGERR_NONE)
  580. {
  581. DBG_ERROR(("failed to set dwfDebugger"));
  582. }
  583. }
  584. else
  585. {
  586. DBG_ERROR(("failed to get debugger flag address"));
  587. rc = DBGERR_CMD_FAILED;
  588. }
  589. }
  590. else
  591. {
  592. DBG_ERROR(("invalid debugger command"));
  593. rc = DBGERR_INVALID_CMD;
  594. }
  595. return rc;
  596. } //AMLIDbgDebugger
  597. /***LP AMLIDbgDNS - Dump Name Space
  598. *
  599. * ENTRY
  600. * pArg -> argument type entry
  601. * pszArg -> argument string
  602. * dwArgNum - argument number
  603. * dwNonSWArgs - number of non-switch arguments
  604. *
  605. * EXIT-SUCCESS
  606. * returns DBGERR_NONE
  607. * EXIT-FAILURE
  608. * returns negative error code
  609. */
  610. LONG LOCAL AMLIDbgDNS(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  611. ULONG dwNonSWArgs)
  612. {
  613. LONG rc = DBGERR_NONE;
  614. ULONG64 ObjData;
  615. ULONG64 uipNSObj;
  616. DEREF(pArg);
  617. DEREF(dwNonSWArgs);
  618. //
  619. // User specified name space path or name space node address
  620. //
  621. if (pszArg != NULL)
  622. {
  623. if (!IsNumber(pszArg, 16, &uipNSObj))
  624. {
  625. //
  626. // The argument is not an address, could be a name space path.
  627. //
  628. _strupr(pszArg);
  629. rc = DumpNSObj(pszArg,
  630. (BOOLEAN)((dwCmdArg & DNSF_RECURSE) != 0));
  631. }
  632. else if (InitTypeRead(uipNSObj, ACPI!_NSObj))
  633. {
  634. DBG_ERROR(("failed to Initialize NameSpace object at %I64x", uipNSObj));
  635. rc = DBGERR_INVALID_CMD;
  636. }
  637. else
  638. {
  639. dprintf("\nACPI Name Space: %s (%I64x)\n",
  640. GetObjAddrPath(uipNSObj), uipNSObj);
  641. if (dwCmdArg & DNSF_RECURSE)
  642. {
  643. DumpNSTree(&uipNSObj, 0);
  644. }
  645. else
  646. {
  647. InitTypeRead(uipNSObj, ACPI!_NSObj);
  648. ObjData = ReadField(ObjData);
  649. AMLIDumpObject(&ObjData, NameSegString((ULONG)ReadField(dwNameSeg)), 0);
  650. }
  651. }
  652. }
  653. else
  654. {
  655. if (dwArgNum == 0)
  656. {
  657. //
  658. // User typed "dns" but did not specify any name space path
  659. // or address.
  660. //
  661. rc = DumpNSObj(NAMESTR_ROOT, TRUE);
  662. }
  663. dwCmdArg = 0;
  664. }
  665. return rc;
  666. } //AMLIDbgDNS
  667. /***LP DumpNSObj - Dump name space object
  668. *
  669. * ENTRY
  670. * pszPath -> name space path string
  671. * fRecursive - TRUE if also dump the subtree recursively
  672. *
  673. * EXIT-SUCCESS
  674. * returns DBGERR_NONE
  675. * EXIT-FAILURE
  676. * returns DBGERR_ code
  677. */
  678. LONG LOCAL DumpNSObj(PSZ pszPath, BOOLEAN fRecursive)
  679. {
  680. LONG rc = DBGERR_NONE;
  681. ULONG64 uipns=0;
  682. ULONG64 NSObj=0;
  683. ULONG64 ObjData=0;
  684. ULONG dwNameSeg = 0;
  685. if ((rc = GetNSObj(pszPath, NULL, &uipns, &NSObj,
  686. NSF_LOCAL_SCOPE | NSF_WARN_NOTFOUND)) == DBGERR_NONE)
  687. {
  688. dprintf("\nACPI Name Space: %s (%I64x)\n", pszPath, uipns);
  689. if (!fRecursive)
  690. {
  691. char szName[sizeof(NAMESEG) + 1] = {0};
  692. InitTypeRead(NSObj, ACPI!_NSObj);
  693. dwNameSeg = (ULONG)ReadField(dwNameSeg);
  694. STRCPYN(szName, (PSZ)&dwNameSeg, sizeof(NAMESEG));
  695. ObjData = ReadField(ObjData);
  696. AMLIDumpObject(&ObjData, szName, 0);
  697. }
  698. else
  699. {
  700. DumpNSTree(&NSObj, 0);
  701. }
  702. }
  703. return rc;
  704. } //DumpNSObj
  705. /***LP DumpNSTree - Dump all the name space objects in the subtree
  706. *
  707. * ENTRY
  708. * pnsObj -> name space subtree root
  709. * dwLevel - indent level
  710. *
  711. * EXIT
  712. * None
  713. */
  714. VOID LOCAL DumpNSTree(PULONG64 pnsObj, ULONG dwLevel)
  715. {
  716. char szName[sizeof(NAMESEG) + 1] = {0};
  717. ULONG64 uipns, uipnsNext;
  718. ULONG64 NSObj, FirstChild, Obj;
  719. ULONG dwNameSeg = 0;
  720. //
  721. // First, dump myself
  722. //
  723. if(InitTypeRead(*pnsObj, ACPI!_NSObj))
  724. dprintf("DumpNSTree: Failed to initialize pnsObj (%I64x)\n", *pnsObj);
  725. else
  726. {
  727. FirstChild = ReadField(pnsFirstChild);
  728. dwNameSeg = (ULONG)ReadField(dwNameSeg);
  729. STRCPYN(szName, (PSZ)&dwNameSeg, sizeof(NAMESEG));
  730. Obj = (ULONG64)ReadField(ObjData);
  731. AMLIDumpObject(&Obj, szName, dwLevel);
  732. //
  733. // Then, recursively dump each of my children
  734. //
  735. for (uipns = FirstChild;
  736. (uipns != 0) && ((NSObj = uipns) !=0) && (InitTypeRead(NSObj, ACPI!_NSObj) == 0);
  737. uipns = uipnsNext)
  738. {
  739. //
  740. // If this is the last child, we have no more.
  741. //
  742. uipnsNext = ((ReadField(list.plistNext) ==
  743. FirstChild)?
  744. 0: ReadField(list.plistNext));
  745. //
  746. // Dump a child
  747. //
  748. DumpNSTree(&NSObj, dwLevel + 1);
  749. }
  750. }
  751. } //DumpNSTree
  752. /***LP AMLIDbgFind - Find NameSpace Object
  753. *
  754. * ENTRY
  755. * pArg -> argument type entry
  756. * pszArg -> argument string
  757. * dwfDataSize - data size flags
  758. *
  759. * EXIT-SUCCESS
  760. * returns DBGERR_NONE
  761. * EXIT-FAILURE
  762. * returns negative error code
  763. */
  764. LONG LOCAL AMLIDbgFind(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  765. ULONG dwNonSWArgs)
  766. {
  767. LONG rc = DBGERR_NONE;
  768. ULONG dwLen;
  769. ULONG64 NSRoot=0;
  770. DEREF(pArg);
  771. DEREF(dwNonSWArgs);
  772. if (pszArg != NULL)
  773. {
  774. dwLen = strlen(pszArg);
  775. _strupr(pszArg);
  776. if (dwLen > sizeof(NAMESEG))
  777. {
  778. DBG_ERROR(("invalid NameSeg - %s", pszArg));
  779. rc = DBGERR_INVALID_CMD;
  780. }
  781. else if(ReadPointer(GetExpression("acpi!gpnsnamespaceroot"), &NSRoot))
  782. {
  783. NAMESEG dwName;
  784. dwName = NAMESEG_BLANK;
  785. memcpy(&dwName, pszArg, dwLen);
  786. if (!FindNSObj(dwName, &NSRoot))
  787. {
  788. dprintf("No such NameSpace object - %s\n", pszArg);
  789. }
  790. }
  791. else
  792. {
  793. DBG_ERROR(("failed to read NameSpace root object"));
  794. }
  795. }
  796. else if (dwArgNum == 0)
  797. {
  798. DBG_ERROR(("invalid Find command"));
  799. rc = DBGERR_INVALID_CMD;
  800. }
  801. return rc;
  802. } //AMLIDbgFind
  803. /***LP FindNSObj - Find and print the full path of a name space object
  804. *
  805. * ENTRY
  806. * dwName - NameSeg of the name space object
  807. * nsRoot - root of subtree to search for object
  808. *
  809. * EXIT-SUCCESS
  810. * returns TRUE - found at least one match
  811. * EXIT-FAILURE
  812. * returns FALSE - found no match
  813. */
  814. BOOLEAN LOCAL FindNSObj(NAMESEG dwName, PULONG64 pnsRoot)
  815. {
  816. BOOLEAN rc = FALSE;
  817. ULONG64 uip=0, uipNext=0, TempNext=0, FirstChild = 0;
  818. ULONG dwNameSeg=0;
  819. ULONG Offset = 0;
  820. if (pnsRoot != 0)
  821. {
  822. if(InitTypeRead(*pnsRoot, ACPI!_NSObj))
  823. dprintf("FindNSObj: Failed to initialize pnsRoot \n");
  824. else
  825. {
  826. dwNameSeg = (ULONG)ReadField(dwNameSeg);
  827. }
  828. if (dwName == dwNameSeg)
  829. {
  830. dprintf("%s\n", GetObjectPath(pnsRoot));
  831. rc = TRUE;
  832. }
  833. FirstChild = ReadField(pnsFirstChild);
  834. if (FirstChild != 0)
  835. {
  836. for (uip = FirstChild;
  837. uip != 0 && InitTypeRead(uip, ACPI!_NSObj) == 0;
  838. uip = uipNext)
  839. {
  840. if(InitTypeRead(uip, ACPI!_NSObj))
  841. dprintf("FindNSObj: Failed to initialize uip \n");
  842. TempNext = ReadField(list.plistNext);
  843. uipNext = ((TempNext == FirstChild) ?
  844. 0: TempNext);
  845. rc |= FindNSObj(dwName, &uip);
  846. }
  847. }
  848. }
  849. return rc;
  850. } //FindNSObj
  851. /***LP GetObjectPath - get object namespace path
  852. *
  853. * ENTRY
  854. * pns -> object
  855. *
  856. * EXIT
  857. * returns name space path
  858. */
  859. PSZ LOCAL GetObjectPath(PULONG64 pns)
  860. {
  861. static char szPath[MAX_NAME_LEN + 1] = {0};
  862. ULONG64 NSParent, NSGrandParent;
  863. ULONG NameSeg=0;
  864. ULONG Length = 0;
  865. int i;
  866. if (pns != NULL)
  867. {
  868. if(InitTypeRead(*pns, ACPI!_NSObj))
  869. dprintf("GetObjectPath: Failed to initialize pns \n");
  870. NSParent = ReadField(pnsParent);
  871. if (NSParent == 0)
  872. {
  873. strcpy(szPath, "\\");
  874. }
  875. else
  876. {
  877. GetObjectPath(&NSParent);
  878. if(InitTypeRead(NSParent, ACPI!_NSObj))
  879. dprintf("GetObjectPath: Failed to initialize NSParent \n");
  880. NSGrandParent = ReadField(pnsParent);
  881. if (NSGrandParent != 0)
  882. {
  883. strcat(szPath, ".");
  884. }
  885. if(InitTypeRead(*pns, ACPI!_NSObj))
  886. dprintf("GetObjectPath: Failed to initialize pns \n");
  887. NameSeg = (ULONG)ReadField(dwNameSeg);
  888. StrCat(szPath, (PSZ)&NameSeg, sizeof(NAMESEG));
  889. }
  890. for (i = StrLen(szPath, -1) - 1; i >= 0; --i)
  891. {
  892. if (szPath[i] == '_')
  893. szPath[i] = '\0';
  894. else
  895. break;
  896. }
  897. }
  898. else
  899. {
  900. szPath[0] = '\0';
  901. }
  902. return szPath;
  903. } //GetObjectPath
  904. /***LP GetObjAddrPath - get object namespace path
  905. *
  906. * ENTRY
  907. * uipns - object address
  908. *
  909. * EXIT
  910. * returns name space path
  911. */
  912. PSZ LOCAL GetObjAddrPath(ULONG64 uipns)
  913. {
  914. PSZ psz = NULL;
  915. if (uipns == 0)
  916. {
  917. psz = "<null>";
  918. }
  919. else
  920. {
  921. psz = GetObjectPath(&uipns);
  922. }
  923. return psz;
  924. } //GetObjAddrPath
  925. /***LP AMLIDumpObject - Dump object info.
  926. *
  927. * ENTRY
  928. * pdata -> data
  929. * pszName -> object name
  930. * iLevel - indent level
  931. *
  932. * EXIT
  933. * None
  934. *
  935. * NOTE
  936. * If iLevel is negative, no indentation and newline are printed.
  937. */
  938. VOID LOCAL AMLIDumpObject(PULONG64 pdata, PSZ pszName, int iLevel)
  939. {
  940. BOOLEAN fPrintNewLine = (BOOLEAN)(iLevel >= 0);
  941. int i;
  942. char szName1[sizeof(NAMESEG) + 1],
  943. szName2[sizeof(NAMESEG) + 1];
  944. for (i = 0; i < iLevel; ++i)
  945. {
  946. dprintf("| ");
  947. }
  948. if (pszName == NULL)
  949. {
  950. pszName = "";
  951. }
  952. if(InitTypeRead(*pdata, ACPI!_ObjData))
  953. dprintf("AMLIDumpObject: Failed to initialize ObjData (%I64x) \n", pdata);
  954. else
  955. {
  956. switch ((ULONG)ReadField(dwDataType))
  957. {
  958. case OBJTYPE_UNKNOWN:
  959. dprintf("Unknown(%s)", pszName);
  960. break;
  961. case OBJTYPE_INTDATA:
  962. dprintf("Integer(%s:Value=0x%016I64x[%d])",
  963. pszName, ReadField(uipDataValue), ReadField(uipDataValue));
  964. break;
  965. case OBJTYPE_STRDATA:
  966. {
  967. PSZ psz = 0;
  968. if ((psz = (PSZ)LocalAlloc(LPTR, (ULONG)ReadField(dwDataLen))) == NULL)
  969. {
  970. DBG_ERROR(("AMLIDumpObject: failed to allocate object buffer (size=%d)",
  971. (ULONG)ReadField(dwDataLen)));
  972. }
  973. else if (!ReadMemory((ULONG64)ReadField(pbDataBuff),
  974. psz,
  975. (ULONG)ReadField(dwDataLen),
  976. NULL))
  977. {
  978. DBG_ERROR(("AMLIDumpObject: failed to read object buffer at %I64x", (ULONG64)ReadField(pbDataBuff)));
  979. LocalFree(psz);
  980. psz = NULL;
  981. }
  982. dprintf("String(%s:Str=\"%s\")", pszName, psz);
  983. if(psz)
  984. LocalFree(psz);
  985. break;
  986. }
  987. case OBJTYPE_BUFFDATA:
  988. {
  989. PUCHAR pbData = 0;
  990. if ((pbData = (PUCHAR)LocalAlloc(LPTR, (ULONG)ReadField(dwDataLen))) == NULL)
  991. {
  992. DBG_ERROR(("AMLIDumpObject: failed to allocate object buffer (size=%d)",
  993. (ULONG)ReadField(dwDataLen)));
  994. }
  995. else if (!ReadMemory((ULONG64)ReadField(pbDataBuff),
  996. pbData,
  997. (ULONG)ReadField(dwDataLen),
  998. NULL))
  999. {
  1000. DBG_ERROR(("AMLIDumpObject: failed to read object buffer at %I64x", (ULONG64)ReadField(pbDataBuff)));
  1001. LocalFree(pbData);
  1002. pbData = NULL;
  1003. }
  1004. dprintf("Buffer(%s:Ptr=%x,Len=%d)",
  1005. pszName, (PUCHAR)ReadField(pbDataBuff), (ULONG)ReadField(dwDataLen));
  1006. PrintBuffData(pbData, (ULONG)ReadField(dwDataLen));
  1007. LocalFree(pbData);
  1008. break;
  1009. }
  1010. case OBJTYPE_PKGDATA:
  1011. {
  1012. ULONG64 Pkg;
  1013. ULONG64 PkgNext = 0;
  1014. ULONG dwcElements = 0;
  1015. ULONG64 offset = 0;
  1016. Pkg = ReadField (pbDataBuff);
  1017. InitTypeRead(Pkg, ACPI!_PackageObj);
  1018. dwcElements = (int)ReadField(dwcElements);
  1019. dprintf("Package(%s:NumElements=%d){", pszName, dwcElements);
  1020. if (fPrintNewLine)
  1021. {
  1022. dprintf("\n");
  1023. }
  1024. for (i = 0; i < (int)dwcElements; ++i)
  1025. {
  1026. GetFieldOffset("acpi!_PackageObj", "adata", (ULONG*) &offset);
  1027. offset += (GetTypeSize ("acpi!_ObjData") * i);
  1028. PkgNext = offset + Pkg;
  1029. AMLIDumpObject(&PkgNext,
  1030. NULL,
  1031. fPrintNewLine? iLevel + 1: -1);
  1032. if (!fPrintNewLine && (i < (int)dwcElements))
  1033. {
  1034. dprintf(",");
  1035. }
  1036. }
  1037. for (i = 0; i < iLevel; ++i)
  1038. {
  1039. dprintf("| ");
  1040. }
  1041. dprintf("}");
  1042. break;
  1043. }
  1044. case OBJTYPE_FIELDUNIT:
  1045. {
  1046. InitTypeRead((ULONG64)ReadField(pbDataBuff), ACPI!_FieldUnitObj);
  1047. dprintf("FieldUnit(%s:FieldParent=%I64x,ByteOffset=0x%x,StartBit=0x%x,NumBits=%d,FieldFlags=0x%x)",
  1048. pszName,
  1049. ReadField(pnsFieldParent),
  1050. (ULONG)ReadField(FieldDesc.dwByteOffset),
  1051. (ULONG)ReadField(FieldDesc.dwStartBitPos),
  1052. (ULONG)ReadField(FieldDesc.dwNumBits),
  1053. (ULONG)ReadField(FieldDesc.dwFieldFlags));
  1054. break;
  1055. }
  1056. case OBJTYPE_DEVICE:
  1057. dprintf("Device(%s)", pszName);
  1058. break;
  1059. case OBJTYPE_EVENT:
  1060. dprintf("Event(%s:pKEvent=%x)", pszName, ReadField(pbDataBuff));
  1061. break;
  1062. case OBJTYPE_METHOD:
  1063. {
  1064. ULONG DataLength = 0;
  1065. ULONG Offset = 0;
  1066. ULONG64 pbDataBuff = 0;
  1067. DataLength = (ULONG)ReadField(dwDataLen);
  1068. pbDataBuff = (ULONG64)ReadField(pbDataBuff);
  1069. InitTypeRead(pbDataBuff, ACPI!_MethodObj);
  1070. GetFieldOffset("ACPI!_MethodObj", "abCodeBuff", &Offset);
  1071. dprintf("Method(%s:Flags=0x%x,CodeBuff=%I64x,Len=%d)",
  1072. pszName, (UCHAR)ReadField(bMethodFlags),
  1073. (ULONG64)Offset + pbDataBuff,
  1074. DataLength - Offset);
  1075. break;
  1076. }
  1077. case OBJTYPE_MUTEX:
  1078. dprintf("Mutex(%s:pKMutex=%I64x)", pszName, (PULONG64)ReadField(pbDataBuff));
  1079. break;
  1080. case OBJTYPE_OPREGION:
  1081. {
  1082. InitTypeRead((ULONG64)ReadField(pbDataBuff), ACPI!_OpRegionObj);
  1083. dprintf("OpRegion(%s:RegionSpace=%s,Offset=0x%I64x,Len=%d)",
  1084. pszName,
  1085. GetRegionSpaceName((UCHAR)ReadField(bRegionSpace)),
  1086. (ULONG64)ReadField(uipOffset),
  1087. (ULONG)ReadField(dwLen));
  1088. break;
  1089. }
  1090. case OBJTYPE_POWERRES:
  1091. {
  1092. InitTypeRead((ULONG64)ReadField(pbDataBuff), ACPI!_PowerResObj);
  1093. dprintf("PowerResource(%s:SystemLevel=0x%x,ResOrder=%d)",
  1094. pszName, (UCHAR)ReadField(bSystemLevel), (UCHAR)ReadField(bResOrder));
  1095. break;
  1096. }
  1097. case OBJTYPE_PROCESSOR:
  1098. {
  1099. InitTypeRead((ULONG64)ReadField(pbDataBuff), ACPI!_ProcessorObj);
  1100. dprintf("Processor(%s:Processor ID=0x%x,PBlk=0x%x,PBlkLen=%d)",
  1101. pszName,
  1102. (UCHAR)ReadField(bApicID),
  1103. (ULONG)ReadField(dwPBlk),
  1104. (ULONG)ReadField(dwPBlkLen));
  1105. break;
  1106. }
  1107. case OBJTYPE_THERMALZONE:
  1108. dprintf("ThermalZone(%s)", pszName);
  1109. break;
  1110. case OBJTYPE_BUFFFIELD:
  1111. {
  1112. InitTypeRead((ULONG64)ReadField(pbDataBuff), ACPI!_BuffFieldObj);
  1113. dprintf("BufferField(%s:Ptr=%I64x,Len=%d,ByteOffset=0x%x,StartBit=0x%x,NumBits=%d,FieldFlags=0x%x)",
  1114. pszName,
  1115. ReadField(pbDataBuff),
  1116. (ULONG)ReadField(dwBuffLen),
  1117. (ULONG)ReadField(FieldDesc.dwByteOffset),
  1118. (ULONG)ReadField(FieldDesc.dwStartBitPos),
  1119. (ULONG)ReadField(FieldDesc.dwNumBits),
  1120. (ULONG)ReadField(FieldDesc.dwFieldFlags));
  1121. break;
  1122. }
  1123. case OBJTYPE_DDBHANDLE:
  1124. dprintf("DDBHandle(%s:Handle=%I64x)", pszName, (ULONG64)ReadField(pbDataBuff));
  1125. break;
  1126. case OBJTYPE_OBJALIAS:
  1127. {
  1128. ULONG64 NSObj = 0;
  1129. ULONG dwDataType;
  1130. NSObj = ReadField(pnsAlias);
  1131. if (NSObj)
  1132. {
  1133. InitTypeRead(NSObj, ACPI!_NSObj);
  1134. dwDataType = (ULONG)ReadField(ObjData.dwDataType);
  1135. }
  1136. else
  1137. {
  1138. dwDataType = OBJTYPE_UNKNOWN;
  1139. }
  1140. dprintf("ObjectAlias(%s:Alias=%s,Type=%s)",
  1141. pszName, GetObjAddrPath(NSObj),
  1142. AMLIGetObjectTypeName(dwDataType));
  1143. break;
  1144. }
  1145. case OBJTYPE_DATAALIAS:
  1146. {
  1147. ULONG64 Obj = 0;
  1148. dprintf("DataAlias(%s:Link=%I64x)", pszName, ReadField(pdataAlias));
  1149. Obj = ReadField(pdataAlias);
  1150. if (fPrintNewLine && Obj)
  1151. {
  1152. AMLIDumpObject(&Obj, NULL, iLevel + 1);
  1153. fPrintNewLine = FALSE;
  1154. }
  1155. break;
  1156. }
  1157. case OBJTYPE_BANKFIELD:
  1158. {
  1159. ULONG64 NSObj = 0;
  1160. ULONG64 DataBuff = 0;
  1161. ULONG dwNameSeg = 0;
  1162. DataBuff = (ULONG64)ReadField(pbDataBuff);
  1163. InitTypeRead(DataBuff, ACPI!_BankFieldObj);
  1164. NSObj = ReadField(pnsBase);
  1165. InitTypeRead(NSObj, ACPI!_NSObj);
  1166. if (NSObj)
  1167. {
  1168. dwNameSeg = (ULONG)ReadField(dwNameSeg);
  1169. STRCPYN(szName1, (PSZ)&dwNameSeg, sizeof(NAMESEG));
  1170. }
  1171. else
  1172. {
  1173. szName1[0] = '\0';
  1174. }
  1175. InitTypeRead(DataBuff, ACPI!_BankFieldObj);
  1176. NSObj = ReadField(pnsBank);
  1177. InitTypeRead(NSObj, ACPI!_NSObj);
  1178. if (NSObj)
  1179. {
  1180. dwNameSeg = (ULONG)ReadField(dwNameSeg);
  1181. STRCPYN(szName2, (PSZ)&dwNameSeg, sizeof(NAMESEG));
  1182. }
  1183. else
  1184. {
  1185. szName2[0] = '\0';
  1186. }
  1187. InitTypeRead(DataBuff, ACPI!_BankFieldObj);
  1188. dprintf("BankField(%s:Base=%s,BankName=%s,BankValue=0x%x)",
  1189. pszName, szName1, szName2, (ULONG)ReadField(dwBankValue));
  1190. break;
  1191. }
  1192. case OBJTYPE_FIELD:
  1193. {
  1194. ULONG64 NSObj = 0;
  1195. ULONG64 pf = 0;
  1196. ULONG dwNameSeg = 0;
  1197. pf = ReadField(pbDataBuff);
  1198. InitTypeRead(pf, ACPI!_FieldObj);
  1199. NSObj = ReadField(pnsBase);
  1200. InitTypeRead(NSObj, ACPI!_NSObj);
  1201. if (NSObj)
  1202. {
  1203. dwNameSeg = (ULONG)ReadField(dwNameSeg);
  1204. STRCPYN(szName1, (PSZ)&dwNameSeg, sizeof(NAMESEG));
  1205. }
  1206. else
  1207. {
  1208. szName1[0] = '\0';
  1209. }
  1210. dprintf("Field(%s:Base=%s)", pszName, szName1);
  1211. break;
  1212. }
  1213. case OBJTYPE_INDEXFIELD:
  1214. {
  1215. ULONG64 pif = 0;
  1216. ULONG64 NSObj = 0;
  1217. ULONG dwNameSeg = 0;
  1218. pif = (ULONG64)ReadField(pbDataBuff);
  1219. InitTypeRead(pif, ACPI!_IndexFieldObj);
  1220. NSObj = ReadField(pnsIndex);
  1221. InitTypeRead(NSObj, ACPI!_NSObj);
  1222. if (NSObj)
  1223. {
  1224. dwNameSeg = (ULONG)ReadField(dwNameSeg);
  1225. STRCPYN(szName1, (PSZ)&dwNameSeg, sizeof(NAMESEG));
  1226. }
  1227. else
  1228. {
  1229. szName1[0] = '\0';
  1230. }
  1231. InitTypeRead(pif, ACPI!_IndexFieldObj);
  1232. NSObj = ReadField(pnsData);
  1233. InitTypeRead(NSObj, ACPI!_NSObj);
  1234. if (NSObj)
  1235. {
  1236. dwNameSeg = (ULONG)ReadField(dwNameSeg);
  1237. STRCPYN(szName2, (PSZ)&dwNameSeg, sizeof(NAMESEG));
  1238. }
  1239. else
  1240. {
  1241. szName2[0] = '\0';
  1242. }
  1243. dprintf("IndexField(%s:IndexName=%s,DataName=%s)",
  1244. pszName, szName1, szName2);
  1245. break;
  1246. }
  1247. default:
  1248. DBG_ERROR(("unexpected data object type (type=%x)",
  1249. (ULONG)ReadField(dwDataType)));
  1250. }
  1251. }
  1252. if (fPrintNewLine)
  1253. {
  1254. dprintf("\n");
  1255. }
  1256. } //DumpObject
  1257. /***LP AMLIGetObjectTypeName - get object type name
  1258. *
  1259. * ENTRY
  1260. * dwObjType - object type
  1261. *
  1262. * EXIT
  1263. * return object type name
  1264. */
  1265. PSZ LOCAL AMLIGetObjectTypeName(ULONG dwObjType)
  1266. {
  1267. PSZ psz = NULL;
  1268. int i;
  1269. static struct
  1270. {
  1271. ULONG dwObjType;
  1272. PSZ pszObjTypeName;
  1273. } ObjTypeTable[] =
  1274. {
  1275. OBJTYPE_UNKNOWN, "Unknown",
  1276. OBJTYPE_INTDATA, "Integer",
  1277. OBJTYPE_STRDATA, "String",
  1278. OBJTYPE_BUFFDATA, "Buffer",
  1279. OBJTYPE_PKGDATA, "Package",
  1280. OBJTYPE_FIELDUNIT, "FieldUnit",
  1281. OBJTYPE_DEVICE, "Device",
  1282. OBJTYPE_EVENT, "Event",
  1283. OBJTYPE_METHOD, "Method",
  1284. OBJTYPE_MUTEX, "Mutex",
  1285. OBJTYPE_OPREGION, "OpRegion",
  1286. OBJTYPE_POWERRES, "PowerResource",
  1287. OBJTYPE_PROCESSOR, "Processor",
  1288. OBJTYPE_THERMALZONE,"ThermalZone",
  1289. OBJTYPE_BUFFFIELD, "BuffField",
  1290. OBJTYPE_DDBHANDLE, "DDBHandle",
  1291. OBJTYPE_DEBUG, "Debug",
  1292. OBJTYPE_OBJALIAS, "ObjAlias",
  1293. OBJTYPE_DATAALIAS, "DataAlias",
  1294. OBJTYPE_BANKFIELD, "BankField",
  1295. OBJTYPE_FIELD, "Field",
  1296. OBJTYPE_INDEXFIELD, "IndexField",
  1297. OBJTYPE_DATA, "Data",
  1298. OBJTYPE_DATAFIELD, "DataField",
  1299. OBJTYPE_DATAOBJ, "DataObject",
  1300. 0, NULL
  1301. };
  1302. for (i = 0; ObjTypeTable[i].pszObjTypeName != NULL; ++i)
  1303. {
  1304. if (dwObjType == ObjTypeTable[i].dwObjType)
  1305. {
  1306. psz = ObjTypeTable[i].pszObjTypeName;
  1307. break;
  1308. }
  1309. }
  1310. return psz;
  1311. } //GetObjectTypeName
  1312. /***LP GetRegionSpaceName - get region space name
  1313. *
  1314. * ENTRY
  1315. * bRegionSpace - region space
  1316. *
  1317. * EXIT
  1318. * return object type name
  1319. */
  1320. PSZ LOCAL GetRegionSpaceName(UCHAR bRegionSpace)
  1321. {
  1322. PSZ psz = NULL;
  1323. int i;
  1324. static PSZ pszVendorDefined = "VendorDefined";
  1325. static struct
  1326. {
  1327. UCHAR bRegionSpace;
  1328. PSZ pszRegionSpaceName;
  1329. } RegionNameTable[] =
  1330. {
  1331. REGSPACE_MEM, "SystemMemory",
  1332. REGSPACE_IO, "SystemIO",
  1333. REGSPACE_PCICFG, "PCIConfigSpace",
  1334. REGSPACE_EC, "EmbeddedController",
  1335. REGSPACE_SMB, "SMBus",
  1336. 0, NULL
  1337. };
  1338. for (i = 0; RegionNameTable[i].pszRegionSpaceName != NULL; ++i)
  1339. {
  1340. if (bRegionSpace == RegionNameTable[i].bRegionSpace)
  1341. {
  1342. psz = RegionNameTable[i].pszRegionSpaceName;
  1343. break;
  1344. }
  1345. }
  1346. if (psz == NULL)
  1347. {
  1348. psz = pszVendorDefined;
  1349. }
  1350. return psz;
  1351. } //GetRegionSpaceName
  1352. /***LP PrintBuffData - Print buffer data
  1353. *
  1354. * ENTRY
  1355. * pb -> buffer
  1356. * dwLen - length of buffer
  1357. *
  1358. * EXIT
  1359. * None
  1360. */
  1361. VOID LOCAL PrintBuffData(PUCHAR pb, ULONG dwLen)
  1362. {
  1363. int i, j;
  1364. dprintf("{");
  1365. for (i = j = 0; i < (int)dwLen; ++i)
  1366. {
  1367. if (j == 0)
  1368. dprintf("\n\t0x%02x", pb[i]);
  1369. else
  1370. dprintf(",0x%02x", pb[i]);
  1371. j++;
  1372. if (j >= 14)
  1373. j = 0;
  1374. }
  1375. dprintf("}");
  1376. } //PrintBuffData
  1377. /***LP IsNumber - Check if string is a number, if so return the number
  1378. *
  1379. * ENTRY
  1380. * pszStr -> string
  1381. * dwBase - base
  1382. * puipValue -> to hold the number
  1383. *
  1384. * EXIT-SUCCESS
  1385. * returns TRUE - the string is a number
  1386. * EXIT-FAILURE
  1387. * returns FALSE - the string is not a number
  1388. */
  1389. BOOLEAN LOCAL IsNumber(PSZ pszStr, ULONG dwBase, PULONG64 puipValue)
  1390. {
  1391. BOOLEAN rc=TRUE;
  1392. PSZ psz;
  1393. *puipValue = AMLIUtilStringToUlong64(pszStr, &psz, dwBase);
  1394. rc = ((psz != pszStr) && (*psz == '\0'))? TRUE: FALSE;
  1395. return rc;
  1396. } //IsNumber
  1397. /***EP DbgParseArgs - parse command arguments
  1398. *
  1399. * ENTRY
  1400. * pArgs -> command argument table
  1401. * pdwNumArgs -> to hold the number of arguments parsed
  1402. * pdwNonSWArgs -> to hold the number of non-switch arguments parsed
  1403. * pszTokenSeps -> token separator characters string
  1404. *
  1405. * EXIT-SUCCESS
  1406. * returns ARGERR_NONE
  1407. * EXIT-FAILURE
  1408. * returns negative error code
  1409. */
  1410. LONG LOCAL DbgParseArgs(PCMDARG ArgTable, PULONG pdwNumArgs,
  1411. PULONG pdwNonSWArgs, PSZ pszTokenSeps)
  1412. {
  1413. LONG rc = ARGERR_NONE;
  1414. PSZ psz;
  1415. *pdwNumArgs = 0;
  1416. *pdwNonSWArgs = 0;
  1417. while ((psz = strtok(NULL, pszTokenSeps)) != NULL)
  1418. {
  1419. (*pdwNumArgs)++;
  1420. if ((rc = DbgParseOneArg(ArgTable, psz, *pdwNumArgs, pdwNonSWArgs)) !=
  1421. ARGERR_NONE)
  1422. {
  1423. break;
  1424. }
  1425. }
  1426. return rc;
  1427. } //DbgParseArgs
  1428. /***LP DbgParseOneArg - parse one command argument
  1429. *
  1430. * ENTRY
  1431. * pArgs -> command argument table
  1432. * psz -> argument string
  1433. * dwArgNum - argument number
  1434. * pdwNonSWArgs -> to hold the number of non-switch arguments parsed
  1435. *
  1436. * EXIT-SUCCESS
  1437. * returns ARGERR_NONE
  1438. * EXIT-FAILURE
  1439. * returns negative error code
  1440. */
  1441. LONG LOCAL DbgParseOneArg(PCMDARG ArgTable, PSZ psz, ULONG dwArgNum,
  1442. PULONG pdwNonSWArgs)
  1443. {
  1444. LONG rc = ARGERR_NONE;
  1445. PCMDARG pArg;
  1446. PSZ pszEnd;
  1447. if ((pArg = DbgMatchArg(ArgTable, &psz, pdwNonSWArgs)) != NULL)
  1448. {
  1449. switch (pArg->dwArgType)
  1450. {
  1451. case AT_STRING:
  1452. case AT_NUM:
  1453. if (pArg->dwfArg & AF_SEP)
  1454. {
  1455. if ((*psz != '\0') &&
  1456. (strchr(pszOptionSeps, *psz) != NULL))
  1457. {
  1458. psz++;
  1459. }
  1460. else
  1461. {
  1462. ARG_ERROR(("argument missing option separator - %s",
  1463. psz));
  1464. rc = ARGERR_SEP_NOT_FOUND;
  1465. break;
  1466. }
  1467. }
  1468. if (pArg->dwArgType == AT_STRING)
  1469. {
  1470. *((PSZ *)pArg->pvArgData) = psz;
  1471. }
  1472. else
  1473. {
  1474. *((PLONG)pArg->pvArgData) =
  1475. strtol(psz, &pszEnd, pArg->dwArgParam);
  1476. if (psz == pszEnd)
  1477. {
  1478. ARG_ERROR(("invalid numeric argument - %s", psz));
  1479. rc = ARGERR_INVALID_NUMBER;
  1480. break;
  1481. }
  1482. }
  1483. if (pArg->pfnArg != NULL)
  1484. {
  1485. rc = pArg->pfnArg(pArg, psz, dwArgNum, *pdwNonSWArgs);
  1486. }
  1487. break;
  1488. case AT_ENABLE:
  1489. case AT_DISABLE:
  1490. if (pArg->dwArgType == AT_ENABLE)
  1491. *((PULONG)pArg->pvArgData) |= pArg->dwArgParam;
  1492. else
  1493. *((PULONG)pArg->pvArgData) &= ~pArg->dwArgParam;
  1494. if ((pArg->pfnArg != NULL) &&
  1495. (pArg->pfnArg(pArg, psz, dwArgNum, *pdwNonSWArgs) !=
  1496. ARGERR_NONE))
  1497. {
  1498. break;
  1499. }
  1500. if (*psz != '\0')
  1501. {
  1502. rc = DbgParseOneArg(ArgTable, psz, dwArgNum, pdwNonSWArgs);
  1503. }
  1504. break;
  1505. case AT_ACTION:
  1506. ASSERT(pArg->pfnArg != NULL);
  1507. rc = pArg->pfnArg(pArg, psz, dwArgNum, *pdwNonSWArgs);
  1508. break;
  1509. default:
  1510. ARG_ERROR(("invalid argument table"));
  1511. rc = ARGERR_ASSERT_FAILED;
  1512. }
  1513. }
  1514. else
  1515. {
  1516. ARG_ERROR(("invalid command argument - %s", psz));
  1517. rc = ARGERR_INVALID_ARG;
  1518. }
  1519. return rc;
  1520. } //DbgParseOneArg
  1521. /***LP DbgMatchArg - match argument type from argument table
  1522. *
  1523. * ENTRY
  1524. * ArgTable -> argument table
  1525. * ppsz -> argument string pointer
  1526. * pdwNonSWArgs -> to hold the number of non-switch arguments parsed
  1527. *
  1528. * EXIT-SUCCESS
  1529. * returns pointer to argument entry matched
  1530. * EXIT-FAILURE
  1531. * returns NULL
  1532. */
  1533. PCMDARG LOCAL DbgMatchArg(PCMDARG ArgTable, PSZ *ppsz, PULONG pdwNonSWArgs)
  1534. {
  1535. PCMDARG pArg;
  1536. for (pArg = ArgTable; pArg->dwArgType != AT_END; pArg++)
  1537. {
  1538. if (pArg->pszArgID == NULL) //NULL means match anything.
  1539. {
  1540. (*pdwNonSWArgs)++;
  1541. break;
  1542. }
  1543. else
  1544. {
  1545. ULONG dwLen;
  1546. if (strchr(pszSwitchChars, **ppsz) != NULL)
  1547. (*ppsz)++;
  1548. dwLen = strlen(pArg->pszArgID);
  1549. if (StrCmp(pArg->pszArgID, *ppsz, dwLen,
  1550. (BOOLEAN)((pArg->dwfArg & AF_NOI) != 0)) == 0)
  1551. {
  1552. (*ppsz) += dwLen;
  1553. break;
  1554. }
  1555. }
  1556. }
  1557. if (pArg->dwArgType == AT_END)
  1558. pArg = NULL;
  1559. return pArg;
  1560. } //DbgMatchArg
  1561. /***EP MemZero - Fill target buffer with zeros
  1562. *
  1563. * ENTRY
  1564. * uipAddr - target buffer address
  1565. * dwSize - target buffer size
  1566. *
  1567. * EXIT
  1568. * None
  1569. */
  1570. VOID MemZero(ULONG64 uipAddr, ULONG dwSize)
  1571. {
  1572. PUCHAR pbBuff;
  1573. //
  1574. // LPTR will zero init the buffer
  1575. //
  1576. if ((pbBuff = LocalAlloc(LPTR, dwSize)) != NULL)
  1577. {
  1578. if (!WriteMemory(uipAddr, pbBuff, dwSize, NULL))
  1579. {
  1580. DBG_ERROR(("MemZero: failed to write memory"));
  1581. }
  1582. LocalFree(pbBuff);
  1583. }
  1584. else
  1585. {
  1586. DBG_ERROR(("MemZero: failed to allocate buffer"));
  1587. }
  1588. } //MemZero
  1589. /***EP ReadMemByte - Read a byte from target address
  1590. *
  1591. * ENTRY
  1592. * uipAddr - target address
  1593. *
  1594. * EXIT
  1595. * None
  1596. */
  1597. BYTE ReadMemByte(ULONG64 uipAddr)
  1598. {
  1599. BYTE bData = 0;
  1600. if (!ReadMemory(uipAddr, &bData, sizeof(bData), NULL))
  1601. {
  1602. DBG_ERROR(("ReadMemByte: failed to read address %I64x", uipAddr));
  1603. }
  1604. return bData;
  1605. } //ReadMemByte
  1606. /***EP ReadMemWord - Read a word from target address
  1607. *
  1608. * ENTRY
  1609. * uipAddr - target address
  1610. *
  1611. * EXIT
  1612. * None
  1613. */
  1614. WORD ReadMemWord(ULONG64 uipAddr)
  1615. {
  1616. WORD wData = 0;
  1617. if (!ReadMemory(uipAddr, &wData, sizeof(wData), NULL))
  1618. {
  1619. DBG_ERROR(("ReadMemWord: failed to read address %I64x", uipAddr));
  1620. }
  1621. return wData;
  1622. } //ReadMemWord
  1623. /***EP ReadMemDWord - Read a dword from target address
  1624. *
  1625. * ENTRY
  1626. * uipAddr - target address
  1627. *
  1628. * EXIT
  1629. * None
  1630. */
  1631. DWORD ReadMemDWord(ULONG64 uipAddr)
  1632. {
  1633. DWORD dwData = 0;
  1634. if (!ReadMemory(uipAddr, &dwData, sizeof(dwData), NULL))
  1635. {
  1636. DBG_ERROR(("ReadMemDWord: failed to read address %I64x", uipAddr));
  1637. }
  1638. return dwData;
  1639. } //ReadMemDWord
  1640. /***EP ReadMemUlong64 - Read a ulong64 from target address
  1641. *
  1642. * ENTRY
  1643. * uipAddr - target address
  1644. *
  1645. * EXIT
  1646. * 64 bit address
  1647. */
  1648. ULONG64 ReadMemUlong64(ULONG64 uipAddr)
  1649. {
  1650. ULONG_PTR uipData = 0;
  1651. if (!ReadMemory(uipAddr, &uipData, sizeof(uipData), NULL))
  1652. {
  1653. DBG_ERROR(("ReadMemUlong64: failed to read address %I64x", uipAddr));
  1654. }
  1655. return uipData;
  1656. } //ReadMemUlongPtr
  1657. /***LP GetObjBuff - Allocate and read object buffer
  1658. *
  1659. * ENTRY
  1660. * pdata -> object data
  1661. *
  1662. * EXIT
  1663. * return the allocated object buffer pointer
  1664. */
  1665. /***LP GetNSObj - Find a name space object
  1666. *
  1667. * ENTRY
  1668. * pszObjPath -> object path string
  1669. * pnsScope - object scope to start the search (NULL means root)
  1670. * puipns -> to hold the pnsobj address if found
  1671. * pns -> buffer to hold the object found
  1672. * dwfNS - flags
  1673. *
  1674. * EXIT-SUCCESS
  1675. * returns DBGERR_NONE
  1676. * EXIT-FAILURE
  1677. * returns DBGERR_ code
  1678. */
  1679. LONG LOCAL GetNSObj(PSZ pszObjPath, PULONG64 pnsScope, PULONG64 puipns,
  1680. PULONG64 pns, ULONG dwfNS)
  1681. {
  1682. LONG rc = DBGERR_NONE;
  1683. BOOLEAN fSearchUp = (BOOLEAN)(!(dwfNS & NSF_LOCAL_SCOPE) &&
  1684. (pszObjPath[0] != '\\') &&
  1685. (pszObjPath[0] != '^') &&
  1686. (StrLen(pszObjPath, -1) <= sizeof(NAMESEG)));
  1687. BOOLEAN fMatch = TRUE;
  1688. PSZ psz;
  1689. ULONG64 NSObj, NSChildObj;
  1690. ULONG64 NSScope=0, UIPns=0, NSO=0;
  1691. if(pnsScope)
  1692. NSScope = *pnsScope;
  1693. if(puipns)
  1694. UIPns = *puipns;
  1695. if(pns)
  1696. NSO = *pns;
  1697. if (*pszObjPath == '\\')
  1698. {
  1699. psz = &pszObjPath[1];
  1700. NSScope = 0;
  1701. }
  1702. else
  1703. {
  1704. if(NSScope)
  1705. {
  1706. if(InitTypeRead(NSScope, ACPI!_NSObj))
  1707. dprintf("GetNSObj: Failed to initialize NSScope (%I64x)\n", NSScope);
  1708. }
  1709. for (psz = pszObjPath;
  1710. (*psz == '^') && (NSScope != 0) &&
  1711. (ReadField(pnsParent) != 0);
  1712. psz++)
  1713. {
  1714. NSObj = ReadField(pnsParent);
  1715. if (!NSObj)
  1716. {
  1717. DBG_ERROR(("failed to read parent object at %I64x",
  1718. ReadField(pnsParent)));
  1719. rc = DBGERR_CMD_FAILED;
  1720. break;
  1721. }
  1722. else
  1723. {
  1724. NSScope = NSObj;
  1725. if(InitTypeRead(NSScope, ACPI!_NSObj))
  1726. dprintf("GetNSObj: Failed to initialize for NSScope (%I64x)\n", NSScope);
  1727. }
  1728. }
  1729. if ((rc == DBGERR_NONE) && (*psz == '^'))
  1730. {
  1731. if (dwfNS & NSF_WARN_NOTFOUND)
  1732. {
  1733. DBG_ERROR(("object %s not found", pszObjPath));
  1734. }
  1735. rc = DBGERR_CMD_FAILED;
  1736. }
  1737. }
  1738. if ((rc == DBGERR_NONE) && (NSScope == 0))
  1739. {
  1740. ReadPointer(GetExpression("acpi!gpnsnamespaceroot"), &UIPns);
  1741. if (UIPns == 0)
  1742. {
  1743. DBG_ERROR(("failed to get root object address"));
  1744. rc = DBGERR_CMD_FAILED;
  1745. }
  1746. else
  1747. {
  1748. NSObj = UIPns;
  1749. NSScope = NSObj;
  1750. }
  1751. }
  1752. while ((rc == DBGERR_NONE) && (*psz != '\0'))
  1753. {
  1754. InitTypeRead(NSScope, ACPI!_NSObj);
  1755. if (ReadField(pnsFirstChild) == 0)
  1756. {
  1757. fMatch = FALSE;
  1758. }
  1759. else
  1760. {
  1761. PSZ pszEnd = strchr(psz, '.');
  1762. ULONG dwLen = (ULONG)(pszEnd? (pszEnd - psz): StrLen(psz, -1));
  1763. if (dwLen > sizeof(NAMESEG))
  1764. {
  1765. DBG_ERROR(("invalid name path %s", pszObjPath));
  1766. rc = DBGERR_CMD_FAILED;
  1767. }
  1768. else
  1769. {
  1770. NAMESEG dwName = NAMESEG_BLANK;
  1771. BOOLEAN fFound = FALSE;
  1772. ULONG64 uip;
  1773. ULONG64 uipFirstChild = ReadField(pnsFirstChild);
  1774. MEMCPY(&dwName, psz, dwLen);
  1775. //
  1776. // Search all siblings for a matching NameSeg.
  1777. //
  1778. for (uip = uipFirstChild;
  1779. ((uip != 0) && ((NSChildObj = uip) != 0) && (InitTypeRead(NSChildObj, ACPI!_NSObj) == 0));
  1780. uip = ((ULONG64)ReadField(list.plistNext) ==
  1781. uipFirstChild)?
  1782. 0: (ULONG64)ReadField(list.plistNext))
  1783. {
  1784. if ((ULONG)ReadField(dwNameSeg) == dwName)
  1785. {
  1786. UIPns = uip;
  1787. fFound = TRUE;
  1788. NSObj = NSChildObj;
  1789. NSScope = NSObj;
  1790. break;
  1791. }
  1792. }
  1793. if (fFound)
  1794. {
  1795. psz += dwLen;
  1796. if (*psz == '.')
  1797. {
  1798. psz++;
  1799. }
  1800. }
  1801. else
  1802. {
  1803. fMatch = FALSE;
  1804. }
  1805. }
  1806. }
  1807. if ((rc == DBGERR_NONE) && !fMatch)
  1808. {
  1809. InitTypeRead(NSScope, ACPI!_NSObj);
  1810. if (fSearchUp && ((NSObj = ReadField(pnsParent)) != 0))
  1811. {
  1812. fMatch = TRUE;
  1813. NSScope = NSObj;
  1814. }
  1815. else
  1816. {
  1817. if (dwfNS & NSF_WARN_NOTFOUND)
  1818. {
  1819. DBG_ERROR(("object %s not found", pszObjPath));
  1820. }
  1821. rc = DBGERR_CMD_FAILED;
  1822. }
  1823. }
  1824. }
  1825. if (rc != DBGERR_NONE)
  1826. {
  1827. UIPns = 0;
  1828. }
  1829. else
  1830. {
  1831. NSO = NSScope;
  1832. }
  1833. if(puipns)
  1834. *puipns = UIPns;
  1835. if(pnsScope)
  1836. *pnsScope = NSScope;
  1837. if(pns)
  1838. *pns = NSO;
  1839. return rc;
  1840. } //GetNSObj
  1841. /***LP NameSegString - convert a NameSeg to an ASCIIZ stri
  1842. *
  1843. * ENTRY
  1844. * dwNameSeg - NameSeg
  1845. *
  1846. * EXIT
  1847. * returns string
  1848. */
  1849. PSZ LOCAL NameSegString(ULONG dwNameSeg)
  1850. {
  1851. static char szNameSeg[sizeof(NAMESEG) + 1] = {0};
  1852. STRCPYN(szNameSeg, (PSZ)&dwNameSeg, sizeof(NAMESEG));
  1853. return szNameSeg;
  1854. } //NameSegString
  1855. /***EP StrCat - concatenate strings
  1856. *
  1857. * ENTRY
  1858. * pszDst -> destination string
  1859. * pszSrc -> source string
  1860. * n - number of bytes to concatenate
  1861. *
  1862. * EXIT
  1863. * returns pszDst
  1864. */
  1865. PSZ LOCAL StrCat(PSZ pszDst, PSZ pszSrc, ULONG n)
  1866. {
  1867. ULONG dwSrcLen, dwDstLen;
  1868. ASSERT(pszDst != NULL);
  1869. ASSERT(pszSrc != NULL);
  1870. dwSrcLen = StrLen(pszSrc, n);
  1871. if ((n == (ULONG)(-1)) || (n > dwSrcLen))
  1872. n = dwSrcLen;
  1873. dwDstLen = StrLen(pszDst, (ULONG)(-1));
  1874. MEMCPY(&pszDst[dwDstLen], pszSrc, n);
  1875. pszDst[dwDstLen + n] = '\0';
  1876. return pszDst;
  1877. } //StrCat
  1878. /***EP StrLen - determine string length
  1879. *
  1880. * ENTRY
  1881. * psz -> string
  1882. * n - limiting length
  1883. *
  1884. * EXIT
  1885. * returns string length
  1886. */
  1887. ULONG LOCAL StrLen(PSZ psz, ULONG n)
  1888. {
  1889. ULONG dwLen;
  1890. ASSERT(psz != NULL);
  1891. if (n != (ULONG)-1)
  1892. n++;
  1893. for (dwLen = 0; (dwLen <= n) && (*psz != '\0'); psz++)
  1894. dwLen++;
  1895. return dwLen;
  1896. } //StrLen
  1897. /***EP StrCmp - compare strings
  1898. *
  1899. * ENTRY
  1900. * psz1 -> string 1
  1901. * psz2 -> string 2
  1902. * n - number of bytes to compare
  1903. * fMatchCase - TRUE if case sensitive
  1904. *
  1905. * EXIT
  1906. * returns 0 if string 1 == string 2
  1907. * <0 if string 1 < string 2
  1908. * >0 if string 1 > string 2
  1909. */
  1910. LONG LOCAL StrCmp(PSZ psz1, PSZ psz2, ULONG n, BOOLEAN fMatchCase)
  1911. {
  1912. LONG rc;
  1913. ULONG dwLen1, dwLen2;
  1914. ULONG i;
  1915. ASSERT(psz1 != NULL);
  1916. ASSERT(psz2 != NULL);
  1917. dwLen1 = StrLen(psz1, n);
  1918. dwLen2 = StrLen(psz2, n);
  1919. if (n == (ULONG)(-1))
  1920. n = (dwLen1 > dwLen2)? dwLen1: dwLen2;
  1921. if (fMatchCase)
  1922. {
  1923. for (i = 0, rc = 0;
  1924. (rc == 0) && (i < n) && (i < dwLen1) && (i < dwLen2);
  1925. ++i)
  1926. {
  1927. rc = (LONG)(psz1[i] - psz2[i]);
  1928. }
  1929. }
  1930. else
  1931. {
  1932. for (i = 0, rc = 0;
  1933. (rc == 0) && (i < n) && (i < dwLen1) && (i < dwLen2);
  1934. ++i)
  1935. {
  1936. rc = (LONG)(TOUPPER(psz1[i]) - TOUPPER(psz2[i]));
  1937. }
  1938. }
  1939. if ((rc == 0) && (i < n))
  1940. {
  1941. if (i < dwLen1)
  1942. rc = (LONG)psz1[i];
  1943. else if (i < dwLen2)
  1944. rc = (LONG)(-psz2[i]);
  1945. }
  1946. return rc;
  1947. } //StrCmp
  1948. /***EP StrCpy - copy string
  1949. *
  1950. * ENTRY
  1951. * pszDst -> destination string
  1952. * pszSrc -> source string
  1953. * n - number of bytes to copy
  1954. *
  1955. * EXIT
  1956. * returns pszDst
  1957. */
  1958. PSZ LOCAL StrCpy(PSZ pszDst, PSZ pszSrc, ULONG n)
  1959. {
  1960. ULONG dwSrcLen;
  1961. ASSERT(pszDst != NULL);
  1962. ASSERT(pszSrc != NULL);
  1963. dwSrcLen = StrLen(pszSrc, n);
  1964. if ((n == (ULONG)(-1)) || (n > dwSrcLen))
  1965. n = dwSrcLen;
  1966. MEMCPY(pszDst, pszSrc, n);
  1967. pszDst[n] = '\0';
  1968. return pszDst;
  1969. } //StrCpy
  1970. ULONG64
  1971. AMLIUtilStringToUlong64 (
  1972. PSZ String,
  1973. PSZ *End,
  1974. ULONG Base
  1975. )
  1976. {
  1977. UCHAR LowDword[9], HighDword[9];
  1978. ZeroMemory (&HighDword, sizeof (HighDword));
  1979. ZeroMemory (&LowDword, sizeof (LowDword));
  1980. if (strlen (String) > 8) {
  1981. memcpy (&LowDword, (void *) &String[strlen (String) - 8], 8);
  1982. memcpy (&HighDword, (void *) &String[0], strlen (String) - 8);
  1983. } else {
  1984. return strtoul (String, End, Base);
  1985. }
  1986. return ((ULONG64) strtoul (HighDword, 0, Base) << 32) + strtoul (LowDword, End, Base);
  1987. }