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

Subversion Repositories mips32r1

[/] [mips32r1/] [trunk/] [Software/] [demos/] [XD3_I2C/] [src/] [os/] [exceptions.asm] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 ayersg
###############################################################################
2
# TITLE: Exception Vectors
3
# AUTHOR: Grant Ayers (ayers@cs.utah.edu)
4
# DATE: 23 May 2012
5
# FILENAME: exceptions.asm
6
# PROJECT: University of Utah XUM Single Core
7
# DESCRIPTION:
8
#   Provides the exception vectors which jump to
9
#   exception-handling routines.
10
#
11
###############################################################################
12
 
13
        .text
14
        .balign 4
15
        .set    noreorder
16
        .set    noat
17
 
18
exc_save:
19
        # Save all registers except k0 k1 sp ra
20
        addiu   $sp, $sp, -112
21
        sw      $1,    0($sp)
22
        sw      $2,    4($sp)
23
        sw      $3,    8($sp)
24
        sw      $4,   12($sp)
25
        sw      $5,   16($sp)
26
        sw      $6,   20($sp)
27
        sw      $7,   24($sp)
28
        sw      $8,   28($sp)
29
        sw      $9,   32($sp)
30
        sw      $10,  36($sp)
31
        sw      $11,  40($sp)
32
        sw      $12,  44($sp)
33
        sw      $13,  48($sp)
34
        sw      $14,  52($sp)
35
        sw      $15,  56($sp)
36
        sw      $16,  60($sp)
37
        sw      $17,  64($sp)
38
        sw      $18,  68($sp)
39
        sw      $19,  72($sp)
40
        sw      $20,  76($sp)
41
        sw      $21,  80($sp)
42
        sw      $22,  84($sp)
43
        sw      $23,  88($sp)
44
        sw      $24,  92($sp)
45
        sw      $25,  96($sp)
46
        sw      $28, 100($sp)
47
        jr      $ra
48
        sw      $30, 104($sp)
49
 
50
exc_restore:
51
        # Restore all registers except k0 k1 sp ra
52
        lw      $1,    0($sp)
53
        lw      $2,    4($sp)
54
        lw      $3,    8($sp)
55
        lw      $4,   12($sp)
56
        lw      $5,   16($sp)
57
        lw      $6,   20($sp)
58
        lw      $7,   24($sp)
59
        lw      $8,   28($sp)
60
        lw      $9,   32($sp)
61
        lw      $10,  36($sp)
62
        lw      $11,  40($sp)
63
        lw      $12,  44($sp)
64
        lw      $13,  48($sp)
65
        lw      $14,  52($sp)
66
        lw      $15,  56($sp)
67
        lw      $16,  60($sp)
68
        lw      $17,  64($sp)
69
        lw      $18,  68($sp)
70
        lw      $19,  72($sp)
71
        lw      $20,  76($sp)
72
        lw      $21,  80($sp)
73
        lw      $22,  84($sp)
74
        lw      $23,  88($sp)
75
        lw      $24,  92($sp)
76
        lw      $25,  96($sp)
77
        lw      $28, 100($sp)
78
        lw      $30, 104($sp)
79
        jr      $ra
80
        addiu   $sp, $sp, 112
81
 
82
 
83
        .global mips32_general_exception
84
        .ent    mips32_general_exception
85
mips32_general_exception:
86
        or      $26, $0, $ra
87
        jal     exc_save
88
        nop
89
        mfc0    $27, $13, 0             # Read Cause which has ExcCode bits
90
        srl     $27, $27, 2             # Extract exception code to $k1
91
        andi    $27, $27, 0x001f
92
 
93
        la      $ra, $end_exception     # Jump to the appropriate handler
94
        addiu   $t0, $0, 4
95
        addiu   $t1, $0, 5
96
        addiu   $t2, $0, 8
97
        addiu   $t3, $0, 9
98
        beq     $t0, $27, mips32_handler_AdEL
99
        addiu   $t0, $0, 10
100
        beq     $t1, $27, mips32_handler_AdES
101
        addiu   $t1, $0, 11
102
        beq     $t2, $27, mips32_handler_Sys
103
        addiu   $t2, $0, 12
104
        beq     $t3, $27, mips32_handler_Bp
105
        addiu   $t3, $0, 13
106
        beq     $t0, $27, mips32_handler_RI
107
        nop
108
        beq     $t1, $27, mips32_handler_CpU
109
        nop
110
        beq     $t2, $27, mips32_handler_Ov
111
        nop
112
        beq     $t3, $27, mips32_handler_Tr
113
        nop
114
 
115
$end_exception:
116
        jal     exc_restore
117
        xor     $27, $0, $0
118
        or      $ra, $0, $26
119
        xor     $26, $0, $0
120
        eret
121
        .end    mips32_general_exception
122
 
123
 
124
 
125
### "Special" Interrupt Vector: Cause_IV must be set.
126
 
127
        .ent    mips32_interrupt_exception
128
        .global mips32_interrupt_exception
129
mips32_interrupt_exception:
130
        mfc0    $26, $12, 0             # Status register for IM bits
131
        mfc0    $27, $13, 0             # Cause register for IP bits
132
        and     $26, $26, $27           # Extract pending, unmasked interrupts
133
        srl     $26, $26, 8
134
        andi    $26, $26, 0x00ff
135
 
136
        addu    $27, $0, $ra
137
        jal     exc_save
138
        clz     $26, $26
139
        la      $ra, $end_interrupt     # All C functions will return here
140
        addiu   $t0, $0, 24
141
        addiu   $t1, $0, 25
142
        addiu   $t2, $0, 26
143
        beq     $26, $t0, mips32_handler_HwInt5
144
        addiu   $t0, $0, 27
145
        beq     $26, $t1, mips32_handler_HwInt4
146
        addiu   $t1, $0, 28
147
        beq     $26, $t2, mips32_handler_HwInt3
148
        addiu   $t2, $0, 29
149
        beq     $26, $t0, mips32_handler_HwInt2
150
        addiu   $t0, $0, 30
151
        beq     $26, $t1, mips32_handler_HwInt1
152
        addiu   $t1, $0, 31
153
        beq     $26, $t2, mips32_handler_HwInt0
154
        nop
155
        beq     $26, $t0, mips32_handler_SwInt1
156
        nop
157
        beq     $26, $t1, mips32_handler_SwInt0
158
        nop
159
 
160
 
161
$end_interrupt:
162
        jal     exc_restore
163
        mfc0    $26, $9, 0              # Clear HwInt5 if applicable
164
        or      $ra, $0, $27
165
        eret
166
        .end    mips32_interrupt_exception
167
 
168
 

powered by: WebSVN 2.1.0

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