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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [hal/] [sparc/] [arch/] [v2_0/] [src/] [vectors.S] - Blame information for rev 587

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
/*=============================================================================
2
//
3
//      vectors.S
4
//
5
//      SPARC vectors and bootup code
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 Red Hat, 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 version.
16
//
17
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
19
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
20
// for more details.
21
//
22
// You should have received a copy of the GNU General Public License along
23
// with eCos; if not, write to the Free Software Foundation, Inc.,
24
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25
//
26
// As a special exception, if other files instantiate templates or use macros
27
// or inline functions from this file, or you compile this file and link it
28
// with other works to produce a work based on this file, this file does not
29
// by itself cause the resulting work to be covered by the GNU General Public
30
// License. However the source code for this file must still be made available
31
// in accordance with section (3) of the GNU General Public License.
32
//
33
// This exception does not invalidate any other reasons why a work based on
34
// this file might be covered by the GNU General Public License.
35
//
36
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
37
// at http://sources.redhat.com/ecos/ecos-license/
38
// -------------------------------------------
39
//####ECOSGPLCOPYRIGHTEND####
40
//=============================================================================
41
//#####DESCRIPTIONBEGIN####
42
//
43
// Author(s):   hmt
44
// Contributors:hmt
45
// Date:        1998-12-15
46
// Purpose:     SPARC vector code
47
// Description: This file contains the code which hangs off SPARC vectors
48
//              including reset; it handles register under/overflow as well
49
//              as bootup, anything else is deferred to the default interrupt
50
//              or exception vsrs respectively.  See vec_[ix]vsr.S ...
51
//
52
//####DESCRIPTIONEND####
53
//
54
//===========================================================================*/
55
 
56
!-----------------------------------------------------------------------------
57
 
58
//      .file   "vectors.S"
59
 
60
!-----------------------------------------------------------------------------
61
 
62
#include 
63
#include 
64
 
65
#include 
66
#include CYGBLD_HAL_PLATFORM_H          // Platform config file
67
 
68
#ifdef CYGPKG_KERNEL
69
# include 
70
#else
71
# undef CYGIMP_HAL_COMMON_INTERRUPTS_USE_INTERRUPT_STACK
72
# undef CYGFUN_HAL_COMMON_KERNEL_SUPPORT
73
#endif
74
 
75
#if defined( CYGPKG_HAL_SPARCLITE_SIM ) || \
76
    defined( CYGIMP_HAL_COMMON_INTERRUPTS_USE_INTERRUPT_STACK ) || \
77
    defined( CYGPKG_HAL_SPARC_LEON ) || \
78
    defined( CYGPKG_HAL_SPARC_ERC32 )
79
#define BOOTUPSTACK_IS_INTERRUPTSTACK
80
#endif
81
 
82
//#define CYGHWR_HAL_SPARC_MULTIPLE_VECTOR_TRAPPING
83
 
84
#ifndef CYGHWR_HAL_SPARC_HAS_ASR17
85
#ifndef CYGHWR_HAL_SPARC_MULTIPLE_VECTOR_TRAPPING
86
#error Single Vector Trapping (SVT) demands ASR17
87
#endif
88
#endif
89
 
90
#ifdef CYG_HAL_STARTUP_ROM
91
# ifndef CYGHWR_HAL_SPARC_MULTIPLE_VECTOR_TRAPPING
92
 
93
! ROM startup and Single Vector Trapping demands a copy to RAM.
94
! Otherwise it may be configured in, but it is not required.
95
 
96
#  ifndef CYGIMP_HAL_SPARC_COPY_VECTORS_TO_RAM
97
#   define CYGIMP_HAL_SPARC_COPY_VECTORS_TO_RAM
98
#  endif
99
 
100
# endif
101
#endif
102
 
103
!------------------------------------------------------------------------
104
 
105
#include 
106
 
107
#define DELAYS_AFTER_WRPSR_SAME_WINDOW
108
#define DELAYS_AFTER_WRWIM
109
 
110
!------------------------------------------------------------------------
111
 
112
#ifdef CYGHWR_HAL_SPARC_MULTIPLE_VECTOR_TRAPPING
113
 
114
        .macro  VECTOR_EXCEPTION
115
        .p2align 4
116
        rd      %tbr, %l3
117
        rd      %psr, %l0
118
        ba      __entry_exception
119
         and    %l3, TT_MASK, %l4
120
        .endm
121
 
122
        .macro  VECTOR_INTERRUPT level
123
        .p2align 4
124
        rd      %psr, %l0
125
        mov     \level << 2, %l5
126
        ba      __entry_interrupt
127
         mov    \level << 4, %l4
