]> CyberLeo.Net >> Repos - FreeBSD/releng/9.0.git/blob - sys/contrib/dev/acpica/debugger/dbhistry.c
Copy stable/9 to releng/9.0 as part of the FreeBSD 9.0-RELEASE release
[FreeBSD/releng/9.0.git] / sys / contrib / dev / acpica / debugger / dbhistry.c
1 /******************************************************************************
2  *
3  * Module Name: dbhistry - debugger HISTORY command
4  *
5  *****************************************************************************/
6
7 /*
8  * Copyright (C) 2000 - 2011, 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
45 #include <contrib/dev/acpica/include/acpi.h>
46 #include <contrib/dev/acpica/include/accommon.h>
47 #include <contrib/dev/acpica/include/acdebug.h>
48
49 #ifdef ACPI_DEBUGGER
50
51 #define _COMPONENT          ACPI_CA_DEBUGGER
52         ACPI_MODULE_NAME    ("dbhistry")
53
54
55 #define HI_NO_HISTORY       0
56 #define HI_RECORD_HISTORY   1
57 #define HISTORY_SIZE        20
58
59
60 typedef struct HistoryInfo
61 {
62     char                    Command[80];
63     UINT32                  CmdNum;
64
65 } HISTORY_INFO;
66
67
68 static HISTORY_INFO         AcpiGbl_HistoryBuffer[HISTORY_SIZE];
69 static UINT16               AcpiGbl_LoHistory = 0;
70 static UINT16               AcpiGbl_NumHistory = 0;
71 static UINT16               AcpiGbl_NextHistoryIndex = 0;
72 static UINT32               AcpiGbl_NextCmdNum = 1;
73
74
75 /*******************************************************************************
76  *
77  * FUNCTION:    AcpiDbAddToHistory
78  *
79  * PARAMETERS:  CommandLine     - Command to add
80  *
81  * RETURN:      None
82  *
83  * DESCRIPTION: Add a command line to the history buffer.
84  *
85  ******************************************************************************/
86
87 void
88 AcpiDbAddToHistory (
89     char                    *CommandLine)
90 {
91
92     /* Put command into the next available slot */
93
94     ACPI_STRCPY (AcpiGbl_HistoryBuffer[AcpiGbl_NextHistoryIndex].Command,
95         CommandLine);
96
97     AcpiGbl_HistoryBuffer[AcpiGbl_NextHistoryIndex].CmdNum = AcpiGbl_NextCmdNum;
98
99     /* Adjust indexes */
100
101     if ((AcpiGbl_NumHistory == HISTORY_SIZE) &&
102         (AcpiGbl_NextHistoryIndex == AcpiGbl_LoHistory))
103     {
104         AcpiGbl_LoHistory++;
105         if (AcpiGbl_LoHistory >= HISTORY_SIZE)
106         {
107             AcpiGbl_LoHistory = 0;
108         }
109     }
110
111     AcpiGbl_NextHistoryIndex++;
112     if (AcpiGbl_NextHistoryIndex >= HISTORY_SIZE)
113     {
114         AcpiGbl_NextHistoryIndex = 0;
115     }
116
117     AcpiGbl_NextCmdNum++;
118     if (AcpiGbl_NumHistory < HISTORY_SIZE)
119     {
120         AcpiGbl_NumHistory++;
121     }
122 }
123
124
125 /*******************************************************************************
126  *
127  * FUNCTION:    AcpiDbDisplayHistory
128  *
129  * PARAMETERS:  None
130  *
131  * RETURN:      None
132  *
133  * DESCRIPTION: Display the contents of the history buffer
134  *
135  ******************************************************************************/
136
137 void
138 AcpiDbDisplayHistory (
139     void)
140 {
141     UINT32                  i;
142     UINT16                  HistoryIndex;
143
144
145     HistoryIndex = AcpiGbl_LoHistory;
146
147     /* Dump entire history buffer */
148
149     for (i = 0; i < AcpiGbl_NumHistory; i++)
150     {
151         AcpiOsPrintf ("%ld  %s\n", AcpiGbl_HistoryBuffer[HistoryIndex].CmdNum,
152                                    AcpiGbl_HistoryBuffer[HistoryIndex].Command);
153
154         HistoryIndex++;
155         if (HistoryIndex >= HISTORY_SIZE)
156         {
157             HistoryIndex = 0;
158         }
159     }
160 }
161
162
163 /*******************************************************************************
164  *
165  * FUNCTION:    AcpiDbGetFromHistory
166  *
167  * PARAMETERS:  CommandNumArg           - String containing the number of the
168  *                                        command to be retrieved
169  *
170  * RETURN:      Pointer to the retrieved command. Null on error.
171  *
172  * DESCRIPTION: Get a command from the history buffer
173  *
174  ******************************************************************************/
175
176 char *
177 AcpiDbGetFromHistory (
178     char                    *CommandNumArg)
179 {
180     UINT32                  i;
181     UINT16                  HistoryIndex;
182     UINT32                  CmdNum;
183
184
185     if (CommandNumArg == NULL)
186     {
187         CmdNum = AcpiGbl_NextCmdNum - 1;
188     }
189
190     else
191     {
192         CmdNum = ACPI_STRTOUL (CommandNumArg, NULL, 0);
193     }
194
195     /* Search history buffer */
196
197     HistoryIndex = AcpiGbl_LoHistory;
198     for (i = 0; i < AcpiGbl_NumHistory; i++)
199     {
200         if (AcpiGbl_HistoryBuffer[HistoryIndex].CmdNum == CmdNum)
201         {
202             /* Found the commnad, return it */
203
204             return (AcpiGbl_HistoryBuffer[HistoryIndex].Command);
205         }
206
207
208         HistoryIndex++;
209         if (HistoryIndex >= HISTORY_SIZE)
210         {
211             HistoryIndex = 0;
212         }
213     }
214
215     AcpiOsPrintf ("Invalid history number: %u\n", HistoryIndex);
216     return (NULL);
217 }
218
219 #endif /* ACPI_DEBUGGER */
220