File: mklkcd.c

package info (click to toggle)
libkdumpfile 0.5.5-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,156 kB
  • sloc: ansic: 36,541; sh: 4,219; python: 1,569; makefile: 812
file content (730 lines) | stat: -rw-r--r-- 16,275 bytes parent folder | download | duplicates (3)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
/* LKCD format test suite.
   Copyright (C) 2016 Petr Tesarik <ptesarik@suse.com>

   This file is free software; you can redistribute it and/or modify
   it under the terms of either

     * the GNU Lesser General Public License as published by the Free
       Software Foundation; either version 3 of the License, or (at
       your option) any later version

   or

     * the GNU General Public License as published by the Free
       Software Foundation; either version 2 of the License, or (at
       your option) any later version

   or both in parallel, as here.

   libkdumpfile is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received copies of the GNU General Public License and
   the GNU Lesser General Public License along with this program.  If
   not, see <http://www.gnu.org/licenses/>.
*/

#include <string.h>
#include <endian.h>
#include <sys/time.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

#include "config.h"
#include "testutil.h"
#include "lkcd.h"

#if USE_ZLIB
# include <zlib.h>
#endif

#define DUMP_VERSION_NUMBER  9

typedef int write_fn(FILE *);

struct page_data_lkcd {
	FILE *f;

	unsigned long long addr;
	unsigned long flags;
	enum {
		compress_auto = -1,
		compress_no,
		compress_yes,
	} compress;

	void *cbuf;
	size_t cbufsz;

	unsigned long skip;
};

static endian_t be;
static write_fn *writeheader_asm;

static char *arch_name;
static unsigned long long page_shift;
static unsigned long long page_offset;
static unsigned long long dump_level = DUMP_LEVEL_KERN;
static char *panic_string;
static unsigned long long compression = DUMP_COMPRESS_NONE;
static unsigned long long buffer_size = (256*1024);

static char *uts_sysname;
static char *uts_nodename;
static char *uts_release;
static char *uts_version;
static char *uts_machine;
static char *uts_domainname;

static unsigned long long NR_CPUS;
static unsigned long long num_cpus;
static struct number_array current_task;
static struct number_array stack;
static struct number_array stack_ptr;

static unsigned long num_dump_pages;

static char *data_file;

static const struct param param_array[] = {
	PARAM_STRING("arch_name", arch_name),
	PARAM_NUMBER("page_shift", page_shift),
	PARAM_NUMBER("page_offset", page_offset),
	PARAM_NUMBER("dump_level", dump_level),
	PARAM_STRING("panic_string", panic_string),
	PARAM_NUMBER("compression", compression),
	PARAM_NUMBER("buffer_size", buffer_size),

	PARAM_STRING("uts.sysname", uts_sysname),
	PARAM_STRING("uts.nodename", uts_nodename),
	PARAM_STRING("uts.release", uts_release),
	PARAM_STRING("uts.version", uts_version),
	PARAM_STRING("uts.machine", uts_machine),
	PARAM_STRING("uts.domainname", uts_domainname),

	PARAM_NUMBER("NR_CPUS", NR_CPUS),
	PARAM_NUMBER("num_cpus", num_cpus),
	PARAM_NUMBER_ARRAY("current_task", current_task),
	PARAM_NUMBER_ARRAY("stack", stack),
	PARAM_NUMBER_ARRAY("stak_ptr", stack_ptr),

	PARAM_STRING("DATA", data_file)
};

static const struct params params = {
	ARRAY_SIZE(param_array),
	param_array
};

static int
set_default_params(void)
{
	arch_name = strdup("x86_64");
	if (!arch_name)
		return TEST_ERR;

	panic_string = strdup("");
	if (!panic_string)
		return TEST_ERR;

	uts_sysname = strdup("Linux");
	if (!uts_sysname)
		return TEST_ERR;

	uts_nodename = strdup("");
	if (!uts_nodename)
		return TEST_ERR;

	uts_release = strdup("0.0.0");
	if (!uts_release)
		return TEST_ERR;

	uts_version = strdup("#1");
	if (!uts_version)
		return TEST_ERR;

	uts_machine = strdup("x86_64");
	if (!uts_machine)
		return TEST_ERR;

	uts_domainname = strdup("(none)");
	if (!uts_domainname)
		return TEST_ERR;

	return TEST_OK;
}