128
        .endm
129
 
130
        .macro  VECTOR_CODE_WIM name
131
        .p2align 4
132
        ba      __entry_\name
133
         rd     %wim, %l0
134
        .endm
135
 
136
#endif // CYGHWR_HAL_SPARC_MULTIPLE_VECTOR_TRAPPING
137
 
138
!------------------------------------------------------------------------
139
! The start of the code; this is the entry point:
140
 
141
        .section ".vectors","ax"
142
 
143
        .global rom_vectors
144
rom_vectors:
145
        .global reset_vector
146
reset_vector:
147
        ! this code goes to the real reset handler, it will be
148
        ! overwritten by the start of vectoring handler...
149
        b       genuine_reset
150
        nop
151
        ! usually drop through to:
152
#ifdef CYGHWR_HAL_SPARC_MULTIPLE_VECTOR_TRAPPING
153
        ba      __entry_exception       ! reset becomes an exception
154
         and    %l3, TT_MASK, %l4       ! once we are running
155
 
156
        VECTOR_EXCEPTION                !   1
157
        VECTOR_EXCEPTION                !   2
158
        VECTOR_EXCEPTION                !   3
159
        VECTOR_EXCEPTION                !   4
160
 
161
        VECTOR_CODE_WIM wover           !   5 window overflow
162
        VECTOR_CODE_WIM wunder          !   6 window underflow
163
        VECTOR_EXCEPTION                !   7
164
        VECTOR_EXCEPTION                !   8
165
        VECTOR_EXCEPTION                !   9
166
 
167
        VECTOR_EXCEPTION                !  10
168
        VECTOR_EXCEPTION                !  11
169
        VECTOR_EXCEPTION                !  12
170
        VECTOR_EXCEPTION                !  13
171
        VECTOR_EXCEPTION                !  14
172
 
173
        VECTOR_EXCEPTION                !  15
174
        VECTOR_EXCEPTION                !  16
175
        VECTOR_INTERRUPT  1             !  17 interrupt_level_1
176
        VECTOR_INTERRUPT  2             !  18 interrupt_level_2
177
        VECTOR_INTERRUPT  3             !  19 interrupt_level_3
178
 
179
        VECTOR_INTERRUPT  4             !  20 interrupt_level_4
180
        VECTOR_INTERRUPT  5             !  21 interrupt_level_5
181
        VECTOR_INTERRUPT  6             !  22 interrupt_level_6
182
        VECTOR_INTERRUPT  7             !  23 interrupt_level_7
183
        VECTOR_INTERRUPT  8             !  24 interrupt_level_8
184
 
185
        VECTOR_INTERRUPT  9             !  25 interrupt_level_9
186
        VECTOR_INTERRUPT 10             !  26 interrupt_level_10
187
        VECTOR_INTERRUPT 11             !  27 interrupt_level_11
188
        VECTOR_INTERRUPT 12             !  28 interrupt_level_12
189
        VECTOR_INTERRUPT 13             !  29 interrupt_level_13
190
 
191
        VECTOR_INTERRUPT 14             !  30 interrupt_level_14
192
        VECTOR_INTERRUPT 15             !  31 interrupt_level_15
193
        VECTOR_EXCEPTION                !  32
194
        VECTOR_EXCEPTION                !  33
195
        VECTOR_EXCEPTION                !  34
196
 
197
        VECTOR_EXCEPTION                !  35
198
        VECTOR_EXCEPTION                !  36
199
        VECTOR_EXCEPTION                !  37
200
        VECTOR_EXCEPTION                !  38
201
        VECTOR_EXCEPTION                !  39
202
 
203
        .rept 216                       ! 40-255 is 216 of them
204
        VECTOR_EXCEPTION                ! whichever
205
        .endr
206
#endif // CYGHWR_HAL_SPARC_MULTIPLE_VECTOR_TRAPPING
207
 
208
#ifndef CYGHWR_HAL_SPARC_MULTIPLE_VECTOR_TRAPPING
209
real_vector:
210
        ! here,locals have been set up as follows:
211
        ! %l0 = psr
212
        ! %l1 = pc
213
        ! %l2 = npc
214
        ! %l3 = tbr
215
        and     %l3, TT_IS_INTR_MASK, %l4
216
        cmp     %l4, TT_IS_INTR_VALUE
217
        bne     not_an_interrupt        ! delay slot does not matter
218
        ! here be the pre-vector interrupt handler
219
interrupt:
220
        and     %l3, 0x0f0, %l4         ! get an interrupt number out
221
        srl     %l4, 2, %l5             ! to a word address offset
