kvm: qemu: add ability to specify ram on command line for bamboo board model
[kvm-userspace.git] / bios / usage.cc
blob409670dfebcd2a626c9a93d0fc89755aab2877a1
1 /////////////////////////////////////////////////////////////////////////
2 // $Id: usage.cc,v 1.4 2003/10/07 01:44:34 danielg4 Exp $
3 /////////////////////////////////////////////////////////////////////////
4 //
5 // Copyright (C) 2001 MandrakeSoft S.A.
6 //
7 // MandrakeSoft S.A.
8 // 43, rue d'Aboukir
9 // 75002 Paris - France
10 // http://www.linux-mandrake.com/
11 // http://www.mandrakesoft.com/
13 // This library is free software; you can redistribute it and/or
14 // modify it under the terms of the GNU Lesser General Public
15 // License as published by the Free Software Foundation; either
16 // version 2 of the License, or (at your option) any later version.
18 // This library is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 // Lesser General Public License for more details.
23 // You should have received a copy of the GNU Lesser General Public
24 // License along with this library; if not, write to the Free Software
25 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include <sys/types.h>
28 #include <sys/stat.h>
29 #include <fcntl.h>
30 #include <stdlib.h>
31 #include <stdio.h>
32 #include <unistd.h>
35 unsigned char bios[65536];
37 int
38 main(int argc, char *argv[])
40 int bios_file;
41 FILE * org_file;
42 unsigned org, last_org, offset;
43 int retval;
44 unsigned int to_read, index;
45 double elements, ratio;
47 if (argc !=3 ) {
48 fprintf(stderr, "Usage: usage bios-file org-file\n");
49 exit(1);
52 bios_file = open(argv[1], O_RDONLY);
53 org_file = fopen(argv[2], "r");
55 if ( (bios_file<0) | (org_file==NULL) ) {
56 fprintf(stderr, "problems opening files.\n");
57 exit(1);
60 printf("files opened OK\n");
62 to_read = 65536;
63 index = 0;
64 while (to_read > 0) {
65 retval = read(bios_file, &bios[index], to_read);
66 if (retval <= 0) {
67 fprintf(stderr, "problem reading bios file\n");
68 exit(1);
70 to_read -= retval;
71 index += retval;
73 printf("bios file read in OK\n");
75 last_org = 0;
77 while (1) {
78 retval = fscanf(org_file, "0x%x\n", &org);
79 if (retval <= 0) break;
80 printf("%04x .. %04x ", last_org, org-1);
81 for (offset=org-1; offset>last_org; offset--) {
82 if (bios[offset] != 0) break;
84 if (offset > last_org) {
85 elements = (1.0 + double(offset) - double(last_org));
87 else {
88 if (bios[last_org] == 0)
89 elements = 0.0;
90 else
91 elements = 1.0;
94 ratio = elements / (double(org) - double(last_org));
95 ratio *= 100.0;
96 printf("%6.2lf\n", ratio);
97 last_org = org;