1 #include <u.h>
2 #include <libc.h>
3 #include <bio.h>
4 #include "debug.h"
5 #include "tap.h"
6 #include "chain.h"
7 #include "jtag.h"
8
9 /*
10 We will only have one active tap at a time.
11 For now we will suppose they are concatenated.
12 IR will be 1s for the rest of the bits (Bypass the rest)
13 DR will be 1 bit per ignored Tap
14 */
15
16 static uchar bufch[4*1024];
17 int
tapshift(JMedium * jmed,ShiftTDesc * req,ShiftRDesc * rep,int tapidx)18 tapshift(JMedium *jmed, ShiftTDesc *req, ShiftRDesc *rep, int tapidx)
19 {
20 int i;
21 u32int ones;
22 ShiftTDesc lreq;
23 Chain *ch;
24
25 lreq = *req;
26 ones = ~0;
27 memset(bufch, 0, sizeof bufch);
28 ch = (Chain *)bufch;
29
30 for(i = 0; i < jmed->ntaps; i++){
31 if(req->reg == TapDR){
32 if(i == tapidx){
33 dprint(DState, "tap %d, DR\n", tapidx);
34 putbits(ch, req->buf, req->nbits);
35 }
36 else {
37 dprint(DState, "tap %d, ignoring DR\n", i);
38 putbits(ch, &ones, 1);
39 }
40 }
41 else if(req->reg == TapIR){
42 if(i == tapidx){
43 dprint(DState, "tap %d, IR\n", tapidx);
44 putbits(ch, req->buf, req->nbits);
45 }
46 else {
47 dprint(DState, "tap %d, IR\n", tapidx);
48 putbits(ch, &ones, jmed->taps[tapidx].irlen);
49 }
50 }
51 }
52
53 lreq.buf = ch->buf;
54 lreq.nbits = ch->e - ch->b;
55 jmed->TapSm = jmed->taps[tapidx].TapSm;
56 if(jmed->regshift(jmed, &lreq, rep) < 0)
57 return -1;
58 jmed->taps[tapidx].TapSm = jmed->TapSm;
59
60 if(req->op & ShiftIn)
61 for(i = 0; i < jmed->ntaps; i++){
62 if(req->reg == TapDR){
63 if(i == tapidx)
64 getbits(req->buf, ch, ch->e - ch->b);
65 else
66 getbits(&ones, ch, 1);
67 }
68 else if(req->reg == TapIR){
69 if(i == tapidx)
70 getbits(req->buf, ch, ch->e - ch->b);
71 else
72 getbits(&ones, ch, jmed->taps[tapidx].irlen);
73 }
74 }
75
76 return 0;
77 }
78