Subversion Repositories HelenOS-historic

Rev

Rev 227 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright (C) 2001-2004 Jakub Jermar
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  *
  9.  * - Redistributions of source code must retain the above copyright
  10.  *   notice, this list of conditions and the following disclaimer.
  11.  * - Redistributions in binary form must reproduce the above copyright
  12.  *   notice, this list of conditions and the following disclaimer in the
  13.  *   documentation and/or other materials provided with the distribution.
  14.  * - The name of the author may not be used to endorse or promote products
  15.  *   derived from this software without specific prior written permission.
  16.  *
  17.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  18.  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  19.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  20.  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  21.  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  22.  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  23.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  24.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26.  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27.  */
  28.  
  29. #include <arch/exception.h>
  30. #include <arch/interrupt.h>
  31. #include <panic.h>
  32. #include <arch/cp0.h>
  33. #include <arch/types.h>
  34. #include <arch.h>
  35. #include <debug.h>
  36.  
  37. void exception(void)
  38. {
  39.     int excno;
  40.     __u32 epc;
  41.     __u32 epc_shift = 0;
  42.  
  43.     ASSERT(CPU != NULL);
  44.  
  45.     /*
  46.      * NOTE ON OPERATION ORDERING
  47.      *
  48.      * On entry, cpu_priority_high() must be called before exception bit is cleared.
  49.      * On exit, exception bit must be set before cpu_priority_restore() is called.
  50.      */
  51.  
  52.     cpu_priority_high();
  53.     epc = cp0_epc_read();
  54.     cp0_status_write(cp0_status_read() & ~ (cp0_status_exl_exception_bit |
  55.                         cp0_status_um_bit));
  56.  
  57.     if (THREAD) {
  58.         THREAD->saved_epc = epc;
  59.     }
  60.     /* decode exception number and process the exception */
  61.     switch (excno = (cp0_cause_read() >> 2) & 0x1f) {
  62.         case EXC_Int:
  63.             interrupt();
  64.             break;
  65.         case EXC_TLBL:
  66.         case EXC_TLBS:
  67.             tlb_invalid();
  68.             break;
  69.         case EXC_Mod:
  70.             panic("unhandled TLB Modification Exception\n");
  71.             break;
  72.         case EXC_AdEL:
  73.             panic("unhandled Address Error Exception - load or instruction fetch\n");
  74.             break;
  75.         case EXC_AdES:
  76.             panic("unhandled Address Error Exception - store\n");
  77.             break;
  78.         case EXC_IBE:
  79.             panic("unhandled Bus Error Exception - fetch instruction\n");
  80.             break;
  81.         case EXC_DBE:
  82.             panic("unhandled Bus Error Exception - data reference: load or store\n");
  83.             break;
  84.         case EXC_Bp:
  85.             /* it is necessary to not re-execute BREAK instruction after returning from Exception handler
  86.                (see page 138 in R4000 Manual for more information) */
  87.             epc_shift = 4;
  88.             break;
  89.         case EXC_RI:
  90.             panic("unhandled Reserved Instruction Exception\n");
  91.             break;
  92.         case EXC_CpU:
  93.             panic("unhandled Coprocessor Unusable Exception\n");
  94.             break;
  95.         case EXC_Ov:
  96.             panic("unhandled Arithmetic Overflow Exception\n");
  97.             break;
  98.         case EXC_Tr:
  99.             panic("unhandled Trap Exception\n");
  100.             break;
  101.         case EXC_VCEI:
  102.             panic("unhandled Virtual Coherency Exception - instruction\n");
  103.             break;
  104.         case EXC_FPE:
  105.             panic("unhandled Floating-Point Exception\n");
  106.             break;
  107.         case EXC_WATCH:
  108.             panic("unhandled reference to WatchHi/WatchLo address\n");
  109.             break;
  110.         case EXC_VCED:
  111.             panic("unhandled Virtual Coherency Exception - data\n");
  112.             break;
  113.         default:
  114.             panic("unhandled exception %d\n", excno);
  115.     }
  116.    
  117.     if (THREAD)
  118.         epc = THREAD->saved_epc;
  119.    
  120.     /* Raise EXL bit before epc_write, so that we support
  121.      * properly nested exceptions
  122.      */
  123.     cp0_status_write(cp0_status_read() | cp0_status_exl_exception_bit);
  124.     cp0_epc_write(epc + epc_shift);
  125. }
  126.