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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [orpsocv2/] [sw/] [tests/] [or1200/] [sim/] [or1200-except.S] - Blame information for rev 493

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

Line No. Rev Author Line
1 349 julius
/*
2
        Exception test.
3
 
4
        The following list outlines the tests performed
5
 
6
        Execption test
7
        - 0x100 reset                        - start addr after reset
8
        - 0x200 bus error                    - unimplemented addr is accessed
9
        - 0x300 data page fault              - NOT tested here
10
        - 0x400 instruction page fault       - NOT tested here
11
        - 0x500 tick timer                   - NOT tested here
12
        - 0x600 alignment                    - write to unaligned addr
13
        - 0x700 illegal instruction          - use unimplemented inst. l.div
14
        - 0x800 external interrupt           - int triggered from wb slave
15
        - 0x900 d-tlb miss                   - translation tests
16
        - 0xA00 i-tlb miss                   - NOT tested here
17
        - 0xB00 range                        - NOT tested here
18
        - 0xC00 system call                  - NOT tested here
19
        - 0xD00 floating point               - NOT tested here
20
        - 0xE00 trap                         - NOT tested here
21
        - 0xF00 RESERVED
22
 
23
        r11 - 1st exception counter incremented inside exception
24
        r12 - 2nd exception counter incremented outside and rigth after
25
              exception
26
        ... other register use to be documented...
27
 
28
        Julius Baxter, julius@opencores.org
29
        Tadej Markovic, tadej@opencores.org
30
 
31
*/
32
//////////////////////////////////////////////////////////////////////
33
////                                                              ////
34
//// Copyright (C) 2010 Authors and OPENCORES.ORG                 ////
35
////                                                              ////
36
//// This source file may be used and distributed without         ////
37
//// restriction provided that this copyright statement is not    ////
38
//// removed from the file and that any derivative work contains  ////
39
//// the original copyright notice and the associated disclaimer. ////
40
////                                                              ////
41
//// This source file is free software; you can redistribute it   ////
42
//// and/or modify it under the terms of the GNU Lesser General   ////
43
//// Public License as published by the Free Software Foundation; ////
44
//// either version 2.1 of the License, or (at your option) any   ////
45
//// later version.                                               ////
46
////                                                              ////
47
//// This source is distributed in the hope that it will be       ////
48
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
49
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
50
//// PURPOSE.  See the GNU Lesser General Public License for more ////
51
//// details.                                                     ////
52
////                                                              ////
53
//// You should have received a copy of the GNU Lesser General    ////
54
//// Public License along with this source; if not, download it   ////
55
//// from http://www.opencores.org/lgpl.shtml                     ////
56
////                                                              ////
57
//////////////////////////////////////////////////////////////////////
58
 
59
#include "spr-defs.h"
60
#include "board.h"
61
#include "or1200-defines.h"
62
 
63
/* =================================================== [ exceptions ] === */
64
        .section .vectors, "ax"
65
 
66
 
67
/* ---[ 0x100: RESET exception ]----------------------------------------- */
68
        .org 0x100
69
        l.movhi r0, 0
70
        /* Clear status register */
71
        l.ori   r1, r0, SPR_SR_SM
72
        l.mtspr r0, r1, SPR_SR
73
        /* Clear timer  */
74
        l.mtspr r0, r0, SPR_TTMR
75
        /* Init the stack */
76
        .global stack
77
        l.movhi r1, hi(stack)
78
        l.ori   r1, r1, lo(stack)
79
        l.addi  r2, r0, -3
80
        l.and   r1, r1, r2
81
        /* Jump to program initialisation code */
82
        .global _start
83
        l.movhi r4, hi(_start)
84
        l.ori   r4, r4, lo(_start)
85
        l.jr    r4
86
        l.nop
87
 
88
 
89
/* ---[ 0x200: BUS error ]------------------------------------------------ */
90
        .org 0x200
91
        .global _bus_handler
92
_bus_handler:
93
        l.mfspr r3,r0,SPR_EPCR_BASE     /* Get EPC */
94
        l.nop   2
95
        l.mfspr r3,r0,SPR_EEAR_BASE     /* Get EEA */
96
        l.nop   2
97
        l.addi  r11,r11,1               /* Increment 1st exception counter */
98
        l.sfeqi r30, 0xd /* Is this a data bus test, if so return with l.rfe */
99
        l.bf 1f
100
        l.movhi r5, 0    /* r5 should be the one causing the error on dbus */
101
        /* Instruction bus error test return */
102
        l.movhi r5, hi(0x44004800) /* Put "l.jr r9" instruction in r5 */
103
        l.ori r5, r5, lo(0x44004800)
104
        l.sw 0x0(r0), r5 /* Write "l.j r9" to address 0x0 in RAM */
105
        l.movhi r5,0x1500       /* Put a "l.nop"  instruction in r5 */
106
        l.sw    0x4(r0),r5      /* Write l.nop instruction to RAM addr 0x4 */
107
        l.mtspr r0,r0,SPR_ICBIR         /* Invalidate line 0 of cache */
