Module Name: src
Committed By: jmcneill
Date: Wed Jun 23 00:38:12 UTC 2021
Modified Files:
src/sys/stand/efiboot: boot.c
Log Message:
print_banner: Print memory size like x86 does
To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/sys/stand/efiboot/boot.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/stand/efiboot/boot.c
diff -u src/sys/stand/efiboot/boot.c:1.32 src/sys/stand/efiboot/boot.c:1.33
--- src/sys/stand/efiboot/boot.c:1.32 Mon Jun 21 21:18:47 2021
+++ src/sys/stand/efiboot/boot.c Wed Jun 23 00:38:12 2021
@@ -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 <[email protected]>
@@ -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");