0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include <acpi/acpi.h>
0011 #include "accommon.h"
0012 #include "acdebug.h"
0013
0014 #define _COMPONENT ACPI_CA_DEBUGGER
0015 ACPI_MODULE_NAME("dbhistry")
0016
0017 #define HI_NO_HISTORY 0
0018 #define HI_RECORD_HISTORY 1
0019 #define HISTORY_SIZE 40
0020 typedef struct history_info {
0021 char *command;
0022 u32 cmd_num;
0023
0024 } HISTORY_INFO;
0025
0026 static HISTORY_INFO acpi_gbl_history_buffer[HISTORY_SIZE];
0027 static u16 acpi_gbl_lo_history = 0;
0028 static u16 acpi_gbl_num_history = 0;
0029 static u16 acpi_gbl_next_history_index = 0;
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043 void acpi_db_add_to_history(char *command_line)
0044 {
0045 u16 cmd_len;
0046 u16 buffer_len;
0047
0048
0049
0050 cmd_len = (u16)strlen(command_line);
0051 if (!cmd_len) {
0052 return;
0053 }
0054
0055 if (acpi_gbl_history_buffer[acpi_gbl_next_history_index].command !=
0056 NULL) {
0057 buffer_len =
0058 (u16)
0059 strlen(acpi_gbl_history_buffer[acpi_gbl_next_history_index].
0060 command);
0061
0062 if (cmd_len > buffer_len) {
0063 acpi_os_free(acpi_gbl_history_buffer
0064 [acpi_gbl_next_history_index].command);
0065 acpi_gbl_history_buffer[acpi_gbl_next_history_index].
0066 command = acpi_os_allocate(cmd_len + 1);
0067 }
0068 } else {
0069 acpi_gbl_history_buffer[acpi_gbl_next_history_index].command =
0070 acpi_os_allocate(cmd_len + 1);
0071 }
0072
0073 strcpy(acpi_gbl_history_buffer[acpi_gbl_next_history_index].command,
0074 command_line);
0075
0076 acpi_gbl_history_buffer[acpi_gbl_next_history_index].cmd_num =
0077 acpi_gbl_next_cmd_num;
0078
0079
0080
0081 if ((acpi_gbl_num_history == HISTORY_SIZE) &&
0082 (acpi_gbl_next_history_index == acpi_gbl_lo_history)) {
0083 acpi_gbl_lo_history++;
0084 if (acpi_gbl_lo_history >= HISTORY_SIZE) {
0085 acpi_gbl_lo_history = 0;
0086 }
0087 }
0088
0089 acpi_gbl_next_history_index++;
0090 if (acpi_gbl_next_history_index >= HISTORY_SIZE) {
0091 acpi_gbl_next_history_index = 0;
0092 }
0093
0094 acpi_gbl_next_cmd_num++;
0095 if (acpi_gbl_num_history < HISTORY_SIZE) {
0096 acpi_gbl_num_history++;
0097 }
0098 }
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112 void acpi_db_display_history(void)
0113 {
0114 u32 i;
0115 u16 history_index;
0116
0117 history_index = acpi_gbl_lo_history;
0118
0119
0120
0121 for (i = 0; i < acpi_gbl_num_history; i++) {
0122 if (acpi_gbl_history_buffer[history_index].command) {
0123 acpi_os_printf("%3u %s\n",
0124 acpi_gbl_history_buffer[history_index].
0125 cmd_num,
0126 acpi_gbl_history_buffer[history_index].
0127 command);
0128 }
0129
0130 history_index++;
0131 if (history_index >= HISTORY_SIZE) {
0132 history_index = 0;
0133 }
0134 }
0135 }
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150 char *acpi_db_get_from_history(char *command_num_arg)
0151 {
0152 u32 cmd_num;
0153
0154 if (command_num_arg == NULL) {
0155 cmd_num = acpi_gbl_next_cmd_num - 1;
0156 }
0157
0158 else {
0159 cmd_num = strtoul(command_num_arg, NULL, 0);
0160 }
0161
0162 return (acpi_db_get_history_by_index(cmd_num));
0163 }
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178 char *acpi_db_get_history_by_index(u32 cmd_num)
0179 {
0180 u32 i;
0181 u16 history_index;
0182
0183
0184
0185 history_index = acpi_gbl_lo_history;
0186 for (i = 0; i < acpi_gbl_num_history; i++) {
0187 if (acpi_gbl_history_buffer[history_index].cmd_num == cmd_num) {
0188
0189
0190
0191 return (acpi_gbl_history_buffer[history_index].command);
0192 }
0193
0194
0195
0196 history_index++;
0197 if (history_index >= HISTORY_SIZE) {
0198 history_index = 0;
0199 }
0200 }
0201
0202 acpi_os_printf("Invalid history number: %u\n", history_index);
0203 return (NULL);
0204 }