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

Subversion Repositories openrisc

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

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
##      OpenRISC exception vectors, interrupt-handling, reset and
6
##        platform-indepent initialization
7
##
8
##==========================================================================
9
## ####ECOSGPLCOPYRIGHTBEGIN####
10
## -------------------------------------------
11
## This file is part of eCos, the Embedded Configurable Operating System.
12
## Copyright (C) 2002 Free Software Foundation, Inc.
13
##
14
## eCos is free software; you can redistribute it and/or modify it under
15
## the terms of the GNU General Public License as published by the Free
16
## Software Foundation; either version 2 or (at your option) any later
17
## version.
18
##
19
## eCos is distributed in the hope that it will be useful, but WITHOUT
20
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21
## FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
22
## for more details.
23
##
24
## You should have received a copy of the GNU General Public License
25
## along with eCos; if not, write to the Free Software Foundation, Inc.,
26
## 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
27
##
28
## As a special exception, if other files instantiate templates or use
29
## macros or inline functions from this file, or you compile this file
30
## and link it with other works to produce a work based on this file,
31
## this file does not by itself cause the resulting work to be covered by
32
## the GNU General Public License. However the source code for this file
33
## must still be made available in accordance with section (3) of the GNU
34
## General Public License v2.
35
##
36
## This exception does not invalidate any other reasons why a work based
37
## on this file might be covered by the GNU General Public License.
38
## -------------------------------------------
39
## ####ECOSGPLCOPYRIGHTEND####
40
##==========================================================================
41
#######DESCRIPTIONBEGIN####
42
##
43
## Author(s):    sfurman
44
## Contributors: Piotr Skrzypek (pskrzypek@antmicro.com)
45
## Date:         2003-01-20
46
## Purpose:      OpenRISC interrupts, exception vectors and reset
47
## Description:  This file defines the code placed into the exception
48
##               vectors. It also contains the first level default VSRs
49
##               that save and restore state for both exceptions and
50
##               interrupts.
51
##
52
######DESCRIPTIONEND####
53
##
54
##==========================================================================
55
 
56
#include 
57
 
58
#ifdef CYGPKG_KERNEL
59
#include      // CYGPKG_KERNEL_INSTRUMENT
60
#endif
61
 
62
#include 
63
#include 
64
 
65
#===========================================================================
66
 
67
 
68
        .extern hal_vsr_table
69
 
70
        .extern cyg_hal_invoke_constructors
71
        .extern _cyg_instrument
72
        .extern cyg_start
73
        .extern _hal_IRQ_init
74
        .extern hal_platform_init
75 791 skrzyp
        .extern initialize_stub
76 786 skrzyp
 
77
        .extern __bss_start
78
        .extern __bss_end
79
        .extern __sbss_start
80
        .extern __sbss_end
81
 
82
# Include variant macros after MSR definition.
83
#include 
84
#include 
85
 
86
 
87
#===========================================================================
88
# Start by defining the exceptions vectors that must be placed in low
89
# memory, starting at location 0x100.
90
 
91
        .section ".vectors","ax"
92
 
93
#---------------------------------------------------------------------------
94
# Macros for generating an exception vector service routine
95
 
96
# Reset vector macro
97
 
98
        .macro  reset_vector name org
99
        .p2align 8
100
        .globl  __exception_\name
101
__exception_\name:
102 838 skrzyp
        l.movhi r0, 0
103 786 skrzyp
        load32i r3,start
104
        l.jr    r3
105 838 skrzyp
#ifdef CYGHWR_BRANCH_SLOT_IMPLEMENTED
106 786 skrzyp
        l.nop           # delay slot
107 838 skrzyp
#endif
108 786 skrzyp
        .endm
109
 
110
# Generic vector macro
111
 
112
        .macro  exception_vector name org
113
        .p2align 8
114
        .globl  __exception_\name
115
__exception_\name:
116
        l.addi  sp,sp,-SIZEOF_OR1KREGS-132  # space for registers
117
 
118
        # Store General Purpose Registers (GPRs).
119
 
120
        l.sw     3 * OR1K_GPRSIZE(sp), r3
121
        l.sw     4 * OR1K_GPRSIZE(sp), r4
122
        l.sw     5 * OR1K_GPRSIZE(sp), r5
123
        l.sw     6 * OR1K_GPRSIZE(sp), r6
124
        l.sw     7 * OR1K_GPRSIZE(sp), r7
125
        l.sw     8 * OR1K_GPRSIZE(sp), r8
126
        l.sw     9 * OR1K_GPRSIZE(sp), r9
127
        l.sw    11 * OR1K_GPRSIZE(sp), r11
128 790 skrzyp
        l.sw    12 * OR1K_GPRSIZE(sp), r12
129 786 skrzyp
        l.sw    13 * OR1K_GPRSIZE(sp), r13
130
        l.sw    15 * OR1K_GPRSIZE(sp), r15
131
        l.sw    17 * OR1K_GPRSIZE(sp), r17
132
        l.sw    19 * OR1K_GPRSIZE(sp), r19
133
        l.sw    21 * OR1K_GPRSIZE(sp), r21
134
        l.sw    23 * OR1K_GPRSIZE(sp), r23
135
        l.sw    25 * OR1K_GPRSIZE(sp), r25
136
        l.sw    27 * OR1K_GPRSIZE(sp), r27
137
        l.sw    29 * OR1K_GPRSIZE(sp), r29
138
        l.sw    31 * OR1K_GPRSIZE(sp), r31
