1 /*
2  * Copyright (c) 2001-2019, Arm Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 
8 
9 #ifndef PKI_DBG_H
10 #define PKI_DBG_H
11 
12 
13 #ifdef __cplusplus
14 extern "C"
15 {
16 #endif
17 
18 #include "cc_pal_types.h"
19 #include "pka_hw_defs.h"
20 #include "cc_pal_abort.h"
21 
22 
23 #ifdef GMP_DEBUG
24 #include "gmp-utils.h"
25 #endif
26 
27 #if defined PKA_DEBUG && defined DEBUG
28 
29 #include <stdio.h>
30 #include "cc_pal_abort.h"
31 #define PKA_PRINTF printf
32 #define ASSERT(x)  if(!(x)) {CC_PalAbort(x);}
33 #define PKA_ASSERT(x, string) if(!(x)) {CC_PalAbort(string);}
34 
35         /* if the value is defined, then debug printing is performed
36         in the parts of code, where the global variable gDoDebugPrint
37         is set to 1 in run time */
38         //#define DBG_PRINT_ON_FAIL_ONLY 1
39         //#define USE_GMP_TEST_DEBUG_BUFFER 1
40         //#define ECC_DEBUG 1
41 
42         /* reference to temp buffers used for debugging of PKA operations */
43         extern uint32_t tempRes[PKA_MAX_REGISTER_SIZE_IN_32BIT_WORDS];
44         extern uint32_t tempRes1[PKA_MAX_REGISTER_SIZE_IN_32BIT_WORDS];
45 
46 void PkiDbgPrintReg(
47                   const char*  label,
48                   const uint32_t reg);
49 
50 void PkiDbgPrintUint32BuffAsNum(
51                   const char     *label,
52                   const uint32_t *pBuf,
53                   uint32_t  sizeWords);
54 
55 void PkiDbgPrintUint8BuffAsNum(const char     *label,
56                      const uint8_t *pBuf,
57                      uint32_t  sizeBytes);
58 void PkiDbgPrintUint8Buff(const char     *label,
59                      const uint8_t *pBuf,
60                      uint32_t  sizeBytes);
61 
62 CCError_t PkiDbgExecOperation(uint32_t       Opcode,
63             uint32_t       lenId,
64             uint32_t       isAImmed,
65             uint32_t       OpA,
66             uint32_t       isBImmed,
67             uint32_t       OpB,
68             uint32_t       ResDiscard,
69             uint32_t       Res,
70             uint32_t       Tag);
71 
72 /* Special debug prints */
73 #define PKA_START_FUNC printf("\n[ %s\n",  __func__)
74 #define PKA_FINISH_FUNC printf("] %s\n",  __func__)
75 #define PPR(reg) printf(#reg); PkiDbgPrintReg("=",reg)
76 #define PPB(buf, size) {printf(#buf); PkiDbgPrintUint32BuffAsNum("=", buf, size);}
77 /* macro for printing one PKA register */
78 #define PKI_DBG_PRINT_REG(label, reg) \
79      do{PKA_PRINTF("%s",label);       \
80         PkiDbgPrintReg(#reg"=",reg); } while (0)
81 /* macro for printing up to 4 PKA regs; if some regs not need,  *
82 *  then set value RES_DISCARD                                   */
83 #define PKI_DBG_PRINT_REGS(label, reg1, reg2, reg3, reg4) \
84      do{PKA_PRINTF("%s",label);                           \
85         if(reg1<32) PkiDbgPrintReg(#reg1"=",reg1);        \
86         if(reg2<32) PkiDbgPrintReg(#reg2"=",reg2);        \
87         if(reg3<32) PkiDbgPrintReg(#reg3"=",reg3);        \
88         if(reg4<32) PkiDbgPrintReg(#reg4"=",reg4);} while(0)
89 
90 /***************************************/
91 #else  // not PKA_DEBUG
92 
93 #define PkiDbgPrintReg(label, reg)
94 #define PkiDbgPrintUint32BuffAsNum(label, pBuf, sizeWords)
95 #define PkiDbgPrintUint8BuffAsNum(label, pBuf, sizeBytes)
96 #define PkiDbgPrintUint8Buff(label, pBuf, sizeBytes)
97 
98 #define PKA_PRINTF(format, ...)  do{}while(0)
99 #define ASSERT(x)  do{}while(0)
100 #define PKA_ASSERT(x, string)
101 
102 #define PKA_START_FUNC
103 #define PKA_FINISH_FUNC
104 #define PPR(reg)
105 #define PPB(buf,size)
106 #define PKI_DBG_PRINT_REGS(label, reg1, reg2, res3, reg4)
107 #define PKI_DBG_PRINT_REG(label, reg)
108 
109 #endif /* end of if/else PKA_DEBUG */
110 
111 
112 #ifdef __cplusplus
113 }
114 #endif
115 
116 #endif
117