108
        l.mtspr r0,r0,SPR_EPCR_BASE     /* RFE to 0x0, which is l.jr r9 */
109
1:      l.rfe
110
 
111
/* ---[ 0x600: ALIGN error ]------------------------------------------------ */
112
        .org 0x600
113
        .global _align_handler
114
_align_handler:
115
        l.mfspr r3,r0,SPR_EPCR_BASE     /* Get EPC */
116
        l.nop   2
117
        l.addi  r11,r11,1               /* Increment 1st exception counter */
118
        l.movhi r5,0                    /* Clear the pointer register */
119
        l.rfe
120
 
121
 
122
/* ---[ 0x700: ILLEGAL INSN exception ]------------------------------------- */
123
        .org 0x700
124
        .global _illinsn_handler
125
_illinsn_handler:
126
        l.mfspr r3,r0,SPR_EPCR_BASE     /* Get EPC */
127
        l.nop   2
128
        l.addi  r11,r11,1               /* Increment 1st exception counter */
129
        /* Delay slot test needs this instruction "fixed" */
130
        l.movhi r5,0x1500               /* Put a "l.nop"  instruction in r5 */
131
        l.sw    0x4(r0),r5      /* Write l.nop instruction to RAM addr 0x4 */
132
        l.mtspr r0,r0,SPR_ICBIR         /* Invalidate line 0 of cache */
133
        l.mtspr r0,r0,SPR_EPCR_BASE     /* Jump to 0, which is l.jr r9 */
134
        l.rfe
135
 
136
/* ---[ 0x900: DTLB exception ]--------------------------------------------- */
137
        .org 0x900
138
        .global _dtlb_handler
139
/* Exception handler - DMMU TLB miss */
140
/* Assume 64-entry TLB cache */
141
_dtlb_handler:
142
        l.mfspr r20, r0, SPR_EEAR_BASE
143
        /* Find the entry/set for this address */
144
        l.srli r21, r20, 13 /* r21 = VPN, shift by size 8192 = 2**13 */
145
        l.andi r22, r21, 0x3f /* 64 entries = 6 bit mask, r22 = set number */
146
        /* If page is in the 0xc0000000 space we map to 16MB part of
147
        memory, ie 0x0 => 0x01000000, otherwise 1-1 mapping */
148
        l.movhi r23, hi(0xc0000000)
149
        l.ori r23, r23, lo(0xc0000000)
150
        l.srli r23, r23, 13 /* Get page address, shift by page size, 13 bits */
151
        l.movhi r24, hi(0xff << 11) /* Mask for top byte of VPN */
152
        l.ori r24, r24, lo(0xff << 11)
153
        l.and r24, r24, r21 /* Mask in only top byte of VPN */
154
        l.sfeq r23, r24 /* Decide if it's in our special mapped region or not*/
155
 
156
        /* First, Setup value for DTLBM (match) reg, is same for both cases */
157
        l.movhi r24, hi(SPR_ITLBMR_VPN) /* VPN mask into r24 */
158
        l.ori r24, r24, lo(SPR_ITLBMR_VPN)
159
        l.and r25, r20, r24 /* AND address with VPN mask */
160
        l.ori r25, r25, SPR_DTLBMR_V /* OR in valid bit */
161
        l.mtspr r22, r25, SPR_DTLBMR_BASE(0) /* Write to DTLBR register */
162
 
163
        l.bf _highmem_map
164
        l.nop
165
 
166
_lomem_map:
167
        /* Do 1:1 mapping for this request */
168
        /* Setup value for translate register */
169
        l.movhi r24, hi(SPR_ITLBTR_PPN) /* PPN mask into r24 */
170
        l.ori r24, r24, lo(SPR_ITLBTR_PPN)
171
        l.and r25, r20, r24 /* AND address with PPN mask */
172
        l.ori r25, r25, DTLB_PR_NOLIMIT /* Set all execute enables, no lims. */
173
        l.mtspr r22, r25, SPR_DTLBTR_BASE(0) /* Write to DTLTR register */
174
        l.j _dtlb_done
175
        l.addi r18, r18, 1 /* Incremement low-mapping counter */
176
 
177
_highmem_map:
178
        /* Do top byte, 0xc0->0x01, mapping for this request */
179
        /* Setup value for translate register */
180
        l.movhi r24, hi(SPR_ITLBTR_PPN) /* PPN mask into r24 */
181
        l.ori r24, r24, lo(SPR_ITLBTR_PPN)
182
        l.and r25, r20, r24 /* AND address with PPN mask */
183
        l.movhi r26, hi(0xff000000) /* Top byte address mask */
184
        l.or r25, r26, r25 /* Set top byte to 0xff */
185
        l.xor r25, r26, r25 /* Now clear top byte with XOR */
186
        l.movhi r26, hi(0x01000000) /* Top address byte */
187
        l.or r25, r26, r25 /* Set top address byte */
188
        l.ori r25, r25, DTLB_PR_NOLIMIT /* Set all execute enables, no lims. */
189
        l.mtspr r22, r25, SPR_DTLBTR_BASE(0) /* Write to DTLTR register */