139
 
140
#ifndef CYGDBG_HAL_COMMON_INTERRUPTS_SAVE_MINIMUM_CONTEXT
141
 
142
        # R0 is not typically stored because it is always zero-valued,
143
        # but we store it here for consistency when examining registers
144
        # in the debugger.
145
        l.sw     0 * OR1K_GPRSIZE(sp), r0
146
 
147
        # Callee-saved regs don't need to be preserved across a call into
148
        # an ISR, but we can do so to make debugging easier.
149
        l.sw     2 * OR1K_GPRSIZE(sp), r2
150
        l.sw    10 * OR1K_GPRSIZE(sp), r10
151
        l.sw    14 * OR1K_GPRSIZE(sp), r14
152
        l.sw    16 * OR1K_GPRSIZE(sp), r16
153
        l.sw    18 * OR1K_GPRSIZE(sp), r18
154
        l.sw    20 * OR1K_GPRSIZE(sp), r20
155
        l.sw    22 * OR1K_GPRSIZE(sp), r22
156
        l.sw    24 * OR1K_GPRSIZE(sp), r24
157
        l.sw    26 * OR1K_GPRSIZE(sp), r26
158
        l.sw    28 * OR1K_GPRSIZE(sp), r28
159
        l.sw    30 * OR1K_GPRSIZE(sp), r30
160
 
161 790 skrzyp
#endif
162 786 skrzyp
        # save MAC LO and HI regs
163
        l.mfspr r5,r0,SPR_MACLO
164
        l.sw    OR1KREG_MACLO(sp),r5
165
        l.mfspr r5,r0,SPR_MACHI
166
        l.sw    OR1KREG_MACHI(sp),r5
167
 
168
        # Save SP of interruptee in reg dump
169
        l.addi  r5,sp,SIZEOF_OR1KREGS+132
170
        l.sw     1 * OR1K_GPRSIZE(sp),r5
171
 
172
        # ...and the PC
173
        l.mfspr r5,r0,SPR_EPCR_BASE
174
        l.sw    OR1KREG_PC(sp),r5
175
 
176
        # ... and the Supervisor Register
177
        l.mfspr r5,r0,SPR_ESR_BASE
178
        l.sw    OR1KREG_SR(sp),r5
179
 
180
        # ... and the exception's effective address, if there is one.
181
        # FIXME - don't need to do this for some exceptions
182
        l.mfspr r5,r0,SPR_EEAR_BASE
183
        l.sw    OR1KREG_EEAR(sp),r5
184
 
185
        # Second arg to VSR is exception number
186
        # First vector is located at 0x100, second at 0x200, etc.
187
        # Shift right to get vector number for address lookup.
188
        l.ori   r4,r0,(\org>>8)
189
        l.sw    OR1KREG_VECTOR(sp),r4
190
 
191
        # Lookup address of VSR in table and jump to it
192
        #   Arg 0: Pointer to HAL_SavedRegisters struct
193
        #   Arg 1: Vector #
194
        load32i r5,hal_vsr_table+(\org>>6)
195
        l.lwz   r5,0(r5)
196 838 skrzyp
#ifdef CYGHWR_BRANCH_SLOT_IMPLEMENTED
197 786 skrzyp
        l.jr    r5                           # To the VSR, Batman
198 838 skrzyp
        l.or    r3,r0,sp                     # First arg to VSR is SP
199
#else
200
        l.or    r3,r0,sp                     # First arg to VSR is SP
201
        l.jr    r5                           # To the VSR, Batman
202
#endif
203 786 skrzyp
 
204
        .endm
205
 
206
#---------------------------------------------------------------------------
207
# Define the exception vectors.
208
 
209
rom_vectors:
210
        # These are the architecture-defined vectors that
211
        # are always present.
212
 
213
        reset_vector            reset                   0x100
214
        exception_vector        bus_error               0x200
215
        exception_vector        data_page_fault         0x300
216
        exception_vector        instruction_page_fault  0x400
217
        exception_vector        tick_timer              0x500
218
        exception_vector        unaligned_access        0x600
219
        exception_vector        illegal_instruction     0x700
220
        exception_vector        external_interrupt      0x800
221
        exception_vector        dtlb_miss               0x900
222
        exception_vector        itlb_miss               0xa00
223
        exception_vector        range                   0xb00
224
        exception_vector        syscall                 0xc00
225
        exception_vector        reserved                0xd00
226
        exception_vector        trap                    0xe00
227
 
228
rom_vectors_end:
229
 
230
 
231
#if (defined(CYG_HAL_STARTUP_ROM)) || \
232
    (defined(CYG_HAL_STARTUP_RAM) && !defined(CYGSEM_HAL_USE_ROM_MONITOR)) || \
233
    (defined(CYG_HAL_STARTUP_JTAG) && !defined(CYGSEM_HAL_USE_ROM_MONITOR))
234
 
235
        .macro  hal_vsr_table_init
236
 
237
        # Next initialize the VSR table. This happens whether the
238
        # vectors were copied to RAM or not.
239
 
240
        # First fill with exception handlers
241
        load32i r3,cyg_hal_default_exception_vsr
242
        load32i r4,hal_vsr_table+4  # First entry in table is unused
243
        l.ori   r5,r0,CYGNUM_HAL_VSR_COUNT
244
1:      l.sw    0(r4),r3
245
        l.addi  r5,r5,-1
246
        l.sfgtsi r5,0
