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

Subversion Repositories openrisc_me

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

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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