OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [orpsocv2/] [sw/] [tests/] [or1200/] [board/] [or1200-configdetect.c] - Blame information for rev 509

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 466 julius
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////                                                              ////
4
//// OR1K configuration detection software                        ////
5
////                                                              ////
6
//// Description:                                                 ////
7
////             Determine capabilities of OR1K processor.        ////
8
////                                                              ////
9
//// Author(s):                                                   ////
10
////            Julius Baxter, julius@opencores.org               ////
11
////                                                              ////
12
//// TODO:                                                        ////
13
////      Add further tests for optional parts of OR1K.           ////
14
////                                                              ////
15
////                                                              ////
16
//////////////////////////////////////////////////////////////////////
17
////                                                              ////
18
//// Copyright (C) 2010 Authors and OPENCORES.ORG                 ////
19
////                                                              ////
20
//// This source file may be used and distributed without         ////
21
//// restriction provided that this copyright statement is not    ////
22
//// removed from the file and that any derivative work contains  ////
23
//// the original copyright notice and the associated disclaimer. ////
24
////                                                              ////
25
//// This source file is free software; you can redistribute it   ////
26
//// and/or modify it under the terms of the GNU Lesser General   ////
27
//// Public License as published by the Free Software Foundation; ////
28
//// either version 2.1 of the License, or (at your option) any   ////
29
//// later version.                                               ////
30
////                                                              ////
31
//// This source is distributed in the hope that it will be       ////
32
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
33
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
34
//// PURPOSE.  See the GNU Lesser General Public License for more ////
35
//// details.                                                     ////
36
////                                                              ////
37
//// You should have received a copy of the GNU Lesser General    ////
38
//// Public License along with this source; if not, download it   ////
39
//// from http://www.opencores.org/lgpl.shtml                     ////
40
////                                                              ////
41
//////////////////////////////////////////////////////////////////////
42
 
43
#include "cpu-utils.h"
44
#include "spr-defs.h"
45
#include "board.h"
46
#include "uart.h"
47
#include "printf.h"
48
 
49
 
50
int illegal_instruction;
51
 
52
int
53
print_or1k_upr(unsigned long upr)
54
{
55
 
56
        if (!(SPR_UPR_UP & upr))
57
        {
58
                printf("UPR not present. Cannot determine present units\n");
59
                return 1;
60
        }
61
 
62
        printf("\nOptional units present:\n");
63
 
64
 
65
        if (upr & SPR_UPR_DCP)
66
                printf("Data Cache\n");
67
 
68
        if (upr & SPR_UPR_ICP)
69
                printf("Instruction Cache\n");
70
 
71
        if (upr & SPR_UPR_DMP)
72
                printf("Data MMU\n");
73
 
74
        if (upr & SPR_UPR_IMP)
75
                printf("Instruction MMU\n");
76
 
77
        if (upr & SPR_UPR_MP)
78
                printf("MAC Unit\n");
79
 
80
        if (upr & SPR_UPR_DUP)
81
                printf("Debug Unit\n");
82
 
83
        if (upr & SPR_UPR_PCUP)
84
                printf("Performance Counters Unit\n");
85
 
86
        if (upr & SPR_UPR_PMP)
87
                printf("Power Management Unit\n");
88
 
89
        if (upr & SPR_UPR_PICP)
90
                printf("Programmable Interrupt Controller\n");
91
 
92
        if (upr & SPR_UPR_TTP)
93
                printf("Tick Timer\n");
94
 
95
        if (upr & SPR_UPR_CUP)
96
                printf("Context units\n");
97
 
98
        return 0;
99
}
100
 
