From nobody Wed Jan 21 12:41:58 2026 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4dx3jf1sx6z6P7y4 for ; Wed, 21 Jan 2026 12:41:58 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R13" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4dx3jf1PJsz3GTW for ; Wed, 21 Jan 2026 12:41:58 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1768999318; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=MaBsZ9LdxQEmS/kV6wgqBQVmU2x7UV4azlwK2+OY1SQ=; b=DYJW99ifOB90fY3CcpQ3sthCpmK5TsLD9yIYd/RbPmQk3HSVAr/qfgIQ6um4AfqfbUu1e+ Ue/x3DIggmjKWKVY3lvAJLq3J76GaBCGD1aDRhVfWFmBf5ywqJI219+mWddsH5qO2c9AOI t2NjwJ5GrBn0zkunAZDSUA4y/hTkOZi8LjfWh9VwpK/DMiQToczO2FdlYasBXpJJLN8KI+ 6Es3+h5Avi1DoYf1HahpjBzojZGQh5QCFGpD0iLZHXwkOYLufQE5gw6b1qDnwRlEUuDhvr 1tVBpcPxycV4RzF8vB2uwDXiZaM7k1VHMKE3an3pymdeOKyzLJ2YcxcqUzZq/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1768999318; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=MaBsZ9LdxQEmS/kV6wgqBQVmU2x7UV4azlwK2+OY1SQ=; b=LKUjyPbvSHlSxuSBhRArgxQqcj9Ws4jYUX+k38FY3z+nzKxOYggIfwKzgHX5jJA/bhRcju HpuC2rKeP3mrFnjjuxNRfZauFSsqi+/2bICyIhhh1ONnPfYl5kzaaIUTLRd5YjkmLzjHNn vOnbdGIEBFyKsCBJlUMk3PqyfMTssDbgziwgiulrPnmJIVCsLT47GimAHaBg2LMeKzgED2 B9q021fEgBIfDu72igPuLoV+RHC+X4LX/ds/1Qbm5/t2cnVsWaEQGDbtWxflzLV2ijTPGm EGIsevtXXz4sg1OeOLir0XfP4tSdW38NtAY3bRJiLF2zKh69XW6kNptWLofhMA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1768999318; a=rsa-sha256; cv=none; b=jzohtVLYDqK4Ce1epETHL+dwKVbPpxQzEhFyf+3BokssDAdBQ4sDSMridxMm8JOt/V4hNb Lum0RSbVxSsj5W7KHCdtKBEvZyJkY5OjJXSlJ9ico3f9BW08d4A4B7170ew+/N4tJbVos7 Hv+GOEqTod0cEbPi4u13fWcccSa2U1/HXalKnMCHhsd2QQoIzs7MwCFae0Ag/P7tnB4ihR GVT61iB92Ctd5MiodJESK86RUDno7HCVCi5BT6JaNjKNSkmfpOl2IE85mvgZA/irAlp1lq Kbn6o/5LjFDazhDxJybTdX2qNqrXU20lxeik0d1+9Ef/uzzq17S7J04crtHqpg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4dx3jf0tD8zpDD for ; Wed, 21 Jan 2026 12:41:58 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 86cb by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Wed, 21 Jan 2026 12:41:58 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Michael Tuexen Subject: git: 39140d9d9a27 - stable/14 - printf.9: Support more than 32 bits in %b List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: tuexen X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 39140d9d9a27884b5941107abe3ddf92751d41b5 Auto-Submitted: auto-generated Date: Wed, 21 Jan 2026 12:41:58 +0000 Message-Id: <6970c996.86cb.87a0bf7@gitrepo.freebsd.org> The branch stable/14 has been updated by tuexen: URL: https://cgit.FreeBSD.org/src/commit/?id=39140d9d9a27884b5941107abe3ddf92751d41b5 commit 39140d9d9a27884b5941107abe3ddf92751d41b5 Author: Michael Tuexen AuthorDate: 2025-12-19 16:26:37 +0000 Commit: Michael Tuexen CommitDate: 2026-01-21 12:40:05 +0000 printf.9: Support more than 32 bits in %b This will be usable after clang has been extended to accept length modifiers for %b when compiling kernel code. But we need FreeBSD to support it first... Reviewed by: markj, Timo Völker Differential Revision: https://reviews.freebsd.org/D54286 (cherry picked from commit d2cb9cab8457b2a84898f0ac86f7b45e907f872c) --- share/man/man9/printf.9 | 25 ++++++++++++++++++------- sys/kern/subr_prf.c | 40 +++++++++++++++++++++++++++++++--------- 2 files changed, 49 insertions(+), 16 deletions(-) diff --git a/share/man/man9/printf.9 b/share/man/man9/printf.9 index 8006590b3d2a..5c819acbec09 100644 --- a/share/man/man9/printf.9 +++ b/share/man/man9/printf.9 @@ -24,7 +24,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd December 18, 2025 +.Dd December 19, 2025 .Dt PRINTF 9 .Os .Sh NAME @@ -95,14 +95,15 @@ arguments. The base value is the output base (radix) expressed as an octal value; for example, \e10 gives octal and \e20 gives hexadecimal. The arguments are made up of a sequence of bit identifiers. -Each bit identifier begins with an -.Em octal -value which is the number of the bit (starting from 1) this identifier -describes. +Each bit identifier begins with a character specifying the number of the bit +(starting from 1) this identifier describes. +The characters from \e01 to \e40 can be used to specify bit numbers in the +range from 1 to 32 and characters from \e200 to \e377 to specify bit numbers +in the range from 1 to 128. The rest of the identifier is a string of characters containing the name of the bit. -The string is terminated by either the bit number at the start of the next -bit identifier or +The identifier is terminated by either the bit number at the start of the next +bit identifier or by .Dv NUL for the last bit identifier. .Pp @@ -173,6 +174,16 @@ reg=3 out: 41:41:5a:5a .Ed .Pp +The same output will be generated by the following function: +.Bd -literal -offset indent +void +printf_test(void) +{ + printf("reg=%b\en", 3, "\e10\e201BITTWO\e200BITONE"); + printf("out: %4D\en", "AAZZ", ":"); +} +.Ed +.Pp The call .Bd -literal -offset indent log(LOG_DEBUG, "%s%d: been there.\en", sc->sc_name, sc->sc_unit); diff --git a/sys/kern/subr_prf.c b/sys/kern/subr_prf.c index 60040a085162..23e51d7f456b 100644 --- a/sys/kern/subr_prf.c +++ b/sys/kern/subr_prf.c @@ -624,6 +624,18 @@ ksprintn(char *nbuf, uintmax_t num, int base, int *lenp, int upper) return (p); } +static inline bool +isbitpos(char c) +{ + return (c != '\0' && (c <= ' ' || (c & 0x80) != 0)); +} + +static inline bool +isprintnospace(char c) +{ + return (isprint(c) && c != ' '); +} + /* * Scaled down version of printf(3). * @@ -636,9 +648,12 @@ ksprintn(char *nbuf, uintmax_t num, int base, int *lenp, int upper) * * where is the output base expressed as a control character, e.g. * \10 gives octal; \20 gives hex. Each arg is a sequence of characters, - * the first of which gives the bit number to be inspected (origin 1), and - * the next characters (up to a control character, i.e. a character <= 32), - * give the name of the register. Thus: + * the first of which gives the bit number to be inspected and the next + * characters (up to the bit number of the next argument or a final NUL + * character), give the name of the register. + * The bit number can be encoded as a character between 1 and 32 or as a + * character between 128 and 255. + * Thus: * * kvprintf("reg=%b\n", 3, "\10\2BITTWO\1BITONE"); * @@ -646,6 +661,10 @@ ksprintn(char *nbuf, uintmax_t num, int base, int *lenp, int upper) * * reg=3 * + * The same output would be generated by using: + * + * kvprintf("reg=%b\n", 3, "\10\201BITTWO\200BITONE"); + * * XXX: %D -- Hexdump, takes pointer and separator string: * ("%6D", ptr, ":") -> XX:XX:XX:XX:XX:XX * ("%*D", len, ptr, " " -> XX XX XX XX ... @@ -947,15 +966,18 @@ number: if (bconv && num != 0) { /* %b conversion flag format. */ tmp = retval; - while (*q) { - n = *q++; - if (num & (1 << (n - 1))) { + while (isbitpos(*q)) { + if ((*q & 0x80) != 0) + n = *q++ & 0x7f; + else + n = *q++ - 1; + if (num & (1ULL << n)) { PCHAR(retval != tmp ? ',' : '<'); - for (; (n = *q) > ' '; ++q) - PCHAR(n); + for (; isprintnospace(*q); ++q) + PCHAR(*q); } else - for (; *q > ' '; ++q) + for (; isprintnospace(*q); ++q) continue; } if (retval != tmp) {