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

Subversion Repositories ion

[/] [ion/] [trunk/] [src/] [opcodes/] [opcodes.s] - Blame information for rev 168

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

Line No. Rev Author Line
1 2 ja_rd
################################################################################
2 4 ja_rd
# opcode.s -- MIPS opcode tester for Ion project
3 2 ja_rd
#-------------------------------------------------------------------------------
4
# ORIGINAL AUTHOR: Steve Rhoads (rhoadss@yahoo.com) -- 1/10/01
5
#
6
# This file is an edited version of 'opcodes.asm', which is part of the Plasma
7
# project (http://opencores.org/project,plasma).
8
# COPYRIGHT: Software placed into the public domain by the original author.
9
# Software 'as is' without warranty.  Author liable for nothing.
10 4 ja_rd
#
11 2 ja_rd
#-------------------------------------------------------------------------------
12 4 ja_rd
# This assembly file tests all of the opcodes supported by the Ion core.
13 2 ja_rd
# This test assumes that address 0x20000000 is the UART write register.
14
# Successful tests will print out "A" or "AB" or "ABC" or ....
15
# Missing letters or letters out of order indicate a failure.
16 14 ja_rd
#
17 2 ja_rd
#-------------------------------------------------------------------------------
18 4 ja_rd
# NOTE: This test bench relies on the simulation logs to catch errors. That is,
19 38 ja_rd
# unlike the original Plasma code, this one does not check the test success
20
# conditions. Instead, it performs the operations to be tested and relies on you
21 4 ja_rd
# to compare the logs from the logic simulation and the software simulation.
22
# Test that work this way have been commented with this tag: "@log"
23
#
24 2 ja_rd
#-------------------------------------------------------------------------------
25 4 ja_rd
# NOTE: NOPs have been inserted after load instructions.
26 2 ja_rd
#
27
################################################################################
28
 
29 4 ja_rd
    #-- Set flags below to >0 to enable/disable test assembly ------------------
30 2 ja_rd
 
31 4 ja_rd
    .set TEST_UNALIGNED_LOADS, 0        # unaligned loads
32
    .set TEST_UNALIGNED_STORES, 0       # unaligned stores
33
    .set TEST_BREAK, 1                  # BREAK instruction
34
    # WARNING: the assembler expands div instructions, see 'as' manual
35 14 ja_rd
    .set TEST_DIV, 1                    # DIV* instructions
36
    .set TEST_MUL, 1                    # MUL* instructions
37 148 ja_rd
    .set USE_CACHE, 1                   # Initialize and enable cache
38 165 ja_rd
    .set EMU_MIPS32, 1                  # Emulates selected MIPS32 opcodes
39 148 ja_rd
 
40
    .set ICACHE_NUM_LINES, 256              # no. of lines in the I-Cache
41
    .set DCACHE_NUM_LINES, 256              # no. of lines in the D-Cache
42
    .set DCACHE_LINE_SIZE, 4                # D-Cache line size in words
43 2 ja_rd
 
44 4 ja_rd
    #---------------------------------------------------------------------------
45
 
46 2 ja_rd
    .text
47
    .align  2
48
    .globl  entry
49
    .ent    entry
50
entry:
51
    .set    noreorder
52
 
53
    la      $gp, _gp            #initialize stack pointer
54
    la      $4, __bss_start     #$4 = .sbss_start
55
    la      $5, _end            #$5 = .bss_end
56
    nop                         #no stack needed
57
    nop
58
 
59
    b       StartTest
60
    nop
61
 
62 29 ja_rd
 
63
    # Trap handler address
64 66 ja_rd
    #.org    0x3c
65
    .org    0x0180
66
 
67 29 ja_rd
    # We have three trap sources: syscall, break and unimplemented opcode
68
    # Plus we have to account for a faulty cause code; that's 4 causes
69
    # Besides, we have to look out for the branch delay flag (BD)
70
    # We'll just increment $4 by a fixed constant depending on the cause
71
    # so we will not save any registers (there's no stack anyway)
72
InterruptVector:
73
    mfc0    $k0,$13             # Get trap cause code
74 152 ja_rd
    srl     $k0,$k0,2
75 29 ja_rd
    andi    $k0,$k0,0x01f
76
    ori     $k1,$zero,0x8       # was it a syscall?
77
    beq     $k0,$k1,trap_syscall
78
    addi    $k1,$k1,0x1         # was it a break?
79
    beq     $k0,$k1,trap_break
80
    addi    $k1,$k1,0x1         # was it a bad opcode?
81
    bne     $k0,$k1,trap_invalid
82 2 ja_rd
    nop
83 29 ja_rd
 
84
    # Unimplemented instruction
85
trap_unimplemented:
86 165 ja_rd
    .ifgt   EMU_MIPS32
87
    # jump to mips32 opcode emulator with c0_cause in $k0
88
    j       opcode_emu
89
    nop
90
    .else
91
    # just do some simple arith so the opcode tester knows we were here
92 29 ja_rd
    j       trap_return
93
    add     $4,$4,4
94 165 ja_rd
    .endif
95 2 ja_rd
 
96 29 ja_rd
    # Break instruction
97
trap_break:
98
    j       trap_return
99 2 ja_rd
    add     $4,$4,5
100 29 ja_rd
 
101
    # Syscall instruction
102
trap_syscall:
103 165 ja_rd
    mfc0    $k0,$12             # test behavior of rfe: invert bit IE of SR...
104
    xori    $k0,0x01
105
    mtc0    $k0,$12             # ...and see (in the @log) if rfe recovers it
106
    j       trap_return
107 29 ja_rd
    add     $4,$4,6
108
 
109
    # Invalid trap cause code, most likely hardware bug
110
trap_invalid:
111
    j       trap_return
112
    add     $4,$4,0xf
113
 
114
trap_return:
115
    mfc0    $k1,$14             # C0_EPC=14 (Exception PC)
116
    mfc0    $k0,$13             # Get bit 31 (BD) from C0 cause register
117
    srl     $k0,31
118
    andi    $k0,$k0,1
119
    bnez    $k0,trap_return_delay_slot
120
    addi    $k1,$k1,4           # skip trap instruction
121
    jr      $k1
122
    nop
123
trap_return_delay_slot:
124
    addi    $k1,$k1,4           # skip jump instruction too
125
    jr      $k1                 # (we just added 8 to epc)
126 165 ja_rd
    rfe
127 29 ja_rd
 
128
 
129 2 ja_rd
StartTest:
130 148 ja_rd
    .ifgt   USE_CACHE
131
    jal     setup_cache
132
    nop
133
    .else
134 165 ja_rd
    ori     $k0,$zero,0x1
135
    mtc0    $k0,$12             # disable interrupts and cache, stay in kernel
136 148 ja_rd
    .endif
137 152 ja_rd
 
138 165 ja_rd
    li      $k0,0x00020000      # enter user mode...
139
    mtc0    $k0,$12             # ...NOW
140
    mfc0    $k0,$12             # verify COP* in user mode triggers trap (@log)
141 152 ja_rd
    ori     $k0,0x01
142
    mtc0    $k0,$12             # verify COP* in user mode triggers trap (@log)
143 165 ja_rd
    # The two above COP0s should trigger a trap. The 1st one tests the delay in
144
    # entering user mode.
145 152 ja_rd
 
146 165 ja_rd
    # The rest of the tests proceed in user mode (not that there's much
147
    # difference...)
148
 
149 2 ja_rd
    lui     $20,0x2000          # serial port write address
150
    ori     $21,$0,'\n'         # <CR> character
