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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_47/] [or1ksim/] [testbench/] [except_test.c] - Blame information for rev 956

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

Line No. Rev Author Line
1 516 markom
/* This is exception test for OpenRISC 1200 */
2
 
3
#include "spr_defs.h"
4
#include "support.h"
5
#include "int.h"
6
 
7
/* Define RAM physical location and size
8
   Bottom half will be used for this program, the rest
9
   will be used for testing */
10
#define FLASH_START 0x00000000
11
#define FLASH_SIZE  0x00200000
12 619 markom
#define RAM_START   0x40000000
13 516 markom
#define RAM_SIZE    0x00200000
14
 
15
/* MMU page size */
16
#define PAGE_SIZE 8192
17
 
18
/* Number of DTLB sets used (power of 2, max is 256) */
19
#define DTLB_SETS 32
20
 
21
/* Number of DTLB ways (2, 2, 3 etc., max is 4). */
22
#define DTLB_WAYS 1
23
 
24
/* Number of ITLB sets used (power of 2, max is 256) */
25
#define ITLB_SETS 32
26
 
27
/* Number of ITLB ways (1, 2, 3 etc., max is 4). */
28
#define ITLB_WAYS 1
29
 
30
/* TLB mode codes */
31
#define TLB_CODE_ONE_TO_ONE     0x00000000
32
#define TLB_CODE_PLUS_ONE_PAGE  0x10000000
33
#define TLB_CODE_MINUS_ONE_PAGE 0x20000000
34
 
35
#define TLB_TEXT_SET_NB 6
36
#define TLB_DATA_SET_NB 2
37
 
38
#define TLB_CODE_MASK   0xfffff000
39
#define TLB_PR_MASK     0x00000fff
40
#define DTLB_PR_NOLIMIT  ( SPR_DTLBTR_CI   | \
41
                          SPR_DTLBTR_URE  | \
42
                          SPR_DTLBTR_UWE  | \
43
                          SPR_DTLBTR_SRE  | \
44
                          SPR_DTLBTR_SWE  )
45
 
46
#define ITLB_PR_NOLIMIT  ( SPR_ITLBTR_CI   | \
47
                          SPR_ITLBTR_SXE  | \
48
                          SPR_ITLBTR_UXE  )
49
 
50
/* fails if x is false */
51
#define ASSERT(x) ((x)?1: fail (__FUNCTION__, __LINE__))
52
 
53
/* Exception vectors */
54
#define V_RESET       1
55
#define V_BERR        2
56
#define V_DPF         3
57
#define V_IPF         4
58 600 simons
#define V_TICK        5
59 516 markom
#define V_ALIGN       6
60
#define V_ILLINSN     7
61 600 simons
#define V_INT         8
62 516 markom
#define V_DTLB_MISS   9
63
#define V_ITLB_MISS   10
64
#define V_RANGE       11
65
#define V_SYS         12
66
#define V_TRAP        14
67
 
68
#if 1
69
#define debug printf
70
#else
71
#define debug
72
#endif
73
 
74
/* Extern functions */
75
extern void lo_dmmu_en (void);
76
extern void lo_immu_en (void);
77
extern unsigned long call (unsigned long add, unsigned long val);
78
extern unsigned long call_with_int (unsigned long add, unsigned long val);
79
extern void trap (void);
80
extern void b_trap (void);
81
extern void range (void);
82
extern void b_range (void);
83
extern int except_basic (void);
84
extern void (*test)(void);
85
extern int load_acc_32 (unsigned long add);
86
extern int load_acc_16 (unsigned long add);
87
extern int store_acc_32 (unsigned long add);
88
extern int store_acc_16 (unsigned long add);
89
extern int load_b_acc_32 (unsigned long add);
90
extern int int_trigger (void);
91
extern int int_loop (void);
92
extern int jump_back (void);
93
 
94
/* Local functions prototypes */
95
void dmmu_disable (void);
96
void immu_disable (void);
97
 
98
/* DTLB mode status */
99
volatile unsigned long dtlb_val;
100
 
101
/* ITLB mode status */
102
volatile unsigned long itlb_val;
103
 
104
/* Exception counter */
105
volatile int except_count;
106
 
107
/* Exception mask */
108
volatile unsigned long except_mask;
109
 
110
/* Exception efective address */
111
volatile unsigned long except_ea;
112
 
113
/* Eception PC */
114
volatile unsigned long except_pc;
115
 
116 956 simons
unsigned long  excpt_buserr;
117
unsigned long excpt_dpfault;
118
unsigned long excpt_ipfault;
119
unsigned long excpt_tick;
120
unsigned long excpt_align;
121
unsigned long excpt_illinsn;
122
unsigned long excpt_int;
123
unsigned long excpt_dtlbmiss;
124
unsigned long excpt_itlbmiss;
125
unsigned long excpt_range;
126
unsigned long excpt_syscall;
127
unsigned long excpt_break;
128
unsigned long excpt_trap;
129
 
130
 
131 516 markom
void fail (char *func, int line)
132
{
133
#ifndef __FUNCTION__
134
#define __FUNCTION__ "?"
135
#endif
136
 
137
  immu_disable ();
138
  dmmu_disable ();
139
 
140
  debug("Test failed in %s:%i\n", func, line);
141
  report (0xeeeeeeee);
142
  exit (1);
143
}
144
 
145
void test_dummy (void)
146
{
147
        asm("_test:");
148
        asm("l.addi\t\tr3,r3,1") ;
149
        asm("l.nop" : :);
150
}
151
 
152
void copy_test (unsigned long phy_add)
153
{
154
        memcpy((void *)phy_add, (void *)&test, 8);
155
}
156
 
157
/* Bus error handler */
158
void bus_err_handler (void)
159
{
160
 
161
  except_mask |= 1 << V_BERR;
162
  except_count++;
163
}
164
 
165
/* Illegal insn handler */
166
void ill_insn_handler (void)
167
{
168
 
169
  except_mask |= 1 << V_ILLINSN;
170
  except_count++;
171
}
172
 
173
/* Low priority interrupt handler */
174 600 simons
void tick_handler (void)
175 516 markom
{
176
 
177
  /* Disable interrupt recognition */
178 600 simons
  mtspr(SPR_ESR_BASE, mfspr(SPR_ESR_BASE) & ~SPR_SR_TEE);
179 516 markom
 
180 600 simons
  except_mask |= 1 << V_TICK;
181 516 markom
  except_count++;
182
}
183
 
