source: liacs/coco/assignment5/trap.handler@ 96

Last change on this file since 96 was 2, checked in by Rick van der Zwet, 15 years ago

Initial import of data of old repository ('data') worth keeping (e.g. tracking
means of URL access statistics)

File size: 3.1 KB
Line 
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/assignment5/trap.handler,v 1.1 2008/11/13 13:44:15 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_
50s1: .word 0
51s2: .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
81ok_pc:
82 li $v0 4 # syscall 4 (print_str)
83 la $a0 __m2_
84 syscall
85 mtc0 $0, $13 # Clear Cause register
86ret: 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:
Note: See TracBrowser for help on using the repository browser.