static int
writeheader(FILE *f)
{
	struct timeval tv;
	struct dump_header hdr;

	if (gettimeofday(&tv, NULL) != 0) {
		perror("gettimeofday");
		return -1;
	}

	/* initialize dump header to zero */
	memset(&hdr, 0, sizeof hdr);

	/* configure dump header values */
	hdr.dh_magic_number = htodump64(be, DUMP_MAGIC_NUMBER);
	hdr.dh_version = htodump32(be, DUMP_VERSION_NUMBER);
	hdr.dh_header_size = htodump32(be, sizeof hdr);
	hdr.dh_dump_level = htodump32(be, dump_level);
	hdr.dh_page_size = htodump32(be, 1UL << page_shift);
	hdr.dh_memory_size = htodump64(be, 0);
	hdr.dh_memory_start = htodump64(be, page_offset);
	hdr.dh_memory_end = htodump64(be, DUMP_MAGIC_NUMBER); /* sic! */
	hdr.dh_num_dump_pages = htodump32(be, num_dump_pages);
	strncpy(hdr.dh_panic_string, panic_string,
		sizeof hdr.dh_panic_string);
	hdr.dh_time.tv_sec = htodump64(be, tv.tv_sec);
	hdr.dh_time.tv_usec = htodump64(be, tv.tv_usec);
	strncpy(hdr.dh_utsname_sysname, uts_sysname,
		sizeof hdr.dh_utsname_sysname);
	strncpy(hdr.dh_utsname_nodename, uts_nodename,
		sizeof hdr.dh_utsname_nodename);
	strncpy(hdr.dh_utsname_release, uts_release,
		sizeof hdr.dh_utsname_release);
	strncpy(hdr.dh_utsname_version, uts_version,
		sizeof hdr.dh_utsname_version);
	strncpy(hdr.dh_utsname_machine, uts_machine,
		sizeof hdr.dh_utsname_machine);
	strncpy(hdr.dh_utsname_domainname, uts_domainname,
		sizeof hdr.dh_utsname_domainname);
	if (current_task.n > 0)
		hdr.dh_current_task = htodump64(be, current_task.val[0]);
	hdr.dh_dump_compress = htodump32(be, compression);
	hdr.dh_dump_buffer_size = htodump64(be, buffer_size);

	if (fseeko(f, 0, SEEK_SET) != 0) {
		perror("seek header");
		return -1;
	}

	if (fwrite(&hdr, sizeof hdr, 1, f) != 1) {
		perror("write header");
		return -1;
	}

	return writeheader_asm(f);
}

static int
writeheader_asm_x86_64(FILE *f)
{
	struct dump_header_asm_x86_64 asmhdr;
	size_t sz;
	off_t off;
	unsigned i;

	memset(&asmhdr, 0, sizeof asmhdr);
	asmhdr.dha_magic_number = htodump64(be, DUMP_ASM_MAGIC_NUMBER_X86_64);
	asmhdr.dha_version = htodump32(be, DUMP_ASM_VERSION_NUMBER_X86_64);
	sz = sizeof asmhdr +
		NR_CPUS * sizeof(struct pt_regs_x86_64) + /* dha_smp_regs */
		NR_CPUS * sizeof(uint64_t) + /* dha_smp_current_task */
		NR_CPUS * sizeof(uint64_t) + /* dha_stack */
		NR_CPUS * sizeof(uint64_t);  /* dha_stack_ptr */
	asmhdr.dha_header_size = htodump32(be, sz);

	asmhdr.dha_smp_num_cpus = htodump32(be, num_cpus);
	asmhdr.dha_dumping_cpu = htodump32(be, 0);

	if (fwrite(&asmhdr, sizeof asmhdr, 1, f) != 1) {
		perror("write asm header");
		return -1;
	}

	off = NR_CPUS * sizeof(struct pt_regs_x86_64);

	if (fseeko(f, off, SEEK_CUR) != 0) {
		perror("seek dha_smp_current_task");
		return -1;
	}
	for (i = 0; i < current_task.n; ++i) {
		uint64_t tmp = htodump64(be, current_task.val[i]);
		if (fwrite(&tmp, sizeof tmp, 1, f) != 1) {
			perror("write dha_smp_current_task");
			return -1;
		}
	}
	off = (NR_CPUS - current_task.n) * sizeof(uint64_t);

	if (fseeko(f, off, SEEK_CUR) != 0) {
		perror("seek dha_stack");
		return -1;
	}
	for (i = 0; i < stack.n; ++i) {
		uint64_t tmp = htodump64(be, stack.val[i]);
		if (fwrite(&tmp, sizeof tmp, 1, f) != 1) {
			perror("write dha_task");
			return -1;
		}
	}
	off = (NR_CPUS - stack.n) * sizeof(uint64_t);

	if (fseeko(f, off, SEEK_CUR) != 0) {
		perror("seek dha_stack_ptr");
		return -1;
	}
	for (i = 0; i < stack_ptr.n; ++i) {
		uint64_t tmp = htodump64(be, stack_ptr.val[i]);
		if (fwrite(&tmp, sizeof tmp, 1, f) != 1) {
			perror("write dha_task");
			return -1;
		}
	}

	return 0;
}

