rdram2data.c 2.59 KB
#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>

#include <verify.h>
#include <em.h>

#include "rdram.h"

#define	BYTE_TO_DOUBLE(n)	(((n) + 7)/8)

#define	NumberDoubleWords(numBytes)	

static void	usage(void);

main(int argc, char **argv)
{
    int			i, c;
    VerifyInfo		*vp;
    unsigned long long	*llp;
    unsigned char	*cp;
    unsigned char	*mainAddress, *hiddenAddress;
    long		mainSize, hiddenSize;
    int			hiddenFlag = RDRAM_NOHIDDEN;
    int			frameBufferFlag = 0;
    int			zBufferFlag = 0;

    while ((c = getopt(argc, argv, "fhz")) != EOF) {
	switch (c) {
	case 'f':
	     frameBufferFlag = 1;
	     break;
	case 'h':
	    hiddenFlag = RDRAM_NEEDHIDDEN;
	    break;
	case 'z':
	    zBufferFlag = 1;
	    break;
	case '?':
	    usage();
	    exit(1);
	}
    }

    if ((argc - optind) != 1) {
	usage();
	exit(1);
    }
    if (rdraminit(argv[optind], RDRAM_RDONLY, hiddenFlag, 0,
		  &mainAddress, &mainSize, &hiddenAddress, &hiddenSize) == 0) {
        exit(1);
    }

    vp = (VerifyInfo *)(mainAddress + VERIFY_INFO_PHYSADDR);

    /* Dump VerifyInfo struct */

    printf("// VerifyInfo structure\n");
    printf("@%x\n", BYTE_TO_DOUBLE(VERIFY_INFO_PHYSADDR));

    llp = (unsigned long long *)(mainAddress + VERIFY_INFO_PHYSADDR);
    for (i = 0; i < BYTE_TO_DOUBLE(sizeof(VerifyInfo)); i++)
	printf("%016llx\n", *llp++);

    /* Dump application data */

    printf("// Application data\n");
    printf("@%x\n", BYTE_TO_DOUBLE(APP_START_ADDR));

    llp = (unsigned long long *)(mainAddress + APP_START_ADDR);
    for (i = 0; i < BYTE_TO_DOUBLE(APP_END_ADDR - APP_START_ADDR); i++)
	printf("%016llx\n", *llp++);

    /* Dump Frame buffer if desired */

    if (frameBufferFlag) {
	printf("// Frame buffer data\n");
	printf("@%x\n", BYTE_TO_DOUBLE(FB_START_ADDR));

	llp = (unsigned long long *)(mainAddress + FB_START_ADDR);
	for (i = 0; i < BYTE_TO_DOUBLE(ZB_START_ADDR - FB_START_ADDR); i++)
	printf("%016llx\n", *llp++);

	if (hiddenFlag) {
            printf("%%%x\n", BYTE_TO_DOUBLE(FB_START_ADDR));

	    cp = (unsigned char *)
		(hiddenAddress + BYTE_TO_DOUBLE(FB_START_ADDR));
	    for (i = 0; i < BYTE_TO_DOUBLE(ZB_START_ADDR - FB_START_ADDR); i++)
		printf("%02x\n", *cp++);
	}
     }

    /* Dump Z-buffer if desired */

    if (zBufferFlag) {
	printf("// Z-buffer data\n");
	printf("@%x\n", BYTE_TO_DOUBLE(ZB_START_ADDR));

	llp = (unsigned long long *)(mainAddress + ZB_START_ADDR);
	for (i = 0; i < BYTE_TO_DOUBLE(ZB_END_ADDR - ZB_START_ADDR); i++)
	    printf("%016llx\n", *llp++);
    }
}

static void
usage(void)
{
    fprintf(stderr, "usage: rdram2data [-h] [-z] <.rdram file>\n");
    exit(1);
}