#ident "$Id: ds-debug.c,v 1.2 2006/12/28 19:44:13 craig Exp $"
/*
 *               Copyright (C) 2005, BroadOn Communications Corp.
 *
 *  These coded instructions, statements, and computer programs contain
 *  unpublished  proprietary information of BroadOn Communications Corp.,
 *  and  are protected by Federal copyright law. They may not be disclosed
 *  to  third  parties or copied or duplicated in any form, in whole or in
 *  part, without the prior written consent of BroadOn Communications Corp.
 *
 */

/*
 * Program comments here
 * 
 */

#include <netcard/ds-debug.h>

#define MAX_WATCHES     10

static int      currentWatches  = 0;

typedef struct watchList_t {
    void        *addr;
    u32         value;
    BOOL        valueSet;
} watchList_t;

static watchList_t    watchList[MAX_WATCHES];

void
watchLocation(const void* const addr)
{
    int i;

    /* First check if it is already being watched */
    for (i = 0; i < currentWatches; i++) {
        if (addr == watchList[i].addr) {
            // printf ("Location 0x%x is already being watched\n", (u32) addr);
            return;
        }
    }
    if (currentWatches >= MAX_WATCHES) {
        printf ("Too many watches - increase MAX_WATCHES (spinning)\n");
        while (1) {
        }
    }
    printf ("Watching location 0x%x\n", (u32) addr);
    currentWatches++;
    watchList[i].addr = (void *) addr;
    watchList[i].valueSet = FALSE;
}

/* --------------------------------------------------------------------- */

void
runWatch()
{
    int i;

    /* First check if it is already being watched */
    for (i = 0; i < currentWatches; i++) {
        if (watchList[i].valueSet == FALSE) {
            watchList[i].valueSet = TRUE;
            watchList[i].value = * (u32 *) watchList[i].addr;
            printf("Addr 0x%x: Initial value: 0x%x\n",
                    (u32) watchList[i].addr, watchList[i].value);
        }
        else if (watchList[i].value != * (u32 *) watchList[i].addr) {
            printf("Addr 0x%x: Old value: 0x%x; New value: 0x%x\n",
                    (u32) watchList[i].addr, watchList[i].value,
                    * (u32 *) watchList[i].addr);
            watchList[i].value = * (u32 *) watchList[i].addr;
        }
    }
}

/* --------------------------------------------------------------------- */
#include "md5.h"

void
printMD5sum(const void* const ptr, const u32 numBytes)
{
    md5_state_t state;
    md5_byte_t digest[16];
    int idx;

    md5_init(&state);
    md5_append(&state, ptr, numBytes);
    md5_finish(&state, digest);

    for (idx = 0; idx < 16; idx++) {
        printf("%02x", digest[idx]);
    }
}
/* --------------------------------------------------------------------- */
