Adding upstream version 6.03~pre2+dfsg.
[syslinux-debian/hramrach.git] / com32 / sysdump / memmap.c
blob48241a7a2f8ef0f8913aa546e0025e1e88c43844
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"
11 #define E820_CHUNK 128
12 struct e820_info {
13 uint32_t ebx;
14 uint32_t len;
15 uint8_t data[24];
18 static void dump_e820(struct upload_backend *be)
20 com32sys_t ireg, oreg;
21 struct e820_info *curr;
22 struct e820_info *buf, *p;
23 int nentry, nalloc;
25 curr = lmalloc(sizeof *curr);
27 buf = p = NULL;
28 nentry = nalloc = 0;
29 memset(&ireg, 0, sizeof ireg);
30 memset(&curr, 0, sizeof curr);
32 ireg.eax.l = 0xe820;
33 ireg.edx.l = 0x534d4150;
34 ireg.ecx.l = sizeof curr->data;
35 ireg.es = SEG(curr->data);
36 ireg.edi.w[0] = OFFS(curr->data);
38 do {
39 __intcall(0x15, &ireg, &oreg);
40 if ((oreg.eflags.l & EFLAGS_CF) ||
41 oreg.eax.l != 0x534d4150)
42 break;
44 if (nentry >= nalloc) {
45 nalloc += E820_CHUNK;
46 buf = realloc(buf, nalloc*sizeof *buf);
47 if (!buf)
48 return; /* FAILED */
50 memcpy(buf[nentry].data, curr->data, sizeof curr->data);
51 buf[nentry].ebx = ireg.ebx.l;
52 buf[nentry].len = oreg.ecx.l;
53 nentry++;
55 ireg.ebx.l = oreg.ebx.l;
56 } while (ireg.ebx.l);
58 if (nentry)
59 cpio_writefile(be, "memmap/15e820", buf, nentry*sizeof *buf);
61 free(buf);
62 lfree(curr);
65 void dump_memory_map(struct upload_backend *be)
67 com32sys_t ireg, oreg;
69 cpio_mkdir(be, "memmap");
71 memset(&ireg, 0, sizeof ireg);
72 __intcall(0x12, &ireg, &oreg);
73 cpio_writefile(be, "memmap/12", &oreg, sizeof oreg);
75 memset(&ireg, 0, sizeof ireg);
76 ireg.eax.b[1] = 0x88;
77 __intcall(0x15, &ireg, &oreg);
78 cpio_writefile(be, "memmap/1588", &oreg, sizeof oreg);
80 memset(&ireg, 0, sizeof ireg);
81 ireg.eax.w[0] = 0xe801;
82 __intcall(0x15, &ireg, &oreg);
83 cpio_writefile(be, "memmap/15e801", &oreg, sizeof oreg);
85 dump_e820(be);