MemLogfVA now use only printf_lite which has better handling of

timestamp at the beginning of lines.
This commit is contained in:
jief666 2020-08-26 21:49:49 +03:00
parent 8703ccab7f
commit 5779130ea5
16 changed files with 485 additions and 199 deletions

View File

@ -16,8 +16,11 @@
#endif
typedef UINT32 char32_t;
typedef UINT16 char16_t;
typedef UINT32 uint32_t;
#define PRIu32 d
#endif
#ifdef _MSC_VER
# define __attribute__(x)
#endif
@ -26,10 +29,14 @@
#define DEFINE_SECTIONS 0
#endif
#define PRINTF_LITE_BUF_SIZE 255 // not more than 255
#define PRINTF_LITE_TIMESTAMP_SUPPORT 1
#define PRINTF_LITE_TIMESTAMP_CUSTOM_FUNCTION 1
#define PRINTF_EMIT_CR_SUPPORT 1
#define PRINTF_CFUNCTION_PREFIX
#define PRINTF_CFUNCTION_SUFFIX f
#define PRINTF_EMIT_CR 0

View File

@ -68,7 +68,11 @@ extern "C"
* 2017/08/31 : Save 22 bytes + bufsize of my STM32F103
*/
#ifndef PRINTF_LITE_BUF_SIZE
#define PRINTF_LITE_BUF_SIZE 200
# define PRINTF_LITE_BUF_SIZE 200
#else
# if PRINTF_LITE_BUF_SIZE > 255
# error PRINTF_LITE_BUF_SIZE > 255
# endif
#endif
/*
* Fallback on something close if specifier isn't supported.
@ -110,7 +114,10 @@ extern "C"
#define PRINTF_LITE_SHORTSHORTINT_SUPPORT 1
#endif
#ifndef PRINTF_LITE_TIMESTAMP_SUPPORT
#define PRINTF_LITE_TIMESTAMP_SUPPORT 0 // 240 bytes
#define PRINTF_LITE_TIMESTAMP_SUPPORT 1 // 240 bytes
#endif
#ifndef PRINTF_LITE_TIMESTAMP_CUSTOM_FUNCTION
#define PRINTF_LITE_TIMESTAMP_CUSTOM_FUNCTION 0
#endif
#ifndef PRINTF_LITE_FIELDWIDTH_SUPPORT
#define PRINTF_LITE_FIELDWIDTH_SUPPORT 1 // 107 bytes
@ -130,8 +137,8 @@ extern "C"
#ifndef PRINTF_LITE_USPECIFIER_SUPPORT
#define PRINTF_LITE_USPECIFIER_SUPPORT 1 // 96 bytes. If not supported, u specifier become d
#endif
#ifndef PRINTF_EMIT_CR
#define PRINTF_EMIT_CR 0
#ifndef PRINTF_EMIT_CR_SUPPORT
#define PRINTF_EMIT_CR_SUPPORT 0
#endif
/*===================================================== Private definition ============================================*/
#if PRINTF_UTF8_OUTPUT_SUPPORT == 1
@ -167,19 +174,83 @@ typedef union {
/*===================================================== User function ============================================*/
void vprintf_with_callback(const char* format, va_list valist, transmitBufCallBackType transmitBufCallBack, void* context
#if PRINTF_LITE_TIMESTAMP_SUPPORT == 1
, int* newline, int timestamp
# if PRINTF_EMIT_CR_SUPPORT == 1
void vprintf_with_callback_timestamp_emitcr(const char* format, va_list valist, transmitBufCallBackType transmitBufCallBack, void* context, int* newline, int timestamp, int emitCr); // emitCr is a boolean flag
inline void vprintf_with_callback_timestamp(const char* format, va_list valist, transmitBufCallBackType transmitBufCallBack, void* context, int* newline, int timestamp) {
vprintf_with_callback_timestamp_emitcr(format, valist, transmitBufCallBack, context, newline, timestamp, 0);
}
inline void vprintf_with_callback_emitcr(const char* format, va_list valist, transmitBufCallBackType transmitBufCallBack, void* context, int emitCr) {
vprintf_with_callback_timestamp_emitcr(format, valist, transmitBufCallBack, context, NULL, 0, emitCr);
}
inline void vprintf_with_callback(const char* format, va_list valist, transmitBufCallBackType transmitBufCallBack, void* context) {
vprintf_with_callback_timestamp_emitcr(format, valist, transmitBufCallBack, context, NULL, 0, 0);
}
# else
void vprintf_with_callback_timestamp(const char* format, va_list valist, transmitBufCallBackType transmitBufCallBack, void* context, int* newline, int timestamp);
inline void vprintf_with_callback(const char* format, va_list valist, transmitBufCallBackType transmitBufCallBack, void* context) {
vprintf_with_callback_timestamp(format, valist, transmitBufCallBack, context, NULL, 0);
}
# endif
#else
# if PRINTF_EMIT_CR_SUPPORT == 1
void vprintf_with_callback_emitcr(const char* format, va_list valist, transmitBufCallBackType transmitBufCallBack, void* context, int emitCr);
inline void vprintf_with_callback(const char* format, va_list valist, transmitBufCallBackType transmitBufCallBack, void* context) {
vprintf_with_callback_emitcr(format, valist, transmitBufCallBack, context, 0);
}
# else
void vprintf_with_callback(const char* format, va_list valist, transmitBufCallBackType transmitBufCallBack, void* context);
# endif
#endif
);
#if PRINTF_UNICODE_OUTPUT_SUPPORT == 1
void vwprintf_with_callback(const char* format, va_list valist, transmitWBufCallBackType transmitBufCallBack, void* context
#if PRINTF_LITE_TIMESTAMP_SUPPORT == 1
, int* newline, int timestamp
# if PRINTF_EMIT_CR_SUPPORT == 1
void printf_with_callback_timestamp_emitcr(const char* format, transmitBufCallBackType transmitBufCallBack, void* context, int* newline, int timestamp, int emitCr, ...);
inline void printf_with_callback_timestamp(const char* format, transmitBufCallBackType transmitBufCallBack, void* context, int* newline, int timestamp, ...) {
va_list va;
va_start(va, timestamp);
vprintf_with_callback_timestamp(format, va, transmitBufCallBack, context, newline, timestamp);
va_end(va);
}
inline void printf_with_callback__emitcr(const char* format, transmitBufCallBackType transmitBufCallBack, void* context, int emitCr, ...) {
va_list va;
va_start(va, emitCr);
vprintf_with_callback_emitcr(format, va, transmitBufCallBack, context, emitCr);
va_end(va);
}
inline void printf_with_callback(const char* format, transmitBufCallBackType transmitBufCallBack, void* context, ...) {
va_list va;
va_start(va, context);
vprintf_with_callback(format, va, transmitBufCallBack, context);
va_end(va);
}
# else
void printf_with_callback_timestamp(const char* format, transmitBufCallBackType transmitBufCallBack, void* context, int* newline, int timestamp, ...);
inline void printf_with_callback(const char* format, transmitBufCallBackType transmitBufCallBack, void* context, ...) {
va_list va;
va_start(va, context);
vprintf_with_callback_timestamp(format, va, transmitBufCallBack, context, NULL, 0);
va_end(va);
}
# endif
#else
# if PRINTF_EMIT_CR_SUPPORT == 1
void printf_with_callback_emitcr(const char* format, transmitBufCallBackType transmitBufCallBack, void* context, bool emitCr, ...);
# else
void printf_with_callback(const char* format, transmitBufCallBackType transmitBufCallBack, void* context, ...);
# endif
#endif
);
#if PRINTF_LITE_TIMESTAMP_SUPPORT == 1
void vwprintf_with_callback_timestamp(const char* format, va_list valist, transmitWBufCallBackType transmitBufCallBack, void* context, int* newline, int timestamp);
inline void vwprintf_with_callback(const char* format, va_list valist, transmitWBufCallBackType transmitWBufCallBack, void* context) {
vwprintf_with_callback_timestamp(format, valist, transmitWBufCallBack, context, NULL, 0);
}
#else
void vwprintf_with_callback(const char* format, va_list valist, transmitWBufCallBackType transmitWBufCallBack, void* context);
#endif
#if PRINTF_LITE_SNPRINTF_SUPPORT == 1
@ -201,5 +272,20 @@ void vwprintf_with_callback(const char* format, va_list valist, transmitWBufCall
}
#endif
//#if defined(__cplusplus) && PRINTF_LITE_TIMESTAMP_SUPPORT == 1
// void vprintf_with_callback(const char* format, va_list valist, transmitBufCallBackType transmitBufCallBack, void* context){
// vprintf_with_callback(format, valist, transmitBufCallBack, NULL, 0, context);
// }
//#endif
//#if defined(__cplusplus) && PRINTF_LITE_TIMESTAMP_SUPPORT == 1
// void printf_with_callback(const char* format, va_list valist, transmitBufCallBackType transmitBufCallBack, void* context){
// printf_with_callback(format, valist, transmitBufCallBack, NULL, 0, context);
// }
//#endif
//#if defined(__cplusplus) && PRINTF_UNICODE_OUTPUT_SUPPORT == 1 && PRINTF_LITE_TIMESTAMP_SUPPORT == 1
// void vwprintf_with_callback(const char* format, va_list valist, transmitBufCallBackType transmitBufCallBack, void* context){
// vwprintf_with_callback(format, valist, transmitBufCallBack, NULL, 0, context);
// }
//#endif
#endif // __PRINTF_LITE_H__

View File

@ -209,11 +209,11 @@ MemLogInit (
mMemLog,
NULL
);
MemLog(TRUE, 1, "MemLog inited, TSC freq: %ld\n", mMemLog->TscFreqSec);
MemLogf(TRUE, 1, "MemLog inited, TSC freq: %lld\n", mMemLog->TscFreqSec);
if (InitError[0] != '\0') {
MemLog(TRUE, 1, "CPU was calibrated with RTC\n");
MemLogf(TRUE, 1, "CPU was calibrated with RTC\n");
} else {
MemLog(TRUE, 1, "CPU was calibrated with ACPI PM Timer\n");
MemLogf(TRUE, 1, "CPU was calibrated with ACPI PM Timer\n");
}
return Status;
}
@ -433,6 +433,56 @@ int _fltused=0; // it should be a single underscore since the double one is the
#endif
#endif
static int printfNewline = 1;
static void transmitS8Printf(const char* buf, unsigned int nbchar, void* context)
{
//
// Check if buffer can accept nbchar chars.
// Increase buffer if not.
//
if ( mMemLog->BufferSize - (UINTN)(mMemLog->Cursor - mMemLog->Buffer) <= nbchar )
{
UINTN Offset;
// not enough place for max line - make buffer bigger
// but not too big (if something gets out of controll)
if (mMemLog->BufferSize + MEM_LOG_INITIAL_SIZE > MEM_LOG_MAX_SIZE) {
// Out of resources!
return;
}
Offset = mMemLog->Cursor - mMemLog->Buffer;
mMemLog->Buffer = ReallocatePool(mMemLog->BufferSize, mMemLog->BufferSize + MEM_LOG_INITIAL_SIZE, mMemLog->Buffer);
mMemLog->BufferSize += MEM_LOG_INITIAL_SIZE;
mMemLog->Cursor = mMemLog->Buffer + Offset;
}
CopyMem(mMemLog->Cursor, buf, nbchar);
mMemLog->Cursor += nbchar;
}
const char* printf_lite_get_timestamp()
{
UINT64 dTStartSec;
UINT64 dTStartMs;
UINT64 dTLastSec;
UINT64 dTLastMs;
UINT64 CurrentTsc;
mTimingTxt[0] = '\0';
if (mMemLog != NULL && mMemLog->TscFreqSec != 0) {
CurrentTsc = AsmReadTsc();
dTStartMs = DivU64x64Remainder(MultU64x32(CurrentTsc - mMemLog->TscStart, 1000), mMemLog->TscFreqSec, NULL);
dTStartSec = DivU64x64Remainder(dTStartMs, 1000, &dTStartMs);
dTLastMs = DivU64x64Remainder(MultU64x32(CurrentTsc - mMemLog->TscLast, 1000), mMemLog->TscFreqSec, NULL);
dTLastSec = DivU64x64Remainder(dTLastMs, 1000, &dTLastMs);
snprintf(mTimingTxt, sizeof(mTimingTxt), "%lld:%03lld %lld:%03lld ", dTStartSec, dTStartMs, dTLastSec, dTLastMs);
mMemLog->TscLast = CurrentTsc;
}
return mTimingTxt;
}
/**
Prints a log message to memory buffer.
@ -452,7 +502,6 @@ MemLogfVA (
)
{
EFI_STATUS Status;
CHAR8 *LastMessage;
if (Format == NULL) {
return;
@ -465,63 +514,19 @@ MemLogfVA (
}
}
//
// Check if buffer can accept MEM_LOG_MAX_LINE_SIZE chars.
// Increase buffer if not.
//
if ((UINTN)(mMemLog->Cursor - mMemLog->Buffer) + MEM_LOG_MAX_LINE_SIZE > mMemLog->BufferSize) {
UINTN Offset;
// not enough place for max line - make buffer bigger
// but not too big (if something gets out of controll)
if (mMemLog->BufferSize + MEM_LOG_INITIAL_SIZE > MEM_LOG_MAX_SIZE) {
// Out of resources!
return;
}
Offset = mMemLog->Cursor - mMemLog->Buffer;
mMemLog->Buffer = ReallocatePool(mMemLog->BufferSize, mMemLog->BufferSize + MEM_LOG_INITIAL_SIZE, mMemLog->Buffer);
mMemLog->BufferSize += MEM_LOG_INITIAL_SIZE;
mMemLog->Cursor = mMemLog->Buffer + Offset;
}
//
// Add log to buffer
//
LastMessage = mMemLog->Cursor;
UINTN TimingDataWritten = 0;
if (Timing) {
//
// Write timing only at the beginning of a new line
//
if ((mMemLog->Buffer[0] == '\0') || (mMemLog->Cursor[-1] == '\n')) {
TimingDataWritten = AsciiSPrint(
mMemLog->Cursor,
mMemLog->BufferSize - (mMemLog->Cursor - mMemLog->Buffer),
"%a ",
GetTiming ());
mMemLog->Cursor += TimingDataWritten;
}
UINTN LastMessage = mMemLog->Cursor - mMemLog->Buffer;
}
// DataWritten = AsciiVSPrint(
// mMemLog->Cursor,
// mMemLog->BufferSize - (mMemLog->Cursor - mMemLog->Buffer),
// Format,
// Marker);
/*DataWritten =*/ vsnprintf(
mMemLog->Cursor,
mMemLog->BufferSize - (mMemLog->Cursor - mMemLog->Buffer),
Format,
Marker);
// mMemLog->Cursor += DataWritten;
// vsnprintf doesn't return the number of char printed. TODO will do it soon in printf_lite
UINTN LastMessageLen = AsciiStrLen(mMemLog->Cursor);
mMemLog->Cursor += LastMessageLen;
vprintf_with_callback_timestamp_emitcr(Format, Marker, transmitS8Printf, NULL, &printfNewline, 1, 1);
size_t DataWritten = mMemLog->Cursor - mMemLog->Buffer - LastMessage;
//
// Pass this last message to callback if defined
//
if (mMemLog->Callback != NULL) {
mMemLog->Callback(DebugMode, LastMessage);
mMemLog->Callback(DebugMode, mMemLog->Buffer + LastMessage);
}
//
@ -534,7 +539,7 @@ MemLogfVA (
// Write to standard debug device also
//
// Jief : use SerialPortWrite instead of DebugPrint to avoid 256 chars message length limitation.
SerialPortWrite((UINT8*)LastMessage, TimingDataWritten+LastMessageLen);
SerialPortWrite((UINT8*)(mMemLog->Buffer + LastMessage), DataWritten);
// DebugPrint(DEBUG_INFO, "%a", LastMessage);
}