static int
writeheader_asm_ia32(FILE *f)
{
	struct dump_header_asm_ia32 asmhdr;
	size_t sz;
	off_t off;
	unsigned i;

	memset(&asmhdr, 0, sizeof asmhdr);
	asmhdr.dha_magic_number = htodump64(be, DUMP_ASM_MAGIC_NUMBER_IA32);
	asmhdr.dha_version = htodump32(be, DUMP_ASM_VERSION_NUMBER_IA32);
	sz = sizeof asmhdr +
		NR_CPUS * sizeof(struct pt_regs_ia32) + /* dha_smp_regs */
		NR_CPUS * sizeof(uint32_t) + /* dha_smp_current_task */
		NR_CPUS * sizeof(uint32_t) + /* dha_stack */
		NR_CPUS * sizeof(uint32_t);  /* dha_stack_ptr */
	asmhdr.dha_header_size = htodump32(be, sz);

	asmhdr.dha_smp_num_cpus = htodump32(be, num_cpus);
	asmhdr.dha_dumping_cpu = htodump32(be, 0);

	if (fwrite(&asmhdr, sizeof asmhdr, 1, f) != 1) {
		perror("write asm header");
		return -1;
	}

	off = NR_CPUS * sizeof(struct pt_regs_ia32);

	if (fseeko(f, off, SEEK_CUR) != 0) {
		perror("seek dha_smp_current_task");
		return -1;
	}
	for (i = 0; i < current_task.n; ++i) {
		uint32_t tmp = htodump32(be, current_task.val[i]);
		if (fwrite(&tmp, sizeof tmp, 1, f) != 1) {
			perror("write dha_smp_current_task");
			return -1;
		}
	}
	off = (NR_CPUS - current_task.n) * sizeof(uint32_t);

	if (fseeko(f, off, SEEK_CUR) != 0) {
		perror("seek dha_stack");
		return -1;
	}
	for (i = 0; i < stack.n; ++i) {
		uint32_t tmp = htodump32(be, stack.val[i]);
		if (fwrite(&tmp, sizeof tmp, 1, f) != 1) {
			perror("write dha_task");
			return -1;
		}
	}
	off = (NR_CPUS - stack.n) * sizeof(uint32_t);

	if (fseeko(f, off, SEEK_CUR) != 0) {
		perror("seek dha_stack_ptr");
		return -1;
	}
	for (i = 0; i < stack_ptr.n; ++i) {
		uint32_t tmp = htodump32(be, stack_ptr.val[i]);
		if (fwrite(&tmp, sizeof tmp, 1, f) != 1) {
			perror("write dha_task");
			return -1;
		}
	}

	return 0;
}