151
    ori     $22,$0,'X'          # 'X' letter
152
    ori     $23,$0,'\r'
153
    ori     $24,$0,0x0f80       # temp memory
154
 
155 165 ja_rd
    sb      $23,0($20)          # Write a message to console
156 2 ja_rd
    sb      $21,0($20)
157
    sb      $23,0($20)
158
    sb      $21,0($20)
159
    sb      $23,0($20)
160
    sb      $21,0($20)
161
    sb      $23,0($20)
162
    sb      $21,0($20)
163 29 ja_rd
 
164 165 ja_rd
 
165 2 ja_rd
    ######################################
166
    #Arithmetic Instructions
167
    ######################################
168
ArthmeticTest:
169
    ori     $2,$0,'A'
170
    sb      $2,0($20)
171
    ori     $2,$0,'r'
172
    sb      $2,0($20)
173
    ori     $2,$0,'i'
174
    sb      $2,0($20)
175
    ori     $2,$0,'t'
176
    sb      $2,0($20)
177
    ori     $2,$0,'h'
178
    sb      $2,0($20)
179
    sb      $23,0($20)
180
    sb      $21,0($20)
181
 
182
    #a: ADD
183
    ori     $2,$0,'a'
184
    sb      $2,0($20)
185
    ori     $3,$0,5
186
    ori     $4,$0,60
187
    add     $2,$3,$4
188
    sb      $2,0($20)    #A
189
    sb      $23,0($20)
190
    sb      $21,0($20)
191
 
192
    #b: ADDI
193
    ori     $2,$0,'b'
194
    sb      $2,0($20)
195
    ori     $4,$0,60
196
    addi    $2,$4,5
197
    sb      $2,0($20)    #A
198
    sb      $23,0($20)
199
    sb      $21,0($20)
200
 
201
    #c: ADDIU
202
    ori     $2,$0,'c'
203
    sb      $2,0($20)
204
    ori     $4,$0,50
205
    addiu   $5,$4,15
206
    sb      $5,0($20)    #A
207
    sb      $23,0($20)
208
    sb      $21,0($20)
209
 
210
    #d: ADDU
211
    ori     $2,$0,'d'
212
    sb      $2,0($20)
213
    ori     $3,$0,5
214
    ori     $4,$0,60
215
    add     $2,$3,$4
216
    sb      $2,0($20)    #A
217
    sb      $23,0($20)
218
    sb      $21,0($20)
219
 
220 4 ja_rd
    # DIV tests, skip conditionally
221
    .ifgt TEST_DIV
222 2 ja_rd
 
223
    #e: DIV
224
    ori     $2,$0,'e'
225
    sb      $2,0($20)
226
    ori     $2,$0,65*117+41
227
    ori     $3,$0,117
228
    div     $2,$3
229
    nop
230
    mflo    $4
231
    sb      $4,0($20)    #A
232
    mfhi    $4
233
    addi    $4,$4,66-41
234
    sb      $4,0($20)    #B
235
    li      $2,-67*19
236
    ori     $3,$0,19
237
    div     $2,$3
238
    nop
239
    mflo    $4
240
    sub     $4,$0,$4
241
    sb      $4,0($20)    #C
242
    ori     $2,$0,68*23
243
    li      $3,-23
244
    div     $2,$3
245
    nop
246
    mflo    $4
247
    sub     $4,$0,$4
248
    sb      $4,0($20)    #D
249
    li      $2,-69*13
250
    li      $3,-13
251
    div     $2,$3
252
    mflo    $4
253
    sb      $4,0($20)    #E
254
    sb      $23,0($20)
255
    sb      $21,0($20)
256
 
257
    #f: DIVU
258
    ori     $2,$0,'f'
259
    sb      $2,0($20)
260
    ori     $2,$0,65*13
261
    ori     $3,$0,13
262
    divu    $2,$3
263
    nop
264
    mflo    $4
265
    sb      $4,0($20)    #A
266
    sb      $23,0($20)
267
    sb      $21,0($20)
268 4 ja_rd
    .endif
269 2 ja_rd
 
270 4 ja_rd
    # MUL tests, skip conditionally
271
    .ifgt   TEST_MUL
272 2 ja_rd
 
273
    #g: MULT
274
    ori     $2,$0,'g'
275
    sb      $2,0($20)
276
    ori     $2,$0,5
277
    ori     $3,$0,13
278
    mult    $2,$3
279
    nop
280
    mflo    $4
281
    sb      $4,0($20)    #A
282
    li      $2,-5
283
    ori     $3,$0,13
284
    mult    $2,$3
285
    mfhi    $5
286
    mflo    $4
287
    sub     $4,$0,$4
288
    addu    $4,$4,$5
289
    addi    $4,$4,2
290
    sb      $4,0($20)    #B
291
    ori     $2,$0,5
292
    li      $3,-13
293
    mult    $2,$3
294
    mfhi    $5
295
    mflo    $4
296
    sub     $4,$0,$4
297
    addu    $4,$4,$5
298
    addi    $4,$4,3
299
    sb      $4,0($20)    #C
300
    li      $2,-5
301
    li      $3,-13
302
    mult    $2,$3
303
    mfhi    $5
304
    mflo    $4
305
    addu    $4,$4,$5
306
    addi    $4,$4,3
307
    sb      $4,0($20)    #D
308
    lui     $4,0xfe98
309
    ori     $4,$4,0x62e5
310
    lui     $5,0x6
311
    ori     $5,0x8db8
312
    mult    $4,$5
313
    mfhi    $6
314
    addiu   $7,$6,2356+1+'E' #E
315
    sb      $7,0($20)
316
    sb      $23,0($20)
317
    sb      $21,0($20)
318
 
319
    #h: MULTU
320
    ori     $2,$0,'h'
321
    sb      $2,0($20)
322
    ori     $2,$0,5
323
    ori     $3,$0,13
324
    multu   $2,$3
325
    nop
326
    mflo    $4
327
    sb      $4,0($20)    #A
328
    sb      $23,0($20)
329
    sb      $21,0($20)
330 4 ja_rd
    .endif
331 2 ja_rd
 
332
    #i: SLT
333
    ori     $2,$0,'i'
334
    sb      $2,0($20)
335
    ori     $2,$0,10
336
    ori     $3,$0,12
337
    slt     $4,$2,$3
338
    addi    $5,$4,64
339
    sb      $5,0($20)    #A
340
    slt     $4,$3,$2
341
    addi    $5,$4,66
342
    sb      $5,0($20)    #B
343
    li      $2,0xfffffff0
344
    slt     $4,$2,$3
345
    addi    $5,$4,66
346
    sb      $5,0($20)    #C
347
    slt     $4,$3,$2
348
    addi    $5,$4,68
349
    sb      $5,0($20)    #D
350
    li      $3,0xffffffff
351
    slt     $4,$2,$3
352
    addi    $5,$4,68
353
    sb      $5,0($20)    #E
354
    slt     $4,$3,$2
355
    addi    $5,$4,70
356
    sb      $5,0($20)    #F
357
    sb      $23,0($20)
358
    sb      $21,0($20)
359
 
360
    #j: SLTI
361
    ori     $2,$0,'j'
362
    sb      $2,0($20)
363
    ori     $2,$0,10
364
    slti    $4,$2,12
365
    addi    $5,$4,64
366
    sb      $5,0($20)    #A
367
    slti    $4,$2,8
368
    addi    $5,$4,66
369
    sb      $5,0($20)    #B
370
    sb      $23,0($20)