184
/* High priority interrupt handler */
185 600 simons
void int_handler (void)
186 516 markom
{
187
 
188
  /* Disable interrupt recognition */
189 600 simons
  mtspr(SPR_ESR_BASE, mfspr(SPR_ESR_BASE) & ~SPR_SR_IEE);
190 516 markom
 
191 600 simons
  except_mask |= 1 << V_INT;
192 516 markom
  except_count++;
193
}
194
 
195
/* Trap handler */
196
void trap_handler (void)
197
{
198
 
199
  except_mask |= 1 << V_TRAP;
200
  except_count++;
201
}
202
 
203
/* Align handler */
204
void align_handler (void)
205
{
206
 
207
  except_mask |= 1 << V_ALIGN;
208
  except_count++;
209
}
210
 
211
/* Range handler */
212
void range_handler (void)
213
{
214
  /* Disable range exception */
215
  mtspr (SPR_ESR_BASE, mfspr (SPR_ESR_BASE) & ~SPR_SR_OVE);
216
 
217
  except_mask |= 1 << V_RANGE;
218
  except_count++;
219
}
220
 
221
/* DTLB miss exception handler */
222
void dtlb_miss_handler (void)
223
{
224
  unsigned long ea;
225
  int set, way = 0;
226
  int i;
227
 
228
  /* Get EA that cause the exception */
229
  ea = mfspr (SPR_EEAR_BASE);
230
 
231
  /* Find TLB set and LRU way */
232
  set = (ea / PAGE_SIZE) % DTLB_SETS;
233
  for (i = 0; i < DTLB_WAYS; i++) {
234
    if ((mfspr (SPR_DTLBMR_BASE(i) + set) & SPR_DTLBMR_LRU) == 0) {
235
      way = i;
236
      break;
237
    }
238
  }
239
 
240
  mtspr (SPR_DTLBMR_BASE(way) + set, (ea & SPR_DTLBMR_VPN) | SPR_DTLBMR_V);
241
  mtspr (SPR_DTLBTR_BASE(way) + set, (ea & SPR_DTLBTR_PPN) | dtlb_val);
242
 
243
  except_mask |= 1 << V_DTLB_MISS;
244
  except_count++;
245
}
246
 
247
/* ITLB miss exception handler */
248
void itlb_miss_handler (void)
249
{
250
  unsigned long ea;
251
  int set, way = 0;
252
  int i;
253
 
254
  /* Get EA that cause the exception */
255
  ea = mfspr (SPR_EEAR_BASE);
256
 
257
  /* Find TLB set and LRU way */
258
  set = (ea / PAGE_SIZE) % ITLB_SETS;
259
  for (i = 0; i < ITLB_WAYS; i++) {
260
    if ((mfspr (SPR_ITLBMR_BASE(i) + set) & SPR_ITLBMR_LRU) == 0) {
261
      way = i;
262
      break;
263
    }
264
  }
265
 
266
  mtspr (SPR_ITLBMR_BASE(way) + set, (ea & SPR_ITLBMR_VPN) | SPR_ITLBMR_V);
267
  mtspr (SPR_ITLBTR_BASE(way) + set, (ea & SPR_ITLBTR_PPN) | itlb_val);
268
  except_mask |= 1 << V_ITLB_MISS;
269
  except_count++;
270
}
271
 
272
/* Data page fault exception handler */
273
void dpage_fault_handler (void)
274
{
275
  unsigned long ea;
276
  int set, way = 0;
277
  int i;
278
 
279
  /* Get EA that cause the exception */
280
  ea = mfspr (SPR_EEAR_BASE);
281
 
282
  /* Find TLB set and way */
283
  set = (ea / PAGE_SIZE) % DTLB_SETS;
284
  for (i = 0; i < DTLB_WAYS; i++) {
285
    if ((mfspr (SPR_DTLBMR_BASE(i) + set) & SPR_DTLBMR_VPN) == (ea & SPR_DTLBMR_VPN)) {
286
      way = i;
287
      break;
288
    }
289
  }
290
 
291
  /* Give permission */
292
  mtspr (SPR_DTLBTR_BASE(way) + set, (mfspr (SPR_DTLBTR_BASE(way) + set) & ~DTLB_PR_NOLIMIT) | dtlb_val);
293
 
294
  except_mask |= 1 << V_DPF;
295
  except_count++;
296
}
297
 
298
/* Intstruction page fault exception handler */
299
void ipage_fault_handler (void)
300
{
301
  unsigned long ea;
302
  int set, way = 0;
303
  int i;
304
 
305
  /* Get EA that cause the exception */
306
  ea = mfspr (SPR_EEAR_BASE);
307
 
308
  /* Find TLB set and way */
309
  set = (ea / PAGE_SIZE) % ITLB_SETS;
310
  for (i = 0; i < ITLB_WAYS; i++) {
311
    if ((mfspr (SPR_ITLBMR_BASE(i) + set) & SPR_ITLBMR_VPN) == (ea & SPR_ITLBMR_VPN)) {
312
      way = i;
313
      break;
314
    }
315
  }
316
 
317
  /* Give permission */
318
  mtspr (SPR_ITLBTR_BASE(way) + set, (mfspr (SPR_ITLBTR_BASE(way) + set) & ~ITLB_PR_NOLIMIT) | itlb_val);
319
 
320
  except_mask |= 1 << V_IPF;
321
  except_count++;
322
}
323
 
324
/*Enable DMMU */
325
void dmmu_enable (void)
326
{
327
  /* Enable DMMU */
328
  lo_dmmu_en ();
329
}
330
 
331
/* Disable DMMU */
332
void dmmu_disable (void)
333
{
334
  mtspr (SPR_SR, mfspr (SPR_SR) & ~SPR_SR_DME);
335
}
336
 
337
/* Enable IMMU */
338
void immu_enable (void)
339
{
340
  /* Enable IMMU */
341
  lo_immu_en ();
342
}
343
 
344
/* Disable IMMU */
345
void immu_disable (void)
346
{
347
  mtspr (SPR_SR, mfspr (SPR_SR) & ~SPR_SR_IME);
348
}
349
 