101
void
102
print_or1k_dc_config (void)
103
{
104
        unsigned long dccfgr = mfspr(SPR_DCCFGR);
105
 
106
        unsigned long ways, sets, bs;
107
 
108
        ways = (1 << (dccfgr & SPR_DCCFGR_NCW));
109
 
110
        sets = (1 << ((dccfgr & SPR_DCCFGR_NCS)>> SPR_DCCFGR_NCS_OFF));
111
 
112
        bs = ((dccfgr & SPR_DCCFGR_CBS) == SPR_DCCFGR_CBS) ? 32 : 16;
113
 
114
        printf("\nData Cache capabilities:\n");
115
 
116
        printf("Ways:\t%d\t", ways);
117
 
118
        printf("Sets:\t%d\t", sets);
119
 
120
        printf("Block size: %d\n", bs);
121
 
122
        printf("Total size: %d kByte\n", (ways * sets * bs) / 1024);
123
 
124
        printf("Write strategy:\t\t\t\t\t%s\n",
125
               ((dccfgr & SPR_DCCFGR_CWS) == SPR_DCCFGR_CWS) ?
126
               "write-back" : "write-through");
127
 
128
        printf("Cache control register:\t\t\t\t%s\n",
129
               ((dccfgr & SPR_DCCFGR_CCRI) == SPR_DCCFGR_CCRI) ?
130
               "implemented" : "not implemented");
131
 
132
        printf("Cache block invalidate capability:\t\t%s\n",
133
               ((dccfgr & SPR_DCCFGR_CBIRI) == SPR_DCCFGR_CBIRI) ?
134
               "implemented" : "not implemented");
135
 
136
        printf("Cache block prefetch capability:\t\t%s\n",
137
               ((dccfgr & SPR_DCCFGR_CBPRI) == SPR_DCCFGR_CBPRI) ?
138
               "implemented" : "not implemented");
139
 
140
        printf("Cache block lock capability:\t\t\t%s\n",
141
               ((dccfgr & SPR_DCCFGR_CBLRI) == SPR_DCCFGR_CBLRI) ?
142
               "implemented" : "not implemented");
143
 
144
        printf("Cache block flush capability:\t\t\t%s\n",
145
               ((dccfgr & SPR_DCCFGR_CBFRI) == SPR_DCCFGR_CBFRI) ?
146
               "implemented" : "not implemented");
147
 
148
        printf("Cache block write-back capability:\t\t%s\n",
149
               ((dccfgr & SPR_DCCFGR_CBWBRI) == SPR_DCCFGR_CBWBRI) ?
150
               "implemented" : "not implemented");
151
 
152
}
153
 
154
void
155
print_or1k_dmmu_config(void)
156
{
157
        unsigned long dmmucfgr = mfspr(SPR_DMMUCFGR);
158
 
159
        printf("\nDMMU Capabilities:\n");
160
 
161
        printf("TLB Ways:\t%d",
162
               (dmmucfgr & SPR_DMMUCFGR_NTW) + 1);
163
 
164
        printf("\tTLB Sets:\t%d",
165
               1 << ((dmmucfgr & SPR_DMMUCFGR_NTS)>> SPR_DMMUCFGR_NTS_OFF));
166
 
167
        printf("\tATB:\t");
168
        if (!(dmmucfgr & SPR_DMMUCFGR_NAE))
169
                printf("none");
170
        else
171
                printf("%d", (dmmucfgr & SPR_DMMUCFGR_NAE)>>5);
172
 
173
        printf("\n");
174
 
175
        printf("Control register:\t\t\t\t%s\n",
176
               ((dmmucfgr & SPR_DMMUCFGR_CRI) == SPR_DMMUCFGR_CRI) ?
177
               "implemented" : "not implemented");
178
 
179
        printf("Protection register:\t\t\t\t%s\n",
180
               ((dmmucfgr & SPR_DMMUCFGR_PRI) == SPR_DMMUCFGR_PRI) ?
181
               "implemented" : "not implemented");
182
 
183
        printf("Invalidate entry register:\t\t\t%s\n",
184
               ((dmmucfgr & SPR_DMMUCFGR_TEIRI) == SPR_DMMUCFGR_TEIRI) ?
185
               "implemented" : "not implemented");
186
 
187
        printf("TLB reload:\t\t\t\t\t%sware\n",
188
               ((dmmucfgr & SPR_DMMUCFGR_HTR) == SPR_DMMUCFGR_HTR) ?
189
               "hard" : "soft");
190
 
191
}
192
 
193
void
194
print_or1k_immu_config(void)
195
{
196
        unsigned long immucfgr = mfspr(SPR_IMMUCFGR);
197
 
198
        printf("\nIMMU Capabilities:\n");
199
 
200
        printf("TLB Ways:\t%d",
201
               (immucfgr & SPR_IMMUCFGR_NTW) + 1);
202
 
203
        printf("\tTLB Sets:\t%d",
204
               1 << ((immucfgr & SPR_IMMUCFGR_NTS)>> SPR_IMMUCFGR_NTS_OFF));
205
 
206
        printf("\tATB:\t");
207
        if (!(immucfgr & SPR_IMMUCFGR_NAE))
208
                printf("none");
209
        else
210
                printf("%d", (immucfgr & SPR_IMMUCFGR_NAE)>>5);
211
 
212
        printf("\n");
213
 
214
        printf("Control register:\t\t\t\t%s\n",
215
               ((immucfgr & SPR_IMMUCFGR_CRI) == SPR_IMMUCFGR_CRI) ?
216
               "implemented" : "not implemented");
217
 
218
        printf("Protection register:\t\t\t\t%s\n",
219
               ((immucfgr & SPR_IMMUCFGR_PRI) == SPR_IMMUCFGR_PRI) ?
220
               "implemented" : "not implemented");
221
 
222
        printf("Invalidate entry register:\t\t\t%s\n",
223
               ((immucfgr & SPR_IMMUCFGR_TEIRI) == SPR_IMMUCFGR_TEIRI) ?
224
               "implemented" : "not implemented");
225
 
226
        printf("TLB reload:\t\t\t\t\t%sware\n",
227
               ((immucfgr & SPR_IMMUCFGR_HTR) == SPR_IMMUCFGR_HTR) ?
228
               "hard" : "soft");
229
 
230
}
231
 
