excArchLib.c
Upload User: datangss
Upload Date: 2017-07-07
Package Size: 10487k
Code Size: 25k
Category:

VxWorks

Development Platform:

C/C++

  1. /* excArchLib.c - MIPS architecture exception handling facilities */
  2. /* Copyright 1984-2001 Wind River Systems, Inc. */
  3. #include "copyright_wrs.h"
  4. /*
  5.  * This file has been developed or significantly modified by the
  6.  * MIPS Center of Excellence Dedicated Engineering Staff.
  7.  * This notice is as per the MIPS Center of Excellence Master Partner
  8.  * Agreement, do not remove this notice without checking first with
  9.  * WR/Platforms MIPS Center of Excellence engineering management.
  10.  */
  11. /*
  12. modification history
  13. --------------------
  14. 02h,16jul01,ros  add CofE comment
  15. 02g,13jul01,sru  fix 32-bit extraction of break type
  16. 02f,17apr01,dxc  SPR 64275: Fix to handle MIPS16 correctly
  17. 02h,13apr01,sru  add BSP-callable functions to set exception vectors
  18. 02g,28mar01,sru  use UT_VEC for R3K tlb vector address
  19. 02f,19dec00,pes  Adapt to MIPS32/MIPS64 CPU architectures
  20. 02e,10sep99,myz  added CW4000_16 support
  21. 02d,19jan99,dra  added CW4000, CW4011, VR4100, VR5000 and VR5400 support.
  22. 02c,14oct96,kkk  added R4650 support.
  23. 02c,22jul96,pr   added windview instrumentation.
  24. 02b,30may96,kkk  changed FP exceptions from excIntHandle to excExcHandle.
  25. 02a,18oct93,cd   added R4000 support.
  26. 01z,29sep93,caf  undid fix of SPR #2359.
  27. 01y,07jul93,yao  fixed to preserve parity error bit of status 
  28.  register (SPR #2359).
  29.            +caf  ansification: added cast to cacheInvalidate() parameter,
  30.  added forward declaration of excGetInfoFromESF().
  31. 01x,19oct92,jcf  swapped 5.0/excInfoShow hook order.
  32. 01w,01oct92,ajm  changed excIntToExc to excIntHandle for fpa ints
  33. 01v,31aug92,rrr  fixed code passed to signal handler
  34. 01u,23aug92,jcf  reverted to version 1t.
  35. 01t,23aug92,jcf  changed cache* to CACHE_*.  changed filename.
  36. 01s,07aug92,ajm  ansified
  37. 01r,02aug92,jcf  pass two of exc split. excJobAdd no longer needed.
  38. 01p,30jul92,rrr  pass one of the exc split
  39. 01o,09jul92,ajm  corrected include list with sigLibP.h
  40. 01n,07jul92,ajm  added 5.1 cache support
  41. 01m,04jul92,jcf  scalable/ANSI/cleanup effort.
  42. 01l,06jun92,ajm  5.0.5 merge, notice mod history changes
  43. 01k,26may92,rrr  the tree shuffle
  44. 01j,16jan92,yao  removed EXC_MSG.  made excExcFix() local.  added missing
  45.                  args to excJobAdd() and printExc(). added excFaultTab[].
  46.                  moved excDeliverSignal() to src/all/excLib.c.
  47. 02i,16jan92,jdi  made excExcFix() NOMANUAL.
  48. 02h,14jan92,jdi  documentation cleanup.
  49. 01g,18nov91,ajm  turned off rom based vectors in excVecInit
  50. 01f,05oct91,ajm  corrected order of VME interrupts in excMsgs
  51. 01e,04oct91,rrr  passed through the ansification filter
  52.                   -changed includes to have absolute path from h/
  53.                   -changed VOID to void
  54.                   -changed copyright notice
  55. 01d,31jul91,ajm  made co-processor exceptions place fpcsr in sigcontext
  56.   made excExcFix global for handling of fpa interrupts
  57.   this should be changed later
  58. 01c,17jul91,ajm  added interrupt ack to excIntHandle
  59. 01b,01jul91,ajm  fixed badva not to be valid on bus error
  60. 01a,01apr91,ajm  MIPS-ized and split from excLib.c.  Derived from 02h of 68k.
  61. */
  62. /*
  63. This module provides architecture-dependent facilities for handling MIPS
  64. R-Series exceptions.  See excLib for the portions that are architecture
  65. independent.
  66. INITIALIZATION
  67. Initialization of exception handling facilities is in two parts.  First,
  68. excVecInit() is called to set all the MIPS exception, trap, and interrupt
  69. vectors to the default handlers provided by this module.  The rest of this
  70. package is initialized by calling excInit() (in excLib), which spawns the
  71. exception support task, excTask(), and creates the pipe used to communicate
  72. with it.  See the manual entry for excLib for more information.
  73. SEE ALSO: excLib,
  74. .pG "Debugging"
  75. */
  76. /* LINTLIBRARY */
  77. #include "vxWorks.h"
  78. #include "esf.h"
  79. #include "iv.h"
  80. #include "sysLib.h"
  81. #include "intLib.h"
  82. #include "msgQLib.h"
  83. #include "signal.h"
  84. #include "cacheLib.h"
  85. #include "errnoLib.h"
  86. #include "dsmLib.h"
  87. #include "private/funcBindP.h"
  88. #include "private/sigLibP.h"
  89. #include "private/taskLibP.h"
  90. #include "string.h"
  91. #include "rebootLib.h"
  92. /* externals  */
  93. IMPORT void excIntToExc ();     /* change interrupt thread */
  94. IMPORT FUNCPTR excExcepHook;    /* add'l rtn to call when exceptions occur */
  95. IMPORT int sysAutoAck(int );
  96. IMPORT ULONG sysBusEar(void );
  97. IMPORT USHORT sysBusEid(void );
  98. /* forward declarations */
  99. LOCAL void excIntHandle (int vecNum, ESFMIPS * pEsf);
  100. void     excExcHandle (int vecNum, ESFMIPS * pEsf, REG_SET * pRegs);
  101. LOCAL int  excGetInfoFromESF (FAST int vecNum, FAST ESFMIPS *pEsf,
  102.       EXC_INFO *pExcInfo);
  103. /*
  104. * excBsrTbl - table of BSRs
  105. *
  106. * The BSR table is the pointer table for MIPS specific 
  107. * exceptions, and interrupts.  After an exception, the least 
  108. * significant bits of the cause register will point us here.  
  109. * After an interrupt, we use the structure intPrioTbl to point 
  110. * us to the correct entry.
  111. */
  112. VOIDFUNCPTR excBsrTbl[] = 
  113.     {
  114.     excIntHandle,  /* 0 - interrupt exception */
  115.     excExcHandle,  /* 1 - tlb mod exception */
  116.     excExcHandle,  /* 2 - tlb load exception */
  117.     excExcHandle, /* 3 - tlb store exception */
  118.     excExcHandle,  /* 4 - address load exception */
  119.     excExcHandle,  /* 5 - address store exception */
  120.     excExcHandle,  /* 6 - instr. bus error exception*/
  121.     excExcHandle, /* 7 - data bus error exception */
  122.     excExcHandle,  /* 8 - system call exception */
  123.     excExcHandle,  /* 9 - break point exception */
  124.     excExcHandle,  /* 10 - rsvd instruction exception*/
  125.     excExcHandle, /* 11 - coprocessor unusable excptn*/
  126.     excExcHandle,  /* 12 - overflow exception */
  127.     excExcHandle, /* 13 - trap exception  */
  128.     excExcHandle,  /* 14 - VCEI exception  */
  129.     excExcHandle, /* 15 - FPE exception  */
  130.     excExcHandle, /* 16 - reserved entry */
  131.     excExcHandle, /* 17 - reserved entry */
  132.     excExcHandle, /* 18 - reserved entry */
  133.     excExcHandle, /* 19 - reserved entry */
  134.     excExcHandle, /* 20 - reserved entry */
  135.     excExcHandle, /* 21 - reserved entry */
  136.     excExcHandle, /* 22 - reserved entry */
  137.     excExcHandle, /* 23 - watch exception */
  138.     excExcHandle, /* 24 - reserved entry */
  139.     excExcHandle, /* 25 - reserved entry */
  140.     excExcHandle, /* 26 - reserved entry */
  141.     excExcHandle, /* 27 - reserved entry */
  142.     excExcHandle, /* 28 - reserved entry */
  143.     excExcHandle, /* 29 - reserved entry */
  144.     excExcHandle, /* 30 - reserved entry */
  145.     excExcHandle, /* 31 - VCED exception */
  146.     excIntHandle, /* 32 - software trap 0  */
  147.     excIntHandle, /* 33 - software trap 1  */
  148.     excIntHandle, /* 34 - autovec VME irq7 interrupt  */
  149.     excIntHandle, /* 35 - autovec VME irq6 interrupt  */
  150.     excIntHandle, /* 36 - autovec VME irq5 interrupt  */
  151.     excIntHandle, /* 37 - autovec VME irq4 interrupt  */
  152.     excIntHandle, /* 38 - autovec VME irq3 interrupt */
  153.     excIntHandle, /* 39 - autovec VME irq2 interrupt */
  154.     excIntHandle, /* 40 - autovec VME irq1 interrupt  */
  155.     excIntHandle, /* 41 - spare interrupt */
  156.     excIntHandle, /* 42 - uart 0 interrupt */
  157.     excIntHandle, /* 43 - uart 1 interrupt */
  158.     excIntHandle, /* 44 - msg pending interrupt */
  159.     excIntHandle, /* 45 - spare interrupt */
  160.     excIntHandle, /* 46 - spare interrupt */
  161.     excIntHandle, /* 47 - hw bp interrupt */
  162.     excIntHandle, /* 48 - spare interrupt */
  163.     excIntHandle, /* 49 - spare interrupt */
  164.     excIntHandle, /* 50 - timer 0 interrupt */
  165.     excIntHandle, /* 51 - timer 1 interrupt */
  166.     excIntHandle, /* 52 - spare exception */
  167.     excIntHandle, /* 53 - spare exception */
  168.     excExcHandle, /* 54 - unimplemented FPA oper */
  169.     excExcHandle, /* 55 - invalid FPA operation */
  170.     excExcHandle, /* 56 - FPA div by zero */
  171.     excExcHandle, /* 57 - FPA overflow exception */
  172.     excExcHandle, /* 58 - FPA underflow exception */
  173.     excExcHandle, /* 59 - FPA inexact operation */
  174.     excIntHandle, /* 60 - bus error interrupt */
  175.     excIntHandle,
  176.     excIntHandle,
  177.     excIntHandle,
  178.     excIntHandle,
  179.     excIntHandle,
  180.     excIntHandle,
  181.     excIntHandle,
  182.     excIntHandle,
  183.     excIntHandle,
  184.     excIntHandle, /* 70 */
  185.     excIntHandle,
  186.     excIntHandle,
  187.     excIntHandle,
  188.     excIntHandle,
  189.     excIntHandle,
  190.     excIntHandle,
  191.     excIntHandle,
  192.     excIntHandle,
  193.     excIntHandle,
  194.     excIntHandle, /* 80 */
  195.     excIntHandle,
  196.     excIntHandle,
  197.     excIntHandle,
  198.     excIntHandle,
  199.     excIntHandle,
  200.     excIntHandle,
  201.     excIntHandle,
  202.     excIntHandle,
  203.     excIntHandle,
  204.     excIntHandle, /* 90 */
  205.     excIntHandle,
  206.     excIntHandle,
  207.     excIntHandle,
  208.     excIntHandle,
  209.     excIntHandle,
  210.     excIntHandle,
  211.     excIntHandle,
  212.     excIntHandle,
  213.     excIntHandle,
  214.     excIntHandle, /* 100 */
  215.     excIntHandle,
  216.     excIntHandle,
  217.     excIntHandle,
  218.     excIntHandle,
  219.     excIntHandle,
  220.     excIntHandle,
  221.     excIntHandle,
  222.     excIntHandle,
  223.     excIntHandle,
  224.     excIntHandle, /* 110 */
  225.     excIntHandle,
  226.     excIntHandle,
  227.     excIntHandle,
  228.     excIntHandle,
  229.     excIntHandle,
  230.     excIntHandle,
  231.     excIntHandle,
  232.     excIntHandle,
  233.     excIntHandle,
  234.     excIntHandle, /* 120 */
  235.     excIntHandle,
  236.     excIntHandle,
  237.     excIntHandle,
  238.     excIntHandle,
  239.     excIntHandle,
  240.     excIntHandle,
  241.     excIntHandle,
  242.     excIntHandle,
  243.     excIntHandle,
  244.     excIntHandle, /* 130 */
  245.     excIntHandle,
  246.     excIntHandle,
  247.     excIntHandle,
  248.     excIntHandle,
  249.     excIntHandle,
  250.     excIntHandle,
  251.     excIntHandle,
  252.     excIntHandle,
  253.     excIntHandle,
  254.     excIntHandle, /* 140 */
  255.     excIntHandle,
  256.     excIntHandle,
  257.     excIntHandle,
  258.     excIntHandle,
  259.     excIntHandle,
  260.     excIntHandle,
  261.     excIntHandle,
  262.     excIntHandle,
  263.     excIntHandle,
  264.     excIntHandle, /* 150 */
  265.     excIntHandle,
  266.     excIntHandle,
  267.     excIntHandle,
  268.     excIntHandle,
  269.     excIntHandle,
  270.     excIntHandle,
  271.     excIntHandle,
  272.     excIntHandle,
  273.     excIntHandle,
  274.     excIntHandle, /* 160 */
  275.     excIntHandle,
  276.     excIntHandle,
  277.     excIntHandle,
  278.     excIntHandle,
  279.     excIntHandle,
  280.     excIntHandle,
  281.     excIntHandle,
  282.     excIntHandle,
  283.     excIntHandle,
  284.     excIntHandle, /* 170 */
  285.     excIntHandle,
  286.     excIntHandle,
  287.     excIntHandle,
  288.     excIntHandle,
  289.     excIntHandle,
  290.     excIntHandle,
  291.     excIntHandle,
  292.     excIntHandle,
  293.     excIntHandle,
  294.     excIntHandle, /* 180 */
  295.     excIntHandle,
  296.     excIntHandle,
  297.     excIntHandle,
  298.     excIntHandle,
  299.     excIntHandle,
  300.     excIntHandle,
  301.     excIntHandle,
  302.     excIntHandle,
  303.     excIntHandle,
  304.     excIntHandle, /* 190 */
  305.     excIntHandle,
  306.     excIntHandle,
  307.     excIntHandle,
  308.     excIntHandle,
  309.     excIntHandle,
  310.     excIntHandle,
  311.     excIntHandle,
  312.     excIntHandle,
  313.     excIntHandle,
  314.     excIntHandle, /* 200 */
  315.     excIntHandle,
  316.     excIntHandle,
  317.     excIntHandle,
  318.     excIntHandle,
  319.     excIntHandle,
  320.     excIntHandle,
  321.     excIntHandle,
  322.     excIntHandle,
  323.     excIntHandle,
  324.     excIntHandle, /* 210 */
  325.     excIntHandle,
  326.     excIntHandle,
  327.     excIntHandle,
  328.     excIntHandle,
  329.     excIntHandle,
  330.     excIntHandle,
  331.     excIntHandle,
  332.     excIntHandle,
  333.     excIntHandle,
  334.     excIntHandle, /* 220 */
  335.     excIntHandle,
  336.     excIntHandle,
  337.     excIntHandle,
  338.     excIntHandle,
  339.     excIntHandle,
  340.     excIntHandle,
  341.     excIntHandle,
  342.     excIntHandle,
  343.     excIntHandle,
  344.     excIntHandle, /* 230 */
  345.     excIntHandle,
  346.     excIntHandle,
  347.     excIntHandle,
  348.     excIntHandle,
  349.     excIntHandle,
  350.     excIntHandle,
  351.     excIntHandle,
  352.     excIntHandle,
  353.     excIntHandle,
  354.     excIntHandle, /* 240 */
  355.     excIntHandle,
  356.     excIntHandle,
  357.     excIntHandle,
  358.     excIntHandle,
  359.     excIntHandle,
  360.     excIntHandle,
  361.     excIntHandle,
  362.     excIntHandle,
  363.     excIntHandle,
  364.     excIntHandle, /* 250 */
  365.     excIntHandle,
  366.     excIntHandle,
  367.     excIntHandle,
  368.     excIntHandle,
  369.     excIntHandle, /* 255 */
  370.     };
  371. /*
  372. * sysExcVecInitHook - Initialized to NULL, but can be modified by a BSP 
  373. * prior to the call to excVecInit() to provide an alternate means of 
  374. * initializing the exception vectors.  This variable is placed in the
  375. * data segment rather than the BSS, because the BSP hook that is used
  376. * to set this variable is called before the BSS is cleared.
  377. */
  378. FUNCPTR sysExcVecInitHook = NULL;
  379. /*******************************************************************************
  380. *
  381. * excNormVecInit - initialize the normal exception vector.
  382. *
  383. * This routine loads the exception handler code for the normal exception 
  384. * vector into the address requested by the BSP.
  385. *
  386. * RETURNS: N/A
  387. */
  388. void excNormVecInit
  389.     (
  390.     void *vecAdrs
  391.     )
  392.     {
  393.     extern int excNormVec[]; /* instructions for branch to normal handler */
  394.     extern int excNormVecSize;
  395.     /* Load normal exception vector and invalidate instruction cache */
  396.     
  397.     bcopy ((const char *) excNormVec, (char *) vecAdrs, excNormVecSize);
  398.     cacheTextUpdate (vecAdrs, excNormVecSize);
  399.     }
  400. /*******************************************************************************
  401. *
  402. * excTlbVecInit - initialize the TLB exception vector.
  403. *
  404. * This routine loads the exception handler code for the TLB exception 
  405. * vector into the address requested by the BSP.
  406. *
  407. * RETURNS: N/A
  408. */
  409. void excTlbVecInit
  410.     (
  411.     void *vecAdrs
  412.     )
  413.     {
  414.     extern int excTlbVec[]; /* instructions for branch to TLB handler */
  415.     extern int excTlbVecSize;
  416.     /* Load tlb vector and invalidate instruction cache */
  417.     bcopy ((const char *) excTlbVec, (char *) vecAdrs, excTlbVecSize);
  418.     cacheTextUpdate (vecAdrs, excTlbVecSize);
  419.     }
  420. #ifndef _WRS_R3K_EXC_SUPPORT
  421. /*******************************************************************************
  422. *
  423. * excXtlbVecInit - initialize the XTLB exception vector.
  424. *
  425. * This routine loads the exception handler code for the XTLB exception 
  426. * vector into the address requested by the BSP.
  427. *
  428. * RETURNS: N/A
  429. */
  430. void excXtlbVecInit
  431.     (
  432.     void *vecAdrs
  433.     )
  434.     {
  435.     extern int excXtlbVec[]; /* instructions for branch to xtlb handler */
  436.     extern int excXtlbVecSize;
  437.     /* Load xtlb vector and invalidate instruction cache */
  438.     bcopy ((const char *) excXtlbVec, (char *) vecAdrs, excXtlbVecSize);
  439.     cacheTextUpdate (vecAdrs, excXtlbVecSize);
  440.     }
  441. /*******************************************************************************
  442. *
  443. * excCacheVecInit - initialize the cache exception vector.
  444. *
  445. * This routine loads the exception handler code for the cache exception 
  446. * vector into the address requested by the BSP.
  447. *
  448. * RETURNS: N/A
  449. */
  450. void excCacheVecInit
  451.     (
  452.     void *vecAdrs
  453.     )
  454.     {
  455.     extern int excCacheVec[]; /* instructions for branch to cache handler */
  456.     extern int excCacheVecSize;
  457.     /* Load cache exception vector and invalidate instruction cache */
  458.     bcopy ((const char *) excCacheVec, (char *) vecAdrs, excCacheVecSize);
  459.     cacheTextUpdate (vecAdrs, excCacheVecSize);
  460.     }
  461. #endif /* _WRS_R3K_EXC_SUPPORT */
  462. /*******************************************************************************
  463. *
  464. * excVecInit - initialize the exception/interrupt vectors
  465. *
  466. * This routine sets up the MIPS exception vectors to point to the 
  467. * appropriate default exception handlers.
  468. *
  469. * INTERNAL
  470. * The common exception handler excStub() is found in excALib.s.
  471. * WHEN TO CALL
  472. * This routine is usually called from the system start-up routine
  473. * usrInit() in usrConfig.c, before interrupts are enabled.
  474. *
  475. * RETURNS: OK (always).
  476. *
  477. * SEE ALSO: excLib
  478. */
  479. STATUS excVecInit (void)
  480.     {
  481.     extern int excNormVec[]; /* instructions for branch to normal handler */
  482.     extern int excNormVecSize;
  483.     extern int excTlbVec[]; /* instructions for branch to tlb handler */
  484.     extern int excTlbVecSize; /* instructions for branch to tlb handler */
  485. #ifndef _WRS_R3K_EXC_SUPPORT
  486.     extern int excXtlbVec[]; /* instructions for branch to xtlb handler */
  487.     extern int excXtlbVecSize; /* instructions for branch to xtlb handler */
  488.     extern int excCacheVec[]; /* instructions for branch to cache handler */
  489.     extern int excCacheVecSize; /* instructions for branch to cache handler */
  490. #endif /* _WRS_R3K_EXC_SUPPORT */
  491.     ULONG srValue; /* status register placeholder */
  492.     /* If available, use BSP-provided initialization function */
  493.     if (sysExcVecInitHook != NULL)
  494. {
  495. (*sysExcVecInitHook)();
  496. }
  497.     else
  498. {
  499. /* Load normal vector and invalidate instruction cache */
  500. bcopy ((const char *)excNormVec, (char *) E_VEC, excNormVecSize);
  501. cacheTextUpdate ((void *) E_VEC, excNormVecSize);
  502.     /* Load tlb vector and invalidate instruction cache */
  503. #ifdef _WRS_R3K_EXC_SUPPORT
  504. bcopy ((const char *)excTlbVec, (char *) UT_VEC, excTlbVecSize);
  505. cacheTextUpdate ((void *) UT_VEC, excTlbVecSize);
  506. #else /* !_WRS_R3K_EXC_SUPPORT */
  507. bcopy ((const char *)excTlbVec, (char *) T_VEC, excTlbVecSize);
  508. cacheTextUpdate ((void *) T_VEC, excTlbVecSize);
  509. #endif /* !_WRS_R3K_EXC_SUPPORT */
  510. #ifndef _WRS_R3K_EXC_SUPPORT
  511. /* Load xtlb vector and invalidate instruction cache */
  512. bcopy ((const char *)excXtlbVec, (char *) X_VEC, excXtlbVecSize);
  513. cacheTextUpdate ((void *) X_VEC, excXtlbVecSize);
  514. /* Load cache exception vector and invalidate instruction cache */
  515. bcopy ((const char *)excCacheVec, (char *) C_VEC, excCacheVecSize);
  516. cacheTextUpdate ((void *) C_VEC, excCacheVecSize);
  517. #endif /* _WRS_R3K_EXC_SUPPORT */
  518. }
  519.     /* Make the vectors usable by turning off rom based vectors */
  520.     srValue = intSRGet();
  521.     srValue &= ~SR_BEV;
  522.     intSRSet(srValue);
  523.     return (OK);
  524.     }
  525. /*******************************************************************************
  526. *
  527. * excExcHandle - interrupt level handling of exceptions
  528. *
  529. * This routine handles exception traps. It is never be called except 
  530. * from the special assembly language interrupt stub routine.
  531. *
  532. * It prints out a bunch of pertinent information about the trap that
  533. * occurred via excTask.
  534. *
  535. * Note that this routine runs in the context of the task that got the exception.
  536. *
  537. * NOMANUAL
  538. */
  539. void excExcHandle
  540.     (
  541.     int vecNum, /* exception vector number */
  542.     ESFMIPS * pEsf, /* pointer to exception stack frame */
  543.     REG_SET * pRegs  /* pointer to general regs on esf */
  544.     )
  545.     {
  546.     EXC_INFO excInfo;
  547.     int esfSize;
  548. #ifdef _WRS_R3K_EXC_SUPPORT
  549.     /* restore old sr so it looks like an rfe occured thus allowing interrupts*/ 
  550.     pEsf->esfRegs.sr = (pEsf->esfRegs.sr & ~(SR_KUP|SR_IEP|SR_KUC|SR_IEC)) |
  551.        ((pEsf->esfRegs.sr & 
  552. (SR_KUO|SR_IEO|SR_KUP|SR_IEP|SR_KUC|SR_IEC)) >> 2);
  553. #else
  554.     /* restore old sr so it looks like an eret occured */ 
  555.     pEsf->esfRegs.sr &= ~SR_EXL;
  556. #endif
  557.     esfSize = excGetInfoFromESF (vecNum, pEsf, &excInfo);
  558.     /* fix task stack pointer and registers */
  559.     pRegs->sr    = pEsf->esfRegs.sr;
  560.     if ((_func_excBaseHook != NULL) && /* user hook around? */
  561. ((* _func_excBaseHook) (vecNum, pEsf, pRegs, &excInfo)))
  562. return; /* user hook fixed it */
  563. #ifdef WV_INSTRUMENTATION
  564.     /* windview - level 3 event logging */
  565.     EVT_CTX_1(EVENT_EXCEPTION, vecNum);
  566. #endif /* WV_INSTRUMENTATION */
  567.     if (INT_CONTEXT ())
  568. {
  569. if (_func_excPanicHook != NULL) /* panic hook? */
  570.     (*_func_excPanicHook) (vecNum, pEsf, pRegs, &excInfo);
  571. reboot (BOOT_WARM_AUTOBOOT);
  572. return; /* reboot returns?! */
  573. }
  574.     /* task caused exception */
  575.     taskIdCurrent->pExcRegSet = pRegs; /* for taskRegs[GS]et */
  576.     taskIdDefault ((int)taskIdCurrent); /* update default tid */
  577.     bcopy ((char *) &excInfo, (char *) &(taskIdCurrent->excInfo),
  578.    sizeof (EXC_INFO)); /* copy in exc info */
  579.     if (_func_sigExcKill != NULL)
  580. _func_sigExcKill((int) vecNum, vecNum, pRegs);
  581.     if (_func_excInfoShow != NULL) /* default show rtn? */
  582. (*_func_excInfoShow) (&excInfo, TRUE);
  583.     if (excExcepHook != NULL)
  584. (* excExcepHook) (taskIdCurrent, vecNum, pEsf);
  585.     taskSuspend (0); /* whoa partner... */
  586.     taskIdCurrent->pExcRegSet = (REG_SET *) NULL; /* invalid after rts */
  587.     }
  588. /*****************************************************************************
  589. *
  590. * excBreakTypeGet - Get break type number from break instruction.
  591. *
  592. * RETURNS: break instruction type
  593. */
  594. uint16_t excBreakTypeGet
  595.     (
  596.     ESFMIPS *pEsf /* pointer to Exception Stack Frame */
  597.     )
  598.     {
  599.     uint32_t epc;       /* Exception Program Counter Register */
  600.     uint32_t *pInst32;  /* epc typed as a pointer to a 32-bit instruction */
  601. #ifdef _WRS_MIPS16
  602.     uint16_t *pInst16;  /* epc typed as a pointer to a 16-bit instruction */
  603. #endif
  604.     uint16_t breakType; /* returned break type */
  605.     
  606.     epc = (uint32_t) pEsf->esfRegs.pc;
  607.     /*
  608.      * Determine type of BREAK exception by examining the BREAK instruction.
  609.      * If the breaked instruction is a branch delay slot, then the pc is the
  610.      * address of the preceding jump or branch instruction. In this case, the
  611.      * instruction at pc + 1 must be examined.
  612.      *
  613.      * For MIPS16 CPU, check the EPC for 16-bit ISA Mode, and retrieve the
  614.      * break exception type from the 16-bit break instruction. In this case,
  615.      * there is no branch delay slot.
  616.      */
  617. #ifdef _WRS_MIPS16
  618.     /* If executing in 16-bit instruction mode then decode 16-bit break
  619.      * instruction. Else decode 32-bit break instruction.
  620.      */
  621.     if (epc & EPC_EIM)
  622. {
  623. /* Executing in 16-bit instruction mode on a MIPS16.
  624.  * There is no branch delay slot in 16-bit ISA mode.
  625.  */
  626. pInst16 = (uint16_t *) (epc & EPC_PC);
  627. breakType = (*pInst16 & BREAK16_CODE_MASK) >> BREAK16_CODE_POS;
  628. }
  629.     else 
  630. { /* Executing in 32-bit instruction mode on a MIPS16*/
  631. pInst32 = (uint32_t *) epc;
  632. if (pEsf->cause & CAUSE_BD) /* Branch Delay Slot */
  633.     pInst32++;
  634. breakType = (uint16_t) ((*pInst32 & BREAK_CODE_MASK) >> BREAK_CODE_POS);
  635. }
  636.     
  637. #else /* !_WRS_MIPS16 */
  638.     
  639.     pInst32 = (uint32_t *) epc;
  640.     if (pEsf->cause & CAUSE_BD) /* Branch Delay Slot */
  641. pInst32++;
  642.     
  643.     breakType = (uint16_t) ((*pInst32 & BREAK_CODE_MASK) >> BREAK_CODE_POS);
  644.     
  645. #endif /* _WRS_MIPS16 */
  646.     return (breakType);
  647.     }
  648. /*******************************************************************************
  649. *
  650. * excIntHandle - interrupt level handling of interrupts
  651. *
  652. * This routine handles interrupts. It is never be called except 
  653. * from the special assembly language interrupt stub routine.
  654. *
  655. * It prints out a bunch of pertinent information about the trap that
  656. * occurred via excTask.
  657. */
  658. LOCAL void excIntHandle
  659.     (
  660.     int vecNum, /* exception vector number */
  661.     ESFMIPS * pEsf  /* pointer to exception stack frame */
  662.     )
  663.     {
  664.     USHORT eid = 0; /* clear data bus interrupt */
  665.     int result; /* unacked ints return value */
  666. #ifdef WV_INSTRUMENTATION
  667.     /* windview - level 3 event logging */
  668.     EVT_CTX_1(EVENT_EXCEPTION, vecNum);
  669. #endif /* WV_INSTRUMENTATION */
  670.     if ((vecNum <= HIGH_VEC) && (vecNum >= LOW_VEC))
  671. {
  672. result = sysAutoAck(vecNum); /* clear interrupt condition */
  673.         if (vecNum == IV_BUS_ERROR_VEC)
  674.     eid = (USHORT) result; /* result of data bus interrupt */
  675.     
  676.         if ((vecNum <= IV_FPA_PREC_VEC) && (vecNum >= IV_FPA_UNIMP_VEC))
  677.             pEsf->fpcsr = result; /* result of fpa interrupt */
  678. }
  679.     if (_func_excIntHook != NULL)
  680. (*_func_excIntHook) (vecNum, pEsf, eid);
  681.     }
  682. /*****************************************************************************
  683. *
  684. * excGetInfoFromESF - get relevent info from exception stack frame
  685. *
  686. * RETURNS: size of specified ESF
  687. */
  688. LOCAL int excGetInfoFromESF
  689.     (
  690.     FAST int vecNum,
  691.     FAST ESFMIPS *pEsf,
  692.     EXC_INFO *pExcInfo 
  693.     )
  694.     {
  695.     pExcInfo->vecNum = vecNum;
  696.     pExcInfo->valid  = EXC_VEC_NUM;
  697.     if (( vecNum == IV_TLBMOD_VEC ) || (vecNum == IV_TLBL_VEC ) ||
  698.         (vecNum == IV_TLBS_VEC ) || (vecNum == IV_ADEL_VEC ) ||
  699.         (vecNum == IV_ADES_VEC ))
  700.         {
  701. /* Its an address error , or tlb miss */
  702. pExcInfo->valid     |= EXC_EPC | EXC_STATUS_REG | EXC_ACCESS_ADDR |
  703.        EXC_CAUSE_REG ;
  704. pExcInfo->epc        = ((ESFMIPS *)pEsf)->esfRegs.pc;
  705. pExcInfo->statusReg  = ((ESFMIPS *)pEsf)->esfRegs.sr;
  706. pExcInfo->causeReg   = ((ESFMIPS *)pEsf)->cause;
  707. pExcInfo->badVa      = ((ESFMIPS *)pEsf)->badva;
  708. return (sizeof (ESFMIPS));
  709. }
  710.     else if ( (vecNum == IV_IBUS_VEC ) || (vecNum == IV_DBUS_VEC ))
  711.         {
  712. /* Its a bus error */
  713. pExcInfo->valid     |= EXC_EPC | EXC_STATUS_REG | 
  714.        EXC_CAUSE_REG | EXC_ERROR_ADDR ;
  715. pExcInfo->epc        = ((ESFMIPS *)pEsf)->esfRegs.pc;
  716. pExcInfo->statusReg  = ((ESFMIPS *)pEsf)->esfRegs.sr;
  717. pExcInfo->causeReg   = ((ESFMIPS *)pEsf)->cause;
  718. pExcInfo->ear        = sysBusEar();
  719. pExcInfo->eid        = sysBusEid();
  720. return (sizeof (ESFMIPS));
  721. }
  722.     else if ((vecNum <= IV_FPA_PREC_VEC) && (vecNum >= IV_FPA_UNIMP_VEC))
  723.         {
  724. /* Its a floating point error */
  725. pExcInfo->valid     |= EXC_EPC | EXC_STATUS_REG |
  726.        EXC_CAUSE_REG | EXC_FP_STATUS_REG ;
  727. pExcInfo->epc        = ((ESFMIPS *)pEsf)->esfRegs.pc;
  728. pExcInfo->statusReg  = ((ESFMIPS *)pEsf)->esfRegs.sr;
  729. pExcInfo->causeReg   = ((ESFMIPS *)pEsf)->cause;
  730. pExcInfo->fpcsr      = ((ESFMIPS *)pEsf)->fpcsr;
  731. return (sizeof (ESFMIPS));
  732. }
  733. #ifdef EXC_BREAK_TYPE    
  734.     else if (vecNum == IV_BP_VEC)
  735. {
  736. pExcInfo->valid    |= EXC_EPC | EXC_STATUS_REG | EXC_CAUSE_REG
  737.                       | EXC_BREAK_TYPE;
  738. pExcInfo->epc       = ((ESFMIPS *)pEsf)->esfRegs.pc;
  739. pExcInfo->statusReg = ((ESFMIPS *)pEsf)->esfRegs.sr;
  740. pExcInfo->causeReg  = ((ESFMIPS *)pEsf)->cause;
  741. pExcInfo->breakType = excBreakTypeGet(pEsf);
  742. return (sizeof (ESFMIPS));
  743. }
  744. #endif
  745.     else
  746. {
  747. pExcInfo->valid    |= EXC_EPC | EXC_STATUS_REG | EXC_CAUSE_REG;
  748. pExcInfo->epc       = ((ESFMIPS *)pEsf)->esfRegs.pc;
  749. pExcInfo->statusReg = ((ESFMIPS *)pEsf)->esfRegs.sr;
  750. pExcInfo->causeReg  = ((ESFMIPS *)pEsf)->cause;
  751. return (sizeof (ESFMIPS));
  752. }
  753.     }
  754. #if 0
  755. /*******************************************************************************
  756. *
  757. * programError - determine if exception is program error
  758. *
  759. * RETURNS:
  760. *   TRUE if exception indicates program error,
  761. *   FALSE if hardware interrupt or failure.
  762. */
  763. LOCAL BOOL programError
  764.     (
  765.     int vecNum  /* exception vector number */
  766.     )
  767.     {
  768.     return (((vecNum < USER_VEC_START) && 
  769.             ((vecNum != IV_SYSCALL_VEC) && (vecNum != IV_BP_VEC))) || 
  770.              (vecNum == IV_BUS_ERROR_VEC) ); 
  771.     }
  772. #endif