• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* ----------------------------------------------------------------------- *
2  *
3  *   Copyright 2001-2008 H. Peter Anvin - All Rights Reserved
4  *
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., 53 Temple Place Ste 330,
8  *   Boston MA 02111-1307, USA; either version 2 of the License, or
9  *   (at your option) any later version; incorporated herein by reference.
10  *
11  * ----------------------------------------------------------------------- */
12 
13 /*
14  * e820hack.c
15  *
16  * Test of INT 15:E820 canonicalization/manipulation routine
17  */
18 
19 #include <string.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <inttypes.h>
23 #include "e820.h"
24 
25 void *sys_bounce;		/* Dummy */
26 
27 extern void parse_mem(void);
28 extern uint32_t dos_mem, low_mem, high_mem;
29 
die(void)30 void __attribute__ ((noreturn)) die(void)
31 {
32     abort();
33 }
34 
printranges(void)35 void printranges(void)
36 {
37     int i;
38 
39     for (i = 0; i < nranges; i++) {
40 	printf("%016llx %016llx %d\n",
41 	       ranges[i].start,
42 	       ranges[i + 1].start - ranges[i].start, ranges[i].type);
43     }
44 }
45 
main(void)46 int main(void)
47 {
48     uint64_t start, len;
49     uint32_t type;
50     char line[BUFSIZ], *p;
51 
52     e820map_init();
53     printranges();
54 
55     while (fgets(line, BUFSIZ, stdin)) {
56 	p = strchr(line, ':');
57 	p = p ? p + 1 : line;
58 	if (sscanf(p, " %llx %llx %d", &start, &len, &type) == 3) {
59 	    putchar('\n');
60 	    printf("%016llx %016llx %d <-\n", start, len, type);
61 	    putchar('\n');
62 	    insertrange(start, len, type);
63 	    printranges();
64 	}
65     }
66 
67     parse_mem();
68 
69     putchar('\n');
70     printf("DOS  mem = %#10x (%u K)\n", dos_mem, dos_mem >> 10);
71     printf("Low  mem = %#10x (%u K)\n", low_mem, low_mem >> 10);
72     printf("High mem = %#10x (%u K)\n", high_mem, high_mem >> 10);
73     putchar('\n');
74 
75     /* Now, steal a chunk (2K) of DOS memory and make sure it registered OK */
76     insertrange(dos_mem - 2048, 2048, 2, 1);	/* Type 2 = reserved */
77 
78     printranges();
79     parse_mem();
80 
81     putchar('\n');
82     printf("DOS  mem = %#10x (%u K)\n", dos_mem, dos_mem >> 10);
83     printf("Low  mem = %#10x (%u K)\n", low_mem, low_mem >> 10);
84     printf("High mem = %#10x (%u K)\n", high_mem, high_mem >> 10);
85     putchar('\n');
86 
87     return 0;
88 }
89