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 54

Go to most recent revision | 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
                long tmp = registers.getDCR(whichWP) & (~mask);
138
                tmp |= val;
139
                registers.setDCR(whichWP, val);
140
        }
141
 
142
        public compareType getWPCompareType(int whichWP) {
143
                int src = (int)((registers.getDCR(whichWP) >> 1) & 0x7);
144
                compareType ret = compareType.MASKED;
145
                switch(src) {
146
                        case 0:
147
                                ret = compareType.MASKED;
148
                                break;
149
                        case 1:
150
                                ret = compareType.EQ;
151
                                break;
152
                        case 2:
153
                                ret = compareType.LT;
154
                                break;
155
                        case  3:
156
                                ret = compareType.LE;
157
                                break;
158
                        case  4:
159
                                ret = compareType.GT;
160
                                break;
161
                        case  5:
162
                                ret = compareType.GE;
163
                                break;
164
                        case  6:
165
                                ret = compareType.NE;
166
                                break;
167
                }
168
                return ret;
169
        }
170
 
171
        public void setWPCompareType(int whichWP, compareType type) {
172
                long val = 0;
173
                switch(type) {
174
                case MASKED:
175
                        val = 0;
176
                        break;
177
                case EQ:
178
                        val = 1;
179
                        break;
180
                case LT:
181
                        val = 2;
182
                        break;
183
                case LE:
184
                        val = 3;
185
                        break;
186
                case GT:
187
                        val = 4;
188
                        break;
189
                case GE:
190
                        val = 5;
191
                        break;
192
                case NE:
193
                        val = 6;
194
                        break;
195
 
196
                }
197
                val = val << 1;
198
                long mask = 7 << 1;
199
                long tmp = registers.getDCR(whichWP);
200
                tmp &= (~mask);
201
                tmp |= val;
202
                registers.setDCR(whichWP, tmp);
203
        }
204
 
205
        public boolean getWPSignedCompare(int whichWP) {
206
                long enabled = registers.getDCR(whichWP) & 0x10;
207
                if(enabled != 0) return true;
208
                else return false;
209
        }
210
 
211
        public void setWPSignedCompare(int whichWP, boolean signed) {
212
                long maskval = 0x10;
213
                long tmp = registers.getDCR(whichWP);
214
                if(signed) tmp |= maskval;
215
                else tmp &= (~maskval);
216
                registers.setDCR(whichWP, tmp);
217
        }
218
 
219
        public chainType getWPChainType(int whichWP) {
220
                int src = (int)((registers.getDMR1() >> (2*whichWP)) & 0x3);
221
                chainType ret = chainType.NONE;
222
                switch(src) {
223
                        case 0:
224
                                ret = chainType.NONE;
225
                                break;
226
                        case 1:
227
                                ret = chainType.AND;
228
                                break;
229
                        case 2:
230
                                ret = chainType.OR;
231
                                break;
232
                }
233
                return ret;
234
        }
235
 
236
        public void setWPChainType(int whichWP, chainType type) {
237
                long val = 0;
238
                switch(type) {
239
                case NONE:
240
                        val = 0;
241
                        break;
242
                case AND:
243
                        val = 1;
244
                        break;
245
                case OR:
246
                        val = 2;
247
                        break;
248
                }
249
                val = val << (2*whichWP);
250
                long mask = 3 << (2*whichWP);
251
                long tmp = registers.getDMR1() & (~mask);
252
                tmp |= val;
253
                registers.setDMR1(val);
254
        }
255
 
256
        public int getWPCounterAssign(int whichWP) {
257
                int val = (int)((registers.getDMR2() >> (2 + whichWP)) & 0x1);
258
                return val;
259
        }
260
 
261
        // Note that for this method, indexes 8 and 9 are valid
262
        // (they indicate counter 0 and counter 1, respectively).
263
        public void setWPCounterAssign(int whichWP, int counter) {
264
                long val = (counter & 0x1) << (2+whichWP);
265
                long mask = 0x1 << (2+whichWP);
266
                long tmp = registers.getDMR2();
267
                tmp &= (~mask);
268
                tmp |= val;
269
                registers.setDMR2(tmp);
270
        }
271
 
272
        public boolean didWPCauseBreak(int whichWP) {
273
                int val = (int)((registers.getDMR2() >> (22+whichWP)) & 0x1);
274
                if(val == 0) return false;
275
                else return true;
276
        }
277
 
278
        public boolean getCounterEnabled(int whichCounter) {
279
                int enabled = (int)((registers.getDMR2() >> (whichCounter&0x1)) & 0x1);
280
                if(enabled != 0) return true;
281
                else return false;
282
        }
