dbmethod.c revision 1.11 1 /*******************************************************************************
2 *
3 * Module Name: dbmethod - Debug commands for control methods
4 *
5 ******************************************************************************/
6
7 /*
8 * Copyright (C) 2000 - 2018, Intel Corp.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
44 #include "acpi.h"
45 #include "accommon.h"
46 #include "acdispat.h"
47 #include "acnamesp.h"
48 #include "acdebug.h"
49 #include "acparser.h"
50 #include "acpredef.h"
51
52
53 #define _COMPONENT ACPI_CA_DEBUGGER
54 ACPI_MODULE_NAME ("dbmethod")
55
56 /* Local prototypes */
57
58 static ACPI_STATUS
59 AcpiDbWalkForExecute (
60 ACPI_HANDLE ObjHandle,
61 UINT32 NestingLevel,
62 void *Context,
63 void **ReturnValue);
64
65
66 /*******************************************************************************
67 *
68 * FUNCTION: AcpiDbSetMethodBreakpoint
69 *
70 * PARAMETERS: Location - AML offset of breakpoint
71 * WalkState - Current walk info
72 * Op - Current Op (from parse walk)
73 *
74 * RETURN: None
75 *
76 * DESCRIPTION: Set a breakpoint in a control method at the specified
77 * AML offset
78 *
79 ******************************************************************************/
80
81 void
82 AcpiDbSetMethodBreakpoint (
83 char *Location,
84 ACPI_WALK_STATE *WalkState,
85 ACPI_PARSE_OBJECT *Op)
86 {
87 UINT32 Address;
88 UINT32 AmlOffset;
89
90
91 if (!Op)
92 {
93 AcpiOsPrintf ("There is no method currently executing\n");
94 return;
95 }
96
97 /* Get and verify the breakpoint address */
98
99 Address = strtoul (Location, NULL, 16);
100 AmlOffset = (UINT32) ACPI_PTR_DIFF (Op->Common.Aml,
101 WalkState->ParserState.AmlStart);
102 if (Address <= AmlOffset)
103 {
104 AcpiOsPrintf ("Breakpoint %X is beyond current address %X\n",
105 Address, AmlOffset);
106 }
107
108 /* Save breakpoint in current walk */
109
110 WalkState->UserBreakpoint = Address;
111 AcpiOsPrintf ("Breakpoint set at AML offset %X\n", Address);
112 }
113
114
115 /*******************************************************************************
116 *
117 * FUNCTION: AcpiDbSetMethodCallBreakpoint
118 *
119 * PARAMETERS: Op - Current Op (from parse walk)
120 *
121 * RETURN: None
122 *
123 * DESCRIPTION: Set a breakpoint in a control method at the specified
124 * AML offset
125 *
126 ******************************************************************************/
127
128 void
129 AcpiDbSetMethodCallBreakpoint (
130 ACPI_PARSE_OBJECT *Op)
131 {
132
133
134 if (!Op)
135 {
136 AcpiOsPrintf ("There is no method currently executing\n");
137 return;
138 }
139
140 AcpiGbl_StepToNextCall = TRUE;
141 }
142
143
144 /*******************************************************************************
145 *
146 * FUNCTION: AcpiDbSetMethodData
147 *
148 * PARAMETERS: TypeArg - L for local, A for argument
149 * IndexArg - which one
150 * ValueArg - Value to set.
151 *
152 * RETURN: None
153 *
154 * DESCRIPTION: Set a local or argument for the running control method.
155 * NOTE: only object supported is Number.
156 *
157 ******************************************************************************/
158
159 void
160 AcpiDbSetMethodData (
161 char *TypeArg,
162 char *IndexArg,
163 char *ValueArg)
164 {
165 char Type;
166 UINT32 Index;
167 UINT32 Value;
168 ACPI_WALK_STATE *WalkState;
169 ACPI_OPERAND_OBJECT *ObjDesc;
170 ACPI_STATUS Status;
171 ACPI_NAMESPACE_NODE *Node;
172
173
174 /* Validate TypeArg */
175
176 AcpiUtStrupr (TypeArg);
177 Type = TypeArg[0];
178 if ((Type != 'L') &&
179 (Type != 'A') &&
180 (Type != 'N'))
181 {
182 AcpiOsPrintf ("Invalid SET operand: %s\n", TypeArg);
183 return;
184 }
185
186 Value = strtoul (ValueArg, NULL, 16);
187
188 if (Type == 'N')
189 {
190 Node = AcpiDbConvertToNode (IndexArg);
191 if (!Node)
192 {
193 return;
194 }
195
196 if (Node->Type != ACPI_TYPE_INTEGER)
197 {
198 AcpiOsPrintf ("Can only set Integer nodes\n");
199 return;
200 }
201 ObjDesc = Node->Object;
202 ObjDesc->Integer.Value = Value;
203 return;
204 }
205
206 /* Get the index and value */
207
208 Index = strtoul (IndexArg, NULL, 16);
209
210 WalkState = AcpiDsGetCurrentWalkState (AcpiGbl_CurrentWalkList);
211 if (!WalkState)
212 {
213 AcpiOsPrintf ("There is no method currently executing\n");
214 return;
215 }
216
217 /* Create and initialize the new object */
218
219 ObjDesc = AcpiUtCreateIntegerObject ((UINT64) Value);
220 if (!ObjDesc)
221 {
222 AcpiOsPrintf ("Could not create an internal object\n");
223 return;
224 }
225
226 /* Store the new object into the target */
227
228 switch (Type)
229 {
230 case 'A':
231
232 /* Set a method argument */
233
234 if (Index > ACPI_METHOD_MAX_ARG)
235 {
236 AcpiOsPrintf ("Arg%u - Invalid argument name\n",
237 Index);
238 goto Cleanup;
239 }
240
241 Status = AcpiDsStoreObjectToLocal (ACPI_REFCLASS_ARG,
242 Index, ObjDesc, WalkState);
243 if (ACPI_FAILURE (Status))
244 {
245 goto Cleanup;
246 }
247
248 ObjDesc = WalkState->Arguments[Index].Object;
249
250 AcpiOsPrintf ("Arg%u: ", Index);
251 AcpiDbDisplayInternalObject (ObjDesc, WalkState);
252 break;
253
254 case 'L':
255
256 /* Set a method local */
257
258 if (Index > ACPI_METHOD_MAX_LOCAL)
259 {
260 AcpiOsPrintf ("Local%u - Invalid local variable name\n",
261 Index);
262 goto Cleanup;
263 }
264
265 Status = AcpiDsStoreObjectToLocal (ACPI_REFCLASS_LOCAL,
266 Index, ObjDesc, WalkState);
267 if (ACPI_FAILURE (Status))
268 {
269 goto Cleanup;
270 }
271
272 ObjDesc = WalkState->LocalVariables[Index].Object;
273
274 AcpiOsPrintf ("Local%u: ", Index);
275 AcpiDbDisplayInternalObject (ObjDesc, WalkState);
276 break;
277
278 default:
279
280 break;
281 }
282
283 Cleanup:
284 AcpiUtRemoveReference (ObjDesc);
285 }
286
287
288 #ifdef ACPI_DISASSEMBLER
289 /*******************************************************************************
290 *
291 * FUNCTION: AcpiDbDisassembleAml
292 *
293 * PARAMETERS: Statements - Number of statements to disassemble
294 * Op - Current Op (from parse walk)
295 *
296 * RETURN: None
297 *
298 * DESCRIPTION: Display disassembled AML (ASL) starting from Op for the number
299 * of statements specified.
300 *
301 ******************************************************************************/
302
303 void
304 AcpiDbDisassembleAml (
305 char *Statements,
306 ACPI_PARSE_OBJECT *Op)
307 {
308 UINT32 NumStatements = 8;
309
310
311 if (!Op)
312 {
313 AcpiOsPrintf ("There is no method currently executing\n");
314 return;
315 }
316
317 if (Statements)
318 {
319 NumStatements = strtoul (Statements, NULL, 0);
320 }
321
322 AcpiDmDisassemble (NULL, Op, NumStatements);
323 }
324
325
326 /*******************************************************************************
327 *
328 * FUNCTION: AcpiDbDisassembleMethod
329 *
330 * PARAMETERS: Name - Name of control method
331 *
332 * RETURN: None
333 *
334 * DESCRIPTION: Display disassembled AML (ASL) starting from Op for the number
335 * of statements specified.
336 *
337 ******************************************************************************/
338
339 ACPI_STATUS
340 AcpiDbDisassembleMethod (
341 char *Name)
342 {
343 ACPI_STATUS Status;
344 ACPI_PARSE_OBJECT *Op;
345 ACPI_WALK_STATE *WalkState;
346 ACPI_OPERAND_OBJECT *ObjDesc;
347 ACPI_NAMESPACE_NODE *Method;
348
349
350 Method = AcpiDbConvertToNode (Name);
351 if (!Method)
352 {
353 return (AE_BAD_PARAMETER);
354 }
355
356 if (Method->Type != ACPI_TYPE_METHOD)
357 {
358 ACPI_ERROR ((AE_INFO, "%s (%s): Object must be a control method",
359 Name, AcpiUtGetTypeName (Method->Type)));
360 return (AE_BAD_PARAMETER);
361 }
362
363 ObjDesc = Method->Object;
364
365 Op = AcpiPsCreateScopeOp (ObjDesc->Method.AmlStart);
366 if (!Op)
367 {
368 return (AE_NO_MEMORY);
369 }
370
371 /* Create and initialize a new walk state */
372
373 WalkState = AcpiDsCreateWalkState (0, Op, NULL, NULL);
374 if (!WalkState)
375 {
376 return (AE_NO_MEMORY);
377 }
378
379 Status = AcpiDsInitAmlWalk (WalkState, Op, NULL,
380 ObjDesc->Method.AmlStart,
381 ObjDesc->Method.AmlLength, NULL, ACPI_IMODE_LOAD_PASS1);
382 if (ACPI_FAILURE (Status))
383 {
384 return (Status);
385 }
386
387 Status = AcpiUtAllocateOwnerId (&ObjDesc->Method.OwnerId);
388 WalkState->OwnerId = ObjDesc->Method.OwnerId;
389
390 /* Push start scope on scope stack and make it current */
391
392 Status = AcpiDsScopeStackPush (Method,
393 Method->Type, WalkState);
394 if (ACPI_FAILURE (Status))
395 {
396 return (Status);
397 }
398
399 /* Parse the entire method AML including deferred operators */
400
401 WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE;
402 WalkState->ParseFlags |= ACPI_PARSE_DISASSEMBLE;
403
404 Status = AcpiPsParseAml (WalkState);
405 (void) AcpiDmParseDeferredOps (Op);
406
407 /* Now we can disassemble the method */
408
409 AcpiGbl_DmOpt_Verbose = FALSE;
410 AcpiDmDisassemble (NULL, Op, 0);
411 AcpiGbl_DmOpt_Verbose = TRUE;
412
413 AcpiPsDeleteParseTree (Op);
414
415 /* Method cleanup */
416
417 AcpiNsDeleteNamespaceSubtree (Method);
418 AcpiNsDeleteNamespaceByOwner (ObjDesc->Method.OwnerId);
419 AcpiUtReleaseOwnerId (&ObjDesc->Method.OwnerId);
420 return (AE_OK);
421 }
422 #endif
423
424
425 /*******************************************************************************
426 *
427 * FUNCTION: AcpiDbWalkForExecute
428 *
429 * PARAMETERS: Callback from WalkNamespace
430 *
431 * RETURN: Status
432 *
433 * DESCRIPTION: Batch execution module. Currently only executes predefined
434 * ACPI names.
435 *
436 ******************************************************************************/
437
438 static ACPI_STATUS
439 AcpiDbWalkForExecute (
440 ACPI_HANDLE ObjHandle,
441 UINT32 NestingLevel,
442 void *Context,
443 void **ReturnValue)
444 {
445 ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
446 ACPI_DB_EXECUTE_WALK *Info = (ACPI_DB_EXECUTE_WALK *) Context;
447 ACPI_BUFFER ReturnObj;
448 ACPI_STATUS Status;
449 char *Pathname;
450 UINT32 i;
451 ACPI_DEVICE_INFO *ObjInfo;
452 ACPI_OBJECT_LIST ParamObjects;
453 ACPI_OBJECT Params[ACPI_METHOD_NUM_ARGS];
454 const ACPI_PREDEFINED_INFO *Predefined;
455
456
457 Predefined = AcpiUtMatchPredefinedMethod (Node->Name.Ascii);
458 if (!Predefined)
459 {
460 return (AE_OK);
461 }
462
463 if (Node->Type == ACPI_TYPE_LOCAL_SCOPE)
464 {
465 return (AE_OK);
466 }
467
468 Pathname = AcpiNsGetExternalPathname (Node);
469 if (!Pathname)
470 {
471 return (AE_OK);
472 }
473
474 /* Get the object info for number of method parameters */
475
476 Status = AcpiGetObjectInfo (ObjHandle, &ObjInfo);
477 if (ACPI_FAILURE (Status))
478 {
479 ACPI_FREE (Pathname);
480 return (Status);
481 }
482
483 ParamObjects.Pointer = NULL;
484 ParamObjects.Count = 0;
485
486 if (ObjInfo->Type == ACPI_TYPE_METHOD)
487 {
488 /* Setup default parameters */
489
490 for (i = 0; i < ObjInfo->ParamCount; i++)
491 {
492 Params[i].Type = ACPI_TYPE_INTEGER;
493 Params[i].Integer.Value = 1;
494 }
495
496 ParamObjects.Pointer = Params;
497 ParamObjects.Count = ObjInfo->ParamCount;
498 }
499
500 ACPI_FREE (ObjInfo);
501 ReturnObj.Pointer = NULL;
502 ReturnObj.Length = ACPI_ALLOCATE_BUFFER;
503
504 /* Do the actual method execution */
505
506 AcpiGbl_MethodExecuting = TRUE;
507
508 Status = AcpiEvaluateObject (Node, NULL, &ParamObjects, &ReturnObj);
509
510 AcpiOsPrintf ("%-32s returned %s\n", Pathname, AcpiFormatException (Status));
511 AcpiGbl_MethodExecuting = FALSE;
512 ACPI_FREE (Pathname);
513
514 /* Ignore status from method execution */
515
516 Status = AE_OK;
517
518 /* Update count, check if we have executed enough methods */
519
520 Info->Count++;
521 if (Info->Count >= Info->MaxCount)
522 {
523 Status = AE_CTRL_TERMINATE;
524 }
525
526 return (Status);
527 }
528
529
530 /*******************************************************************************
531 *
532 * FUNCTION: AcpiDbEvaluatePredefinedNames
533 *
534 * PARAMETERS: None
535 *
536 * RETURN: None
537 *
538 * DESCRIPTION: Namespace batch execution. Execute predefined names in the
539 * namespace, up to the max count, if specified.
540 *
541 ******************************************************************************/
542
543 void
544 AcpiDbEvaluatePredefinedNames (
545 void)
546 {
547 ACPI_DB_EXECUTE_WALK Info;
548
549
550 Info.Count = 0;
551 Info.MaxCount = ACPI_UINT32_MAX;
552
553 /* Search all nodes in namespace */
554
555 (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
556 AcpiDbWalkForExecute, NULL, (void *) &Info, NULL);
557
558 AcpiOsPrintf ("Evaluated %u predefined names in the namespace\n", Info.Count);
559 }
560