222
#endif // !CYGHWR_HAL_SPARC_MULTIPLE_VECTOR_TRAPPING
223
__entry_interrupt:
224
        sethi   %hi(hal_vsr_table), %l6
225
        or      %l6, %lo(hal_vsr_table), %l6
226
        ld      [ %l6 + %l5 ], %l6      ! get vector in %l6
227
        jmp     %l6                     ! and go there
228
        srl     %l4, 4, %l3             ! vector number into %l3: so that
229
                                        ! interrupts and exceptions/traps
230
                                        ! have the same API to VSRs
231
 
232
#ifndef CYGHWR_HAL_SPARC_MULTIPLE_VECTOR_TRAPPING
233
not_an_interrupt:
234
        and     %l3, TT_MASK, %l4
235
        cmp     %l4, (TRAP_WUNDER << TT_SHL)
236
 
237
        bne,a   not_window_underflow
238
        cmp     %l4, (TRAP_WOVER << TT_SHL)     ! (if taken)
239
 
240
        ! here be the window underflow handler:
241
window_underflow:
242
        ! CWP is trap handler
243
        ! CWP + 1 is trapped RESTORE instruction
244
        ! CWP + 2 is invalid context which must be restored
245
        ! CWP + 3 is next invalid context
246
 
247
        wr      %l0, %psr               ! restore the condition flags
248
                                        ! (CWP is unchanged)
249
        ! the following instructions delay enough; no need for NOPs
250
        rd      %wim, %l0               ! get the wim
251
#endif // !CYGHWR_HAL_SPARC_MULTIPLE_VECTOR_TRAPPING
252
__entry_wunder:
253
        sll     %l0, 1, %l3             ! Rotate wim left
254
        srl     %l0, __WINSIZE-1, %l0
255
        wr      %l0, %l3, %wim          ! Install the new wim
256
 
257
#ifdef DELAYS_AFTER_WRWIM
258
        nop                             ! are these delays needed?
259
        nop                             ! (following restore uses wim)
260
        nop
261
#endif
262
        restore                         ! Users window
263
        restore                         ! Her callers window (now valid)
264
 
265
        ldd     [%sp + 0 * 4], %l0      ! restore L & I registers
266
        ldd     [%sp + 2 * 4], %l2
267
        ldd     [%sp + 4 * 4], %l4
268
        ldd     [%sp + 6 * 4], %l6
269
 
270
        ldd     [%sp + 8 * 4], %i0
271
        ldd     [%sp + 10 * 4], %i2
272
        ldd     [%sp + 12 * 4], %i4
273
        ldd     [%sp + 14 * 4], %i6
274
 
275
        save                            ! Back to trap window
276
        save
277
 
278
        jmp     %l1
279
        rett    %l2
280
 
281
#ifndef CYGHWR_HAL_SPARC_MULTIPLE_VECTOR_TRAPPING
282
not_window_underflow:
283
        bne,a   not_window_overflow
284
        srl     %l4, 4, %l4             ! (if taken)
285
 
286
        ! here be the window overflow handler:
287
window_overflow:
288
        ! CWP + 1 is caller whose SAVE bounced
289
        ! CWP is trap handler = invalid window
290
        ! CWP - 1 is next invalid window which needs to be saved
291
 
292
        wr      %l0, %psr               ! restore the condition flags
293
                                        ! (CWP is unchanged)
294
        ! the following instructions delay enough; no need for NOPs
295
        rd      %wim, %l0
296
#endif // !CYGHWR_HAL_SPARC_MULTIPLE_VECTOR_TRAPPING
297
__entry_wover:
298
        mov     %g1, %l3                ! Save g1, we use it to hold the wim
299
        srl     %l0, 1, %g1             ! Rotate wim right
300
        sll     %l0, __WINSIZE-1, %l0
301
        or      %l0, %g1, %g1
302
 
303
        save                            ! Slip into next window
304
        mov     %g1, %wim               ! Install the new wim
305
                                        ! (invalidates current window!)
306
 
307
        std     %l0, [%sp + 0 * 4]      ! save L & I registers
308
        std     %l2, [%sp + 2 * 4]
309
        std     %l4, [%sp + 4 * 4]
310
        std     %l6, [%sp + 6 * 4]
311
 
312
        std     %i0, [%sp + 8 * 4]
313
        std     %i2, [%sp + 10 * 4]
314
        std     %i4, [%sp + 12 * 4]
315
        std     %i6, [%sp + 14 * 4]
316
 
317
        restore                         ! Go back to trap window.
318
        mov     %l3, %g1                ! Restore %g1
319
 
320
        jmpl    %l1,  %g0
321
        rett    %l2