371
    sb      $21,0($20)
372
 
373
    #k: SLTIU
374
    ori     $2,$0,'k'
375
    sb      $2,0($20)
376
    ori     $2,$0,10
377
    sltiu   $4,$2,12
378
    addi    $5,$4,64
379
    sb      $5,0($20)    #A
380
    sltiu   $4,$2,8
381
    addi    $5,$4,66
382
    sb      $5,0($20)    #B
383
    sb      $23,0($20)
384
    sb      $21,0($20)
385
 
386
    #l: SLTU
387
    ori     $2,$0,'l'
388
    sb      $2,0($20)
389
    ori     $2,$0,10
390
    ori     $3,$0,12
391
    slt     $4,$2,$3
392
    addi    $5,$4,64
393
    sb      $5,0($20)    #A
394
    slt     $4,$3,$2
395
    addi    $5,$4,66
396
    sb      $5,0($20)    #B
397
    sb      $23,0($20)
398
    sb      $21,0($20)
399
 
400
    #m: SUB
401
    ori     $2,$0,'m'
402
    sb      $2,0($20)
403
    ori     $3,$0,70
404
    ori     $4,$0,5
405
    sub     $2,$3,$4
406
    sb      $2,0($20)    #A
407
    sb      $23,0($20)
408
    sb      $21,0($20)
409
 
410
    #n: SUBU
411
    ori     $2,$0,'n'
412
    sb      $2,0($20)
413
    ori     $3,$0,70
414
    ori     $4,$0,5
415
    sub     $2,$3,$4
416
    sb      $2,0($20)    #A
417
    sb      $23,0($20)
418
    sb      $21,0($20)
419
 
420
    ######################################
421
    #Branch and Jump Instructions
422
    ######################################
423
BranchTest:
424
    ori     $2,$0,'B'
425
    sb      $2,0($20)
426
    ori     $2,$0,'r'
427
    sb      $2,0($20)
428
    ori     $2,$0,'a'
429
    sb      $2,0($20)
430
    ori     $2,$0,'n'
431
    sb      $2,0($20)
432
    ori     $2,$0,'c'
433
    sb      $2,0($20)
434
    ori     $2,$0,'h'
435
    sb      $2,0($20)
436
    sb      $23,0($20)
437
    sb      $21,0($20)
438
 
439
    #a: B
440
    ori     $2,$0,'a'
441
    sb      $2,0($20)
442
    ori     $10,$0,'A'
443
    ori     $11,$0,'B'
444
    b       $B1
445
    sb      $10,0($20)
446
    sb      $22,0($20)
447
$B1:
448
    sb      $11,0($20)
449
    sb      $23,0($20)
450
    sb      $21,0($20)
451
 
452
    #b: BAL
453
    ori     $2,$0,'b'
454
    sb      $2,0($20)
455
    ori     $10,$0,'A'
456
    ori     $11,$0,'B'
457
    ori     $12,$0,'C'
458
    ori     $13,$0,'D'
459
    ori     $14,$0,'E'
460
    ori     $15,$0,'X'
461
    bal     $BAL1
462
    sb      $10,0($20)
463
    sb      $13,0($20)
464
    b       $BAL2
465
    sb      $14,0($20)
466
    sb      $15,0($20)
467
$BAL1:
468
    sb      $11,0($20)
469
    jr      $31
470
    sb      $12,0($20)
471
    sb      $22,0($20)
472
$BAL2:
473
    sb      $23,0($20)
474
    sb      $21,0($20)
475
 
476
    #c: BEQ
477
    ori     $2,$0,'c'
478
    sb      $2,0($20)
479
    ori     $10,$0,'A'
480
    ori     $11,$0,'B'
481
    ori     $12,$0,'C'
482
    ori     $13,$0,'D'
483
    ori     $2,$0,100
484
    ori     $3,$0,123
485
    ori     $4,$0,123
486
    beq     $2,$3,$BEQ1
487
    sb      $10,0($20)
488
    sb      $11,0($20)
489
    beq     $3,$4,$BEQ1
490
    sb      $12,0($20)
491
    sb      $22,0($20)
492
$BEQ1:
493
    sb      $13,0($20)
494
    sb      $23,0($20)
495
    sb      $21,0($20)
496
 
497
    #d: BGEZ
498
    ori     $2,$0,'d'
499
    sb      $2,0($20)
500
    ori     $10,$0,'A'
501
    ori     $11,$0,'B'
502
    ori     $12,$0,'C'
503
    ori     $13,$0,'D'
504
    or      $15,$0,'X'
505
    ori     $2,$0,100
506
    li      $3,0xffff1234
507
    ori     $4,$0,123
508
    bgez    $3,$BGEZ1
509
    sb      $10,0($20)
510
    sb      $11,0($20)
511
    bgez    $2,$BGEZ1
512
    sb      $12,0($20)
513
    sb      $22,0($20)
514
$BGEZ1:
515
    bgez    $0,$BGEZ2
516
    nop
517
    sb      $15,0($20)
518
$BGEZ2:
519
    sb      $13,0($20)
520
    sb      $23,0($20)
521
    sb      $21,0($20)
522
 
523
    #e: BGEZAL
524
    ori     $2,$0,'e'
525
    sb      $2,0($20)
526
    ori     $10,$0,'A'
527
    ori     $11,$0,'B'
528
    ori     $12,$0,'C'
529
    ori     $13,$0,'D'
530
    ori     $14,$0,'E'
531
    ori     $15,$0,'X'
532
    li      $3,0xffff1234
533
    bgezal  $3,$BGEZAL1
534
    nop
535
    sb      $10,0($20)
536
    bgezal  $0,$BGEZAL1
537
    nop
538
    sb      $13,0($20)
539
    b       $BGEZAL2
540
    sb      $14,0($20)
541
    sb      $15,0($20)
542
$BGEZAL1:
543
    sb      $11,0($20)
544
    jr      $31
545
    sb      $12,0($20)
546
    sb      $22,0($20)
547
$BGEZAL2:
548
    sb      $23,0($20)
549
    sb      $21,0($20)
550
 
551
    #f: BGTZ
552
    ori     $2,$0,'f'
553
    sb      $2,0($20)
554
    ori     $10,$0,'A'
555
    ori     $11,$0,'B'
556
    ori     $12,$0,'C'
557
    ori     $13,$0,'D'
558
    ori     $2,$0,100
559
    li      $3,0xffff1234
560
    bgtz    $3,$BGTZ1
561
    sb      $10,0($20)
562
    sb      $11,0($20)
563
    bgtz    $2,$BGTZ1
564
    sb      $12,0($20)
565
    sb      $22,0($20)
566
$BGTZ1:
567
    sb      $13,0($20)
568
    sb      $23,0($20)
569
    sb      $21,0($20)
570
 
571
    #g: BLEZ
572
    ori     $2,$0,'g'
573
    sb      $2,0($20)
574
    ori     $10,$0,'A'
575
    ori     $11,$0,'B'
576
    ori     $12,$0,'C'
577
    ori     $13,$0,'D'
578
    ori     $2,$0,100
579
    li      $3,0xffff1234
580
    blez    $2,$BLEZ1
581
    sb      $10,0($20)
582
    sb      $11,0($20)
583
    blez    $3,$BLEZ1
584
    sb      $12,0($20)
585
    sb      $22,0($20)
586
$BLEZ1:
587
    blez    $0,$BLEZ2
588
    nop
589
    sb      $22,0($20)
590
$BLEZ2:
591
    sb      $13,0($20)
592
    sb      $23,0($20)
