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

Subversion Repositories openrisc

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

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

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

powered by: WebSVN 2.1.0

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