232
void
233
print_or1k_ic_config (void)
234
{
235
        unsigned long iccfgr = mfspr(SPR_ICCFGR);
236
 
237
        unsigned long ways, sets, bs;
238
 
239
        printf("\nInstruction Cache capabilities:\n");
240
 
241
        ways = (1 << (iccfgr & SPR_ICCFGR_NCW));
242
 
243
        sets = (1 << ((iccfgr & SPR_ICCFGR_NCS)>> SPR_ICCFGR_NCS_OFF));
244
 
245
        bs = ((iccfgr & SPR_ICCFGR_CBS) == SPR_ICCFGR_CBS) ? 32 : 16;
246
 
247
        printf("Ways:\t%d\t", ways);
248
 
249
        printf("Sets:\t%d\t", sets);
250
 
251
        printf("Block size: %d\n", bs);
252
 
253
        printf("Total size: %d kByte\n", (ways * sets * bs) / 1024);
254
 
255
        printf("Cache control register:\t\t\t\t%s\n",
256
               ((iccfgr & SPR_ICCFGR_CCRI) == SPR_ICCFGR_CCRI) ?
257
               "implemented" : "not implemented");
258
 
259
        printf("Cache block invalidate capability:\t\t%s\n",
260
               ((iccfgr & SPR_ICCFGR_CBIRI) == SPR_ICCFGR_CBIRI) ?
261
               "implemented" : "not implemented");
262
 
263
        printf("Cache block prefetch capability:\t\t%s\n",
264
               ((iccfgr & SPR_ICCFGR_CBPRI) == SPR_ICCFGR_CBPRI) ?
265
               "implemented" : "not implemented");
266
 
267
        printf("Cache block lock capability:\t\t\t%s\n",
268
               ((iccfgr & SPR_ICCFGR_CBLRI) == SPR_ICCFGR_CBLRI) ?
269
               "implemented" : "not implemented");
270
 
271
}
272
 
273
void
274
print_or1k_cpu_config(void)
275
{
276
        unsigned long cpucfgr = mfspr(SPR_CPUCFGR);
277
 
278
        printf("\nCPU Capabilities:\n");
279
 
280
        printf("Shadow GPR files: %d\n",(cpucfgr & SPR_CPUCFGR_NSGF));
281
 
282
        printf("GPR file size: %s\n",
283
               ((cpucfgr & SPR_CPUCFGR_CGF)==SPR_CPUCFGR_CGF) ? "<32" : "32");
284
 
285
        printf("ORBIS32: %ssupported\n",
286
               ((cpucfgr & SPR_CPUCFGR_OB32S)==SPR_CPUCFGR_OB32S) ?"":"not ");
287
 
288
        printf("ORBIS64: %ssupported\n",
289
               ((cpucfgr & SPR_CPUCFGR_OB64S)==SPR_CPUCFGR_OB64S) ?"":"not ");
290
 
291
        printf("ORFPX32: %ssupported\n",
292
               ((cpucfgr & SPR_CPUCFGR_OF32S)==SPR_CPUCFGR_OF32S) ?"":"not ");
293
 
294
        printf("ORFPX64: %ssupported\n",
295
               ((cpucfgr & SPR_CPUCFGR_OF64S)==SPR_CPUCFGR_OF64S) ?"":"not ");
296
 
297
        printf("ORVDX64: %ssupported\n",
298
               ((cpucfgr & SPR_CPUCFGR_OV64S)==SPR_CPUCFGR_OV64S) ?"":"not ");
299
}
300
 
301
void
302
print_or1k_version_reg(void)
303
{
304
        unsigned long vr = mfspr(SPR_VR);
305
 
306
        printf("\nVersion Register\n");
307
 
308
        printf("Version:\t0x%2x",(vr & SPR_VR_VER) >> SPR_VR_VER_OFF);
309
        printf("\tConfig:\t%d",(vr & SPR_VR_CFG) >> SPR_VR_CFG_OFF);
310
        printf("\tRevision:\t%d",(vr & SPR_VR_REV));
311
        printf("\n");
312
}
313
void
314
print_or1k_du_config(void)
315
{
316
        unsigned long dcfgr = mfspr(SPR_DCFGR);
317
 
318
        printf("\nDebug Unit Capabilities:\n");
319
 
320
        printf("Debug Pairs: %d\n",
321
               (dcfgr & SPR_DCFGR_NDP) + 1);
322
 
323
        printf("Watchpoint counters:\t\t\t\t%simplemented\n",
324
               ((dcfgr & SPR_DCFGR_WPCI)==SPR_DCFGR_WPCI) ?"":"not ");
325
}
326
 