593
    sb      $21,0($20)
594
 
595
    #h: BLTZ
596
    ori     $2,$0,'h'
597
    sb      $2,0($20)
598
    ori     $10,$0,'A'
599
    ori     $11,$0,'B'
600
    ori     $12,$0,'C'
601
    ori     $13,$0,'D'
602
    ori     $14,$0,'E'
603
    ori     $2,$0,100
604
    li      $3,0xffff1234
605
    ori     $4,$0,0
606
    bltz    $2,$BLTZ1
607
    sb      $10,0($20)
608
    sb      $11,0($20)
609
    bltz    $3,$BLTZ1
610
    sb      $12,0($20)
611
    sb      $22,0($20)
612
$BLTZ1:
613
    bltz    $4,$BLTZ2
614
    nop
615
    sb      $13,0($20)
616
$BLTZ2:
617
    sb      $14,0($20)
618
    sb      $23,0($20)
619
    sb      $21,0($20)
620
 
621
    #i: BLTZAL
622
    ori     $2,$0,'i'
623
    sb      $2,0($20)
624
    ori     $10,$0,'A'
625
    ori     $11,$0,'B'
626
    ori     $12,$0,'C'
627
    ori     $13,$0,'D'
628
    ori     $14,$0,'E'
629
    ori     $15,$0,'X'
630
    li      $3,0xffff1234
631
    bltzal  $0,$BLTZAL1
632
    nop
633
    sb      $10,0($20)
634
    bltzal  $3,$BLTZAL1
635
    nop
636
    sb      $13,0($20)
637
    b       $BLTZAL2
638
    sb      $14,0($20)
639
    sb      $15,0($20)
640
$BLTZAL1:
641
    sb      $11,0($20)
642
    jr      $31
643
    sb      $12,0($20)
644
    sb      $22,0($20)
645
$BLTZAL2:
646
    sb      $23,0($20)
647
    sb      $21,0($20)
648
 
649
    #j: BNE
650
    ori     $2,$0,'j'
651
    sb      $2,0($20)
652
    ori     $10,$0,'A'
653
    ori     $11,$0,'B'
654
    ori     $12,$0,'C'
655
    ori     $13,$0,'D'
656
    ori     $2,$0,100
657
    ori     $3,$0,123
658
    ori     $4,$0,123
659
    bne     $3,$4,$BNE1
660
    sb      $10,0($20)
661
    sb      $11,0($20)
662
    bne     $2,$3,$BNE1
663
    sb      $12,0($20)
664
    sb      $22,0($20)
665
$BNE1:
666
    sb      $13,0($20)
667
    sb      $23,0($20)
668
    sb      $21,0($20)
669
 
670
    #k: J
671
    ori     $2,$0,'k'
672
    sb      $2,0($20)
673
    ori     $10,$0,'A'
674
    ori     $11,$0,'B'
675
    ori     $15,$0,'X'
676
    j       $J1
677
    sb      $10,0($20)
678
    sb      $15,0($20)
679
$J1:
680
    sb      $11,0($20)
681
    sb      $23,0($20)
682
    sb      $21,0($20)
683
 
684
    #l: JAL
685
    ori     $2,$0,'l'
686
    sb      $2,0($20)
687
    ori     $10,$0,'A'
688
    ori     $11,$0,'B'
689
    ori     $12,$0,'C'
690
    ori     $13,$0,'D'
691
    ori     $14,$0,'E'
692
    ori     $15,$0,'X'
693
    jal     $JAL1
694
    sb      $10,0($20)
695
    sb      $13,0($20)
696
    b       $JAL2
697
    sb      $14,0($20)
698
    sb      $15,0($20)
699
$JAL1:
700
    sb      $11,0($20)
701
    jr      $31
702
    sb      $12,0($20)
703
    sb      $22,0($20)
704
$JAL2:
705
    sb      $23,0($20)
706
    sb      $21,0($20)
707
 
708
    #m: JALR
709
    ori     $2,$0,'m'
710
    sb      $2,0($20)
711
    ori     $10,$0,'A'
712
    ori     $11,$0,'B'
713
    ori     $12,$0,'C'
714
    ori     $13,$0,'D'
715
    ori     $14,$0,'E'
716
    ori     $15,$0,'X'
717
    la      $3,$JALR1
718
    jalr    $3
719
    sb      $10,0($20)
720
    sb      $13,0($20)
721
    b       $JALR2
722
    sb      $14,0($20)
723
    sb      $15,0($20)
724
$JALR1:
725
    sb      $11,0($20)
726
    jr      $31
727
    sb      $12,0($20)
728
    sb      $22,0($20)
729
$JALR2:
730
    sb      $23,0($20)
731
    sb      $21,0($20)
732
 
733
    #n: JR
734
    ori     $2,$0,'n'
735
    sb      $2,0($20)
736
    ori     $10,$0,'A'
737
    ori     $11,$0,'B'
738
    ori     $15,$0,'X'
739
    la      $3,$JR1
740
    jr      $3
741
    sb      $10,0($20)
742
    sb      $15,0($20)
743
$JR1:
744
    sb      $11,0($20)
745
    sb      $23,0($20)
746
    sb      $21,0($20)
747
 
748
    #o: NOP
749
    ori     $2,$0,'o'
750
    sb      $2,0($20)
751
    ori     $2,$0,65
752
    nop
753
    sb      $2,0($20)
754
    sb      $23,0($20)
755
    sb      $21,0($20)
756
 
757
 #   b     LoadTest
758
 
759 4 ja_rd
 
760 2 ja_rd
BreakTest:
761 4 ja_rd
    .ifgt TEST_BREAK
762 2 ja_rd
    #p: BREAK
763 4 ja_rd
    ori     $2,$0,'p'       # check if it jumps to break address and comes back
764 2 ja_rd
    sb      $2,0($20)
765
    ori     $2,$0,'z'
766
    ori     $4,$0,59
767
    break   0
768
    addi    $4,$4,1
769
    sb      $4,0($20)
770 4 ja_rd
 
771
    break   0               # check if load instruction is aborted (@log)
772
    lb      $2,16($2)
773
 
774
    break   0               # check if jump instruction is aborted (@log)
775 9 ja_rd
    j       break_jump_test1
776 4 ja_rd
    add     $4,$4,5
777
 
778 9 ja_rd
break_jump_test1:
779 4 ja_rd
    add     $4,$4,1         # make sure the jump shows in the log (@log)
780
 
781 29 ja_rd
    break   0               # check if store instruction is aborted
782
    sb      $4,0($20)
783
 
784 152 ja_rd
    j       break_jump_test2 # check if break works in delay slot of jump
785 29 ja_rd
    break   0
786 9 ja_rd
    nop
787
    j       break_continue
788
    nop
789
 
790
break_jump_test2:
791
    add     $4,$4,1
792
 
793
break_continue:
794 2 ja_rd
    sb      $23,0($20)
795 4 ja_rd
    sb      $21,0($20)
796
    .endif
797 2 ja_rd
 
798
    #q: SYSCALL
799 14 ja_rd
    ori     $2,$0,'q'       # check if it jumpts to trap vector and comes back
800 2 ja_rd
    sb      $2,0($20)
801
    ori     $4,$0,61
802
    syscall 0
803
    addi    $4,$4,-1
804
    sb      $4,0($20)
805 14 ja_rd
 
806
    syscall 0               # check if load instruction is aborted (@log)
807
    lb      $2,16($2)
808
 
809
    syscall 0               # check if jump instruction is aborted (@log)
810
    j       syscall_jump_test1