247 838 skrzyp
 
248
#ifdef CYGHWR_BRANCH_SLOT_IMPLEMENTED
249 786 skrzyp
        l.bf    1b
250 838 skrzyp
        l.addi  r4,r4,4
251
#else
252
        l.addi  r4,r4,4
253
        l.bf    1b
254
#endif
255 786 skrzyp
 
256
        # Then fill in the interrupt handlers
257
        load32i r4,hal_vsr_table
258
        load32i r3,cyg_hal_default_interrupt_vsr
259
        l.sw    CYGNUM_HAL_VECTOR_INTERRUPT*4(r4),r3
260
        l.sw    CYGNUM_HAL_VECTOR_TICK_TIMER*4(r4),r3
261
        .endm
262
 
263
#elif (defined(CYG_HAL_STARTUP_RAM) && defined(CYGSEM_HAL_USE_ROM_MONITOR)) || \
264
      (defined(CYG_HAL_STARTUP_JTAG) && defined(CYGSEM_HAL_USE_ROM_MONITOR))
265
 
266
        # Initialize the VSR table entries
267
        # We only take control of the interrupt vectors,
268
        # the rest are left to the ROM for now...
269
 
270
        .macro  hal_vsr_table_init
271
        load32i r4,hal_vsr_table
272
        load32i r3,cyg_hal_default_interrupt_vsr
273
        l.sw    CYGNUM_HAL_VECTOR_INTERRUPT*4(r4),r3
274
        l.sw    CYGNUM_HAL_VECTOR_TICK_TIMER*4(r4),r3
275
        .endm
276
 
277
 
278
#else
279
 
280
#error "Need to define hal_vsr_table_init"
281
 
282
#endif
283
 
284
# I-Cache initialization macro
285
        .macro  hal_icache_init
286
        /* Disable I-Cache */
287
        l.mfspr r13,r0,SPR_SR
288
        l.addi  r11,r0,-1
289
        l.xori  r11,r11,SPR_SR_ICE
290
        l.and   r11,r13,r11
291
        l.mtspr r0,r11,SPR_SR
292
 
293
        /* Invalidate I-Cache */
294
        l.addi  r13,r0,0
295
        l.addi  r11,r0,HAL_ICACHE_SIZE
296
1:
297
        l.mtspr r0,r13,SPR_ICBIR
298
        l.sfne  r13,r11
299 838 skrzyp
#ifdef CYGHWR_BRANCH_SLOT_IMPLEMENTED
300 786 skrzyp
        l.bf    1b
301
        l.addi  r13,r13,HAL_ICACHE_LINE_SIZE
302 838 skrzyp
#else
303
        l.addi  r13,r13,HAL_ICACHE_LINE_SIZE
304
        l.bf    1b
305
#endif
306
 
307 786 skrzyp
        /* Enable I-Cache */
308
        l.mfspr r13,r0,SPR_SR
309
        l.ori   r13,r13,SPR_SR_ICE
310
        l.mtspr r0,r13,SPR_SR
311
 
312
        /* Flush instructions out of instruction buffer */
313
        l.nop
314
        l.nop
315
        l.nop
316
        l.nop
317
        l.nop
318
        .endm
319
 
320
# D-Cache initialization macro
321
        .macro  hal_dcache_init
322
 
323
        /* Flush DC */
324
        l.addi  r10,r0,0
325
        l.addi  r11,r0,HAL_DCACHE_SIZE
326
1:
327
        l.mtspr r0,r10,SPR_DCBIR
328
        l.sfne  r10,r11
329 838 skrzyp
#ifdef CYGHWR_BRANCH_SLOT_IMPLEMENTED
330 786 skrzyp
        l.bf    1b
331
        l.addi  r10,r10,HAL_DCACHE_LINE_SIZE
332 838 skrzyp
#else
333
        l.addi  r10,r10,HAL_DCACHE_LINE_SIZE
334
        l.bf    1b
335
#endif
336 786 skrzyp
 
337
        /* Enable DC */
338
        l.mfspr r10,r0,SPR_SR
339
        l.ori   r10,r10,SPR_SR_DCE
340
        l.mtspr r0,r10,SPR_SR
341
        .endm
342
 
343
#===========================================================================
344
# Startup code:  We jump here from the reset vector to set up the world.
345
 
346
        .text
347
 
348
FUNC_START(start)
349
 
350
        # Initialize Supervision Register:
351
        #   Supervisor mode on, all interrupts off, caches off
352
        #
353
        # (If we've entered here from a hardware reset, then the SR is already
354
        # set to this value, but we may have jumped here as part of a soft
355
        # system reset.)
356
        l.ori   r3,r0,SPR_SR_SM
357
        l.mtspr r0,r3,SPR_SR
358
 
359
        # Run platform-specific hardware initialization code.
360
        # This may include memory controller initialization.
361
        # Hence, it is not safe to access RAM until after this point.
362
        #hal_hardware_init
363
 
364 791 skrzyp
#if defined(CYGSEM_HAL_ENABLE_ICACHE_ON_STARTUP) && defined(HAL_ICACHE_SIZE)
365 786 skrzyp
        # Enable I-Cache
366
        hal_icache_init
367
#endif
368
 
369 791 skrzyp
#if defined(CYGSEM_HAL_ENABLE_DCACHE_ON_STARTUP) && defined(HAL_DCACHE_SIZE)
370 786 skrzyp
        # Enable D-Cache
371
        hal_dcache_init