350
/* Tick timer init */
351
void tick_init (int period, int hp_int)
352
{
353 600 simons
  /* Disable tick timer exception recognition */
354
  mtspr(SPR_SR, mfspr(SPR_SR) & ~SPR_SR_TEE);
355 516 markom
 
356
  /* Set period of one cycle, restartable mode */
357
  mtspr(SPR_TTMR, SPR_TTMR_IE | SPR_TTMR_RT | (period & SPR_TTMR_PERIOD));
358
 
359
  /* Reset counter */
360
  mtspr(SPR_TTCR, 0);
361
}
362
 
363
/* Interrupt test */
364
int interrupt_test (void)
365
{
366
  unsigned long ret;
367
  int i;
368
 
369
  /* Init tick timer */
370
  tick_init (1, 1);
371
 
372
  /* Reset except counter */
373
  except_count = 0;
374
  except_mask = 0;
375
  except_pc = 0;
376
  except_ea = 0;
377
 
378
  /* Test normal high priority interrupt trigger */
379
  ret = call ((unsigned long)&int_trigger, 0);
380
  ASSERT(except_count == 1);
381 600 simons
  ASSERT(except_mask == (1 << V_TICK));
382 516 markom
  ASSERT(ret == 0);
383
  ASSERT(except_pc == (unsigned long)int_trigger + 16);
384
 
385
  /* Reset except counter */
386
  except_count = 0;
387
  except_mask = 0;
388
  except_pc = 0;
389
  except_ea = 0;
390
 
391
  /* Test inetrrupt in delay slot */
392 612 simons
  tick_init (100, 1);
393 516 markom
 
394
  /* Hopefully we will have interrupt recognition between branch insn and delay slot */
395
  except_pc = (unsigned long)&int_loop;
396
  for (i = 0; i < 10; i++) {
397
    call_with_int (except_pc, RAM_START);
398
    ASSERT(except_pc == (unsigned long)&int_loop);
399
  }
400
 
401
  return 0;
402
}
403
 
404
/* ITLB miss test */
405
int itlb_test (void)
406
{
407
  int i, j, ret;
408
  unsigned long ea, ta;
409
 
410
  /* Invalidate all entries in ITLB */
411
  for (i = 0; i < ITLB_WAYS; i++) {
412
    for (j = 0; j < ITLB_SETS; j++) {
413
      mtspr (SPR_ITLBMR_BASE(i) + j, 0);
414
      mtspr (SPR_ITLBTR_BASE(i) + j, 0);
415
    }
416
  }
417
 
418
  /* Set one to one translation for the use of this program */
419
  for (i = 0; i < TLB_TEXT_SET_NB; i++) {
420
    ea = FLASH_START + (i*PAGE_SIZE);
421
    ta = FLASH_START + (i*PAGE_SIZE);
422
    mtspr (SPR_ITLBMR_BASE(0) + i, ea | SPR_ITLBMR_V);
423
    mtspr (SPR_ITLBTR_BASE(0) + i, ta | ITLB_PR_NOLIMIT);
424
  }
425
 
426
  /* Set dtlb no permisions */
427
  itlb_val = SPR_ITLBTR_CI;
428
 
429
  /* Reset except counter */
430
  except_count = 0;
431
  except_mask = 0;
432
  except_pc = 0;
433
  except_ea = 0;
434
 
435
  /* Enable IMMU */
436
  immu_enable ();
437
 
438
  /* Copy jump instruction to last location of a page */
439
  ea = RAM_START + (RAM_SIZE/2) + ((TLB_TEXT_SET_NB + 1)*PAGE_SIZE) - 8;
440
  memcpy((void *)ea, (void *)&jump_back, 12);
441
 
442
  /* Check if there was ITLB miss exception */
443
  ret = call (ea, 0);
444
  ASSERT(except_count == 1);
445
  ASSERT(except_mask == (1 << V_ITLB_MISS));
446
  ASSERT(except_pc == ea);
447
  ASSERT(ret == 0);
448
 
449
  /* Set dtlb no permisions */
450
  itlb_val = SPR_ITLBTR_CI | SPR_ITLBTR_SXE;
451
 
452
  /* Reset except counter */
453
  except_count = 0;
454
  except_mask = 0;
455
  except_pc = 0;
456
  except_ea = 0;
457
 
458
  /* Check if there was IPF miss exception */
459
  ret = call (ea, 0);
460
  ASSERT(except_count == 1);
461
  ASSERT(except_mask == (1 << V_IPF));
462
  ASSERT(except_pc == ea);
463
  ASSERT(ret == 0);
464
 
465
  /* Set dtlb no permisions */
466
  itlb_val = SPR_ITLBTR_CI;
467
 
468
  /* Reset except counter */
469
  except_count = 0;
470
  except_mask = 0;
471
  except_pc = 0;
472
  except_ea = 0;
473
 
474
  /* Check if there was ITLB miss exception */
475
  ret = call (ea, 0);
476
  ASSERT(except_count == 1);
477
  ASSERT(except_mask == (1 << V_ITLB_MISS));
478
  ASSERT(except_pc == ea + 4);
479
  ASSERT(ret == 0);
480
 
481
  /* Set dtlb no permisions */
482
  itlb_val = SPR_ITLBTR_CI | SPR_ITLBTR_SXE;
483
 
484
  /* Reset except counter */
485
  except_count = 0;
486
  except_mask = 0;
487
  except_pc = 0;
488
  except_ea = 0;
489
 
490
  /* Check if there was IPF exception */
491
  ret = call (ea, 0);
492
  ASSERT(except_count == 1);
493
  ASSERT(except_mask == (1 << V_IPF));
494
  ASSERT(except_pc == ea + 4);
495
  ASSERT(ret == 0);
496
 
497
  /* Reset except counter */
498
  except_count = 0;
499
  except_mask = 0;
500
  except_pc = 0;
501
  except_ea = 0;
502
 
503
  ret = call (ea, 0);
504
  ASSERT(except_count == 0);
505
  ASSERT(ret == 1);
506
 
507
  /* Disable IMMU */
508
  immu_disable ();
509
 
510
  return 0;
511
}
512
 
