File: memmap.c

package info (click to toggle)
syslinux 2%3A4.05%2Bdfsg-6%2Bdeb7u1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 25,684 kB
  • sloc: ansic: 276,159; asm: 9,973; pascal: 9,907; perl: 3,492; makefile: 1,736; sh: 626; python: 266; xml: 39
file content (84 lines) | stat: -rw-r--r-- 1,781 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
 * Dump memory map information
 */

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <com32.h>
#include "sysdump.h"

#define E820_CHUNK 128
struct e820_info {
    uint32_t ebx;
    uint32_t len;
    uint8_t  data[24];
};

static void dump_e820(struct upload_backend *be)
{
    com32sys_t ireg, oreg;
    struct e820_info *curr;
    struct e820_info *buf, *p;
    int nentry, nalloc;

    curr = lmalloc(sizeof *curr);

    buf = p = NULL;
    nentry = nalloc = 0;
    memset(&ireg, 0, sizeof ireg);
    memset(&curr, 0, sizeof curr);

    ireg.eax.l = 0xe820;
    ireg.edx.l = 0x534d4150;
    ireg.ecx.l = sizeof curr->data;
    ireg.es = SEG(curr->data);
    ireg.edi.w[0] = OFFS(curr->data);

    do {
	__intcall(0x15, &ireg, &oreg);
	if ((oreg.eflags.l & EFLAGS_CF) ||
	    oreg.eax.l != 0x534d4150)
	    break;

	if (nentry >= nalloc) {
	    nalloc += E820_CHUNK;
	    buf = realloc(buf, nalloc*sizeof *buf);
	    if (!buf)
		return;		/* FAILED */
	}
	memcpy(buf[nentry].data, curr->data, sizeof curr->data);
	buf[nentry].ebx = ireg.ebx.l;
	buf[nentry].len = oreg.ecx.l;
	nentry++;

	ireg.ebx.l = oreg.ebx.l;
    } while (ireg.ebx.l);

    if (nentry)
	cpio_writefile(be, "memmap/15e820", buf, nentry*sizeof *buf);

    free(buf);
    lfree(curr);
}

void dump_memory_map(struct upload_backend *be)
{
    com32sys_t ireg, oreg;

    cpio_mkdir(be, "memmap");

    memset(&ireg, 0, sizeof ireg);
    __intcall(0x12, &ireg, &oreg);
    cpio_writefile(be, "memmap/12", &oreg, sizeof oreg);

    ireg.eax.b[1] = 0x88;
    __intcall(0x15, &ireg, &oreg);
    cpio_writefile(be, "memmap/1588", &oreg, sizeof oreg);

    ireg.eax.w[0] = 0xe801;
    __intcall(0x15, &ireg, &oreg);
    cpio_writefile(be, "memmap/15e801", &oreg, sizeof oreg);

    dump_e820(be);
}