dbinput.c revision 82367
1200576Sroberto/******************************************************************************* 254359Sroberto * 3182007Sroberto * Module Name: dbinput - user front-end to the AML debugger 4200576Sroberto * $Revision: 64 $ 582498Sroberto * 682498Sroberto ******************************************************************************/ 782498Sroberto 854359Sroberto/****************************************************************************** 982498Sroberto * 1082498Sroberto * 1. Copyright Notice 1182498Sroberto * 1282498Sroberto * Some or all of this work - Copyright (c) 1999, 2000, 2001, Intel Corp. 1354359Sroberto * All rights reserved. 14200576Sroberto * 15200576Sroberto * 2. License 16200576Sroberto * 17200576Sroberto * 2.1. This is your license from Intel Corp. under its intellectual property 18200576Sroberto * rights. You may have additional license terms from the party that provided 19200576Sroberto * you this software, covering your right to use that party's intellectual 20200576Sroberto * property rights. 21200576Sroberto * 22182007Sroberto * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 23182007Sroberto * copy of the source code appearing in this file ("Covered Code") an 24182007Sroberto * irrevocable, perpetual, worldwide license under Intel's copyrights in the 25182007Sroberto * base code distributed originally by Intel ("Original Intel Code") to copy, 26182007Sroberto * make derivatives, distribute, use and display any portion of the Covered 27182007Sroberto * Code in any form, with the right to sublicense such rights; and 28182007Sroberto * 29182007Sroberto * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 30182007Sroberto * license (with the right to sublicense), under only those claims of Intel 31182007Sroberto * patents that are infringed by the Original Intel Code, to make, use, sell, 32182007Sroberto * offer to sell, and import the Covered Code and derivative works thereof 33182007Sroberto * solely to the minimum extent necessary to exercise the above copyright 34182007Sroberto * license, and in no event shall the patent license extend to any additions 35182007Sroberto * to or modifications of the Original Intel Code. No other license or right 36182007Sroberto * is granted directly or by implication, estoppel or otherwise; 37182007Sroberto * 38182007Sroberto * The above copyright and patent license is granted only if the following 39182007Sroberto * conditions are met: 40182007Sroberto * 41182007Sroberto * 3. Conditions 42182007Sroberto * 43182007Sroberto * 3.1. Redistribution of Source with Rights to Further Distribute Source. 44182007Sroberto * Redistribution of source code of any substantial portion of the Covered 45182007Sroberto * Code or modification with rights to further distribute source must include 46182007Sroberto * the above Copyright Notice, the above License, this list of Conditions, 47182007Sroberto * and the following Disclaimer and Export Compliance provision. In addition, 48182007Sroberto * Licensee must cause all Covered Code to which Licensee contributes to 49182007Sroberto * contain a file documenting the changes Licensee made to create that Covered 50182007Sroberto * Code and the date of any change. Licensee must include in that file the 51182007Sroberto * documentation of any changes made by any predecessor Licensee. Licensee 52182007Sroberto * must include a prominent statement that the modification is derived, 53182007Sroberto * directly or indirectly, from Original Intel Code. 54182007Sroberto * 55182007Sroberto * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 56182007Sroberto * Redistribution of source code of any substantial portion of the Covered 57182007Sroberto * Code or modification without rights to further distribute source must 58182007Sroberto * include the following Disclaimer and Export Compliance provision in the 59182007Sroberto * documentation and/or other materials provided with distribution. In 60182007Sroberto * addition, Licensee may not authorize further sublicense of source of any 61182007Sroberto * portion of the Covered Code, and must include terms to the effect that the 62182007Sroberto * license from Licensee to its licensee is limited to the intellectual 63182007Sroberto * property embodied in the software Licensee provides to its licensee, and 64182007Sroberto * not to intellectual property embodied in modifications its licensee may 65182007Sroberto * make. 66182007Sroberto * 67182007Sroberto * 3.3. Redistribution of Executable. Redistribution in executable form of any 68182007Sroberto * substantial portion of the Covered Code or modification must reproduce the 69182007Sroberto * above Copyright Notice, and the following Disclaimer and Export Compliance 70182007Sroberto * provision in the documentation and/or other materials provided with the 71182007Sroberto * distribution. 72182007Sroberto * 73182007Sroberto * 3.4. Intel retains all right, title, and interest in and to the Original 74182007Sroberto * Intel Code. 75182007Sroberto * 76182007Sroberto * 3.5. Neither the name Intel nor any other trademark owned or controlled by 77182007Sroberto * Intel shall be used in advertising or otherwise to promote the sale, use or 78182007Sroberto * other dealings in products derived from or relating to the Covered Code 79182007Sroberto * without prior written authorization from Intel. 80182007Sroberto * 81182007Sroberto * 4. Disclaimer and Export Compliance 82182007Sroberto * 83182007Sroberto * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 84182007Sroberto * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 85182007Sroberto * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 86182007Sroberto * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 87182007Sroberto * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 88182007Sroberto * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 89182007Sroberto * PARTICULAR PURPOSE. 90182007Sroberto * 91182007Sroberto * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 92182007Sroberto * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 93182007Sroberto * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 94182007Sroberto * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 95182007Sroberto * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 96182007Sroberto * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 97182007Sroberto * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 98182007Sroberto * LIMITED REMEDY. 99182007Sroberto * 100182007Sroberto * 4.3. Licensee shall not export, either directly or indirectly, any of this 101182007Sroberto * software or system incorporating such software without first obtaining any 102182007Sroberto * required license or other approval from the U. S. Department of Commerce or 103182007Sroberto * any other agency or department of the United States Government. In the 104182007Sroberto * event Licensee exports any such software from the United States or 105182007Sroberto * re-exports any such software from a foreign destination, Licensee shall 106182007Sroberto * ensure that the distribution and export/re-export of the software is in 107182007Sroberto * compliance with all laws, regulations, orders, or other restrictions of the 108182007Sroberto * U.S. Export Administration Regulations. Licensee agrees that neither it nor 109182007Sroberto * any of its subsidiaries will export/re-export any technical data, process, 110182007Sroberto * software, or service, directly or indirectly, to any country for which the 11182498Sroberto * United States government or any agency thereof requires an export license, 11282498Sroberto * other governmental approval, or letter of assurance, without first obtaining 113182007Sroberto * such license, approval or letter. 114182007Sroberto * 115182007Sroberto *****************************************************************************/ 116182007Sroberto 117182007Sroberto 118182007Sroberto#include "acpi.h" 119182007Sroberto#include "acparser.h" 120182007Sroberto#include "actables.h" 121182007Sroberto#include "acnamesp.h" 122182007Sroberto#include "acinterp.h" 123182007Sroberto#include "acdebug.h" 124182007Sroberto 125182007Sroberto 126182007Sroberto#ifdef ENABLE_DEBUGGER 127182007Sroberto 128182007Sroberto#define _COMPONENT ACPI_DEBUGGER 129182007Sroberto MODULE_NAME ("dbinput") 130182007Sroberto 131182007Sroberto 132182007Sroberto/* 133182007Sroberto * Globals that are specific to the debugger 134182007Sroberto */ 135182007Sroberto 136182007SrobertoNATIVE_CHAR LineBuf[80]; 137182007SrobertoNATIVE_CHAR ParsedBuf[80]; 138182007SrobertoNATIVE_CHAR ScopeBuf[40]; 139182007SrobertoNATIVE_CHAR DebugFilename[40]; 140182007SrobertoNATIVE_CHAR *Args[DB_MAX_ARGS]; 141182007SrobertoNATIVE_CHAR *Buffer; 142182007SrobertoNATIVE_CHAR *Filename = NULL; 143182007SrobertoBOOLEAN OutputToFile = FALSE; 144182007Sroberto 145182007Sroberto 146182007SrobertoUINT32 AcpiGbl_DbDebugLevel = 0x0FFFFFFF; 147182007SrobertoUINT32 AcpiGbl_DbConsoleDebugLevel = NORMAL_DEFAULT | ACPI_LV_TABLES; 148182007SrobertoUINT8 AcpiGbl_DbOutputFlags = DB_CONSOLE_OUTPUT; 149182007Sroberto 150182007Sroberto 151182007SrobertoBOOLEAN opt_tables = FALSE; 152182007SrobertoBOOLEAN opt_disasm = FALSE; 153182007SrobertoBOOLEAN opt_stats = FALSE; 154182007SrobertoBOOLEAN opt_parse_jit = FALSE; 155182007SrobertoBOOLEAN opt_verbose = TRUE; 156182007SrobertoBOOLEAN opt_ini_methods = TRUE; 157182007Sroberto 158182007Sroberto 159182007Sroberto/* 160182007Sroberto * Top-level debugger commands. 161182007Sroberto * 162182007Sroberto * This list of commands must match the string table below it 163182007Sroberto */ 164182007Sroberto 165182007Srobertoenum AcpiExDebuggerCommands 166182007Sroberto{ 167182007Sroberto CMD_NOT_FOUND = 0, 168182007Sroberto CMD_NULL, 169182007Sroberto CMD_ALLOCATIONS, 170182007Sroberto CMD_ARGS, 171182007Sroberto CMD_ARGUMENTS, 172182007Sroberto CMD_BREAKPOINT, 173182007Sroberto CMD_CALL, 174182007Sroberto CMD_CLOSE, 175182007Sroberto CMD_DEBUG, 176182007Sroberto CMD_DUMP, 177182007Sroberto CMD_ENABLEACPI, 178182007Sroberto CMD_EVENT, 179182007Sroberto CMD_EXECUTE, 180182007Sroberto CMD_EXIT, 181182007Sroberto CMD_FIND, 182182007Sroberto CMD_GO, 183182007Sroberto CMD_HELP, 184182007Sroberto CMD_HELP2, 185182007Sroberto CMD_HISTORY, 186182007Sroberto CMD_HISTORY_EXE, 187182007Sroberto CMD_HISTORY_LAST, 188182007Sroberto CMD_INFORMATION, 189182007Sroberto CMD_INTO, 190182007Sroberto CMD_LEVEL, 191182007Sroberto CMD_LIST, 192182007Sroberto CMD_LOAD, 193182007Sroberto CMD_LOCALS, 194182007Sroberto CMD_LOCKS, 195182007Sroberto CMD_METHODS, 196182007Sroberto CMD_NAMESPACE, 197182007Sroberto CMD_NOTIFY, 198182007Sroberto CMD_OBJECT, 199182007Sroberto CMD_OPEN, 200182007Sroberto CMD_OWNER, 201182007Sroberto CMD_PREFIX, 202182007Sroberto CMD_QUIT, 203182007Sroberto CMD_REFERENCES, 204182007Sroberto CMD_RESOURCES, 205182007Sroberto CMD_RESULTS, 206182007Sroberto CMD_SET, 207182007Sroberto CMD_STATS, 208182007Sroberto CMD_STOP, 209182007Sroberto CMD_TABLES, 210182007Sroberto CMD_TERMINATE, 211182007Sroberto CMD_THREADS, 212182007Sroberto CMD_TREE, 213182007Sroberto CMD_UNLOAD 214182007Sroberto}; 215182007Sroberto 216182007Sroberto#define CMD_FIRST_VALID 2 217182007Sroberto 218182007Sroberto 219182007SrobertoCOMMAND_INFO Commands[] = 220182007Sroberto{ 221182007Sroberto {"<NOT FOUND>", 0}, 222182007Sroberto {"<NULL>", 0}, 223182007Sroberto {"ALLOCATIONS", 0}, 224182007Sroberto {"ARGS", 0}, 225182007Sroberto {"ARGUMENTS", 0}, 226182007Sroberto {"BREAKPOINT", 1}, 227182007Sroberto {"CALL", 0}, 228182007Sroberto {"CLOSE", 0}, 229182007Sroberto {"DEBUG", 1}, 230182007Sroberto {"DUMP", 1}, 231182007Sroberto {"ENABLEACPI", 0}, 232182007Sroberto {"EVENT", 1}, 233182007Sroberto {"EXECUTE", 1}, 234182007Sroberto {"EXIT", 0}, 235182007Sroberto {"FIND", 1}, 236182007Sroberto {"GO", 0}, 237182007Sroberto {"HELP", 0}, 238182007Sroberto {"?", 0}, 239182007Sroberto {"HISTORY", 0}, 240182007Sroberto {"!", 1}, 241182007Sroberto {"!!", 0}, 242182007Sroberto {"INFORMATION", 0}, 243182007Sroberto {"INTO", 0}, 244182007Sroberto {"LEVEL", 0}, 245182007Sroberto {"LIST", 0}, 246182007Sroberto {"LOAD", 1}, 247182007Sroberto {"LOCALS", 0}, 248182007Sroberto {"LOCKS", 0}, 249182007Sroberto {"METHODS", 0}, 250182007Sroberto {"NAMESPACE", 0}, 251182007Sroberto {"NOTIFY", 2}, 252182007Sroberto {"OBJECT", 1}, 253182007Sroberto {"OPEN", 1}, 254182007Sroberto {"OWNER", 1}, 255182007Sroberto {"PREFIX", 0}, 256182007Sroberto {"QUIT", 0}, 257182007Sroberto {"REFERENCES", 1}, 258182007Sroberto {"RESOURCES", 1}, 259182007Sroberto {"RESULTS", 0}, 260182007Sroberto {"SET", 3}, 261182007Sroberto {"STATS", 0}, 26282498Sroberto {"STOP", 0}, 26382498Sroberto {"TABLES", 0}, 26454359Sroberto {"TERMINATE", 0}, 265182007Sroberto {"THREADS", 3}, 266182007Sroberto {"TREE", 0}, 267182007Sroberto {"UNLOAD", 1}, 268182007Sroberto {NULL, 0} 269182007Sroberto}; 270182007Sroberto 271182007Sroberto 272182007Sroberto/******************************************************************************* 273182007Sroberto * 274182007Sroberto * FUNCTION: AcpiDbDisplayHelp 275182007Sroberto * 27654359Sroberto * PARAMETERS: HelpType - Subcommand (optional) 27782498Sroberto * 278182007Sroberto * RETURN: None 279182007Sroberto * 280182007Sroberto * DESCRIPTION: Print a usage message. 281182007Sroberto * 282182007Sroberto ******************************************************************************/ 283182007Sroberto 284182007Srobertovoid 285182007SrobertoAcpiDbDisplayHelp ( 286182007Sroberto NATIVE_CHAR *HelpType) 287182007Sroberto{ 288182007Sroberto 28982498Sroberto 29082498Sroberto /* No parameter, just give the overview */ 291182007Sroberto 292182007Sroberto if (!HelpType) 293182007Sroberto { 294182007Sroberto AcpiOsPrintf ("ACPI CA Debugger Commands\n\n"); 295182007Sroberto AcpiOsPrintf ("The following classes of commands are available. Help is available for\n"); 296182007Sroberto AcpiOsPrintf ("each class by entering \"Help <ClassName>\"\n\n"); 297182007Sroberto AcpiOsPrintf (" [GENERAL] General-Purpose Commands\n"); 298182007Sroberto AcpiOsPrintf (" [NAMESPACE] Namespace Access Commands\n"); 299182007Sroberto AcpiOsPrintf (" [METHOD] Control Method Execution Commands\n"); 300182007Sroberto AcpiOsPrintf (" [FILE] File I/O Commands\n"); 301182007Sroberto return; 302182007Sroberto 303182007Sroberto } 304182007Sroberto 305182007Sroberto 306182007Sroberto /* 307182007Sroberto * Parameter is the command class 308106163Sroberto * 30954359Sroberto * The idea here is to keep each class of commands smaller than a screenful 310182007Sroberto */ 311182007Sroberto 312182007Sroberto switch (HelpType[0]) 313182007Sroberto { 314182007Sroberto case 'G': 315182007Sroberto AcpiOsPrintf ("\nGeneral-Purpose Commands\n\n"); 316182007Sroberto AcpiOsPrintf ("Allocations Display list of current memory allocations\n"); 317182007Sroberto AcpiOsPrintf ("Dump <Address>|<Namepath>\n"); 318182007Sroberto AcpiOsPrintf (" [Byte|Word|Dword|Qword] Display ACPI objects or memory\n"); 31954359Sroberto AcpiOsPrintf ("EnableAcpi Enable ACPI (hardware) mode\n"); 32054359Sroberto AcpiOsPrintf ("Help This help screen\n"); 321182007Sroberto AcpiOsPrintf ("History Display command history buffer\n"); 322182007Sroberto AcpiOsPrintf ("Level [<DebugLevel>] [console] Get/Set debug level for file or console\n"); 323182007Sroberto AcpiOsPrintf ("Locks Current status of internal mutexes\n"); 324182007Sroberto AcpiOsPrintf ("Quit or Exit Exit this command\n"); 325182007Sroberto AcpiOsPrintf ("Stats [Allocations|Memory|Misc\n"); 326182007Sroberto AcpiOsPrintf (" |Objects|Tables] Display namespace and memory statistics\n"); 327182007Sroberto AcpiOsPrintf ("Tables Display info about loaded ACPI tables\n"); 328182007Sroberto AcpiOsPrintf ("Unload <TableSig> [Instance] Unload an ACPI table\n"); 32982498Sroberto AcpiOsPrintf ("! <CommandNumber> Execute command from history buffer\n"); 330182007Sroberto AcpiOsPrintf ("!! Execute last command again\n"); 331182007Sroberto return; 332182007Sroberto 333182007Sroberto case 'N': 334182007Sroberto AcpiOsPrintf ("\nNamespace Access Commands\n\n"); 335182007Sroberto AcpiOsPrintf ("Debug <Namepath> [Arguments] Single Step a control method\n"); 33682498Sroberto AcpiOsPrintf ("Event <F|G> <Value> Generate AcpiEvent (Fixed/GPE)\n"); 337182007Sroberto AcpiOsPrintf ("Execute <Namepath> [Arguments] Execute control method\n"); 338182007Sroberto AcpiOsPrintf ("Find <Name> (? is wildcard) Find ACPI name(s) with wildcards\n"); 339182007Sroberto AcpiOsPrintf ("Method Display list of loaded control methods\n"); 340182007Sroberto AcpiOsPrintf ("Namespace [<Addr>|<Path>] [Depth] Display loaded namespace tree/subtree\n"); 341182007Sroberto AcpiOsPrintf ("Notify <NamePath> <Value> Send a notification\n"); 342182007Sroberto AcpiOsPrintf ("Objects <ObjectType> Display all objects of the given type\n"); 343182007Sroberto AcpiOsPrintf ("Owner <OwnerId> [Depth] Display loaded namespace by object owner\n"); 344182007Sroberto AcpiOsPrintf ("Prefix [<NamePath>] Set or Get current execution prefix\n"); 345182007Sroberto AcpiOsPrintf ("References <Addr> Find all references to object at addr\n"); 346182007Sroberto AcpiOsPrintf ("Resources xxx Get and display resources\n"); 347182007Sroberto AcpiOsPrintf ("Terminate Delete namespace and all internal objects\n"); 348182007Sroberto AcpiOsPrintf ("Thread <Threads><Loops><NamePath> Spawn threads to execute method(s)\n"); 349182007Sroberto return; 350182007Sroberto 35182498Sroberto case 'M': 352182007Sroberto AcpiOsPrintf ("\nControl Method Execution Commands\n\n"); 353182007Sroberto AcpiOsPrintf ("Arguments (or Args) Display method arguments\n"); 354182007Sroberto AcpiOsPrintf ("Breakpoint <AmlOffset> Set an AML execution breakpoint\n"); 355182007Sroberto AcpiOsPrintf ("Call Run to next control method invocation\n"); 356182007Sroberto AcpiOsPrintf ("Go Allow method to run to completion\n"); 357182007Sroberto AcpiOsPrintf ("Information Display info about the current method\n"); 358182007Sroberto AcpiOsPrintf ("Into Step into (not over) a method call\n"); 359182007Sroberto AcpiOsPrintf ("List [# of Aml Opcodes] Display method ASL statements\n"); 36082498Sroberto AcpiOsPrintf ("Locals Display method local variables\n"); 361182007Sroberto AcpiOsPrintf ("Results Display method result stack\n"); 362182007Sroberto AcpiOsPrintf ("Set <A|L> <#> <Value> Set method data (Arguments/Locals)\n"); 363182007Sroberto AcpiOsPrintf ("Stop Terminate control method\n"); 364132451Sroberto AcpiOsPrintf ("Tree Display control method calling tree\n"); 365182007Sroberto AcpiOsPrintf ("<Enter> Single step next AML opcode (over calls)\n"); 366182007Sroberto return; 367182007Sroberto 368182007Sroberto case 'F': 369182007Sroberto AcpiOsPrintf ("\nFile I/O Commands\n\n"); 370182007Sroberto AcpiOsPrintf ("Close Close debug output file\n"); 371182007Sroberto AcpiOsPrintf ("Open <Output Filename> Open a file for debug output\n"); 372182007Sroberto AcpiOsPrintf ("Load <Input Filename> Load ACPI table from a file\n"); 373182007Sroberto return; 374182007Sroberto 375182007Sroberto default: 376182007Sroberto AcpiOsPrintf ("Unrecognized Command Class: %x\n", HelpType); 377182007Sroberto return; 378132451Sroberto } 379182007Sroberto} 380182007Sroberto 381182007Sroberto 382182007Sroberto/******************************************************************************* 383182007Sroberto * 384182007Sroberto * FUNCTION: AcpiDbGetNextToken 385182007Sroberto * 386182007Sroberto * PARAMETERS: String - Command buffer 387182007Sroberto * Next - Return value, end of next token 388182007Sroberto * 389132451Sroberto * RETURN: Pointer to the start of the next token. 390182007Sroberto * 391182007Sroberto * DESCRIPTION: Command line parsing. Get the next token on the command line 392182007Sroberto * 393182007Sroberto ******************************************************************************/ 394182007Sroberto 395182007SrobertoNATIVE_CHAR * 396182007SrobertoAcpiDbGetNextToken ( 397182007Sroberto NATIVE_CHAR *String, 398182007Sroberto NATIVE_CHAR **Next) 399182007Sroberto{ 400182007Sroberto NATIVE_CHAR *Start; 401182007Sroberto 402132451Sroberto /* At end of buffer? */ 403182007Sroberto 404182007Sroberto if (!String || !(*String)) 405182007Sroberto { 406182007Sroberto return (NULL); 407182007Sroberto } 408182007Sroberto 409182007Sroberto 410182007Sroberto /* Get rid of any spaces at the beginning */ 411182007Sroberto 412182007Sroberto if (*String == ' ') 413182007Sroberto { 414182007Sroberto while (*String && (*String == ' ')) 415182007Sroberto { 416182007Sroberto String++; 417182007Sroberto } 418182007Sroberto 419182007Sroberto if (!(*String)) 420182007Sroberto { 421182007Sroberto return (NULL); 422182007Sroberto } 423182007Sroberto } 424182007Sroberto 425182007Sroberto Start = String; 426182007Sroberto 427182007Sroberto /* Find end of token */ 428182007Sroberto 429182007Sroberto while (*String && (*String != ' ')) 430182007Sroberto { 431182007Sroberto String++; 432182007Sroberto } 433182007Sroberto 434182007Sroberto 435182007Sroberto if (!(*String)) 436182007Sroberto { 437182007Sroberto *Next = NULL; 438182007Sroberto } 439182007Sroberto 440182007Sroberto else 441182007Sroberto { 442182007Sroberto *String = 0; 443182007Sroberto *Next = String + 1; 444182007Sroberto } 445182007Sroberto 446182007Sroberto return (Start); 447182007Sroberto} 448182007Sroberto 449182007Sroberto 450182007Sroberto/******************************************************************************* 451182007Sroberto * 452182007Sroberto * FUNCTION: AcpiDbGetLine 453182007Sroberto * 454182007Sroberto * PARAMETERS: InputBuffer - Command line buffer 455182007Sroberto * 456182007Sroberto * RETURN: None 457182007Sroberto * 458182007Sroberto * DESCRIPTION: Get the next command line from the user. Gets entire line 459182007Sroberto * up to the next newline 460182007Sroberto * 461182007Sroberto ******************************************************************************/ 462182007Sroberto 46354359SrobertoUINT32 464182007SrobertoAcpiDbGetLine ( 46582498Sroberto NATIVE_CHAR *InputBuffer) 466182007Sroberto{ 467182007Sroberto UINT32 i; 468182007Sroberto UINT32 Count; 469182007Sroberto NATIVE_CHAR *Next; 470182007Sroberto NATIVE_CHAR *This; 471182007Sroberto 472182007Sroberto 473182007Sroberto STRCPY (ParsedBuf, InputBuffer); 474182007Sroberto STRUPR (ParsedBuf); 475182007Sroberto 476182007Sroberto This = ParsedBuf; 477182007Sroberto for (i = 0; i < DB_MAX_ARGS; i++) 478182007Sroberto { 479182007Sroberto Args[i] = AcpiDbGetNextToken (This, &Next); 480182007Sroberto if (!Args[i]) 481182007Sroberto { 482182007Sroberto break; 483182007Sroberto } 484182007Sroberto 485182007Sroberto This = Next; 486182007Sroberto } 487182007Sroberto 488182007Sroberto 489182007Sroberto /* Uppercase the actual command */ 490182007Sroberto 491182007Sroberto if (Args[0]) 492182007Sroberto { 493182007Sroberto STRUPR (Args[0]); 494182007Sroberto } 495182007Sroberto 496182007Sroberto Count = i; 497182007Sroberto if (Count) 498182007Sroberto { 499182007Sroberto Count--; /* Number of args only */ 500132451Sroberto } 501182007Sroberto 502182007Sroberto return (Count); 503182007Sroberto} 504182007Sroberto 505182007Sroberto 506182007Sroberto/******************************************************************************* 507182007Sroberto * 508182007Sroberto * FUNCTION: AcpiDbMatchCommand 509182007Sroberto * 510182007Sroberto * PARAMETERS: UserCommand - User command line 511182007Sroberto * 512182007Sroberto * RETURN: Index into command array, -1 if not found 513182007Sroberto * 514182007Sroberto * DESCRIPTION: Search command array for a command match 515182007Sroberto * 516182007Sroberto ******************************************************************************/ 517182007Sroberto 518182007SrobertoUINT32 519182007SrobertoAcpiDbMatchCommand ( 520182007Sroberto NATIVE_CHAR *UserCommand) 521182007Sroberto{ 522182007Sroberto UINT32 i; 523182007Sroberto 524182007Sroberto 525182007Sroberto if (!UserCommand || UserCommand[0] == 0) 526182007Sroberto { 527182007Sroberto return (CMD_NULL); 528182007Sroberto } 529182007Sroberto 530182007Sroberto for (i = CMD_FIRST_VALID; Commands[i].Name; i++) 531182007Sroberto { 532182007Sroberto if (STRSTR (Commands[i].Name, UserCommand) == Commands[i].Name) 533182007Sroberto { 534182007Sroberto return (i); 535182007Sroberto } 536182007Sroberto } 537182007Sroberto 538182007Sroberto /* Command not recognized */ 539182007Sroberto 540182007Sroberto return (CMD_NOT_FOUND); 541182007Sroberto} 542182007Sroberto 543182007Sroberto 544182007Sroberto/******************************************************************************* 545182007Sroberto * 546182007Sroberto * FUNCTION: AcpiDbCommandDispatch 547182007Sroberto * 548182007Sroberto * PARAMETERS: InputBuffer - Command line buffer 549182007Sroberto * WalkState - Current walk 550182007Sroberto * Op - Current (executing) parse op 551182007Sroberto * 552182007Sroberto * RETURN: Status 553182007Sroberto * 554182007Sroberto * DESCRIPTION: Command dispatcher. Called from two places: 555182007Sroberto * 556182007Sroberto ******************************************************************************/ 557182007Sroberto 558182007SrobertoACPI_STATUS 559182007SrobertoAcpiDbCommandDispatch ( 560182007Sroberto NATIVE_CHAR *InputBuffer, 561182007Sroberto ACPI_WALK_STATE *WalkState, 562182007Sroberto ACPI_PARSE_OBJECT *Op) 563182007Sroberto{ 564182007Sroberto UINT32 Temp; 565182007Sroberto UINT32 CommandIndex; 566182007Sroberto UINT32 ParamCount; 567182007Sroberto NATIVE_CHAR *CommandLine; 568182007Sroberto ACPI_STATUS Status = AE_CTRL_TRUE; 569182007Sroberto 570182007Sroberto 571182007Sroberto /* If AcpiTerminate has been called, terminate this thread */ 572182007Sroberto 573182007Sroberto if (AcpiGbl_DbTerminateThreads) 574182007Sroberto { 575182007Sroberto return (AE_CTRL_TERMINATE); 576182007Sroberto } 577182007Sroberto 578182007Sroberto ParamCount = AcpiDbGetLine (InputBuffer); 579182007Sroberto CommandIndex = AcpiDbMatchCommand (Args[0]); 580182007Sroberto Temp = 0; 581182007Sroberto 582182007Sroberto /* Verify that we have the minimum number of params */ 583182007Sroberto 584182007Sroberto if (ParamCount < Commands[CommandIndex].MinArgs) 585182007Sroberto { 586182007Sroberto AcpiOsPrintf ("%d parameters entered, [%s] requires %d parameters\n", 587182007Sroberto ParamCount, Commands[CommandIndex].Name, Commands[CommandIndex].MinArgs); 588182007Sroberto return (AE_CTRL_TRUE); 589182007Sroberto } 590182007Sroberto 591182007Sroberto /* Decode and dispatch the command */ 592182007Sroberto 593182007Sroberto switch (CommandIndex) 594182007Sroberto { 595182007Sroberto case CMD_NULL: 596182007Sroberto if (Op) 597182007Sroberto { 598182007Sroberto return (AE_OK); 599182007Sroberto } 600182007Sroberto break; 601182007Sroberto 602182007Sroberto case CMD_ALLOCATIONS: 603182007Sroberto#ifdef ACPI_DBG_TRACK_ALLOCATIONS 604182007Sroberto AcpiUtDumpCurrentAllocations ((UINT32) -1, NULL); 605182007Sroberto#endif 606182007Sroberto break; 607182007Sroberto 608182007Sroberto case CMD_ARGS: 609182007Sroberto case CMD_ARGUMENTS: 610182007Sroberto AcpiDbDisplayArguments (); 611182007Sroberto break; 612182007Sroberto 613182007Sroberto case CMD_BREAKPOINT: 614182007Sroberto AcpiDbSetMethodBreakpoint (Args[1], WalkState, Op); 615182007Sroberto break; 616182007Sroberto 617182007Sroberto case CMD_CALL: 618182007Sroberto AcpiDbSetMethodCallBreakpoint (Op); 619182007Sroberto Status = AE_OK; 620182007Sroberto break; 621182007Sroberto 622182007Sroberto case CMD_CLOSE: 623182007Sroberto AcpiDbCloseDebugFile (); 624182007Sroberto break; 625182007Sroberto 626182007Sroberto case CMD_DEBUG: 627182007Sroberto AcpiDbExecute (Args[1], &Args[2], EX_SINGLE_STEP); 628182007Sroberto break; 629182007Sroberto 630182007Sroberto case CMD_DUMP: 631182007Sroberto AcpiDbDecodeAndDisplayObject (Args[1], Args[2]); 632182007Sroberto break; 633182007Sroberto 634182007Sroberto case CMD_ENABLEACPI: 635182007Sroberto Status = AcpiEnable(); 636182007Sroberto if (ACPI_FAILURE(Status)) 637182007Sroberto { 638182007Sroberto AcpiOsPrintf("AcpiEnable failed (Status=%X)\n", Status); 639182007Sroberto return (Status); 640182007Sroberto } 641182007Sroberto break; 642182007Sroberto 643182007Sroberto case CMD_EVENT: 644182007Sroberto AcpiOsPrintf ("Event command not implemented\n"); 645182007Sroberto break; 646132451Sroberto 647182007Sroberto case CMD_EXECUTE: 648132451Sroberto AcpiDbExecute (Args[1], &Args[2], EX_NO_SINGLE_STEP); 649132451Sroberto break; 650182007Sroberto 651182007Sroberto case CMD_FIND: 652182007Sroberto AcpiDbFindNameInNamespace (Args[1]); 653182007Sroberto break; 654182007Sroberto 655182007Sroberto case CMD_GO: 656182007Sroberto AcpiGbl_CmSingleStep = FALSE; 657182007Sroberto return (AE_OK); 658182007Sroberto 659182007Sroberto case CMD_HELP: 660182007Sroberto case CMD_HELP2: 661182007Sroberto AcpiDbDisplayHelp (Args[1]); 662182007Sroberto break; 663182007Sroberto 664182007Sroberto case CMD_HISTORY: 665182007Sroberto AcpiDbDisplayHistory (); 666182007Sroberto break; 667182007Sroberto 668182007Sroberto case CMD_HISTORY_EXE: 669182007Sroberto CommandLine = AcpiDbGetFromHistory (Args[1]); 670182007Sroberto if (!CommandLine) 671182007Sroberto { 672182007Sroberto return (AE_CTRL_TRUE); 673182007Sroberto } 674182007Sroberto 675182007Sroberto Status = AcpiDbCommandDispatch (CommandLine, WalkState, Op); 676182007Sroberto if (ACPI_SUCCESS (Status)) 677182007Sroberto { 67882498Sroberto Status = AE_CTRL_TRUE; 679182007Sroberto } 680182007Sroberto return (Status); 681182007Sroberto break; 682182007Sroberto 683182007Sroberto case CMD_HISTORY_LAST: 684182007Sroberto CommandLine = AcpiDbGetFromHistory (NULL); 685132451Sroberto if (!CommandLine) 686182007Sroberto { 687182007Sroberto return (AE_CTRL_TRUE); 688182007Sroberto } 689182007Sroberto 690182007Sroberto Status = AcpiDbCommandDispatch (CommandLine, WalkState, Op); 691182007Sroberto if (ACPI_SUCCESS (Status)) 692182007Sroberto { 693182007Sroberto Status = AE_CTRL_TRUE; 694182007Sroberto } 695182007Sroberto return (Status); 696182007Sroberto 697182007Sroberto case CMD_INFORMATION: 698182007Sroberto AcpiDbDisplayMethodInfo (Op); 699182007Sroberto break; 700182007Sroberto 701182007Sroberto case CMD_INTO: 702182007Sroberto if (Op) 703182007Sroberto { 704182007Sroberto AcpiGbl_CmSingleStep = TRUE; 705182007Sroberto 706182007Sroberto/* TBD: Must get current walk state */ 707182007Sroberto /* AcpiGbl_MethodBreakpoint = 0; */ 708182007Sroberto return (AE_OK); 709182007Sroberto } 710182007Sroberto break; 711182007Sroberto 712182007Sroberto case CMD_LEVEL: 713182007Sroberto if (ParamCount == 0) 714182007Sroberto { 715182007Sroberto AcpiOsPrintf ("Current debug level for file output is: %8.8lX\n", AcpiGbl_DbDebugLevel); 716182007Sroberto AcpiOsPrintf ("Current debug level for console output is: %8.8lX\n", AcpiGbl_DbConsoleDebugLevel); 717182007Sroberto } 718182007Sroberto else if (ParamCount == 2) 719182007Sroberto { 720182007Sroberto Temp = AcpiGbl_DbConsoleDebugLevel; 721182007Sroberto AcpiGbl_DbConsoleDebugLevel = STRTOUL (Args[1], NULL, 16); 722182007Sroberto AcpiOsPrintf ("Debug Level for console output was %8.8lX, now %8.8lX\n", Temp, AcpiGbl_DbConsoleDebugLevel); 723182007Sroberto } 724182007Sroberto else 725182007Sroberto { 726182007Sroberto Temp = AcpiGbl_DbDebugLevel; 727182007Sroberto AcpiGbl_DbDebugLevel = STRTOUL (Args[1], NULL, 16); 728182007Sroberto AcpiOsPrintf ("Debug Level for file output was %8.8lX, now %8.8lX\n", Temp, AcpiGbl_DbDebugLevel); 729182007Sroberto } 730182007Sroberto break; 731182007Sroberto 732182007Sroberto case CMD_LIST: 733182007Sroberto AcpiDbDisassembleAml (Args[1], Op); 734182007Sroberto break; 735182007Sroberto 736182007Sroberto case CMD_LOAD: 737182007Sroberto Status = AcpiDbLoadAcpiTable (Args[1]); 738182007Sroberto if (ACPI_FAILURE (Status)) 739182007Sroberto { 740182007Sroberto return (Status); 741182007Sroberto } 742182007Sroberto break; 743182007Sroberto 744182007Sroberto case CMD_LOCKS: 745182007Sroberto AcpiDbDisplayLocks (); 746182007Sroberto break; 747182007Sroberto 748182007Sroberto case CMD_LOCALS: 749182007Sroberto AcpiDbDisplayLocals (); 750182007Sroberto break; 751182007Sroberto 752182007Sroberto case CMD_METHODS: 753182007Sroberto AcpiDbDisplayObjects ("METHOD", Args[1]); 754182007Sroberto break; 755182007Sroberto 756182007Sroberto case CMD_NAMESPACE: 757182007Sroberto AcpiDbDumpNamespace (Args[1], Args[2]); 758182007Sroberto break; 759182007Sroberto 760182007Sroberto case CMD_NOTIFY: 761182007Sroberto Temp = STRTOUL (Args[2], NULL, 0); 762182007Sroberto AcpiDbSendNotify (Args[1], Temp); 763182007Sroberto break; 764182007Sroberto 765182007Sroberto case CMD_OBJECT: 766182007Sroberto AcpiDbDisplayObjects (STRUPR (Args[1]), Args[2]); 767182007Sroberto break; 768182007Sroberto 769182007Sroberto case CMD_OPEN: 770182007Sroberto AcpiDbOpenDebugFile (Args[1]); 771182007Sroberto break; 772182007Sroberto 773182007Sroberto case CMD_OWNER: 774182007Sroberto AcpiDbDumpNamespaceByOwner (Args[1], Args[2]); 775182007Sroberto break; 77656746Sroberto 777182007Sroberto case CMD_PREFIX: 778182007Sroberto AcpiDbSetScope (Args[1]); 779182007Sroberto break; 780182007Sroberto 781182007Sroberto case CMD_REFERENCES: 782182007Sroberto AcpiDbFindReferences (Args[1]); 783182007Sroberto break; 784182007Sroberto 785182007Sroberto case CMD_RESOURCES: 786182007Sroberto AcpiDbDisplayResources (Args[1]); 787182007Sroberto break; 788182007Sroberto 789182007Sroberto case CMD_RESULTS: 790182007Sroberto AcpiDbDisplayResults (); 791182007Sroberto break; 792182007Sroberto 793182007Sroberto case CMD_SET: 794182007Sroberto AcpiDbSetMethodData (Args[1], Args[2], Args[3]); 795182007Sroberto break; 796182007Sroberto 797182007Sroberto case CMD_STATS: 798182007Sroberto AcpiDbDisplayStatistics (Args[1]); 799182007Sroberto break; 800182007Sroberto 801182007Sroberto case CMD_STOP: 802182007Sroberto return (AE_AML_ERROR); 803182007Sroberto break; 804182007Sroberto 805182007Sroberto case CMD_TABLES: 806182007Sroberto AcpiDbDisplayTableInfo (Args[1]); 807182007Sroberto break; 808182007Sroberto 809182007Sroberto case CMD_TERMINATE: 810182007Sroberto AcpiDbSetOutputDestination (DB_REDIRECTABLE_OUTPUT); 811182007Sroberto AcpiUtSubsystemShutdown (); 812182007Sroberto 813182007Sroberto /* TBD: [Restructure] Need some way to re-initialize without re-creating the semaphores! */ 814182007Sroberto 815182007Sroberto /* AcpiInitialize (NULL); */ 816182007Sroberto break; 817182007Sroberto 818182007Sroberto case CMD_THREADS: 819182007Sroberto AcpiDbCreateExecutionThreads (Args[1], Args[2], Args[3]); 820182007Sroberto break; 821182007Sroberto 822182007Sroberto case CMD_TREE: 823182007Sroberto AcpiDbDisplayCallingTree (); 824182007Sroberto break; 825182007Sroberto 826182007Sroberto case CMD_UNLOAD: 827182007Sroberto AcpiDbUnloadAcpiTable (Args[1], Args[2]); 828182007Sroberto break; 829182007Sroberto 830182007Sroberto case CMD_EXIT: 831182007Sroberto case CMD_QUIT: 832182007Sroberto if (Op) 833182007Sroberto { 834182007Sroberto AcpiOsPrintf ("Method execution terminated\n"); 835182007Sroberto return (AE_CTRL_TERMINATE); 836182007Sroberto } 837182007Sroberto 838182007Sroberto if (!OutputToFile) 839182007Sroberto { 840182007Sroberto AcpiDbgLevel = DEBUG_DEFAULT; 841182007Sroberto } 842182007Sroberto 843182007Sroberto /* Shutdown */ 844182007Sroberto 845182007Sroberto /* AcpiUtSubsystemShutdown (); */ 846182007Sroberto AcpiDbCloseDebugFile (); 847182007Sroberto 848182007Sroberto AcpiGbl_DbTerminateThreads = TRUE; 849182007Sroberto 850182007Sroberto return (AE_CTRL_TERMINATE); 851182007Sroberto 852182007Sroberto case CMD_NOT_FOUND: 853182007Sroberto AcpiOsPrintf ("Unknown Command\n"); 854182007Sroberto return (AE_CTRL_TRUE); 855182007Sroberto } 856182007Sroberto 857182007Sroberto 858182007Sroberto /* Add all commands that come here to the history buffer */ 859182007Sroberto 860182007Sroberto AcpiDbAddToHistory (InputBuffer); 861182007Sroberto return (Status); 862182007Sroberto} 863182007Sroberto 864182007Sroberto 865182007Sroberto/******************************************************************************* 866182007Sroberto * 867182007Sroberto * FUNCTION: AcpiDbExecuteThread 868182007Sroberto * 869182007Sroberto * PARAMETERS: Context - Not used 870182007Sroberto * 871182007Sroberto * RETURN: None 872182007Sroberto * 873182007Sroberto * DESCRIPTION: Debugger execute thread. Waits for a command line, then 874182007Sroberto * simply dispatches it. 875182007Sroberto * 876182007Sroberto ******************************************************************************/ 877182007Sroberto 878182007Srobertovoid 879182007SrobertoAcpiDbExecuteThread ( 880182007Sroberto void *Context) 881182007Sroberto{ 882182007Sroberto ACPI_STATUS Status = AE_OK; 883182007Sroberto 884182007Sroberto 885182007Sroberto while (Status != AE_CTRL_TERMINATE) 886182007Sroberto { 887182007Sroberto AcpiGbl_MethodExecuting = FALSE; 888182007Sroberto AcpiGbl_StepToNextCall = FALSE; 889182007Sroberto 890182007Sroberto AcpiUtAcquireMutex (ACPI_MTX_DEBUG_CMD_READY); 891182007Sroberto Status = AcpiDbCommandDispatch (LineBuf, NULL, NULL); 892182007Sroberto AcpiUtReleaseMutex (ACPI_MTX_DEBUG_CMD_COMPLETE); 893182007Sroberto } 894182007Sroberto} 895182007Sroberto 896182007Sroberto 897182007Sroberto/******************************************************************************* 898182007Sroberto * 899182007Sroberto * FUNCTION: AcpiDbSingleThread 900182007Sroberto * 901182007Sroberto * PARAMETERS: None 902182007Sroberto * 903182007Sroberto * RETURN: None 904182007Sroberto * 905182007Sroberto * DESCRIPTION: Debugger execute thread. Waits for a command line, then 906182007Sroberto * simply dispatches it. 907182007Sroberto * 908182007Sroberto ******************************************************************************/ 909182007Sroberto 910182007Srobertovoid 911182007SrobertoAcpiDbSingleThread ( 912182007Sroberto void) 913182007Sroberto{ 914182007Sroberto ACPI_STATUS Status = AE_OK; 915182007Sroberto 916182007Sroberto 917182007Sroberto AcpiGbl_MethodExecuting = FALSE; 918182007Sroberto AcpiGbl_StepToNextCall = FALSE; 919182007Sroberto 920182007Sroberto Status = AcpiDbCommandDispatch (LineBuf, NULL, NULL); 921182007Sroberto} 922182007Sroberto 923182007Sroberto 924182007Sroberto/******************************************************************************* 925182007Sroberto * 926182007Sroberto * FUNCTION: AcpiDbUserCommands 927182007Sroberto * 928182007Sroberto * PARAMETERS: Prompt - User prompt (depends on mode) 929182007Sroberto * Op - Current executing parse op 930182007Sroberto * 931182007Sroberto * RETURN: None 932182007Sroberto * 933182007Sroberto * DESCRIPTION: Command line execution for the AML debugger. Commands are 934182007Sroberto * matched and dispatched here. 935182007Sroberto * 936182007Sroberto ******************************************************************************/ 937182007Sroberto 938182007SrobertoACPI_STATUS 939182007SrobertoAcpiDbUserCommands ( 940182007Sroberto NATIVE_CHAR Prompt, 941182007Sroberto ACPI_PARSE_OBJECT *Op) 942182007Sroberto{ 943182007Sroberto ACPI_STATUS Status = AE_OK; 944182007Sroberto 945182007Sroberto 946182007Sroberto /* TBD: [Restructure] Need a separate command line buffer for step mode */ 947182007Sroberto 948182007Sroberto while (!AcpiGbl_DbTerminateThreads) 949182007Sroberto { 950182007Sroberto /* Force output to console until a command is entered */ 951182007Sroberto 952182007Sroberto AcpiDbSetOutputDestination (DB_CONSOLE_OUTPUT); 953182007Sroberto 954182007Sroberto /* Different prompt if method is executing */ 955182007Sroberto 956182007Sroberto if (!AcpiGbl_MethodExecuting) 957182007Sroberto { 958182007Sroberto AcpiOsPrintf ("%1c ", DB_COMMAND_PROMPT); 959182007Sroberto } 960182007Sroberto else 961182007Sroberto { 962182007Sroberto AcpiOsPrintf ("%1c ", DB_EXECUTE_PROMPT); 963182007Sroberto } 964182007Sroberto 965182007Sroberto /* Get the user input line */ 966182007Sroberto 967182007Sroberto AcpiOsGetLine (LineBuf); 968182007Sroberto 969182007Sroberto 970182007Sroberto /* Check for single or multithreaded debug */ 971182007Sroberto 972182007Sroberto if (AcpiGbl_DebuggerConfiguration & DEBUGGER_MULTI_THREADED) 973182007Sroberto { 974182007Sroberto /* 975182007Sroberto * Signal the debug thread that we have a command to execute, 976182007Sroberto * and wait for the command to complete. 977182007Sroberto */ 978182007Sroberto 979182007Sroberto AcpiUtReleaseMutex (ACPI_MTX_DEBUG_CMD_READY); 980182007Sroberto AcpiUtAcquireMutex (ACPI_MTX_DEBUG_CMD_COMPLETE); 981182007Sroberto } 982182007Sroberto 983182007Sroberto else 984182007Sroberto { 985182007Sroberto /* Just call to the command line interpreter */ 986182007Sroberto 987182007Sroberto AcpiDbSingleThread (); 988182007Sroberto } 989182007Sroberto } 990182007Sroberto 991182007Sroberto 992182007Sroberto /* 993182007Sroberto * Only this thread (the original thread) should actually terminate the subsystem, 994182007Sroberto * because all the semaphores are deleted during termination 995182007Sroberto */ 996182007Sroberto AcpiTerminate (); 997182007Sroberto 998182007Sroberto return (Status); 999182007Sroberto} 1000182007Sroberto 1001182007Sroberto 1002182007Sroberto#endif /* ENABLE_DEBUGGER */ 1003182007Sroberto 1004182007Sroberto