513
/* DTLB miss test */
514
int dtlb_test (void)
515
{
516
  int i, j, ret;
517
  unsigned long ea, ta;
518
 
519
  /* Invalidate all entries in DTLB */
520
  for (i = 0; i < DTLB_WAYS; i++) {
521
    for (j = 0; j < DTLB_SETS; j++) {
522
      mtspr (SPR_DTLBMR_BASE(i) + j, 0);
523
      mtspr (SPR_DTLBTR_BASE(i) + j, 0);
524
    }
525
  }
526
 
527
  /* Set one to one translation for the use of this program */
528
  for (i = 0; i < TLB_DATA_SET_NB; i++) {
529
    ea = RAM_START + (i*PAGE_SIZE);
530
    ta = RAM_START + (i*PAGE_SIZE);
531
    mtspr (SPR_DTLBMR_BASE(0) + i, ea | SPR_ITLBMR_V);
532
    mtspr (SPR_DTLBTR_BASE(0) + i, ta | DTLB_PR_NOLIMIT);
533
  }
534
 
535
  /* Set dtlb no permisions */
536
  dtlb_val = SPR_DTLBTR_CI;
537
 
538
  /* Reset except counter */
539
  except_count = 0;
540
  except_mask = 0;
541
  except_pc = 0;
542
  except_ea = 0;
543
 
544
  /* Set pattern */
545
  ea = RAM_START + (RAM_SIZE/2) + ((TLB_DATA_SET_NB)*PAGE_SIZE);
546
  REG32(ea) = 0x87654321;
547
 
548
  /* Enable DMMU */
549
  dmmu_enable ();
550
 
551
  /* Check if there was DTLB miss exception */
552
  ret = call ((unsigned long)&load_b_acc_32, ea);
553
  ASSERT(except_count == 1);
554
  ASSERT(except_mask == (1 << V_DTLB_MISS));
555
  ASSERT(except_pc == (unsigned long)load_b_acc_32 + 8);
556
  ASSERT(except_ea == ea);
557
  ASSERT(ret == 0x12345678);
558
 
559
  /* Set dtlb no permisions */
560
  dtlb_val = SPR_DTLBTR_CI | SPR_DTLBTR_SRE;
561
 
562
  /* Reset except counter */
563
  except_count = 0;
564
  except_mask = 0;
565
  except_pc = 0;
566
  except_ea = 0;
567
 
568
  /* Check if there was DPF miss exception */
569
  ret = call ((unsigned long)&load_b_acc_32, ea);
570
  ASSERT(except_count == 1);
571
  ASSERT(except_mask == (1 << V_DPF));
572
  ASSERT(except_pc == (unsigned long)load_b_acc_32 + 8);
573
  ASSERT(except_ea == ea);
574
  ASSERT(ret == 0x12345678);
575
 
576
  /* Reset except counter */
577
  except_count = 0;
578
  except_mask = 0;
579
  except_pc = 0;
580
  except_ea = 0;
581
 
582
  ret = call ((unsigned long)&load_b_acc_32, ea);
583
  ASSERT(except_count == 0);
584
  ASSERT(ret == 0x87654321);
585
 
586
  /* Disable DMMU */
587
  dmmu_disable ();
588
 
589
  return 0;
590
}
591
 
592
/* Bus error test */
593
int buserr_test (void)
594
{
595
  int i, j, ret;
596
  unsigned long ea, ta;
597
 
598
  /* Invalidate all entries in ITLB */
599
  for (i = 0; i < ITLB_WAYS; i++) {
600
    for (j = 0; j < ITLB_SETS; j++) {
601
      mtspr (SPR_ITLBMR_BASE(i) + j, 0);
602
      mtspr (SPR_ITLBTR_BASE(i) + j, 0);
603
    }
604
  }
605
 
606
  /* Set one to one translation for the use of this program */
607
  for (i = 0; i < TLB_TEXT_SET_NB; i++) {
608
    ea = FLASH_START + (i*PAGE_SIZE);
609
    ta = FLASH_START + (i*PAGE_SIZE);
610
    mtspr (SPR_ITLBMR_BASE(0) + i, ea | SPR_ITLBMR_V);
611
    mtspr (SPR_ITLBTR_BASE(0) + i, ta | ITLB_PR_NOLIMIT);
612
  }
613
 
614
  /* Invalidate all entries in DTLB */
615
  for (i = 0; i < DTLB_WAYS; i++) {
616
    for (j = 0; j < DTLB_SETS; j++) {
617
      mtspr (SPR_DTLBMR_BASE(i) + j, 0);
618
      mtspr (SPR_DTLBTR_BASE(i) + j, 0);
619
    }
620
  }
621
 
622
  /* Set one to one translation for the use of this program */
623
  for (i = 0; i < TLB_DATA_SET_NB; i++) {
624
    ea = RAM_START + (i*PAGE_SIZE);
625
    ta = RAM_START + (i*PAGE_SIZE);
626
    mtspr (SPR_DTLBMR_BASE(0) + i, ea | SPR_ITLBMR_V);
627
    mtspr (SPR_DTLBTR_BASE(0) + i, ta | DTLB_PR_NOLIMIT);
628
  }
629
 
630
  /* Reset except counter */
631
  except_count = 0;
632
  except_mask = 0;
633
  except_pc = 0;
634
  except_ea = 0;
635
 
636
  /* Set IMMU translation */
637
  ea = RAM_START + (RAM_SIZE) + ((TLB_TEXT_SET_NB)*PAGE_SIZE);
638
  itlb_val = SPR_ITLBTR_CI | SPR_ITLBTR_SXE;
639
  mtspr (SPR_ITLBMR_BASE(0) + TLB_TEXT_SET_NB, (ea & SPR_ITLBMR_VPN) | SPR_ITLBMR_V);
640
  mtspr (SPR_ITLBTR_BASE(0) + TLB_TEXT_SET_NB, ((ea + PAGE_SIZE) & SPR_ITLBTR_PPN) | itlb_val);
641
 
642
  /* Enable IMMU */
643
  immu_enable ();
644
 
645
  /* Check if there was bus error exception */
646
  ret = call (ea, 0);
647
  ASSERT(except_count == 1);
648
  ASSERT(except_mask == (1 << V_BERR));
649
  ASSERT(except_pc == ea);
650 525 simons
  ASSERT(except_ea == ea);
651 516 markom
 
652
  /* Disable IMMU */
653
  immu_disable ();
654
 
655
  /* Reset except counter */
656
  except_count = 0;
657
  except_mask = 0;
658
  except_pc = 0;
659
  except_ea = 0;
660
 
661
  /* Copy jump instruction to last location of RAM */
662
  ea = RAM_START + RAM_SIZE - 8;
663
  memcpy((void *)ea, (void *)&jump_back, 8);
664
 
665
  /* Check if there was bus error exception */
666
  ret = call (ea, 0);
667
  ASSERT(except_count == 1);
668
  ASSERT(except_mask == (1 << V_BERR));
669
  ASSERT(except_pc == ea + 4);
670
  ASSERT(except_ea == ea + 8);
671
 
672
  /* Reset except counter */
673
  except_count = 0;
674
  except_mask = 0;
675
  except_pc = 0;
676
  except_ea = 0;
677
 
678
  /* Set DMMU translation */
679
  ea = RAM_START + (RAM_SIZE) + ((TLB_DATA_SET_NB)*PAGE_SIZE);
680
  dtlb_val = SPR_DTLBTR_CI | SPR_DTLBTR_SRE;
681
  mtspr (SPR_DTLBMR_BASE(0) + TLB_DATA_SET_NB, (ea & SPR_DTLBMR_VPN) | SPR_DTLBMR_V);
682
  mtspr (SPR_DTLBTR_BASE(0) + TLB_DATA_SET_NB, ((ea + PAGE_SIZE) & SPR_DTLBTR_PPN) | dtlb_val);
683
 
684
  /* Enable DMMU */
685
  dmmu_enable ();
686
 
687
  /* Check if there was bus error exception */
688
  ret = call ((unsigned long)&load_acc_32, ea );
689
  ASSERT(except_count == 1);
690
  ASSERT(except_mask == (1 << V_BERR));
691
  ASSERT(except_pc == (unsigned long)load_acc_32 + 8);
692 525 simons
  ASSERT(except_ea == ea);
693 516 markom
  ASSERT(ret == 0x12345678);
694
 
695
  /* Disable DMMU */
696
  dmmu_disable ();
697
 
698
  /* Reset except counter */
699
  except_count = 0;
700
  except_mask = 0;
701
  except_pc = 0;
702
  except_ea = 0;
703
 
704
  /* Check if there was bus error exception */
705
  ret = call ((unsigned long)&load_b_acc_32, ea );
706
  ASSERT(except_count == 1);
707
  ASSERT(except_mask == (1 << V_BERR));
708
  ASSERT(except_pc == (unsigned long)load_b_acc_32 + 8);
709
  ASSERT(except_ea == ea);
710
  ASSERT(ret == 0x12345678);
711
 
712
  return 0;
713
}
714
 
