* Test of INT 15:E820 canonicalization/manipulation routine
*/
+#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
{
uint64_t start, len;
uint32_t type;
+ char line[BUFSIZ], *p;
e820map_init();
printranges();
- while ( scanf("%llx %llx %d", &start, &len, &type) == 3 ) {
- putchar('\n');
- printf("%016llx %016llx %d <-\n", start, len, type);
- putchar('\n');
- insertrange(start, len, type);
- printranges();
- }
+ while ( fgets(line, BUFSIZ, stdin) ) {
+ p = strchr(line, ':');
+ p = p ? p+1 : line;
+ if ( sscanf(p, " %llx %llx %d", &start, &len, &type) == 3 ) {
+ putchar('\n');
+ printf("%016llx %016llx %d <-\n", start, len, type);
+ putchar('\n');
+ insertrange(start, len, type);
+ printranges();
+ }
+ }
parse_mem();
typedef uint16_t ush;
typedef uint32_t ulg;
-#define WSIZE 0x8000 /* Window size must be at least 32k, */
+#define WSIZE 0x8000 /* Window size must be at least 32k, */
/* and a power of two */
-static uch *inbuf; /* input buffer */
-static uch window[WSIZE]; /* Sliding window buffer */
+static uch *inbuf; /* input pointer */
+static uch window[WSIZE]; /* sliding output window buffer */
-static unsigned insize; /* valid bytes in inbuf */
-static unsigned inptr; /* index of next byte to be processed in inbuf */
-static unsigned outcnt; /* bytes in output buffer */
+static unsigned insize; /* total input bytes read */
+static unsigned inbytes; /* valid bytes in inbuf */
+static unsigned outcnt; /* bytes in output buffer */
+
+/* This is here to try to debug strange errors seen on some machines. */
+static ulg in_crc; /* crc of input bytes as read */
/* gzip flag byte */
#define ASCII_FLAG 0x01 /* bit 0 set: file probably ASCII text */
#define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */
#define RESERVED 0xC0 /* bit 6,7: reserved */
-#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())
-
/* Diagnostic functions */
#ifdef DEBUG
# define Assert(cond,msg) {if(!(cond)) error(msg);}
static void error(char *m);
static void gzip_mark(void **);
static void gzip_release(void **);
-
+
+extern ulg crc_32_tab[256];
+
+/* Get byte from input buffer */
+static inline uch get_byte(void)
+{
+ if ( inbytes ) {
+ uch b = *inbuf++;
+ inbytes--;
+ in_crc = crc_32_tab[(in_crc ^ b) & 0xff] ^ (in_crc >> 8);
+
+ return b;
+ } else {
+ return fill_inbuf(); /* Input buffer underrun */
+ }
+}
+
static ulg bytes_out = 0; /* Number of bytes output */
static uch *output_data; /* Output data pointer */
static ulg output_size; /* Number of output bytes expected */
{
/* This should never happen. We have already pointed the algorithm
to all the data we have. */
- error("ran out of input data");
- return 0;
+ printf("failed\nDecompression error: ran out of input data, cksum = %lu %u\n",
+ in_crc^0xffffffffUL, insize);
+ die();
}
/* ===========================================================================
out = output_data;
for (n = 0; n < outcnt; n++) {
ch = *out++ = *in++;
- c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
+ c = crc_32_tab[(c ^ ch) & 0xff] ^ (c >> 8);
}
crc = c;
output_data = out;
static void error(char *x)
{
printf("failed\nDecompression error: %s\n", x);
- puts(x);
die();
}
free_mem_end_ptr = free_mem_ptr + 0x10000;
/* Set up input buffer */
+ in_crc = 0xffffffffUL;
inbuf = indata;
- insize = zbytes;
+ insize = inbytes = zbytes;
/* Set up output buffer */
outcnt = 0;