dbhistry.c revision 217365
167754Smsmith/****************************************************************************** 267754Smsmith * 367754Smsmith * Module Name: dbhistry - debugger HISTORY command 467754Smsmith * 567754Smsmith *****************************************************************************/ 667754Smsmith 7217365Sjkim/* 8217365Sjkim * Copyright (C) 2000 - 2011, Intel Corp. 970243Smsmith * All rights reserved. 1067754Smsmith * 11217365Sjkim * Redistribution and use in source and binary forms, with or without 12217365Sjkim * modification, are permitted provided that the following conditions 13217365Sjkim * are met: 14217365Sjkim * 1. Redistributions of source code must retain the above copyright 15217365Sjkim * notice, this list of conditions, and the following disclaimer, 16217365Sjkim * without modification. 17217365Sjkim * 2. Redistributions in binary form must reproduce at minimum a disclaimer 18217365Sjkim * substantially similar to the "NO WARRANTY" disclaimer below 19217365Sjkim * ("Disclaimer") and any redistribution must be conditioned upon 20217365Sjkim * including a substantially similar Disclaimer requirement for further 21217365Sjkim * binary redistribution. 22217365Sjkim * 3. Neither the names of the above-listed copyright holders nor the names 23217365Sjkim * of any contributors may be used to endorse or promote products derived 24217365Sjkim * from this software without specific prior written permission. 2567754Smsmith * 26217365Sjkim * Alternatively, this software may be distributed under the terms of the 27217365Sjkim * GNU General Public License ("GPL") version 2 as published by the Free 28217365Sjkim * Software Foundation. 2967754Smsmith * 30217365Sjkim * NO WARRANTY 31217365Sjkim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 32217365Sjkim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 33217365Sjkim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 34217365Sjkim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 35217365Sjkim * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36217365Sjkim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37217365Sjkim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38217365Sjkim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 39217365Sjkim * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 40217365Sjkim * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 41217365Sjkim * POSSIBILITY OF SUCH DAMAGES. 42217365Sjkim */ 4367754Smsmith 4467754Smsmith 45193341Sjkim#include <contrib/dev/acpica/include/acpi.h> 46193341Sjkim#include <contrib/dev/acpica/include/accommon.h> 47193341Sjkim#include <contrib/dev/acpica/include/acdebug.h> 4867754Smsmith 49102550Siwasaki#ifdef ACPI_DEBUGGER 5067754Smsmith 51102550Siwasaki#define _COMPONENT ACPI_CA_DEBUGGER 5291116Smsmith ACPI_MODULE_NAME ("dbhistry") 5367754Smsmith 5467754Smsmith 5567754Smsmith#define HI_NO_HISTORY 0 5667754Smsmith#define HI_RECORD_HISTORY 1 5767754Smsmith#define HISTORY_SIZE 20 5867754Smsmith 5967754Smsmith 6067754Smsmithtypedef struct HistoryInfo 6167754Smsmith{ 62114237Snjl char Command[80]; 6367754Smsmith UINT32 CmdNum; 6467754Smsmith 6567754Smsmith} HISTORY_INFO; 6667754Smsmith 6767754Smsmith 6899679Siwasakistatic HISTORY_INFO AcpiGbl_HistoryBuffer[HISTORY_SIZE]; 6999679Siwasakistatic UINT16 AcpiGbl_LoHistory = 0; 7099679Siwasakistatic UINT16 AcpiGbl_NumHistory = 0; 7199679Siwasakistatic UINT16 AcpiGbl_NextHistoryIndex = 0; 7299679Siwasakistatic UINT32 AcpiGbl_NextCmdNum = 1; 7367754Smsmith 7467754Smsmith 7567754Smsmith/******************************************************************************* 7667754Smsmith * 7767754Smsmith * FUNCTION: AcpiDbAddToHistory 7867754Smsmith * 7967754Smsmith * PARAMETERS: CommandLine - Command to add 8067754Smsmith * 8167754Smsmith * RETURN: None 8267754Smsmith * 8367754Smsmith * DESCRIPTION: Add a command line to the history buffer. 8467754Smsmith * 8567754Smsmith ******************************************************************************/ 8667754Smsmith 8767754Smsmithvoid 8867754SmsmithAcpiDbAddToHistory ( 89114237Snjl char *CommandLine) 9067754Smsmith{ 9167754Smsmith 9267754Smsmith /* Put command into the next available slot */ 9367754Smsmith 94151937Sjkim ACPI_STRCPY (AcpiGbl_HistoryBuffer[AcpiGbl_NextHistoryIndex].Command, 95151937Sjkim CommandLine); 9667754Smsmith 9783174Smsmith AcpiGbl_HistoryBuffer[AcpiGbl_NextHistoryIndex].CmdNum = AcpiGbl_NextCmdNum; 9883174Smsmith 9967754Smsmith /* Adjust indexes */ 10067754Smsmith 10183174Smsmith if ((AcpiGbl_NumHistory == HISTORY_SIZE) && 10283174Smsmith (AcpiGbl_NextHistoryIndex == AcpiGbl_LoHistory)) 10367754Smsmith { 10483174Smsmith AcpiGbl_LoHistory++; 10583174Smsmith if (AcpiGbl_LoHistory >= HISTORY_SIZE) 10667754Smsmith { 10783174Smsmith AcpiGbl_LoHistory = 0; 10867754Smsmith } 10967754Smsmith } 11067754Smsmith 11183174Smsmith AcpiGbl_NextHistoryIndex++; 11283174Smsmith if (AcpiGbl_NextHistoryIndex >= HISTORY_SIZE) 11367754Smsmith { 11483174Smsmith AcpiGbl_NextHistoryIndex = 0; 11567754Smsmith } 11667754Smsmith 11783174Smsmith AcpiGbl_NextCmdNum++; 11883174Smsmith if (AcpiGbl_NumHistory < HISTORY_SIZE) 11967754Smsmith { 12083174Smsmith AcpiGbl_NumHistory++; 12167754Smsmith } 12267754Smsmith} 12367754Smsmith 12467754Smsmith 12567754Smsmith/******************************************************************************* 12667754Smsmith * 12767754Smsmith * FUNCTION: AcpiDbDisplayHistory 12867754Smsmith * 12967754Smsmith * PARAMETERS: None 13067754Smsmith * 13167754Smsmith * RETURN: None 13267754Smsmith * 13367754Smsmith * DESCRIPTION: Display the contents of the history buffer 13467754Smsmith * 13567754Smsmith ******************************************************************************/ 13667754Smsmith 13767754Smsmithvoid 138151937SjkimAcpiDbDisplayHistory ( 139151937Sjkim void) 14067754Smsmith{ 141193267Sjkim UINT32 i; 14267754Smsmith UINT16 HistoryIndex; 14367754Smsmith 14467754Smsmith 14583174Smsmith HistoryIndex = AcpiGbl_LoHistory; 14667754Smsmith 14767754Smsmith /* Dump entire history buffer */ 14867754Smsmith 14983174Smsmith for (i = 0; i < AcpiGbl_NumHistory; i++) 15067754Smsmith { 15183174Smsmith AcpiOsPrintf ("%ld %s\n", AcpiGbl_HistoryBuffer[HistoryIndex].CmdNum, 15283174Smsmith AcpiGbl_HistoryBuffer[HistoryIndex].Command); 15367754Smsmith 15467754Smsmith HistoryIndex++; 15567754Smsmith if (HistoryIndex >= HISTORY_SIZE) 15667754Smsmith { 15767754Smsmith HistoryIndex = 0; 15867754Smsmith } 15967754Smsmith } 16067754Smsmith} 16167754Smsmith 16267754Smsmith 16367754Smsmith/******************************************************************************* 16467754Smsmith * 16567754Smsmith * FUNCTION: AcpiDbGetFromHistory 16667754Smsmith * 16767754Smsmith * PARAMETERS: CommandNumArg - String containing the number of the 16867754Smsmith * command to be retrieved 16967754Smsmith * 170151937Sjkim * RETURN: Pointer to the retrieved command. Null on error. 17167754Smsmith * 17267754Smsmith * DESCRIPTION: Get a command from the history buffer 17367754Smsmith * 17467754Smsmith ******************************************************************************/ 17567754Smsmith 176114237Snjlchar * 17767754SmsmithAcpiDbGetFromHistory ( 178114237Snjl char *CommandNumArg) 17967754Smsmith{ 180193267Sjkim UINT32 i; 18167754Smsmith UINT16 HistoryIndex; 18267754Smsmith UINT32 CmdNum; 18367754Smsmith 18467754Smsmith 18567754Smsmith if (CommandNumArg == NULL) 18667754Smsmith { 18783174Smsmith CmdNum = AcpiGbl_NextCmdNum - 1; 18867754Smsmith } 18967754Smsmith 19067754Smsmith else 19167754Smsmith { 19291116Smsmith CmdNum = ACPI_STRTOUL (CommandNumArg, NULL, 0); 19367754Smsmith } 19467754Smsmith 19567754Smsmith /* Search history buffer */ 19667754Smsmith 19783174Smsmith HistoryIndex = AcpiGbl_LoHistory; 19883174Smsmith for (i = 0; i < AcpiGbl_NumHistory; i++) 19967754Smsmith { 20083174Smsmith if (AcpiGbl_HistoryBuffer[HistoryIndex].CmdNum == CmdNum) 20167754Smsmith { 20267754Smsmith /* Found the commnad, return it */ 20367754Smsmith 20483174Smsmith return (AcpiGbl_HistoryBuffer[HistoryIndex].Command); 20567754Smsmith } 20667754Smsmith 20767754Smsmith 20867754Smsmith HistoryIndex++; 20967754Smsmith if (HistoryIndex >= HISTORY_SIZE) 21067754Smsmith { 21167754Smsmith HistoryIndex = 0; 21267754Smsmith } 21367754Smsmith } 21467754Smsmith 215209746Sjkim AcpiOsPrintf ("Invalid history number: %u\n", HistoryIndex); 21667754Smsmith return (NULL); 21767754Smsmith} 21867754Smsmith 219102550Siwasaki#endif /* ACPI_DEBUGGER */ 22067754Smsmith 221