715
/* Illegal instruction test */
716
int illegal_insn_test (void)
717
{
718
  int ret;
719
 
720
  /* Reset except counter */
721
  except_count = 0;
722
  except_mask = 0;
723
  except_pc = 0;
724
  except_ea = 0;
725
 
726
  /* Set illegal insn */
727 956 simons
  REG32(RAM_START + (RAM_SIZE/2)) = REG32((unsigned long)jump_back + 4);
728
  REG32(RAM_START + (RAM_SIZE/2) + 4) = 0xffffffff;
729 516 markom
 
730
  /* Check if there was illegal insn exception */
731 956 simons
  ret = call (RAM_START + (RAM_SIZE/2) + 4, 0 );
732 516 markom
  ASSERT(except_count == 1);
733
  ASSERT(except_mask == (1 << V_ILLINSN));
734 956 simons
  ASSERT(except_pc == (RAM_START + (RAM_SIZE/2) + 4));
735 516 markom
 
736
  /* Reset except counter */
737
  except_count = 0;
738
  except_mask = 0;
739
  except_pc = 0;
740
  except_ea = 0;
741
 
742
  /* Check if there was illegal insn exception */
743 956 simons
  ret = call (RAM_START + (RAM_SIZE/2), 0 );
744 516 markom
  ASSERT(except_count == 1);
745
  ASSERT(except_mask == (1 << V_ILLINSN));
746 956 simons
  ASSERT(except_pc == RAM_START + (RAM_SIZE/2));
747 516 markom
 
748
  return 0;
749
}
750
 
