diff -urN armtool/src/arm.c armtool.pn/src/arm.c --- armtool/src/arm.c 2003-07-20 19:52:30.000000000 +0200 +++ armtool.pn/src/arm.c 2003-12-31 18:00:40.000000000 +0100 @@ -242,7 +242,7 @@ if (verbose) fprintf(stderr,"ReadIDCode()\n"); ResetTapC(); /* First reset the TAP machine */ - EnterIRInst(4, 0x0e); /* Enter IDCODE instr. */ +// EnterIRInst(4, 0x0e); /* Enter IDCODE instr. */ EnterDRBits(32, NULL, &idcode, 1,1); /* Read out 32 bits into idcode */ return idcode; } @@ -295,6 +295,14 @@ return outdata[1]; /* Return 32 bits readout */ } + +void ScanChain0Read(u_int32_t *outdata) +{ + + SelectScanChain(0); /* Select IceBreaker Scan chain */ + EnterIRInst(4, 0x0c); /* Enter INTEST instr. */ + EnterDRBits(114, NULL, outdata,1,1); /* Read 114 bits out */ +} /***--------------------------------------------***/ /*** Overwrite IceBreaker register contents ***/ /***--------------------------------------------***/ @@ -322,6 +330,7 @@ printf ("IceB Debug Control = 0x%08X\n", IceBreakerRegRead(0)); printf ("IceB Debug Status = 0x%08X\n", IceBreakerRegRead(1)); + printf ("IceB Abort Status = 0x%08X\n", IceBreakerRegRead(2)); printf ("IceB Debug Comms Control = 0x%08X\n", IceBreakerRegRead(4)); printf ("IceB Debug Comms Status = 0x%08X\n", IceBreakerRegRead(5)); @@ -342,6 +351,11 @@ return 0; } +int WaitForDebug(void) +{ + while (!(IceBreakerRegRead(1) & 1)) ; +} + /***------------------------------------------------***/ /*** Stop a running program and enter DEBUG state ***/ /***------------------------------------------------***/ @@ -356,6 +370,8 @@ /* After sending data, RUN-TEST/IDLE state must be entered: */ StepNextTAPState(0); /* goto Run-Test/Idle */ + WaitForDebug(); + /* Show the Debug Status Register contents to see if the processor is stopped: */ /* @@ -373,12 +389,13 @@ } /* Put a breakpoint at some address using ICEBreaker */ -int PutBreakPoint(unsigned int addr) +int PutBreakPoint(unsigned int addr, unsigned int mask) { IceBreakerRegWrite(12, 0x0f0); /* WP0 contr value DISABLE */ IceBreakerRegWrite(20, 0x0f0); /* WP1 contr value DISABLE */ - IceBreakerRegWrite(9, 0xffffffff); /* WP0 Addr mask=ignore */ + IceBreakerRegWrite(8, addr); /* WP0 Addr value */ + IceBreakerRegWrite(9, mask); /* WP0 Addr mask=ignore */ IceBreakerRegWrite(11, 0xffffffff); /* WP0 data mask=ignore */ IceBreakerRegWrite(13, 0x0f7); /* WP0 contr mask=nOPC only*/ IceBreakerRegWrite(12, 0x1f0); /* WP0 contr value nOPC=0 */ @@ -494,6 +511,7 @@ i = outdata[1]; /* Send opcode & read out data */ if (was_in_thumb == 0) is_watchpoint = i; /* Value returned shows BREAKPT/WATCHPT */ + if (verbose) printf("we got here by %s.\n", is_watchpoint ? "watchpoint" : "breakpoint"); total_ins_exec++; /* MRS R0,CPSR */ @@ -522,6 +540,8 @@ } /* printf ("\n"); */ + if (verbose) printf("PC read was %08x, after adjustment is %08x\n", CPU_regs[15], CPU_regs[15]-0x18); + /* PC must be adjusted to allow for pipelining. Adjustment varies depending on how debug state was entered (breakpoint, watchpoint, debug request) */ if (is_debugrequest) @@ -547,6 +567,7 @@ /* printf ("CPSR = %08x\n",outdata[0]); */ /* Still work to do to read USER, FIQ, SPSR regs.... */ + if (verbose) printf("exiting ReadCPURegisters, so far we have executed %d instructions\n", total_ins_exec); return 0; } @@ -556,10 +577,10 @@ int i; for (i=0; i<8; i++) - printf ("%08X ", CPU_regs[i]); + printf ("R%02d=%08X ", i, CPU_regs[i]); printf("\n"); for (i=8; i<16; i++) - printf ("%08X ", CPU_regs[i]); + printf ("R%02d=%08X ", i, CPU_regs[i]); printf("\n"); printf ("CPSR = 0x%08X\n", CPU_CPSR); @@ -623,6 +644,8 @@ if (is_debugrequest == 0) dest--; + if (verbose) printf("the branch to fix the debug instructions is %d, total_ins_exec is %d\n", dest, total_ins_exec); + /* generate the branch field in the instr.: */ dest &= 0x00ffffff; dest |= 0xEA000000; @@ -675,7 +698,7 @@ // printf ("READ MEMORY AT 0x%08X l=%d\n", address,howmanywords); if (verbose) fprintf(stderr,"ReadMemory 0x%lx, l=%d\n",address,howmanywords); - PutBreakPoint(0x20000000); /* Put 'any address' breakpt.-> stop NOW! */ + PutBreakPoint(0, 0xffffffff); /* Put 'any address' breakpt.-> stop NOW! */ while (howmanywords > 0) { @@ -716,7 +739,7 @@ StepNextTAPState(0); /* goto Run-Test/Idle */ /* wait for breakpoint to be triggered */ - for (i=0; i<16; i++) { } /* Busy wait loop */ + WaitForDebug(); /* After doing this, the CPU will be stopped again in DEBUG state. Registers R0-R7 must be read out to know the desired value */ @@ -763,7 +786,7 @@ int lines=0; j=0; - PutBreakPoint(0x20000000); /* Put 'any address' breakpt.-> stop NOW! */ + PutBreakPoint(0, 0xffffffff); /* Put 'any address' breakpt.-> stop NOW! */ SelectScanChain(1); /* Select Debug Scan chain */ EnterIRInst(4, 0x0c); /* Enter INTEST instr. */ @@ -800,7 +823,7 @@ StepNextTAPState(0); /* goto Run-Test/Idle */ /* wait for breakpoint to be triggered */ - for (i=0; i<16; i++) { } /* Busy wait loop */ + WaitForDebug(); /* After doing this, the CPU will be stopped again in DEBUG state. Registers R0-R7 must be read out to know the desired value */ @@ -853,7 +876,7 @@ //printf("write 0x%0lx -> 0x%08lx\n",value,address); - PutBreakPoint(0x20000000); /* Put 'any address' breakpt.-> stop NOW! */ + PutBreakPoint(0, 0xffffffff); /* Put 'any address' breakpt.-> stop NOW! */ SelectScanChain(1); /* Select Debug Scan chain */ EnterIRInst(4, 0x0c); /* Enter INTEST instr. */ @@ -880,7 +903,7 @@ StepNextTAPState(0); /* goto Run-Test/Idle */ /* wait for breakpoint to be triggered */ - for (i=0; i<16; i++) { } /* Busy wait loop */ + WaitForDebug(); ClearAnyBreakPoint(); /* Avoid entering debug state after exiting */ } @@ -917,7 +940,7 @@ StepNextTAPState(0); /* goto Run-Test/Idle */ /* wait for breakpoint to be triggered */ - for (i=0; i<16; i++) { } /* Busy wait loop */ + WaitForDebug(); //xxx ClearAnyBreakPoint(); /* Avoid entering debug state after exiting */ } @@ -951,142 +974,3 @@ cpu_reset(0); // TCK=TMS=TDI=0 /* Yippieeh! We are running! */ } - -#if 0 -/***-----------------------------------***/ -/*** ***/ -/*** MAIN ***/ -/*** ***/ -/***-----------------------------------***/ - -int xmain (int argc, char *argv[]) -{ int x,i,j; -u_int32_t v1,v2; -int rand=0; - initialize_jtag_hardware(); - -/* First thing to do is to check IDCODE: */ -//SetTDI(0); -ResetTapC(); -printf ("IDCODE=%08X\n", ReadIDCode()); - -usleep(500000); - - for (;;) - { -#ifdef TESTPINS - /* Just to check connections...*/ - outb(1, DATA_PORT); - usleep(300000); - outb(0, DATA_PORT); - usleep(300000); - x = inb(STATUS_PORT); - printf("DATA= %02x\n", x); -#endif - -/* First thing to do is to check IDCODE: */ -#ifdef TEST1 -ResetTapC(); -printf ("IDCODE=%08X\n", ReadIDCode()); -#endif - -/* Then try more advanced things: */ -#ifdef TEST2 -ResetTapC(); /* First reset the TAP machine */ -ReadAllIceBreakerRegs(); -IceBreakerRegWrite(9, 0xdefabada); /* Just to see if writing works...*/ -printf ("IceB WatchP #0 Addr.mask = 0x%08X\n\n", IceBreakerRegRead(9)); -usleep(1000000); -#endif - -/* Show IceB. registers before & after entering debug state: */ -printf ("IceB Debug Control = 0x%08X Status = 0x%08X\n", - IceBreakerRegRead(0), IceBreakerRegRead(1)); - -/*StopRunningProgram();*/ /* Stop by user request */ -PutBreakPoint(0x20000000); /* Put 'any address' brekpt.-> stop NOW! */ -usleep(100000); /* Wait a bit to allow entering the breakpoint */ - -printf ("IceB Debug Control = 0x%08X Status = 0x%08X\n", - IceBreakerRegRead(0), IceBreakerRegRead(1)); - -/*ClearUserDebugRequest();*/ /* Clear user debug request */ -ClearAnyBreakPoint(); /* Avoid entering debug state after exiting */ -total_ins_exec = 0; /* From now on, count instructions */ -ReadCpuRegs(0); /* Read CPU registers & store away */ - -/* EBI read */ -ReadMemory(0xffe00000,8); -//ReadMemory(0xffe00020,1); -//ReadMemory(0xfffff000,64); - -/* System speed access test */ -//ReadMemory(0x00000000, 96); /* Read memory (in words, 4 bytes/each) */ - -// try read-id. Write at top half of flash. -WriteMemory(0x0101aaaa,0xaaaaaaaa); -WriteMemory(0x01015554,0x55555555); -WriteMemory(0x0101aaaa,0x90909090); - -v1=ReadWord(0x01000000); -v2=ReadWord(0x01000002); -printf("******************* 0x%lx 0x%lx\n",v1,v2); -sleep(1); -v1=ReadWord(0x01000000); -v2=ReadWord(0x01000002); -printf("******************FFF 0x%lx 0x%lx\n",v1,v2); -//sleep(1); -ReadMemory(0x1000000,0x20); - -//exit(0); - - -//ReadMemory(0x01000000,128*1024/4); // Flash 128KB -//ReadMemory(0x02000000,100*1024/4); // RAM 512KB -//WriteMemory(0x02000008,0xaaaaaaab); -//WriteMemory(0x0200000a,0x55555556); -rand +=0x22221111; - - - SelectScanChain(1); /* Select Debug Scan chain */ - -j=5555; -WriteMemory(0x2000004,0x1234+j); -ReadMemory(0x02000000,16); // RAM 512KB -WriteMemory(0x2000006,0x2345+j); -ReadMemory(0x02000000,16); // RAM 512KB -WriteMemory(0x2000008,0x6789+j); - -ReadMemory(0x02000000,16); // RAM 512KB -exit(0); - -ExitDebug(); /* Leave debug state & run again */ -//exit(0); - -/* Show the reason the program was stopped: */ -printf ("Program halted by user debug request: %s\n", is_debugrequest ? - "YES" : "NO, is a breakpoint/watchpoint"); -if (is_debugrequest == 0) - printf ("BREAK/WATCH: %s\n", is_watchpoint ? "WATCHPOINT" : "BREAKPOINT"); - -/* Show register values: */ -printf ("Register contents:\n"); -for (i=0; i<16; i++) - printf ("%08X ", CPU_regs[i]); -printf ("CPSR = 0x%08X\n", CPU_CPSR); - -usleep(3000000); - - } - - return 0; -} - -STAT() -{ - printf ("IceB Debug Status = 0x%08X\n", IceBreakerRegRead(1)); - SelectScanChain(1); -} - -#endif - diff -urN armtool/src/armtool.c armtool.pn/src/armtool.c --- armtool/src/armtool.c 2003-07-14 22:28:53.000000000 +0200 +++ armtool.pn/src/armtool.c 2004-01-02 17:44:57.000000000 +0100 @@ -1,4 +1,4 @@ -/************************************************************************** +/************************************************************************* * Copyright (C) Dipl.-Ing. Erwin Authried 2000 * * Softwareentwicklung und Systemdesign * * All Rights Reserved. * @@ -16,6 +16,19 @@ int verbose=0; +unsigned int reverse(unsigned int in) +{ + unsigned int out = 0; + int i; + int d; + for (i = 0; i<32; i++) { + d = in&1; + in >>= 1; + out = (out<<1)|d; + } + return out; +} + int main(int argc,char **argv) { u_int32_t adr,words,value; @@ -23,13 +36,147 @@ FILE *f; int mode,n; - - if (argc==2) { + if (argc==2 && !strcmp(argv[1], "reset")) { /* apply reset */ initialize_jtag_hardware(); cpu_reset(1); + sleep(1); + cpu_reset(0); + printf ("IDCODE=%08X\n", ReadIDCode()); exit(0); } + if (argc==2 && !strcmp(argv[1], "scan0")) { + u_int32_t scan0[4]; + + initialize_jtag_hardware(); + ScanChain0Read(scan0); + printf("Scan Chain 0: DATA=%08x ", scan0[0]); + printf("nENIN=%d nENOUT=%d LOCK=%d BIGEND=%d DBE=%d MAS0=%d MAS1=%d BL0=%d BL1=%d BL2=%d BL3=%d nRW=%d\nnFIQ=%d nIRQ=%d nRESET=%d ISYNC=%d ", + (scan0[1]>>31)&1, // nENIN + (scan0[1]>>30)&1, // nENOUT + (scan0[1]>>29)&1, // LOCK + (scan0[1]>>28)&1, // BIGEND + (scan0[1]>>27)&1, // DBE + (scan0[1]>>26)&1, // MAS0 + (scan0[1]>>25)&1, // MAS1 + (scan0[1]>>24)&1, // BL0 + (scan0[1]>>23)&1, // BL1 + (scan0[1]>>22)&1, // BL2 + (scan0[1]>>21)&1, // BL3 + (scan0[1]>>20)&1, // nRW + (scan0[1]>>19)&1, // nFIQ + (scan0[1]>>18)&1, // nIRQ + (scan0[1]>>17)&1, // nRESET + (scan0[1]>>16)&1 // ISYNC + ); + printf("ABORT=%d nOPC=%d nCPI=%d nMREQ=%d SEQ=%d nTRANS=%d nM4=%d nM3=%d nM2=%d nM1=%d nM0=%d nEXEC=%d\nINSTRVALID=%d ALE=%d ABE=%d APE=%d ", + (scan0[1]>>15)&1, // ABORT + (scan0[1]>>14)&1, // nOPC + (scan0[1]>>13)&1, // nCPI + (scan0[1]>>12)&1, // nMREQ + (scan0[1]>>11)&1, // SEQ + (scan0[1]>>10)&1, // nTRANS + (scan0[1]>>9)&1, // nM4 + (scan0[1]>>8)&1, // nM3 + (scan0[1]>>7)&1, // nM2 + (scan0[1]>>6)&1, // nM1 + (scan0[1]>>5)&1, // nM0 + (scan0[1]>>4)&1, // nEXEC + (scan0[1]>>3)&1, // INSTRVALID + (scan0[1]>>2)&1, // ALE + (scan0[1]>>1)&1, // ABE + (scan0[1]>>0)&1 // APE + ); + printf("TBIT=%d nWAIT=%d\n", + (scan0[2]>>31)&1, // TBIT + (scan0[2]>>30)&1 // NWAIT + ); + printf("ADDRESS=%08x\n", reverse(((scan0[2]<<2)&(0xfffffffc))|((scan0[3]>>30)&3))); + printf("DBGRQ=%d DBGEN=%d CPA=%d CPB=%d BUSEN=%d EXTERN0=%d EXTERN1=%d BREAKPT=%d DBGACK=%d RANGEOUT0=%d RANGEOUT1=%d nENOUT1=%d COMMTX=%d COMMRX=%d DBGRQI=%d\n", + (scan0[3]>>29)&1, // DBGRQ + (scan0[3]>>28)&1, // DBGEN + (scan0[3]>>27)&1, // CPA + (scan0[3]>>26)&1, // CPB + (scan0[3]>>25)&1, // BUSEN + (scan0[3]>>24)&1, // EXTERN0 + (scan0[3]>>23)&1, // EXTERN1 + (scan0[3]>>22)&1, // BREAKPT + (scan0[3]>>21)&1, // DBGACK + (scan0[3]>>20)&1, // RANGEOUT0 + (scan0[3]>>19)&1, // RANGEOUT1 + (scan0[3]>>18)&1, // nENOUT1 + (scan0[3]>>17)&1, // COMMTX + (scan0[3]>>16)&1, // COMMRX + (scan0[3]>>15)&1 // DBGRQI + ); + ResetTapC(); + exit(0); + } + if (argc==2 && !strcmp(argv[1], "where")) { + unsigned debug_save[16]; + + initialize_jtag_hardware(); + debug_save[8] = IceBreakerRegRead(8); + debug_save[9] = IceBreakerRegRead(9); + debug_save[11] = IceBreakerRegRead(11); + debug_save[12] = IceBreakerRegRead(12); + PutBreakPoint(0, 0xffffffff); /* Put 'any address' brekpt.-> stop NOW! */ + WaitForDebug(); + ClearAnyBreakPoint(); + ReadCpuRegs(1); /* Read CPU registers & store away */ + DumpCPUregs(); + IceBreakerRegWrite(8, debug_save[8]); + IceBreakerRegWrite(9, debug_save[9]); + IceBreakerRegWrite(11, debug_save[11]); + IceBreakerRegWrite(12, debug_save[12]); + ExitDebug(); + ResetTapC(); + exit(0); + } + if (argc==2 && !strcmp(argv[1], "ice")) { + initialize_jtag_hardware(); + ReadAllIceBreakerRegs(); + exit(0); + } + if (argc==2 && !strcmp(argv[1], "wait")) { + initialize_jtag_hardware(); + ReadAllIceBreakerRegs(); + WaitForDebug(); + ReadCpuRegs(1); + DumpCPUregs(); + ClearAnyBreakPoint(); + ExitDebug(); + ResetTapC(); + exit(0); + } + if (argc==3 && !strcmp(argv[1], "breakw")) { + n=sscanf(argv[2],"%lu",&adr); + if (n && adr==0 && argv[2][1]=='x') n=0; + if (!n) n=sscanf(argv[2],"%lxu",&adr); + if (n!=1) {fprintf(stderr,"argument error: adr\n");exit(1);} + + initialize_jtag_hardware(); + PutBreakPoint(adr, 0); + WaitForDebug(); + ReadCpuRegs(1); + DumpCPUregs(); + ClearAnyBreakPoint(); + ExitDebug(); + ResetTapC(); + exit(0); + } + if (argc==3 && !strcmp(argv[1], "break")) { + n=sscanf(argv[2],"%lu",&adr); + if (n && adr==0 && argv[2][1]=='x') n=0; + if (!n) n=sscanf(argv[2],"%lxu",&adr); + if (n!=1) {fprintf(stderr,"argument error: adr\n");exit(1);} + + initialize_jtag_hardware(); + //ResetTapC(); + PutBreakPoint(adr, 0); + ReadAllIceBreakerRegs(); + exit(0); + } if (argc<3) { fprintf(stderr, "Usage: %s r{ead} adr words {filename} ... read from target\n" " %s w{rite} adr value ... write a single word to target\n" @@ -55,15 +202,16 @@ // printf("adr=0x%lx words=0x%x\n",adr,words); initialize_jtag_hardware(); - ResetTapC(); - PutBreakPoint(0x20000000); /* Put 'any address' brekpt.-> stop NOW! */ -cpu_reset(0); - printf ("IDCODE=%08X\n", ReadIDCode()); // geht nicht wenn reset aktiv! + //ResetTapC(); +// PutBreakPoint(0, 0xffffffff); /* Put 'any address' brekpt.-> stop NOW! */ +// StopRunningProgram(); +//cpu_reset(0); + //printf ("IDCODE=%08X\n", ReadIDCode()); // geht nicht wenn reset aktiv! cpu_reset(0); // Core is stopped now, release rst // add this for test ! - PutBreakPoint(0x20000000); /* Put 'any address' brekpt.-> stop NOW! */ + PutBreakPoint(0, 0xffffffff); /* Put 'any address' brekpt.-> stop NOW! */ ClearAnyBreakPoint(); /* Avoid entering debug state after exiting */ // total_ins_exec = 0; /* From now on, count instructions */ ReadCpuRegs(0); /* Read CPU registers & store away */ @@ -82,6 +230,7 @@ if (n==0) {fclose(f); fprintf(stderr, "end of file at 0x%lx\n",adr); exit(0);} WriteMemoryBuf(adr,n,buf); adr+=4*n; words-=n; + printf("\r%08x ", adr); } fclose(f); @@ -108,6 +257,7 @@ RunProgram(adr); break; } /* switch */ + ResetTapC(); /* make sure we leave in Idle/Run state */ close_jtag_hardware(); } diff -urN armtool/src/Makefile armtool.pn/src/Makefile --- armtool/src/Makefile 2003-07-14 22:28:53.000000000 +0200 +++ armtool.pn/src/Makefile 2003-12-27 23:51:10.000000000 +0100 @@ -1,12 +1,16 @@ EXEC = armtool OBJS = armtool.o arm.o -CFLAGS += -O2 +CFLAGS += -O2 -I../../libjtag/src +LDFLAGS += -L../../libjtag/src