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 790

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

powered by: WebSVN 2.1.0

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