751
/* Align test */
752
int align_test (void)
753
{
754
  int ret;
755
 
756
  /* Reset except counter */
757
  except_count = 0;
758
  except_mask = 0;
759
  except_pc = 0;
760
  except_ea = 0;
761
 
762
  /* Check if there was alignment exception on read insn */
763
  ret = call ((unsigned long)&load_acc_32, RAM_START + (RAM_SIZE) + (TLB_DATA_SET_NB*PAGE_SIZE) + 1);
764
  ASSERT(except_count == 1);
765
  ASSERT(except_mask == (1 << V_ALIGN));
766
  ASSERT(ret == 0x12345678);
767
  ASSERT(except_pc == ((unsigned long)(load_acc_32) + 8));
768
  ASSERT(except_ea == (RAM_START + (RAM_SIZE) + (TLB_DATA_SET_NB*PAGE_SIZE + 1)));
769
 
770
  ret = call ((unsigned long)&load_acc_32, RAM_START + (RAM_SIZE) + (TLB_DATA_SET_NB*PAGE_SIZE) + 2);
771
  ASSERT(except_count == 2);
772
  ASSERT(except_mask == (1 << V_ALIGN));
773
  ASSERT(ret == 0x12345678);
774
  ASSERT(except_pc == ((unsigned long)(load_acc_32) + 8));
775
  ASSERT(except_ea == (RAM_START + (RAM_SIZE) + (TLB_DATA_SET_NB*PAGE_SIZE + 2)));
776
 
777
  ret = call ((unsigned long)&load_acc_32, RAM_START + (RAM_SIZE) + (TLB_DATA_SET_NB*PAGE_SIZE) + 3);
778
  ASSERT(except_count == 3);
779
  ASSERT(except_mask == (1 << V_ALIGN));
780
  ASSERT(ret == 0x12345678);
781
  ASSERT(except_pc == ((unsigned long)(load_acc_32) + 8));
782
  ASSERT(except_ea == (RAM_START + (RAM_SIZE) + (TLB_DATA_SET_NB*PAGE_SIZE + 3)));
783
 
784
  ret = call ((unsigned long)&load_acc_16, RAM_START + (RAM_SIZE) + (TLB_DATA_SET_NB*PAGE_SIZE) + 1);
785
  ASSERT(except_count == 4);
786
  ASSERT(except_mask == (1 << V_ALIGN));
787
  ASSERT(ret == 0x12345678);
788
  ASSERT(except_pc == ((unsigned long)(load_acc_16) + 8));
789
  ASSERT(except_ea == (RAM_START + (RAM_SIZE) + (TLB_DATA_SET_NB*PAGE_SIZE + 1)));
790
 
791
  /* Check alignment exception on write  insn */
792
  call ((unsigned long)&store_acc_32, RAM_START + (RAM_SIZE) + (TLB_DATA_SET_NB*PAGE_SIZE) + 1);
793
  ASSERT(except_count == 5);
794
  ASSERT(except_mask == (1 << V_ALIGN));
795
  ASSERT(except_pc == ((unsigned long)(store_acc_32) + 8));
796
  ASSERT(except_ea == (RAM_START + (RAM_SIZE) + (TLB_DATA_SET_NB*PAGE_SIZE + 1)));
797
 
798
  call ((unsigned long)&store_acc_32, RAM_START + (RAM_SIZE) + (TLB_DATA_SET_NB*PAGE_SIZE) + 2);
799
  ASSERT(except_count == 6);
800
  ASSERT(except_mask == (1 << V_ALIGN));
801
  ASSERT(except_pc == ((unsigned long)(store_acc_32) + 8));
802
  ASSERT(except_ea == (RAM_START + (RAM_SIZE) + (TLB_DATA_SET_NB*PAGE_SIZE + 2)));
803
 
804
  call ((unsigned long)&store_acc_32, RAM_START + (RAM_SIZE) + (TLB_DATA_SET_NB*PAGE_SIZE) + 3);
805
  ASSERT(except_count == 7);
806
  ASSERT(except_mask == (1 << V_ALIGN));
807
  ASSERT(except_pc == ((unsigned long)(store_acc_32) + 8));
808
  ASSERT(except_ea == (RAM_START + (RAM_SIZE) + (TLB_DATA_SET_NB*PAGE_SIZE + 3)));
809
 
810
  call ((unsigned long)&store_acc_16, RAM_START + (RAM_SIZE) + (TLB_DATA_SET_NB*PAGE_SIZE) + 1);
811
  ASSERT(except_count == 8);
812
  ASSERT(except_mask == (1 << V_ALIGN));
813
  ASSERT(except_pc == ((unsigned long)(store_acc_16) + 8));
814
  ASSERT(except_ea == (RAM_START + (RAM_SIZE) + (TLB_DATA_SET_NB*PAGE_SIZE + 1)));
815
 
816
 
817
  ret = call ((unsigned long)&load_b_acc_32, RAM_START + (RAM_SIZE) + (TLB_DATA_SET_NB*PAGE_SIZE) + 1);
818
  ASSERT(except_count == 9);
819
  ASSERT(except_mask == (1 << V_ALIGN));
820
  ASSERT(ret == 0x12345678);
821
  ASSERT(except_pc == ((unsigned long)(load_b_acc_32) + 8));
822
  ASSERT(except_ea == (RAM_START + (RAM_SIZE) + (TLB_DATA_SET_NB*PAGE_SIZE + 1)));
823
 
824
 
825
  return 0;
826
}
827
 
828
/* Trap test */
829
int trap_test (void)
830
{
831
  /* Reset except counter */
832
  except_count = 0;
833
  except_mask = 0;
834
  except_pc = 0;
835
  except_ea = 0;
836
 
837
  /* Check if there was trap exception */
838
  call ((unsigned long)&trap, 0);
839
  ASSERT(except_count == 1);
840
  ASSERT(except_mask == (1 << V_TRAP));
841
  ASSERT(except_pc == (unsigned long)(trap));
842
 
843
  /* Check if there was trap exception */
844
  call ((unsigned long)&b_trap, 0);
845
  ASSERT(except_count == 2);
846
  ASSERT(except_mask == (1 << V_TRAP));
847
  ASSERT(except_pc == (unsigned long)(b_trap));
848
 
849
  return 0;
850
}
851
 
852
/* Range test */
853
int range_test (void)
854
{
855
  /* Reset except counter */
856
  except_count = 0;
857
  except_mask = 0;
858
  except_pc = 0;
859
  except_ea = 0;
860
 
861
  /* Check if there was range exception */
862
  mtspr (SPR_SR, mfspr (SPR_SR) | SPR_SR_OVE);
863
  call ((unsigned long)&range, 0);
864
  ASSERT(except_count == 1);
865
  ASSERT(except_mask == (1 << V_RANGE));
866
  ASSERT(except_pc == (unsigned long)(range));
867
  ASSERT(except_ea == 0);
868
 
869
  /* Check if there was range exception */
870
  mtspr (SPR_SR, mfspr (SPR_SR) | SPR_SR_OVE);
871
  call ((unsigned long)&b_range, 0);
872
  ASSERT(except_count == 2);
873
  ASSERT(except_mask == (1 << V_RANGE));
874
  ASSERT(except_pc == (unsigned long)(b_range));
875
 
876
  return 0;
877
}
878
 
