1 /*- 2 * Copyright (c) 2000 Michael Smith 3 * Copyright (c) 2000 BSDi 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 * 27 * $FreeBSD: head/sys/dev/acpica/Osd/OsdDebug.c 222544 2011-05-31 19:45:58Z jkim $ 28 */ 29 30 /* 31 * Debugging Support 32 */ 33 34 #include "opt_ddb.h" 35 36 #include <sys/param.h> 37 #include <sys/kernel.h> 38 #include <sys/bus.h> 39 #include <ddb/ddb.h> 40 #include <ddb/db_output.h> 41 42 #include "acpi.h" 43 #include "accommon.h" 44 #include "acpivar.h" 45 #include "acdebug.h" 46 47 ACPI_MODULE_NAME("DEBUG") 48 49 ACPI_STATUS 50 AcpiOsGetLine(char *Buffer, UINT32 BufferLength, UINT32 *BytesRead) 51 { 52 #ifdef DDB 53 char *cp; 54 55 cp = Buffer; 56 if (db_readline(Buffer, BufferLength) > 0) 57 while (*cp != '\0' && *cp != '\n' && *cp != '\r') 58 cp++; 59 *cp = '\0'; 60 if (BytesRead != NULL) 61 *BytesRead = cp - Buffer; 62 return (AE_OK); 63 #else 64 kprintf("AcpiOsGetLine called but no input support"); 65 return (AE_NOT_EXIST); 66 #endif /* DDB */ 67 } 68 69 ACPI_STATUS 70 AcpiOsSignal(UINT32 Function, void *Info) 71 { 72 ACPI_SIGNAL_FATAL_INFO *fatal; 73 74 switch (Function) { 75 case ACPI_SIGNAL_FATAL: 76 fatal = (ACPI_SIGNAL_FATAL_INFO *)Info; 77 kprintf("ACPI fatal signal, type 0x%x code 0x%x argument 0x%x", 78 fatal->Type, fatal->Code, fatal->Argument); 79 #ifdef ACPI_DEBUG 80 Debugger("AcpiOsSignal"); 81 #endif 82 break; 83 84 case ACPI_SIGNAL_BREAKPOINT: 85 #ifdef ACPI_DEBUG 86 Debugger((char *)Info); 87 #endif 88 break; 89 90 default: 91 return (AE_BAD_PARAMETER); 92 } 93 94 return (AE_OK); 95 } 96 97 #ifdef ACPI_DEBUGGER 98 ACPI_STATUS 99 AcpiOsInitializeDebugger(void) 100 { 101 return (AE_OK); 102 } 103 104 void 105 AcpiOsTerminateDebugger(void) 106 { 107 } 108 109 ACPI_STATUS 110 AcpiOsWaitCommandReady(void) 111 { 112 ACPI_STATUS Status; 113 114 /* Force output to console until a command is entered */ 115 116 AcpiDbSetOutputDestination(ACPI_DB_CONSOLE_OUTPUT); 117 118 /* Different prompt if method is executing */ 119 120 if (!AcpiGbl_MethodExecuting) 121 AcpiOsPrintf("%1c ", ACPI_DEBUGGER_COMMAND_PROMPT); 122 else 123 AcpiOsPrintf("%1c ", ACPI_DEBUGGER_EXECUTE_PROMPT); 124 125 /* Get the user input line */ 126 127 Status = AcpiOsGetLine(AcpiGbl_DbLineBuf, 128 ACPI_DB_LINE_BUFFER_SIZE, NULL); 129 130 if (ACPI_FAILURE (Status) && Status != AE_CTRL_TERMINATE) 131 ACPI_EXCEPTION ((AE_INFO, Status, 132 "While parsing/handling command line")); 133 return (Status); 134 } 135 136 ACPI_STATUS 137 AcpiOsNotifyCommandComplete(void) 138 { 139 return (AE_OK); 140 } 141 142 DB_COMMAND(acpidb, db_cmd_acpidb) 143 { 144 kprintf("Entering ACPICA debugger...\n"); 145 while (!AcpiGbl_DbTerminateLoop) { 146 if (ACPI_FAILURE(AcpiOsWaitCommandReady())) 147 break; 148 AcpiDbCommandDispatch(AcpiGbl_DbLineBuf, NULL, NULL); 149 } 150 AcpiGbl_DbTerminateLoop = FALSE; 151 kprintf("Leaving ACPICA debugger...\n"); 152 } 153 #endif /* ACPI_DEBUGGER */ 154