372
#endif
373
 
374
        # Start the tick timer, in case timer polling routine hal_delay_us() is called.
375
        # Initially, no interrupts are generated by the tick timer.  Later on, that
376
        # may change when the kernel is initialized.
377
        l.movhi r3, hi(0x40000000|CYGNUM_HAL_RTC_PERIOD)
378
        l.ori r3, r3, lo(CYGNUM_HAL_RTC_PERIOD)
379
        l.mtspr r0,r3, SPR_TTMR
380
 
381
        .globl  hal_hardware_init_done
382
hal_hardware_init_done:
383
 
384
        # set up stack
385
        load32i sp,__interrupt_stack
386
 
387
        # Make a dummy frame on the stack, so that stack backtraces are sane
388
        # for debugging.  On return from that function, the restore_state()
389
        # function is called to resume the interrupted thread.
390
        l.addi  sp,sp,-8
391
        l.sw    4(sp),r0        # Dummy saved FP
392
        l.sw    0(sp),r0        # Dummy saved LR
393
 
394
        # Set up exception handlers and VSR table, taking care not to
395
        # step on any ROM monitor VSRs.
396
        hal_vsr_table_init
397
 
398
#if defined(CYG_HAL_STARTUP_ROM)
399
        # Copy exception/interrupt vectors from ROM to address 0x100
400
        load32i r4,0x100
401
        load32i r3,rom_vectors
402
        load32i r5,rom_vectors_end
403
1:      l.sfeq  r3,r5
404
        l.bf    2f
405
        l.lwz   r6,0(r3)
406
        l.sw    0(r4),r6
407
        l.addi  r3,r3,4
408 838 skrzyp
#ifdef CYGHWR_BRANCH_SLOT_IMPLEMENTED
409 786 skrzyp
        l.j     1b
410
        l.addi  r4,r4,4         # delay slot
411 838 skrzyp
#else
412
        l.addi  r4,r4,4
413
        l.j     1b
414
#endif
415 786 skrzyp
2:
416
 
417
        # Copy .data section into RAM
418
        load32i r3,__rom_data_start
419
        load32i r4,__ram_data_start
420
        load32i r5,__ram_data_end
421
1:      l.sfeq  r4,r5
422
        l.bf    2f
423
        l.lwz   r6,0(r3)
424
        l.sw    0(r4),r6
425
        l.addi  r3,r3,4
426 838 skrzyp
#ifdef CYGHWR_BRANCH_SLOT_IMPLEMENTED
427 786 skrzyp
        l.j     1b
428
        l.addi  r4,r4,4         # delay slot
429 838 skrzyp
#else
430
        l.addi  r4,r4,4
431
        l.j     1b
432
#endif
433 786 skrzyp
2:
434
 
435
#endif
436
 
437
        # clear BSS
438
        load32i r4,__bss_start
439
        load32i r5,__bss_end
440
1:      l.sfeq  r4,r5
441
        l.bf    2f
442 838 skrzyp
#ifdef CYGHWR_BRANCH_SLOT_IMPLEMENTED
443 786 skrzyp
        l.nop
444 838 skrzyp
#endif
445 786 skrzyp
        l.sw    0(r4),r0
446 838 skrzyp
#ifdef CYGHWR_BRANCH_SLOT_IMPLEMENTED
447 786 skrzyp
        l.j     1b
448
        l.addi  r4,r4,4
449 838 skrzyp
#else
450
        l.addi  r4,r4,4
451
        l.j     1b
452
#endif
453 786 skrzyp
2:
454
 
455
        # Note:  no SBSS section to clear with OpenRISC target
456
 
457
        # Platform-specific initialization
458
        l.jal   hal_platform_init
459 838 skrzyp
#ifdef CYGHWR_BRANCH_SLOT_IMPLEMENTED
460 786 skrzyp
        l.nop   # delay slot
461 838 skrzyp
#endif
462 786 skrzyp
 
463
        # call c++ constructors
464
        l.jal   cyg_hal_invoke_constructors
465 838 skrzyp
#ifdef CYGHWR_BRANCH_SLOT_IMPLEMENTED
466 786 skrzyp
        l.nop   # delay slot
467 838 skrzyp
#endif
468 786 skrzyp
 
469
#ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
470 791 skrzyp
        l.jal   initialize_stub
471 838 skrzyp
#ifdef CYGHWR_BRANCH_SLOT_IMPLEMENTED
472 786 skrzyp
        l.nop   # delay slot
473
#endif
474 838 skrzyp
#endif
475 786 skrzyp
 
476
#if defined(CYGDBG_HAL_DEBUG_GDB_CTRLC_SUPPORT) \
477
    || defined(CYGDBG_HAL_DEBUG_GDB_BREAK_SUPPORT)
478
        .extern hal_ctrlc_isr_init
479
        l.jal   hal_ctrlc_isr_init
480 838 skrzyp
#ifdef CYGHWR_BRANCH_SLOT_IMPLEMENTED
481 786 skrzyp
        l.nop   # delay slot
482
#endif
483 838 skrzyp
#endif
484 786 skrzyp
 
485
        l.jal   cyg_start       # call cyg_start()
486 838 skrzyp
#ifdef CYGHWR_BRANCH_SLOT_IMPLEMENTED
487 786 skrzyp
        l.nop   # delay slot
488 838 skrzyp
#endif
489 786 skrzyp
9:
490
        l.j     9b              # if we return, loop