static int
writeheader_asm_ppc64(FILE *f)
{
	struct dump_header_asm_ppc64 asmhdr;
	size_t sz;
	off_t off;
	unsigned i;

	memset(&asmhdr, 0, sizeof asmhdr);
	asmhdr.dha_magic_number = htodump64(be, DUMP_ASM_MAGIC_NUMBER_PPC64);
	asmhdr.dha_version = htodump32(be, DUMP_ASM_VERSION_NUMBER_PPC64);
	sz = sizeof asmhdr +
		NR_CPUS * sizeof(struct pt_regs_ppc64) + /* dha_smp_regs */
		NR_CPUS * sizeof(uint64_t) + /* dha_smp_current_task */
		NR_CPUS * sizeof(uint64_t) + /* dha_stack */
		NR_CPUS * sizeof(uint64_t);  /* dha_stack_ptr */
	asmhdr.dha_header_size = htodump32(be, sz);

	asmhdr.dha_smp_num_cpus = htodump32(be, num_cpus);
	asmhdr.dha_dumping_cpu = htodump32(be, 0);

	if (fwrite(&asmhdr, sizeof asmhdr, 1, f) != 1) {
		perror("write asm header");
		return -1;
	}

	off = NR_CPUS * sizeof(struct pt_regs_ppc64);

	if (fseeko(f, off, SEEK_CUR) != 0) {
		perror("seek dha_smp_current_task");
		return -1;
	}
	for (i = 0; i < current_task.n; ++i) {
		uint64_t tmp = htodump64(be, current_task.val[i]);
		if (fwrite(&tmp, sizeof tmp, 1, f) != 1) {
			perror("write dha_smp_current_task");
			return -1;
		}
	}
	off = (NR_CPUS - current_task.n) * sizeof(uint64_t);

	if (fseeko(f, off, SEEK_CUR) != 0) {
		perror("seek dha_stack");
		return -1;
	}
	for (i = 0; i < stack.n; ++i) {
		uint64_t tmp = htodump64(be, stack.val[i]);
		if (fwrite(&tmp, sizeof tmp, 1, f) != 1) {
			perror("write dha_task");
			return -1;
		}
	}
	off = (NR_CPUS - stack.n) * sizeof(uint64_t);

	if (fseeko(f, off, SEEK_CUR) != 0) {
		perror("seek dha_stack_ptr");
		return -1;
	}
	for (i = 0; i < stack_ptr.n; ++i) {
		uint64_t tmp = htodump64(be, stack_ptr.val[i]);
		if (fwrite(&tmp, sizeof tmp, 1, f) != 1) {
			perror("write dha_task");
			return -1;
		}
	}

	return 0;
}

static int
parseheader(struct page_data *pg, char *p)
{
	struct page_data_lkcd *pglkcd = pg->priv;
	char *endp;

	if (!*p) {
		pglkcd->addr += 1ULL << page_shift;
		return TEST_OK;
	}

	pglkcd->addr = strtoull(p, &endp, 0);
	if (*endp && !isspace(*endp)) {
		*endp = '\0';
		fprintf(stderr, "Invalid address: %s\n", p);
		return TEST_FAIL;
	}

	pglkcd->flags = 0;
	pglkcd->compress = compress_auto;
	pglkcd->skip = 0;

	p = endp;
	while (*p && isspace(*p))
		++p;

	if (!strncmp(p, "skip=", 5)) {
		p += 5;
		pglkcd->skip = strtoul(p, &endp, 0);
		if (*endp && !isspace(*endp)) {
			fprintf(stderr, "Invalid skip: %s\n", p);
			return TEST_FAIL;
		}
		p = endp;
		while (*p && isspace(*p))
			++p;
	}

	if (!*p)
		return TEST_OK;

	if (!strcmp(p, "raw")) {
		pglkcd->flags |= DUMP_DH_RAW;
		pglkcd->compress = compress_no;
	} else if (!strcmp(p, "compress")) {
		pglkcd->flags |= DUMP_DH_COMPRESSED;
		pglkcd->compress = compress_yes;
	} else if (!strcmp(p, "end")) {
		pglkcd->flags |= DUMP_DH_END;
	} else {
		pglkcd->flags = strtoul(p, &endp, 0);
		if (*endp) {
			fprintf(stderr, "Invalid flags: %s\n", p);
			return TEST_FAIL;
		}
	}

	return TEST_OK;
}

static size_t
do_rle(struct page_data *pg)
{
	struct page_data_lkcd *pglkcd = pg->priv;
	size_t clen;

	clen = pglkcd->cbufsz;
	while (compress_rle(pglkcd->cbuf, &clen, pg->buf, pg->len)) {
		unsigned char *newbuf;

		clen = pglkcd->cbufsz + (1UL << (page_shift-2));
		newbuf = realloc(pglkcd->cbuf, clen);
		if (!newbuf) {
			perror("Cannot allocate compression buffer");
			return 0;
		}
		pglkcd->cbuf = newbuf;
		pglkcd->cbufsz = clen;
	}
	return clen;
}

#if USE_ZLIB
static size_t
do_gzip(struct page_data *pg)
{
	struct page_data_lkcd *pglkcd = pg->priv;
	uLongf clen;

	clen = pglkcd->cbufsz;
	while (compress(pglkcd->cbuf, &clen, pg->buf, pg->len) != Z_OK) {
		unsigned char *newbuf;

		clen = pglkcd->cbufsz + (1UL << (page_shift-2));
		newbuf = realloc(pglkcd->cbuf, clen);
		if (!newbuf) {
			perror("Cannot allocate compression buffer");
			return 0;
		}
		pglkcd->cbuf = newbuf;
		pglkcd->cbufsz = clen;
	}
	return clen;
}
#endif

