PRINTF(9) BSD Kernel Manual PRINTF(9)
printf, snprintf, vprintf, vsnprintf, uprintf, ttyprintf, db_printf - kernel formatted output conversion
#include <sys/types.h> #include <sys/systm.h> int printf(const char *format, ...); int snprintf(char *buf, size_t size, const char *format, ...); int vprintf(const char *format, va_list ap); int vsnprintf(char *buf, size_t size, const char *fmt, va_list ap); void uprintf(const char *format, ...); void ttyprintf(struct tty *tty, const char *format, ...); void db_printf(const char *format, ...);
The printf(), snprintf(), vprintf(), vsnprintf(), uprintf(), ttyprintf(), and db_printf() functions allow the kernel to send formatted messages to various output devices. The functions printf() and vprintf() send format- ted strings to the system console and to the system log. The functions uprintf() and ttyprintf() send formatted strings to the current process's controlling tty and a specific tty, respectively. The function db_printf() sends formatted strings to the ddb console, and is only used to implement ddb(4). Since each of these kernel functions is a variant of its user space coun- terpart, this page describes only the differences between the user space and kernel versions. Refer to printf(3) for functional details.
The kernel functions don't support any floating point formatting specif- iers. In addition to other formatting specifiers common with the user space functions, the kernel functions accept the following format specif- iers in the format string format: %b Bit field expansion. This format specifier is useful for decoding bit fields in device registers. It displays an integer using a specified radix (base) and an interpretation of the bits within that integer as though they were flags. It requires two arguments from the argument vector, the first argument being the bit field to be decoded (as an integer) and the second being a decoding direc- tive string. The decoding directive string describes how the bitfield is to be interpreted and displayed. The first character of the string is a binary character representation of the output numeral base in which the bitfield will be printed before it is decoded. Recognized radix values (in C escape-character format) are \10 (octal), \12 (decimal), and \20 (hexadecimal). The remaining characters in the decoding directive string are in- terpreted as a list of bit-positiondescription pairs. A bit- positiondescription pair begins with a binary character value that represents the position of the bit being described. A bit position value of one describes the least significant bit. Whereas a posi- tion value of 32 (octal 40, hexadecimal 20, the ASCII space character) describes the most significant bit. The remaining characters in a bit-positiondescription pair are the characters to print should the bit being described be set. Descrip- tion strings are delimited by the next bit position value character encountered (distinguishable by its value being ≤ 32), or the end of the decoding directive string itself. %r Displays an integer using the current DDB radix. This non-standard interpretation of %r is only available to db_printf(). %z Displays a signed integer using the C-style hexadecimal constant format. This format specifier is only available to db_printf().
The printf(), snprintf(), vprintf(), and vsnprintf() functions return the number of characters they placed in the buffer buf.
Use of the %b format specifier for decoding device registers. printf("reg=%b\n", 3, "\10\2BITTWO\1BITONE") "reg=3<BITTWO,BITONE>" printf("enablereg=%b\n", 0xe860, "\20\x10NOTBOOT\x0fFPP\x0eSDVMA\x0cVIDEO" "\x0bLORES\x0aFPA\x09DIAG\x07CACHE" "\x06IOCACHE\x05LOOPBACK\x04DBGCACHE") "enablereg=e860<NOTBOOT,FPP,SDVMA,VIDEO,CACHE,IOCACHE>"
revoke(2), printf(3), ddb(4), log(9)
The %b format specifier cannot be used to decode integers greater than 32 bits in size. MirOS BSD #10-current September 1, 1998 1
Generated on 2013-04-27 00:20:00 by $MirOS: src/scripts/roff2htm,v 1.77 2013/01/01 20:49:09 tg Exp $
These manual pages and other documentation are copyrighted by their respective writers;
their source is available at our CVSweb,
AnonCVS, and other mirrors. The rest is Copyright © 2002‒2013 The MirOS Project, Germany.
This product includes material provided by Thorsten Glaser.
This manual page’s HTML representation is supposed to be valid XHTML/1.1; if not, please send a bug report – diffs preferred.