190
        l.addi r19, r19, 1 /* Incremement low-mapping counter */
191
 
192
_dtlb_done:
193
 
194
        l.rfe
195
 
196
 
197
 
198
/* =================================================== [ text section ] === */
199
        .section  .text
200
 
201
/* =================================================== [ start ] === */
202
 
203
        .global _start
204
_start:
205
 
206
        /* Instruction cache enable */
207
        /* Check if IC present and skip enabling otherwise */
208
        l.mfspr r24,r0,SPR_UPR
209
        l.andi  r26,r24,SPR_UPR_ICP
210
        l.sfeq  r26,r0
211
        l.bf    .L8
212
        l.nop
213
 
214
        /* Disable IC */
215
        l.mfspr r6,r0,SPR_SR
216
        l.addi  r5,r0,-1
217
        l.xori  r5,r5,SPR_SR_ICE
218
        l.and   r5,r6,r5
219
        l.mtspr r0,r5,SPR_SR
220
 
221
        /* Establish cache block size
222
        If BS=0, 16;
223
        If BS=1, 32;
224
        r14 contain block size
225
        */
226
        l.mfspr r24,r0,SPR_ICCFGR
227
        l.andi  r26,r24,SPR_ICCFGR_CBS
228
        l.srli  r28,r26,7
229
        l.ori   r30,r0,16
230
        l.sll   r14,r30,r28
231
 
232
        /* Establish number of cache sets
233
        r16 contains number of cache sets
234
        r28 contains log(# of cache sets)
235
        */
236
        l.andi  r26,r24,SPR_ICCFGR_NCS
237
        l.srli  r28,r26,3
238
        l.ori   r30,r0,1
239
        l.sll   r16,r30,r28
240
 
241
        /* Invalidate IC */
242
        l.addi  r6,r0,0
243
        l.sll   r5,r14,r28
244
 
245
.L7:
246
        l.mtspr r0,r6,SPR_ICBIR
247
        l.sfne  r6,r5
248
        l.bf    .L7
249
        l.add   r6,r6,r14
250
 
251
        /* Enable IC */
252
        l.mfspr r6,r0,SPR_SR
253
        l.ori   r6,r6,SPR_SR_ICE
254
        l.mtspr r0,r6,SPR_SR
255
        l.nop
256
        l.nop
257
        l.nop
258
        l.nop
259
        l.nop
260
        l.nop
261
        l.nop
262
        l.nop
263
 
264
.L8:
265
        /* Data cache enable */
266
        /* Check if DC present and skip enabling otherwise */
267
        l.mfspr r24,r0,SPR_UPR
268
        l.andi  r26,r24,SPR_UPR_DCP
269
        l.sfeq  r26,r0
270
        l.bf    .L10
271
        l.nop
272
        /* Disable DC */
273
        l.mfspr r6,r0,SPR_SR
274
        l.addi  r5,r0,-1
275
        l.xori  r5,r5,SPR_SR_DCE
276
        l.and   r5,r6,r5
277
        l.mtspr r0,r5,SPR_SR
278
        /* Establish cache block size
279
           If BS=0, 16;
280
           If BS=1, 32;
281
           r14 contain block size
282
        */
283
        l.mfspr r24,r0,SPR_DCCFGR
284
        l.andi  r26,r24,SPR_DCCFGR_CBS
285
        l.srli  r28,r26,7
286
        l.ori   r30,r0,16
287
        l.sll   r14,r30,r28
288
        /* Establish number of cache sets
289
           r16 contains number of cache sets
290
           r28 contains log(# of cache sets)
291
        */
292
        l.andi  r26,r24,SPR_DCCFGR_NCS
293
        l.srli  r28,r26,3
294
        l.ori   r30,r0,1
295
        l.sll   r16,r30,r28
296
        /* Invalidate DC */
297
        l.addi  r6,r0,0
298
        l.sll   r5,r14,r28
299
.L9:
300
        l.mtspr r0,r6,SPR_DCBIR
301
        l.sfne  r6,r5
302
        l.bf    .L9
303
        l.add   r6,r6,r14
304
        /* Enable DC */
305
        l.mfspr r6,r0,SPR_SR
306
        l.ori   r6,r6,SPR_SR_DCE
307
        l.mtspr r0,r6,SPR_SR
308
.L10:
309
        // Kick off test
310
        l.jal   _main
311
        l.nop
312
 
313
/* ========================================================= [ main ] === */
314
 
315
        .global _main
316
        .global _dmmu_invalidate
317
        .global _dmmu_except1
318
 
319
_main:
320
        l.nop
321
        l.addi  r3,r0,0
322
        l.addi  r5,r0,0
323
        l.addi  r11,r0,0 /* exception counter 1 */
324
        l.addi  r12,r0,0 /* exception counter 2 */
325
        l.addi  r13,r0,0
326
        l.addi  r18,r0,0 /* DMMU exception counter for low mem mapping */
327
        l.addi  r19,r0,0 /* DMMU exception counter for hi mem mapping */