491 838 skrzyp
#ifdef CYGHWR_BRANCH_SLOT_IMPLEMENTED
492 786 skrzyp
        l.nop   # delay slot
493 838 skrzyp
#endif
494 786 skrzyp
 
495
FUNC_END(start)
496
 
497
#---------------------------------------------------------------------------
498
# This code handles the common part of all exception handlers.
499
# On entry, the machine state is already saved on the stack.
500
#
501
# R3 = pointer to HAL_SavedRegisters struct containing saved machine state
502
# R4 = Vector number
503
#
504
# It calls a C routine to do any work, which may result in
505
# thread switches and changes to the saved state. When we return
506
# here, the saved state is restored and execution is continued.
507
 
508
        .text
509
 
510
FUNC_START(cyg_hal_default_exception_vsr)
511
 
512
        .extern cyg_hal_exception_handler
513
 
514
        # Call C code
515
 
516
        # When cyg_hal_exception_handler() returns, it will jump
517
        # directly to restore_state(), which will resume execution
518
        # at the location of the exception.
519
        l.movhi r9, hi(restore_state)
520 838 skrzyp
#ifdef CYGHWR_BRANCH_SLOT_IMPLEMENTED
521 786 skrzyp
        l.j     cyg_hal_exception_handler
522
        l.ori   r9,r9,lo(restore_state) #Delay slot
523 838 skrzyp
#else
524
        l.ori   r9,r9,lo(restore_state)
525
        l.j     cyg_hal_exception_handler
526
#endif
527 786 skrzyp
 
528
        # Control never reaches this point,
529
 
530
FUNC_END(cyg_hal_default_exception_vsr)
531
 
532
#---------------------------------------------------------------------------
533
# This code handles all interrupts and dispatches to a C ISR function
534
# On entry, the machine state is already saved on the stack.
535
#
536
# R3 = pointer to HAL_SavedRegisters struct containing saved machine state
537
# R4 = Vector number
538
#
539
# After we return here, the saved state is restored and execution is continued.
540
 
541
#ifdef CYGIMP_FORCE_INTERRUPT_HANDLING_CODE_IN_RAM
542
        .section .text.ram,"ax"
543
#else
544
        .section .text,"ax"
545
#endif
546
 
547
FUNC_START(cyg_hal_default_interrupt_vsr)
548
 
549
        # Stash away pointer to saved regs for later
550
        l.or    r31,r3,r3
551
 
552
        # Set scheduler lock to prevent thread rescheduling while the ISR runs
553
#ifdef CYGFUN_HAL_COMMON_KERNEL_SUPPORT
554
        .extern cyg_scheduler_sched_lock
555
        load32i r5, cyg_scheduler_sched_lock
556
        l.lwz   r6,0(r5)
557
        l.addi  r6,r6,1
558
        l.sw    0(r5),r6
559
#endif
560
 
561
#ifdef CYGIMP_HAL_COMMON_INTERRUPTS_USE_INTERRUPT_STACK
562
        # Interrupts execute on their own dedicated stack.
563
        # If we're on a thread stack, switch to the interrupt stack.
564
        # If we're called inside a nested interrupt, do nothing.
565
        l.or    r6,sp,sp                        # Stash SP for later
566
        load32i r7,__interrupt_stack            # stack top (highest addr + 1)
567
        load32i r8,__interrupt_stack_base       # stack base (lowest addr)
568
        l.sfltu sp,r8                           # if (sp < __interrupt_stack_base)
569
        l.bf    1f                              #    switch to interrupt stack
570
        l.sfltu sp,r7                           # if (sp < __interrupt_stack_top)
571
        l.bf   2f                               #    already on interrupt stack
572 838 skrzyp
#ifdef CYGHWR_BRANCH_SLOT_IMPLEMENTED
573 786 skrzyp
        l.nop                                   # delay slot
574 838 skrzyp
#endif
575 786 skrzyp
1:      l.or    sp,r7,r7                        # Switch to interrupt stack
576
2:      l.addi  sp,sp,-8                        # Make space to save old SP...
577
        l.sw    0(sp),r6                        # ...and save it on the stack
578
#endif
579
 
580
        # Call C code
581
 
582
#if defined(CYGPKG_KERNEL_INSTRUMENT) && defined(CYGDBG_KERNEL_INSTRUMENT_INTR)
583
        # Log the interrupt if kernel tracing is enabled
584
        l.ori   r3,r0,0x0301                    # arg1 = type = INTR,RAISE
585
                                                # arg2 = vector number
586
        l.ori   r5,r0,r0                        # arg3 = 0
587
        l.jal   _cyg_instrument                  # call instrument function
588 838 skrzyp
#ifdef CYGHWR_BRANCH_SLOT_IMPLEMENTED
589
        l.nop
590
#endif
591 786 skrzyp
 
592
#endif
593
 
594
#if defined(CYGDBG_HAL_DEBUG_GDB_CTRLC_SUPPORT) \
595
    || defined(CYGDBG_HAL_DEBUG_GDB_BREAK_SUPPORT)
596
        # If we are supporting Ctrl-C interrupts from GDB, we must squirrel
597
        # away a pointer to the save interrupt state here so that we can
598
        # plant a breakpoint at some later time.
599
 
600
        .extern hal_saved_interrupt_state
601
        load32i r8,hal_saved_interrupt_state
602
        l.sw    0(r8),r31
603
 
604
#endif
605
 
606
        # In the event of multiple pending interrupts, determine which
