rdram2rdp.c
1.14 KB
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
#include <stdio.h>
#include <stdlib.h>
#include <verify.h>
#define LIST_ADDR (VERIFY_INFO_PHYSADDR + RDPLIST_ADDR_OFFSET)
#define COUNT_ADDR (VERIFY_INFO_PHYSADDR + RDPLISTSIZE_OFFSET)
main (int argc, char *argv[])
{
FILE *fp;
int startaddr;
int count;
unsigned char *cp;
unsigned long long int lcount;
if (argc != 2) {
fprintf(stderr, "Usage: %s memory_file\n", argv[0]);
exit(1);
}
if ( (fp = fopen(argv[1], "r")) == NULL) {
fprintf(stderr, "Could not open %s\n", argv[1]);
exit(1);
}
fseek(fp, LIST_ADDR, SEEK_SET);
fread(&startaddr, sizeof (startaddr), 1, fp);
startaddr = ntohl(startaddr);
fseek(fp, COUNT_ADDR, SEEK_SET);
fread(&lcount, sizeof (lcount), 1, fp);
{
int tmp, *x = (int*)&lcount;
tmp = ntohl(x[0]);
x[0] = ntohl(x[1]);
x[1] = tmp;
}
count = (int) lcount;
/* extract only the offset into 2 MB memory */
startaddr &= 0x3fffff;
fprintf(stderr, "start 0x%x, count 0x%x\n", startaddr, count);
cp = (unsigned char *)malloc(count*4);
fseek(fp, startaddr, SEEK_SET);
fread(cp, count, 1, fp);
fwrite(cp, count, 1, stdout);
return 0;
}