328
        l.sw    0x0(r0),r0      /* Initialize RAM */
329
        l.sw    0x4(r0),r0      /* Initialize RAM */
330
        l.sw    0x8(r0),r0      /* Initialize RAM */
331
        l.sw    0xc(r0),r0      /* Initialize RAM */
332
        l.sw    0x10(r0),r0     /* Initialize RAM */
333
        l.sw    0x14(r0),r0     /* Initialize RAM */
334
        l.sw    0x18(r0),r0     /* Initialize RAM */
335
        l.sw    0x1c(r0),r0     /* Initialize RAM */
336
        l.sw    0x20(r0),r0     /* Initialize RAM */
337
        l.sw    0x24(r0),r0     /* Initialize RAM */
338
        l.sw    0x28(r0),r0     /* Initialize RAM */
339
        l.sw    0x2c(r0),r0     /* Initialize RAM */
340
        l.sw    0x30(r0),r0     /* Initialize RAM */
341
        l.sw    0x34(r0),r0     /* Initialize RAM */
342
        l.sw    0x38(r0),r0     /* Initialize RAM */
343
        l.sw    0x3c(r0),r0     /* Initialize RAM */
344
        l.sw    0x40(r0),r0     /* Initialize RAM */
345
        l.sw    0x44(r0),r0     /* Initialize RAM */
346
        l.sw    0x48(r0),r0     /* Initialize RAM */
347
        l.sw    0x4c(r0),r0     /* Initialize RAM */
348
        l.j     _align1
349
        //l.j _dmmu_except1
350
        l.nop
351
 
352
 
353
        /* Exceptions followed by NOPs */
354
 
355
        /* SW alignment exception */
356
_align1:
357
        l.movhi r11,0
358
        l.nop
359
        /* Test l.sh */
360
        l.ori r5,r0,0x1 /* Half-word access, offset 1 */
361
        l.sh 0x0(r5),r0
362
        l.addi r12,r12,1 /* Increment 2nd exception counter */
363
        l.ori r5,r0,0x3 /* Half-word access, offset 3 */
364
        l.sh 0x0(r5),r0
365
        l.addi r12,r12,1 /* Increment 2nd exception counter */
366
        /* Test l.lhz */
367
        l.ori r5,r0,0x1 /* Half-word access, offset 1 */
368
        l.lhz r3,0x0(r5)
369
        l.addi r12,r12,1 /* Increment 2nd exception counter */
370
        l.ori r5,r0,0x3 /* Half-word access, offset 3 */
371
        l.lhz r3,0x0(r5)
372
        l.addi r12,r12,1 /* Increment 2nd exception counter */
373
        /* Test l.lhs */
374
        l.ori r5,r0,0x1 /* Half-word access, offset 1 */
375
        l.lhs r3,0x0(r5)
376
        l.addi r12,r12,1 /* Increment 2nd exception counter */
377
        l.ori r5,r0,0x3 /* Half-word access, offset 3 */
378
        l.lhs r3,0x0(r5)
379
        l.addi r12,r12,1 /* Increment 2nd exception counter */
380
        /* Test l.sw */
381
        l.ori r5,r0,0x1 /* Word access, offset 1 */
382
        l.sw 0x0(r5), r0
383
        l.addi r12,r12,1 /* Increment 2nd exception counter */
384
        l.ori r5,r0,0x2 /* Word access, offset 2 */
385
        l.sw 0x0(r5), r0
386
        l.addi r12,r12,1 /* Increment 2nd exception counter */
387
        l.ori r5,r0,0x3 /* Word access, offset 3 */
388
        l.sw 0x0(r5), r0
389
        l.addi r12,r12,1 /* Increment 2nd exception counter */
390
        /* Test l.lwz */
391
        l.ori r5,r0,0x1 /* Word access, offset 1 */
392
        l.lwz r3,0x0(r5)
393
        l.addi r12,r12,1 /* Increment 2nd exception counter */
394
        l.ori r5,r0,0x2 /* Word access, offset 2 */
395
        l.lwz r3,0x0(r5)
396
        l.addi r12,r12,1 /* Increment 2nd exception counter */
397
        l.ori r5,r0,0x3 /* Word access, offset 3 */
398
        l.lwz r3,0x0(r5)
399
        l.addi r12,r12,1 /* Increment 2nd exception counter */
400
#if OR1200_HAS_LWS==1
401
        /* Test l.lws */
402
        l.ori r5,r0,0x1 /* Word access, offset 1 */
403
        l.lws r3,0x0(r5)
404
        l.addi r12,r12,1 /* Increment 2nd exception counter */
405
        l.ori r5,r0,0x2 /* Word access, offset 2 */
406
        l.lws r3,0x0(r5)
407
        l.addi r12,r12,1 /* Increment 2nd exception counter */
408
        l.ori r5,r0,0x3 /* Word access, offset 3 */
409
        l.lws r3,0x0(r5)
410
        l.addi r12,r12,1 /* Increment 2nd exception counter */
411
        l.nop
412
#endif
413
        /* Now test them in delay slots */
414
 
