github.com/jlmucb/cloudproxy@v0.0.0-20170830161738-b5aa0b619bc4/cpvmm/vmm/include/vmm_dbg.h (about) 1 /* 2 * Copyright (c) 2013 Intel Corporation 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * Unless required by applicable law or agreed to in writing, software 9 * distributed under the License is distributed on an "AS IS" BASIS, 10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 * See the License for the specific language governing permissions and 12 * limitations under the License. 13 */ 14 15 #pragma once 16 #ifndef _VMM_DBG_H_ 17 #define _VMM_DBG_H_ 18 19 #include "vmm_startup.h" 20 #include "heap.h" 21 #include "cli_monitor.h" 22 23 24 extern CPU_ID hw_cpu_id(); 25 extern void ipc_set_no_resend_flag(BOOLEAN val); 26 extern BOOLEAN vmm_debug_port_init_params(const VMM_DEBUG_PORT_PARAMS *p_params); 27 extern VMM_DEBUG_PORT_VIRT_MODE vmm_debug_port_get_virt_mode(void); 28 extern UINT16 vmm_debug_port_get_io_base(void);// If the debug port uses an I/O range, returns its base address. -Otherwise, returns 0 29 extern UINT16 vmm_debug_port_get_io_end(void);// If the debug port uses an I/O range, returns its end address. - Otherwise, returns 0 30 extern int vmm_printf( const char *format, ...);// __attribute__((format (printf, 1,2))); 31 extern int vmm_vprintf(const char *format, va_list args); 32 #ifdef VMM_DEBUG_SCREEN 33 extern void vmm_printf_screen( const char *format, ...); 34 extern void vmm_clear_screen(void); 35 #endif 36 37 extern VMM_STARTUP_STRUCT vmm_startup_data; 38 extern void vmm_deadloop_dump(UINT32 file_code, UINT32 line_num); 39 40 BOOLEAN DeadloopHelper(const char* assert_condition, const char* func_name, 41 const char* file_name, UINT32 line_num, UINT32 access_level); 42 43 #ifdef DEBUG 44 #define VMM_DEBUG_CODE(__xxx) __xxx 45 #else 46 #define VMM_DEBUG_CODE(__xxx) 47 #endif 48 49 50 51 enum debug_bit_mask 52 { 53 // NOTE: values should be in the range of 0 - 31 54 mask_anonymous = 0, // a temporary mask to maintain backwards compatibility. Eventually every component should create its own mask. 55 mask_cli = 1, 56 mask_emulator = 2, 57 mask_gdb = 3, 58 mask_ept = 4, 59 mask_uvmm = 5, 60 mask_tmm = 6, 61 mask_tmsl = 7, 62 mask_handler = 8 63 }; 64 65 #define DEBUG_MASK_ALL (unsigned long long)(-1) 66 67 68 69 enum msg_level 70 { 71 level_print_always = 0, 72 level_error = 1, 73 level_warning = 2, 74 level_info = 3, 75 level_trace = 4 76 }; 77 78 79 #define VMM_COMPILE_TIME_ADDRESS(__a) ((__a) - vmm_startup_data.vmm_memory_layout[uvmm_image].base_address) 80 #define VMM_RANGE_ADDRESS(__a) \ 81 ((__a) >= vmm_startup_data.vmm_memory_layout[uvmm_image].base_address && \ 82 (__a) < (vmm_startup_data.vmm_memory_layout[uvmm_image].base_address + vmm_startup_data.vmm_memory_layout[uvmm_image].total_size)) 83 84 #define VMM_DEFAULT_LOG_MASK vmm_startup_data.debug_params.mask 85 #define VMM_DEFAULT_LOG_LEVEL vmm_startup_data.debug_params.verbosity 86 87 88 #define VMM_BREAKPOINT() \ 89 { \ 90 ipc_set_no_resend_flag(TRUE); \ 91 VMM_UP_BREAKPOINT(); \ 92 } 93 94 #ifdef CLI_INCLUDE 95 #define VMM_DEADLOOP_HELPER Cli_DeadloopHelper 96 #else 97 #define VMM_DEADLOOP_HELPER DeadloopHelper 98 #endif 99 100 //JLM(FIX) 101 #if 0 102 #ifdef DEBUG 103 #define VMM_DEADLOOP_LOG(FILE_CODE) \ 104 { \ 105 if (VMM_DEADLOOP_HELPER(NULL, __FUNCTION__, __FILE__, __LINE__, 1)) \ 106 { \ 107 VMM_UP_BREAKPOINT(); \ 108 } \ 109 } 110 #else 111 #define VMM_DEADLOOP_LOG(FILE_CODE) vmm_deadloop_dump(FILE_CODE, __LINE__); 112 #endif 113 #else 114 #define VMM_DEADLOOP_LOG(FILE_CODE) 115 #endif 116 117 118 #ifdef LOG_MASK 119 #define VMM_MASK_CHECK(MASK) (((unsigned long long)1<<MASK) & LOG_MASK) && (((unsigned long long)1<<MASK) & VMM_DEFAULT_LOG_MASK) 120 #else 121 #define VMM_MASK_CHECK(MASK) (((unsigned long long)1<<MASK) & VMM_DEFAULT_LOG_MASK) 122 #endif 123 124 #ifdef LOG_LEVEL 125 #define VMM_LEVEL_CHECK(LEVEL) (LEVEL <= LOG_LEVEL) && (LEVEL <= VMM_DEFAULT_LOG_LEVEL) 126 #else 127 #define VMM_LEVEL_CHECK(LEVEL) (LEVEL <= VMM_DEFAULT_LOG_LEVEL) 128 #endif 129 130 //JLM(FIX) 131 #if 0 132 #if defined ENABLE_RELEASE_VMM_LOG && !defined DEBUG 133 #define VMM_LOG(MASK,LEVEL,...) ((((LEVEL==level_print_always) || (LEVEL==level_error)) && (VMM_MASK_CHECK(MASK) && VMM_LEVEL_CHECK(LEVEL))) && (vmm_printf(__VA_ARGS__))) 134 #else 135 #define VMM_LOG(MASK,LEVEL,...) VMM_DEBUG_CODE(((LEVEL==level_print_always) || (LEVEL==level_error) || ((VMM_MASK_CHECK(MASK) && VMM_LEVEL_CHECK(LEVEL)))) && (vmm_printf(__VA_ARGS__))) 136 #endif 137 #else 138 #define VMM_LOG(MASK,LEVEL,...) 139 #endif 140 141 142 #ifdef VMM_DEBUG_SCREEN 143 #define VMM_LOG_SCREEN(...) VMM_DEBUG_CODE(vmm_printf_screen(__VA_ARGS__)) 144 #else 145 #define VMM_LOG_SCREEN(...) 146 #endif 147 #define VMM_LOG_NOLOCK(...) VMM_DEBUG_CODE(vmm_printf_nolock(__VA_ARGS__)) 148 149 //JLM(FIX) 150 #if 0 151 #ifdef DEBUG 152 #define VMM_ASSERT_LOG(FILE_CODE, __condition) \ 153 { \ 154 if ( ! (__condition)) \ 155 { \ 156 if (VMM_DEADLOOP_HELPER(#__condition, __FUNCTION__, __FILE__, __LINE__, 1)) \ 157 { \ 158 VMM_UP_BREAKPOINT(); \ 159 } \ 160 } \ 161 } 162 #else 163 #define VMM_ASSERT_LOG(FILE_CODE, __condition) \ 164 { \ 165 if ( ! (__condition)) \ 166 { \ 167 vmm_deadloop_dump(FILE_CODE, __LINE__); \ 168 } \ 169 } 170 #endif 171 #else 172 // TODO(tmroeder): Fix ASSERT to work correct and not just ignore the condition. 173 #define VMM_ASSERT_LOG(FILE_CODE, __condition) (void)(__condition); 174 175 #endif 176 177 #define VMM_ASSERT_NOLOCK_LOG(FILE_CODE, __condition) VMM_ASSERT_LOG(FILE_CODE, __condition) 178 179 #define VMM_CALLTRACE_ENTER() VMM_LOG(mask_anonymous, level_trace, "[%d enter>>> %s\n", hw_cpu_id(), __FUNCTION__) 180 #define VMM_CALLTRACE_LEAVE() VMM_LOG(mask_anonymous, level_trace, "<<<leave %d] %s\n", hw_cpu_id(), __FUNCTION__) 181 182 183 int CLI_active(void); 184 185 /* ERROR levels used in the macros below. */ 186 enum error_level 187 { 188 API_ERROR = 0, 189 FATAL_ERROR = 1, 190 FATAL_ERROR_DEADLOOP = 2 191 }; 192 193 194 /* Depending on the error_level, it either injects an exception into the 195 * guest or causes an infinite loop that never returns. 196 */ 197 #define VMM_ERROR_CHECK(__condition, __error_level) \ 198 { \ 199 if ( ! (__condition)) \ 200 { \ 201 Cli_HandleError(#__condition, __FUNCTION__, __FILE__, __LINE__, __error_level);\ 202 } \ 203 } 204 205 #endif // _VMM_DBG_H_ 206 207