Main Page | Modules | File List | Globals | Examples

register.c

Example remote register dump

/*
 *
 * This is just an example to dump the registers.
 *
 * The output to expect is the following:

Initializing emulation
Detecting device...
Idcode: 327a50cb
Detected Device: BF-533 rev:3
------------------------------------------------------------------------
    RETE = 00000de4
    RETI = 20000144
    RETX = 00000de4
    RETN = 80803589
      R0 = 07f80000
      R1 = 00000000
      R2 = 00000004
      R3 = 00000000
      R4 = 07f80000
      R5 = 00000000
      R6 = 07f80000
      R7 = 00000000
      P0 = 07f80000
      P1 = 200161dc
      P2 = 07f95f40
      P3 = 00000004
      P4 = 00000000
      P5 = 00000000
      SP = 07f3bff8
      FP = 0fe77ff0
 SEQSTAT = 0000e025
  SYSCFG = 00000030
------------------------------------------------------------------------
current PC: 00000de4
------------------------------------------------------------------------

 *
 */

#include <stdio.h>

#include "bfemu.h"
#include "bfin-registers.h"
#include "platform.h"
#include "timing.h"   // Always include after bfemu.h

static char g_line[] =
"------------------------------------------------------------------------\n";

#define DEF_REG(x) {REG_##x, #x}

static struct _regrepr {
        int regno;
        const char *repr;
} g_registers[] = {
        DEF_REG(RETE),
        DEF_REG(RETI),
        DEF_REG(RETX),
        DEF_REG(RETN),
        DEF_REG(R0),
        DEF_REG(R1),
        DEF_REG(R2),
        DEF_REG(R3),
        DEF_REG(R4),
        DEF_REG(R5),
        DEF_REG(R6),
        DEF_REG(R7),
        DEF_REG(P0),
        DEF_REG(P1),
        DEF_REG(P2),
        DEF_REG(P3),
        DEF_REG(P4),
        DEF_REG(P5),
        DEF_REG(SP),
        DEF_REG(FP),
        DEF_REG(SEQSTAT),
        DEF_REG(SYSCFG),
        { -1, "" }
};

void dump_registers(CPU cpu)
{
        struct _regrepr *r;
        int regnos[128];
        BFIN_REGISTER regs[128];
        TIMEVAL t0, t1;
        float t;


        r = g_registers;
        int *reg = regnos;

        int i = 0;
        while (r->regno != -1) {
                *reg++ = r->regno;
                r++; i++;
        }
        *reg = -1;

        // Read all specified registers into the buffer:
        gettime(&t0);
        save_registers(cpu, regs, regnos);
        gettime(&t1);

        r = g_registers;
        reg = regnos;
        i = 0;
        while (r->regno != -1) {
                printf("%8s = %08lx\n", r->repr, regs[i]);
                r++; i++;
        }

        t = took_time(&t0, &t1);
        printf("took: %f\n", t);
}

// The main program
//
// Make sure you always follow the proper initialization scheme:
//
// 1. jtag_init()
// 2. emulation_init()
// 3. emulation_enter()
// 4. < Do your examination >
// 5. emulation_leave()
// 6. emulation_exit()
// 7. jtag_exit()
//

int main(int argc, char **argv)
{
        CPU cpu;
        int error;
        unsigned int revision;

        if (jtag_init(0, &cpu) < 0) {
                printf("Could not open jtag controller\n");
                return -1;
        }

        printf("Initializing emulation\n");
        error = emulation_init(cpu);
        if (error < 0) return -1;

        char *s;
        printf("Detecting device...\n");
        s = detect_device(cpu, &revision);
        if (s) {
                printf("Detected Device: %s rev:%d\n", s, revision);
        } else {
                printf("Could not detect device, JTAG failure ?\n");
                return -1;
        }

        error = emulation_enter(cpu);
        if (error < 0) {
                printf("Emulator not ready!\n");
                return -1;
        }

        printf(g_line);
        dump_registers(cpu);
        printf(g_line);

        BFIN_REGISTER pc = get_cpuregister(cpu, REG_RETE);
        printf("current PC: %08lx\n", pc);
        printf(g_line);
        emulation_leave(cpu);
        emulation_exit(cpu);
        jtag_exit(cpu);

        return 0;
}


Generated on Thu Sep 1 15:02:53 2005 for bfemu - Blackfin emulation library by  doxygen 1.4.3-20050530