415
        l.ori r5,r0,0x1 /* Half-word access, offset 1 */
416
        l.j 1f
417
        l.sh 0x0(r5),r0
418
        l.nop
419
1:      l.addi r12,r12,1 /* Increment 2nd exception counter */
420
        l.ori r5,r0,0x3 /* Half-word access, offset 3 */
421
        l.j 2f
422
        l.sh 0x0(r5),r0
423
        l.nop
424
2:      l.addi r12,r12,1 /* Increment 2nd exception counter */
425
 
426
        /* Test l.lhz */
427
        l.ori r5,r0,0x1 /* Half-word access, offset 1 */
428
        l.j 3f
429
        l.lhz r3,0x0(r5)
430
        l.nop
431
3:      l.addi r12,r12,1 /* Increment 2nd exception counter */
432
        l.ori r5,r0,0x3 /* Half-word access, offset 3 */
433
        l.j 4f
434
        l.lhz r3,0x0(r5)
435
        l.nop
436
4:      l.addi r12,r12,1 /* Increment 2nd exception counter */
437
 
438
        /* Test l.lhs */
439
        l.ori r5,r0,0x1 /* Half-word access, offset 1 */
440
        l.j 5f
441
        l.lhs r3,0x0(r5)
442
        l.nop
443
5:      l.addi r12,r12,1 /* Increment 2nd exception counter */
444
        l.ori r5,r0,0x3 /* Half-word access, offset 3 */
445
        l.j 6f
446
        l.lhs r3,0x0(r5)
447
        l.nop
448
6:      l.addi r12,r12,1 /* Increment 2nd exception counter */
449
 
450
        /* Test l.sw */
451 412 julius
        l.ori   r5,r0,0x1 /* Word access, offset 1 */
452
        l.j     7f
453
        l.sw    0x0(r5), r0
454 349 julius
        l.nop
455 412 julius
7:      l.addi  r12,r12,1 /* Increment 2nd exception counter */
456
        l.ori   r5,r0,0x2 /* Word access, offset 2 */
457
        l.j     8f
458
        l.sw    0x0(r5), r0
459 349 julius
        l.nop
460 412 julius
8:      l.addi  r12,r12,1 /* Increment 2nd exception counter */
461
        l.ori   r5,r0,0x3 /* Word access, offset 3 */
462
        l.j     9f
463
        l.sh    0x0(r5), r0
464 349 julius
        l.nop
465 412 julius
9:      l.addi  r12,r12,1 /* Increment 2nd exception counter */
466 349 julius
 
467
        /* Test l.lwz */
468 412 julius
        l.ori   r5,r0,0x1 /* Word access, offset 1 */
469
        l.j     10f
470
        l.lwz   r3,0x0(r5)
471 349 julius
        l.nop
472 412 julius
10:     l.addi  r12,r12,1 /* Increment 2nd exception counter */
473
        l.ori   r5,r0,0x2 /* Word access, offset 2 */
474
        l.j     11f
475
        l.lwz   r3,0x0(r5)
476 349 julius
        l.nop
477 412 julius
11:     l.addi  r12,r12,1 /* Increment 2nd exception counter */
478
        l.ori   r5,r0,0x3 /* Word access, offset 3 */
479
        l.j     12f
480
        l.lwz   r3,0x0(r5)
481 349 julius
        l.nop
482 412 julius
12:     l.addi  r12,r12,1 /* Increment 2nd exception counter */
483 349 julius
#if OR1200_HAS_LWS==1
484
        /* Test l.lws */
485 412 julius
        l.ori   r5,r0,0x1 /* Word access, offset 1 */
486
        l.j     13f
487
        l.lws   r3,0x0(r5)
488 349 julius
        l.nop
489 412 julius
13:     l.addi  r12,r12,1 /* Increment 2nd exception counter */
490
        l.ori   r5,r0,0x2 /* Word access, offset 2 */
491
        l.j     14f
492
        l.lws   r3,0x0(r5)
493 349 julius
        l.nop
494 412 julius
14:     l.addi  r12,r12,1 /* Increment 2nd exception counter */
495
        l.ori   r5,r0,0x3 /* Word access, offset 3 */
496
        l.j     15f
497
        l.lws   r3,0x0(r5)
498 349 julius
        l.nop
499 412 julius
15:     l.addi  r12,r12,1 /* Increment 2nd exception counter */
500 349 julius
 
501
#endif
502
        /* Check 1st and 2nd exception counters are equal */
503
        l.sfeq  r11,r12                 /* Should be equal */
504
        l.bf    17f
505
        l.nop
506
        l.nop   1
507
17:     l.nop   2
508
        l.nop
509
 
510
        /* Illegal instruction exception */
511
_illegal1:
512
        l.nop
513
        l.nop
514
        l.movhi r5, hi(0x44004800) /* Put "l.jr r9" instruction in r5 */
515 412 julius
        l.ori   r5, r5, lo(0x44004800)
516 426 julius
        l.sw    0x0(r0), r5     /* Write "l.j r9" to address 0x0 in RAM */
517
        l.movhi r5, 0xee00      /* Put an illegal instruction in r5 */