811
    add     $4,$4,5
812
 
813
syscall_jump_test1:
814
    add     $4,$4,1         # make sure the jump shows in the log (@log)
815
 
816 152 ja_rd
    j       syscall_jump_test2 # check if syscall works in delay slot of jump
817
    syscall 0
818 14 ja_rd
    nop
819
    j       syscall_continue
820
    nop
821
 
822
syscall_jump_test2:
823
    add     $4,$4,1
824
 
825
syscall_continue:
826 2 ja_rd
    sb      $23,0($20)
827
    sb      $21,0($20)
828
 
829
 
830
    ######################################
831
    #Load, Store, and Memory Control Instructions
832
    ######################################
833
LoadTest:
834
    ori     $2,$0,'L'
835
    sb      $2,0($20)
836
    ori     $2,$0,'o'
837
    sb      $2,0($20)
838
    ori     $2,$0,'a'
839
    sb      $2,0($20)
840
    ori     $2,$0,'d'
841
    sb      $2,0($20)
842
    sb      $23,0($20)
843
    sb      $21,0($20)
844
 
845
    #a: LB
846
    ori     $2,$0,'a'
847
    sb      $2,0($20)
848
    or      $2,$0,$24
849
    li      $3,0x414243fc
850
    sw      $3,16($2)              # 16($2)    = 0x414243fc
851
    lb      $4,16($2)              # $4        = 0x41
852
    sb      $4,0($20)              # UART      = 0x41
853
    lb      $4,17($2)              # $4        = 0x42
854
    nop
855
    sb      $4,0($20)              # UART      = 0x42
856
    lb      $4,18($2)              # $4        = 0x43
857
    nop
858
    sb      $4,0($20)              # UART      = 0x43
859
    lb      $2,19($2)              # $2        = 0xffff.fffc
860
    nop
861
    sra     $3,$2,8                # $3        = 0xffff.ffff
862
    addi    $3,$3,0x45             # $3        = 0x44
863
    sb      $3,0($20)              # UART      = 0x44
864
    addi    $2,$2,0x49             # $4        = 0x45, overflow
865
    sb      $2,0($20)              # UART      = 0x45
866
    sb      $23,0($20)             # UART      = CR
867
    sb      $21,0($20)             # UART      = LF
868
 
869
    #b: LBU
870
    ori     $2,$0,'b'
871
    sb      $2,0($20)
872
    or      $2,$0,$24
873
    li      $3,0x41424344
874
    sw      $3,16($2)
875
    lb      $4,16($2)
876
    sb      $4,0($20)
877
    lb      $4,17($2)
878
    sb      $4,0($20)
879
    lb      $4,18($2)
880
    sb      $4,0($20)
881
    lb      $2,19($2)
882
    sb      $2,0($20)
883
    sb      $23,0($20)
884
    sb      $21,0($20)
885
 
886
    #c: LH
887
    ori     $2,$0,'c'
888
    sb      $2,0($20)
889
    or      $2,$0,$24
890
    li      $3,0x00410042
891
    sw      $3,16($2)
892
    lh      $4,16($2)
893
    sb      $4,0($20)
894
    lh      $2,18($2)
895
    sb      $2,0($20)
896
    sb      $23,0($20)
897
    sb      $21,0($20)
898
 
899
    #d: LHU
900
    ori     $2,$0,'d'
901
    sb      $2,0($20)
902
    or      $2,$0,$24
903
    li      $3,0x00410042
904
    sw      $3,16($2)
905
    lh      $4,16($2)
906
    sb      $4,0($20)
907
    lh      $2,18($2)
908
    sb      $2,0($20)
909
    sb      $23,0($20)
910
    sb      $21,0($20)
911
 
912
    #e: LW
913
    ori     $2,$0,'e'
914
    sb      $2,0($20)
915
    or      $2,$0,$24
916
    li      $3,'A'
917
    sw      $3,16($2)
918
    ori     $3,$0,0
919
    lw      $2,16($2)
920
    sb      $2,0($20)
921
    sb      $23,0($20)
922
    sb      $21,0($20)
923
 
924
    .ifgt TEST_UNALIGNED_LOADS
925
    #f: LWL & LWR
926
    ori     $2,$0,'f'
927
    sb      $2,0($20)
928
    or      $2,$0,$24
929
    li      $3,'A'
930
    sw      $3,16($2)
931
    ori     $3,$0,0
932
    lwl     $2,16($2)
933
    lwr     $2,16($2)
934
    sb      $2,0($20)
935
    sb      $23,0($20)
936
    sb      $21,0($20)
937
    .endif
938
 
939
    #g: SB
940
    ori     $2,$0,'g'
941
    sb      $2,0($20)
942
    ori     $2,$0,'A'
943
    sb      $2,0($20)
944
    sb      $23,0($20)
945
    sb      $21,0($20)
946
 
947
    #h: SH
948
    ori     $2,$0,'h'
949
    sb      $2,0($20)
950
    or      $4,$0,$24
951
    ori     $2,$0,0x4142
952
    sh      $2,16($4)
953
    lb      $3,16($4)
954
    sb      $3,0($20)
955
    lb      $2,17($4)
956
    sb      $2,0($20)
957
    sb      $23,0($20)
958
    sb      $21,0($20)
959
 
960
    #i: SW
961
    ori     $2,$0,'i'
962
    sb      $2,0($20)
963
    or      $2,$0,$24
964
    li      $3,0x41424344
965
    sw      $3,16($2)
966
    lb      $4,16($2)
967
    sb      $4,0($20)
968
    lb      $4,17($2)
969
    sb      $4,0($20)
970
    lb      $4,18($2)
971
    sb      $4,0($20)
972
    lb      $2,19($2)
973
    sb      $2,0($20)
974
    sb      $23,0($20)
975
    sb      $21,0($20)
976
 
977
    .ifgt  TEST_UNALIGNED_STORES
978
    #j: SWL & SWR
979
    ori     $2,$0,'j'
980
    sb      $2,0($20)
981
    or      $2,$0,$24
982
    li      $3,0x41424344
983
    swl     $3,16($2)
984
    swr     $3,16($2)
985
    lb      $4,16($2)
986
    sb      $4,0($20)
987
    lb      $4,17($2)
988
    sb      $4,0($20)
989
    lb      $4,18($2)
990
    sb      $4,0($20)
991
    lb      $2,19($2)
992
    sb      $2,0($20)
993
    sb      $23,0($20)
994
    sb      $21,0($20)
995
    .endif
996
 
997
    ######################################
998
    #Logical Instructions
999
    ######################################
1000
LogicalTest:
1001
    ori     $2,$0,'L'
1002
    sb      $2,0($20)
1003
    ori     $2,$0,'o'
1004
    sb      $2,0($20)
1005
    ori     $2,$0,'g'
1006
    sb      $2,0($20)
1007
    ori     $2,$0,'i'
1008
    sb      $2,0($20)
1009
    ori     $2,$0,'c'
1010
    sb      $2,0($20)
1011
    sb      $23,0($20)
1012
    sb      $21,0($20)
1013
 
1014
    #a: AND
1015
    ori     $2,$0,'a'
1016
    sb      $2,0($20)
1017
    ori     $2,$0,0x0741
1018
    ori     $3,$0,0x60f3
1019
    and     $4,$2,$3
1020
    sb      $4,0($20)
1021
    sb      $23,0($20)
1022
    sb      $21,0($20)
1023
 
1024
    #b: ANDI
1025
    ori     $2,$0,'b'
1026
    sb      $2,0($20)
