dbinput.c revision 80062
1181834Sroberto/******************************************************************************* 2181834Sroberto * 3181834Sroberto * Module Name: dbinput - user front-end to the AML debugger 4181834Sroberto * $Revision: 62 $ 5181834Sroberto * 6181834Sroberto ******************************************************************************/ 7181834Sroberto 8181834Sroberto/****************************************************************************** 9181834Sroberto * 10181834Sroberto * 1. Copyright Notice 11181834Sroberto * 12181834Sroberto * Some or all of this work - Copyright (c) 1999, 2000, 2001, Intel Corp. 13181834Sroberto * All rights reserved. 14181834Sroberto * 15181834Sroberto * 2. License 16181834Sroberto * 17181834Sroberto * 2.1. This is your license from Intel Corp. under its intellectual property 18181834Sroberto * rights. You may have additional license terms from the party that provided 19181834Sroberto * you this software, covering your right to use that party's intellectual 20181834Sroberto * property rights. 21181834Sroberto * 22181834Sroberto * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 23181834Sroberto * copy of the source code appearing in this file ("Covered Code") an 24181834Sroberto * irrevocable, perpetual, worldwide license under Intel's copyrights in the 25181834Sroberto * base code distributed originally by Intel ("Original Intel Code") to copy, 26181834Sroberto * make derivatives, distribute, use and display any portion of the Covered 27181834Sroberto * Code in any form, with the right to sublicense such rights; and 28181834Sroberto * 29181834Sroberto * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 30181834Sroberto * license (with the right to sublicense), under only those claims of Intel 31181834Sroberto * patents that are infringed by the Original Intel Code, to make, use, sell, 32181834Sroberto * offer to sell, and import the Covered Code and derivative works thereof 33181834Sroberto * solely to the minimum extent necessary to exercise the above copyright 34181834Sroberto * license, and in no event shall the patent license extend to any additions 35181834Sroberto * to or modifications of the Original Intel Code. No other license or right 36181834Sroberto * is granted directly or by implication, estoppel or otherwise; 37181834Sroberto * 38181834Sroberto * The above copyright and patent license is granted only if the following 39181834Sroberto * conditions are met: 40181834Sroberto * 41181834Sroberto * 3. Conditions 42181834Sroberto * 43181834Sroberto * 3.1. Redistribution of Source with Rights to Further Distribute Source. 44181834Sroberto * Redistribution of source code of any substantial portion of the Covered 45181834Sroberto * Code or modification with rights to further distribute source must include 46181834Sroberto * the above Copyright Notice, the above License, this list of Conditions, 47181834Sroberto * and the following Disclaimer and Export Compliance provision. In addition, 48181834Sroberto * Licensee must cause all Covered Code to which Licensee contributes to 49181834Sroberto * contain a file documenting the changes Licensee made to create that Covered 50181834Sroberto * Code and the date of any change. Licensee must include in that file the 51181834Sroberto * documentation of any changes made by any predecessor Licensee. Licensee 52181834Sroberto * must include a prominent statement that the modification is derived, 53181834Sroberto * directly or indirectly, from Original Intel Code. 54181834Sroberto * 55181834Sroberto * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 56181834Sroberto * Redistribution of source code of any substantial portion of the Covered 57181834Sroberto * Code or modification without rights to further distribute source must 58181834Sroberto * include the following Disclaimer and Export Compliance provision in the 59181834Sroberto * documentation and/or other materials provided with distribution. In 60181834Sroberto * addition, Licensee may not authorize further sublicense of source of any 61181834Sroberto * portion of the Covered Code, and must include terms to the effect that the 62181834Sroberto * license from Licensee to its licensee is limited to the intellectual 63181834Sroberto * property embodied in the software Licensee provides to its licensee, and 64181834Sroberto * not to intellectual property embodied in modifications its licensee may 65181834Sroberto * make. 66181834Sroberto * 67181834Sroberto * 3.3. Redistribution of Executable. Redistribution in executable form of any 68181834Sroberto * substantial portion of the Covered Code or modification must reproduce the 69181834Sroberto * above Copyright Notice, and the following Disclaimer and Export Compliance 70181834Sroberto * provision in the documentation and/or other materials provided with the 71181834Sroberto * distribution. 72181834Sroberto * 73181834Sroberto * 3.4. Intel retains all right, title, and interest in and to the Original 74181834Sroberto * Intel Code. 75181834Sroberto * 76181834Sroberto * 3.5. Neither the name Intel nor any other trademark owned or controlled by 77181834Sroberto * Intel shall be used in advertising or otherwise to promote the sale, use or 78181834Sroberto * other dealings in products derived from or relating to the Covered Code 79181834Sroberto * without prior written authorization from Intel. 80181834Sroberto * 81181834Sroberto * 4. Disclaimer and Export Compliance 82181834Sroberto * 83181834Sroberto * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 84181834Sroberto * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 85181834Sroberto * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 86181834Sroberto * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 87181834Sroberto * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 88181834Sroberto * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 89181834Sroberto * PARTICULAR PURPOSE. 90181834Sroberto * 91181834Sroberto * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 92181834Sroberto * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 93181834Sroberto * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 94181834Sroberto * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 95181834Sroberto * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 96181834Sroberto * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 97181834Sroberto * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 98181834Sroberto * LIMITED REMEDY. 99181834Sroberto * 100181834Sroberto * 4.3. Licensee shall not export, either directly or indirectly, any of this 101181834Sroberto * software or system incorporating such software without first obtaining any 102181834Sroberto * required license or other approval from the U. S. Department of Commerce or 103181834Sroberto * any other agency or department of the United States Government. In the 104181834Sroberto * event Licensee exports any such software from the United States or 105181834Sroberto * re-exports any such software from a foreign destination, Licensee shall 106181834Sroberto * ensure that the distribution and export/re-export of the software is in 107181834Sroberto * compliance with all laws, regulations, orders, or other restrictions of the 108181834Sroberto * U.S. Export Administration Regulations. Licensee agrees that neither it nor 109181834Sroberto * any of its subsidiaries will export/re-export any technical data, process, 110181834Sroberto * software, or service, directly or indirectly, to any country for which the 111181834Sroberto * United States government or any agency thereof requires an export license, 112181834Sroberto * other governmental approval, or letter of assurance, without first obtaining 113181834Sroberto * such license, approval or letter. 114181834Sroberto * 115181834Sroberto *****************************************************************************/ 116181834Sroberto 117181834Sroberto 118181834Sroberto#include "acpi.h" 119181834Sroberto#include "acparser.h" 120181834Sroberto#include "actables.h" 121181834Sroberto#include "acnamesp.h" 122181834Sroberto#include "acinterp.h" 123181834Sroberto#include "acdebug.h" 124181834Sroberto 125181834Sroberto 126181834Sroberto#ifdef ENABLE_DEBUGGER 127181834Sroberto 128181834Sroberto#define _COMPONENT ACPI_DEBUGGER 129181834Sroberto MODULE_NAME ("dbinput") 130181834Sroberto 131181834Sroberto 132181834Sroberto/* 133181834Sroberto * Globals that are specific to the debugger 134181834Sroberto */ 135181834Sroberto 136181834SrobertoNATIVE_CHAR LineBuf[80]; 137181834SrobertoNATIVE_CHAR ParsedBuf[80]; 138181834SrobertoNATIVE_CHAR ScopeBuf[40]; 139181834SrobertoNATIVE_CHAR DebugFilename[40]; 140181834SrobertoNATIVE_CHAR *Args[DB_MAX_ARGS]; 141181834SrobertoNATIVE_CHAR *Buffer; 142181834SrobertoNATIVE_CHAR *Filename = NULL; 143181834SrobertoBOOLEAN OutputToFile = FALSE; 144181834Sroberto 145181834Sroberto 146181834SrobertoUINT32 AcpiGbl_DbDebugLevel = 0x0FFFFFFF; 147181834SrobertoUINT32 AcpiGbl_DbConsoleDebugLevel = NORMAL_DEFAULT | TRACE_TABLES; 148181834SrobertoUINT8 AcpiGbl_DbOutputFlags = DB_CONSOLE_OUTPUT; 149181834Sroberto 150181834Sroberto 151181834SrobertoBOOLEAN opt_tables = FALSE; 152181834SrobertoBOOLEAN opt_disasm = FALSE; 153181834SrobertoBOOLEAN opt_stats = FALSE; 154181834SrobertoBOOLEAN opt_parse_jit = FALSE; 155181834SrobertoBOOLEAN opt_verbose = TRUE; 156181834SrobertoBOOLEAN opt_ini_methods = TRUE; 157181834Sroberto 158181834Sroberto 159181834Sroberto/* 160181834Sroberto * Top-level debugger commands. 161181834Sroberto * 162181834Sroberto * This list of commands must match the string table below it 163181834Sroberto */ 164181834Sroberto 165181834Srobertoenum AcpiExDebuggerCommands 166181834Sroberto{ 167181834Sroberto CMD_NOT_FOUND = 0, 168181834Sroberto CMD_NULL, 169181834Sroberto CMD_ALLOCATIONS, 170181834Sroberto CMD_ARGS, 171181834Sroberto CMD_ARGUMENTS, 172181834Sroberto CMD_BREAKPOINT, 173181834Sroberto CMD_CALL, 174181834Sroberto CMD_CLOSE, 175181834Sroberto CMD_DEBUG, 176181834Sroberto CMD_DUMP, 177181834Sroberto CMD_ENABLEACPI, 178181834Sroberto CMD_EVENT, 179181834Sroberto CMD_EXECUTE, 180181834Sroberto CMD_EXIT, 181181834Sroberto CMD_FIND, 182181834Sroberto CMD_GO, 183181834Sroberto CMD_HELP, 184181834Sroberto CMD_HELP2, 185181834Sroberto CMD_HISTORY, 186181834Sroberto CMD_HISTORY_EXE, 187181834Sroberto CMD_HISTORY_LAST, 188181834Sroberto CMD_INFORMATION, 189181834Sroberto CMD_INTO, 190181834Sroberto CMD_LEVEL, 191181834Sroberto CMD_LIST, 192181834Sroberto CMD_LOAD, 193181834Sroberto CMD_LOCALS, 194181834Sroberto CMD_LOCKS, 195181834Sroberto CMD_METHODS, 196181834Sroberto CMD_NAMESPACE, 197181834Sroberto CMD_NOTIFY, 198181834Sroberto CMD_OBJECT, 199181834Sroberto CMD_OPEN, 200181834Sroberto CMD_OWNER, 201181834Sroberto CMD_PREFIX, 202181834Sroberto CMD_QUIT, 203181834Sroberto CMD_REFERENCES, 204181834Sroberto CMD_RESOURCES, 205181834Sroberto CMD_RESULTS, 206181834Sroberto CMD_SET, 207181834Sroberto CMD_STATS, 208181834Sroberto CMD_STOP, 209181834Sroberto CMD_TABLES, 210181834Sroberto CMD_TERMINATE, 211181834Sroberto CMD_THREADS, 212181834Sroberto CMD_TREE, 213181834Sroberto CMD_UNLOAD 214181834Sroberto}; 215181834Sroberto 216181834Sroberto#define CMD_FIRST_VALID 2 217181834Sroberto 218181834Sroberto 219181834SrobertoCOMMAND_INFO Commands[] = 220181834Sroberto{ 221181834Sroberto {"<NOT FOUND>", 0}, 222181834Sroberto {"<NULL>", 0}, 223181834Sroberto {"ALLOCATIONS", 0}, 224181834Sroberto {"ARGS", 0}, 225181834Sroberto {"ARGUMENTS", 0}, 226181834Sroberto {"BREAKPOINT", 1}, 227181834Sroberto {"CALL", 0}, 228181834Sroberto {"CLOSE", 0}, 229181834Sroberto {"DEBUG", 1}, 230181834Sroberto {"DUMP", 1}, 231181834Sroberto {"ENABLEACPI", 0}, 232181834Sroberto {"EVENT", 1}, 233181834Sroberto {"EXECUTE", 1}, 234181834Sroberto {"EXIT", 0}, 235181834Sroberto {"FIND", 1}, 236181834Sroberto {"GO", 0}, 237181834Sroberto {"HELP", 0}, 238181834Sroberto {"?", 0}, 239181834Sroberto {"HISTORY", 0}, 240181834Sroberto {"!", 1}, 241181834Sroberto {"!!", 0}, 242181834Sroberto {"INFORMATION", 0}, 243181834Sroberto {"INTO", 0}, 244181834Sroberto {"LEVEL", 0}, 245181834Sroberto {"LIST", 0}, 246181834Sroberto {"LOAD", 1}, 247181834Sroberto {"LOCALS", 0}, 248181834Sroberto {"LOCKS", 0}, 249181834Sroberto {"METHODS", 0}, 250181834Sroberto {"NAMESPACE", 0}, 251181834Sroberto {"NOTIFY", 2}, 252181834Sroberto {"OBJECT", 1}, 253181834Sroberto {"OPEN", 1}, 254181834Sroberto {"OWNER", 1}, 255181834Sroberto {"PREFIX", 0}, 256181834Sroberto {"QUIT", 0}, 257181834Sroberto {"REFERENCES", 1}, 258181834Sroberto {"RESOURCES", 1}, 259181834Sroberto {"RESULTS", 0}, 260181834Sroberto {"SET", 3}, 261181834Sroberto {"STATS", 0}, 262181834Sroberto {"STOP", 0}, 263181834Sroberto {"TABLES", 0}, 264181834Sroberto {"TERMINATE", 0}, 265181834Sroberto {"THREADS", 3}, 266181834Sroberto {"TREE", 0}, 267181834Sroberto {"UNLOAD", 0}, 268181834Sroberto {NULL, 0} 269181834Sroberto}; 270181834Sroberto 271181834Sroberto 272181834Sroberto/******************************************************************************* 273181834Sroberto * 274181834Sroberto * FUNCTION: AcpiDbDisplayHelp 275181834Sroberto * 276181834Sroberto * PARAMETERS: HelpType - Subcommand (optional) 277181834Sroberto * 278181834Sroberto * RETURN: None 279181834Sroberto * 280181834Sroberto * DESCRIPTION: Print a usage message. 281181834Sroberto * 282181834Sroberto ******************************************************************************/ 283181834Sroberto 284181834Srobertovoid 285181834SrobertoAcpiDbDisplayHelp ( 286181834Sroberto NATIVE_CHAR *HelpType) 287181834Sroberto{ 288181834Sroberto 289181834Sroberto 290181834Sroberto /* No parameter, just give the overview */ 291181834Sroberto 292181834Sroberto if (!HelpType) 293181834Sroberto { 294181834Sroberto AcpiOsPrintf ("ACPI CA Debugger Commands\n\n"); 295181834Sroberto AcpiOsPrintf ("The following classes of commands are available. Help is available for\n"); 296181834Sroberto AcpiOsPrintf ("each class by entering \"Help <ClassName>\"\n\n"); 297181834Sroberto AcpiOsPrintf (" [GENERAL] General-Purpose Commands\n"); 298181834Sroberto AcpiOsPrintf (" [NAMESPACE] Namespace Access Commands\n"); 299181834Sroberto AcpiOsPrintf (" [METHOD] Control Method Execution Commands\n"); 300181834Sroberto AcpiOsPrintf (" [FILE] File I/O Commands\n"); 301181834Sroberto return; 302181834Sroberto 303181834Sroberto } 304181834Sroberto 305181834Sroberto 306181834Sroberto /* 307181834Sroberto * Parameter is the command class 308181834Sroberto * 309181834Sroberto * The idea here is to keep each class of commands smaller than a screenful 310181834Sroberto */ 311181834Sroberto 312181834Sroberto switch (HelpType[0]) 313181834Sroberto { 314181834Sroberto case 'G': 315181834Sroberto AcpiOsPrintf ("\nGeneral-Purpose Commands\n\n"); 316181834Sroberto AcpiOsPrintf ("Allocations Display list of current memory allocations\n"); 317181834Sroberto AcpiOsPrintf ("Dump <Address>|<Namepath>\n"); 318181834Sroberto AcpiOsPrintf (" [Byte|Word|Dword|Qword] Display ACPI objects or memory\n"); 319181834Sroberto AcpiOsPrintf ("EnableAcpi Enable ACPI (hardware) mode\n"); 320181834Sroberto AcpiOsPrintf ("Help This help screen\n"); 321181834Sroberto AcpiOsPrintf ("History Display command history buffer\n"); 322181834Sroberto AcpiOsPrintf ("Level [<DebugLevel>] [console] Get/Set debug level for file or console\n"); 323181834Sroberto AcpiOsPrintf ("Locks Current status of internal mutexes\n"); 324181834Sroberto AcpiOsPrintf ("Quit or Exit Exit this command\n"); 325181834Sroberto AcpiOsPrintf ("Stats [Allocations|Memory|Misc\n"); 326181834Sroberto AcpiOsPrintf (" |Objects|Tables] Display namespace and memory statistics\n"); 327181834Sroberto AcpiOsPrintf ("Tables Display info about loaded ACPI tables\n"); 328181834Sroberto AcpiOsPrintf ("Unload Unload an ACPI table\n"); 329181834Sroberto AcpiOsPrintf ("! <CommandNumber> Execute command from history buffer\n"); 330181834Sroberto AcpiOsPrintf ("!! Execute last command again\n"); 331181834Sroberto return; 332181834Sroberto 333181834Sroberto case 'N': 334181834Sroberto AcpiOsPrintf ("\nNamespace Access Commands\n\n"); 335181834Sroberto AcpiOsPrintf ("Debug <Namepath> [Arguments] Single Step a control method\n"); 336181834Sroberto AcpiOsPrintf ("Event <F|G> <Value> Generate AcpiEvent (Fixed/GPE)\n"); 337181834Sroberto AcpiOsPrintf ("Execute <Namepath> [Arguments] Execute control method\n"); 338181834Sroberto AcpiOsPrintf ("Find <Name> (? is wildcard) Find ACPI name(s) with wildcards\n"); 339181834Sroberto AcpiOsPrintf ("Method Display list of loaded control methods\n"); 340181834Sroberto AcpiOsPrintf ("Namespace [<Addr>|<Path>] [Depth] Display loaded namespace tree/subtree\n"); 341181834Sroberto AcpiOsPrintf ("Notify <NamePath> <Value> Send a notification\n"); 342181834Sroberto AcpiOsPrintf ("Objects <ObjectType> Display all objects of the given type\n"); 343181834Sroberto AcpiOsPrintf ("Owner <OwnerId> [Depth] Display loaded namespace by object owner\n"); 344181834Sroberto AcpiOsPrintf ("Prefix [<NamePath>] Set or Get current execution prefix\n"); 345181834Sroberto AcpiOsPrintf ("References <Addr> Find all references to object at addr\n"); 346181834Sroberto AcpiOsPrintf ("Resources xxx Get and display resources\n"); 347181834Sroberto AcpiOsPrintf ("Terminate Delete namespace and all internal objects\n"); 348181834Sroberto AcpiOsPrintf ("Thread <Threads><Loops><NamePath> Spawn threads to execute method(s)\n"); 349181834Sroberto return; 350181834Sroberto 351181834Sroberto case 'M': 352181834Sroberto AcpiOsPrintf ("\nControl Method Execution Commands\n\n"); 353181834Sroberto AcpiOsPrintf ("Arguments (or Args) Display method arguments\n"); 354181834Sroberto AcpiOsPrintf ("Breakpoint <AmlOffset> Set an AML execution breakpoint\n"); 355181834Sroberto AcpiOsPrintf ("Call Run to next control method invocation\n"); 356181834Sroberto AcpiOsPrintf ("Go Allow method to run to completion\n"); 357181834Sroberto AcpiOsPrintf ("Information Display info about the current method\n"); 358181834Sroberto AcpiOsPrintf ("Into Step into (not over) a method call\n"); 359181834Sroberto AcpiOsPrintf ("List [# of Aml Opcodes] Display method ASL statements\n"); 360181834Sroberto AcpiOsPrintf ("Locals Display method local variables\n"); 361181834Sroberto AcpiOsPrintf ("Results Display method result stack\n"); 362181834Sroberto AcpiOsPrintf ("Set <A|L> <#> <Value> Set method data (Arguments/Locals)\n"); 363181834Sroberto AcpiOsPrintf ("Stop Terminate control method\n"); 364181834Sroberto AcpiOsPrintf ("Tree Display control method calling tree\n"); 365181834Sroberto AcpiOsPrintf ("<Enter> Single step next AML opcode (over calls)\n"); 366181834Sroberto return; 367181834Sroberto 368181834Sroberto case 'F': 369181834Sroberto AcpiOsPrintf ("\nFile I/O Commands\n\n"); 370181834Sroberto AcpiOsPrintf ("Close Close debug output file\n"); 371181834Sroberto AcpiOsPrintf ("Open <Output Filename> Open a file for debug output\n"); 372181834Sroberto AcpiOsPrintf ("Load <Input Filename> Load ACPI table from a file\n"); 373181834Sroberto return; 374181834Sroberto 375181834Sroberto default: 376181834Sroberto AcpiOsPrintf ("Unrecognized Command Class: %x\n", HelpType); 377181834Sroberto return; 378181834Sroberto } 379181834Sroberto} 380181834Sroberto 381181834Sroberto 382181834Sroberto/******************************************************************************* 383181834Sroberto * 384181834Sroberto * FUNCTION: AcpiDbGetNextToken 385181834Sroberto * 386181834Sroberto * PARAMETERS: String - Command buffer 387181834Sroberto * Next - Return value, end of next token 388181834Sroberto * 389181834Sroberto * RETURN: Pointer to the start of the next token. 390181834Sroberto * 391181834Sroberto * DESCRIPTION: Command line parsing. Get the next token on the command line 392181834Sroberto * 393181834Sroberto ******************************************************************************/ 394181834Sroberto 395181834SrobertoNATIVE_CHAR * 396181834SrobertoAcpiDbGetNextToken ( 397181834Sroberto NATIVE_CHAR *String, 398181834Sroberto NATIVE_CHAR **Next) 399181834Sroberto{ 400181834Sroberto NATIVE_CHAR *Start; 401181834Sroberto 402181834Sroberto /* At end of buffer? */ 403181834Sroberto 404181834Sroberto if (!String || !(*String)) 405181834Sroberto { 406181834Sroberto return (NULL); 407181834Sroberto } 408181834Sroberto 409181834Sroberto 410181834Sroberto /* Get rid of any spaces at the beginning */ 411181834Sroberto 412181834Sroberto if (*String == ' ') 413181834Sroberto { 414181834Sroberto while (*String && (*String == ' ')) 415181834Sroberto { 416181834Sroberto String++; 417181834Sroberto } 418181834Sroberto 419181834Sroberto if (!(*String)) 420181834Sroberto { 421181834Sroberto return (NULL); 422181834Sroberto } 423181834Sroberto } 424181834Sroberto 425181834Sroberto Start = String; 426181834Sroberto 427181834Sroberto /* Find end of token */ 428181834Sroberto 429181834Sroberto while (*String && (*String != ' ')) 430181834Sroberto { 431181834Sroberto String++; 432181834Sroberto } 433181834Sroberto 434181834Sroberto 435181834Sroberto if (!(*String)) 436181834Sroberto { 437181834Sroberto *Next = NULL; 438181834Sroberto } 439181834Sroberto 440181834Sroberto else 441181834Sroberto { 442181834Sroberto *String = 0; 443181834Sroberto *Next = String + 1; 444181834Sroberto } 445181834Sroberto 446181834Sroberto return (Start); 447181834Sroberto} 448181834Sroberto 449181834Sroberto 450181834Sroberto/******************************************************************************* 451181834Sroberto * 452181834Sroberto * FUNCTION: AcpiDbGetLine 453181834Sroberto * 454181834Sroberto * PARAMETERS: InputBuffer - Command line buffer 455181834Sroberto * 456181834Sroberto * RETURN: None 457181834Sroberto * 458181834Sroberto * DESCRIPTION: Get the next command line from the user. Gets entire line 459181834Sroberto * up to the next newline 460181834Sroberto * 461181834Sroberto ******************************************************************************/ 462181834Sroberto 463181834SrobertoUINT32 464181834SrobertoAcpiDbGetLine ( 465181834Sroberto NATIVE_CHAR *InputBuffer) 466181834Sroberto{ 467181834Sroberto UINT32 i; 468181834Sroberto UINT32 Count; 469181834Sroberto NATIVE_CHAR *Next; 470181834Sroberto NATIVE_CHAR *This; 471181834Sroberto 472181834Sroberto 473181834Sroberto STRCPY (ParsedBuf, InputBuffer); 474181834Sroberto STRUPR (ParsedBuf); 475181834Sroberto 476181834Sroberto This = ParsedBuf; 477181834Sroberto for (i = 0; i < DB_MAX_ARGS; i++) 478181834Sroberto { 479181834Sroberto Args[i] = AcpiDbGetNextToken (This, &Next); 480181834Sroberto if (!Args[i]) 481181834Sroberto { 482181834Sroberto break; 483181834Sroberto } 484181834Sroberto 485181834Sroberto This = Next; 486181834Sroberto } 487181834Sroberto 488181834Sroberto 489181834Sroberto /* Uppercase the actual command */ 490181834Sroberto 491181834Sroberto if (Args[0]) 492181834Sroberto { 493181834Sroberto STRUPR (Args[0]); 494181834Sroberto } 495181834Sroberto 496181834Sroberto Count = i; 497181834Sroberto if (Count) 498181834Sroberto { 499181834Sroberto Count--; /* Number of args only */ 500181834Sroberto } 501181834Sroberto 502181834Sroberto return (Count); 503181834Sroberto} 504181834Sroberto 505181834Sroberto 506181834Sroberto/******************************************************************************* 507181834Sroberto * 508181834Sroberto * FUNCTION: AcpiDbMatchCommand 509181834Sroberto * 510181834Sroberto * PARAMETERS: UserCommand - User command line 511181834Sroberto * 512181834Sroberto * RETURN: Index into command array, -1 if not found 513181834Sroberto * 514181834Sroberto * DESCRIPTION: Search command array for a command match 515181834Sroberto * 516181834Sroberto ******************************************************************************/ 517181834Sroberto 518181834SrobertoUINT32 519181834SrobertoAcpiDbMatchCommand ( 520181834Sroberto NATIVE_CHAR *UserCommand) 521181834Sroberto{ 522181834Sroberto UINT32 i; 523181834Sroberto 524181834Sroberto 525181834Sroberto if (!UserCommand || UserCommand[0] == 0) 526181834Sroberto { 527181834Sroberto return (CMD_NULL); 528181834Sroberto } 529181834Sroberto 530181834Sroberto for (i = CMD_FIRST_VALID; Commands[i].Name; i++) 531181834Sroberto { 532181834Sroberto if (STRSTR (Commands[i].Name, UserCommand) == Commands[i].Name) 533181834Sroberto { 534181834Sroberto return (i); 535181834Sroberto } 536181834Sroberto } 537181834Sroberto 538181834Sroberto /* Command not recognized */ 539181834Sroberto 540181834Sroberto return (CMD_NOT_FOUND); 541181834Sroberto} 542181834Sroberto 543181834Sroberto 544181834Sroberto/******************************************************************************* 545181834Sroberto * 546181834Sroberto * FUNCTION: AcpiDbCommandDispatch 547181834Sroberto * 548181834Sroberto * PARAMETERS: InputBuffer - Command line buffer 549181834Sroberto * WalkState - Current walk 550181834Sroberto * Op - Current (executing) parse op 551181834Sroberto * 552181834Sroberto * RETURN: Status 553181834Sroberto * 554181834Sroberto * DESCRIPTION: Command dispatcher. Called from two places: 555181834Sroberto * 556181834Sroberto ******************************************************************************/ 557181834Sroberto 558181834SrobertoACPI_STATUS 559181834SrobertoAcpiDbCommandDispatch ( 560181834Sroberto NATIVE_CHAR *InputBuffer, 561181834Sroberto ACPI_WALK_STATE *WalkState, 562181834Sroberto ACPI_PARSE_OBJECT *Op) 563181834Sroberto{ 564181834Sroberto UINT32 Temp; 565181834Sroberto UINT32 CommandIndex; 566181834Sroberto UINT32 ParamCount; 567181834Sroberto NATIVE_CHAR *CommandLine; 568181834Sroberto ACPI_STATUS Status = AE_CTRL_TRUE; 569181834Sroberto 570181834Sroberto 571181834Sroberto /* If AcpiTerminate has been called, terminate this thread */ 572181834Sroberto 573181834Sroberto if (AcpiGbl_DbTerminateThreads) 574181834Sroberto { 575181834Sroberto return (AE_CTRL_TERMINATE); 576181834Sroberto } 577181834Sroberto 578181834Sroberto ParamCount = AcpiDbGetLine (InputBuffer); 579181834Sroberto CommandIndex = AcpiDbMatchCommand (Args[0]); 580181834Sroberto Temp = 0; 581181834Sroberto 582181834Sroberto /* Verify that we have the minimum number of params */ 583181834Sroberto 584181834Sroberto if (ParamCount < Commands[CommandIndex].MinArgs) 585181834Sroberto { 586181834Sroberto AcpiOsPrintf ("%d parameters entered, [%s] requires %d parameters\n", 587181834Sroberto ParamCount, Commands[CommandIndex].Name, Commands[CommandIndex].MinArgs); 588181834Sroberto return (AE_CTRL_TRUE); 589181834Sroberto } 590181834Sroberto 591181834Sroberto /* Decode and dispatch the command */ 592181834Sroberto 593181834Sroberto switch (CommandIndex) 594181834Sroberto { 595181834Sroberto case CMD_NULL: 596181834Sroberto if (Op) 597181834Sroberto { 598181834Sroberto return (AE_OK); 599181834Sroberto } 600181834Sroberto break; 601181834Sroberto 602181834Sroberto case CMD_ALLOCATIONS: 603181834Sroberto#ifdef ACPI_DBG_TRACK_ALLOCATIONS 604181834Sroberto AcpiUtDumpCurrentAllocations ((UINT32) -1, NULL); 605181834Sroberto#endif 606181834Sroberto break; 607181834Sroberto 608181834Sroberto case CMD_ARGS: 609181834Sroberto case CMD_ARGUMENTS: 610181834Sroberto AcpiDbDisplayArguments (); 611181834Sroberto break; 612181834Sroberto 613181834Sroberto case CMD_BREAKPOINT: 614181834Sroberto AcpiDbSetMethodBreakpoint (Args[1], WalkState, Op); 615181834Sroberto break; 616181834Sroberto 617181834Sroberto case CMD_CALL: 618181834Sroberto AcpiDbSetMethodCallBreakpoint (Op); 619181834Sroberto Status = AE_OK; 620181834Sroberto break; 621181834Sroberto 622181834Sroberto case CMD_CLOSE: 623181834Sroberto AcpiDbCloseDebugFile (); 624181834Sroberto break; 625181834Sroberto 626181834Sroberto case CMD_DEBUG: 627181834Sroberto AcpiDbExecute (Args[1], &Args[2], EX_SINGLE_STEP); 628181834Sroberto break; 629181834Sroberto 630181834Sroberto case CMD_DUMP: 631181834Sroberto AcpiDbDecodeAndDisplayObject (Args[1], Args[2]); 632181834Sroberto break; 633181834Sroberto 634181834Sroberto case CMD_ENABLEACPI: 635181834Sroberto Status = AcpiEnable(); 636181834Sroberto if (ACPI_FAILURE(Status)) 637181834Sroberto { 638181834Sroberto AcpiOsPrintf("AcpiEnable failed (Status=%X)\n", Status); 639181834Sroberto return (Status); 640181834Sroberto } 641181834Sroberto break; 642181834Sroberto 643181834Sroberto case CMD_EVENT: 644181834Sroberto AcpiOsPrintf ("Event command not implemented\n"); 645181834Sroberto break; 646181834Sroberto 647181834Sroberto case CMD_EXECUTE: 648181834Sroberto AcpiDbExecute (Args[1], &Args[2], EX_NO_SINGLE_STEP); 649181834Sroberto break; 650181834Sroberto 651181834Sroberto case CMD_FIND: 652181834Sroberto AcpiDbFindNameInNamespace (Args[1]); 653181834Sroberto break; 654181834Sroberto 655181834Sroberto case CMD_GO: 656181834Sroberto AcpiGbl_CmSingleStep = FALSE; 657181834Sroberto return (AE_OK); 658181834Sroberto 659181834Sroberto case CMD_HELP: 660181834Sroberto case CMD_HELP2: 661181834Sroberto AcpiDbDisplayHelp (Args[1]); 662181834Sroberto break; 663181834Sroberto 664181834Sroberto case CMD_HISTORY: 665181834Sroberto AcpiDbDisplayHistory (); 666181834Sroberto break; 667181834Sroberto 668181834Sroberto case CMD_HISTORY_EXE: 669181834Sroberto CommandLine = AcpiDbGetFromHistory (Args[1]); 670181834Sroberto if (!CommandLine) 671181834Sroberto { 672181834Sroberto return (AE_CTRL_TRUE); 673181834Sroberto } 674181834Sroberto 675181834Sroberto Status = AcpiDbCommandDispatch (CommandLine, WalkState, Op); 676181834Sroberto if (ACPI_SUCCESS (Status)) 677181834Sroberto { 678181834Sroberto Status = AE_CTRL_TRUE; 679181834Sroberto } 680181834Sroberto return (Status); 681181834Sroberto break; 682181834Sroberto 683181834Sroberto case CMD_HISTORY_LAST: 684181834Sroberto CommandLine = AcpiDbGetFromHistory (NULL); 685181834Sroberto if (!CommandLine) 686181834Sroberto { 687181834Sroberto return (AE_CTRL_TRUE); 688181834Sroberto } 689181834Sroberto 690181834Sroberto Status = AcpiDbCommandDispatch (CommandLine, WalkState, Op); 691181834Sroberto if (ACPI_SUCCESS (Status)) 692181834Sroberto { 693181834Sroberto Status = AE_CTRL_TRUE; 694181834Sroberto } 695181834Sroberto return (Status); 696181834Sroberto 697181834Sroberto case CMD_INFORMATION: 698181834Sroberto AcpiDbDisplayMethodInfo (Op); 699181834Sroberto break; 700181834Sroberto 701181834Sroberto case CMD_INTO: 702181834Sroberto if (Op) 703181834Sroberto { 704181834Sroberto AcpiGbl_CmSingleStep = TRUE; 705181834Sroberto 706181834Sroberto/* TBD: Must get current walk state */ 707181834Sroberto /* AcpiGbl_MethodBreakpoint = 0; */ 708181834Sroberto return (AE_OK); 709181834Sroberto } 710181834Sroberto break; 711181834Sroberto 712181834Sroberto case CMD_LEVEL: 713181834Sroberto if (ParamCount == 0) 714181834Sroberto { 715181834Sroberto AcpiOsPrintf ("Current debug level for file output is: %8.8lX\n", AcpiGbl_DbDebugLevel); 716181834Sroberto AcpiOsPrintf ("Current debug level for console output is: %8.8lX\n", AcpiGbl_DbConsoleDebugLevel); 717181834Sroberto } 718181834Sroberto else if (ParamCount == 2) 719181834Sroberto { 720181834Sroberto Temp = AcpiGbl_DbConsoleDebugLevel; 721181834Sroberto AcpiGbl_DbConsoleDebugLevel = STRTOUL (Args[1], NULL, 16); 722181834Sroberto AcpiOsPrintf ("Debug Level for console output was %8.8lX, now %8.8lX\n", Temp, AcpiGbl_DbConsoleDebugLevel); 723181834Sroberto } 724181834Sroberto else 725181834Sroberto { 726181834Sroberto Temp = AcpiGbl_DbDebugLevel; 727181834Sroberto AcpiGbl_DbDebugLevel = STRTOUL (Args[1], NULL, 16); 728181834Sroberto AcpiOsPrintf ("Debug Level for file output was %8.8lX, now %8.8lX\n", Temp, AcpiGbl_DbDebugLevel); 729181834Sroberto } 730181834Sroberto break; 731181834Sroberto 732181834Sroberto case CMD_LIST: 733181834Sroberto AcpiDbDisassembleAml (Args[1], Op); 734181834Sroberto break; 735181834Sroberto 736181834Sroberto case CMD_LOAD: 737181834Sroberto Status = AcpiDbLoadAcpiTable (Args[1]); 738181834Sroberto if (ACPI_FAILURE (Status)) 739181834Sroberto { 740181834Sroberto return (Status); 741181834Sroberto } 742181834Sroberto break; 743181834Sroberto 744181834Sroberto case CMD_LOCKS: 745181834Sroberto AcpiDbDisplayLocks (); 746181834Sroberto break; 747181834Sroberto 748181834Sroberto case CMD_LOCALS: 749181834Sroberto AcpiDbDisplayLocals (); 750181834Sroberto break; 751181834Sroberto 752181834Sroberto case CMD_METHODS: 753181834Sroberto AcpiDbDisplayObjects ("METHOD", Args[1]); 754181834Sroberto break; 755181834Sroberto 756181834Sroberto case CMD_NAMESPACE: 757181834Sroberto AcpiDbDumpNamespace (Args[1], Args[2]); 758181834Sroberto break; 759181834Sroberto 760181834Sroberto case CMD_NOTIFY: 761181834Sroberto Temp = STRTOUL (Args[2], NULL, 0); 762181834Sroberto AcpiDbSendNotify (Args[1], Temp); 763181834Sroberto break; 764181834Sroberto 765181834Sroberto case CMD_OBJECT: 766181834Sroberto AcpiDbDisplayObjects (STRUPR (Args[1]), Args[2]); 767181834Sroberto break; 768181834Sroberto 769181834Sroberto case CMD_OPEN: 770181834Sroberto AcpiDbOpenDebugFile (Args[1]); 771181834Sroberto break; 772181834Sroberto 773181834Sroberto case CMD_OWNER: 774181834Sroberto AcpiDbDumpNamespaceByOwner (Args[1], Args[2]); 775181834Sroberto break; 776181834Sroberto 777181834Sroberto case CMD_PREFIX: 778181834Sroberto AcpiDbSetScope (Args[1]); 779181834Sroberto break; 780181834Sroberto 781181834Sroberto case CMD_REFERENCES: 782181834Sroberto AcpiDbFindReferences (Args[1]); 783181834Sroberto break; 784181834Sroberto 785181834Sroberto case CMD_RESOURCES: 786181834Sroberto AcpiDbDisplayResources (Args[1]); 787181834Sroberto break; 788181834Sroberto 789181834Sroberto case CMD_RESULTS: 790181834Sroberto AcpiDbDisplayResults (); 791181834Sroberto break; 792181834Sroberto 793181834Sroberto case CMD_SET: 794181834Sroberto AcpiDbSetMethodData (Args[1], Args[2], Args[3]); 795181834Sroberto break; 796181834Sroberto 797181834Sroberto case CMD_STATS: 798181834Sroberto AcpiDbDisplayStatistics (Args[1]); 799181834Sroberto break; 800181834Sroberto 801181834Sroberto case CMD_STOP: 802181834Sroberto return (AE_AML_ERROR); 803181834Sroberto break; 804181834Sroberto 805181834Sroberto case CMD_TABLES: 806181834Sroberto AcpiDbDisplayTableInfo (Args[1]); 807181834Sroberto break; 808181834Sroberto 809181834Sroberto case CMD_TERMINATE: 810181834Sroberto AcpiDbSetOutputDestination (DB_REDIRECTABLE_OUTPUT); 811181834Sroberto AcpiUtSubsystemShutdown (); 812181834Sroberto 813181834Sroberto /* TBD: [Restructure] Need some way to re-initialize without re-creating the semaphores! */ 814181834Sroberto 815181834Sroberto /* AcpiInitialize (NULL); */ 816181834Sroberto break; 817181834Sroberto 818181834Sroberto case CMD_THREADS: 819181834Sroberto AcpiDbCreateExecutionThreads (Args[1], Args[2], Args[3]); 820181834Sroberto break; 821181834Sroberto 822181834Sroberto case CMD_TREE: 823181834Sroberto AcpiDbDisplayCallingTree (); 824181834Sroberto break; 825181834Sroberto 826181834Sroberto case CMD_UNLOAD: 827181834Sroberto AcpiDbUnloadAcpiTable (Args[1], Args[2]); 828181834Sroberto break; 829181834Sroberto 830181834Sroberto case CMD_EXIT: 831181834Sroberto case CMD_QUIT: 832181834Sroberto if (Op) 833181834Sroberto { 834181834Sroberto AcpiOsPrintf ("Method execution terminated\n"); 835181834Sroberto return (AE_CTRL_TERMINATE); 836181834Sroberto } 837181834Sroberto 838181834Sroberto if (!OutputToFile) 839181834Sroberto { 840181834Sroberto AcpiDbgLevel = DEBUG_DEFAULT; 841181834Sroberto } 842181834Sroberto 843181834Sroberto /* Shutdown */ 844181834Sroberto 845181834Sroberto /* AcpiUtSubsystemShutdown (); */ 846181834Sroberto AcpiDbCloseDebugFile (); 847181834Sroberto 848181834Sroberto AcpiGbl_DbTerminateThreads = TRUE; 849181834Sroberto 850181834Sroberto return (AE_CTRL_TERMINATE); 851181834Sroberto 852181834Sroberto case CMD_NOT_FOUND: 853181834Sroberto AcpiOsPrintf ("Unknown Command\n"); 854181834Sroberto return (AE_CTRL_TRUE); 855181834Sroberto } 856181834Sroberto 857181834Sroberto 858181834Sroberto /* Add all commands that come here to the history buffer */ 859181834Sroberto 860181834Sroberto AcpiDbAddToHistory (InputBuffer); 861181834Sroberto return (Status); 862181834Sroberto} 863181834Sroberto 864181834Sroberto 865181834Sroberto/******************************************************************************* 866181834Sroberto * 867181834Sroberto * FUNCTION: AcpiDbExecuteThread 868181834Sroberto * 869181834Sroberto * PARAMETERS: Context - Not used 870181834Sroberto * 871181834Sroberto * RETURN: None 872181834Sroberto * 873181834Sroberto * DESCRIPTION: Debugger execute thread. Waits for a command line, then 874181834Sroberto * simply dispatches it. 875181834Sroberto * 876181834Sroberto ******************************************************************************/ 877181834Sroberto 878181834Srobertovoid 879181834SrobertoAcpiDbExecuteThread ( 880181834Sroberto void *Context) 881181834Sroberto{ 882181834Sroberto ACPI_STATUS Status = AE_OK; 883181834Sroberto 884181834Sroberto 885181834Sroberto while (Status != AE_CTRL_TERMINATE) 886181834Sroberto { 887181834Sroberto AcpiGbl_MethodExecuting = FALSE; 888181834Sroberto AcpiGbl_StepToNextCall = FALSE; 889181834Sroberto 890181834Sroberto AcpiUtAcquireMutex (ACPI_MTX_DEBUG_CMD_READY); 891181834Sroberto Status = AcpiDbCommandDispatch (LineBuf, NULL, NULL); 892181834Sroberto AcpiUtReleaseMutex (ACPI_MTX_DEBUG_CMD_COMPLETE); 893181834Sroberto } 894181834Sroberto} 895181834Sroberto 896181834Sroberto 897181834Sroberto/******************************************************************************* 898181834Sroberto * 899181834Sroberto * FUNCTION: AcpiDbSingleThread 900181834Sroberto * 901181834Sroberto * PARAMETERS: None 902181834Sroberto * 903181834Sroberto * RETURN: None 904181834Sroberto * 905181834Sroberto * DESCRIPTION: Debugger execute thread. Waits for a command line, then 906181834Sroberto * simply dispatches it. 907181834Sroberto * 908181834Sroberto ******************************************************************************/ 909181834Sroberto 910181834Srobertovoid 911181834SrobertoAcpiDbSingleThread ( 912181834Sroberto void) 913181834Sroberto{ 914181834Sroberto ACPI_STATUS Status = AE_OK; 915181834Sroberto 916181834Sroberto 917181834Sroberto AcpiGbl_MethodExecuting = FALSE; 918181834Sroberto AcpiGbl_StepToNextCall = FALSE; 919181834Sroberto 920181834Sroberto Status = AcpiDbCommandDispatch (LineBuf, NULL, NULL); 921181834Sroberto} 922181834Sroberto 923181834Sroberto 924181834Sroberto/******************************************************************************* 925181834Sroberto * 926181834Sroberto * FUNCTION: AcpiDbUserCommands 927181834Sroberto * 928181834Sroberto * PARAMETERS: Prompt - User prompt (depends on mode) 929181834Sroberto * Op - Current executing parse op 930181834Sroberto * 931181834Sroberto * RETURN: None 932181834Sroberto * 933181834Sroberto * DESCRIPTION: Command line execution for the AML debugger. Commands are 934181834Sroberto * matched and dispatched here. 935181834Sroberto * 936181834Sroberto ******************************************************************************/ 937181834Sroberto 938181834SrobertoACPI_STATUS 939181834SrobertoAcpiDbUserCommands ( 940181834Sroberto NATIVE_CHAR Prompt, 941181834Sroberto ACPI_PARSE_OBJECT *Op) 942181834Sroberto{ 943181834Sroberto ACPI_STATUS Status = AE_OK; 944181834Sroberto 945181834Sroberto 946181834Sroberto /* TBD: [Restructure] Need a separate command line buffer for step mode */ 947181834Sroberto 948181834Sroberto while (!AcpiGbl_DbTerminateThreads) 949181834Sroberto { 950181834Sroberto /* Force output to console until a command is entered */ 951181834Sroberto 952181834Sroberto AcpiDbSetOutputDestination (DB_CONSOLE_OUTPUT); 953181834Sroberto 954181834Sroberto /* Different prompt if method is executing */ 955181834Sroberto 956181834Sroberto if (!AcpiGbl_MethodExecuting) 957181834Sroberto { 958181834Sroberto AcpiOsPrintf ("%1c ", DB_COMMAND_PROMPT); 959181834Sroberto } 960181834Sroberto else 961181834Sroberto { 962181834Sroberto AcpiOsPrintf ("%1c ", DB_EXECUTE_PROMPT); 963181834Sroberto } 964181834Sroberto 965181834Sroberto /* Get the user input line */ 966181834Sroberto 967181834Sroberto AcpiOsGetLine (LineBuf); 968181834Sroberto 969181834Sroberto 970181834Sroberto /* Check for single or multithreaded debug */ 971181834Sroberto 972181834Sroberto if (AcpiGbl_DebuggerConfiguration & DEBUGGER_MULTI_THREADED) 973181834Sroberto { 974181834Sroberto /* 975181834Sroberto * Signal the debug thread that we have a command to execute, 976181834Sroberto * and wait for the command to complete. 977181834Sroberto */ 978181834Sroberto 979181834Sroberto AcpiUtReleaseMutex (ACPI_MTX_DEBUG_CMD_READY); 980181834Sroberto AcpiUtAcquireMutex (ACPI_MTX_DEBUG_CMD_COMPLETE); 981181834Sroberto } 982181834Sroberto 983181834Sroberto else 984181834Sroberto { 985181834Sroberto /* Just call to the command line interpreter */ 986181834Sroberto 987181834Sroberto AcpiDbSingleThread (); 988181834Sroberto } 989181834Sroberto } 990181834Sroberto 991181834Sroberto 992181834Sroberto /* 993181834Sroberto * Only this thread (the original thread) should actually terminate the subsystem, 994181834Sroberto * because all the semaphores are deleted during termination 995181834Sroberto */ 996181834Sroberto AcpiTerminate (); 997181834Sroberto 998181834Sroberto return (Status); 999181834Sroberto} 1000181834Sroberto 1001181834Sroberto 1002181834Sroberto#endif /* ENABLE_DEBUGGER */ 1003181834Sroberto 1004181834Sroberto