summaryrefslogtreecommitdiffstats
path: root/src/util/zbin.c
diff options
context:
space:
mode:
authorMichael Brown2008-10-09 19:02:19 +0200
committerMichael Brown2008-10-10 04:42:08 +0200
commit96ea558e984eb1238a5df9473f1ae298ec0a36c6 (patch)
treebfeafc5e6a16efad16e67526a86d663c6e8db6a3 /src/util/zbin.c
parent[makefile] Split config.h out into config/*.h and kill off mkconfig.pl (diff)
downloadipxe-96ea558e984eb1238a5df9473f1ae298ec0a36c6.tar.gz
ipxe-96ea558e984eb1238a5df9473f1ae298ec0a36c6.tar.xz
ipxe-96ea558e984eb1238a5df9473f1ae298ec0a36c6.zip
[util] Add optional debug messages to zbin.c
Diffstat (limited to 'src/util/zbin.c')
-rw-r--r--src/util/zbin.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/util/zbin.c b/src/util/zbin.c
index b24f401e..c1082b31 100644
--- a/src/util/zbin.c
+++ b/src/util/zbin.c
@@ -6,6 +6,8 @@
#include "nrv2b.c"
FILE *infile, *outfile;
+#define DEBUG 0
+
struct input_file {
void *buf;
size_t len;
@@ -151,6 +153,11 @@ static int process_zinfo_copy ( struct input_file *input,
return -1;
}
+ if ( DEBUG ) {
+ fprintf ( stderr, "COPY [%#zx,%#zx) to [%#zx,%#zx)\n", offset, ( offset + len ),
+ output->len, ( output->len + len ) );
+ }
+
memcpy ( ( output->buf + output->len ),
( input->buf + offset ), len );
output->len += len;
@@ -184,6 +191,11 @@ static int process_zinfo_pack ( struct input_file *input,
return -1;
}
+ if ( DEBUG ) {
+ fprintf ( stderr, "PACK [%#zx,%#zx) to [%#zx,%#zx)\n", offset, ( offset + len ),
+ output->len, ( output->len + packed_len ) );
+ }
+
output->len += packed_len;
if ( output->len > output->max_len ) {
fprintf ( stderr, "Output buffer overrun on pack\n" );
@@ -200,6 +212,8 @@ static int process_zinfo_subtract ( struct input_file *input,
size_t offset = subtract->offset;
void *target;
long delta;
+ unsigned long old;
+ unsigned long new;
if ( ( offset + datasize ) > output->len ) {
fprintf ( stderr, "Subtract at %#zx outside output buffer\n",
@@ -214,21 +228,34 @@ static int process_zinfo_subtract ( struct input_file *input,
switch ( datasize ) {
case 1: {
uint8_t *byte = target;
+ old = *byte;
*byte += delta;
+ new = *byte;
break; }
case 2: {
uint16_t *word = target;
+ old = *word;
*word += delta;
+ new = *word;
break; }
case 4: {
uint32_t *dword = target;
+ old = *dword;
*dword += delta;
+ new = *dword;
break; }
default:
fprintf ( stderr, "Unsupported subtract datasize %d\n",
datasize );
return -1;
}
+
+ if ( DEBUG ) {
+ fprintf ( stderr, "SUBx [%#zx,%#zx) (%#lx+(%#lx/%#lx)-(%#lx/%#lx)) = %#lx\n",
+ offset, ( offset + datasize ), old, output->len, subtract->divisor,
+ input->len, subtract->divisor, new );
+ }
+
return 0;
}