607
        # one will be serviced first.  By software convention, the lowest
608
        # numbered external interrupt gets priority.
609
        #
610
        # The (internal) tick timer interrupt is serviced only if no
611
        # external interrupts are pending.
612
 
613
        # Read the PIC interrupt controller's status register
614
        l.mfspr r9,r0,SPR_PICSR
615
 
616
        # Any pending external interrupts ?
617
        l.sfnei r9,0
618
        l.bf    check_for_external_interrupts
619 838 skrzyp
#ifdef CYGHWR_BRANCH_SLOT_IMPLEMENTED
620
        l.nop
621
#endif
622 786 skrzyp
 
623
        # Theoretically, the only way we could get here is if the tick timer
624
        # interrupt fired, but we check to be sure that's what happened.
625
        l.sfeqi r4,CYGNUM_HAL_VECTOR_TICK_TIMER
626 838 skrzyp
#ifdef CYGHWR_BRANCH_SLOT_IMPLEMENTED
627 786 skrzyp
        l.bf    3f
628
        l.ori   r3,r0,CYGNUM_HAL_INTERRUPT_RTC  # delay slot
629 838 skrzyp
#else
630
        l.ori   r3,r0,CYGNUM_HAL_INTERRUPT_RTC
631
        l.bf    3f
632
#endif
633
 
634 786 skrzyp
#ifndef CYGIMP_HAL_COMMON_INTERRUPTS_IGNORE_SPURIOUS
635
        l.jal   hal_spurious_IRQ
636 838 skrzyp
#ifdef CYGHWR_BRANCH_SLOT_IMPLEMENTED
637 786 skrzyp
        l.nop
638 838 skrzyp
#endif
639 786 skrzyp
#endif // CYGIMP_HAL_COMMON_INTERRUPTS_IGNORE_SPURIOUS
640
        l.j     ignore_spurious_interrupt
641 838 skrzyp
#ifdef CYGHWR_BRANCH_SLOT_IMPLEMENTED
642
        l.nop
643
#endif
644 786 skrzyp
 
645
        # Identify the lowest numbered interrupt bit in the PIC's PSR,
646
        # numbering the MSB as 31 and the LSB as 0
647
check_for_external_interrupts:
648
        l.ori   r3,r0,0
649
2:      l.andi  r11,r9,1                        # Test low bit
650
        l.sfnei r11,0
651
        l.bf    3f
652
        l.srli  r9,r9,1                         # Shift right 1 bit
653 838 skrzyp
#ifdef CYGHWR_BRANCH_SLOT_IMPLEMENTED
654 786 skrzyp
        l.j     2b
655
        l.addi  r3,r3,1                         # Delay slot
656 838 skrzyp
#else
657
        l.addi  r3,r3,1
658
        l.j     2b
659
#endif
660 786 skrzyp
3:
661
 
662
        # At this point, r3 contains the ISR number, from 0-32
663
        # which will be used to index the table of ISRs
664
        l.slli  r15,r3,2
665
        load32i r9, hal_interrupt_handlers     # get interrupt handler table
666
        l.add   r9,r9,r15
667
        l.lwz   r11,0(r9)                       # load ISR pointer
668
        load32i r9, hal_interrupt_data         # get interrupt data table
669
        l.add   r9,r9,r15
670
        l.lwz   r4,0(r9)                        # load data arg to ISR
671
 
672
        # Call ISR
673
        #   arg0 = ISR #
674
        #   arg1 = data arg associated with interrupt
675
        l.jalr  r11
676 838 skrzyp
#ifdef CYGHWR_BRANCH_SLOT_IMPLEMENTED
677 786 skrzyp
        l.nop
678 838 skrzyp
#endif
679 786 skrzyp
 
680
ignore_spurious_interrupt:
681
 
682
#ifdef CYGIMP_HAL_COMMON_INTERRUPTS_USE_INTERRUPT_STACK
683
 
684
        # If we are returning from the last nested interrupt, move back
685
        # to the thread stack. interrupt_end() must be called on the
686
        # thread stack since it potentially causes a context switch.
687
        # Since we have arranged for the top of stack location to
688
        # contain the sp we need to go back to here, just pop it off
689
        # and put it in SP.
690
 
691
        l.lwz   sp,0(sp)
692
#endif
693
 
694
#ifdef CYGFUN_HAL_COMMON_KERNEL_SUPPORT
695
 
696
        # We only need to call _interrupt_end() when there is a kernel
697
        # present to do any tidying up.
698
 
699
        # on return r11 bit 1 will indicate whether a DSR is
700
        # to be posted. Pass this together with a pointer to
701
        # the interrupt object we have just used to the
702
        # interrupt tidy up routine.
703
        l.or    r3,r11,r11
704
 
705
        # Get pointer to HAL_SavedRegisters struct, stashed earlier
706
        l.or    r5,r31,r31
707
 
708
        # Get opaque object associated w/ interrupt vector
709
        load32i r9, hal_interrupt_objects          # get interrupt data table
710
        l.add   r9,r9,r15
711
        l.lwz   r4,0(r9)
712
 
713
        # Call interrupt_end() to execute any pending DSRs
714
        #   Arg 0 = return value from ISR
715
        #   Arg 1 = object associated with interrupt
716
        #   Arg 2 = HAL_SavedRegisters struct
717
 
718
        .extern interrupt_end
719
        l.jal   interrupt_end                   # call into C to finish off
