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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
|
/*===========================================================================
//
// vec_xvsr.S
//
// SPARC vectors: exception vector service routine
//
//===========================================================================
// ####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
//
// eCos 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 2 or (at your option) any later
// version.
//
// eCos 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 eCos; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
// As a special exception, if other files instantiate templates or use
// macros or inline functions from this file, or you compile this file
// and link it with other works to produce a work based on this file,
// this file does not by itself cause the resulting work to be covered by
// the GNU General Public License. However the source code for this file
// must still be made available in accordance with section (3) of the GNU
// General Public License v2.
//
// This exception does not invalidate any other reasons why a work based
// on this file might be covered by the GNU General Public License.
// -------------------------------------------
// ####ECOSGPLCOPYRIGHTEND####
//===========================================================================
//#####DESCRIPTIONBEGIN####
//
// Author(s): hmt
// Contributors: hmt
// Date: 1999-02-20
// Purpose: SPARC vector code
// Description: see vectors.S; this is the default vector service routine
// for exceptions.
//
//####DESCRIPTIONEND####
//
//=========================================================================*/
!-----------------------------------------------------------------------------
// .file "vec_xvsr.S"
!----------------------------------------------------------------------------
#include <pkgconf/system.h>
#include <pkgconf/hal.h>
#ifdef CYGPKG_KERNEL
# include <pkgconf/kernel.h>
#endif
!------------------------------------------------------------------------
#include <cyg/hal/vectors.h>
#define DELAYS_AFTER_WRPSR_SAME_WINDOW
#define DELAYS_AFTER_WRWIM
!------------------------------------------------------------------------
.text
!---------------------------------------------------------------------------
! default exception handler VSR, which calls the appropriate ISR after
! interrupt masking - much the same as the interrupt VSR but does not lock
! scheduler or call interrupt_end().
.global hal_default_exception_vsr
hal_default_exception_vsr:
! here,locals have been set up as follows:
! %l0 = psr (with this CWP/window-level in it)
! %l1 = pc
! %l2 = npc
! %l3 = vector number (16-25 for traps)
! and we are in our own register window, though it is likely that
! the next one will need to be saved before we can use it:
! ie. this one is the invalid register window.
! must establish a safe stack before re-enabling interrupts + traps
and %l0, __WINBITS, %l7 ! CWP extracted
! no inc/dec here, so no need for special measures for not-8-windows
mov 1, %l6
sll %l6, %l7, %l6 ! 1 << CWP
rd %wim, %l5
cmp %l5, %l6 ! are they the same?
bne 1f ! No, so the stack is OK as is.
! now do by hand an overflow trap, effectively
mov %g1, %l7 ! (DELAY SLOT)
srl %l5, 1, %l5
sll %l6, __WINSIZE-1, %l6
or %l6, %l5, %g1 ! new WIM in %g1 so we can get it
! within the save:
save ! Slip into next window
mov %g1, %wim ! Install the new wim
! (invalidates current window!)
#ifdef DELAYS_AFTER_WRWIM
nop
nop
nop
#endif
std %l0, [%sp + 0 * 4] ! save L & I registers
std %l2, [%sp + 2 * 4]
std %l4, [%sp + 4 * 4]
std %l6, [%sp + 6 * 4]
std %i0, [%sp + 8 * 4]
std %i2, [%sp + 10 * 4]
std %i4, [%sp + 12 * 4]
std %i6, [%sp + 14 * 4]
restore ! Go back to trap window.
mov %l7, %g1 ! Restore %g1
1: ! now save away the regs we must preserve
sub %fp, 32 * 4, %sp
! save a maximal context regardless: see also
! CYGDBG_HAL_COMMON_INTERRUPTS_SAVE_MINIMUM_CONTEXT
std %l0, [%sp + 0 * 4] ! save L & I registers
std %l2, [%sp + 2 * 4]
std %l4, [%sp + 4 * 4]
std %l6, [%sp + 6 * 4]
std %i0, [%sp + 8 * 4]
std %i2, [%sp + 10 * 4]
std %i4, [%sp + 12 * 4]
std %i6, [%sp + 14 * 4]
st %g1, [%sp + 17 * 4] ! save G registers
std %g2, [%sp + 18 * 4]
std %g4, [%sp + 20 * 4]
std %g6, [%sp + 22 * 4]
! no point whatsoever in saving O registers
! and save the CWP in %g0 save place
st %l0, [%sp + 16 * 4]
sub %sp, 24 * 4, %sp ! fresh frame including
! arg spill area for callees
! do not lock the scheduler
! HELP_GDB_WITH_BACKTRACE
mov %i7, %l5 ! preserve it JIC
mov %l1, %i7 ! bogus return link here
! and we must preserve the Y register (multiply/divide auxiliary)
! over these calls; we will keep it in %l4 which is otherwise unused.
rd %y, %l4
! Now we can reenable traps (preserving interrupt level)
or %l0, 0x0e0, %l7 ! set ET (+S,PS), preserve PIL
wr %l7, %psr ! and enable!
#ifdef DELAYS_AFTER_WRPSR_SAME_WINDOW
nop
nop
nop
#endif
! now call the XSR and so on with the appropriate args:
! ie.
! isr_retcode = (*(hal_interrupt_handlers[ vector ]))
! ( vector, hal_interrupt_data[ vector ], stackp );
! from hal_arch.h
!// ISR tables
!CYG_ADDRESS hal_interrupt_handlers[CYGNUM_HAL_ISR_COUNT];
!CYG_ADDRWORD hal_interrupt_data[CYGNUM_HAL_ISR_COUNT];
!CYG_ADDRESS hal_interrupt_objects[CYGNUM_HAL_ISR_COUNT];
mov %l3, %o0
sll %l3, 2, %l3 ! %l3 to a word offset
sethi %hi(hal_interrupt_data), %l7
or %l7, %lo(hal_interrupt_data), %l7
ld [ %l7 + %l3 ], %o1 ! data
add %sp, 24 * 4, %o2 ! stackpointer of saved regset
sethi %hi(hal_interrupt_handlers), %l7
or %l7, %lo(hal_interrupt_handlers), %l7
ld [ %l7 + %l3 ], %l6
call %l6
nop
! do not call _interrupt_end()
! restore the Y register having done our callouts to C
wr %l4, %y
! We can reinstall the original CWP here; even if interrupt_end()
! performed a reschedule (ie. yield/resume pair) we will be in the
! same window. The window is preserved by reschedule precisely
! because it is impossible atomically to disable traps here without
! involving a CWP living in a register for a time when other
! interrupts may occur.
! disable traps (using the saved psr is fastest way)
wr %l0, %psr ! restores flags, disables traps, same PIL.
#ifdef DELAYS_AFTER_WRPSR_SAME_WINDOW
nop
nop
nop
#endif
! HELP_GDB_WITH_BACKTRACE
mov %l5, %i7 ! restore (unused) return link
! and restore other saved regs
add %sp, 24 * 4, %sp ! undo fresh frame
! restore a maximal context regardless: see also
! CYGDBG_HAL_COMMON_INTERRUPTS_SAVE_MINIMUM_CONTEXT
ldd [%sp + 0 * 4], %l0 ! restore L & I registers
ldd [%sp + 2 * 4], %l2 ! to support the handler
ldd [%sp + 4 * 4], %l4 ! having messed with them.
ldd [%sp + 6 * 4], %l6
ldd [%sp + 8 * 4], %i0
ldd [%sp + 10 * 4], %i2
ldd [%sp + 12 * 4], %i4
ldd [%sp + 14 * 4], %i6
ld [%sp + 17 * 4], %g1 ! and G registers
ldd [%sp + 18 * 4], %g2
ldd [%sp + 20 * 4], %g4
ldd [%sp + 22 * 4], %g6
! no point whatsoever in loading back O registers.
! Now test for window underflow here and fix up if needs be.
!
! Why? interrupt_end() might have yielded us, when only
! its own frame was restored; its own return to us caused a
! window underflow trap, as would our return to interruptee
! unless we deal with it now.
add %l0, 1, %l7 ! interruptee~s CWP plus noise
and %l7, __WINBITS, %l7 ! CWP only
#if 8 == __WINSIZE
! it is in range already
#else // expect 5 or 6 or 7 windows
cmp %l7, __WINSIZE
bge,a 567f ! taken: do delay slot, handle overflow
mov 0, %l7 ! only if .ge. above
567:
#endif
mov 1, %l6
sll %l6, %l7, %l6 ! 1 << CWP
rd %wim, %l5
cmp %l5, %l6 ! are they the same?
bne 2f ! No, so the stack is OK as is.
! now do by hand an underflow trap, effectively
sll %l5, 1, %l5 ! Rotate wim left
srl %l6, __WINSIZE-1, %l6
wr %l5, %l6, %wim
#ifdef DELAYS_AFTER_WRWIM
nop ! are these delays needed?
nop ! (following restore uses wim)
nop
#endif
restore ! Interruptee~s window
ldd [%sp + 0 * 4], %l0 ! restore L & I registers
ldd [%sp + 2 * 4], %l2
ldd [%sp + 4 * 4], %l4
ldd [%sp + 6 * 4], %l6
ldd [%sp + 8 * 4], %i0
ldd [%sp + 10 * 4], %i2
ldd [%sp + 12 * 4], %i4
ldd [%sp + 14 * 4], %i6
save ! Back to trap window
2: ! restore the condition codes, PSR and PIL and return from trap.
wr %l0, %psr ! restores flags, disables traps, and old PIL
#ifdef DELAYS_AFTER_WRPSR_SAME_WINDOW
nop
nop
nop
#endif
jmpl %l1, %g0
rett %l2
! end of vec_xvsr.S
|