我有 2 个几乎相同的 C++ 程序。编译并运行(使用 Verilator)时,所有 printf 语句都会写入终端。在另一个程序中,没有任何 printf 语句被写入终端。由于重新编译这两个程序几乎是相同的(即相同的 Makefile、输入文件所在目录中完全相同的其他 c++ 和头文件等),因此我很困惑一个程序如何决定完全尊重 printf 语句而另一个程序完全尊重压制他们。
由于这两个程序几乎相同,我想不出任何方法可以让 printf 处理失败的程序。
TIA。
macroMix(printf 有效):
//--------------------------------------------------------------------------------------
// Copyright 2022 Massachusets Institute of Technology
// SPDX short identifier: BSD-3-Clause
//
// File Name: riscv_wrapper.cc
// Program: Common Evaluation Platform (CEP)
// Description: RISC-V template for MacroMix
// Notes:
//
//--------------------------------------------------------------------------------------
`//` `// For bareMetal mode ONLY` `//` `#ifdef BARE_MODE` ` #include "cep_apis.h"` ` #include "portable_io.h"` ` #include "CEP.h"` ` #include "cepRegTest.h"` `#ifdef VERILATOR` ` #include "smp.h"` ` #define smpResume() asm ("#smp_resume(s1, s2)")` `#endif`
// Include the test vectors related to this test
#include "SROT_playback.h"
#include "AES_playback.h"
#include "SHA256_1_playback.h"
#include "IIR_playback.h"
#include "FIR_playback.h"
` #ifdef __cplusplus` ` extern "C" {` ` #endif`
int cep_readNspin(int coreIndex, uint32_t pAddress,uint64_t pData,uint64_t mask, int timeOut) {
uint64_t rdDat;
while (timeOut > 0) {
rdDat = cep_read64(coreIndex, pAddress);
if (((rdDat ^ pData) & mask) == 0) {
break;
}
USEC_SLEEP(100);
timeOut--;
};
return (timeOut <= 0) ? 1 : 0;
}
`#ifdef VERILATOR` ` int main() {` `#else` ` void thread_entry(int cid, int nc) {` `#endif` ` `
int errCnt = 0;
int testId[4] = {0x00, 0x11, 0x22, 0x33};
int coreId = read_csr(mhartid);
int revCheck = 1;
int verbose = 1;
int maxTO = 5000;
uint64_t upper;
uint64_t lower;
`#ifdef VERILATOR` ` if (coreId == 0)` ` smpResume();` `#endif`
// Set the current core's status to running
set_cur_status(CEP_RUNNING_STATUS);
` LOGI("Core %d initialized\n", coreId);`
// There is no Crypto++ support for RISC-V, so pre-recorded vectors will be used
if (coreId == 0) {
upper = SROT_adrBase + SROT_adrSize;
lower = SROT_adrBase;
errCnt += cep_playback(SROT_playback, upper, lower, SROT_totalCommands, verbose);
cep_write64(CEP_VERSION_REG_INDEX, cep_scratch4_reg, CEP_OK2RUN_SIGNATURE);
LOGI("Core %d running test\n", coreId);
upper = AES_adrBase + AES_adrSize;
lower = AES_adrBase;
errCnt += cep_playback(AES_playback, upper, lower, AES_totalCommands, verbose);
}
else if (coreId == 1) {
errCnt += cep_readNspin(CEP_VERSION_REG_INDEX, cep_scratch4_reg, CEP_OK2RUN_SIGNATURE, 0xFFFFFFFF, maxTO);
if (errCnt) goto cleanup;
LOGI("Core %d running test\n", coreId);
upper = SHA256_1_adrBase + SHA256_1_adrSize;
lower = SHA256_1_adrBase;
errCnt += cep_playback(SHA256_1_playback, upper, lower, SHA256_1_totalCommands, verbose);
}
else if (coreId == 2) {
errCnt += cep_readNspin(CEP_VERSION_REG_INDEX, cep_scratch4_reg, CEP_OK2RUN_SIGNATURE, 0xFFFFFFFF, maxTO);
if (errCnt) goto cleanup;
LOGI("Core %d running test\n", coreId);
upper = IIR_adrBase + IIR_adrSize;
lower = IIR_adrBase;
errCnt += cep_playback(IIR_playback, upper, lower, IIR_totalCommands, verbose);
}
else if (coreId == 3) {
errCnt += cep_readNspin(CEP_VERSION_REG_INDEX, cep_scratch4_reg, CEP_OK2RUN_SIGNATURE, 0xFFFFFFFF, maxTO);
if (errCnt) goto cleanup;
LOGI("Core %d running test\n", coreId);
upper = FIR_adrBase + FIR_adrSize;
lower = FIR_adrBase;
errCnt += cep_playback(FIR_playback, upper, lower, FIR_totalCommands, verbose);
}
` // Set the core status` ` cleanup:` ` set_status(errCnt, testId[coreId]);`
#ifdef VERILATOR
if (errCnt)
LOGE("Test Failed\n");
else
LOGI("Test Passed\n");
` return errCnt;` `#else ` ` exit(errCnt);` `#endif` ` }`
#ifdef __cplusplus
}
#endif
#endif // #ifdef BARE_MODE
``
macro4Mix(printf 不起作用):
//--------------------------------------------------------------------------------------
// Copyright 2022 Massachusets Institute of Technology
// SPDX short identifier: BSD-3-Clause
//
// File Name: riscv_wrapper.cc
// Program: Common Evaluation Platform (CEP)
// Description: RISC-V template for MacroMix
// Notes:
//
//--------------------------------------------------------------------------------------
`//` `// For bareMetal mode ONLY` `//` `#ifdef BARE_MODE` ` #include "cep_apis.h"` ` #include "portable_io.h"` ` #include "CEP.h"` ` #include "cepRegTest.h"` `// JAK Added from macroMix. No idea what this does or doesn't do` `//#ifdef VERILATOR` `// #include "smp.h"` `// #define smpResume() asm ("#smp_resume(s1, s2)")` `//#endif`
// Include the test vectors related to this test
#include "SROT_playback.h"
#include "RSA_playback.h"
#include "DES3_playback.h"
#include "DFT_playback.h"
#include "IDFT_playback.h"
` #ifdef __cplusplus` ` extern "C" {` ` #endif`
int cep_readNspin(int coreIndex, uint32_t pAddress,uint64_t pData,uint64_t mask, int timeOut) {
uint64_t rdDat;
while (timeOut > 0) {
rdDat = cep_read64(coreIndex, pAddress);
if (((rdDat ^ pData) & mask) == 0) {
break;
}
USEC_SLEEP(100);
timeOut--;
};
return (timeOut <= 0) ? 1 : 0;
}
`#ifdef VERILATOR` ` int main() {` `#else` ` void thread_entry(int cid, int nc) {` `#endif`
int errCnt = 0;
int testId[4] = {0x00, 0x11, 0x22, 0x33};
int coreId = read_csr(mhartid);
int revCheck = 1;
int verbose = 1;
int maxTO = 5000;
uint64_t upper;
uint64_t lower;
`// JAK Added from macroMix. No idea what this does or doesn't do` `//#ifdef VERILATOR` `// if (coreId == 0)` `// smpResume();` `//#endif`
// Set the current core's status to running
// FIXME: Is this causing the Verilator sanitize problems
set_cur_status(CEP_RUNNING_STATUS);
` LOGI("Core %d initialized\n", coreId);`
// There is no Crypto++ support for RISC-V, so pre-recorded vectors will be used
if (coreId == 0) {
upper = SROT_adrBase + SROT_adrSize;
lower = SROT_adrBase;
errCnt += cep_playback(SROT_playback, upper, lower, SROT_totalCommands, verbose);
cep_write64(CEP_VERSION_REG_INDEX, cep_scratch4_reg, CEP_OK2RUN_SIGNATURE);
upper = RSA_adrBase + RSA_adrSize;
lower = RSA_adrBase;
printf("RSA_totalCommands = %d\n",RSA_totalCommands);
errCnt += cep_playback(RSA_playback, upper, lower, RSA_totalCommands, verbose);
}
else if (coreId == 1) {
errCnt += cep_readNspin(CEP_VERSION_REG_INDEX, cep_scratch4_reg, CEP_OK2RUN_SIGNATURE, 0xFFFFFFFF, maxTO);
if (errCnt) goto cleanup;
upper = DES3_adrBase + DES3_adrSize;
lower = DES3_adrBase;
errCnt += cep_playback(DES3_playback, upper, lower, DES3_totalCommands, verbose);
}
else if (coreId == 2) {
errCnt += cep_readNspin(CEP_VERSION_REG_INDEX, cep_scratch4_reg, CEP_OK2RUN_SIGNATURE, 0xFFFFFFFF, maxTO);
if (errCnt) goto cleanup;
upper = DFT_adrBase + DFT_adrSize;
lower = DFT_adrBase;
errCnt += cep_playback(DFT_playback, upper, lower, DFT_totalCommands, verbose);
}
else if (coreId == 3) {
errCnt += cep_readNspin(CEP_VERSION_REG_INDEX, cep_scratch4_reg, CEP_OK2RUN_SIGNATURE, 0xFFFFFFFF, maxTO);
if (errCnt) goto cleanup;
upper = IDFT_adrBase + IDFT_adrSize;
lower = IDFT_adrBase;
errCnt += cep_playback(IDFT_playback, upper, lower, IDFT_totalCommands, verbose);
}
` // Set the core status` `cleanup:` ` set_status(errCnt, testId[coreId]);`
// Exit with the error count
#ifdef VERILATOR
if (errCnt)
LOGE("Test Failed\n");
else
LOGI("Test Passed\n");
` return errCnt;` `#else `
exit(errCnt);
#endif
}
`#ifdef __cplusplus` ` }` `#endif` ` ` `#endif // #ifdef BARE_MODE`