static size_t
compresspage(struct page_data *pg)
{
	switch (compression) {
	case DUMP_COMPRESS_RLE:
		return do_rle(pg);

#if USE_ZLIB
	case DUMP_COMPRESS_GZIP:
		return do_gzip(pg);
#endif

	default:
		fprintf(stderr, "Unsupported compression method: %llu\n",
			compression);
	}

	return 0;
}

static int
writepage(struct page_data *pg)
{
	struct page_data_lkcd *pglkcd = pg->priv;
	struct dump_page dp;
	unsigned char *buf;
	size_t buflen;
	uint32_t flags;

	flags = pglkcd->flags;

	if (pg->len && compression != DUMP_COMPRESS_NONE &&
	    pglkcd->compress != compress_no) {
		buflen = compresspage(pg);
		if (!buflen)
			return TEST_ERR;
		buf = pglkcd->cbuf;

		if (pglkcd->compress == compress_auto) {
			if (buflen >= pg->len) {
				buflen = pg->len;
				buf = pg->buf;
				flags &= ~DUMP_DH_COMPRESSED;
				flags |= DUMP_DH_RAW;
			} else {
				flags &= ~DUMP_DH_RAW;
				flags |= DUMP_DH_COMPRESSED;
			}
		}
	} else {
		buflen = pg->len;
		buf = pg->buf;
	}
	dp.dp_address = htodump64(be, pglkcd->addr);
	dp.dp_size = htodump32(be, buflen + pglkcd->skip);
	dp.dp_flags = htodump32(be, flags);

	if (fwrite(&dp, sizeof dp, 1, pglkcd->f) != 1) {
		perror("write page desc");
		return TEST_ERR;
	}

	if (fwrite(buf, 1, buflen, pglkcd->f) != buflen) {
		perror("write page data");
		return TEST_ERR;
	}

	if (pglkcd->skip &&
	    fseeko(pglkcd->f, pglkcd->skip, SEEK_CUR) != 0) {
		perror("skip page data");
		return TEST_ERR;
	}

	return TEST_OK;
}

static int
writedata(FILE *f)
{
	struct page_data_lkcd pglkcd;
	struct page_data pg;
	int rc;

	if (!data_file)
		return TEST_OK;

	if (fseeko(f, buffer_size, SEEK_SET) != 0) {
		perror("seek data");
		return TEST_ERR;
	}

	printf("Creating page data\n");

	pglkcd.f = f;
	pglkcd.addr = 0;
	pglkcd.flags = 0;
	pglkcd.cbuf = NULL;
	pglkcd.cbufsz = 0;

	pg.endian = be;
	pg.priv = &pglkcd;
	pg.parse_hdr = parseheader;
	pg.write_page = writepage;

	rc = process_data(&pg, data_file);

	if (pglkcd.cbuf)
		free(pglkcd.cbuf);

	return rc;
}

static int
writedump(FILE *f)
{
	int rc;

	rc = writedata(f);
	if (rc != 0)
		return rc;

	rc = writeheader(f);
	if (rc != 0)
		return rc;

	return 0;
}

static int
create_file(const char *name)
{
	FILE *f;
	int rc;

	f = fopen(name, "w");
	if (!f) {
		perror("Cannot create output");
		return TEST_ERR;
	}

	rc = writedump(f);
	if (fclose(f) != 0) {
		perror("Error closing output");
		rc = TEST_ERR;
	}

	return rc;
}

static int
setup_arch(void)
{
	if (!strcmp(arch_name, "x86_64")) {
		be = 0;
		writeheader_asm = writeheader_asm_x86_64;
	} else if (!strcmp(arch_name, "ia32")) {
		be = 0;
		writeheader_asm = writeheader_asm_ia32;
	} else if (!strcmp(arch_name, "ppc64")) {
		be = 1;
		writeheader_asm = writeheader_asm_ppc64;
	} else {
		fprintf(stderr, "Unknown architecture: %s\n", arch_name);
		return -1;
	}

	return 0;
}

int
main(int argc, char **argv)
{
	int rc;

	if (argc != 2) {
		fprintf(stderr, "Usage: %s <dump>\n", argv[0]);
		return TEST_ERR;
	}

	rc = set_default_params();
	if (rc != TEST_OK) {
		perror("Cannot set default params");
		return rc;
	}

	rc = parse_params_file(&params, stdin);
	if (rc != TEST_OK)
		return rc;

	rc = setup_arch();
	if (rc != TEST_OK)
		return rc;

	rc = create_file(argv[1]);
	if (rc != TEST_OK)
		return rc;

	return TEST_OK;
}