aboutsummaryrefslogtreecommitdiffstats
path: root/memdisk/e820test.c
blob: 2d8be07aa17d4dcc2b4dd196df7d36c7516998a4 (plain)
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
#ident "$Id$"
/* ----------------------------------------------------------------------- *
 *   
 *   Copyright 2001 H. Peter Anvin - All Rights Reserved
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, Inc., 53 Temple Place Ste 330,
 *   Bostom MA 02111-1307, USA; either version 2 of the License, or
 *   (at your option) any later version; incorporated herein by reference.
 *
 * ----------------------------------------------------------------------- */

/*
 * e820hack.c
 *
 * Test of INT 15:E820 canonicalization/manipulation routine
 */

#include <stdio.h>
#include <inttypes.h>
#include "e820.h"

extern void parse_mem(void);
extern uint32_t dos_mem, low_mem, high_mem;

void __attribute__((noreturn)) die(void)
{
  abort();
}

void printranges(void) {
  int i;

  for ( i = 0 ; i < nranges ; i++ ) {
    printf("%016Lx %016Lx %d\n",
	   ranges[i].start,
	   ranges[i+1].start - ranges[i].start,
	   ranges[i].type);
  }
}

int main(int argc, char *argv[])
{
  uint64_t start, len;
  uint32_t type;

  printranges();

  while ( scanf("%Lx %Lx %d", &start, &len, &type) == 3 ) {
    putchar('\n'); 
    printf("%016Lx %016Lx %d <-\n", start, len, type);
    putchar('\n'); 
    insertrange(start, len, type);
    printranges(); 
 }

  parse_mem();

  putchar('\n');
  printf("DOS  mem = %#10x (%u K)\n", dos_mem, dos_mem >> 10);
  printf("Low  mem = %#10x (%u K)\n", low_mem, low_mem >> 10);
  printf("High mem = %#10x (%u K)\n", high_mem, high_mem >> 10);
  putchar('\n');

  /* Now, steal a chunk (2K) of DOS memory and make sure it registered OK */
  insertrange(dos_mem-2048, 2048, 2); /* Type 2 = reserved */
  
  printranges();
  parse_mem();

  putchar('\n');
  printf("DOS  mem = %#10x (%u K)\n", dos_mem, dos_mem >> 10);
  printf("Low  mem = %#10x (%u K)\n", low_mem, low_mem >> 10);
  printf("High mem = %#10x (%u K)\n", high_mem, high_mem >> 10);
  putchar('\n');

  return 0;
}