518
        l.sw    0x4(r0), r5     /* Write illegal instruction to RAM addr 0x4 */
519
        l.movhi r5, 0x1500      /* l.nop after illegal instruction */
520
        l.sw    0x8(r0), r5     /* Write nop to RAM addr 0x8 */
521 349 julius
        l.mtspr r0,r0,SPR_ICBIR /* Invalidate line 0 of cache */
522 426 julius
        /* Jump to 0x4 - illegal opcode instruction */
523 412 julius
        l.ori   r6, r0, 0x4
524 426 julius
        l.jalr  r6              /* Jump to address 0x4, land on illegal insn */
525
        l.addi  r12,r12,1       /* Increment 2nd exception counter */
526
        l.nop                   /* Should return here */
527 349 julius
        l.nop
528
 
529
        /* Test in delay slot */
530
 
531 426 julius
        l.movhi r5, 0xee00      /* Put an illegal instruction in r5 */
532
        l.sw    0x4(r0), r5     /* Write illegal instruction to RAM addr 0x4 */
533 412 julius
        l.mtspr r0,r0,SPR_ICBIR /* Invalidate line 0 of cache */
534
        l.jalr  r0 /* Jump to address 0, will be a jump back but with an illegal
535 349 julius
                     dslot instruction which will befixed by handler */
536 426 julius
        l.addi  r12,r12,1       /* Increment 2nd exception counter */
537
        l.nop                   /* Should return here */
538 349 julius
 
539
        /* Check 1st and 2nd exception counters are equal */
540 426 julius
        l.sfeq  r11,r12         /* Should be equal */
541 412 julius
        l.bf    1f
542 349 julius
        l.nop
543 412 julius
        l.or    r3, r12, r12
544 426 julius
        l.nop   2               /* Report expected exception count */
545 412 julius
        l.or    r3, r11, r11
546 426 julius
        l.nop   2               /* Report actual exception count */
547 412 julius
        l.nop   1
548 349 julius
1:      l.nop
549
        l.nop
550
 
551
 
552
_dbus1:
553
        l.nop
554
        l.movhi r12, 0 /* Reset exception counters */
555
        l.movhi r11, 0
556
        l.ori r30, r0, 0xd /* put 0xd in r30, indicate it's databus test */
557
        /* Cause access error */
558
        /* Load word */
559
        l.movhi r5, 0xee00 /* Address to cause an error */
560
        l.lwz r6, 0(r5)
561
        l.addi r12, r12, 1 /* Incremement secondary exception counter */
562
        /* Load half */
563
        l.movhi r5, 0xee00 /* Address to cause an error */
564
        l.lhz r6, 0(r5)
565
        l.addi r12, r12, 1 /* Incremement secondary exception counter */
566
        /* Load byte */
567
        l.movhi r5, 0xee00 /* Address to cause an error */
568
        l.lbz r6, 0(r5)
569
        l.addi r12, r12, 1 /* Incremement secondary exception counter */
570
        /* Store word */
571
        l.movhi r5, 0xee00 /* Address to cause an error */
572
        l.sw 0(r5), r6
573
        l.addi r12, r12, 1 /* Incremement secondary exception counter */
574
        /* Store half */
575
        l.movhi r5, 0xee00 /* Address to cause an error */
576
        l.sh 0(r5), r6
577
        l.addi r12, r12, 1 /* Incremement secondary exception counter */
578
        /* Store byte */
579
        l.movhi r5, 0xee00 /* Address to cause an error */
580
        l.sb 0(r5), r6
581
        l.addi r12, r12, 1 /* Incremement secondary exception counter */
582
        l.nop
583
        /* Delay slot tests */
584
        /* Load word */
585
        l.movhi r5, 0xee00 /* Address to cause an error */
586
        l.j 1f
587
        l.lwz r6, 0(r5) /* Data bus error in delay slot */
588
        l.nop
589
1:      l.addi r12, r12, 1
590
        /* Load half */
591
        l.movhi r5, 0xee00 /* Address to cause an error */
592
        l.j 2f
593
        l.lhz r6, 0(r5) /* Data bus error in delay slot */
594
        l.nop
595
2:      l.addi r12, r12, 1
596
        /* Load byte */
597
        l.movhi r5, 0xee00 /* Address to cause an error */
598
        l.j 3f
599
        l.lbz r6, 0(r5) /* Data bus error in delay slot */
600
        l.nop
601
3:      l.addi r12, r12, 1
602
        /* Store word */
603
        l.movhi r5, 0xee00 /* Address to cause an error */
604
        l.j 4f
605
        l.sw 0(r5), r6  /* Data bus error in delay slot */
606
        l.nop
607
4:      l.addi r12, r12, 1
608
        /* Store half */
609
        l.movhi r5, 0xee00 /* Address to cause an error */
610
        l.j 5f
611
        l.sh 0(r5), r6  /* Data bus error in delay slot */
612
        l.nop
613
5:      l.addi r12, r12, 1
614
        /* Store byte */
615
        l.movhi r5, 0xee00 /* Address to cause an error */
