git: f7fd7f8b88a1 - stable/13 - acpidump: add printfield() helper

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Wed, 17 Apr 2024 08:13:43 UTC
The branch stable/13 has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=f7fd7f8b88a15cd70e8d5b471264875d006fcd39

commit f7fd7f8b88a15cd70e8d5b471264875d006fcd39
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2024-04-04 04:49:21 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2024-04-17 08:13:18 +0000

    acpidump: add printfield() helper
    
    (cherry picked from commit 969a4b8be5a7d8edf55bd8945a5a071f57386b0e)
---
 usr.sbin/acpi/acpidump/acpi.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/usr.sbin/acpi/acpidump/acpi.c b/usr.sbin/acpi/acpidump/acpi.c
index 5005c4bbe630..ec7bd65b14c9 100644
--- a/usr.sbin/acpi/acpidump/acpi.c
+++ b/usr.sbin/acpi/acpidump/acpi.c
@@ -156,6 +156,18 @@ printflag(uint64_t var, uint64_t mask, const char *name)
 	}
 }
 
+static void
+printfield(uint64_t var, int lbit, int hbit, const char *name)
+{
+	uint64_t mask;
+	int len;
+
+	len = hbit - lbit + 1;
+	mask = ((1 << (len + 1)) - 1) << lbit;
+	printf("%c%s=%#jx", pf_sep, name, (uintmax_t)((var & mask) >> lbit));
+	pf_sep = ',';
+}
+
 static void
 acpi_print_string(char *s, size_t length)
 {