283
 
284
 
285
        public void setCounterEnabled(int whichCounter, boolean enabled) {
286
                long maskval = 0x1 << (whichCounter & 0x1);
287
                long tmp = registers.getDMR2();
288
                if(enabled) tmp |= maskval;
289
                else tmp &= (~maskval);
290
                registers.setDMR2(tmp);
291
        }
292
 
293
 
294
        public boolean getCounterBreakEnabled(int whichCounter) {
295
                int enabled = (int)((registers.getDMR2() >> (20+whichCounter)) & 0x1);
296
                if(enabled != 0) return true;
297
                else return false;
298
        }
299
 
300
 
301
        public void setCounterBreakEnabled(int whichCounter, boolean enabled) {
302
                long maskval = 0x1 << (20+whichCounter);
303
                long tmp = registers.getDMR2();
304
                if(enabled) tmp |= maskval;
305
                else tmp &= (~maskval);
306
                registers.setDMR2(tmp);
307
        }
308
 
309
        public boolean didCounterCauseBreak(int whichCounter) {
310
                int val = (int)((registers.getDMR2() >> (30+whichCounter)) & 0x1);
311
                if(val == 0) return false;
312
                else return true;
313
        }
314
 
315
        public int getCounterWatchValue(int whichCounter) {
316
                int val = 0;
317
                if(whichCounter == 0) val = (int)((registers.getDWCR0() >> 16) & 0xFFFF);
318
                else val = (int)((registers.getDWCR1() >> 16) & 0xFFFF);
319
                return val;
320
        }
321
 
322
        public void setCounterWatchValue(int whichCounter, int value) {
323
                long val = (value & 0xFFFF) << 16;
324
                long mask = 0x0000FFFF;
325
                long tmp;
326
                if(whichCounter == 0) {
327
                        tmp = registers.getDWCR0();
328
                        tmp &= mask;
329
                        tmp |= val;
330
                        registers.setDWCR0(tmp);
331
                } else {
332
                        tmp = registers.getDWCR1();
333
                        tmp &= mask;
334
                        tmp |= val;
335
                        registers.setDWCR1(tmp);
336
                }
337
        }
338
 
339
        public int getCounterCountValue(int whichCounter) {
340
                int val = 0;
341
                if(whichCounter == 0) val = (int)(registers.getDWCR0() & 0xFFFF);
342
                else val = (int)(registers.getDWCR1() & 0xFFFF);
343
                return val;
344
        }
345
 
346
        public void setCounterCountValue(int whichCounter, int value) {
347
                long val = value & 0xFFFF;
348
                long mask = 0xFFFF0000;
349
                long tmp;
350
                if(whichCounter == 0) {
351
                        tmp = registers.getDWCR0();
352
                        tmp &= mask;
353
                        tmp |= val;
354
                        registers.setDWCR0(tmp);
355
                } else {
356
                        tmp = registers.getDWCR1();
357
                        tmp &= mask;
358
                        tmp |= val;
359
                        registers.setDWCR1(tmp);
360
                }
361
        }
362
 
363
 
364
        public chainType getCounterChainType(int whichCounter) {
365
                int src = (int)((registers.getDMR1() >> (16+(2*whichCounter))) & 0x3);
366
                chainType ret = chainType.NONE;
367
                switch(src) {
368
                        case 0:
369
                                ret = chainType.NONE;
370
                                break;
371
                        case 1:
372
                                ret = chainType.AND;
373
                                break;
374
                        case 2:
375
                                ret = chainType.OR;
376
                                break;
377
                }
378
                return ret;
379
        }
380
 
381
        public void setCounterChainType(int whichCounter, chainType type) {
382
                long val = 0;
383
                switch(type) {
384
                case NONE:
385
                        val = 0;
386
                        break;
387
                case AND:
388
                        val = 1;
389
                        break;
390
                case OR:
391
                        val = 2;
392
                        break;
393
                }
394
                val = val << (16+(2*whichCounter));
395
                long mask = 3 << (16+(2*whichCounter));
396
                long tmp = registers.getDMR1();
397
                tmp &= (~mask);
398
                tmp |= val;
399
                registers.setDMR1(tmp);
400
        }
401
 
402
        public void setDVR(int which, long val) {
403
                registers.setDVR(which, val);
404
        }
405
 
406
        public long getDVR(int which) {
407
                return registers.getDVR(which);
408
        }
409
 
410
}

powered by: WebSVN 2.1.0

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