322
 
323
#ifdef CYGHWR_HAL_SPARC_MULTIPLE_VECTOR_TRAPPING
324
        // ADDITIONAL code to provide an entry point:
325
__entry_exception:
326
        srl     %l4, 4, %l4
327
#endif // CYGHWR_HAL_SPARC_MULTIPLE_VECTOR_TRAPPING
328
not_window_overflow:
329
        ! from here on in, %l4 is the trap number in clear
330
        cmp     %l4, 128
331
        bge     1f
332
        mov     0, %l5                  ! offset 0 for user traps
333
 
334
        cmp     %l4, 36                 ! coprocessor special case
335
        beq     1f
336
        mov     4, %l5                  ! ...treated as FP, code 4
337
 
338
        cmp     %l4, 10
339
        bge     1f
340
        mov     10, %l5                 ! offset 10 for "others"
341
 
342
        ! if we are here, the trap number is 1-9 inclusive
343
        ! so put it in %l5 and drop through...
344
        mov     %l4, %l5
345
1:
346
        or      %l5, 16, %l5            ! offset into table is 16... for traps.
347
        sll     %l5,  2, %l5            ! to a word address offset
348
        sethi   %hi(hal_vsr_table), %l6
349
        or      %l6, %lo(hal_vsr_table), %l6
350
        ld      [ %l6 + %l5 ], %l6      ! get vector in %l6
351
        jmp     %l6                     ! and go there
352
        srl     %l5, 2, %l3             ! vector number into %l3: so that
353
                                        ! interrupts and exceptions/traps
354
                                        ! have the same API to VSRs
355
        ! NB that~s eCos vector number not TRAP number above.
356
 
357
        ! and that is the end of the pre-vector trap handler
358
 
359
        .global rom_vectors_end
360
rom_vectors_end:
361
 
362
        ! these instructions are copied into the reset vector
363
        ! after startup to _not_ branch to the genuine_reset code below
364
real_vector_instructions:
365
        rd      %tbr, %l3
366
        rd      %psr, %l0
367
 
368
 
369
 
370
        ! genuine reset code called from time zero:
371
genuine_reset:                          ! set psr, mask interrupts & traps
372
        sethi   %hi(reset_vector), %g1
373
        andn    %g1, 0xfff, %g1         ! should not be needed
374
        wr      %g1, %tbr               ! Traps are at reset_vector
375
        wr      %g0, 0xfc0 + __WIN_INIT, %psr ! mode = prevMode = S, CWP=7
376
        wr      %g0, 0, %wim            ! No invalid windows (yet)
377
#ifdef CYGHWR_HAL_SPARC_HAS_ASR17
378
#ifdef CYGHWR_HAL_SPARC_MULTIPLE_VECTOR_TRAPPING
379
        wr      %g0, 0, %asr17          ! Multiple vector trapping
380
#else
381
        wr      %g0, 1, %asr17          ! Single vector trapping
382
#endif // !CYGHWR_HAL_SPARC_MULTIPLE_VECTOR_TRAPPING
383
#endif // CYGHWR_HAL_SPARC_HAS_ASR17
384
        nop
385
        nop
386
        nop
387
 
388
// INCLUDE PLATFORM BOOT
389
 
390
// This should set up RAM and caches, and calm down any external interrupt
391
// sources.  Also copy two instructions from real_vector_instructions
392
// into reset_vector, then invalidate the instruction cache.
393
 
394
#include 
395
 
396
// halboot.si returns with %sp all set, in sleb versions.
397
// (though we override if there is an interrupt stack)
398
 
399
        led     0x80
400
 
401
        ! now set up a stack and initial frame linkage
402
        ! so as to be able to make C function calls:
403
        ! current window is 7, the highest, so we store a
404
        ! saved frame thingy that refers to itself in the stack,
405
        ! then another which is valid and drop into main from there.
406
 
407
#ifdef BOOTUPSTACK_IS_INTERRUPTSTACK
408
        sethi   %hi(cyg_interrupt_stack), %i6
409
        or      %i6, %lo(cyg_interrupt_stack), %i6
410
#endif
411
        andn    %i6, 7, %i6             ! round fp down to double alignment
412
        mov     0, %i7                  ! null return address
413
        sethi   %hi(0xb51ac000), %i0    ! "BStac" pattern
414
        or      %i0, 24, %i0
415
        or      %i0, 1, %i1
416
        or      %i0, 2, %i2
417
        or      %i0, 3, %i3
418
        or      %i0, 4, %i4
419
        or      %i0, 5, %i5
420
 
421
        sethi   %hi(0xb51ac000), %l0    ! "BStac" pattern
