Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/stand/efiboot print_banner: Print memory size like x86 does
details: https://anonhg.NetBSD.org/src/rev/17b4bcf73310
branches: trunk
changeset: 379860:17b4bcf73310
user: jmcneill <jmcneill%NetBSD.org@localhost>
date: Wed Jun 23 00:38:12 2021 +0000
description:
print_banner: Print memory size like x86 does
diffstat:
sys/stand/efiboot/boot.c | 47 +++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 45 insertions(+), 2 deletions(-)
diffs (67 lines):
diff -r 06edf87d8d8f -r 17b4bcf73310 sys/stand/efiboot/boot.c
--- a/sys/stand/efiboot/boot.c Tue Jun 22 21:56:51 2021 +0000
+++ b/sys/stand/efiboot/boot.c Wed Jun 23 00:38:12 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: boot.c,v 1.32 2021/06/21 21:18:47 jmcneill Exp $ */
+/* $NetBSD: boot.c,v 1.33 2021/06/23 00:38:12 jmcneill Exp $ */
/*-
* Copyright (c) 2016 Kimihiro Nonaka <nonaka%netbsd.org@localhost>
@@ -450,13 +450,56 @@ set_bootargs(const char *arg)
return 0;
}
+static void
+get_memory_info(uint64_t *ptotal)
+{
+ EFI_MEMORY_DESCRIPTOR *md, *memmap;
+ UINTN nentries, mapkey, descsize;
+ UINT32 descver;
+ uint64_t totalpg = 0;
+ int n;
+
+ memmap = LibMemoryMap(&nentries, &mapkey, &descsize, &descver);
+ for (n = 0, md = memmap; n < nentries; n++, md = NextMemoryDescriptor(md, descsize)) {
+ if ((md->Attribute & EFI_MEMORY_WB) == 0) {
+ continue;
+ }
+ totalpg += md->NumberOfPages;
+ }
+
+ *ptotal = totalpg * EFI_PAGE_SIZE;
+}
+
+static void
+format_bytes(uint64_t val, uint64_t *pdiv, const char **punit)
+{
+ static const char *units[] = { "KB", "MB", "GB" };
+ unsigned n;
+
+ *punit = "bytes";
+ *pdiv = 1;
+
+ for (n = 0; n < __arraycount(units) && val >= 1024; n++) {
+ *punit = units[n];
+ *pdiv *= 1024;
+ val /= 1024;
+ }
+}
+
void
print_banner(void)
{
+ const char *total_unit;
+ uint64_t total, total_div;
+
+ get_memory_info(&total);
+ format_bytes(total, &total_div, &total_unit);
+
printf(" \\-__,------,___.\n");
printf(" \\ __,---` %s\n", bootprog_name);
printf(" \\ `---,_. Revision %s\n", bootprog_rev);
- printf(" \\-,_____,.---`\n");
+ printf(" \\-,_____,.---` Memory: %" PRIu64 " %s\n",
+ total / total_div, total_unit);
printf(" \\\n");
printf(" \\\n");
printf(" \\\n\n");
Home |
Main Index |
Thread Index |
Old Index