616
        l.j 6f
617
        l.sb 0(r5), r6  /* Data bus error in delay slot */
618
        l.nop
619
6:      l.addi r12, r12, 1
620
 
621
 
622
/* Check 1st and 2nd exception counters are equal */
623
        l.sfeq  r11,r12                 /* Should be equal */
624
        l.bf 7f
625
        l.nop
626
        l.or r3, r12, r12
627
        l.nop 2 /* Report expected exception count */
628
        l.or r3, r11, r11
629
        l.nop 2 /* Report actual exception count */
630
        l.nop 1
631
7:      l.nop
632
 
633
 
634
 
635
_ibus1:
636
        /* TODO: do this it with cache enabled/disabled */
637
        l.movhi r12, 0 /* Reset exception counters */
638
        l.movhi r11, 0
639
        l.movhi r30, 0x0 /* put 0x0 in r30,indicate it's instruction bus test*/
640
        /* Cause access error */
641
        l.movhi r5, 0xee00 /* Address to cause an error */
642
        l.jalr r5 /* Jump and link to bad address */
643
        l.nop
644
        l.addi r12, r12, 1 /* Incremement secondary exception counter */
645
        /* Check 1st and 2nd exception counters are equal */
646
        l.sfeq  r11,r12                 /* Should be equal */
647
        l.bf 1f
648
        l.nop
649
        l.or r3, r12, r12
650
        l.nop 2 /* Report expected exception count */
651
        l.or r3, r11, r11
652
        l.nop 2 /* Report actual exception count */
653
        l.nop 1
654
1:      l.nop
655
        l.nop
656
 
657
 
658
        /* Data MMU exception - try case where we need to translate address as
659
           we l.rfe to it */
660
        // Check the DMMU is the in the design, otherwise don't compile in this
661
        // test.
662
#ifndef OR1200_NO_DMMU
663 373 julius
        .extern lo_dmmu_en
664 349 julius
_dmmu_except1:
665
        /* Call DMMU invalidate function */
666
        l.movhi r4, hi(_dmmu_invalidate)
667
        l.ori r4, r4, lo(_dmmu_invalidate)
668
        l.jalr r4
669
        l.ori r3, r0, 64 /* Put number of entries in r3 */
670
 
671
        l.movhi r5, hi(0x01000000)
672
        /* Write a word to the place where we'll translate to */
673
        l.movhi r7, hi(0xaabbccdd)
674
        l.ori r7, r7, lo(0xaabbccdd)
675
        l.sw 0(r5), r7 /* Shouldn't trigger MMU */
676
        l.sfne r18, r0
677
        l.bf _dmmu_test_error
678
        l.nop
679
        l.sfne r19, r0
680
        l.bf _dmmu_test_error
681
        l.nop
682
 
683
        /* Now enable DMMU */
684 373 julius
        l.movhi r4, hi(lo_dmmu_en)
685
        l.ori r4, r4, lo(lo_dmmu_en)
686 349 julius
        l.jalr r4
687
        l.nop
688
 
689
        /* Now start test. 0xc0000000 should go to 0x01000000 */
690
        l.lwz r8, 0(r5) /* Should cause DMMU miss, lomem */
691
        /* Check value was OK */
692
        l.sfne r7, r8
693
        l.bf _dmmu_test_error
694
        l.nop
695
        l.sfnei r18, 0x1 /* Check for lo mem mapping */
696
        l.bf _dmmu_test_error
697
        l.nop
698
        l.sfne r19, r0 /* hi-mem counter should still be 0 */
699
        l.bf _dmmu_test_error
700
        l.nop
701
 
702
        /* Test accesses to mapped area */
703
        l.movhi r6, hi(0xc0000000)
704
        l.lwz r8, 0(r6) /* Should cause DMMU miss, himem */
705
        /* Check value was OK */
706
        l.sfne r7, r8
707
        l.bf _dmmu_test_error
708
        l.nop
709
        l.sfnei r18, 0x1 /* Check for lo mem mapping */
710
        l.bf _dmmu_test_error
711
        l.nop
712
        l.sfnei r19, 0x1 /* hi-mem counter should still be 0 */
713
        l.bf _dmmu_test_error
714
        l.nop
715
 
716
        /* Now start test. 0xc0000000 should go to 0x01000000 */
717
        l.lwz r8, 0(r5) /* Should cause DMMU miss, lomem */
718
        /* Check value was OK */
719
        l.sfne r7, r8
720
        l.bf _dmmu_test_error
721
        l.nop
722
        l.sfnei r18, 0x2 /* Check for lo mem mapping increment */
723
        l.bf _dmmu_test_error
724
        l.nop
725
        l.sfnei r19, 0x1 /* hi-mem counter should still be 1 */
726
        l.bf _dmmu_test_error
727
        l.nop
728
 
729
        l.addi r7, r7, 0x1111 /* Incremement value we're writing */
730
 
731
        l.sw 4(r6), r7 /* Should cause DMMU miss, himem */
732
        l.sfnei r18, 0x2 /* Check for lo mem mapping */