422
        or      %l0, 16, %l0
423
        or      %l0, 1, %l1
424
        or      %l0, 2, %l2
425
        or      %l0, 3, %l3
426
        or      %l0, 4, %l4
427
        or      %l0, 5, %l5
428
        or      %l0, 6, %l6
429
        or      %l0, 7, %l7
430
 
431
        sub     %fp, 16 * 4, %sp        ! Stack pointer
432
 
433
        led     0x90
434
 
435
        std     %l0, [%sp + 0 * 4]      ! save L & I registers
436
        std     %l2, [%sp + 2 * 4]      ! into new stack frame
437
        std     %l4, [%sp + 4 * 4]
438
        std     %l6, [%sp + 6 * 4]
439
 
440
        led     0x91
441
 
442
        std     %i0, [%sp + 8 * 4]
443
        std     %i2, [%sp + 10 * 4]
444
        std     %i4, [%sp + 12 * 4]
445
        std     %i6, [%sp + 14 * 4]
446
 
447
        led     0x92
448
 
449
        sethi   %hi(0xb0010000), %o0    ! "Boot" pattern
450
        or      %o0, 8, %o0
451
        or      %o0, 1, %o1
452
        or      %o0, 2, %o2
453
        or      %o0, 3, %o3
454
        or      %o0, 4, %o4
455
        or      %o0, 5, %o5
456
 
457
        led     0x98
458
 
459
        wr      %g0, __WIM_INIT, %wim   ! Window 7 (current) is invalid
460
        nop
461
        nop
462
        nop
463
 
464
        led     0x99
465
 
466
        sethi   %hi(0xb0010000), %g1    ! "Boot" pattern
467
        or      %g1, 2, %g2
468
        or      %g1, 3, %g3
469
        or      %g1, 4, %g4
470
        or      %g1, 5, %g5
471
        or      %g1, 6, %g6
472
        or      %g1, 7, %g7
473
        or      %g1, 1, %g1
474
 
475
        led     0xa0
476
 
477
        wr      %g0, 0xfe0 + __WIN_INIT, %psr
478
        nop                             ! Enable traps:
479
        nop                             ! set psr, _do_ mask interrupts
480
        nop                             ! mode = prevMode = S, CWP=7
481
 
482
        led     0xb0
483
 
484
        ! now we can start calling out and running C code!
485
        .extern cyg_hal_start
486
        call    cyg_hal_start           ! puts return address in %o7
487
        or      %g1, 1, %g1
488
 
489
loop_forever:
490
        ta      1
491
        b       loop_forever            ! if it returns
492
        nop
493
 
494
 
495
!---------------------------------------------------------------------------
496
! hal_vsr_table...
497
 
498
        .section ".data"
499
        .balign 4
500
        .global hal_vsr_table
501
hal_vsr_table:
502
        .rept 16
503
        .word hal_default_interrupt_vsr
504
        .endr
505
        .rept 11
506
        .word hal_default_exception_vsr
507
        .endr
508
 
509
!---------------------------------------------------------------------------
510
! Bootup stack (only needed explicitly in sim)
511
 
512
#ifdef BOOTUPSTACK_IS_INTERRUPTSTACK
513
        .section ".bss"
514
 
515
#ifndef CYGNUM_HAL_COMMON_INTERRUPTS_STACK_SIZE
516
#define CYGNUM_HAL_COMMON_INTERRUPTS_STACK_SIZE 4096
517
#endif
518
        .balign 16
519
        .global cyg_interrupt_stack_base
520
cyg_interrupt_stack_base:
521
        .rept CYGNUM_HAL_COMMON_INTERRUPTS_STACK_SIZE
522
        .byte 0
523
        .endr
524
        .balign 16
525
        .global cyg_interrupt_stack
526
cyg_interrupt_stack:
527
        .long   0,0,0,0,0,0,0,0         ! here be secret state stored
528
#endif
529
 
530
!------------------------------------------------------------------------
531
! Define a section that reserves space at the start of RAM for the
532
! vectors to be copied into, for ROM start only.
533
 
534
        .section ".ram_vectors","awx",@nobits
535
#ifdef CYGIMP_HAL_SPARC_COPY_VECTORS_TO_RAM
536
        ! need a space at base of RAM for copied vector/trampoline code
537
        .align 0x1000
538
        .space 8                        ! for fencepost errors
539
        .space (rom_vectors_end - rom_vectors)
540
#endif // CYGIMP_HAL_SPARC_COPY_VECTORS_TO_RAM
541
 
542
!------------------------------------------------------------------------
543
! end of vectors.S

powered by: WebSVN 2.1.0

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