Repository navigation
Expand file tree
/
Copy pathtrap.S
More file actions
117 lines (104 loc) · 3.26 KB
/
Copy pathtrap.S
File metadata and controls
117 lines (104 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*************************************************************************
* Project : shakti devt board
* Name of the file : trap.S
* Brief description : Trap handling is managed from here.
* Name of Author : Abhinav Ramnath & Sathya Narayanan N
* Email id : abhinavramnath13@gmail.com & sathya281@gmail.com
Copyright (C) 2019 IIT Madras. All rights reserved.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
****************************************************************************/
/**
@file trap.S
@details Context switching on trap is taken here. After saving the context, trap handler
is called. After servicing the trap, context is restored.
*/
#include "defines.h"
.global trap_entry
.align 2
trap_entry:
/*
If trap comes, do
1. push all x* register values to stack
2. handle trap
3. restore x* register values from stack
*/
addi sp, sp, -32*REGSIZE
.p2align 3
SREG x1, 1*REGSIZE(sp)
SREG x2, 2*REGSIZE(sp)
SREG x3, 3*REGSIZE(sp)
SREG x4, 4*REGSIZE(sp)
SREG x5, 5*REGSIZE(sp)
SREG x6, 6*REGSIZE(sp)
SREG x7, 7*REGSIZE(sp)
SREG x8, 8*REGSIZE(sp)
SREG x9, 9*REGSIZE(sp)
SREG x10, 10*REGSIZE(sp)
SREG x11, 11*REGSIZE(sp)
SREG x12, 12*REGSIZE(sp)
SREG x13, 13*REGSIZE(sp)
SREG x14, 14*REGSIZE(sp)
SREG x15, 15*REGSIZE(sp)
SREG x16, 16*REGSIZE(sp)
SREG x17, 17*REGSIZE(sp)
SREG x18, 18*REGSIZE(sp)
SREG x19, 19*REGSIZE(sp)
SREG x20, 20*REGSIZE(sp)
SREG x21, 21*REGSIZE(sp)
SREG x22, 22*REGSIZE(sp)
SREG x23, 23*REGSIZE(sp)
SREG x24, 24*REGSIZE(sp)
SREG x25, 25*REGSIZE(sp)
SREG x26, 26*REGSIZE(sp)
SREG x27, 27*REGSIZE(sp)
SREG x28, 28*REGSIZE(sp)
SREG x29, 29*REGSIZE(sp)
SREG x30, 30*REGSIZE(sp)
SREG x31, 31*REGSIZE(sp)
csrr a0, mcause
csrr a1, mepc
mv a2, sp
jal Trap_Handler
csrw mepc, a0
LREG x1, 1*REGSIZE(sp)
LREG x2, 2*REGSIZE(sp)
LREG x3, 3*REGSIZE(sp)
LREG x4, 4*REGSIZE(sp)
LREG x5, 5*REGSIZE(sp)
LREG x6, 6*REGSIZE(sp)
LREG x7, 7*REGSIZE(sp)
LREG x8, 8*REGSIZE(sp)
LREG x9, 9*REGSIZE(sp)
LREG x10, 10*REGSIZE(sp)
LREG x11, 11*REGSIZE(sp)
LREG x12, 12*REGSIZE(sp)
LREG x13, 13*REGSIZE(sp)
LREG x14, 14*REGSIZE(sp)
LREG x15, 15*REGSIZE(sp)
LREG x16, 16*REGSIZE(sp)
LREG x17, 17*REGSIZE(sp)
LREG x18, 18*REGSIZE(sp)
LREG x19, 19*REGSIZE(sp)
LREG x20, 20*REGSIZE(sp)
LREG x21, 21*REGSIZE(sp)
LREG x22, 22*REGSIZE(sp)
LREG x23, 23*REGSIZE(sp)
LREG x24, 24*REGSIZE(sp)
LREG x25, 25*REGSIZE(sp)
LREG x26, 26*REGSIZE(sp)
LREG x27, 27*REGSIZE(sp)
LREG x28, 28*REGSIZE(sp)
LREG x29, 29*REGSIZE(sp)
LREG x30, 30*REGSIZE(sp)
LREG x31, 31*REGSIZE(sp)
addi sp, sp, 32*REGSIZE
mret