1027
    ori     $2,$0,0x0741
1028
    andi    $4,$2,0x60f3
1029
    sb      $4,0($20)
1030
    sb      $23,0($20)
1031
    sb      $21,0($20)
1032
 
1033
    #c: LUI
1034
    ori     $2,$0,'c'
1035
    sb      $2,0($20)
1036
    lui     $2,0x41
1037
    srl     $3,$2,16
1038
    sb      $3,0($20)
1039
    sb      $23,0($20)
1040
    sb      $21,0($20)
1041
 
1042
    #d: NOR
1043
    ori     $2,$0,'d'
1044
    sb      $2,0($20)
1045
    li      $2,0xf0fff08e
1046
    li      $3,0x0f0f0f30
1047
    nor     $4,$2,$3
1048
    sb      $4,0($20)
1049
    sb      $23,0($20)
1050
    sb      $21,0($20)
1051
 
1052
    #e: OR
1053
    ori     $2,$0,'e'
1054
    sb      $2,0($20)
1055
    ori     $2,$0,0x40
1056
    ori     $3,$0,0x01
1057
    or      $4,$2,$3
1058
    sb      $4,0($20)
1059
    sb      $23,0($20)
1060
    sb      $21,0($20)
1061
 
1062
    #f: ORI
1063
    ori     $2,$0,'f'
1064
    sb      $2,0($20)
1065
    ori     $2,$0,0x40
1066
    ori     $4,$2,0x01
1067
    sb      $4,0($20)
1068
    sb      $23,0($20)
1069
    sb      $21,0($20)
1070
 
1071
    #g: XOR
1072
    ori     $2,$0,'g'
1073
    sb      $2,0($20)
1074
    ori     $2,$0,0xf043
1075
    ori     $3,$0,0xf002
1076
    xor     $4,$2,$3
1077
    sb      $4,0($20)
1078
    sb      $23,0($20)
1079
    sb      $21,0($20)
1080
 
1081
    #h: XORI
1082
    ori     $2,$0,'h'
1083
    sb      $2,0($20)
1084
    ori     $2,$0,0xf043
1085
    xor     $4,$2,0xf002
1086
    sb      $4,0($20)
1087
    sb      $23,0($20)
1088
    sb      $21,0($20)
1089
 
1090
 
1091
    ######################################
1092
    #Move Instructions
1093
    ######################################
1094
MoveTest:
1095
    ori     $2,$0,'M'
1096
    sb      $2,0($20)
1097
    ori     $2,$0,'o'
1098
    sb      $2,0($20)
1099
    ori     $2,$0,'v'
1100
    sb      $2,0($20)
1101
    ori     $2,$0,'e'
1102
    sb      $2,0($20)
1103
    sb      $23,0($20)
1104
    sb      $21,0($20)
1105
 
1106 25 ja_rd
    # HI and LO are only implemented if the mul/div block is
1107
    .ifgt (TEST_DIV + TEST_MUL)
1108 2 ja_rd
    #a: MFHI
1109
    ori     $2,$0,'a'
1110
    sb      $2,0($20)
1111
    ori     $2,$0,65
1112
    mthi    $2
1113
    mfhi    $3
1114
    sb      $3,0($20)
1115
    sb      $23,0($20)
1116
    sb      $21,0($20)
1117
 
1118
    #b: MFLO
1119
    ori     $2,$0,'b'
1120
    sb      $2,0($20)
1121
    ori     $2,$0,65
1122
    mtlo    $2
1123
    mflo    $3
1124
    sb      $3,0($20)
1125
    sb      $23,0($20)
1126
    sb      $21,0($20)
1127
 
1128
    #c: MTHI
1129
    ori     $2,$0,'c'
1130
    sb      $2,0($20)
1131
    ori     $2,$0,65
1132
    mthi    $2
1133
    mfhi    $3
1134
    sb      $3,0($20)
1135
    sb      $23,0($20)
1136
    sb      $21,0($20)
1137
 
1138
    #d: MTLO
1139
    ori     $2,$0,'d'
1140
    sb      $2,0($20)
1141 66 ja_rd
    ori     $2,$0,66   # use 'B' instead of 'A' to cach change in HI and LO
1142 2 ja_rd
    mtlo    $2
1143
    mflo    $3
1144
    sb      $3,0($20)
1145
    sb      $23,0($20)
1146
    sb      $21,0($20)
1147 25 ja_rd
    .endif
1148 2 ja_rd
 
1149
    ######################################
1150
    #Shift Instructions
1151
    ######################################
1152
ShiftTest:
1153
    ori     $2,$0,'S'
1154
    sb      $2,0($20)
1155
    ori     $2,$0,'h'
1156
    sb      $2,0($20)
1157
    ori     $2,$0,'i'
1158
    sb      $2,0($20)
1159
    ori     $2,$0,'f'
1160
    sb      $2,0($20)
1161
    ori     $2,$0,'t'
1162
    sb      $2,0($20)
1163
    sb      $23,0($20)
1164
    sb      $21,0($20)
1165
 
1166
    #a: SLL
1167
    ori     $2,$0,'a'
1168
    sb      $2,0($20)
1169
    li      $2,0x40414243
1170
    sll     $3,$2,8
1171
    srl     $3,$3,24
1172
    sb      $3,0($20)
1173
    sb      $23,0($20)
1174
    sb      $21,0($20)
1175
 
1176
    #b: SLLV
1177
    ori     $2,$0,'b'
1178
    sb      $2,0($20)
1179
    li      $2,0x40414243
1180
    ori     $3,$0,8
1181
    sllv    $3,$2,$3
1182
    srl     $3,$3,24
1183
    sb      $3,0($20)
1184
    sb      $23,0($20)
1185
    sb      $21,0($20)
1186
 
1187
    #c: SRA
1188
    ori     $2,$0,'c'
1189
    sb      $2,0($20)
1190
    li      $2,0x40414243
1191
    sra     $3,$2,16
1192
    sb      $3,0($20)
1193
    li      $2,0x84000000
1194
    sra     $3,$2,25
1195
    sub     $3,$3,0x80
1196
    sb      $3,0($20)
1197
    sb      $23,0($20)
1198
    sb      $21,0($20)
1199
 
1200
    #d: SRAV
1201
    ori     $2,$0,'d'
1202
    sb      $2,0($20)
1203
    li      $2,0x40414243
1204
    ori     $3,$0,16
1205
    srav    $3,$2,$3
1206
    sb      $3,0($20)
1207
    ori     $3,$0,25
1208
    li      $2,0x84000000
1209
    srav    $3,$2,$3
1210
    sub     $3,$3,0x80
1211
    sb      $3,0($20)
1212
    sb      $23,0($20)
1213
    sb      $21,0($20)
1214
 
1215
    #e: SRL
1216
    ori     $2,$0,'e'
1217
    sb      $2,0($20)
1218
    li      $2,0x40414243
1219
    srl     $3,$2,16
1220
    sb      $3,0($20)
1221
    li      $2,0x84000000
1222
    srl     $3,$2,25
1223
    sb      $3,0($20)
1224
    sb      $23,0($20)
1225
    sb      $21,0($20)
1226
 
1227
    #f: SRLV
1228
    ori     $2,$0,'f'
1229
    sb      $2,0($20)
1230
    li      $2,0x40414243
1231
    ori     $3,$0,16
1232
    srlv    $4,$2,$3
1233
    sb      $4,0($20)
1234
    ori     $3,$0,25
1235
    li      $2,0x84000000
1236
    srlv    $3,$2,$3
