Adding upstream version 4.02+dfsg.
[syslinux-debian/hramrach.git] / com32 / sysdump / memmap.c
blob251107d5e8c1f3202894cffd2bd286f55783674b
1 /*
2 * Dump memory map information
3 */
5 #include <stdio.h>
6 #include <string.h>
7 #include <stdlib.h>
8 #include <com32.h>
9 #include "sysdump.h"
10 #include "backend.h"
12 #define E820_CHUNK 128
13 struct e820_info {
14 uint32_t ebx;
15 uint32_t len;
16 uint8_t data[24];
19 static void dump_e820(struct backend *be)
21 com32sys_t ireg, oreg;
22 struct e820_info *curr;
23 struct e820_info *buf, *p;
24 int nentry, nalloc;
26 curr = lmalloc(sizeof *curr);
28 buf = p = NULL;
29 nentry = nalloc = 0;
30 memset(&ireg, 0, sizeof ireg);
31 memset(&curr, 0, sizeof curr);
33 ireg.eax.l = 0xe820;
34 ireg.edx.l = 0x534d4150;
35 ireg.ecx.l = sizeof curr->data;
36 ireg.es = SEG(curr->data);
37 ireg.edi.w[0] = OFFS(curr->data);
39 do {
40 __intcall(0x15, &ireg, &oreg);
41 if ((oreg.eflags.l & EFLAGS_CF) ||
42 oreg.eax.l != 0x534d4150)
43 break;
45 if (nentry >= nalloc) {
46 nalloc += E820_CHUNK;
47 buf = realloc(buf, nalloc*sizeof *buf);
48 if (!buf)
49 return; /* FAILED */
51 memcpy(buf[nentry].data, curr->data, sizeof curr->data);
52 buf[nentry].ebx = ireg.ebx.l;
53 buf[nentry].len = oreg.ecx.l;
54 nentry++;
56 ireg.ebx.l = oreg.ebx.l;
57 } while (ireg.ebx.l);
59 if (nentry)
60 cpio_writefile(be, "memmap/15e820", buf, nentry*sizeof *buf);
62 free(buf);
63 lfree(curr);
66 void dump_memory_map(struct backend *be)
68 com32sys_t ireg, oreg;
70 cpio_mkdir(be, "memmap");
72 memset(&ireg, 0, sizeof ireg);
73 __intcall(0x12, &ireg, &oreg);
74 cpio_writefile(be, "memmap/12", &oreg, sizeof oreg);
76 ireg.eax.b[1] = 0x88;
77 __intcall(0x15, &ireg, &oreg);
78 cpio_writefile(be, "memmap/1588", &oreg, sizeof oreg);
80 ireg.eax.w[0] = 0xe801;
81 __intcall(0x15, &ireg, &oreg);
82 cpio_writefile(be, "memmap/15e801", &oreg, sizeof oreg);
84 dump_e820(be);