327
/* Handler for illegal instructions, to indicate if the exception was tripped */
328
void
329
illegal_insn_handler(void)
330
{
331
        // Step past illegal instruction
332
        unsigned long epcr = mfspr(SPR_EPCR_BASE);
333
        epcr += 4;
334
        mtspr(SPR_EPCR_BASE,epcr);
335
        illegal_instruction = 1;
336
        return;
337
}
338
 
339
/* Call function we passed, return 1 if supported by hardware, 0 if not */
340
int
341
or1k_insn_hw_support_detect(void (* function)(void))
342
{
343
        /* Install illegal instruction handler */
344
        add_handler(7, illegal_insn_handler);
345
 
346
        /* Clear illegal instruction indicator */
347
        illegal_instruction = 0;
348
 
349
        /* Call function that tests hardware support of an instruction,
350
           potentially resulting in illegal instruction exception occurring. */
351
        (*function)();
352
 
353
        return !illegal_instruction;
354
}
355
 
356
void
357
or1k_test_mul (void)
358
{
359
        volatile int a, b, c;
360
        a = b = 12;
361
        asm ("l.mul %0,%1,%2" : "=r" (c) : "r" (a), "r" (b));
362
        return;
363
}
364
 
365
void
366
or1k_test_div (void)
367
{
368
        volatile int a, b, c;
369
        a = b = 12;
370
        asm ("l.div %0,%1,%2" : "=r" (c) : "r" (a), "r" (b));
371
        return;
372
}
373
 
374
void
375
or1k_test_ff1 (void)
376
{
377
        volatile int a, b;
378
        a = b = 12;
379
        asm ("l.ff1 %0,%1" : "=r" (a) : "r" (b));
380
        return;
381
}
382
 
383
 
384
void
385
or1k_test_fl1 (void)
386
{
387
        volatile int a, b;
388
        a = b = 12;
389
        asm ("l.fl1 %0,%1" : "=r" (a) : "r" (b));
390
        return;
391
}
392
 
393
void
394
or1k_test_lfrem (void)
395
{
396
        volatile int a, b, c;
397
        a = b = 12;
398
        asm ("lf.rem.s %0,%1,%2" : "=r" (c) : "r" (a), "r" (b));
399
        return;
400
}
401
 
402
void
403
print_or1k_insn_support (char* insnname,void (* function)(void))
404
{
405
 
406
        printf("\n%s instruction:\t %ssupported by hardware\n", insnname,
407
               or1k_insn_hw_support_detect(function) ? "" : "not ");
408
}
409
 
410
int
411
main (void)
412
{
413
 
414
        unsigned long upr;
415
 
416
        uart_init(DEFAULT_UART);
417
 
418
        printf("\nOR1200 capability detection\n");
419
 
420
        print_or1k_cpu_config();
421
 
422
        print_or1k_version_reg();
423
 
424
        /* Unit present register */
425
        upr = mfspr(SPR_UPR);
426
 
427
        if (print_or1k_upr(upr))
428
                /* No UPR - can't tell what's here */
429
                return 0;
430
 
431
        if (upr & SPR_UPR_DCP)
432
                print_or1k_dc_config();
433
 
434
        if (upr & SPR_UPR_ICP)
435
                print_or1k_ic_config();
436
 
437
        if (upr & SPR_UPR_DMP)
438
                print_or1k_dmmu_config();
439
 
440
        if (upr & SPR_UPR_IMP)
441
                print_or1k_immu_config();
442
 
443
        if (upr & SPR_UPR_DUP)
444
                print_or1k_du_config();
445
 
446
        /* Now test for supported instructions */
447
        print_or1k_insn_support("Multiply", or1k_test_mul);
448
        print_or1k_insn_support("Multiply", or1k_test_mul);
449
        print_or1k_insn_support("Divide", or1k_test_div);
450
        print_or1k_insn_support("Find first '1'", or1k_test_ff1);
451
        print_or1k_insn_support("Find last '1'", or1k_test_fl1);
452
        print_or1k_insn_support("Floating remainder", or1k_test_lfrem);
453
 
454
        printf("End of capabilities testing\n");
455
 
456
}

powered by: WebSVN 2.1.0

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