OpenCores
URL https://opencores.org/ocsvn/adv_debug_sys/adv_debug_sys/trunk

Subversion Repositories adv_debug_sys

[/] [adv_debug_sys/] [trunk/] [Software/] [AdvancedWatchpointControl/] [src/] [advancedWatchpointControl/] [registerInterpreter.java] - Blame information for rev 56

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 54 nyawn
////////////////////////////////////////////////////////////////
2
//
3
// registerInterpreter.java
4
//
5
// Copyright (C) 2010 Nathan Yawn 
6
//                    (nyawn@opencores.org)
7
//
8 51 nyawn
// This class wraps the basic register set cache.  It adds
9
// convenience methods so that the UI classes do not need to
10
// interpret the various bit meanings in the registers.
11 54 nyawn
//
12
////////////////////////////////////////////////////////////////
13
//
14
// This source file may be used and distributed without
15
// restriction provided that this copyright statement is not
16
// removed from the file and that any derivative work contains
17
// the original copyright notice and the associated disclaimer.
18
// 
19
// This source file is free software; you can redistribute it
20
// and/or modify it under the terms of the GNU General
21
// Public License as published by the Free Software Foundation;
22
// either version 3.0 of the License, or (at your option) any
23
// later version.
24
//
25
// This source is distributed in the hope that it will be
26
// useful, but WITHOUT ANY WARRANTY; without even the implied 
27
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
28
// PURPOSE.  See the GNU Lesser General Public License for more
29
// details.
30
// 
31
// You should have received a copy of the GNU General
32
// Public License along with this source; if not, download it 
33
// from http://www.gnu.org/licenses/gpl.html
34
//
35
////////////////////////////////////////////////////////////////
36 51 nyawn
package advancedWatchpointControl;
37
 
38
 