720 838 skrzyp
#ifdef CYGHWR_BRANCH_SLOT_IMPLEMENTED
721 786 skrzyp
        l.nop
722
#endif
723 838 skrzyp
#endif
724 786 skrzyp
 
725
        # Fall through to restore_state...
726
 
727
# Return from either an interrupt or an exception
728
#
729
# On entry:
730
#    SP = pointer to (HAL_SavedRegisters struct)
731
#
732
restore_state:
733
 
734
        # Restore General Purpose Registers (GPRs).
735
        # R0 is not restored because it is always zero-valued.
736
        # R1, R3, and R4 are used as temps, so they are restored a little later
737
        l.lwz   r5,   5 * OR1K_GPRSIZE(sp)
738
        l.lwz   r6,   6 * OR1K_GPRSIZE(sp)
739
        l.lwz   r7,   7 * OR1K_GPRSIZE(sp)
740
        l.lwz   r8,   8 * OR1K_GPRSIZE(sp)
741
        l.lwz   r9,   9 * OR1K_GPRSIZE(sp)
742
        l.lwz   r11, 11 * OR1K_GPRSIZE(sp)
743 790 skrzyp
        l.lwz   r12, 12 * OR1K_GPRSIZE(sp)
744 786 skrzyp
        l.lwz   r13, 13 * OR1K_GPRSIZE(sp)
745
        l.lwz   r15, 15 * OR1K_GPRSIZE(sp)
746
        l.lwz   r17, 17 * OR1K_GPRSIZE(sp)
747
        l.lwz   r19, 19 * OR1K_GPRSIZE(sp)
748
        l.lwz   r21, 21 * OR1K_GPRSIZE(sp)
749
        l.lwz   r23, 23 * OR1K_GPRSIZE(sp)
750
        l.lwz   r25, 25 * OR1K_GPRSIZE(sp)
751
        l.lwz   r27, 27 * OR1K_GPRSIZE(sp)
752
        l.lwz   r29, 29 * OR1K_GPRSIZE(sp)
753
        l.lwz   r31, 31 * OR1K_GPRSIZE(sp)
754
 
755
#ifndef CYGDBG_HAL_COMMON_INTERRUPTS_SAVE_MINIMUM_CONTEXT
756
        # Callee-saved regs don't need to be preserved across a call into
757
        # an ISR, but we can do so to make debugging easier.
758
 
759
        l.lwz   r2,   2 * OR1K_GPRSIZE(sp)
760
        l.lwz   r10, 10 * OR1K_GPRSIZE(sp)
761
        l.lwz   r14, 14 * OR1K_GPRSIZE(sp)
762
        l.lwz   r16, 16 * OR1K_GPRSIZE(sp)
763
        l.lwz   r18, 18 * OR1K_GPRSIZE(sp)
764
        l.lwz   r20, 20 * OR1K_GPRSIZE(sp)
765
        l.lwz   r22, 22 * OR1K_GPRSIZE(sp)
766
        l.lwz   r24, 24 * OR1K_GPRSIZE(sp)
767
        l.lwz   r26, 26 * OR1K_GPRSIZE(sp)
768
        l.lwz   r28, 28 * OR1K_GPRSIZE(sp)
769
        l.lwz   r30, 30 * OR1K_GPRSIZE(sp)
770
 
771 790 skrzyp
#endif
772 786 skrzyp
        # Restore MAC LO and HI regs
773
        l.lwz   r4, OR1KREG_MACLO(sp)
774
        l.mtspr r0,r4,SPR_MACLO
775
        l.lwz   r4, OR1KREG_MACHI(sp)
776
        l.mtspr r0,r4,SPR_MACHI
777
 
778
        # Must disable interrupts, since they could clobber ESR and EPC regs
779
        l.mfspr r3, r0, SPR_SR
780
        load32i r4,~(SPR_SR_TEE|SPR_SR_IEE)
781
        l.and   r3, r4, r3
782
        l.mtspr r0, r3, SPR_SR
783
 
784
        # At this point we've restored all the pre-interrupt GPRs except for the SP.
785
        # Restore pre-interrupt SR, SP, and PC
786
        l.lwz    r4,  OR1KREG_SR(sp)
787
        l.mtspr  r0, r4, SPR_ESR_BASE
788
 
789
        l.lwz    r4,  OR1KREG_PC(sp)
790
        l.mtspr  r0, r4, SPR_EPCR_BASE
791
 
792
        l.lwz   r4,   4 * OR1K_GPRSIZE(sp)
793
        l.lwz   r3,   3 * OR1K_GPRSIZE(sp)
794
        l.lwz    sp,  1 * OR1K_GPRSIZE(sp)
795
 
796
        # All done, restore CPU state and continue
797
        l.rfe
798 838 skrzyp
#ifdef CYGHWR_BRANCH_SLOT_IMPLEMENTED
799 786 skrzyp
        l.nop           # Delay slot
800 838 skrzyp
#endif
801 786 skrzyp
 
802
 
803
##-----------------------------------------------------------------------------
804
## Execute pending DSRs on the interrupt stack with interrupts enabled.
805
## Note: this can only be called from code running on a thread stack
806
 
807
#ifdef CYGIMP_HAL_COMMON_INTERRUPTS_USE_INTERRUPT_STACK
808
        .extern cyg_interrupt_call_pending_DSRs
809
 
810
        .text
811
FUNC_START(hal_interrupt_stack_call_pending_DSRs)
812
        # Switch to interrupt stack
813
        l.or    r3, sp, sp      # Stash entry SP