1237
    sb      $3,0($20)
1238
    sb      $23,0($20)
1239
    sb      $21,0($20)
1240
 
1241 165 ja_rd
    ######################################
1242
    #Emulated MIPS32r2 Instructions
1243
    ######################################
1244
    .ifgt   EMU_MIPS32
1245
    ori     $2,$0,'M'
1246
    sb      $2,0($20)
1247
    ori     $2,$0,'i'
1248
    sb      $2,0($20)
1249
    ori     $2,$0,'p'
1250
    sb      $2,0($20)
1251
    ori     $2,$0,'s'
1252
    sb      $2,0($20)
1253
    ori     $2,$0,'3'
1254
    sb      $2,0($20)
1255
    ori     $2,$0,'2'
1256
    sb      $2,0($20)
1257
    ori     $2,$0,'r'
1258
    sb      $2,0($20)
1259
    ori     $2,$0,'2'
1260
    sb      $2,0($20)
1261
    sb      $23,0($20)
1262
    sb      $21,0($20)
1263
 
1264
    #-- EXT ---------------------------
1265
    ori     $a1,$zero,'a'
1266
    sb      $a1,0($20)
1267
    li      $a0,0x01234567
1268
    ext     $a1,$a0,12,8
1269
    addi    $a1,$a1,'A' - 0x34
1270
    sb      $a1,0($20)
1271
    ext     $a1,$a0,0,8
1272
    addi    $a1,$a1,'B' - 0x67
1273
    sb      $a1,0($20)
1274
    ext     $a1,$a0,0,4
1275
    addi    $a1,$a1,'C' - 0x7
1276
    sb      $a1,0($20)
1277
    ext     $a2,$a0,20,12
1278
    addi    $a2,$a2,'D' - 0x012
1279
    sb      $a2,0($20)
1280
 
1281
    sb      $23,0($20)
1282
    sb      $21,0($20)
1283
 
1284
    #-- INS ---------------------------
1285
    ori     $a1,$zero,'b'
1286
    sb      $a1,0($20)
1287
    li      $a0,0x01234567
1288
    ori     $a2,$zero,0xc35a
1289
test_ins_1:
1290
    move    $a1,$a0
1291
    ins     $a1,$a2,0,8
1292
    li      $a3,0x0123455a
1293
    bne     $a3,$a1,test_ins_2
1294
    ori     $a1,$zero,'A'
1295
    sb      $a1,0($20)
1296
test_ins_2:
1297
    move    $a1,$a0
1298
    ins     $a1,$a2,4,8
1299
    li      $a3,0x012345a7
1300
    bne     $a3,$a1,test_ins_3
1301
    ori     $a1,$zero,'B'
1302
    sb      $a1,0($20)
1303
test_ins_3:
1304
    move    $a1,$a0
1305
    ins     $a1,$a2,24,8
1306
    li      $a3,0x5a234567
1307
    bne     $a3,$a1,test_ins_4
1308
    ori     $a1,$zero,'C'
1309
    sb      $a1,0($20)
1310
test_ins_4:
1311
    move    $a1,$a0
1312
    ins     $a1,$a2,30,2
1313
    li      $a3,0x81234567
1314
    bne     $a3,$a1,test_ins_5
1315
    ori     $a1,$zero,'D'
1316
    sb      $a1,0($20)
1317
test_ins_5:
1318
    sb      $23,0($20)
1319
    sb      $21,0($20)
1320
 
1321
    #-- CLZ ---------------------------
1322
    ori     $a1,$zero,'c'
1323
    sb      $a1,0($20)
1324
 
1325
    li      $a1,0x00080000
1326
    clz     $a1,$a1
1327
    addiu   $a1,$a1,'A'-12
1328
    sb      $a1,0($20)
1329
 
1330
    li      $a1,0x40000000
1331
    clz     $a1,$a1
1332
    addiu   $a1,$a1,'B'-1
1333
    sb      $a1,0($20)
1334
 
1335
    clz     $a1,$zero
1336
    addiu   $a1,$a1,'C'-32
1337
    sb      $a1,0($20)
1338
 
1339
    li      $k1,0x80000000
1340
    clz     $k0,$k1
1341
    addiu   $a1,$k0,'D'-0
1342
    sb      $a1,0($20)
1343
 
1344
    sb      $23,0($20)
1345
    sb      $21,0($20)
1346
 
1347
    #-- CLO ---------------------------
1348
    ori     $a1,$zero,'d'
1349
    sb      $a1,0($20)
1350
 
1351
    li      $a1,0xfff7ffff
1352
    clo     $a1,$a1
1353
    addiu   $a1,$a1,'A'-12
1354
    sb      $a1,0($20)
1355
 
1356
    li      $a1,0xbfffffff
1357
    clo     $a1,$a1
1358
    addiu   $a1,$a1,'B'-1
1359
    sb      $a1,0($20)
1360
 
1361
    li      $a1,0xffffffff
1362
    clo     $a1,$a1
1363
    addiu   $a1,$a1,'C'-32
1364
    sb      $a1,0($20)
1365
 
1366
    li      $k1,0x7fffffff
1367
    clo     $k0,$k1
1368
    addiu   $a1,$k0,'D'-0
1369
    sb      $a1,0($20)
1370
 
1371
    sb      $23,0($20)
1372
    sb      $21,0($20)
1373
    .endif
1374
 
1375
    # Print 'Done'; the rest of the tests are for log matching only
1376 2 ja_rd
    ori     $2,$0,'D'
1377
    sb      $2,0($20)
1378
    ori     $2,$0,'o'
1379
    sb      $2,0($20)
1380
    ori     $2,$0,'n'
1381
    sb      $2,0($20)
1382
    ori     $2,$0,'e'
1383
    sb      $2,0($20)
1384
    sb      $23,0($20)
1385
    sb      $21,0($20)
1386 38 ja_rd
 
1387 165 ja_rd
 
1388 90 ja_rd
    # These tests are to be evaluated by matching logs with the software
1389
    # simulator. There is no need to perform any actual tests here, if there is
1390
    # any error it will show up as a mismatch in the logs.
1391
 
1392
    #-- Arithmetic --------------------------------------------------
1393
    ori     $s0,$zero,0xa5a5
1394
    ori     $s1,$zero,15
1395
    ori     $s2,$zero,1
1396
    li      $s3,-1
1397
    li      $s4,-1000
1398
    li      $s5,0x80000000
1399
    li      $s6,0x7fffffff
1400
 
1401
    #-- ADD ---------------------------
1402
    move    $t0,$s0                     # P + P = P
1403
    move    $t1,$s1
1404
    add     $t0,$t1,$s1
1405
    move    $t0,$s0                     # P + N = P
1406
    move    $t1,$s1
1407
    add     $t0,$t1,$s3
1408
    move    $t0,$s0                     # P + N = N
1409
    move    $t1,$s1
1410
    add     $t0,$t1,$s4
1411
    move    $t0,$s0                     # P + P = N (overflow)
1412
    move    $t1,$s6
1413
    add     $t0,$t1,$s6
1414
    move    $t0,$s0                     # N + N = P (overflow)
1415
    move    $t1,$s5
1416
    add     $t0,$t1,$s5
1417
 
1418
    #-- ADDI --------------------------
1419
    move    $t0,$s0                     # N + N = P (overflow)
1420
    move    $t1,$s5
1421
    addi    $t0,$t1,-1
1422
    move    $t0,$s0                     # N + P = N
1423
    move    $t1,$s5
1424
    addi    $t0,$t1,15