879
/* Exception priority test */
880
void except_priority_test (void)
881
{
882
  int i, j;
883
  unsigned long ea, ta, ret;
884
 
885
  /* Invalidate all entries in ITLB */
886
  for (i = 0; i < ITLB_WAYS; i++) {
887
    for (j = 0; j < ITLB_SETS; j++) {
888
      mtspr (SPR_ITLBMR_BASE(i) + j, 0);
889
      mtspr (SPR_ITLBTR_BASE(i) + j, 0);
890
    }
891
  }
892
 
893
  /* Set one to one translation for the use of this program */
894
  for (i = 0; i < TLB_TEXT_SET_NB; i++) {
895
    ea = FLASH_START + (i*PAGE_SIZE);
896
    ta = FLASH_START + (i*PAGE_SIZE);
897
    mtspr (SPR_ITLBMR_BASE(0) + i, ea | SPR_ITLBMR_V);
898
    mtspr (SPR_ITLBTR_BASE(0) + i, ta | ITLB_PR_NOLIMIT);
899
  }
900
 
901
  /* Set dtlb no permisions */
902
  itlb_val = SPR_ITLBTR_CI;
903
 
904
  /* Invalidate all entries in DTLB */
905
  for (i = 0; i < DTLB_WAYS; i++) {
906
    for (j = 0; j < DTLB_SETS; j++) {
907
      mtspr (SPR_DTLBMR_BASE(i) + j, 0);
908
      mtspr (SPR_DTLBTR_BASE(i) + j, 0);
909
    }
910
  }
911
 
912
  /* Set one to one translation for the use of this program */
913
  for (i = 0; i < TLB_DATA_SET_NB; i++) {
914
    ea = RAM_START + (i*PAGE_SIZE);
915
    ta = RAM_START + (i*PAGE_SIZE);
916
    mtspr (SPR_DTLBMR_BASE(0) + i, ea | SPR_ITLBMR_V);
917
    mtspr (SPR_DTLBTR_BASE(0) + i, ta | DTLB_PR_NOLIMIT);
918
  }
919
 
920
  /* Init tick timer */
921
  tick_init (1, 1);
922
 
923
  /* Set dtlb no permisions */
924
  dtlb_val = SPR_DTLBTR_CI;
925
 
926
  /* Reset except counter */
927
  except_count = 0;
928
  except_mask = 0;
929
  except_pc = 0;
930
  except_ea = 0;
931
 
932
  /* Enable IMMU */
933
  immu_enable ();
934
 
935
  /* Check if there was INT exception */
936
  call_with_int (RAM_START + (RAM_SIZE) + (TLB_TEXT_SET_NB*PAGE_SIZE), 0);
937
  ASSERT(except_count == 1);
938 600 simons
  ASSERT(except_mask == (1 << V_TICK));
939 516 markom
  ASSERT(except_pc == (RAM_START + (RAM_SIZE) + (TLB_TEXT_SET_NB*PAGE_SIZE)));
940
 
941
  /* Reset except counter */
942
  except_count = 0;
943
  except_mask = 0;
944
  except_pc = 0;
945
  except_ea = 0;
946
 
947
  /* Check if there was ITLB exception */
948
  call (RAM_START + (RAM_SIZE) + (TLB_TEXT_SET_NB*PAGE_SIZE), 0);
949
  ASSERT(except_count == 1);
950
  ASSERT(except_mask == (1 << V_ITLB_MISS));
951
  ASSERT(except_pc == (RAM_START + (RAM_SIZE) + (TLB_TEXT_SET_NB*PAGE_SIZE)));
952
  ASSERT(except_ea == (RAM_START + (RAM_SIZE) + (TLB_TEXT_SET_NB*PAGE_SIZE)));
953
 
954
  /* Set dtlb permisions */
955
  itlb_val |= SPR_ITLBTR_SXE;
956
 
957
  /* Reset except counter */
958
  except_count = 0;
959
  except_mask = 0;
960
  except_pc = 0;
961
  except_ea = 0;
962
 
963
  /* Check if there was IPF exception */
964
  call (RAM_START + (RAM_SIZE) + (TLB_TEXT_SET_NB*PAGE_SIZE), 0);
965
  ASSERT(except_count == 1);
966
  ASSERT(except_mask == (1 << V_IPF));
967
  ASSERT(except_pc == (RAM_START + (RAM_SIZE) + (TLB_TEXT_SET_NB*PAGE_SIZE)));
968
  ASSERT(except_ea == (RAM_START + (RAM_SIZE) + (TLB_TEXT_SET_NB*PAGE_SIZE)));
969
 
970
  /* Reset except counter */
971
  except_count = 0;
972
  except_mask = 0;
973
  except_pc = 0;
974
  except_ea = 0;
975
 
976 956 simons
printf("Buserrrrr!\n");
977 516 markom
  /* Check if there was bus error exception */
978
  call (RAM_START + (RAM_SIZE) + (TLB_TEXT_SET_NB*PAGE_SIZE), 0);
979
  ASSERT(except_count == 1);
980
  ASSERT(except_mask == (1 << V_BERR));
981
  ASSERT(except_pc == (RAM_START + (RAM_SIZE) + (TLB_TEXT_SET_NB*PAGE_SIZE)));
982
  ASSERT(except_ea == (RAM_START + (RAM_SIZE) + (TLB_TEXT_SET_NB*PAGE_SIZE)));
983
 
984
  /* Reset except counter */
985
  except_count = 0;
986
  except_mask = 0;
987
  except_pc = 0;
988
  except_ea = 0;
989
 
990
  /* Disable MMU */
991
  immu_disable ();
992
 
993
  /* Set illegal instruction */
994
  REG32(RAM_START + (RAM_SIZE/2) + (TLB_TEXT_SET_NB*PAGE_SIZE) + 0) = 0x00000000;
995
  REG32(RAM_START + (RAM_SIZE/2) + (TLB_TEXT_SET_NB*PAGE_SIZE) + 4) = 0xffffffff;
996
  REG32(RAM_START + (RAM_SIZE/2) + (TLB_TEXT_SET_NB*PAGE_SIZE) + 8) = 0x00000000;
997
 
998
  /* Check if there was illegal insn exception */
999
  call (RAM_START + (RAM_SIZE/2) + (TLB_TEXT_SET_NB*PAGE_SIZE) + 4, 0);
1000
  ASSERT(except_count == 1);
1001
  ASSERT(except_mask == (1 << V_ILLINSN));
1002
  ASSERT(except_pc == (RAM_START + (RAM_SIZE/2) + (TLB_TEXT_SET_NB*PAGE_SIZE) + 4));
1003
  ASSERT(except_ea == (RAM_START + (RAM_SIZE/2) + (TLB_TEXT_SET_NB*PAGE_SIZE) + 4 ));
1004
 
1005
  /* Reset except counter */
1006
  except_count = 0;
1007
  except_mask = 0;
1008
  except_pc = 0;
1009
  except_ea = 0;
1010
 
1011
  /* Enable DMMU */
1012
  dmmu_enable ();
1013
 
1014
  /* Check if there was alignment exception on read insn */
1015
  ret = call ((unsigned long)&load_acc_32, RAM_START + (RAM_SIZE) + (TLB_DATA_SET_NB*PAGE_SIZE) + 1);
1016
  ASSERT(except_count == 1);
1017
  ASSERT(except_mask == (1 << V_ALIGN));
1018
  ASSERT(ret == 0x12345678);
1019
  ASSERT(except_pc == ((unsigned long)(load_acc_32) + 8));
1020
  ASSERT(except_ea == (RAM_START + (RAM_SIZE) + (TLB_DATA_SET_NB*PAGE_SIZE + 1)));
1021
 
1022
  /* Reset except counter */
1023
  except_count = 0;
1024
  except_mask = 0;
1025
  except_pc = 0;
1026
  except_ea = 0;
1027
 
1028
  /* Check if there was DTLB exception */
1029
  ret = call ((unsigned long)&load_acc_32, RAM_START + (RAM_SIZE) + (TLB_DATA_SET_NB*PAGE_SIZE));
1030
  ASSERT(except_count == 1);
1031
  ASSERT(except_mask == (1 << V_DTLB_MISS));
1032
  ASSERT(ret == 0x12345678);
1033
  ASSERT(except_pc == ((unsigned long)(load_acc_32) + 8));
1034
  ASSERT(except_ea == (RAM_START + (RAM_SIZE) + (TLB_DATA_SET_NB*PAGE_SIZE)));
1035
 
1036
  /* Reset except counter */
1037
  except_count = 0;
1038
  except_mask = 0;
1039
  except_pc = 0;
1040
  except_ea = 0;
1041
 
1042
  /* Set dtlb permisions */
1043
  dtlb_val |= SPR_DTLBTR_SRE;
1044
 
1045
  /* Check if there was DPF exception */
1046
  ret = call ((unsigned long)&load_acc_32, RAM_START + (RAM_SIZE) + (TLB_DATA_SET_NB*PAGE_SIZE));
1047
  ASSERT(except_count == 1);
1048
  ASSERT(except_mask == (1 << V_DPF));
1049
  ASSERT(ret == 0x12345678);
1050
  ASSERT(except_pc == ((unsigned long)(load_acc_32) + 8));
1051
  ASSERT(except_ea == (RAM_START + (RAM_SIZE) + (TLB_DATA_SET_NB*PAGE_SIZE)));
1052
 
1053
  /* Reset except counter */
1054
  except_count = 0;
1055
  except_mask = 0;
1056
  except_pc = 0;
1057
  except_ea = 0;
1058
 
1059
  /* Check if there was bus error exception */
1060
  ret = call ((unsigned long)&load_acc_32, RAM_START + (RAM_SIZE) + (TLB_DATA_SET_NB*PAGE_SIZE));
1061
  ASSERT(except_count == 1);
1062
  ASSERT(except_mask == (1 << V_BERR));
1063
  ASSERT(ret == 0x12345678);
1064
  ASSERT(except_pc == ((unsigned long)(load_acc_32) + 8));
1065
  ASSERT(except_ea == (RAM_START + (RAM_SIZE) + (TLB_DATA_SET_NB*PAGE_SIZE)));
1066
 
1067
  /* Reset except counter */
1068
  except_count = 0;
1069
  except_mask = 0;
1070
  except_pc = 0;
1071
  except_ea = 0;
1072
 
1073
  /* Check if there was trap exception */
1074
  call ((unsigned long)&trap, 0);
1075
  ASSERT(except_count == 1);
1076
  ASSERT(except_mask == (1 << V_TRAP));
1077
  ASSERT(except_pc == (unsigned long)(trap));
1078
 
1079 608 simons
#if 0
1080 516 markom
  /* Reset except counter */
1081
  except_count = 0;
1082
  except_mask = 0;
1083
  except_pc = 0;
1084
  except_ea = 0;
1085
 
1086
  /* Check if there was range exception */
1087
  mtspr (SPR_SR, mfspr (SPR_SR) | SPR_SR_OVE);
1088
  call ((unsigned long)&range, 0);
1089
  ASSERT(except_count == 1);
1090
  ASSERT(except_mask == (1 << V_RANGE));
1091
  ASSERT(except_pc == (unsigned long)(range));
1092
  ASSERT(except_ea == 0);
1093 608 simons
#endif
1094 516 markom
}
1095
 