View File

@ -36,6 +36,8 @@
DebugLib
PciLib
IoLib
BaseDebugPrintErrorLevelLib
BaseSerialPortLib
[BuildOptions]
XCODE:*_*_*_CC_FLAGS = -Os -fno-lto -UUSING_LTO -DMDEPKG_NDEBUG

View File

@ -29,11 +29,10 @@ extern "C"
{
#endif
#if PRINTF_LITE_TIMESTAMP_SUPPORT == 1
static void print_timestamp(PrintfParams* printfParams);
#if PRINTF_LITE_BUF_SIZE == 0
#define PRINTF_LITE_REENTRANT 1 // call printf_with_callback from print_timestamp
#endif
#if PRINTF_UTF8_OUTPUT_SUPPORT == 1 && PRINTF_UNICODE_OUTPUT_SUPPORT == 1
#define print_char_macro(c, printfParams) printfParams->printCharFunction(c, printfParams);
#elif PRINTF_UNICODE_OUTPUT_SUPPORT == 1
@ -97,10 +96,37 @@ typedef struct PrintfParams {
#if PRINTF_LITE_XSPECIFIER_SUPPORT == 1
int uppercase;
#endif
#if PRINTF_EMIT_CR_SUPPORT
int emitCr;
#endif
void* context;
} PrintfParams;
#if PRINTF_LITE_TIMESTAMP_SUPPORT == 1
# if PRINTF_LITE_TIMESTAMP_CUSTOM_FUNCTION == 1
extern char* printf_lite_get_timestamp(void);
# else
static void print_timestamp(PrintfParams* printfParams);
# endif
#endif
#if PRINTF_LITE_TIMESTAMP_SUPPORT == 1
void printf_with_callback(const char* format, transmitBufCallBackType transmitBufCallBack, void* context, ...);
#ifdef ARDUINO
void printf_with_callback(const __FlashStringHelper* format, transmitBufCallBackType transmitBufCallBack
#if PRINTF_LITE_TIMESTAMP_SUPPORT == 1
, int* newline, int timestamp,
#endif // PRINTF_LITE_TIMESTAMP_SUPPORT
...);
#endif // ARDUINO
//#include <inttypes.h> // for PRIu32
#endif // PRINTF_LITE_REENTRANT
#if PRINTF_UTF8_OUTPUT_SUPPORT == 1
// Print a char as is. No analyse is made to check if it's a utf8 partial char
// c is an int for prototype compatibility, but must be < 255
@ -112,10 +138,19 @@ static void print_utf8_char(int c, PrintfParams* printfParams)
if ( *printfParams->newlinePtr )
{
*printfParams->newlinePtr = 0; // to do BEFORE call to printTimeStamp
if ( printfParams->timestamp ) print_timestamp(printfParams);
#if PRINTF_LITE_TIMESTAMP_SUPPORT == 1
#if PRINTF_LITE_TIMESTAMP_CUSTOM_FUNCTION == 1
char* ts = printf_lite_get_timestamp();
if ( printfParams->timestamp && ts ) {
while (*ts ) print_utf8_char(*ts++, printfParams);
}
#else
if ( printfParams->timestamp ) print_timestamp(printfParams);
#endif
#endif
}
#if PRINTF_EMIT_CR == 1
if ( c == '\n' ) print_utf8_char('\r', printfParams);
#if PRINTF_EMIT_CR_SUPPORT == 1
if ( printfParams->emitCr && c == '\n' ) print_utf8_char('\r', printfParams);
#endif
#if PRINTF_LITE_BUF_SIZE > 1
printfParams->buf.buf[(printfParams->bufIdx)++] = (char)c;
@ -124,8 +159,8 @@ static void print_utf8_char(int c, PrintfParams* printfParams)
#endif
if ( c == '\n' ) *printfParams->newlinePtr = 1;
}else{
#if PRINTF_EMIT_CR == 1
if ( c == '\n' ) print_utf8_char('\r', printfParams);
#if PRINTF_EMIT_CR_SUPPORT == 1
if ( printfParams->emitCr && c == '\n' ) print_utf8_char('\r', printfParams);
#endif
#if PRINTF_LITE_BUF_SIZE > 1
printfParams->buf.buf[(printfParams->bufIdx)++] = (char)c;
@ -135,8 +170,8 @@ static void print_utf8_char(int c, PrintfParams* printfParams)
}
#else
{
#if PRINTF_EMIT_CR == 1
if ( c == '\n' ) print_utf8_char('\r', printfParams);
#if PRINTF_EMIT_CR_SUPPORT == 1
if ( printfParams.emit_cr && c == '\n' ) print_utf8_char('\r', printfParams);
#endif
#if PRINTF_LITE_BUF_SIZE > 1
printfParams->buf.buf[(printfParams->bufIdx)++] = (char)c;
@ -165,10 +200,17 @@ static void print_wchar(int c, PrintfParams* printfParams)
if ( *printfParams->newlinePtr )
{
*printfParams->newlinePtr = 0; // to do BEFORE call to printTimeStamp
if ( printfParams->timestamp ) print_timestamp(printfParams);
#if PRINTF_LITE_TIMESTAMP_SUPPORT == 1
#if PRINTF_LITE_TIMESTAMP_CUSTOM_FUNCTION == 1
char* ts = printf_lite_get_timestamp();
if ( printfParams->timestamp ) printf_with_callback("%s", printfParams->transmitBufCallBack.transmitBufCallBack, printfParams->context, ts);
#else
if ( printfParams->timestamp ) print_timestamp(printfParams);
#endif
#endif
}
#if PRINTF_EMIT_CR == 1
if ( c == '\n' ) print_wchar('\r', printfParams);
#if PRINTF_EMIT_CR_SUPPORT == 1
if ( printfParams->emitCr && c == '\n' ) print_wchar('\r', printfParams);
#endif
#if PRINTF_LITE_BUF_SIZE > 1
printfParams->buf.wbuf[(printfParams->bufIdx)++] = (wchar_t)c;
@ -179,8 +221,8 @@ static void print_wchar(int c, PrintfParams* printfParams)
*printfParams->newlinePtr = 1;
}
}else{
#if PRINTF_EMIT_CR == 1
if ( c == '\n' ) print_wchar('\r', printfParams);
#if PRINTF_EMIT_CR_SUPPORT == 1
if ( printfParams->emitCr && c == '\n' ) print_wchar('\r', printfParams);
#endif
#if PRINTF_LITE_BUF_SIZE > 1
printfParams->buf.wbuf[(printfParams->bufIdx)++] = (wchar_t)c;
@ -190,8 +232,8 @@ static void print_wchar(int c, PrintfParams* printfParams)
}
#else
{
#if PRINTF_EMIT_CR == 1
if ( c == '\n' ) print_wchar('\r', printfParams);
#if PRINTF_EMIT_CR_SUPPORT == 1
if ( printfParams.emit_cr && c == '\n' ) print_wchar('\r', printfParams);
#endif
#if PRINTF_LITE_BUF_SIZE > 1
printfParams->buf.wbuf[(printfParams->bufIdx)++] = (wchar_t)c; // cast suposed to be safe, as this function must be called
@ -504,26 +546,27 @@ static void print_ulonglong(UINT_BIGGEST_TYPE v, unsigned int base, PrintfParams
#if defined(EFIAPI)
#error TODO
extern uint32_t getUptimeInMilliseconds();
#elif defined(__APPLE__)
#include <mach/mach_time.h>
#include <time.h>
uint32_t getUptimeInMilliseconds()
{
static mach_timebase_info_data_t s_timebase_info;
kern_return_t result = mach_timebase_info(&s_timebase_info);
(void(result));
(void)result;
// assert(result == 0);
// multiply to get value in the nano seconds
double multiply = (double)s_timebase_info.numer / (double)s_timebase_info.denom;
// divide to get value in the seconds
multiply /= 1000;
return mach_absolute_time() * multiply;
uint64_t time = mach_absolute_time();
time *= s_timebase_info.numer;
time /= s_timebase_info.denom;
time /= 1000;
time /= 1000;
return (uint32_t)(time);
}
#endif
#endif //PRINTF_LITE_TIMESTAMP_SUPPORT
@ -543,29 +586,9 @@ static void print_longlong(INT_BIGGEST_TYPE v, unsigned int base, PrintfParams*
else print_ulonglong((UINT_BIGGEST_TYPE)-v, base, printfParams, 1); // -(INT64_MIN) == INT64_MIN !!! But cast as UINT64, it becomes +v. Good for us.
}
#define PRINTF_LITE_REENTRANT 1
#if PRINTF_LITE_REENTRANT == 1 && PRINTF_LITE_TIMESTAMP_SUPPORT == 1
void printf_with_callback(const char* format, transmitBufCallBackType transmitBufCallBack,
#if PRINTF_LITE_TIMESTAMP_SUPPORT == 1
int* newline, int timestamp,
#endif // PRINTF_LITE_TIMESTAMP_SUPPORT
...);
#ifdef ARDUINO
void printf_with_callback(const __FlashStringHelper* format, transmitBufCallBackType transmitBufCallBack
#if PRINTF_LITE_TIMESTAMP_SUPPORT == 1
, int* newline, int timestamp,
#endif // PRINTF_LITE_TIMESTAMP_SUPPORT
...);
#endif // ARDUINO
#include <inttypes.h> // for PRIu32
#endif // PRINTF_LITE_REENTRANT
#if PRINTF_LITE_TIMESTAMP_SUPPORT == 1
#if PRINTF_LITE_TIMESTAMP_SUPPORT == 1 && PRINTF_LITE_TIMESTAMP_CUSTOM_FUNCTION == 0
static void print_timestamp(PrintfParams* printfParams)
{
#ifdef USE_HAL_DRIVER
@ -591,9 +614,9 @@ static void print_timestamp(PrintfParams* printfParams)
ms %= 1000;
#if PRINTF_LITE_REENTRANT == 1
#ifdef ARDUINO
printf_with_callback(F("%03" PRIu32 ":%02" PRIu32 ":%02" PRIu32 ".%03" PRIu32 " - "), printfParams->transmitBufCallBack, NULL, 0, h, m, s, ms);
printf_with_callback(F("%03" PRIu32 ":%02" PRIu32 ":%02" PRIu32 ".%03" PRIu32 " - "), printfParams->transmitBufCallBack.transmitBufCallBack, NULL, h, m, s, ms);
#else
printf_with_callback("%03" PRIu32 ":%02" PRIu32 ":%02" PRIu32 ".%03" PRIu32 " - ", printfParams->transmitBufCallBack, NULL, 0, h, m, s, ms);
printf_with_callback("%03" PRIu32 ":%02" PRIu32 ":%02" PRIu32 ".%03" PRIu32 " - ", printfParams->transmitBufCallBack.transmitBufCallBack, NULL, h, m, s, ms);
#endif
#else
// non reentrant version take a bit more code size
@ -1095,11 +1118,19 @@ __attribute__((noinline, section(".vprintf_with_callback")))
#elif DEFINE_SECTIONS == 2
__attribute__((noinline, section(".printf_lite")))
#endif
void vprintf_with_callback(const char* format, va_list valist, transmitBufCallBackType transmitBufCallBack, void* context
#if PRINTF_LITE_TIMESTAMP_SUPPORT == 1
, int* newline, int timestamp
# if PRINTF_EMIT_CR_SUPPORT == 1
void vprintf_with_callback_timestamp_emitcr(const char* format, va_list valist, transmitBufCallBackType transmitBufCallBack, void* context, int* newline, int timestamp, int emitCr)
# else
void vprintf_with_callback_timestamp(const char* format, va_list valist, transmitBufCallBackType transmitBufCallBack, void* context, int* newline, int timestamp)
# endif
#else
# if PRINTF_EMIT_CR_SUPPORT == 1
void vprintf_with_callback_emitcr(const char* format, va_list valist, transmitBufCallBackType transmitBufCallBack, void* context, int emitCr)
# else
void vprintf_with_callback(const char* format, va_list valist, transmitBufCallBackType transmitBufCallBack, void* context)
# endif
#endif
)
{
PrintfParams printfParams;
#if PRINTF_LITE_TIMESTAMP_SUPPORT == 1
@ -1115,6 +1146,9 @@ void vprintf_with_callback(const char* format, va_list valist, transmitBufCallBa
printfParams.printCharFunction = print_utf8_char;
#endif
printfParams.transmitBufCallBack.transmitBufCallBack = transmitBufCallBack;
#if PRINTF_EMIT_CR_SUPPORT == 1
printfParams.emitCr = emitCr;
#endif
printfParams.context = context;
while ( 1 ) //Iterate over formatting string
@ -1130,28 +1164,53 @@ void vprintf_with_callback(const char* format, va_list valist, transmitBufCallBa
va_end(valist);
}
#if DEFINE_SECTIONS == 1
__attribute__((noinline, section(".printf_with_callback")))
#elif DEFINE_SECTIONS == 2
__attribute__((noinline, section(".printf_lite")))
#endif
void printf_with_callback(const char* format, transmitBufCallBackType transmitBufCallBack, void* context,
#if PRINTF_LITE_TIMESTAMP_SUPPORT == 1
int* newline, int timestamp,
# if PRINTF_EMIT_CR_SUPPORT == 1
void printf_with_callback_timestamp_emitcr(const char* format, transmitBufCallBackType transmitBufCallBack, void* context, int* newline, int timestamp, int emitCr, ...)
# else
void printf_with_callback_timestamp(const char* format, transmitBufCallBackType transmitBufCallBack, void* context, int* newline, int timestamp, ...)
# endif
#else
# if PRINTF_EMIT_CR_SUPPORT == 1
void printf_with_callback_emitcr(const char* format, transmitBufCallBackType transmitBufCallBack, void* context, int emitCr, ...)
# else
void printf_with_callback(const char* format, transmitBufCallBackType transmitBufCallBack, void* context, ...)
# endif
#endif
...)
{
va_list valist;
#if PRINTF_LITE_TIMESTAMP_SUPPORT == 1
# if PRINTF_EMIT_CR_SUPPORT == 1
va_start(valist, emitCr);
# else
va_start(valist, timestamp);
#endif
#else
# if PRINTF_EMIT_CR_SUPPORT == 1
va_start(valist, emitCr);
# else
va_start(valist, context);
#endif
#endif
vprintf_with_callback(format, valist, transmitBufCallBack, context
#if PRINTF_LITE_TIMESTAMP_SUPPORT == 1
, NULL, 0
# if PRINTF_EMIT_CR_SUPPORT == 1
vprintf_with_callback_timestamp_emitcr(format, valist, transmitBufCallBack, context, newline, timestamp, emitCr);
# else
vprintf_with_callback_timestamp(format, valist, transmitBufCallBack, context, newline, timestamp);
# endif
#else
# if PRINTF_EMIT_CR_SUPPORT == 1
vprintf_with_callback_emitcr(format, valist, transmitBufCallBack, context, emitCr);
# else
vprintf_with_callback(format, valist, transmitBufCallBack, context);
# endif
#endif
);
va_end(valist);
}
@ -1224,55 +1283,95 @@ tryagain:
}
}
void vwprintf_with_callback(const char* format, va_list valist, transmitWBufCallBackType transmitWBufCallBack, void* context
#if PRINTF_LITE_TIMESTAMP_SUPPORT == 1
, int* newline, int timestamp
void vwprintf_with_callback_timestamp(const char* format, va_list valist, transmitWBufCallBackType transmitWBufCallBack, void* context, int* newline, int timestamp)
{
PrintfParams printfParams;
printfParams.newlinePtr = newline;
printfParams.timestamp = timestamp;
#if PRINTF_LITE_BUF_SIZE > 1
printfParams.bufIdx = 0;
#endif
printfParams.inDirective = 0;
printfParams.unicode_output = 1;
printfParams.printCharFunction = print_wchar;
printfParams.transmitBufCallBack.transmitWBufCallBack = transmitWBufCallBack;
printfParams.context = context;
while ( *format ) //Iterate over formatting string
{
char32_t c;
format = get_utf32_from_utf8(format, &c);
if (format == 0) break;
if ( c <= 0x80) {
printf_handle_format_char((char)c, VALIST_PARAM(valist), &printfParams);
continue;
}
#if __WCHAR_MAX__ <= 0xFFFFu
if ( c <= 0xFFFF) {
print_wchar((wchar_t)c, &printfParams);
} else {
c -= halfBase;
print_wchar((wchar_t)((c >> halfShift) + UNI_SUR_HIGH_START), &printfParams);
print_wchar((wchar_t)((c & halfMask) + UNI_SUR_LOW_START), &printfParams);
}
#else
print_wchar((wchar_t)c, &printfParams);
#endif
}
#if PRINTF_LITE_BUF_SIZE > 1
if ( printfParams.bufIdx > 0 ) printfParams.transmitBufCallBack.transmitBufCallBack(printfParams.buf.buf, printfParams.bufIdx, printfParams.context);
#endif
va_end(valist);
}
#else
void vwprintf_with_callback(const char* format, va_list valist, transmitWBufCallBackType transmitWBufCallBack, void* context)
{
PrintfParams printfParams;
#if PRINTF_LITE_BUF_SIZE > 1
printfParams.bufIdx = 0;
#endif
printfParams.inDirective = 0;
printfParams.unicode_output = 1;
printfParams.printCharFunction = print_wchar;
printfParams.transmitBufCallBack.transmitWBufCallBack = transmitWBufCallBack;
printfParams.emitCr = 0;
printfParams.context = context;
while ( *format ) //Iterate over formatting string
{
char32_t c;
format = get_utf32_from_utf8(format, &c);
if (format == 0) break;
if ( c <= 0x80) {
printf_handle_format_char((char)c, VALIST_PARAM(valist), &printfParams);
continue;
}
#if __WCHAR_MAX__ <= 0xFFFFu
if ( c <= 0xFFFF) {
print_wchar((wchar_t)c, &printfParams);
} else {
c -= halfBase;
print_wchar((wchar_t)((c >> halfShift) + UNI_SUR_HIGH_START), &printfParams);
print_wchar((wchar_t)((c & halfMask) + UNI_SUR_LOW_START), &printfParams);
}
#else
print_wchar((wchar_t)c, &printfParams);
#endif
}
#if PRINTF_LITE_BUF_SIZE > 1
if ( printfParams.bufIdx > 0 ) printfParams.transmitBufCallBack.transmitBufCallBack(printfParams.buf.buf, printfParams.bufIdx, printfParams.context);
#endif
va_end(valist);
}
#endif
)
{
PrintfParams printfParams;
#if PRINTF_LITE_TIMESTAMP_SUPPORT == 1
printfParams.newlinePtr = newline;
printfParams.timestamp = timestamp;
#endif
#if PRINTF_LITE_BUF_SIZE > 1
printfParams.bufIdx = 0;
#endif
printfParams.inDirective = 0;
printfParams.unicode_output = 1;
printfParams.printCharFunction = print_wchar;
printfParams.transmitBufCallBack.transmitWBufCallBack = transmitWBufCallBack;
printfParams.context = context;
while ( *format ) //Iterate over formatting string
{
char32_t c;
format = get_utf32_from_utf8(format, &c);
if (format == 0) break;
if ( c <= 0x80) {
printf_handle_format_char((char)c, VALIST_PARAM(valist), &printfParams);
continue;
}
#if __WCHAR_MAX__ <= 0xFFFFu
if ( c <= 0xFFFF) {
print_wchar((wchar_t)c, &printfParams);
} else {
c -= halfBase;
print_wchar((wchar_t)((c >> halfShift) + UNI_SUR_HIGH_START), &printfParams);
print_wchar((wchar_t)((c & halfMask) + UNI_SUR_LOW_START), &printfParams);
}
#else
print_wchar((wchar_t)c, &printfParams);
#endif
}
#if PRINTF_LITE_BUF_SIZE > 1
if ( printfParams.bufIdx > 0 ) printfParams.transmitBufCallBack.transmitBufCallBack(printfParams.buf.buf, printfParams.bufIdx, printfParams.context);
#endif
va_end(valist);
}
void wprintf_with_callback(const char* format, transmitWBufCallBackType transmitWBufCallBack, void* context,
#if PRINTF_LITE_TIMESTAMP_SUPPORT == 1
int* newline, int timestamp,
@ -1285,11 +1384,11 @@ void wprintf_with_callback(const char* format, transmitWBufCallBackType transmit
#else
va_start(valist, context);
#endif
vwprintf_with_callback(format, valist, transmitWBufCallBack, context
#if PRINTF_LITE_TIMESTAMP_SUPPORT == 1
, NULL, 0
vwprintf_with_callback_timestamp(format, valist, transmitWBufCallBack, context, newline, timestamp);
#else
vwprintf_with_callback(format, valist, transmitWBufCallBack, context);
#endif
);
va_end(valist);
}
#endif
@ -1328,11 +1427,11 @@ int PRINTF_FUNCTION_NAME(PRINTF_CFUNCTION_PREFIX, vsnprint, PRINTF_CFUNCTION_SUF
SPrintfContext.printf_callback_vsnprintf_buffer = buf;
SPrintfContext.printf_callback_vsnprintf_buffer_len = len > 0 ? len-1 : 0;
SPrintfContext.printf_callback_vsnprintf_count = 0;
vprintf_with_callback(format, valist, transmitSPrintf, (void*)&SPrintfContext
#if PRINTF_LITE_TIMESTAMP_SUPPORT == 1
, NULL, 0
vprintf_with_callback_timestamp(format, valist, transmitSPrintf, (void*)&SPrintfContext, NULL, 0);
#else
vprintf_with_callback(format, valist, transmitSPrintf, (void*)&SPrintfContext);
#endif
);
if ( len > 0 ) *(char*)(SPrintfContext.printf_callback_vsnprintf_buffer) = 0;
return SPrintfContext.printf_callback_vsnprintf_count;
}
@ -1374,11 +1473,11 @@ int PRINTF_FUNCTION_NAME(PRINTF_CFUNCTION_PREFIX, vsnwprint, PRINTF_CFUNCTION_SU
SWPrintfContext.printf_callback_vsnprintf_buffer = buf;
SWPrintfContext.printf_callback_vsnprintf_buffer_len = len-1;
SWPrintfContext.printf_callback_vsnprintf_count = 0;
vwprintf_with_callback(format, valist, transmitSWPrintf, (void*)(&SWPrintfContext)
#if PRINTF_LITE_TIMESTAMP_SUPPORT == 1
, NULL, 0
vwprintf_with_callback_timestamp(format, valist, transmitSWPrintf, (void*)(&SWPrintfContext), NULL, 0);
#else
vwprintf_with_callback(format, valist, transmitSWPrintf, (void*)(&SWPrintfContext));
#endif
);
*(wchar_t*)(SWPrintfContext.printf_callback_vsnprintf_buffer) = 0;
#if VSNWPRINTF_RETURN_MINUS1_ON_OVERFLOW == 1
if ( (size_t)(SWPrintfContext.printf_callback_vsnprintf_count) >= len ) return -1;

View File

@ -26,9 +26,6 @@
9A28CD0C241B8DD400F3D247 /* strcmp_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A28CD06241B8DD400F3D247 /* strcmp_test.cpp */; };
9A28CD0D241B8DD400F3D247 /* strcmp_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A28CD06241B8DD400F3D247 /* strcmp_test.cpp */; };
9A28CD0E241B8DD400F3D247 /* strcmp_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A28CD06241B8DD400F3D247 /* strcmp_test.cpp */; };
9A28CD10241B9EF800F3D247 /* strcmp.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A28CD0F241B9EF800F3D247 /* strcmp.cpp */; };
9A28CD11241B9EF800F3D247 /* strcmp.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A28CD0F241B9EF800F3D247 /* strcmp.cpp */; };
9A28CD12241B9EF800F3D247 /* strcmp.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A28CD0F241B9EF800F3D247 /* strcmp.cpp */; };
9A28CD16241BACBB00F3D247 /* strlen_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A28CD15241BACBB00F3D247 /* strlen_test.cpp */; };
9A28CD17241BACBB00F3D247 /* strlen_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A28CD15241BACBB00F3D247 /* strlen_test.cpp */; };
9A28CD18241BACBB00F3D247 /* strlen_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A28CD15241BACBB00F3D247 /* strlen_test.cpp */; };
@ -57,7 +54,6 @@
9A2A7C7924576CCE00422263 /* global_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A0B08642403144C00E2B470 /* global_test.cpp */; };
9A2A7C7A24576CCE00422263 /* printf_lite.c in Sources */ = {isa = PBXBuildFile; fileRef = 9ACAB116242623EE00BDB3CF /* printf_lite.c */; };
9A2A7C7B24576CCE00422263 /* XStringArray_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A0B084F2402FE9B00E2B470 /* XStringArray_test.cpp */; };
9A2A7C7C24576CCE00422263 /* strcmp.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A28CD0F241B9EF800F3D247 /* strcmp.cpp */; };
9A2A7C7D24576CCE00422263 /* XStringArray.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A4185BE2439F73A00BEAFB8 /* XStringArray.cpp */; };
9A2A7C7E24576CCE00422263 /* XArray_tests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A0B08532402FE9B00E2B470 /* XArray_tests.cpp */; };
9A2A7C7F24576CCE00422263 /* printf_lite-test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AA045892425F94D000D6970 /* printf_lite-test.cpp */; };
@ -219,7 +215,6 @@
9A28CD06241B8DD400F3D247 /* strcmp_test.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = strcmp_test.cpp; sourceTree = "<group>"; };
9A28CD07241B8DD400F3D247 /* strcmp_test.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = strcmp_test.h; sourceTree = "<group>"; };
9A28CD08241B8DD400F3D247 /* strncmp_test.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = strncmp_test.h; sourceTree = "<group>"; };
9A28CD0F241B9EF800F3D247 /* strcmp.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = strcmp.cpp; sourceTree = "<group>"; };
9A28CD13241B9FEE00F3D247 /* posix.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = posix.h; sourceTree = "<group>"; };
9A28CD14241BACBB00F3D247 /* strlen_test.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = strlen_test.h; sourceTree = "<group>"; };
9A28CD15241BACBB00F3D247 /* strlen_test.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = strlen_test.cpp; sourceTree = "<group>"; };
@ -418,7 +413,6 @@
9AC790112452C45A0004FBE9 /* abort.h */,
9A28CD1D241BB61B00F3D247 /* abort.cpp */,
9A28CD1E241BB61B00F3D247 /* strlen.cpp */,
9A28CD0F241B9EF800F3D247 /* strcmp.cpp */,
);
path = Posix;
sourceTree = "<group>";
@ -674,7 +668,6 @@
9ACAB1192426255C00BDB3CF /* printf_lite.c in Sources */,
9A36E4F924F3B537007A1107 /* xml.cpp in Sources */,
9A0B087D2403B08400E2B470 /* XStringArray_test.cpp in Sources */,
9A28CD11241B9EF800F3D247 /* strcmp.cpp in Sources */,
9A36E51124F3B537007A1107 /* TagArray.cpp in Sources */,
9A36E4F124F3B537007A1107 /* TagString8.cpp in Sources */,
9A36E50924F3B537007A1107 /* TagDate.cpp in Sources */,
@ -719,7 +712,6 @@
9A2A7C7A24576CCE00422263 /* printf_lite.c in Sources */,
9A36E4FB24F3B537007A1107 /* xml.cpp in Sources */,
9A2A7C7B24576CCE00422263 /* XStringArray_test.cpp in Sources */,
9A2A7C7C24576CCE00422263 /* strcmp.cpp in Sources */,
9A36E51324F3B537007A1107 /* TagArray.cpp in Sources */,
9A36E4F324F3B537007A1107 /* TagString8.cpp in Sources */,
9A36E50B24F3B537007A1107 /* TagDate.cpp in Sources */,
@ -764,7 +756,6 @@
9ACAB11A2426255C00BDB3CF /* printf_lite.c in Sources */,
9A36E4FA24F3B537007A1107 /* xml.cpp in Sources */,
9A57C2252418B9A00029A39F /* XStringArray_test.cpp in Sources */,
9A28CD12241B9EF800F3D247 /* strcmp.cpp in Sources */,
9A36E51224F3B537007A1107 /* TagArray.cpp in Sources */,
9A36E4F224F3B537007A1107 /* TagString8.cpp in Sources */,
9A36E50A24F3B537007A1107 /* TagDate.cpp in Sources */,
@ -813,7 +804,6 @@
9A36E51024F3B537007A1107 /* TagArray.cpp in Sources */,
9A36E4F024F3B537007A1107 /* TagString8.cpp in Sources */,
9A36E50824F3B537007A1107 /* TagDate.cpp in Sources */,
9A28CD10241B9EF800F3D247 /* strcmp.cpp in Sources */,
9A36E51F24F3B82A007A1107 /* b64cdecode.cpp in Sources */,
9A0B085B2402FF8700E2B470 /* XArray_tests.cpp in Sources */,
9A670D1C24E535AB00B5D780 /* XBuffer_tests.cpp in Sources */,

