| 1 | # SPIM S20 MIPS simulator.
|
---|
| 2 | # The default trap handler for spim.
|
---|
| 3 | #
|
---|
| 4 | # Copyright (C) 1990-2000 James Larus, larus@cs.wisc.edu.
|
---|
| 5 | # ALL RIGHTS RESERVED.
|
---|
| 6 | #
|
---|
| 7 | # SPIM is distributed under the following conditions:
|
---|
| 8 | #
|
---|
| 9 | # You may make copies of SPIM for your own use and modify those copies.
|
---|
| 10 | #
|
---|
| 11 | # All copies of SPIM must retain my name and copyright notice.
|
---|
| 12 | #
|
---|
| 13 | # You may not sell SPIM or distributed SPIM in conjunction with a commerical
|
---|
| 14 | # product or service without the expressed written consent of James Larus.
|
---|
| 15 | #
|
---|
| 16 | # THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
---|
| 17 | # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
---|
| 18 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
---|
| 19 | # PURPOSE.
|
---|
| 20 | #
|
---|
| 21 |
|
---|
| 22 | # $Header: /cvs/coco08/group6/assignment4/trap.handler,v 1.1 2008/11/06 10:06:41 svhaastr Exp $
|
---|
| 23 |
|
---|
| 24 |
|
---|
| 25 | # Define the exception handling code. This must go first!
|
---|
| 26 |
|
---|
| 27 | .kdata
|
---|
| 28 | __m1_: .asciiz " Exception "
|
---|
| 29 | __m2_: .asciiz " occurred and ignored\n"
|
---|
| 30 | __e0_: .asciiz " [Interrupt] "
|
---|
| 31 | __e1_: .asciiz ""
|
---|
| 32 | __e2_: .asciiz ""
|
---|
| 33 | __e3_: .asciiz ""
|
---|
| 34 | __e4_: .asciiz " [Unaligned address in inst/data fetch] "
|
---|
| 35 | __e5_: .asciiz " [Unaligned address in store] "
|
---|
| 36 | __e6_: .asciiz " [Bad address in text read] "
|
---|
| 37 | __e7_: .asciiz " [Bad address in data/stack read] "
|
---|
| 38 | __e8_: .asciiz " [Error in syscall] "
|
---|
| 39 | __e9_: .asciiz " [Breakpoint] "
|
---|
| 40 | __e10_: .asciiz " [Reserved instruction] "
|
---|
| 41 | __e11_: .asciiz ""
|
---|
| 42 | __e12_: .asciiz " [Arithmetic overflow] "
|
---|
| 43 | __e13_: .asciiz " [Inexact floating point result] "
|
---|
| 44 | __e14_: .asciiz " [Invalid floating point result] "
|
---|
| 45 | __e15_: .asciiz " [Divide by 0] "
|
---|
| 46 | __e16_: .asciiz " [Floating point overflow] "
|
---|
| 47 | __e17_: .asciiz " [Floating point underflow] "
|
---|
| 48 | __excp: .word __e0_,__e1_,__e2_,__e3_,__e4_,__e5_,__e6_,__e7_,__e8_,__e9_
|
---|
| 49 | .word __e10_,__e11_,__e12_,__e13_,__e14_,__e15_,__e16_,__e17_
|
---|
| 50 | s1: .word 0
|
---|
| 51 | s2: .word 0
|
---|
| 52 |
|
---|
| 53 | .ktext 0x80000080
|
---|
| 54 | .set noat
|
---|
| 55 | # Because we are running in the kernel, we can use $k0/$k1 without
|
---|
| 56 | # saving their old values.
|
---|
| 57 | move $k1 $at # Save $at
|
---|
| 58 | .set at
|
---|
| 59 | sw $v0 s1 # Not re-entrent and we can't trust $sp
|
---|
| 60 | sw $a0 s2
|
---|
| 61 | mfc0 $k0 $13 # Cause
|
---|
| 62 | sgt $v0 $k0 0x44 # ignore interrupt exceptions
|
---|
| 63 | bgtz $v0 ret
|
---|
| 64 | addu $0 $0 0
|
---|
| 65 | li $v0 4 # syscall 4 (print_str)
|
---|
| 66 | la $a0 __m1_
|
---|
| 67 | syscall
|
---|
| 68 | li $v0 1 # syscall 1 (print_int)
|
---|
| 69 | srl $a0 $k0 2 # shift Cause reg
|
---|
| 70 | syscall
|
---|
| 71 | li $v0 4 # syscall 4 (print_str)
|
---|
| 72 | lw $a0 __excp($k0)
|
---|
| 73 | syscall
|
---|
| 74 | bne $k0 0x18 ok_pc # Bad PC requires special checks
|
---|
| 75 | mfc0 $a0, $14 # EPC
|
---|
| 76 | and $a0, $a0, 0x3 # Is EPC word-aligned?
|
---|
| 77 | beq $a0, 0, ok_pc
|
---|
| 78 | li $v0 10 # Exit on really bad PC (out of text)
|
---|
| 79 | syscall
|
---|
| 80 |
|
---|
| 81 | ok_pc:
|
---|
| 82 | li $v0 4 # syscall 4 (print_str)
|
---|
| 83 | la $a0 __m2_
|
---|
| 84 | syscall
|
---|
| 85 | mtc0 $0, $13 # Clear Cause register
|
---|
| 86 | ret: lw $v0 s1
|
---|
| 87 | lw $a0 s2
|
---|
| 88 | mfc0 $k0 $14 # EPC
|
---|
| 89 | .set noat
|
---|
| 90 | move $at $k1 # Restore $at
|
---|
| 91 | .set at
|
---|
| 92 | rfe # Return from exception handler
|
---|
| 93 | addiu $k0 $k0 4 # Return to next instruction
|
---|
| 94 | jr $k0
|
---|
| 95 |
|
---|
| 96 |
|
---|
| 97 | # Standard startup code. Invoke the routine main with no arguments.
|
---|
| 98 |
|
---|
| 99 | .text
|
---|
| 100 | .globl __start
|
---|
| 101 | __start:
|
---|
| 102 | lw $a0, 0($sp) # argc
|
---|
| 103 | addiu $a1, $sp, 4 # argv
|
---|
| 104 | addiu $a2, $a1, 4 # envp
|
---|
| 105 | sll $v0, $a0, 2
|
---|
| 106 | addu $a2, $a2, $v0
|
---|
| 107 | jal main
|
---|
| 108 | li $v0 10
|
---|
| 109 | syscall # syscall 10 (exit)
|
---|
| 110 |
|
---|
| 111 | .globl __eoth
|
---|
| 112 | __eoth:
|
---|