39
public class registerInterpreter {
40
 
41
        public enum compareSource  { DISABLED, INSTR_FETCH_ADDR, LOAD_ADDR, STORE_ADDR, LOAD_DATA, STORE_DATA,
42
                LOAD_STORE_ADDR, LOAD_STORE_DATA }
43
        public enum compareType  { MASKED, EQ, LT, LE, GT, GE, NE }
44
        public enum chainType { NONE, AND, OR }
45
 
46
        private targetDebugRegisterSet registers;
47
 
48
        public registerInterpreter(targetDebugRegisterSet regs) {
49
                registers = regs;
50
        }
51
 
52
 
53
        public boolean isWPImplemented(int whichWP) {
54
                long exists = registers.getDCR(whichWP) & 0x1;
55
                if(exists != 0) return true;
56
                else return false;
57
        }
58
 
59
        public boolean getWPBreakEnabled(int whichWP) {
60
                long enabled = (registers.getDMR2() >> (12+whichWP)) & 0x1;
61
                if(enabled != 0) return true;
62
                else return false;
63
        }
64
 
65
        public void setWPBreakEnabled(int whichWP, boolean enabled) {
66
                long maskval = 0x1 << (12+whichWP);
67
                if(enabled) {
68
                        registers.setDMR2(registers.getDMR2() | maskval);
69
                }
70
                else {
71
                        registers.setDMR2(registers.getDMR2() & (~maskval));
72
                }
73
        }
74
 
75
        public compareSource getWPCompareSource(int whichWP) {
76
                int src = (int)((registers.getDCR(whichWP) >> 5) & 0x7);
77
                compareSource ret = compareSource.DISABLED;
78
                switch(src) {
79
                        case 0:
80
                                ret = compareSource.DISABLED;
81
                                break;
82
                        case 1:
83
                                ret = compareSource.INSTR_FETCH_ADDR;
84
                                break;
85
                        case 2:
86
                                ret = compareSource.LOAD_ADDR;
87
                                break;
88
                        case  3:
89
                                ret = compareSource.STORE_ADDR;
90
                                break;
91
                        case  4:
92
                                ret = compareSource.LOAD_DATA;
93
                                break;
94
                        case  5:
95
                                ret = compareSource.STORE_DATA;
96
                                break;
97
                        case  6:
98
                                ret = compareSource.LOAD_STORE_ADDR;
99
                                break;
100
                        case  7:
101
                                ret = compareSource.LOAD_STORE_DATA;
102
                                break;
103
                }
104
                return ret;
105
        }
106
 
107
        public void setWPCompareSource(int whichWP, compareSource src) {
108
                long val = 0;
109
                switch(src) {
110
                case DISABLED:
111
                        val = 0;
112
                        break;
113
                case INSTR_FETCH_ADDR:
114
                        val = 1;
115
                        break;
116
                case LOAD_ADDR:
117
                        val = 2;
118
                        break;
119
                case STORE_ADDR:
120
                        val = 3;
121
                        break;
122
                case LOAD_DATA:
123
                        val = 4;
124
                        break;
125
                case STORE_DATA:
126
                        val = 5;
127
                        break;
128
                case LOAD_STORE_ADDR:
129
                        val = 6;
130
                        break;
131
                case LOAD_STORE_DATA:
132
                        val = 7;
133
                        break;
134
                }
135
                val = val << 5;
136
                long mask = 7 << 5;
137 56 nyawn
                long tmp = registers.getDCR(whichWP);
138
                tmp &= (~mask);
139 51 nyawn
                tmp |= val;
140 56 nyawn
                registers.setDCR(whichWP, tmp);
141 51 nyawn
        }
142
 
143
        public compareType getWPCompareType(int whichWP) {
144
                int src = (int)((registers.getDCR(whichWP) >> 1) & 0x7);
145
                compareType ret = compareType.MASKED;
146
                switch(src) {
147
                        case 0:
148
                                ret = compareType.MASKED;
149
                                break;
150
                        case 1:
151
                                ret = compareType.EQ;
152
                                break;
153
                        case 2:
154
                                ret = compareType.LT;
155
                                break;
156
                        case  3:
157
                                ret = compareType.LE;
158
                                break;
159
                        case  4:
160
                                ret = compareType.GT;
161
                                break;
162
                        case  5:
163
                                ret = compareType.GE;
164
                                break;
165
                        case  6:
166
                                ret = compareType.NE;
167
                                break;
168
                }
169
                return ret;
170
        }
171
 
172
        public void setWPCompareType(int whichWP, compareType type) {
173
                long val = 0;
174
                switch(type) {
175
                case MASKED:
176
                        val = 0;
177
                        break;
178
                case EQ:
179
                        val = 1;
180
                        break;
181
                case LT:
182
                        val = 2;
183
                        break;
184
                case LE:
185
                        val = 3;
186
                        break;
187
                case GT:
188
                        val = 4;
189
                        break;
190
                case GE:
191
                        val = 5;
192
                        break;
193
                case NE:
194
                        val = 6;
195
                        break;
196
 
197
                }
198
                val = val << 1;
199
                long mask = 7 << 1;
200
                long tmp = registers.getDCR(whichWP);
201
                tmp &= (~mask);
202
                tmp |= val;
203
                registers.setDCR(whichWP, tmp);
204
        }
205
 
206
        public boolean getWPSignedCompare(int whichWP) {
207
                long enabled = registers.getDCR(whichWP) & 0x10;
208
                if(enabled != 0) return true;
209
                else return false;
210
        }
211
 
212
        public void setWPSignedCompare(int whichWP, boolean signed) {
213
                long maskval = 0x10;
214
                long tmp = registers.getDCR(whichWP);
215
                if(signed) tmp |= maskval;
216
                else tmp &= (~maskval);
217
                registers.setDCR(whichWP, tmp);
218
        }
219
 
220
        public chainType getWPChainType(int whichWP) {
221
                int src = (int)((registers.getDMR1() >> (2*whichWP)) & 0x3);
222
                chainType ret = chainType.NONE;
223
                switch(src) {
224
                        case 0:
225
                                ret = chainType.NONE;
226
                                break;
227
                        case 1:
228
                                ret = chainType.AND;
229
                                break;
230
                        case 2:
231
                                ret = chainType.OR;
232
                                break;
233
                }
234
                return ret;
235
        }
236
 
237
        public void setWPChainType(int whichWP, chainType type) {
238
                long val = 0;
239
                switch(type) {
240
                case NONE:
241
                        val = 0;
242
                        break;
243
                case AND:
244
                        val = 1;
245
                        break;
246
                case OR:
247
                        val = 2;
248
                        break;
249
                }
250
                val = val << (2*whichWP);
251
                long mask = 3 << (2*whichWP);
252
                long tmp = registers.getDMR1() & (~mask);
253
                tmp |= val;
254 56 nyawn
                registers.setDMR1(tmp);
255 51 nyawn
        }
256
 
257
        public int getWPCounterAssign(int whichWP) {
258
                int val = (int)((registers.getDMR2() >> (2 + whichWP)) & 0x1);
259
                return val;
260
        }
261
 
262
        // Note that for this method, indexes 8 and 9 are valid
263
        // (they indicate counter 0 and counter 1, respectively).
264
        public void setWPCounterAssign(int whichWP, int counter) {
265
                long val = (counter & 0x1) << (2+whichWP);
266
                long mask = 0x1 << (2+whichWP);
267
                long tmp = registers.getDMR2();
268
                tmp &= (~mask);
269
                tmp |= val;
270
                registers.setDMR2(tmp);
271
        }
272
 
273
        public boolean didWPCauseBreak(int whichWP) {
274
                int val = (int)((registers.getDMR2() >> (22+whichWP)) & 0x1);
275
                if(val == 0) return false;
276
                else return true;
277
        }
278
 
279
        public boolean getCounterEnabled(int whichCounter) {
280
                int enabled = (int)((registers.getDMR2() >> (whichCounter&0x1)) & 0x1);
281
                if(enabled != 0) return true;
282
                else return false;
283
        }
284
 
285
 
286
        public void setCounterEnabled(int whichCounter, boolean enabled) {
287
                long maskval = 0x1 << (whichCounter & 0x1);
288
                long tmp = registers.getDMR2();
289
                if(enabled) tmp |= maskval;
290
                else tmp &= (~maskval);
291
                registers.setDMR2(tmp);
292
        }
293
 
294
 
295
        public boolean getCounterBreakEnabled(int whichCounter) {
296
                int enabled = (int)((registers.getDMR2() >> (20+whichCounter)) & 0x1);
297
                if(enabled != 0) return true;
298
                else return false;
299
        }
300
 
301
 
302
        public void setCounterBreakEnabled(int whichCounter, boolean enabled) {
303
                long maskval = 0x1 << (20+whichCounter);
304
                long tmp = registers.getDMR2();
305
                if(enabled) tmp |= maskval;
306
                else tmp &= (~maskval);
307
                registers.setDMR2(tmp);
308
        }
309
 
310
        public boolean didCounterCauseBreak(int whichCounter) {
311
                int val = (int)((registers.getDMR2() >> (30+whichCounter)) & 0x1);
312
                if(val == 0) return false;
313
                else return true;
314
        }
315
 
316
        public int getCounterWatchValue(int whichCounter) {
317
                int val = 0;
318
                if(whichCounter == 0) val = (int)((registers.getDWCR0() >> 16) & 0xFFFF);
319
                else val = (int)((registers.getDWCR1() >> 16) & 0xFFFF);
320
                return val;
321
        }
322
 
323
        public void setCounterWatchValue(int whichCounter, int value) {
324
                long val = (value & 0xFFFF) << 16;
325
                long mask = 0x0000FFFF;
326
                long tmp;
327
                if(whichCounter == 0) {
328
                        tmp = registers.getDWCR0();
329
                        tmp &= mask;
330
                        tmp |= val;
331
                        registers.setDWCR0(tmp);
332
                } else {
333
                        tmp = registers.getDWCR1();
334
                        tmp &= mask;
335
                        tmp |= val;
336
                        registers.setDWCR1(tmp);
337
                }
338
        }
339
 
340
        public int getCounterCountValue(int whichCounter) {
341
                int val = 0;
342
                if(whichCounter == 0) val = (int)(registers.getDWCR0() & 0xFFFF);
343
                else val = (int)(registers.getDWCR1() & 0xFFFF);
344
                return val;
345
        }
346
 
347
        public void setCounterCountValue(int whichCounter, int value) {
348
                long val = value & 0xFFFF;
349
                long mask = 0xFFFF0000;
350
                long tmp;
351
                if(whichCounter == 0) {
352
                        tmp = registers.getDWCR0();
353
                        tmp &= mask;
354
                        tmp |= val;
355
                        registers.setDWCR0(tmp);
356
                } else {
357
                        tmp = registers.getDWCR1();
358
                        tmp &= mask;
359
                        tmp |= val;
360
                        registers.setDWCR1(tmp);
361
                }
362
        }
363
 
364
 
365
        public chainType getCounterChainType(int whichCounter) {
366
                int src = (int)((registers.getDMR1() >> (16+(2*whichCounter))) & 0x3);
367
                chainType ret = chainType.NONE;
368
                switch(src) {
369
                        case 0:
370
                                ret = chainType.NONE;
371
                                break;
372
                        case 1:
373
                                ret = chainType.AND;
374
                                break;
375
                        case 2:
376
                                ret = chainType.OR;
377
                                break;
378
                }
379
                return ret;
380
        }
381
 
382
        public void setCounterChainType(int whichCounter, chainType type) {
383
                long val = 0;
384
                switch(type) {
385
                case NONE:
386
                        val = 0;
387
                        break;
388
                case AND:
389
                        val = 1;
390
                        break;
391
                case OR:
392
                        val = 2;
393
                        break;
394
                }
395
                val = val << (16+(2*whichCounter));
396
                long mask = 3 << (16+(2*whichCounter));
397
                long tmp = registers.getDMR1();
398
                tmp &= (~mask);
399
                tmp |= val;
400
                registers.setDMR1(tmp);
401
        }
402
 
403
        public void setDVR(int which, long val) {
404
                registers.setDVR(which, val);
405
        }
406
 
407
        public long getDVR(int which) {
408
                return registers.getDVR(which);
409
        }
410
 
411
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.