733
        l.bf _dmmu_test_error
734
        l.nop
735
        l.sfnei r19, 0x2 /* hi-mem counter should be 2 */
736
        l.bf _dmmu_test_error
737
        l.nop
738
 
739
        l.lwz r8, 4(r5) /* Should cause DMMU miss, lomem */
740
        /* Check value was OK */
741
        l.sfne r7, r8
742
        l.bf _dmmu_test_error
743
        l.nop
744
        l.sfnei r18, 0x3 /* Check for lo mem mapping increment */
745
        l.bf _dmmu_test_error
746
        l.nop
747
        l.sfnei r19, 0x2 /* hi-mem counter should still be 2 */
748
        l.bf _dmmu_test_error
749
        l.nop
750
 
751
        /* Fast DMMU exceptions should follow */
752
        l.addi r7, r7, 0x1111 /* Incremement value we're writing */
753
        l.sw 8(r6), r7 /* Should cause DMMU miss, himem */
754
        l.lwz r8, 8(r5) /* Should cause DMMU miss, lomem */
755
        l.addi r7, r7, 0x1111 /* Incremement value we're writing */
756
        l.sw 0xc(r6), r7 /* Should cause DMMU miss, himem */
757
        l.lwz r8, 0xc(r5) /* Should cause DMMU miss, lomem */
758
        l.addi r7, r7, 0x1111 /* Incremement value we're writing */
759
        l.sw 0x10(r6), r7 /* Should cause DMMU miss, himem */
760
        l.lwz r8, 0x10(r5) /* Should cause DMMU miss, lomem */
761
        l.addi r7, r7, 0x1111 /* Incremement value we're writing */
762
        l.sw 0x14(r6), r7 /* Should cause DMMU miss, himem */
763
        l.lwz r8, 0x14(r5) /* Should cause DMMU miss, lomem */
764
        l.addi r7, r7, 0x1111 /* Incremement value we're writing */
765
        l.sw 0x18(r6), r7 /* Should cause DMMU miss, himem */
766
        l.lwz r8, 0x18(r5) /* Should cause DMMU miss, lomem */
767
        l.addi r7, r7, 0x1111 /* Incremement value we're writing */
768
        l.sw 0x1c(r6), r7 /* Should cause DMMU miss, himem */
769
        l.lwz r8, 0x1c(r5) /* Should cause DMMU miss, lomem */
770
        l.addi r7, r7, 0x1111 /* Incremement value we're writing */
771
        l.sw 0x20(r6), r7 /* Should cause DMMU miss, himem */
772
        l.lwz r8, 0x20(r5) /* Should cause DMMU miss, lomem */
773
        l.addi r7, r7, 0x1111 /* Incremement value we're writing */
774
        l.sw 0x24(r6), r7 /* Should cause DMMU miss, himem */
775
        l.lwz r8, 0x24(r5) /* Should cause DMMU miss, lomem */
776
        /* Should now be 11 lowmem DTLB misses and 10 for high memory space */
777
        l.sfne r7, r8
778
        l.bf _dmmu_test_error
779
        l.nop
780
        l.sfnei r18, 0xb /* Check for lo mem mapping increment to 11 */
781
        l.bf _dmmu_test_error
782
        l.nop
783
        l.sfnei r19, 0xa /* hi-mem counter should be 10 */
784
        l.bf _dmmu_test_error
785
        l.nop
786
 
787
        l.j _dmmu_test_ok
788
        l.nop
789
 
790
 
791
_dmmu_test_error:
792
        l.movhi r3, hi(0xeeeeeeed)
793
        l.ori r3, r3, lo(0xeeeeeeed)
794
        l.nop 2
795
        l.nop 1
796
 
797
_dmmu_test_ok:
798
        l.nop
799
 
800
#endif // #ifndef OR1200_NO_DMMU
801
 
802
        /* End of tests - report and finish simulation */
803
        l.movhi r3,hi(0xdeaddead)
804
        l.ori   r3,r3,lo(0xdeaddead)
805
        l.nop   2
806
 
807
        l.movhi r3,hi(0x8000000d)
808
        l.ori   r3,r3,lo(0x8000000d)
809
        l.nop   2
810
 
811
        l.addi r3,r0,0
812 373 julius
        l.jal   exit
813 349 julius
        l.nop
814
 
815
 
816
        /* DMMU invalidate function */
817
        /* First parameter, r3, has number of DMMU entries (should be 64)*/
818
 
819
_dmmu_invalidate:
820
        /* Setup the Data MMU's TLBS */
821
        l.movhi r4, hi(SPR_DTLBMR_BASE(0))
822
        l.ori r4, r4, lo(SPR_DTLBMR_BASE(0))
823
 
824
        /* DTLB invalidate loop */
825
1:
826
        l.mtspr r4, r0, 0x0
827
        l.addi r4, r4, 0x1
828
        l.sfeq r3, r0
829
        l.bnf 1b
830
        l.addi r3, r3, -1
831
        l.jr r9
832
        l.nop
833
 

powered by: WebSVN 2.1.0

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