1425
    move    $t0,$s0                     # N + P = P
1426
    move    $t1,$s3
1427
    addi    $t0,$t1,2
1428
    move    $t0,$s0                     # P + P = P
1429
    move    $t1,$s1
1430
    addi    $t0,$t1,2
1431
    move    $t0,$s0                     # P + P = N (overflow)
1432
    move    $t1,$s6
1433
    addi    $t0,$t1,2
1434
 
1435
    #-- ADDIU -------------------------
1436
    move    $t0,$s0                     # N + N = P (overflow)
1437
    move    $t1,$s5
1438
    addiu   $t0,$t1,-1
1439
    move    $t0,$s0                     # N + P = N
1440
    move    $t1,$s5
1441
    addiu   $t0,$t1,15
1442
    move    $t0,$s0                     # N + P = P
1443
    move    $t1,$s3
1444
    addiu   $t0,$t1,2
1445
    move    $t0,$s0                     # P + P = P
1446
    move    $t1,$s1
1447
    addiu   $t0,$t1,2
1448
    move    $t0,$s0                     # P + P = N (overflow)
1449
    move    $t1,$s6
1450
    addiu   $t0,$t1,2
1451
 
1452
    #-- ADDU --------------------------
1453
    move    $t0,$s0                     # P + P = P
1454
    move    $t1,$s1
1455
    addu    $t0,$t1,$s1
1456
    move    $t0,$s0                     # P + N = P
1457
    move    $t1,$s1
1458
    addu    $t0,$t1,$s3
1459
    move    $t0,$s0                     # P + N = N
1460
    move    $t1,$s1
1461
    addu    $t0,$t1,$s4
1462
    move    $t0,$s0                     # P + P = N (overflow)
1463
    move    $t1,$s6
1464
    addu    $t0,$t1,$s6
1465
    move    $t0,$s0                     # N + N = P (overflow)
1466
    move    $t1,$s5
1467
    addu    $t0,$t1,$s5
1468
 
1469
    #-- SUB ---------------------------
1470
    move    $t0,$s0                     # P - P = P
1471
    move    $t1,$s2
1472
    sub     $t0,$t1,$s1
1473
    move    $t0,$s0                     # P - N = P
1474
    move    $t1,$s1
1475
    add     $t0,$t1,$s3
1476
    move    $t0,$s0                     # P + N = N
1477
    move    $t1,$s1
1478
    add     $t0,$t1,$s4
1479
    move    $t0,$s0                     # P + P = N (overflow)
1480
    move    $t1,$s6
1481
    add     $t0,$t1,$s6
1482
    move    $t0,$s0                     # N + N = P (overflow)
1483
    move    $t1,$s5
1484
    add     $t0,$t1,$s5
1485
 
1486
    # SLT, SLTI, SLTIU
1487
    ori     $a2,$zero,0xa5a5
1488
    ori     $a0,$zero,15
1489
    ori     $a1,$zero,1
1490
    move    $v0,$a3
1491
    slt     $v0,$a0,$a1
1492
    move    $v0,$a3
1493
    slt     $v0,$a1,$a0
1494
    move    $v0,$a3
1495
    slti    $v0,$a0,1
1496
    move    $v0,$a3
1497
    slti    $v0,$a1,15
1498
    move    $v0,$a3
1499
    sltiu   $v0,$a0,1
1500
    move    $v0,$a3
1501
    sltiu   $v0,$a1,15
1502
    li      $a1,0xa5a5
1503
    li      $a0,1029
1504
    addiu   $a0,$a0,-2000
1505
    sltu    $a1,$a0,1000
1506
 
1507
 
1508
    #-- Relative jumps ----------------------------------------------
1509
    li      $s0,0x7fffffff
1510
    ori     $s1,1000
1511
    ori     $s1,15
1512
    ori     $s1,2
1513
    li      $s4,0x80000000
1514
    li      $s5,-1001
1515
    li      $s6,-16
1516
    li      $s7,-3
1517
 
1518
    bgtz    $s1,test_b0
1519
    nop
1520
    ori     $v0,0x5500
1521
test_b0:
1522
    bgtz    $s7,test_b1
1523
    nop
1524
    ori     $v0,0x5501
1525
test_b1:
1526
    bgtz    $s0,test_b2
1527
    nop
1528
    ori     $v0,0x5502
1529
test_b2:
1530
    bgtz    $s4,test_b3
1531
    nop
1532
    ori     $v0,0x5503
1533
test_b3:
1534
    bgez    $s1,test_b4
1535
    nop
1536
    ori     $v0,0x5500
1537
test_b4:
1538
    bgez    $s7,test_b5
1539
    nop
1540
    ori     $v0,0x5501
1541
test_b5:
1542
    bgez    $s0,test_b6
1543
    nop
1544
    ori     $v0,0x5502
1545
test_b6:
1546
    bgez    $s4,test_b7
1547
    nop
1548
    ori     $v0,0x5503
1549
test_b7:
1550
    bltz    $s1,test_b8
1551
    nop
1552
    ori     $v0,0x5500
1553
test_b8:
1554
    bltz    $s7,test_b9
1555
    nop
1556
    ori     $v0,0x5501
1557
test_b9:
1558
    bltz    $s0,test_b10
1559
    nop
1560
    ori     $v0,0x5502
1561
test_b10:
1562
    bltz    $s4,test_b11
1563
    nop
1564
    ori     $v0,0x5503
1565
test_b11:
1566
 
1567 2 ja_rd
$DONE:
1568
    j       $DONE
1569
    nop
1570 148 ja_rd
 
1571
# void setup_cache(void) -- invalidates all I- and D-Cache lines (uses no RAM)
1572
setup_cache:
1573 152 ja_rd
    li      $a0,0x00010002      # Enable I-cache line invalidation
1574 148 ja_rd
    mtc0    $a0,$12
1575
 
1576
    # In order to invalidate a I-Cache line we have to write its tag number to
1577
    # any address while bits CP0[12].17:16=01. The write will be executed as a
1578
    # regular write too, as a side effect, so we need to choose a harmless
1579
    # target address. The BSS will do -- it will be cleared later.
1580
    # We'll cover all ICACHE_NUM_LINES lines no matter what the starting
1581
    # address is, anyway.
1582
 
1583
    la      $a0,__bss_start
1584
    li      $a2,0
1585
    li      $a1,ICACHE_NUM_LINES-1
1586
 
1587
inv_i_cache_loop:
1588
    sw      $a2,0($a0)
1589
    blt     $a2,$a1,inv_i_cache_loop
1590
    addi    $a2,1
1591
 
1592
    # Now, the D-Cache is different. To invalidate a D-Cache line you just
1593
    # read from it (by proper selection of a dummy target address)  while bits
1594
    # CP0[12].17:16=01. The data read is undefined and should be discarded.
1595
 
1596
    li      $a0,0               # Use any base address that is mapped
1597
    li      $a2,0
1598
    li      $a1,DCACHE_NUM_LINES-1
1599
 
1600
inv_d_cache_loop:
1601
    lw      $zero,0($a0)
1602
    addi    $a0,DCACHE_LINE_SIZE*4
1603
    blt     $a2,$a1,inv_d_cache_loop
1604
    addi    $a2,1
1605
 
1606 152 ja_rd
    li      $a1,0x00020002      # Leave with cache enabled
1607 148 ja_rd
    jr      $ra
1608
    mtc0    $a1,$12
1609 2 ja_rd
    .set    reorder
1610
    .end    entry
1611
 

powered by: WebSVN 2.1.0

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