Changeset 58809 in vbox for trunk/src/VBox/ValidationKit
- Timestamp:
- Nov 21, 2015 7:28:49 PM (9 years ago)
- Location:
- trunk/src/VBox/ValidationKit/bootsectors/bs3kit
- Files:
-
- 14 added
- 5 edited
- 1 copied
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/bootsectors/bs3kit/Makefile.kmk
r58808 r58809 446 446 bs3-cmn-Panic.asm \ 447 447 bs3-cmn-PrintChr.asm \ 448 bs3-cmn-Print F.c \448 bs3-cmn-Printf.c \ 449 449 bs3-cmn-PrintU32.asm \ 450 450 bs3-cmn-PrintX32.asm \ … … 452 452 bs3-cmn-PrintStrColonSpaces.asm \ 453 453 bs3-cmn-PrintStrSpacesColonSpace.c \ 454 bs3-cmn-StrFormatV.c \ 455 bs3-cmn-StrPrintf.c \ 454 456 bs3-cmn-StrLen.c \ 455 457 bs3-cmn-StrNLen.c \ … … 488 490 bs3-system-data.asm \ 489 491 bs3-rm-InitMemory.c \ 490 bs3-cmn-hexdigits.c 492 bs3-cmn-hexdigits.c \ 493 bs3-wc16-U8DR.asm \ 494 bs3-wc16-U8DQ.asm \ 495 bs3-wc16-I8DR.asm \ 496 bs3-wc16-I8DQ.asm \ 497 bs3-wc16-I8RS.asm \ 498 bs3-wc16-U8RS.asm \ 499 bs3-wc16-U8LS.asm \ 500 bs3-wc16-U4D.asm \ 501 bs3-wc16-I4D.asm \ 491 502 492 503 # The 32-bit BS3Kit library. … … 495 506 bs3kit-common-32_DEFS = TMPL_PE32 BS3_CMN_ONLY 496 507 bs3kit-common-32_ASDEFS = RT_ASMDEFS_INC_FIRST_FILE 497 bs3kit-common-32_SOURCES = $(VBOX_BS3KIT_COMMON_SOURCES) 508 bs3kit-common-32_SOURCES = $(VBOX_BS3KIT_COMMON_SOURCES) \ 509 bs3-wc32-U8D.asm \ 510 bs3-wc32-I8D.asm \ 511 bs3-wc32-I8RS.asm \ 512 bs3-wc32-U8RS.asm \ 513 bs3-wc32-U8LS.asm \ 498 514 499 515 # The 64-bit BS3Kit library. -
trunk/src/VBox/ValidationKit/bootsectors/bs3kit/VBoxBs3ObjConverter.cpp
r58808 r58809 516 516 "\x05" "__I4D", 517 517 "\x05" "__I4M", 518 "\x05" "__I8D", 518 519 "\x06" "__I8DQ", 519 520 "\x07" "__I8DQE", … … 530 531 "\x05" "__U4D", 531 532 "\x05" "__U4M", 533 "\x05" "__U8D", 532 534 "\x06" "__U8DQ", 533 535 "\x07" "__U8DQE", … … 617 619 && memcmp(&g_apszExtDefRenames[i][1], pchName, cch) == 0) 618 620 { 619 pchName[0] = fProbably32bit ? ' 3' : '1';620 pchName[1] = fProbably32bit ? ' 2' : '6';621 pchName[0] = fProbably32bit ? '?' : '_'; 622 pchName[1] = fProbably32bit ? '?' : '?'; 621 623 break; 622 624 } -
trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-Printf.c
r58806 r58809 1 1 /* $Id$ */ 2 2 /** @file 3 * BS3Kit - Bs3Print F3 * BS3Kit - Bs3Printf, Bs3PrintfV 4 4 */ 5 5 … … 29 29 30 30 31 #define STR_F_CAPITAL 0x0001 32 #define STR_F_LEFT 0x0002 33 #define STR_F_ZEROPAD 0x0004 34 #define STR_F_SPECIAL 0x0008 35 #define STR_F_VALSIGNED 0x0010 36 #define STR_F_PLUS 0x0020 37 #define STR_F_BLANK 0x0040 38 #define STR_F_WIDTH 0x0080 39 #define STR_F_PRECISION 0x0100 40 #define STR_F_THOUSAND_SEP 0x0200 41 42 43 static size_t bs3PrintFormatString(const char *psz, size_t cchMax, uint16_t fFlags, int cchWidth, int cchPrecision) 31 BS3_DECL(size_t) bs3PrintFmtOutput(char ch, void *pvUser) 44 32 { 45 size_t cchRet; 46 if (cchMax == ~(size_t)0) 47 cchMax = Bs3StrNLen(psz, cchMax); 48 cchRet = cchMax; 49 50 /** @todo this is kind of crude, full fleged formatting can wait. */ 51 while (cchMax-- > 0) 52 Bs3PrintChr(*psz++); 53 54 return cchRet; 33 if (ch) 34 { 35 if (ch != '\n') 36 Bs3PrintChr('\r'); 37 Bs3PrintChr(ch); 38 return 1; 39 } 40 NOREF(pvUser); 41 return 0; 55 42 } 56 43 57 44 58 static size_t bs3PrintFormatU64(char szTmp[64], uint64_t uValue, unsigned uBase, uint16_t fFlags, int cchWidth, int cchPrecision)45 BS3_DECL(size_t) Bs3PrintfV(const char BS3_FAR *pszFormat, va_list va) 59 46 { 60 #if 0 61 const char *pachDigits = !(fFlags & STR_F_CAPITAL) ? BS3_DATA_NM(g_achBs3HexDigits) : BS3_DATA_NM(g_achBs3HexDigitsUpper); 62 char *psz = &szTmp[64]; 63 64 *--psz = '\0'; 65 if (uBase == 10) 66 { 67 do 68 { 69 *--psz = pachDigits[uValue % 10]; 70 uValue /= 10; 71 } while (uValue > 0); 72 } 73 else 74 { 75 unsigned const cShift = uBase == 8 ? 2 : 3; 76 unsigned const fMask = uBase == 8 ? 7 : 15; 77 do 78 { 79 *--psz = pachDigits[uValue & fMask]; 80 uValue >>= cShift; 81 } while (uValue > 0); 82 } 83 return bs3PrintFormatString(psz, &szTmp[63] - psz, 0, 0, 0); 84 #else 85 return 0; 86 #endif 87 } 88 89 #if ARCH_BITS == 64 90 # define bs3PrintFormatU32 bs3PrintFormatU64 91 # define bs3PrintFormatU16 bs3PrintFormatU64 92 93 #else 94 static size_t bs3PrintFormatU32(char szTmp[64], uint32_t uValue, unsigned uBase, uint16_t fFlags, int cchWidth, int cchPrecision) 95 { 96 const char *pachDigits = !(fFlags & STR_F_CAPITAL) ? BS3_DATA_NM(g_achBs3HexDigits) : BS3_DATA_NM(g_achBs3HexDigitsUpper); 97 char *psz = &szTmp[64]; 98 99 *--psz = '\0'; 100 if (uBase == 10) 101 { 102 do 103 { 104 *--psz = pachDigits[uValue % 10]; 105 uValue /= 10; 106 } while (uValue > 0); 107 } 108 else 109 { 110 unsigned const cShift = uBase == 8 ? 2 : 3; 111 unsigned const fMask = uBase == 8 ? 7 : 15; 112 do 113 { 114 *--psz = pachDigits[uValue & fMask]; 115 uValue >>= cShift; 116 } while (uValue > 0); 117 } 118 return bs3PrintFormatString(psz, &szTmp[63] - psz, 0, 0, 0); 119 } 120 121 # if ARCH_BITS == 16 122 static size_t bs3PrintFormatU16(char szTmp[64], uint16_t uValue, unsigned uBase, uint16_t fFlags, int cchWidth, int cchPrecision) 123 { 124 if (uBase == 10) 125 { 126 const char *pachDigits = !(fFlags & STR_F_CAPITAL) ? BS3_DATA_NM(g_achBs3HexDigits) : BS3_DATA_NM(g_achBs3HexDigitsUpper); 127 char *psz = &szTmp[64]; 128 129 *--psz = '\0'; 130 do 131 { 132 *--psz = pachDigits[uValue % 10]; 133 uValue /= 10; 134 } while (uValue > 0); 135 return bs3PrintFormatString(psz, &szTmp[63] - psz, 0, 0, 0); 136 } 137 /* 32-bit shifting is reasonably cheap, so combine with 32-bit. */ 138 return bs3PrintFormatU32(szTmp, uValue, uBase, fFlags, cchWidth, cchPrecision); 139 } 140 # endif /* 16-bit */ 141 #endif /* !64-bit */ 142 143 144 static size_t bs3PrintFormatS64(char szTmp[64], int16_t iValue, uint16_t fFlags, int cchWidth, int cchPrecision) 145 { 146 /** @todo this is kind of crude, full fleged formatting can wait. */ 147 size_t cchRet = 0; 148 if (iValue < 0) 149 { 150 Bs3PrintChr('-'); 151 cchRet++; 152 } 153 cchRet += bs3PrintFormatU64(szTmp, iValue, 10, fFlags & ~STR_F_VALSIGNED, cchWidth, cchPrecision); 154 return cchRet; 47 return Bs3StrFormatV(pszFormat, va, bs3PrintFmtOutput, NULL); 155 48 } 156 49 157 50 158 static size_t bs3PrintFormatS32(char szTmp[64], int16_t iValue, uint16_t fFlags, int cchWidth, int cchPrecision) 159 { 160 /** @todo this is kind of crude, full fleged formatting can wait. */ 161 size_t cchRet = 0; 162 if (iValue < 0) 163 { 164 Bs3PrintChr('-'); 165 cchRet++; 166 } 167 cchRet += bs3PrintFormatU32(szTmp, iValue, 10, fFlags & ~STR_F_VALSIGNED, cchWidth, cchPrecision); 168 return cchRet; 169 } 170 171 172 #if ARCH_BITS == 16 173 static size_t bs3PrintFormatS16(char szTmp[64], int16_t iValue, uint16_t fFlags, int cchWidth, int cchPrecision) 174 { 175 /** @todo this is kind of crude, full fleged formatting can wait. */ 176 size_t cchRet = 0; 177 if (iValue < 0) 178 { 179 Bs3PrintChr('-'); 180 cchRet++; 181 } 182 cchRet += bs3PrintFormatU16(szTmp, iValue, 10, fFlags & ~STR_F_VALSIGNED, cchWidth, cchPrecision); 183 return cchRet; 184 } 185 #endif 186 187 188 189 190 191 BS3_DECL(size_t) Bs3PrintFV(const char BS3_FAR *pszFormat, va_list va) 192 { 193 size_t cchRet = 0; 194 char ch; 195 while ((ch = *pszFormat++) != '\0') 196 { 197 unsigned int fFlags; 198 int cchWidth; 199 int cchPrecision; 200 char chArgSize; 201 char szTmp[64]; 202 203 /* 204 * Deal with plain chars. 205 */ 206 if (ch != '%') 207 { 208 if (ch == '\n') 209 Bs3PrintChr('\r'); 210 Bs3PrintChr(ch); 211 cchRet++; 212 continue; 213 } 214 215 ch = *pszFormat++; 216 if (ch == '%') 217 { 218 Bs3PrintChr(ch); 219 cchRet++; 220 continue; 221 } 222 223 /* 224 * Flags. 225 */ 226 fFlags = 0; 227 for (;;) 228 { 229 unsigned int fThis; 230 switch (ch) 231 { 232 default: fThis = 0; break; 233 case '#': fThis = STR_F_SPECIAL; break; 234 case '-': fThis = STR_F_LEFT; break; 235 case '+': fThis = STR_F_PLUS; break; 236 case ' ': fThis = STR_F_BLANK; break; 237 case '0': fThis = STR_F_ZEROPAD; break; 238 case '\'': fThis = STR_F_THOUSAND_SEP; break; 239 } 240 if (!fThis) 241 break; 242 fFlags |= fThis; 243 ch = *pszFormat++; 244 } 245 246 /* 247 * Width. 248 */ 249 cchWidth = 0; 250 if (RT_C_IS_DIGIT(ch)) 251 { 252 do 253 { 254 cchWidth *= 10; 255 cchWidth = ch - '0'; 256 ch = *pszFormat++; 257 } while (RT_C_IS_DIGIT(ch)); 258 fFlags |= STR_F_WIDTH; 259 } 260 else if (ch == '*') 261 { 262 cchWidth = va_arg(va, int); 263 if (cchWidth < 0) 264 { 265 cchWidth = -cchWidth; 266 fFlags |= STR_F_LEFT; 267 } 268 fFlags |= STR_F_WIDTH; 269 } 270 271 /* 272 * Precision 273 */ 274 cchPrecision = 0; 275 if (RT_C_IS_DIGIT(ch)) 276 { 277 do 278 { 279 cchPrecision *= 10; 280 cchPrecision = ch - '0'; 281 ch = *pszFormat++; 282 } while (RT_C_IS_DIGIT(ch)); 283 fFlags |= STR_F_PRECISION; 284 } 285 else if (ch == '*') 286 { 287 cchPrecision = va_arg(va, int); 288 if (cchPrecision < 0) 289 cchPrecision = 0; 290 fFlags |= STR_F_PRECISION; 291 } 292 293 /* 294 * Argument size. 295 */ 296 chArgSize = ch; 297 switch (ch) 298 { 299 default: 300 chArgSize = 0; 301 break; 302 303 case 'z': 304 case 'L': 305 case 'j': 306 case 't': 307 ch = *pszFormat++; 308 break; 309 310 case 'l': 311 ch = *pszFormat++; 312 if (ch == 'l') 313 { 314 chArgSize = 'L'; 315 ch = *pszFormat++; 316 } 317 break; 318 319 case 'h': 320 ch = *pszFormat++; 321 if (ch == 'h') 322 { 323 chArgSize = 'H'; 324 ch = *pszFormat++; 325 } 326 break; 327 } 328 329 /* 330 * The type. 331 */ 332 switch (ch) 333 { 334 /* 335 * Char 336 */ 337 case 'c': 338 szTmp[0] = va_arg(va, int /*char*/); 339 szTmp[1] = '\0'; 340 cchRet += bs3PrintFormatString(szTmp, 1, fFlags, cchWidth, cchPrecision); 341 break; 342 343 /* 344 * String. 345 */ 346 case 's': 347 { 348 const char BS3_FAR *psz = va_arg(va, const char BS3_FAR *); 349 if (psz == NULL) 350 psz = "<NULL>"; 351 cchRet += bs3PrintFormatString(psz, ~(size_t)0, fFlags, cchWidth, cchPrecision); 352 break; 353 } 354 355 /* 356 * Signed integers. 357 */ 358 case 'i': 359 case 'd': 360 fFlags |= STR_F_VALSIGNED; 361 switch (chArgSize) 362 { 363 case 0: 364 case 'h': /* signed short should be promoted to int or be the same as int */ 365 case 'H': /* signed char should be promoted to int. */ 366 { 367 signed int iValue = va_arg(va, signed int); 368 #if ARCH_BITS == 16 369 cchRet += bs3PrintFormatS16(szTmp, iValue, fFlags, cchWidth, cchPrecision); 370 #else 371 cchRet += bs3PrintFormatS32(szTmp, iValue, fFlags, cchWidth, cchPrecision); 372 #endif 373 break; 374 } 375 case 'l': 376 { 377 signed long lValue = va_arg(va, signed long); 378 if (sizeof(lValue) == 4) 379 cchRet += bs3PrintFormatS32(szTmp, lValue, fFlags, cchWidth, cchPrecision); 380 else 381 cchRet += bs3PrintFormatS64(szTmp, lValue, fFlags, cchWidth, cchPrecision); 382 break; 383 } 384 case 'L': 385 { 386 unsigned long long ullValue = va_arg(va, unsigned long long); 387 cchRet += bs3PrintFormatS64(szTmp, ullValue, fFlags, cchWidth, cchPrecision); 388 break; 389 } 390 } 391 break; 392 393 /* 394 * Unsigned integers. 395 */ 396 case 'X': 397 fFlags |= STR_F_CAPITAL; 398 case 'x': 399 case 'u': 400 { 401 unsigned uBase = ch = 'u' ? 10 : 16; 402 switch (chArgSize) 403 { 404 case 0: 405 case 'h': /* unsigned short should be promoted to int or be the same as int */ 406 case 'H': /* unsigned char should be promoted to int. */ 407 { 408 unsigned int uValue = va_arg(va, unsigned int); 409 #if ARCH_BITS == 16 410 cchRet += bs3PrintFormatU16(szTmp, uValue, uBase, fFlags, cchWidth, cchPrecision); 411 #else 412 cchRet += bs3PrintFormatU32(szTmp, uValue, uBase, fFlags, cchWidth, cchPrecision); 413 #endif 414 break; 415 } 416 case 'l': 417 { 418 unsigned long ulValue = va_arg(va, unsigned long); 419 if (sizeof(ulValue) == 4) 420 cchRet += bs3PrintFormatU32(szTmp, ulValue, uBase, fFlags, cchWidth, cchPrecision); 421 else 422 cchRet += bs3PrintFormatU64(szTmp, ulValue, uBase, fFlags, cchWidth, cchPrecision); 423 break; 424 } 425 case 'L': 426 { 427 unsigned long long ullValue = va_arg(va, unsigned long long); 428 cchRet += bs3PrintFormatU64(szTmp, ullValue, uBase, fFlags, cchWidth, cchPrecision); 429 break; 430 } 431 } 432 break; 433 } 434 435 /* 436 * Our stuff. 437 */ 438 case 'R': 439 { 440 unsigned uBase; 441 ch = *pszFormat++; 442 switch (ch) 443 { 444 case 'I': 445 fFlags |= STR_F_VALSIGNED; 446 /* fall thru */ 447 case 'U': 448 uBase = 10; 449 break; 450 case 'X': 451 uBase = 16; 452 break; 453 default: 454 uBase = 0; 455 break; 456 } 457 if (uBase) 458 { 459 ch = *pszFormat++; 460 switch (ch) 461 { 462 #if ARCH_BITS != 16 463 case '3': 464 case '1': /* Will an unsigned 16-bit value always be promoted 465 to a 16-bit unsigned int. It certainly will be promoted to a 32-bit int. */ 466 pszFormat++; /* Assumes (1)'6' or (3)'2' */ 467 #else 468 case '1': 469 pszFormat++; /* Assumes (1)'6' */ 470 #endif 471 case '8': /* An unsigned 8-bit value should be promoted to int, which is at least 16-bit. */ 472 { 473 unsigned int uValue = va_arg(va, unsigned int); 474 #if ARCH_BITS == 16 475 cchRet += bs3PrintFormatU16(szTmp, uValue, uBase, fFlags, cchWidth, cchPrecision); 476 #else 477 cchRet += bs3PrintFormatU32(szTmp, uValue, uBase, fFlags, cchWidth, cchPrecision); 478 #endif 479 break; 480 } 481 #if ARCH_BITS == 16 482 case '3': 483 { 484 uint32_t uValue = va_arg(va, uint32_t); 485 pszFormat++; 486 cchRet += bs3PrintFormatU32(szTmp, uValue, uBase, fFlags, cchWidth, cchPrecision); 487 break; 488 } 489 #endif 490 case '6': 491 { 492 uint64_t uValue = va_arg(va, uint64_t); 493 pszFormat++; 494 cchRet += bs3PrintFormatU64(szTmp, uValue, uBase, fFlags, cchWidth, cchPrecision); 495 break; 496 } 497 } 498 } 499 break; 500 } 501 502 /* 503 * Pointers. 504 */ 505 case 'P': 506 fFlags |= STR_F_CAPITAL; 507 /* fall thru */ 508 case 'p': 509 { 510 void BS3_FAR *pv = va_arg(va, void BS3_FAR *); 511 #if ARCH_BITS == 16 512 cchRet += bs3PrintFormatU16(szTmp, BS3_FP_SEG(pv), 16, fFlags, fFlags & STR_F_SPECIAL ? 6 : 4, 0); 513 Bs3PrintChr(':'); 514 cchRet += 1; 515 cchRet += bs3PrintFormatU16(szTmp, BS3_FP_OFF(pv), 16, fFlags & ~STR_F_SPECIAL, 4, 0); 516 #elif ARCH_BITS == 32 517 cchRet += bs3PrintFormatU32(szTmp, (uintptr_t)pv, 16, fFlags | STR_F_SPECIAL, 10, 0); 518 #elif ARCH_BITS == 64 519 cchRet += bs3PrintFormatU64(szTmp, (uintptr_t)pv, 16, fFlags | STR_F_SPECIAL | STR_F_THOUSAND_SEP, 19, 0); 520 #else 521 # error "Undefined or invalid ARCH_BITS." 522 #endif 523 break; 524 } 525 526 } 527 } 528 return cchRet; 529 } 530 531 532 BS3_DECL(size_t) Bs3PrintF(const char BS3_FAR *pszFormat, ...) 51 BS3_DECL(size_t) Bs3Printf(const char BS3_FAR *pszFormat, ...) 533 52 { 534 53 size_t cchRet; 535 54 va_list va; 536 55 va_start(va, pszFormat); 537 cchRet = Bs3 PrintFV(pszFormat, va);56 cchRet = Bs3StrFormatV(pszFormat, va, bs3PrintFmtOutput, NULL); 538 57 va_end(va); 539 58 return cchRet; -
trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-StrFormatV.c
r58806 r58809 1 1 /* $Id$ */ 2 2 /** @file 3 * BS3Kit - Bs3 PrintF3 * BS3Kit - Bs3StrFormatV 4 4 */ 5 5 … … 25 25 */ 26 26 27 28 /********************************************************************************************************************************* 29 * Header Files * 30 *********************************************************************************************************************************/ 27 31 #include "bs3kit-template-header.h" 28 32 #include <iprt/ctype.h> 29 33 30 34 31 #define STR_F_CAPITAL 0x0001 32 #define STR_F_LEFT 0x0002 33 #define STR_F_ZEROPAD 0x0004 34 #define STR_F_SPECIAL 0x0008 35 #define STR_F_VALSIGNED 0x0010 36 #define STR_F_PLUS 0x0020 37 #define STR_F_BLANK 0x0040 38 #define STR_F_WIDTH 0x0080 39 #define STR_F_PRECISION 0x0100 40 #define STR_F_THOUSAND_SEP 0x0200 41 42 43 static size_t bs3PrintFormatString(const char *psz, size_t cchMax, uint16_t fFlags, int cchWidth, int cchPrecision) 44 { 45 size_t cchRet; 46 if (cchMax == ~(size_t)0) 47 cchMax = Bs3StrNLen(psz, cchMax); 48 cchRet = cchMax; 49 50 /** @todo this is kind of crude, full fleged formatting can wait. */ 51 while (cchMax-- > 0) 52 Bs3PrintChr(*psz++); 53 54 return cchRet; 35 /********************************************************************************************************************************* 36 * Defined Constants And Macros * 37 *********************************************************************************************************************************/ 38 #define STR_F_CAPITAL 0x0001 39 #define STR_F_LEFT 0x0002 40 #define STR_F_ZEROPAD 0x0004 41 #define STR_F_SPECIAL 0x0008 42 #define STR_F_VALSIGNED 0x0010 43 #define STR_F_PLUS 0x0020 44 #define STR_F_BLANK 0x0040 45 #define STR_F_WIDTH 0x0080 46 #define STR_F_PRECISION 0x0100 47 #define STR_F_THOUSAND_SEP 0x0200 48 #define STR_F_NEGATIVE 0x0400 /**< Used to indicated '-' must be printed. */ 49 50 51 /********************************************************************************************************************************* 52 * Structures and Typedefs * 53 *********************************************************************************************************************************/ 54 /** Size of the temporary buffer. */ 55 #define BS3FMT_TMP_SIZE 64 56 57 /** 58 * BS3kit string format state. 59 */ 60 typedef struct BS3FMTSTATE 61 { 62 /** The output function. */ 63 PFNBS3STRFORMATOUTPUT pfnOutput; 64 /** User argument for pfnOutput. */ 65 void BS3_FAR *pvUser; 66 67 /** STR_F_XXX flags. */ 68 unsigned fFlags; 69 /** The width when STR_F_WIDTH is specific. */ 70 int cchWidth; 71 /** The width when STR_F_PRECISION is specific. */ 72 int cchPrecision; 73 /** The number format base. */ 74 unsigned uBase; 75 /** Temporary buffer. */ 76 char szTmp[BS3FMT_TMP_SIZE]; 77 } BS3FMTSTATE; 78 /** Pointer to a BS3Kit string formatter state. */ 79 typedef BS3FMTSTATE *PBS3FMTSTATE; 80 81 82 83 /********************************************************************************************************************************* 84 * Internal Functions * 85 *********************************************************************************************************************************/ 86 #if ARCH_BITS != 64 87 static size_t bs3StrFormatU32(PBS3FMTSTATE pState, uint32_t uValue); 88 #endif 89 90 91 92 /** 93 * Formats a number string. 94 * 95 * @returns Number of chars printed. 96 * @param pState The string formatter state. 97 * @param pszNumber The formatted number string. 98 * @param cchNumber The length of the number. 99 */ 100 static size_t bs3StrFormatNumberString(PBS3FMTSTATE pState, char const *pszNumber, size_t cchNumber) 101 { 102 /* 103 * Calc the length of the core number with prefixes. 104 */ 105 size_t cchActual = 0; 106 size_t cchRet = cchNumber; 107 108 /* Accunt for sign char. */ 109 cchRet += !!(pState->fFlags & (STR_F_NEGATIVE | STR_F_PLUS | STR_F_BLANK)); 110 111 /* Account for the hex prefix: '0x' or '0X' */ 112 if (pState->fFlags & STR_F_SPECIAL) 113 { 114 cchRet += 2; 115 BS3_ASSERT(pState->uBase == 16); 116 } 117 118 /* Account for thousand separators (applied while printing). */ 119 if (pState->fFlags & STR_F_THOUSAND_SEP) 120 cchRet += (cchNumber - 1) / (pState->uBase == 10 ? 3 : 8); 121 122 /* 123 * Do left blank padding. 124 */ 125 if ((pState->fFlags & (STR_F_ZEROPAD | STR_F_LEFT | STR_F_WIDTH)) == STR_F_WIDTH) 126 while (cchRet < pState->cchWidth) 127 { 128 cchActual += pState->pfnOutput(' ', pState->pvUser); 129 cchRet++; 130 } 131 132 /* 133 * Sign indicator / space. 134 */ 135 if (pState->fFlags & (STR_F_NEGATIVE | STR_F_PLUS | STR_F_BLANK)) 136 { 137 char ch; 138 if (pState->fFlags & STR_F_NEGATIVE) 139 ch = '-'; 140 else if (pState->fFlags & STR_F_PLUS) 141 ch = '+'; 142 else 143 ch = ' '; 144 cchActual += pState->pfnOutput(ch, pState->pvUser); 145 } 146 147 /* 148 * Hex prefix. 149 */ 150 if (pState->fFlags & STR_F_SPECIAL) 151 { 152 cchActual += pState->pfnOutput(0, pState->pvUser); 153 cchActual += pState->pfnOutput(!(pState->fFlags & STR_F_CAPITAL) ? 'x' : 'X', pState->pvUser); 154 } 155 156 /* 157 * Zero padding. 158 */ 159 if (pState->fFlags & STR_F_ZEROPAD) 160 while (cchRet < pState->cchWidth) 161 { 162 cchActual += pState->pfnOutput('0', pState->pvUser); 163 cchRet++; 164 } 165 166 /* 167 * Output the number. 168 */ 169 if ( !(pState->fFlags & STR_F_THOUSAND_SEP) 170 || cchNumber < 4) 171 while (cchNumber-- > 0) 172 cchActual += pState->pfnOutput(*pszNumber++, pState->pvUser); 173 else 174 { 175 char const chSep = pState->uBase == 10 ? ' ' : '\''; 176 unsigned const cchEvery = pState->uBase == 10 ? 3 : 8; 177 unsigned cchLeft = --cchNumber % cchEvery; 178 179 cchActual += pState->pfnOutput(*pszNumber++, pState->pvUser); 180 while (cchNumber-- > 0) 181 { 182 if (cchLeft == 0) 183 { 184 cchActual += pState->pfnOutput(chSep, pState->pvUser); 185 cchLeft = cchEvery; 186 } 187 cchLeft--; 188 cchActual += pState->pfnOutput(*pszNumber++, pState->pvUser); 189 } 190 } 191 192 /* 193 * Do right blank padding. 194 */ 195 if ((pState->fFlags & (STR_F_ZEROPAD | STR_F_LEFT | STR_F_WIDTH)) == (STR_F_WIDTH | STR_F_LEFT)) 196 while (cchRet < pState->cchWidth) 197 { 198 cchActual += pState->pfnOutput(' ', pState->pvUser); 199 cchRet++; 200 } 201 202 return cchActual; 55 203 } 56 204 57 205 58 static size_t bs3PrintFormatU64(char szTmp[64], uint64_t uValue, unsigned uBase, uint16_t fFlags, int cchWidth, int cchPrecision) 59 { 60 #if 0 61 const char *pachDigits = !(fFlags & STR_F_CAPITAL) ? BS3_DATA_NM(g_achBs3HexDigits) : BS3_DATA_NM(g_achBs3HexDigitsUpper); 62 char *psz = &szTmp[64]; 206 /** 207 * Format a 64-bit number. 208 * 209 * @returns Number of characters. 210 * @param pState The string formatter state. 211 * @param uValue The value. 212 */ 213 static size_t bs3StrFormatU64(PBS3FMTSTATE pState, uint64_t uValue) 214 { 215 #if ARCH_BITS != 64 216 /* Avoid 64-bit division by formatting 64-bit numbers as hex if they're higher than _4G. */ 217 if ( pState->uBase == 10 218 && !(uValue >> 32)) /* uValue <= UINT32_MAX does not work, trouble with 64-bit compile time math! */ 219 return bs3StrFormatU32(pState, uValue); 220 pState->fFlags |= STR_F_SPECIAL; 221 pState->uBase = 16; 222 #endif 223 224 { 225 const char *pachDigits = !(pState->fFlags & STR_F_CAPITAL) 226 ? BS3_DATA_NM(g_achBs3HexDigits) : BS3_DATA_NM(g_achBs3HexDigitsUpper); 227 char *psz = &pState->szTmp[BS3FMT_TMP_SIZE]; 228 229 *--psz = '\0'; 230 #if ARCH_BITS == 64 231 if (pState->uBase == 10) 232 { 233 do 234 { 235 *--psz = pachDigits[uValue % 10]; 236 uValue /= 10; 237 } while (uValue > 0); 238 } 239 else 240 #endif 241 { 242 BS3_ASSERT(pState->uBase == 16); 243 do 244 { 245 *--psz = pachDigits[uValue & 0xf]; 246 uValue >>= 4; 247 } while (uValue > 0); 248 } 249 return bs3StrFormatNumberString(pState, psz, &pState->szTmp[BS3FMT_TMP_SIZE - 1] - psz); 250 } 251 } 252 253 254 /** 255 * Format a 32-bit number. 256 * 257 * @returns Number of characters. 258 * @param pState The string formatter state. 259 * @param uValue The value. 260 */ 261 static size_t bs3StrFormatU32(PBS3FMTSTATE pState, uint32_t uValue) 262 { 263 #if ARCH_BITS < 64 264 const char *pachDigits = !(pState->fFlags & STR_F_CAPITAL) 265 ? BS3_DATA_NM(g_achBs3HexDigits) : BS3_DATA_NM(g_achBs3HexDigitsUpper); 266 char *psz = &pState->szTmp[BS3FMT_TMP_SIZE]; 63 267 64 268 *--psz = '\0'; 65 if ( uBase == 10)269 if (pState->uBase == 10) 66 270 { 67 271 do … … 73 277 else 74 278 { 75 unsigned const cShift = uBase == 8 ? 2 : 3; 76 unsigned const fMask = uBase == 8 ? 7 : 15; 279 BS3_ASSERT(pState->uBase == 16); 77 280 do 78 281 { 79 *--psz = pachDigits[uValue & fMask];80 uValue >>= cShift;282 *--psz = pachDigits[uValue & 0xf]; 283 uValue >>= 4; 81 284 } while (uValue > 0); 82 285 } 83 return bs3PrintFormatString(psz, &szTmp[63] - psz, 0, 0, 0); 286 return bs3StrFormatNumberString(pState, psz, &pState->szTmp[BS3FMT_TMP_SIZE - 1] - psz); 287 84 288 #else 85 return 0; 289 /* We've got native 64-bit division, save space. */ 290 return bs3StrFormatU64(pState, uValue); 86 291 #endif 87 292 } 88 293 89 #if ARCH_BITS == 64 90 # define bs3PrintFormatU32 bs3PrintFormatU64 91 # define bs3PrintFormatU16 bs3PrintFormatU64 92 93 #else 94 static size_t bs3PrintFormatU32(char szTmp[64], uint32_t uValue, unsigned uBase, uint16_t fFlags, int cchWidth, int cchPrecision) 95 { 96 const char *pachDigits = !(fFlags & STR_F_CAPITAL) ? BS3_DATA_NM(g_achBs3HexDigits) : BS3_DATA_NM(g_achBs3HexDigitsUpper); 97 char *psz = &szTmp[64]; 98 99 *--psz = '\0'; 100 if (uBase == 10) 101 { 294 295 #if ARCH_BITS == 16 296 /** 297 * Format a 16-bit number. 298 * 299 * @returns Number of characters. 300 * @param pState The string formatter state. 301 * @param uValue The value. 302 */ 303 static size_t bs3StrFormatU16(PBS3FMTSTATE pState, uint16_t uValue) 304 { 305 if (pState->uBase == 10) 306 { 307 const char *pachDigits = !(pState->fFlags & STR_F_CAPITAL) 308 ? BS3_DATA_NM(g_achBs3HexDigits) : BS3_DATA_NM(g_achBs3HexDigitsUpper); 309 char *psz = &pState->szTmp[BS3FMT_TMP_SIZE]; 310 311 *--psz = '\0'; 102 312 do 103 313 { … … 105 315 uValue /= 10; 106 316 } while (uValue > 0); 107 } 108 else 109 { 110 unsigned const cShift = uBase == 8 ? 2 : 3; 111 unsigned const fMask = uBase == 8 ? 7 : 15; 112 do 113 { 114 *--psz = pachDigits[uValue & fMask]; 115 uValue >>= cShift; 116 } while (uValue > 0); 117 } 118 return bs3PrintFormatString(psz, &szTmp[63] - psz, 0, 0, 0); 317 return bs3StrFormatNumberString(pState, psz, &pState->szTmp[BS3FMT_TMP_SIZE - 1] - psz); 318 } 319 320 /* 321 * 32-bit shifting is reasonably cheap and inlined, so combine with 32-bit. 322 */ 323 return bs3StrFormatU32(pState, uValue); 119 324 } 120 121 # if ARCH_BITS == 16 122 static size_t bs3PrintFormatU16(char szTmp[64], uint16_t uValue, unsigned uBase, uint16_t fFlags, int cchWidth, int cchPrecision) 123 { 124 if (uBase == 10) 125 { 126 const char *pachDigits = !(fFlags & STR_F_CAPITAL) ? BS3_DATA_NM(g_achBs3HexDigits) : BS3_DATA_NM(g_achBs3HexDigitsUpper); 127 char *psz = &szTmp[64]; 128 129 *--psz = '\0'; 130 do 131 { 132 *--psz = pachDigits[uValue % 10]; 133 uValue /= 10; 134 } while (uValue > 0); 135 return bs3PrintFormatString(psz, &szTmp[63] - psz, 0, 0, 0); 136 } 137 /* 32-bit shifting is reasonably cheap, so combine with 32-bit. */ 138 return bs3PrintFormatU32(szTmp, uValue, uBase, fFlags, cchWidth, cchPrecision); 325 #endif 326 327 328 static size_t bs3StrFormatS64(PBS3FMTSTATE pState, int32_t iValue) 329 { 330 if (iValue < 0) 331 { 332 iValue = -iValue; 333 pState->fFlags |= STR_F_NEGATIVE; 334 } 335 return bs3StrFormatU64(pState, iValue); 139 336 } 140 # endif /* 16-bit */ 141 #endif /* !64-bit */ 142 143 144 static size_t bs3PrintFormatS64(char szTmp[64], int16_t iValue, uint16_t fFlags, int cchWidth, int cchPrecision) 145 { 146 /** @todo this is kind of crude, full fleged formatting can wait. */ 147 size_t cchRet = 0; 337 338 339 static size_t bs3StrFormatS32(PBS3FMTSTATE pState, int32_t iValue) 340 { 148 341 if (iValue < 0) 149 342 { 150 Bs3PrintChr('-'); 151 cchRet++; 152 } 153 cchRet += bs3PrintFormatU64(szTmp, iValue, 10, fFlags & ~STR_F_VALSIGNED, cchWidth, cchPrecision); 154 return cchRet; 343 iValue = -iValue; 344 pState->fFlags |= STR_F_NEGATIVE; 345 } 346 return bs3StrFormatU32(pState, iValue); 155 347 } 156 348 157 349 158 static size_t bs3PrintFormatS32(char szTmp[64], int16_t iValue, uint16_t fFlags, int cchWidth, int cchPrecision) 159 { 160 /** @todo this is kind of crude, full fleged formatting can wait. */ 161 size_t cchRet = 0; 350 #if ARCH_BITS == 16 351 static size_t bs3StrFormatS16(PBS3FMTSTATE pState, int16_t iValue) 352 { 162 353 if (iValue < 0) 163 354 { 164 Bs3PrintChr('-'); 165 cchRet++; 166 } 167 cchRet += bs3PrintFormatU32(szTmp, iValue, 10, fFlags & ~STR_F_VALSIGNED, cchWidth, cchPrecision); 168 return cchRet; 355 iValue = -iValue; 356 pState->fFlags |= STR_F_NEGATIVE; 357 } 358 return bs3StrFormatU16(pState, iValue); 169 359 } 170 171 172 #if ARCH_BITS == 16 173 static size_t bs3PrintFormatS16(char szTmp[64], int16_t iValue, uint16_t fFlags, int cchWidth, int cchPrecision) 174 { 175 /** @todo this is kind of crude, full fleged formatting can wait. */ 176 size_t cchRet = 0; 177 if (iValue < 0) 178 { 179 Bs3PrintChr('-'); 180 cchRet++; 181 } 182 cchRet += bs3PrintFormatU16(szTmp, iValue, 10, fFlags & ~STR_F_VALSIGNED, cchWidth, cchPrecision); 183 return cchRet; 184 } 185 #endif 186 187 188 189 190 191 BS3_DECL(size_t) Bs3PrintFV(const char BS3_FAR *pszFormat, va_list va) 192 { 193 size_t cchRet = 0; 194 char ch; 360 #endif 361 362 363 BS3_DECL(size_t) Bs3StrFormatV(const char BS3_FAR *pszFormat, va_list va, PFNBS3STRFORMATOUTPUT pfnOutput, void *pvUser) 364 { 365 BS3FMTSTATE State; 366 size_t cchRet = 0; 367 char ch; 368 369 State.pfnOutput = pfnOutput; 370 State.pvUser = pvUser; 371 195 372 while ((ch = *pszFormat++) != '\0') 196 373 { 197 unsigned int fFlags; 198 int cchWidth; 199 int cchPrecision; 200 char chArgSize; 201 char szTmp[64]; 374 char chArgSize; 202 375 203 376 /* … … 206 379 if (ch != '%') 207 380 { 208 if (ch == '\n') 209 Bs3PrintChr('\r'); 210 Bs3PrintChr(ch); 211 cchRet++; 381 cchRet += State.pfnOutput(ch, State.pvUser); 212 382 continue; 213 383 } … … 216 386 if (ch == '%') 217 387 { 218 Bs3PrintChr(ch); 219 cchRet++; 388 cchRet += State.pfnOutput(ch, State.pvUser); 220 389 continue; 221 390 } … … 224 393 * Flags. 225 394 */ 226 fFlags = 0;395 State.fFlags = 0; 227 396 for (;;) 228 397 { … … 240 409 if (!fThis) 241 410 break; 242 fFlags |= fThis;411 State.fFlags |= fThis; 243 412 ch = *pszFormat++; 244 413 } … … 247 416 * Width. 248 417 */ 249 cchWidth = 0;418 State.cchWidth = 0; 250 419 if (RT_C_IS_DIGIT(ch)) 251 420 { 252 421 do 253 422 { 254 cchWidth *= 10;255 cchWidth = ch - '0';423 State.cchWidth *= 10; 424 State.cchWidth = ch - '0'; 256 425 ch = *pszFormat++; 257 426 } while (RT_C_IS_DIGIT(ch)); 258 fFlags |= STR_F_WIDTH;427 State.fFlags |= STR_F_WIDTH; 259 428 } 260 429 else if (ch == '*') 261 430 { 262 cchWidth = va_arg(va, int);263 if ( cchWidth < 0)264 { 265 cchWidth = -cchWidth;266 fFlags |= STR_F_LEFT;431 State.cchWidth = va_arg(va, int); 432 if (State.cchWidth < 0) 433 { 434 State.cchWidth = -State.cchWidth; 435 State.fFlags |= STR_F_LEFT; 267 436 } 268 fFlags |= STR_F_WIDTH;437 State.fFlags |= STR_F_WIDTH; 269 438 } 270 439 … … 272 441 * Precision 273 442 */ 274 cchPrecision = 0;443 State.cchPrecision = 0; 275 444 if (RT_C_IS_DIGIT(ch)) 276 445 { 277 446 do 278 447 { 279 cchPrecision *= 10;280 cchPrecision = ch - '0';448 State.cchPrecision *= 10; 449 State.cchPrecision = ch - '0'; 281 450 ch = *pszFormat++; 282 451 } while (RT_C_IS_DIGIT(ch)); 283 fFlags |= STR_F_PRECISION;452 State.fFlags |= STR_F_PRECISION; 284 453 } 285 454 else if (ch == '*') 286 455 { 287 cchPrecision = va_arg(va, int);288 if ( cchPrecision < 0)289 cchPrecision = 0;290 fFlags |= STR_F_PRECISION;456 State.cchPrecision = va_arg(va, int); 457 if (State.cchPrecision < 0) 458 State.cchPrecision = 0; 459 State.fFlags |= STR_F_PRECISION; 291 460 } 292 461 … … 336 505 */ 337 506 case 'c': 338 szTmp[0] = va_arg(va, int /*char*/); 339 szTmp[1] = '\0'; 340 cchRet += bs3PrintFormatString(szTmp, 1, fFlags, cchWidth, cchPrecision); 341 break; 507 { 508 char ch = va_arg(va, int /*char*/); 509 cchRet += State.pfnOutput(ch, State.pvUser); 510 break; 511 } 342 512 343 513 /* … … 347 517 { 348 518 const char BS3_FAR *psz = va_arg(va, const char BS3_FAR *); 349 if (psz == NULL) 519 size_t cch; 520 if (psz != NULL) 521 cch = Bs3StrNLen(psz, State.fFlags & STR_F_PRECISION ? RT_ABS(State.cchPrecision) : ~(size_t)0); 522 else 523 { 350 524 psz = "<NULL>"; 351 cchRet += bs3PrintFormatString(psz, ~(size_t)0, fFlags, cchWidth, cchPrecision); 525 cch = 6; 526 } 527 528 if ((State.fFlags & (STR_F_LEFT | STR_F_WIDTH)) == STR_F_WIDTH) 529 while (--State.cchWidth >= cch) 530 cchRet += State.pfnOutput(' ', State.pvUser); 531 532 cchRet += cch; 533 while (cch-- > 0) 534 cchRet += State.pfnOutput(*psz++, State.pvUser); 535 536 if ((State.fFlags & (STR_F_LEFT | STR_F_WIDTH)) == (STR_F_LEFT | STR_F_WIDTH)) 537 while (--State.cchWidth >= cch) 538 cchRet += State.pfnOutput(' ', State.pvUser); 352 539 break; 353 540 } … … 358 545 case 'i': 359 546 case 'd': 360 fFlags |= STR_F_VALSIGNED; 547 State.fFlags &= ~STR_F_SPECIAL; 548 State.fFlags |= STR_F_VALSIGNED; 549 State.uBase = 10; 361 550 switch (chArgSize) 362 551 { … … 367 556 signed int iValue = va_arg(va, signed int); 368 557 #if ARCH_BITS == 16 369 cchRet += bs3 PrintFormatS16(szTmp, iValue, fFlags, cchWidth, cchPrecision);558 cchRet += bs3StrFormatS16(&State, iValue); 370 559 #else 371 cchRet += bs3 PrintFormatS32(szTmp, iValue, fFlags, cchWidth, cchPrecision);560 cchRet += bs3StrFormatS32(&State, iValue); 372 561 #endif 373 562 break; … … 377 566 signed long lValue = va_arg(va, signed long); 378 567 if (sizeof(lValue) == 4) 379 cchRet += bs3 PrintFormatS32(szTmp, lValue, fFlags, cchWidth, cchPrecision);568 cchRet += bs3StrFormatS32(&State, lValue); 380 569 else 381 cchRet += bs3 PrintFormatS64(szTmp, lValue, fFlags, cchWidth, cchPrecision);570 cchRet += bs3StrFormatS64(&State, lValue); 382 571 break; 383 572 } … … 385 574 { 386 575 unsigned long long ullValue = va_arg(va, unsigned long long); 387 cchRet += bs3 PrintFormatS64(szTmp, ullValue, fFlags, cchWidth, cchPrecision);576 cchRet += bs3StrFormatS64(&State, ullValue); 388 577 break; 389 578 } … … 395 584 */ 396 585 case 'X': 397 fFlags |= STR_F_CAPITAL;586 State.fFlags |= STR_F_CAPITAL; 398 587 case 'x': 399 588 case 'u': 400 589 { 401 unsigned uBase = ch = 'u' ? 10 : 16; 590 if (ch == 'u') 591 { 592 State.uBase = 10; 593 State.fFlags &= ~(STR_F_PLUS | STR_F_BLANK | STR_F_SPECIAL); 594 } 595 else 596 { 597 State.uBase = 16; 598 State.fFlags &= ~(STR_F_PLUS | STR_F_BLANK); 599 } 402 600 switch (chArgSize) 403 601 { … … 408 606 unsigned int uValue = va_arg(va, unsigned int); 409 607 #if ARCH_BITS == 16 410 cchRet += bs3 PrintFormatU16(szTmp, uValue, uBase, fFlags, cchWidth, cchPrecision);608 cchRet += bs3StrFormatU16(&State, uValue); 411 609 #else 412 cchRet += bs3 PrintFormatU32(szTmp, uValue, uBase, fFlags, cchWidth, cchPrecision);610 cchRet += bs3StrFormatU32(&State, uValue); 413 611 #endif 414 612 break; … … 418 616 unsigned long ulValue = va_arg(va, unsigned long); 419 617 if (sizeof(ulValue) == 4) 420 cchRet += bs3 PrintFormatU32(szTmp, ulValue, uBase, fFlags, cchWidth, cchPrecision);618 cchRet += bs3StrFormatU32(&State, ulValue); 421 619 else 422 cchRet += bs3 PrintFormatU64(szTmp, ulValue, uBase, fFlags, cchWidth, cchPrecision);620 cchRet += bs3StrFormatU64(&State, ulValue); 423 621 break; 424 622 } … … 426 624 { 427 625 unsigned long long ullValue = va_arg(va, unsigned long long); 428 cchRet += bs3 PrintFormatU64(szTmp, ullValue, uBase, fFlags, cchWidth, cchPrecision);626 cchRet += bs3StrFormatU64(&State, ullValue); 429 627 break; 430 628 } … … 438 636 case 'R': 439 637 { 440 unsigned uBase;441 638 ch = *pszFormat++; 442 639 switch (ch) 443 640 { 444 641 case 'I': 445 fFlags |= STR_F_VALSIGNED; 446 /* fall thru */ 642 State.fFlags |= STR_F_VALSIGNED; 643 State.uBase &= ~STR_F_SPECIAL; 644 State.uBase = 10; 645 break; 447 646 case 'U': 448 uBase = 10; 647 State.fFlags &= ~(STR_F_PLUS | STR_F_BLANK | STR_F_SPECIAL); 648 State.uBase = 10; 449 649 break; 450 650 case 'X': 451 uBase = 16; 651 State.fFlags &= ~(STR_F_PLUS | STR_F_BLANK); 652 State.uBase = 16; 452 653 break; 453 654 default: 454 uBase= 0;455 break; 456 } 457 if ( uBase)655 State.uBase = 0; 656 break; 657 } 658 if (State.uBase) 458 659 { 459 660 ch = *pszFormat++; … … 473 674 unsigned int uValue = va_arg(va, unsigned int); 474 675 #if ARCH_BITS == 16 475 cchRet += bs3 PrintFormatU16(szTmp, uValue, uBase, fFlags, cchWidth, cchPrecision);676 cchRet += bs3StrFormatU16(&State, uValue); 476 677 #else 477 cchRet += bs3 PrintFormatU32(szTmp, uValue, uBase, fFlags, cchWidth, cchPrecision);678 cchRet += bs3StrFormatU32(&State, uValue); 478 679 #endif 479 680 break; … … 484 685 uint32_t uValue = va_arg(va, uint32_t); 485 686 pszFormat++; 486 cchRet += bs3 PrintFormatU32(szTmp, uValue, uBase, fFlags, cchWidth, cchPrecision);687 cchRet += bs3StrFormatU32(&State, uValue); 487 688 break; 488 689 } … … 492 693 uint64_t uValue = va_arg(va, uint64_t); 493 694 pszFormat++; 494 cchRet += bs3 PrintFormatU64(szTmp, uValue, uBase, fFlags, cchWidth, cchPrecision);695 cchRet += bs3StrFormatU64(&State, uValue); 495 696 break; 496 697 } … … 504 705 */ 505 706 case 'P': 506 fFlags |= STR_F_CAPITAL;707 State.fFlags |= STR_F_CAPITAL; 507 708 /* fall thru */ 508 709 case 'p': 509 710 { 510 711 void BS3_FAR *pv = va_arg(va, void BS3_FAR *); 712 State.uBase = 16; 713 State.fFlags &= ~(STR_F_PLUS | STR_F_BLANK); 511 714 #if ARCH_BITS == 16 512 cchRet += bs3PrintFormatU16(szTmp, BS3_FP_SEG(pv), 16, fFlags, fFlags & STR_F_SPECIAL ? 6 : 4, 0); 513 Bs3PrintChr(':'); 514 cchRet += 1; 515 cchRet += bs3PrintFormatU16(szTmp, BS3_FP_OFF(pv), 16, fFlags & ~STR_F_SPECIAL, 4, 0); 715 State.fFlags |= STR_F_ZEROPAD; 716 State.cchWidth = State.fFlags & STR_F_SPECIAL ? 6: 4; 717 cchRet += bs3StrFormatU16(&State, BS3_FP_SEG(pv)); 718 cchRet += State.pfnOutput(':', State.pvUser); 719 cchRet += bs3StrFormatU16(&State, BS3_FP_OFF(pv)); 516 720 #elif ARCH_BITS == 32 517 cchRet += bs3PrintFormatU32(szTmp, (uintptr_t)pv, 16, fFlags | STR_F_SPECIAL, 10, 0); 721 State.fFlags |= STR_F_SPECIAL | STR_F_ZEROPAD; 722 State.cchWidth = 10; 723 cchRet += bs3StrFormatU32(&State, (uintptr_t)pv); 518 724 #elif ARCH_BITS == 64 519 cchRet += bs3PrintFormatU64(szTmp, (uintptr_t)pv, 16, fFlags | STR_F_SPECIAL | STR_F_THOUSAND_SEP, 19, 0); 725 State.fFlags |= STR_F_SPECIAL | STR_F_ZEROPAD | STR_F_THOUSAND_SEP; 726 State.cchWidth = 19; 727 cchRet += bs3StrFormatU64(&State, (uintptr_t)pv); 520 728 #else 521 729 # error "Undefined or invalid ARCH_BITS." … … 526 734 } 527 735 } 736 737 /* 738 * Termination call. 739 */ 740 cchRet += State.pfnOutput(0, State.pvUser); 741 528 742 return cchRet; 529 743 } 530 744 531 532 BS3_DECL(size_t) Bs3PrintF(const char BS3_FAR *pszFormat, ...)533 {534 size_t cchRet;535 va_list va;536 va_start(va, pszFormat);537 cchRet = Bs3PrintFV(pszFormat, va);538 va_end(va);539 return cchRet;540 }541 -
trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-first-rm.asm
r58799 r58809 141 141 extern BS3_CMN_NM(Bs3Shutdown) 142 142 extern NAME(Main_rm) 143 extern _Bs3PrintF_c32144 143 145 144 BS3_BEGIN_SYSTEM16 -
trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-shutdown.c
r58799 r58809 23 23 Bs3PrintStr("\r\n"); 24 24 25 Bs3Print F("Bs3PrintF: RX32=%RX32\n", UINT32_C(0xfdb97531));25 Bs3Printf("Bs3Printf: RX32=%#'RX32 string='%s' d=%d p=%p\n", UINT32_C(0xfdb97531), "my string", 42, Main_rm); 26 26 27 27 pvTmp2 = Bs3MemAlloc(BS3MEMKIND_REAL, _4K); -
trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit.h
r58799 r58809 937 937 938 938 /** 939 * Converts a 64-bit unsigned integer to a string.940 *941 * @returns The length for the formatted string.942 * @param pszDst The destination buffer. Caller is responsible for943 * ensuring sufficient space.944 * @param uValue The 64-bit value.945 * @param uBase The base to format the number in: 2, 8,10 or 16.946 */947 BS3_DECL(size_t) Bs3FormatU64_c16(char BS3_FAR *pszDst, uint64_t uValue, unsigned uBase);948 BS3_DECL(size_t) Bs3FormatU64_c32(char BS3_FAR *pszDst, uint64_t uValue, unsigned uBase); /**< @copydoc Bs3FormatU64_c16 */949 BS3_DECL(size_t) Bs3FormatU64_c64(char BS3_FAR *pszDst, uint64_t uValue, unsigned uBase); /**< @copydoc Bs3FormatU64_c16 */950 #define Bs3FormatU64 BS3_CMN_NM(Bs3FormatU64) /**< Selects #Bs3FormatU64_c16, #Bs3FormatU64_c32 or #Bs3FormatU64_c64. */951 952 /**953 939 * Formats and prints a string to the screen. 954 940 * 955 * @param pszFormat The format string. See #Bs3PrintFV for supported 956 * format types and flags. 941 * See #Bs3StrFormatV_c16 for supported format types. 942 * 943 * @param pszFormat The format string. 957 944 * @param ... Format arguments. 958 945 */ 959 BS3_DECL(size_t) Bs3Print F_c16(const char BS3_FAR *pszFormat, ...);960 BS3_DECL(size_t) Bs3Print F_c32(const char BS3_FAR *pszFormat, ...); /**< @copydoc Bs3PrintF_c16 */961 BS3_DECL(size_t) Bs3Print F_c64(const char BS3_FAR *pszFormat, ...); /**< @copydoc Bs3PrintF_c16 */962 #define Bs3Print F BS3_CMN_NM(Bs3PrintF) /**< Selects #Bs3PrintF_c16, #Bs3PrintF_c32 or #Bs3PrintF_c64. */946 BS3_DECL(size_t) Bs3Printf_c16(const char BS3_FAR *pszFormat, ...); 947 BS3_DECL(size_t) Bs3Printf_c32(const char BS3_FAR *pszFormat, ...); /**< @copydoc Bs3Printf_c16 */ 948 BS3_DECL(size_t) Bs3Printf_c64(const char BS3_FAR *pszFormat, ...); /**< @copydoc Bs3Printf_c16 */ 949 #define Bs3Printf BS3_CMN_NM(Bs3Printf) /**< Selects #Bs3Printf_c16, #Bs3Printf_c32 or #Bs3Printf_c64. */ 963 950 964 951 /** 965 952 * Formats and prints a string to the screen, va_list version. 953 * 954 * See #Bs3Format_c16 for supported format types. 955 * 956 * @param pszFormat The format string. 957 * @param va Format arguments. 958 */ 959 BS3_DECL(size_t) Bs3PrintfV_c16(const char BS3_FAR *pszFormat, va_list va); 960 BS3_DECL(size_t) Bs3PrintfV_c32(const char BS3_FAR *pszFormat, va_list va); /**< @copydoc Bs3PrintfV_c16 */ 961 BS3_DECL(size_t) Bs3PrintfV_c64(const char BS3_FAR *pszFormat, va_list va); /**< @copydoc Bs3PrintfV_c16 */ 962 #define Bs3PrintfV BS3_CMN_NM(Bs3PrintfV) /**< Selects #Bs3PrintfV_c16, #Bs3PrintfV_c32 or #Bs3PrintfV_c64. */ 963 964 /** 965 * Prints a string to the screen. 966 * 967 * @param pszString The string to print. 968 */ 969 BS3_DECL(void) Bs3PrintStr_c16(const char BS3_FAR *pszString); 970 BS3_DECL(void) Bs3PrintStr_c32(const char BS3_FAR *pszString); /**< @copydoc Bs3PrintStr_c16 */ 971 BS3_DECL(void) Bs3PrintStr_c64(const char BS3_FAR *pszString); /**< @copydoc Bs3PrintStr_c16 */ 972 #define Bs3PrintStr BS3_CMN_NM(Bs3PrintStr) /**< Selects #Bs3PrintStr_c16, #Bs3PrintStr_c32 or #Bs3PrintStr_c64. */ 973 974 /** 975 * Prints a char to the screen. 976 * 977 * @param ch The character to print. 978 */ 979 BS3_DECL(void) Bs3PrintChr_c16(char ch); 980 BS3_DECL(void) Bs3PrintChr_c32(char ch); /**< @copydoc Bs3PrintChr_c16 */ 981 BS3_DECL(void) Bs3PrintChr_c64(char ch); /**< @copydoc Bs3PrintChr_c16 */ 982 #define Bs3PrintChr BS3_CMN_NM(Bs3PrintChr) /**< Selects #Bs3PrintChr_c16, #Bs3PrintChr_c32 or #Bs3PrintChr_c64. */ 983 984 985 /** 986 * Pointer to a #Bs3StrFormatV output function. 987 * 988 * @returns Number of characters written. 989 * @param ch The character to write. Zero in the final call. 990 * @param pvUser User argument supplied to #Bs3StrFormatV. 991 */ 992 typedef size_t (BS3_CALL *PFNBS3STRFORMATOUTPUT)(char ch, void *pvUser); 993 994 /** 995 * Formats a string, sending the output to @a pfnOutput. 966 996 * 967 997 * Supported types: … … 976 1006 * - %s (far pointer) 977 1007 * 978 * @param pszFormat The format string. See #Bs3PrintFV for supported 979 * format types and flags. 980 * @param va Format arguments. 981 */ 982 BS3_DECL(size_t) Bs3PrintFV_c16(const char BS3_FAR *pszFormat, va_list va); 983 BS3_DECL(size_t) Bs3PrintFV_c32(const char BS3_FAR *pszFormat, va_list va); /**< @copydoc Bs3PrintFV_c16 */ 984 BS3_DECL(size_t) Bs3PrintFV_c64(const char BS3_FAR *pszFormat, va_list va); /**< @copydoc Bs3PrintFV_c16 */ 985 #define Bs3PrintFV BS3_CMN_NM(Bs3PrintFV) /**< Selects #Bs3PrintFV_c16, #Bs3PrintFV_c32 or #Bs3PrintFV_c64. */ 986 987 /** 988 * Prints a string to the screen. 989 * 990 * @param pszString The string to print. 991 */ 992 BS3_DECL(void) Bs3PrintStr_c16(const char BS3_FAR *pszString); 993 BS3_DECL(void) Bs3PrintStr_c32(const char BS3_FAR *pszString); /**< @copydoc Bs3PrintStr_c16 */ 994 BS3_DECL(void) Bs3PrintStr_c64(const char BS3_FAR *pszString); /**< @copydoc Bs3PrintStr_c16 */ 995 #define Bs3PrintStr BS3_CMN_NM(Bs3PrintStr) /**< Selects #Bs3PrintStr_c16, #Bs3PrintStr_c32 or #Bs3PrintStr_c64. */ 996 997 /** 998 * Prints a char to the screen. 999 * 1000 * @param ch The character to print. 1001 */ 1002 BS3_DECL(void) Bs3PrintChr_c16(char ch); 1003 BS3_DECL(void) Bs3PrintChr_c32(char ch); /**< @copydoc Bs3PrintChr_c16 */ 1004 BS3_DECL(void) Bs3PrintChr_c64(char ch); /**< @copydoc Bs3PrintChr_c16 */ 1005 #define Bs3PrintChr BS3_CMN_NM(Bs3PrintChr) /**< Selects #Bs3PrintChr_c16, #Bs3PrintChr_c32 or #Bs3PrintChr_c64. */ 1008 * @returns Sum of @a pfnOutput return values. 1009 * @param pszFormat The format string. 1010 * @param va Format arguments. 1011 * @param pfnOutput The output function. 1012 * @param pvUser The user argument for the output function. 1013 */ 1014 BS3_DECL(size_t) Bs3StrFormatV_c16(const char BS3_FAR *pszFormat, va_list va, PFNBS3STRFORMATOUTPUT pfnOutput, void *pvUser); 1015 /** @copydoc Bs3StrFormatV_c16 */ 1016 BS3_DECL(size_t) Bs3StrFormatV_c32(const char BS3_FAR *pszFormat, va_list va, PFNBS3STRFORMATOUTPUT pfnOutput, void *pvUser); 1017 /** @copydoc Bs3StrFormatV_c16 */ 1018 BS3_DECL(size_t) Bs3StrFormatV_c64(const char BS3_FAR *pszFormat, va_list va, PFNBS3STRFORMATOUTPUT pfnOutput, void *pvUser); 1019 #define Bs3StrFormatV BS3_CMN_NM(Bs3StrFormatV) /**< Selects #Bs3StrFormatV_c16, #Bs3StrFormatV_c32 or #Bs3StrFormatV_c64. */ 1020 1021 /** 1022 * Formats a string into a buffer. 1023 * 1024 * See #Bs3Format_c16 for supported format types. 1025 * 1026 * @returns The length of the formatted string (excluding terminator). 1027 * This will be higher or equal to @c cbBuf in case of an overflow. 1028 * @param pszBuf The output buffer. 1029 * @param cbBuf The size of the output buffer. 1030 * @param pszFormat The format string. 1031 * @param va Format arguments. 1032 */ 1033 BS3_DECL(size_t) Bs3StrPrintfV_c16(char BS3_FAR *pszBuf, size_t cbBuf, const char BS3_FAR *pszFormat, va_list va); 1034 /** @copydoc Bs3StrPrintfV_c16 */ 1035 BS3_DECL(size_t) Bs3StrPrintfV_c32(char BS3_FAR *pszBuf, size_t cbBuf, const char BS3_FAR *pszFormat, va_list va); 1036 /** @copydoc Bs3StrPrintfV_c16 */ 1037 BS3_DECL(size_t) Bs3StrPrintfV_c64(char BS3_FAR *pszBuf, size_t cbBuf, const char BS3_FAR *pszFormat, va_list va); 1038 #define Bs3StrPrintfV BS3_CMN_NM(Bs3StrPrintfV) /**< Selects #Bs3StrPrintfV_c16, #Bs3StrPrintfV_c32 or #Bs3StrPrintfV_c64. */ 1039 1040 /** 1041 * Formats a string into a buffer. 1042 * 1043 * See #Bs3Format_c16 for supported format types. 1044 * 1045 * @returns The length of the formatted string (excluding terminator). 1046 * This will be higher or equal to @c cbBuf in case of an overflow. 1047 * @param pszBuf The output buffer. 1048 * @param cbBuf The size of the output buffer. 1049 * @param pszFormat The format string. 1050 * @param ... Format arguments. 1051 */ 1052 BS3_DECL(size_t) Bs3StrPrintf_c16(char BS3_FAR *pszBuf, size_t cbBuf, const char BS3_FAR *pszFormat, ...); 1053 /** @copydoc Bs3StrPrintf_c16 */ 1054 BS3_DECL(size_t) Bs3StrPrintf_c32(char BS3_FAR *pszBuf, size_t cbBuf, const char BS3_FAR *pszFormat, ...); 1055 /** @copydoc Bs3StrPrintf_c16 */ 1056 BS3_DECL(size_t) Bs3StrPrintf_c64(char BS3_FAR *pszBuf, size_t cbBuf, const char BS3_FAR *pszFormat, ...); 1057 #define Bs3StrPrintf BS3_CMN_NM(Bs3StrPrintf) /**< Selects #Bs3StrPrintf_c16, #Bs3StrPrintf_c32 or #Bs3StrPrintf_c64. */ 1006 1058 1007 1059
Note:
See TracChangeset
for help on using the changeset viewer.