View File

@ -10,6 +10,7 @@
#include <stdarg.h>
#include <stddef.h> // for size_t
#include <stdint.h>
#include <inttypes.h>
#ifndef __cplusplus
#ifdef _MSC_VER
@ -30,8 +31,8 @@
#define PRINTF_CFUNCTION_PREFIX
#define PRINTF_CFUNCTION_SUFFIX fl
#define PRINTF_EMIT_CR 0
#define PRINTF_LITE_TIMESTAMP_SUPPORT 1
#define PRINTF_EMIT_CR_SUPPORT 1
#endif // __PRINTF_LITE_CONF_H__

View File

@ -37,9 +37,6 @@
void abort(void);
//// edkII Strcmp seems quite inefficient, even vs a naive implementation
int strcmp(const char* s1, const char* s2);
int strncmp(const char* s1, const char* s2, size_t n);
size_t strlen(const char *str);

View File

@ -2,6 +2,24 @@
#include <posix.h>
// Function to implement strncat() function in C
char* strncat(char* destination, const char* source, size_t num)
{
// make ptr point to the end of destination string
char* ptr = destination + strlen(destination);
// Appends characters of source to the destination string
while (*source != '\0' && num--)
*ptr++ = *source++;
// null terminate destination string
*ptr = '\0';
// destination string is returned by standard strncat()
return destination;
}
#ifndef strcmp
/*
* Taken from glibc. Seems not optimized at all...

View File

@ -33,6 +33,9 @@ inline char* strcat(char* s1, const char* s2)
return s1;
}
char* strncat(char* s1, const char* s2, size_t n);
inline char* strcpy(char* dst, const char* src)
{
AsciiStrCpyS(dst,AsciiStrLen(src)+1,src);
@ -45,6 +48,12 @@ inline char* strncpy(char * dst, const char * src, size_t len)
return dst;
}
//// edkII Strcmp seems quite inefficient, even vs a naive implementation
int strcmp(const char* s1, const char* s2);
int strncmp(const char* s1, const char* s2, size_t n);
int strncmp(const char *s1, const char *s2, size_t n);
extern void* memset(void *b, int c, size_t len); // memset is defined in cpp_util/memory.cpp because it is required by c++
//inline void* memset(void *b, int c, size_t len)
//{

View File

@ -1116,9 +1116,9 @@ VOID LOADER_ENTRY::AnyKextPatch(UINT8 *Driver, UINT32 DriverSize, CHAR8 *InfoPli
const KEXT_PATCH& kextpatch = KernelAndKextPatches.KextPatches[N];
UINTN SearchLen = kextpatch.SearchLen;
DBG_RT("\nAnyKextPatch %zu: driverAddr = %llx, driverSize = %x\nAnyKext = %s\n",
DBG_RT("\nAnyKextPatch %zu: driverAddr = %llx, driverSize = %x\n Label = %s\n",
N, (UINTN)Driver, DriverSize, kextpatch.Label.c_str());
DBG("\nAnyKextPatch %zu: driverAddr = %llx, driverSize = %x\nLabel = %s\n",
DBG("\nAnyKextPatch %zu: driverAddr = %llx, driverSize = %x\n Label = %s\n",
N, (UINTN)Driver, DriverSize, kextpatch.Label.c_str());
if (!kextpatch.MenuItem.BValue) {

View File

@ -39,9 +39,9 @@ bool all_tests()
// all_ok = false;
// }
#if defined(JIEF_DEBUG)
ret = plist_tests();
ret = printf_lite_tests();
if ( ret != 0 ) {
printf("plist_tests() failed at test %d\n", ret);
printf("printf_lite_tests() failed at test %d\n", ret);
all_ok = false;
}
// ret = XBuffer_tests();

View File

@ -140,6 +140,7 @@ static int testWPrintf(const char* label, const wchar_t* expectResult, int expe
testWPrintf(label,L##expectResult,expectedRet,format,c,d,e,f,g); \
}
int test_printf_with_callback_timestamp();
int printf_lite_tests(void)
{
@ -524,6 +525,71 @@ int printf_lite_tests(void)
Test1arg(F("-1.789010"), F("%015.2f"), -1.78901f);
#endif
// TODO : check when CLOVER_BUILD because of special timing function
// nbTestFailed += test_printf_with_callback_timestamp();
return nbTestFailed;
}
static int printfNewline = 1;
static char test_printf_with_callback_timestamp_buf[1024];
static void test_printf_transmitS8Printf(const char* buf, unsigned int nbchar, void* context)
{
(void)context;
strncat(test_printf_with_callback_timestamp_buf, buf, nbchar);
}
int test_printf_with_callback_timestamp()
{
test_printf_with_callback_timestamp_buf[0] = 0;
printf_with_callback_timestamp("Hello %s\n", test_printf_transmitS8Printf, nullptr, &printfNewline, 1, "world");
size_t i;
for ( i=0 ; i<sizeof(test_printf_with_callback_timestamp_buf) ; i++ ) {
if ( test_printf_with_callback_timestamp_buf[i] == ':' ) break;
if ( test_printf_with_callback_timestamp_buf[i] < '0' or test_printf_with_callback_timestamp_buf[i] > '9' ) return 1;
}
if ( i < 1 ) return 1;
if ( test_printf_with_callback_timestamp_buf[i] != ':' ) return 1; else i++;
if ( test_printf_with_callback_timestamp_buf[i] < '0' or test_printf_with_callback_timestamp_buf[i] > '9' ) return 1; else i++;
if ( test_printf_with_callback_timestamp_buf[i] < '0' or test_printf_with_callback_timestamp_buf[i] > '9' ) return 1; else i++;
if ( test_printf_with_callback_timestamp_buf[i] != ':' ) return 1; else i++;
if ( test_printf_with_callback_timestamp_buf[i] < '0' or test_printf_with_callback_timestamp_buf[i] > '9' ) return 1; else i++;
if ( test_printf_with_callback_timestamp_buf[i] < '0' or test_printf_with_callback_timestamp_buf[i] > '9' ) return 1; else i++;
if ( test_printf_with_callback_timestamp_buf[i] != '.' ) return 1; else i++;
if ( test_printf_with_callback_timestamp_buf[i] < '0' or test_printf_with_callback_timestamp_buf[i] > '9' ) return 1; else i++;
if ( test_printf_with_callback_timestamp_buf[i] < '0' or test_printf_with_callback_timestamp_buf[i] > '9' ) return 1; else i++;
if ( test_printf_with_callback_timestamp_buf[i] < '0' or test_printf_with_callback_timestamp_buf[i] > '9' ) return 1; else i++;
if ( test_printf_with_callback_timestamp_buf[i] != ' ' ) return 1; else i++;
if ( test_printf_with_callback_timestamp_buf[i] != '-' ) return 1; else i++;
if ( test_printf_with_callback_timestamp_buf[i] != ' ' ) return 1; else i++;
if ( strcmp(&test_printf_with_callback_timestamp_buf[i], "Hello world\n") != 0) {
nbTestFailed += 1;
}
test_printf_with_callback_timestamp_buf[0] = 0;
printf_with_callback_timestamp_emitcr("Hello %s\n", test_printf_transmitS8Printf, nullptr, &printfNewline, 1, 1, "world");
for ( i=0 ; i<sizeof(test_printf_with_callback_timestamp_buf) ; i++ ) {
if ( test_printf_with_callback_timestamp_buf[i] == ':' ) break;
if ( test_printf_with_callback_timestamp_buf[i] < '0' or test_printf_with_callback_timestamp_buf[i] > '9' ) return 1;
}
if ( i < 1 ) return 1;
if ( test_printf_with_callback_timestamp_buf[i] != ':' ) return 1; else i++;
if ( test_printf_with_callback_timestamp_buf[i] < '0' or test_printf_with_callback_timestamp_buf[i] > '9' ) return 1; else i++;
if ( test_printf_with_callback_timestamp_buf[i] < '0' or test_printf_with_callback_timestamp_buf[i] > '9' ) return 1; else i++;
if ( test_printf_with_callback_timestamp_buf[i] != ':' ) return 1; else i++;
if ( test_printf_with_callback_timestamp_buf[i] < '0' or test_printf_with_callback_timestamp_buf[i] > '9' ) return 1; else i++;
if ( test_printf_with_callback_timestamp_buf[i] < '0' or test_printf_with_callback_timestamp_buf[i] > '9' ) return 1; else i++;
if ( test_printf_with_callback_timestamp_buf[i] != '.' ) return 1; else i++;
if ( test_printf_with_callback_timestamp_buf[i] < '0' or test_printf_with_callback_timestamp_buf[i] > '9' ) return 1; else i++;
if ( test_printf_with_callback_timestamp_buf[i] < '0' or test_printf_with_callback_timestamp_buf[i] > '9' ) return 1; else i++;
if ( test_printf_with_callback_timestamp_buf[i] < '0' or test_printf_with_callback_timestamp_buf[i] > '9' ) return 1; else i++;
if ( test_printf_with_callback_timestamp_buf[i] != ' ' ) return 1; else i++;
if ( test_printf_with_callback_timestamp_buf[i] != '-' ) return 1; else i++;
if ( test_printf_with_callback_timestamp_buf[i] != ' ' ) return 1; else i++;
if ( strcmp(&test_printf_with_callback_timestamp_buf[i], "Hello world\r\n") != 0) {
nbTestFailed += 1;
}
return 0;
}

View File

@ -53,6 +53,7 @@ extern "C" {
#include <Library/IoLib.h>
#include <Library/DxeServicesTableLib.h>
#include <Library/HobLib.h>
#include <Library/SerialPortLib.h>
#include <Framework/FrameworkInternalFormRepresentation.h>

View File

@ -121,7 +121,7 @@
Platform/Posix/stdlib.h
Platform/Posix/stdio.h
Platform/Posix/stdio.cpp
Platform/Posix/strcmp.cpp
Platform/Posix/string.cpp
Platform/Posix/string.h
Platform/Posix/strlen.cpp
Platform/Posix/wchar.h

View File

@ -1832,6 +1832,11 @@ RefitMain (IN EFI_HANDLE ImageHandle,
{
EFI_LOADED_IMAGE* LoadedImage;
Status = gBS->HandleProtocol(gImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **) &LoadedImage);
// if ( !EFI_ERROR(Status) ) {
// XString8 msg = S8Printf("Clover : Image base = 0x%llX\n", (uintptr_t)LoadedImage->ImageBase); // do not change, it's used by grep to feed the debugger
// SerialPortWrite((UINT8*)msg.c_str(), msg.length());
// }
if ( !EFI_ERROR(Status) ) DBG("Clover : Image base = 0x%llX\n", (uintptr_t)LoadedImage->ImageBase); // do not change, it's used by grep to feed the debugger
#ifdef JIEF_DEBUG