printf.rst 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. .. SPDX-License-Identifier: GPL-2.0+
  2. Printf() format codes
  3. =====================
  4. Each conversion specification consists of:
  5. * leading '%' character
  6. * zero or more flags
  7. * an optional minimum field width
  8. * an optional precision field preceded by '.'
  9. * an optional length modifier
  10. * a conversion specifier
  11. Flags
  12. -----
  13. 'space'
  14. fill up with spaces to reach the specified length
  15. \-
  16. left justify
  17. \+
  18. add sign field of decimal conversion
  19. #
  20. convert to alternative form
  21. * prepend 0 to octal output
  22. * ignored for decimal output
  23. * prepend 0X to hexadecimal output
  24. 0
  25. fill up with zeroes to reach the specified length
  26. Integer types
  27. -------------
  28. Length modifiers
  29. ''''''''''''''''
  30. The optional length modifier specifies the size of the argument.
  31. no modifier
  32. bool, enum, short, int are passed as int
  33. %h
  34. convert to (unsigned) short before printing.
  35. Only the low 16 bits are printed.
  36. %hh
  37. **not implemented**
  38. %j
  39. **not implemented**
  40. %l
  41. long
  42. %ll, %L
  43. long long
  44. %t
  45. ptr_diff_t
  46. %z, %Z
  47. size_t, ssize_t
  48. Conversion specifiers
  49. '''''''''''''''''''''
  50. Conversion specifiers control the output.
  51. %d
  52. signed decimal
  53. %u
  54. unsigned decimal
  55. %o
  56. unsigned octal
  57. %x
  58. unsigned lower case hexadecimal
  59. %X
  60. unsigned upper case hexadecimal
  61. The floating point conversion specifiers are not implemented:
  62. * %a
  63. * %A
  64. * %e
  65. * %E
  66. * %f
  67. * %F
  68. * %g
  69. * %G
  70. The following tables shows the correct combinations of modifiers and specifiers
  71. for the individual integer types.
  72. =================== ==================
  73. Type Format specifier
  74. =================== ==================
  75. bool %d, %x
  76. char %d, %x
  77. unsigned char %u, %x
  78. short %d, %x
  79. unsigned short %u, %x
  80. int %d, %x
  81. unsigned int %d, %x
  82. long %ld, %lx
  83. unsigned long %lu, %lx
  84. long long %lld, %llx
  85. unsigned long long %llu, %llx
  86. off_t %llu, %llx
  87. ptr_diff_t %td, %tx
  88. fdt_addr_t %pa, see pointers
  89. fdt_size_t %pa, see pointers
  90. phys_addr_t %pa, see pointers
  91. phys_size_t %pa, see pointers
  92. resource_size_t %pa, see pointers
  93. size_t %zu, %zx, %zX
  94. ssize_t %zd, %zx, %zX
  95. =================== ==================
  96. Characters
  97. ----------
  98. %%
  99. a '%' character is written
  100. %c
  101. prints a single character
  102. %lc
  103. **not implemented**
  104. Strings
  105. -------
  106. %s
  107. prints a UTF-8 string (char \*)
  108. %ls
  109. prints a UTF-16 string (u16 \*)
  110. Pointers
  111. --------
  112. %p
  113. prints the address the pointer points to hexadecimally
  114. %pa, %pap
  115. prints the value of a phys_addr_t value that the pointer points to
  116. preceded with 0x and zero padding according to the size of phys_addr_t.
  117. The following types should be printed this way:
  118. * fdt_addr_t
  119. * fdt_size_t
  120. * phys_addr_t
  121. * phys_size_t
  122. * resource_size_t
  123. %pD
  124. prints a UEFI device path
  125. %pi4, %pI4
  126. prints IPv4 address, e.g. '192.168.0.1'
  127. %pm
  128. prints MAC address without separators, e.g. '001122334455'
  129. %pM
  130. print MAC address colon separated, e.g. '00:01:02:03:04:05'
  131. %pUb
  132. prints GUID big endian, lower case
  133. e.g. '00112233-4455-6677-8899-aabbccddeeff'
  134. %pUB
  135. prints GUID big endian, upper case
  136. e.g. '00112233-4455-6677-8899-AABBCCDDEEFF'
  137. %pUl
  138. prints GUID little endian, lower case
  139. e.g. '33221100-5544-7766-8899-aabbccddeeff'
  140. %pUL
  141. prints GUID little endian, upper case
  142. e.g. '33221100-5544-7766-8899-AABBCCDDEEFF'
  143. %pUs
  144. prints text description of a GUID or if such is not known little endian,
  145. lower case, e.g. 'system' for a GUID identifying an EFI system
  146. partition.