1096
int main (void)
1097
{
1098
  int ret;
1099
 
1100 520 simons
  printf("except_test\n");
1101
 
1102 516 markom
  /* Register bus error handler */
1103
  excpt_buserr = (unsigned long)bus_err_handler;
1104
 
1105
  /* Register illegal insn handler */
1106
  excpt_illinsn = (unsigned long)ill_insn_handler;
1107
 
1108 600 simons
  /* Register tick timer exception handler */
1109
  excpt_tick = (unsigned long)tick_handler;
1110 516 markom
 
1111 600 simons
  /* Register external interrupt handler */
1112
  excpt_int = (unsigned long)int_handler;
1113 516 markom
 
1114
  /* Register ITLB miss handler */
1115
  excpt_itlbmiss = (unsigned long)itlb_miss_handler;
1116
 
1117
  /* Register instruction page fault handler */
1118
  excpt_ipfault = (unsigned long)ipage_fault_handler;
1119
 
1120
  /* Register DTLB miss handler */
1121
  excpt_dtlbmiss = (unsigned long)dtlb_miss_handler;
1122
 
1123
  /* Register data page fault handler */
1124
  excpt_dpfault = (unsigned long)dpage_fault_handler;
1125
 
1126
  /* Register trap handler */
1127
  excpt_trap = (unsigned long)trap_handler;
1128
 
1129
  /* Register align handler */
1130
  excpt_align = (unsigned long)align_handler;
1131
 
1132
  /* Register range handler */
1133
  excpt_range = (unsigned long)range_handler;
1134
 
1135
  /* Exception basic test */
1136
  ret = except_basic ();
1137
  ASSERT(ret == 0);
1138
 
1139
  /* Interrupt exception test */
1140
  interrupt_test ();
1141
 
1142
  /* ITLB exception test */
1143
  itlb_test ();
1144
 
1145
  /* DTLB exception test */
1146
  dtlb_test ();
1147
 
1148
  /* Bus error exception test */
1149
  buserr_test ();
1150
 
1151
  /* Illegal insn test */
1152
  illegal_insn_test ();
1153
 
1154
  /* Alignment test */
1155
  align_test ();
1156
 
1157
  /* Trap test */
1158
  trap_test ();
1159
 
1160
  /* Range test */
1161 520 simons
//  range_test ();
1162 516 markom
 
1163
  /* Exception priority test */
1164
  except_priority_test ();
1165
 
1166
  report (0xdeaddead);
1167
  exit (0);
1168
 
1169
  return 0;
1170
}
1171
 

powered by: WebSVN 2.1.0

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