Adding upstream version 3.61+dfsg.
[syslinux-debian/hramrach.git] / com32 / modules / meminfo.c
blob81678c5cac519fe88b081ea1305c08cbc30157cf
1 /* ----------------------------------------------------------------------- *
3 * Copyright 2008 H. Peter Anvin - All Rights Reserved
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
8 * Boston MA 02110-1301, USA; either version 2 of the License, or
9 * (at your option) any later version; incorporated herein by reference.
11 * ----------------------------------------------------------------------- */
14 * meminfo.c
16 * Dump the memory map of the system
18 #include <inttypes.h>
19 #include <stdio.h>
20 #include <string.h>
21 #include <console.h>
22 #include <com32.h>
24 struct e820_data {
25 uint64_t base;
26 uint64_t len;
27 uint32_t type;
28 } __attribute__((packed));
30 static const char * const e820_types[] = {
31 "usable",
32 "reserved",
33 "ACPI reclaim",
34 "ACPI NVS",
37 static void dump_e820(void)
39 com32sys_t ireg, oreg;
40 struct e820_data ed;
41 uint32_t type;
43 memset(&ireg, 0, sizeof ireg);
45 ireg.eax.w[0] = 0xe820;
46 ireg.edx.l = 0x534d4150;
47 ireg.ecx.l = sizeof(struct e820_data);
48 ireg.edi.w[0] = OFFS(__com32.cs_bounce);
49 ireg.es = SEG(__com32.cs_bounce);
51 do {
52 __intcall(0x15, &ireg, &oreg);
53 if (oreg.eflags.l & EFLAGS_CF ||
54 oreg.eax.l != 0x534d4150)
55 break;
57 memcpy(&ed, __com32.cs_bounce, sizeof ed);
59 /* ebx base length end type */
60 printf("%8x %016llx %016llx %016llx %x",
61 ireg.ebx.l, ed.base, ed.len, ed.base+ed.len, ed.type);
63 type = ed.type - 1;
64 if (type < sizeof(e820_types)/sizeof(e820_types[0]))
65 printf(" %s", e820_types[type]);
67 putchar('\n');
69 ireg.ebx.l = oreg.ebx.l;
70 } while (ireg.ebx.l);
73 static void dump_legacy(void)
75 com32sys_t ireg, oreg;
76 uint16_t dosram = *(uint16_t *)0x413;
77 struct { uint16_t offs, seg; } * const ivt = (void *)0;
79 memset(&ireg, 0, sizeof ireg);
81 __intcall(0x12, &ireg, &oreg);
83 printf("INT 15h = %04x:%04x DOS RAM: %dK (0x%05x) INT 12h: %dK (0x%05x)\n",
84 ivt[0x15].seg, ivt[0x15].offs,
85 dosram, dosram << 10,
86 oreg.eax.w[0], oreg.eax.w[0] << 10);
88 ireg.eax.b[1] = 0x88;
89 __intcall(0x15, &ireg, &oreg);
91 printf("INT 15 88: 0x%04x (%uK) ",
92 oreg.eax.w[0], oreg.eax.w[0]);
94 ireg.eax.w[0] = 0xe801;
95 __intcall(0x15, &ireg, &oreg);
97 printf("INT 15 E801: 0x%04x (%uK) 0x%04x (%uK)\n",
98 oreg.ecx.w[0], oreg.ecx.w[0], oreg.edx.w[0], oreg.edx.w[0] << 6);
101 int main(void)
103 openconsole(&dev_null_r, &dev_stdcon_w);
105 dump_legacy();
106 dump_e820();
108 return 0;