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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [sparclite/] [arch/] [current/] [src/] [vec_xvsr.S] - Blame information for rev 786

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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