Adding upstream version 4.00~pre61+dfsg.
[syslinux-debian/hramrach.git] / com32 / hdt / hdt-cli-memory.c
blob51d087e88c5896121406ca92a46b4abeed642b1f
1 /* ----------------------------------------------------------------------- *
3 * Copyright 2009 Pierre-Alexandre Meyer - All Rights Reserved
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without
8 * restriction, including without limitation the rights to use,
9 * copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom
11 * the Software is furnished to do so, subject to the following
12 * conditions:
14 * The above copyright notice and this permission notice shall
15 * be included in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 * OTHER DEALINGS IN THE SOFTWARE.
26 * -----------------------------------------------------------------------
29 #include <memory.h>
31 #include "hdt-cli.h"
32 #include "hdt-common.h"
34 static void show_memory_e820(int argc __unused, char **argv __unused,
35 struct s_hardware *hardware __unused)
37 struct e820entry map[E820MAX];
38 unsigned long memsize = 0;
39 int count = 0;
40 char type[14];
42 detect_memory_e820(map, E820MAX, &count);
43 memsize = memsize_e820(map, count);
44 reset_more_printf();
45 more_printf("Detected RAM : %lu MiB (%lu KiB)\n",
46 (memsize + (1 << 9)) >> 10, memsize);
47 more_printf("BIOS-provided physical RAM e820 map:\n");
48 for (int i = 0; i < count; i++) {
49 get_type(map[i].type, type, 14);
50 more_printf("%016llx - %016llx %016llx (%s)\n",
51 map[i].addr, map[i].size, map[i].addr + map[i].size,
52 remove_spaces(type));
54 struct e820entry nm[E820MAX];
56 /* Clean up, adjust and copy the BIOS-supplied E820-map. */
57 int nr = sanitize_e820_map(map, nm, count);
59 more_printf("\n");
60 more_printf("Sanitized e820 map:\n");
61 for (int i = 0; i < nr; i++) {
62 get_type(nm[i].type, type, 14);
63 more_printf("%016llx - %016llx %016llx (%s)\n",
64 nm[i].addr, nm[i].size, nm[i].addr + nm[i].size,
65 remove_spaces(type));
69 static void show_memory_e801(int argc __unused, char **argv __unused,
70 struct s_hardware *hardware __unused)
72 int mem_low, mem_high = 0;
74 reset_more_printf();
75 if (detect_memory_e801(&mem_low, &mem_high)) {
76 more_printf("e801 bogus!\n");
77 } else {
78 more_printf("Detected RAM : %d MiB(%d KiB)\n",
79 (mem_low >> 10) + (mem_high >> 4),
80 mem_low + (mem_high << 6));
81 more_printf("e801 details : %d Kb (%d MiB) - %d Kb (%d MiB)\n", mem_low,
82 mem_low >> 10, mem_high << 6, mem_high >> 4);
86 static void show_memory_88(int argc __unused, char **argv __unused,
87 struct s_hardware *hardware __unused)
89 int mem_size = 0;
91 reset_more_printf();
92 if (detect_memory_88(&mem_size)) {
93 more_printf("8800h bogus!\n");
94 } else {
95 more_printf("8800h memory size: %d Kb (%d MiB)\n", mem_size,
96 mem_size >> 10);
100 struct cli_callback_descr list_memory_show_modules[] = {
102 .name = "e820",
103 .exec = show_memory_e820,
106 .name = "e801",
107 .exec = show_memory_e801,
110 .name = "88",
111 .exec = show_memory_88,
114 .name = CLI_DMI_MEMORY_BANK,
115 .exec = show_dmi_memory_bank,
118 .name = NULL,
119 .exec = NULL,
123 struct cli_module_descr memory_show_modules = {
124 .modules = list_memory_show_modules,
125 .default_callback = show_dmi_memory_modules,
128 struct cli_mode_descr memory_mode = {
129 .mode = MEMORY_MODE,
130 .name = CLI_MEMORY,
131 .default_modules = NULL,
132 .show_modules = &memory_show_modules,
133 .set_modules = NULL,