814
        load32i sp, __interrupt_stack
815
        l.addi  sp, sp, -16
816
        l.sw    0(sp), r3       # Save entry SP
817
        l.mfspr r4,r0,SPR_SR
818
        l.sw    4(sp), r4       # Save interrupt state
819
        l.ori   r4, r4, SPR_SR_IEE|SPR_SR_TEE
820
        l.sw    8(sp),lr
821 838 skrzyp
#ifdef CYGHWR_BRANCH_SLOT_IMPLEMENTED
822 786 skrzyp
        l.jal   cyg_interrupt_call_pending_DSRs
823 838 skrzyp
        l.mtspr r0, r4, SPR_SR  # Enable interrupts before calling DSRs
824
#else
825
        l.mtspr r0, r4, SPR_SR  # Enable interrupts before calling DSRs
826
        l.jal   cyg_interrupt_call_pending_DSRs
827
#endif
828 786 skrzyp
        l.lwz   r4, 4(sp)
829
        l.lwz   lr, 8(sp)
830
        l.lwz   sp, 0(sp)
831
 
832
        # Merge original interrupt state with (possibly altered) SR reg
833
        l.andi  r4, r4, SPR_SR_IEE|SPR_SR_TEE
834
        l.mfspr r5, r0, SPR_SR
835
        load32i r6, ~(SPR_SR_IEE|SPR_SR_TEE)
836
        l.and   r5, r5, r6
837
        l.or    r4, r4, r5
838 838 skrzyp
#ifdef CYGHWR_BRANCH_SLOT_IMPLEMENTED
839 786 skrzyp
        l.jr    r9
840
        l.mtspr r0, r4, SPR_SR  # Delay slot
841 838 skrzyp
#else
842
        l.mtspr r0, r4, SPR_SR
843
        l.jr    r9
844
#endif
845
 
846 786 skrzyp
FUNC_END(hal_interrupt_stack_call_pending_DSRs)
847
#endif
848
 
849
##-----------------------------------------------------------------------------
850
## Switch to a new stack.
851
## This is used in RedBoot to allow code to execute in a different
852
## stack context.
853
 
854
FUNC_START(hal_program_new_stack)
855
        # Arguments are:
856
        # r3 = function to call
857
        # r4 = stack pointer to use
858
 
859
        # Dummy prologue, so that debugger is fooled into thinking there
860
        # is a stack frame.  The debugger will use the offsets in the prologue
861
        # below to read the saved register values out of the *new* stack.
862
        l.addi  sp,sp,-8
863
        l.sw    0(sp),fp
864
        l.addi  fp,sp,8
865
        l.sw    4(sp),lr
866
 
867
        l.or    r5,sp,sp        # Remember original SP
868
        l.addi  r6,fp,-8        # Remember original FP
869
        l.or    sp,r4,r4        # Switch to new stack
870
 
871
        # "Real prologue" - Offsets here must match dummy prologue above
872
        l.addi  sp,sp,-16
873
        l.sw    0(sp),r6        # So debugger can know caller's FP
874
        l.sw    4(sp),lr        # So debugger can know caller's PC
875
        l.sw    8(sp),r5        # Save old SP on stack
876
 
877
        # Call function
878
        l.jalr  r3
879 838 skrzyp
#ifdef CYGHWR_BRANCH_SLOT_IMPLEMENTED
880 786 skrzyp
        l.nop
881 838 skrzyp
#endif
882 786 skrzyp
 
883
        l.lwz   sp, 8(sp)       # Restore original SP
884
        l.lwz   lr, 4(sp)
885 838 skrzyp
#ifdef CYGHWR_BRANCH_SLOT_IMPLEMENTED
886 786 skrzyp
        l.jr    lr              # Return to caller
887
        l.addi  sp,sp, 8        # Delay slot
888 838 skrzyp
#else
889
        l.addi  sp,sp, 8
890
        l.jr    lr              # Return to caller
891
#endif
892
 
893 786 skrzyp
FUNC_END(hal_program_new_stack)
894
 
895
#---------------------------------------------------------------------------
896
## Temporary interrupt stack
897
 
898
        .section ".bss"
899
 
900
        .balign 16
901
        .global cyg_interrupt_stack_base
902
cyg_interrupt_stack_base:
903
__interrupt_stack_base:
904
        .rept CYGNUM_HAL_COMMON_INTERRUPTS_STACK_SIZE
905
        .byte 0
906
        .endr
907
        .balign 16
908
        .global cyg_interrupt_stack
909
cyg_interrupt_stack:
910
__interrupt_stack:
911
 
912
        .long   0,0,0,0,0,0,0,0
913
 
914
#--------------------------------------
915
        .data
916
        .extern hal_default_isr
917
 
918
        .globl  hal_interrupt_handlers
919
hal_interrupt_handlers:
920
        .rept   CYGNUM_HAL_ISR_COUNT
921
        .long   hal_default_isr
922
        .endr
923
 
924
        .globl  hal_interrupt_data
925
hal_interrupt_data:
926
        .rept   CYGNUM_HAL_ISR_COUNT
927
        .long   0
928
        .endr
929
 
930
        .globl  hal_interrupt_objects
931
hal_interrupt_objects:
932
        .rept   CYGNUM_HAL_ISR_COUNT
933
        .long   0
934
        .endr
935
 
936
#---------------------------------------------------------------------------
937
# end of vectors.S

powered by: WebSVN 2.1.0

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