summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libcpu/mips/mongoosev/vectorisrs/vectorisrs.c
blob: 92c752aff08fd47cf71aa4925658861d6c91fa68 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
 *  ISR Vectoring support for the Synova Mongoose-V.
 *
 *  COPYRIGHT (c) 1989-2001.
 *  On-Line Applications Research Corporation (OAR).
 *
 *  The license and distribution terms for this file may be
 *  found in the file LICENSE in this distribution or at
 *  http://www.OARcorp.com/rtems/license.html.
 *
 *  $Id$
 */

#include <rtems.h>
#include <stdlib.h>
#include <libcpu/mongoose-v.h>

#define mips_get_cause( _cause ) \
  do { \
    asm volatile( "mfc0 %0, $13; nop" : "=r" (_cause) :  ); \
  } while (0)

#define CALL_ISR(_vector) \
  do { \
    if ( _ISR_Vector_table[_vector] ) \
      (_ISR_Vector_table[_vector])(_vector); \
    else \
      mips_default_exception(_vector); \
  } while (0)

#include <bspIo.h>  /* for printk */

void mips_default_exception( int vector )
{
  printk( "Unhandled exception %d\n", vector );
  rtems_fatal_error_occurred(1);
}

void mips_vector_isr_handlers( void )
{
  unsigned int sr;
  unsigned int cause;
  int          bit;
  unsigned int pf_icr;

  mips_get_sr( sr );
  mips_get_cause( cause );

  cause &= (sr & SR_IMASK);
  cause >>= CAUSE_IPSHIFT;

  if ( cause & 0x04 )       /* IP[0] ==> INT0 == TIMER1 */
    CALL_ISR( MONGOOSEV_IRQ_TIMER1 );
    
  if ( cause & 0x08 )       /* IP[1] ==> INT1 == TIMER2*/
    CALL_ISR( MONGOOSEV_IRQ_TIMER2 );
    
  if ( cause & 0x10 )       /* IP[2] ==> INT2 */
    CALL_ISR( MONGOOSEV_IRQ_INT2 );
    
  if ( cause & 0x20 )       /* IP[3] ==> INT4 */
    CALL_ISR( MONGOOSEV_IRQ_INT4 );
    
  if ( cause & 0x40 ) {     /* IP[4] ==> INT5 */
    pf_icr =
      MONGOOSEV_READ( MONGOOSEV_PERIPHERAL_FUNCTION_INTERRUPT_CAUSE_REGISTER );
    /* XXX if !pf_icr */
    for ( bit=0 ; bit <= 31 ; bit++, pf_icr >>= 1 ) {
      if ( pf_icr & 1 )
        CALL_ISR( MONGOOSEV_IRQ_PERIPHERAL_BASE + bit );
    } 
  }

  if ( cause & 0x02 )       /* SW[0] */
    CALL_ISR( MONGOOSEV_IRQ_SOFTWARE_1 );

  if ( cause & 0x01 )       /* IP[1] */
    CALL_ISR( MONGOOSEV_IRQ_SOFTWARE_2 );
}