| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (c) 2005-2011, Broadcom Corporation |
|---|
| 3 | * All Rights Reserved |
|---|
| 4 | * Confidential Property of Broadcom Corporation |
|---|
| 5 | * |
|---|
| 6 | * THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE |
|---|
| 7 | * AGREEMENT BETWEEN THE USER AND BROADCOM. YOU HAVE NO RIGHT TO USE OR |
|---|
| 8 | * EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. |
|---|
| 9 | * |
|---|
| 10 | * $brcm_Workfile: brdc_dbg.c $ |
|---|
| 11 | * $brcm_Revision: Hydra_Software_Devel/11 $ |
|---|
| 12 | * $brcm_Date: 10/6/11 2:00p $ |
|---|
| 13 | * |
|---|
| 14 | * Module Description: |
|---|
| 15 | * |
|---|
| 16 | * Revision History: |
|---|
| 17 | * |
|---|
| 18 | ***************************************************************************/ |
|---|
| 19 | |
|---|
| 20 | #include "bstd.h" |
|---|
| 21 | #include "bkni.h" |
|---|
| 22 | #include "brdc.h" |
|---|
| 23 | #include "brdc_private.h" |
|---|
| 24 | |
|---|
| 25 | #include "brdc_dbg.h" |
|---|
| 26 | |
|---|
| 27 | BDBG_MODULE(BRDC_DBG); |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | /*************************************************************************** |
|---|
| 31 | * |
|---|
| 32 | */ |
|---|
| 33 | BERR_Code BRDC_DBG_SetList( |
|---|
| 34 | BRDC_List_Handle hList |
|---|
| 35 | ) |
|---|
| 36 | { |
|---|
| 37 | BERR_Code eErr = BERR_SUCCESS; |
|---|
| 38 | |
|---|
| 39 | /* initialize list state */ |
|---|
| 40 | hList->eNextEntry = BRDC_DBG_ListEntry_eCommand; |
|---|
| 41 | |
|---|
| 42 | BKNI_EnterCriticalSection(); |
|---|
| 43 | hList->pulCurListAddr = BRDC_List_GetStartAddress_isr(hList); |
|---|
| 44 | |
|---|
| 45 | /* get number of entries */ |
|---|
| 46 | eErr = BERR_TRACE(BRDC_List_GetNumEntries_isr(hList, &hList->ulNumEntries)); |
|---|
| 47 | BKNI_LeaveCriticalSection(); |
|---|
| 48 | |
|---|
| 49 | return eErr; |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | /*************************************************************************** |
|---|
| 54 | * |
|---|
| 55 | */ |
|---|
| 56 | BERR_Code BRDC_DBG_SetList_isr( |
|---|
| 57 | BRDC_List_Handle hList |
|---|
| 58 | ) |
|---|
| 59 | { |
|---|
| 60 | BERR_Code eErr = BERR_SUCCESS; |
|---|
| 61 | |
|---|
| 62 | /* initialize list state */ |
|---|
| 63 | hList->eNextEntry = BRDC_DBG_ListEntry_eCommand; |
|---|
| 64 | |
|---|
| 65 | hList->pulCurListAddr = BRDC_List_GetStartAddress_isr(hList); |
|---|
| 66 | |
|---|
| 67 | /* get number of entries */ |
|---|
| 68 | eErr = BERR_TRACE(BRDC_List_GetNumEntries_isr(hList, &hList->ulNumEntries)); |
|---|
| 69 | |
|---|
| 70 | /*printf("++++++++++++++++++++++++++++++++++++++++++++++ hList->ulNumEntries = %d\n", hList->ulNumEntries);*/ |
|---|
| 71 | |
|---|
| 72 | return eErr; |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | /*************************************************************************** |
|---|
| 77 | * |
|---|
| 78 | */ |
|---|
| 79 | BERR_Code BRDC_DBG_GetListEntry( |
|---|
| 80 | BRDC_List_Handle hList, |
|---|
| 81 | BRDC_DBG_ListEntry *peEntry, |
|---|
| 82 | uint32_t aulArgs[4] |
|---|
| 83 | ) |
|---|
| 84 | { |
|---|
| 85 | BERR_Code eErr = BERR_SUCCESS; |
|---|
| 86 | uint32_t ulEntry; |
|---|
| 87 | |
|---|
| 88 | /* clear out arguments */ |
|---|
| 89 | BKNI_Memset(aulArgs, 0x0, sizeof(uint32_t) * 4); |
|---|
| 90 | |
|---|
| 91 | /* no more entries in list? */ |
|---|
| 92 | if(hList->ulNumEntries == 0) |
|---|
| 93 | { |
|---|
| 94 | /* next entry better be a command or we stopped in mid command */ |
|---|
| 95 | if(hList->eNextEntry != BRDC_DBG_ListEntry_eCommand) |
|---|
| 96 | { |
|---|
| 97 | /* error */ |
|---|
| 98 | eErr = BERR_TRACE(BERR_UNKNOWN); |
|---|
| 99 | goto done; |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | /* list terminated correctly */ |
|---|
| 103 | *peEntry = BRDC_DBG_ListEntry_eEnd; |
|---|
| 104 | goto done; |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | /* get next entry in list */ |
|---|
| 108 | *peEntry = hList->eNextEntry; |
|---|
| 109 | ulEntry = *(hList->pulCurListAddr++); |
|---|
| 110 | --hList->ulNumEntries; |
|---|
| 111 | |
|---|
| 112 | /* current entry should be a command? */ |
|---|
| 113 | if(hList->eNextEntry == BRDC_DBG_ListEntry_eCommand) |
|---|
| 114 | { |
|---|
| 115 | /* which command? */ |
|---|
| 116 | aulArgs[0] = BRDC_GET_OPCODE(ulEntry); |
|---|
| 117 | hList->ulCurrCommand = aulArgs[0]; |
|---|
| 118 | hList->iCommandIndex = 0; |
|---|
| 119 | hList->iDataCount = 0; |
|---|
| 120 | |
|---|
| 121 | /* get other command entries */ |
|---|
| 122 | switch(hList->ulCurrCommand) |
|---|
| 123 | { |
|---|
| 124 | case BRDC_OP_REG_TO_VAR_OPCODE: |
|---|
| 125 | case BRDC_OP_IMM_TO_VAR_OPCODE: |
|---|
| 126 | /* variable stored in bits 5-0 */ |
|---|
| 127 | aulArgs[1] = ulEntry & UINT32_C(0x3F); |
|---|
| 128 | break; |
|---|
| 129 | |
|---|
| 130 | case BRDC_OP_VAR_TO_REG_OPCODE: |
|---|
| 131 | case BRDC_OP_COND_SKIP_OPCODE: |
|---|
| 132 | /* variable stored in bits 17-12 */ |
|---|
| 133 | aulArgs[1] = (ulEntry >> 12) & UINT32_C(0x3F); |
|---|
| 134 | break; |
|---|
| 135 | |
|---|
| 136 | case BRDC_OP_IMMS_TO_REG_OPCODE: |
|---|
| 137 | case BRDC_OP_IMMS_TO_REGS_OPCODE: |
|---|
| 138 | /* count-1 stored in bits 11-0 (store data count) */ |
|---|
| 139 | aulArgs[1] = (ulEntry & UINT32_C(0xFFF)) + 1; |
|---|
| 140 | hList->iDataCount = aulArgs[1]; |
|---|
| 141 | break; |
|---|
| 142 | |
|---|
| 143 | case BRDC_OP_REG_TO_REG_OPCODE: |
|---|
| 144 | case BRDC_OP_REGS_TO_REGS_OPCODE: |
|---|
| 145 | case BRDC_OP_REG_TO_REGS_OPCODE: |
|---|
| 146 | case BRDC_OP_REGS_TO_REG_OPCODE: |
|---|
| 147 | /* count-1 stored in bits 11-0 */ |
|---|
| 148 | aulArgs[1] = (ulEntry & UINT32_C(0xFFF)) + 1; |
|---|
| 149 | break; |
|---|
| 150 | |
|---|
| 151 | case BRDC_OP_VAR_AND_VAR_TO_VAR_OPCODE: |
|---|
| 152 | case BRDC_OP_VAR_OR_VAR_TO_VAR_OPCODE: |
|---|
| 153 | case BRDC_OP_VAR_XOR_VAR_TO_VAR_OPCODE: |
|---|
| 154 | case BRDC_OP_VAR_SUM_VAR_TO_VAR_OPCODE: |
|---|
| 155 | /* bit 17-12 = src1; bit 11-6 = src2; bit 5-0 = dst */ |
|---|
| 156 | aulArgs[1] = (ulEntry >> 12) & UINT32_C(0x3F); |
|---|
| 157 | aulArgs[2] = (ulEntry >> 6) & UINT32_C(0x3F); |
|---|
| 158 | aulArgs[3] = (ulEntry ) & UINT32_C(0x3F); |
|---|
| 159 | break; |
|---|
| 160 | |
|---|
| 161 | case BRDC_OP_VAR_AND_IMM_TO_VAR_OPCODE: |
|---|
| 162 | case BRDC_OP_VAR_OR_IMM_TO_VAR_OPCODE: |
|---|
| 163 | case BRDC_OP_VAR_XOR_IMM_TO_VAR_OPCODE: |
|---|
| 164 | case BRDC_OP_NOT_VAR_TO_VAR_OPCODE: |
|---|
| 165 | case BRDC_OP_VAR_SUM_IMM_TO_VAR_OPCODE: |
|---|
| 166 | /* bit 17-12 = src; bit 5-0 = dst */ |
|---|
| 167 | aulArgs[1] = (ulEntry >> 12) & UINT32_C(0x3F); |
|---|
| 168 | aulArgs[2] = (ulEntry ) & UINT32_C(0x3F); |
|---|
| 169 | break; |
|---|
| 170 | |
|---|
| 171 | case BRDC_OP_VAR_ROR_TO_VAR_OPCODE: |
|---|
| 172 | /* bit 22-18 = rotate; bit 17-12 = src; bit 5-0 = dst */ |
|---|
| 173 | aulArgs[1] = (ulEntry >> 18) & UINT32_C(0x1F); |
|---|
| 174 | aulArgs[2] = (ulEntry >> 12) & UINT32_C(0x3F); |
|---|
| 175 | aulArgs[3] = (ulEntry ) & UINT32_C(0x3F); |
|---|
| 176 | break; |
|---|
| 177 | |
|---|
| 178 | case BRDC_OP_NOP_OPCODE: |
|---|
| 179 | case BRDC_OP_IMM_TO_REG_OPCODE: |
|---|
| 180 | case BRDC_OP_SKIP_OPCODE: |
|---|
| 181 | case BRDC_OP_EXIT_OPCODE: |
|---|
| 182 | /* no extra data in command word */ |
|---|
| 183 | break; |
|---|
| 184 | |
|---|
| 185 | default: |
|---|
| 186 | /* unknown command */ |
|---|
| 187 | eErr = BERR_TRACE(BERR_UNKNOWN); |
|---|
| 188 | goto done; |
|---|
| 189 | } |
|---|
| 190 | |
|---|
| 191 | /* next entry is not a command */ |
|---|
| 192 | } else |
|---|
| 193 | { |
|---|
| 194 | /* register? */ |
|---|
| 195 | if(hList->eNextEntry == BRDC_DBG_ListEntry_eRegister) |
|---|
| 196 | { |
|---|
| 197 | /* convert RDC register to offset register type */ |
|---|
| 198 | aulArgs[0] = BRDC_REGISTER_TO_OFFSET(ulEntry); |
|---|
| 199 | |
|---|
| 200 | /* data */ |
|---|
| 201 | } else |
|---|
| 202 | { |
|---|
| 203 | /* unmodified data */ |
|---|
| 204 | aulArgs[0] = ulEntry; |
|---|
| 205 | } |
|---|
| 206 | } |
|---|
| 207 | |
|---|
| 208 | /* determine what the next value should be next time */ |
|---|
| 209 | switch(hList->ulCurrCommand) |
|---|
| 210 | { |
|---|
| 211 | case BRDC_OP_IMM_TO_REG_OPCODE: |
|---|
| 212 | /* register then data */ |
|---|
| 213 | if(hList->iCommandIndex == 0) |
|---|
| 214 | { |
|---|
| 215 | /* register */ |
|---|
| 216 | hList->eNextEntry = BRDC_DBG_ListEntry_eRegister; |
|---|
| 217 | } else if(hList->iCommandIndex == 1) |
|---|
| 218 | { |
|---|
| 219 | /* data */ |
|---|
| 220 | hList->eNextEntry = BRDC_DBG_ListEntry_eData; |
|---|
| 221 | } else |
|---|
| 222 | { |
|---|
| 223 | /* next command */ |
|---|
| 224 | hList->eNextEntry = BRDC_DBG_ListEntry_eCommand; |
|---|
| 225 | } |
|---|
| 226 | break; |
|---|
| 227 | |
|---|
| 228 | case BRDC_OP_VAR_TO_REG_OPCODE: |
|---|
| 229 | case BRDC_OP_REG_TO_VAR_OPCODE: |
|---|
| 230 | case BRDC_OP_COND_SKIP_OPCODE: |
|---|
| 231 | /* register only */ |
|---|
| 232 | if(hList->iCommandIndex == 0) |
|---|
| 233 | { |
|---|
| 234 | /* register */ |
|---|
| 235 | hList->eNextEntry = BRDC_DBG_ListEntry_eRegister; |
|---|
| 236 | } else |
|---|
| 237 | { |
|---|
| 238 | /* next command */ |
|---|
| 239 | hList->eNextEntry = BRDC_DBG_ListEntry_eCommand; |
|---|
| 240 | } |
|---|
| 241 | break; |
|---|
| 242 | |
|---|
| 243 | case BRDC_OP_IMM_TO_VAR_OPCODE: |
|---|
| 244 | case BRDC_OP_VAR_AND_IMM_TO_VAR_OPCODE: |
|---|
| 245 | case BRDC_OP_VAR_OR_IMM_TO_VAR_OPCODE: |
|---|
| 246 | case BRDC_OP_VAR_XOR_IMM_TO_VAR_OPCODE: |
|---|
| 247 | case BRDC_OP_VAR_SUM_IMM_TO_VAR_OPCODE: |
|---|
| 248 | /* data only */ |
|---|
| 249 | if(hList->iCommandIndex == 0) |
|---|
| 250 | { |
|---|
| 251 | /* register */ |
|---|
| 252 | hList->eNextEntry = BRDC_DBG_ListEntry_eData; |
|---|
| 253 | } else |
|---|
| 254 | { |
|---|
| 255 | /* next command */ |
|---|
| 256 | hList->eNextEntry = BRDC_DBG_ListEntry_eCommand; |
|---|
| 257 | } |
|---|
| 258 | break; |
|---|
| 259 | |
|---|
| 260 | case BRDC_OP_VAR_AND_VAR_TO_VAR_OPCODE: |
|---|
| 261 | case BRDC_OP_VAR_OR_VAR_TO_VAR_OPCODE: |
|---|
| 262 | case BRDC_OP_VAR_XOR_VAR_TO_VAR_OPCODE: |
|---|
| 263 | case BRDC_OP_VAR_SUM_VAR_TO_VAR_OPCODE: |
|---|
| 264 | /* no data follows command */ |
|---|
| 265 | hList->eNextEntry = BRDC_DBG_ListEntry_eCommand; |
|---|
| 266 | break; |
|---|
| 267 | |
|---|
| 268 | case BRDC_OP_IMMS_TO_REG_OPCODE: |
|---|
| 269 | case BRDC_OP_IMMS_TO_REGS_OPCODE: |
|---|
| 270 | /* single register then N data */ |
|---|
| 271 | if(hList->iCommandIndex == 0) |
|---|
| 272 | { |
|---|
| 273 | /* register */ |
|---|
| 274 | hList->eNextEntry = BRDC_DBG_ListEntry_eRegister; |
|---|
| 275 | } else if(hList->iCommandIndex <= hList->iDataCount) |
|---|
| 276 | { |
|---|
| 277 | /* data */ |
|---|
| 278 | hList->eNextEntry = BRDC_DBG_ListEntry_eData; |
|---|
| 279 | } else |
|---|
| 280 | { |
|---|
| 281 | /* next command */ |
|---|
| 282 | hList->eNextEntry = BRDC_DBG_ListEntry_eCommand; |
|---|
| 283 | } |
|---|
| 284 | break; |
|---|
| 285 | |
|---|
| 286 | case BRDC_OP_REG_TO_REG_OPCODE: |
|---|
| 287 | case BRDC_OP_REGS_TO_REGS_OPCODE: |
|---|
| 288 | case BRDC_OP_REG_TO_REGS_OPCODE: |
|---|
| 289 | case BRDC_OP_REGS_TO_REG_OPCODE: |
|---|
| 290 | /* source register followed by destination register */ |
|---|
| 291 | if(hList->iCommandIndex <= 1) |
|---|
| 292 | { |
|---|
| 293 | /* register */ |
|---|
| 294 | hList->eNextEntry = BRDC_DBG_ListEntry_eRegister; |
|---|
| 295 | } else |
|---|
| 296 | { |
|---|
| 297 | /* next command */ |
|---|
| 298 | hList->eNextEntry = BRDC_DBG_ListEntry_eCommand; |
|---|
| 299 | } |
|---|
| 300 | break; |
|---|
| 301 | |
|---|
| 302 | case BRDC_OP_NOT_VAR_TO_VAR_OPCODE: |
|---|
| 303 | case BRDC_OP_VAR_ROR_TO_VAR_OPCODE: |
|---|
| 304 | case BRDC_OP_NOP_OPCODE: |
|---|
| 305 | case BRDC_OP_SKIP_OPCODE: |
|---|
| 306 | case BRDC_OP_EXIT_OPCODE: |
|---|
| 307 | /* no data follows command */ |
|---|
| 308 | hList->eNextEntry = BRDC_DBG_ListEntry_eCommand; |
|---|
| 309 | break; |
|---|
| 310 | |
|---|
| 311 | default: |
|---|
| 312 | /* unknown command */ |
|---|
| 313 | eErr = BERR_TRACE(BERR_UNKNOWN); |
|---|
| 314 | goto done; |
|---|
| 315 | } |
|---|
| 316 | |
|---|
| 317 | /* next command index */ |
|---|
| 318 | ++hList->iCommandIndex; |
|---|
| 319 | |
|---|
| 320 | done: |
|---|
| 321 | return eErr; |
|---|
| 322 | } |
|---|
| 323 | |
|---|
| 324 | BERR_Code BRDC_DBG_GetListEntry_isr( |
|---|
| 325 | BRDC_List_Handle hList, |
|---|
| 326 | BRDC_DBG_ListEntry *peEntry, |
|---|
| 327 | uint32_t aulArgs[4] |
|---|
| 328 | ) |
|---|
| 329 | { |
|---|
| 330 | return (BRDC_DBG_GetListEntry(hList, peEntry, aulArgs)); |
|---|
| 331 | } |
|---|
| 332 | |
|---|
| 333 | /*************************************************************************** |
|---|
| 334 | * |
|---|
| 335 | */ |
|---|
| 336 | BERR_Code BRDC_DBG_DumpList( |
|---|
| 337 | BRDC_List_Handle hList |
|---|
| 338 | ) |
|---|
| 339 | { |
|---|
| 340 | BERR_Code eErr = BERR_SUCCESS; |
|---|
| 341 | BRDC_DBG_ListEntry eEntry = BRDC_DBG_ListEntry_eCommand; |
|---|
| 342 | uint32_t aulArgs[4]; |
|---|
| 343 | |
|---|
| 344 | /* store the list to be dumped */ |
|---|
| 345 | eErr = BERR_TRACE(BRDC_DBG_SetList(hList)); |
|---|
| 346 | if(eErr != BERR_SUCCESS) |
|---|
| 347 | { |
|---|
| 348 | /* error */ |
|---|
| 349 | goto done; |
|---|
| 350 | } |
|---|
| 351 | |
|---|
| 352 | /* get first entry */ |
|---|
| 353 | eErr = BERR_TRACE(BRDC_DBG_GetListEntry(hList, &eEntry, aulArgs)); |
|---|
| 354 | if(eErr != BERR_SUCCESS) |
|---|
| 355 | { |
|---|
| 356 | /* error parsing list */ |
|---|
| 357 | BDBG_ERR(("error parsing list")); |
|---|
| 358 | goto done; |
|---|
| 359 | } |
|---|
| 360 | |
|---|
| 361 | /* traverse until all entries are displayed */ |
|---|
| 362 | while(eEntry != BRDC_DBG_ListEntry_eEnd) |
|---|
| 363 | { |
|---|
| 364 | /* display entry */ |
|---|
| 365 | switch(eEntry) |
|---|
| 366 | { |
|---|
| 367 | case BRDC_DBG_ListEntry_eCommand: |
|---|
| 368 | /* which command? */ |
|---|
| 369 | switch(aulArgs[0]) |
|---|
| 370 | { |
|---|
| 371 | case BRDC_OP_NOP_OPCODE: |
|---|
| 372 | BDBG_MSG(("++ NOP")); |
|---|
| 373 | break; |
|---|
| 374 | |
|---|
| 375 | case BRDC_OP_IMM_TO_REG_OPCODE: |
|---|
| 376 | BDBG_MSG(("++ IMM TO REG")); |
|---|
| 377 | break; |
|---|
| 378 | |
|---|
| 379 | case BRDC_OP_VAR_TO_REG_OPCODE: |
|---|
| 380 | BDBG_MSG(("++ VAR TO REG: (%d)", |
|---|
| 381 | aulArgs[1])); |
|---|
| 382 | break; |
|---|
| 383 | |
|---|
| 384 | case BRDC_OP_REG_TO_VAR_OPCODE: |
|---|
| 385 | BDBG_MSG(("++ REG TO VAR: (%d)", |
|---|
| 386 | aulArgs[1])); |
|---|
| 387 | break; |
|---|
| 388 | |
|---|
| 389 | case BRDC_OP_IMM_TO_VAR_OPCODE: |
|---|
| 390 | BDBG_MSG(("++ IMM TO VAR: (%d)", |
|---|
| 391 | aulArgs[1])); |
|---|
| 392 | break; |
|---|
| 393 | |
|---|
| 394 | case BRDC_OP_IMMS_TO_REG_OPCODE: |
|---|
| 395 | BDBG_MSG(("++ IMMS TO REG: (%d)", |
|---|
| 396 | aulArgs[1])); |
|---|
| 397 | break; |
|---|
| 398 | |
|---|
| 399 | case BRDC_OP_IMMS_TO_REGS_OPCODE: |
|---|
| 400 | BDBG_MSG(("++ IMMS TO REGS: (%d)", |
|---|
| 401 | aulArgs[1])); |
|---|
| 402 | break; |
|---|
| 403 | |
|---|
| 404 | case BRDC_OP_REG_TO_REG_OPCODE: |
|---|
| 405 | BDBG_MSG(("++ REG TO REG: (%d)", |
|---|
| 406 | aulArgs[1])); |
|---|
| 407 | break; |
|---|
| 408 | |
|---|
| 409 | case BRDC_OP_REGS_TO_REGS_OPCODE: |
|---|
| 410 | BDBG_MSG(("++ REGS TO REGS: (%d)", |
|---|
| 411 | aulArgs[1])); |
|---|
| 412 | break; |
|---|
| 413 | |
|---|
| 414 | case BRDC_OP_REG_TO_REGS_OPCODE: |
|---|
| 415 | BDBG_MSG(("++ REG TO REGS: (%d)", |
|---|
| 416 | aulArgs[1])); |
|---|
| 417 | break; |
|---|
| 418 | |
|---|
| 419 | case BRDC_OP_REGS_TO_REG_OPCODE: |
|---|
| 420 | BDBG_MSG(("++ REGS TO REG: (%d)", |
|---|
| 421 | aulArgs[1])); |
|---|
| 422 | break; |
|---|
| 423 | |
|---|
| 424 | case BRDC_OP_VAR_AND_VAR_TO_VAR_OPCODE: |
|---|
| 425 | BDBG_MSG(("++ VAR AND VAR TO VAR: (%d, %d, %d)", |
|---|
| 426 | aulArgs[1], aulArgs[2], aulArgs[3])); |
|---|
| 427 | break; |
|---|
| 428 | |
|---|
| 429 | case BRDC_OP_VAR_AND_IMM_TO_VAR_OPCODE: |
|---|
| 430 | BDBG_MSG(("++ VAR AND IMM TO VAR: (%d, %d)", |
|---|
| 431 | aulArgs[1], aulArgs[2])); |
|---|
| 432 | break; |
|---|
| 433 | |
|---|
| 434 | case BRDC_OP_VAR_OR_VAR_TO_VAR_OPCODE: |
|---|
| 435 | BDBG_MSG(("++ VAR OR VAR TO VAR: (%d, %d, %d)", |
|---|
| 436 | aulArgs[1], aulArgs[2], aulArgs[3])); |
|---|
| 437 | break; |
|---|
| 438 | |
|---|
| 439 | case BRDC_OP_VAR_OR_IMM_TO_VAR_OPCODE: |
|---|
| 440 | BDBG_MSG(("++ VAR OR IMM TO VAR: (%d, %d)", |
|---|
| 441 | aulArgs[1], aulArgs[2])); |
|---|
| 442 | break; |
|---|
| 443 | |
|---|
| 444 | case BRDC_OP_VAR_XOR_VAR_TO_VAR_OPCODE: |
|---|
| 445 | BDBG_MSG(("++ VAR XOR VAR TO VAR: (%d, %d, %d)", |
|---|
| 446 | aulArgs[1], aulArgs[2], aulArgs[3])); |
|---|
| 447 | break; |
|---|
| 448 | |
|---|
| 449 | case BRDC_OP_VAR_XOR_IMM_TO_VAR_OPCODE: |
|---|
| 450 | BDBG_MSG(("++ VAR XOR IMM TO VAR: (%d, %d)", |
|---|
| 451 | aulArgs[1], aulArgs[2])); |
|---|
| 452 | break; |
|---|
| 453 | |
|---|
| 454 | case BRDC_OP_NOT_VAR_TO_VAR_OPCODE: |
|---|
| 455 | BDBG_MSG(("++ NOT VAR TO VAR: (%d, %d)", |
|---|
| 456 | aulArgs[1], aulArgs[2])); |
|---|
| 457 | break; |
|---|
| 458 | |
|---|
| 459 | case BRDC_OP_VAR_ROR_TO_VAR_OPCODE: |
|---|
| 460 | BDBG_MSG(("++ VAR ROR TO VAR: (%d, %d, %d)", |
|---|
| 461 | aulArgs[1], aulArgs[2], aulArgs[3])); |
|---|
| 462 | break; |
|---|
| 463 | |
|---|
| 464 | case BRDC_OP_VAR_SUM_VAR_TO_VAR_OPCODE: |
|---|
| 465 | BDBG_MSG(("++ VAR SUM VAR TO VAR: (%d, %d, %d)", |
|---|
| 466 | aulArgs[1], aulArgs[2], aulArgs[3])); |
|---|
| 467 | break; |
|---|
| 468 | |
|---|
| 469 | case BRDC_OP_VAR_SUM_IMM_TO_VAR_OPCODE: |
|---|
| 470 | BDBG_MSG(("++ VAR SUM IMM TO VAR: (%d, %d)", |
|---|
| 471 | aulArgs[1], aulArgs[2])); |
|---|
| 472 | break; |
|---|
| 473 | |
|---|
| 474 | case BRDC_OP_COND_SKIP_OPCODE: |
|---|
| 475 | BDBG_MSG(("++ COND SKIP: (%d)", |
|---|
| 476 | aulArgs[1])); |
|---|
| 477 | break; |
|---|
| 478 | |
|---|
| 479 | case BRDC_OP_SKIP_OPCODE: |
|---|
| 480 | BDBG_MSG(("++ SKIP ")); |
|---|
| 481 | break; |
|---|
| 482 | |
|---|
| 483 | case BRDC_OP_EXIT_OPCODE: |
|---|
| 484 | BDBG_MSG(("++ EXIT ")); |
|---|
| 485 | break; |
|---|
| 486 | |
|---|
| 487 | default: |
|---|
| 488 | /* unknown command */ |
|---|
| 489 | BDBG_ERR(("unknown command")); |
|---|
| 490 | goto done; |
|---|
| 491 | } |
|---|
| 492 | break; |
|---|
| 493 | |
|---|
| 494 | case BRDC_DBG_ListEntry_eRegister: |
|---|
| 495 | BDBG_MSG(("REGISTER: %08x", aulArgs[0])); |
|---|
| 496 | break; |
|---|
| 497 | |
|---|
| 498 | case BRDC_DBG_ListEntry_eData: |
|---|
| 499 | BDBG_MSG(("DATA: %08x", aulArgs[0])); |
|---|
| 500 | break; |
|---|
| 501 | |
|---|
| 502 | default: |
|---|
| 503 | /* unknown */ |
|---|
| 504 | eErr = BERR_TRACE(BERR_UNKNOWN); |
|---|
| 505 | break; |
|---|
| 506 | } |
|---|
| 507 | |
|---|
| 508 | /* get next entry */ |
|---|
| 509 | eErr = BERR_TRACE(BRDC_DBG_GetListEntry(hList, &eEntry, aulArgs)); |
|---|
| 510 | if(eErr != BERR_SUCCESS) |
|---|
| 511 | { |
|---|
| 512 | /* error parsing list */ |
|---|
| 513 | BDBG_ERR(("error parsing list")); |
|---|
| 514 | goto done; |
|---|
| 515 | } |
|---|
| 516 | } |
|---|
| 517 | |
|---|
| 518 | done: |
|---|
| 519 | return eErr; |
|---|
| 520 | } |
|---|
| 521 | |
|---|
| 522 | |
|---|
| 523 | /************************************************************** |
|---|
| 524 | * |
|---|
| 525 | * CaptureBuffer |
|---|
| 526 | * |
|---|
| 527 | */ |
|---|
| 528 | |
|---|
| 529 | BERR_Code BRDC_DBG_CreateCaptureBuffer(BRDC_DBG_CaptureBuffer *buffer, int size) |
|---|
| 530 | { |
|---|
| 531 | BKNI_Memset(buffer, 0, sizeof(*buffer)); |
|---|
| 532 | buffer->size = size; |
|---|
| 533 | buffer->mem = BKNI_Malloc(size); |
|---|
| 534 | if (!buffer->mem) |
|---|
| 535 | return BERR_TRACE(BERR_OUT_OF_SYSTEM_MEMORY); |
|---|
| 536 | buffer->enable = true; |
|---|
| 537 | return 0; |
|---|
| 538 | } |
|---|
| 539 | |
|---|
| 540 | void BRDC_DBG_DestroyCaptureBuffer(BRDC_DBG_CaptureBuffer *buffer) |
|---|
| 541 | { |
|---|
| 542 | BKNI_Free(buffer->mem); |
|---|
| 543 | } |
|---|
| 544 | |
|---|
| 545 | static void BRDC_DBG_Write_isr(BRDC_DBG_CaptureBuffer *buffer, const void *mem_, int size) |
|---|
| 546 | { |
|---|
| 547 | const uint8_t *mem = (uint8_t*)mem_; |
|---|
| 548 | int remainder = 0; |
|---|
| 549 | if (size > buffer->size - buffer->writeptr) { |
|---|
| 550 | int temp = buffer->size - buffer->writeptr; |
|---|
| 551 | remainder = size - temp; |
|---|
| 552 | size = temp; |
|---|
| 553 | } |
|---|
| 554 | |
|---|
| 555 | BKNI_Memcpy(&buffer->mem[buffer->writeptr], mem, size); |
|---|
| 556 | buffer->writeptr += size; |
|---|
| 557 | if (buffer->writeptr == buffer->size) |
|---|
| 558 | buffer->writeptr = 0; |
|---|
| 559 | |
|---|
| 560 | if (remainder) |
|---|
| 561 | BRDC_DBG_Write_isr(buffer, &mem[size], remainder); |
|---|
| 562 | } |
|---|
| 563 | |
|---|
| 564 | void BRDC_DBG_WriteCapture_isr(BRDC_DBG_CaptureBuffer *buffer, BRDC_Slot_Handle hSlot, BRDC_List_Handle hList) |
|---|
| 565 | { |
|---|
| 566 | int n = hList->ulEntries * sizeof(uint32_t); |
|---|
| 567 | uint32_t prefix = BRDC_DBG_RUL; |
|---|
| 568 | |
|---|
| 569 | /* assumed to be called in isr context, so no synchronization is needed */ |
|---|
| 570 | |
|---|
| 571 | if (buffer->enable) |
|---|
| 572 | { |
|---|
| 573 | char timestamp[80]; |
|---|
| 574 | |
|---|
| 575 | buffer->num_ruls++; |
|---|
| 576 | buffer->total_bytes += n; |
|---|
| 577 | |
|---|
| 578 | BKNI_Snprintf(timestamp, 80, "Slot%d timestamp = %#x", hSlot->eSlotId, BRDC_Slot_GetTimerSnapshot_isr(hSlot)); |
|---|
| 579 | BRDC_DBG_LogErrorCode_isr(hSlot->hRdc, BRDC_DBG_RUL_TIMESTAMP, timestamp); |
|---|
| 580 | |
|---|
| 581 | BRDC_DBG_Write_isr(buffer, &prefix, sizeof(prefix)); |
|---|
| 582 | BRDC_DBG_Write_isr(buffer, &hList->ulEntries, sizeof(hList->ulEntries)); |
|---|
| 583 | BRDC_DBG_Write_isr(buffer, &hSlot->eSlotId, sizeof(hSlot->eSlotId)); |
|---|
| 584 | BRDC_DBG_Write_isr(buffer, hList->pulRULAddr, n); |
|---|
| 585 | } |
|---|
| 586 | #if 0 |
|---|
| 587 | /* internal metrics */ |
|---|
| 588 | if (buffer->num_ruls % 1000 == 0) { |
|---|
| 589 | BDBG_WRN(("total %d, total_size %d", buffer->num_ruls, buffer->total_bytes)); |
|---|
| 590 | } |
|---|
| 591 | #endif |
|---|
| 592 | } |
|---|
| 593 | |
|---|
| 594 | void BRDC_DBG_ReadCapture_isr(BRDC_Handle rdc, uint8_t *mem, int size, int *read) |
|---|
| 595 | { |
|---|
| 596 | #ifdef BRDC_USE_CAPTURE_BUFFER |
|---|
| 597 | int max; |
|---|
| 598 | BRDC_DBG_CaptureBuffer *buffer = &rdc->captureBuffer; |
|---|
| 599 | |
|---|
| 600 | if (buffer->readptr <= buffer->writeptr) { |
|---|
| 601 | max = buffer->writeptr - buffer->readptr; |
|---|
| 602 | } |
|---|
| 603 | else { |
|---|
| 604 | /* don't read around the wrap, let the app do that */ |
|---|
| 605 | max = buffer->size - buffer->readptr; |
|---|
| 606 | } |
|---|
| 607 | |
|---|
| 608 | if (size > max) |
|---|
| 609 | size = max; |
|---|
| 610 | *read = size; |
|---|
| 611 | |
|---|
| 612 | if (size) { |
|---|
| 613 | BKNI_Memcpy(mem, &buffer->mem[buffer->readptr], size); |
|---|
| 614 | buffer->readptr += size; |
|---|
| 615 | if (buffer->readptr == buffer->size) |
|---|
| 616 | buffer->readptr = 0; |
|---|
| 617 | } |
|---|
| 618 | #else |
|---|
| 619 | BSTD_UNUSED(rdc); |
|---|
| 620 | BSTD_UNUSED(mem); |
|---|
| 621 | BSTD_UNUSED(size); |
|---|
| 622 | *read = 0; |
|---|
| 623 | #endif |
|---|
| 624 | } |
|---|
| 625 | |
|---|
| 626 | #ifdef BRDC_USE_CAPTURE_BUFFER |
|---|
| 627 | static int BKNI_Strlen(const char *str) |
|---|
| 628 | { |
|---|
| 629 | int total = 0; |
|---|
| 630 | while (*str++) total++; |
|---|
| 631 | return total; |
|---|
| 632 | } |
|---|
| 633 | #endif |
|---|
| 634 | |
|---|
| 635 | void BRDC_DBG_LogErrorCode_isr(BRDC_Handle rdc, uint32_t errortype, const char *str) |
|---|
| 636 | { |
|---|
| 637 | #ifdef BRDC_USE_CAPTURE_BUFFER |
|---|
| 638 | uint32_t val[2]; |
|---|
| 639 | val[0] = errortype; |
|---|
| 640 | val[1] = BKNI_Strlen(str); |
|---|
| 641 | BRDC_DBG_Write_isr(&rdc->captureBuffer, val, sizeof(val)); |
|---|
| 642 | BRDC_DBG_Write_isr(&rdc->captureBuffer, str, val[1]); |
|---|
| 643 | #else |
|---|
| 644 | BSTD_UNUSED(rdc); |
|---|
| 645 | BSTD_UNUSED(errortype); |
|---|
| 646 | BSTD_UNUSED(str); |
|---|
| 647 | #endif |
|---|
| 648 | } |
|---|
| 649 | |
|---|
| 650 | |
|---|
| 651 | void BRDC_DBG_EnableCapture_isr(BRDC_Handle rdc, bool enable) |
|---|
| 652 | { |
|---|
| 653 | #ifdef BRDC_USE_CAPTURE_BUFFER |
|---|
| 654 | BRDC_DBG_CaptureBuffer *buffer = &rdc->captureBuffer; |
|---|
| 655 | buffer->enable = enable; |
|---|
| 656 | #else |
|---|
| 657 | BSTD_UNUSED(rdc); |
|---|
| 658 | BSTD_UNUSED(enable); |
|---|
| 659 | #endif |
|---|
| 660 | } |
|---|
| 661 | |
|---|
| 662 | |
|---|
| 663 | /* end of file */ |
|---|