Subversion Repositories HelenOS

Rev

Rev 2235 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1.     /*
  2.  * Copyright (c) 2007 Petr Stepan
  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. /** @addtogroup arm32
  30.  * @{
  31.  */
  32. /** @file
  33.     @brief  Exception handlers and exception initialization routines.
  34.  */
  35.  
  36. #include <arch/exception.h>
  37. #include "aux_print/printf.h"
  38. #include <arch/memstr.h>
  39.  
  40. #define PREFETCH_OFFSET     0x8
  41. #define BRANCH_OPCODE       0xea000000
  42. #define VALID_BRANCH_MASK   0xff000000
  43.  
  44. /** Updates specified exception vector to jump to given handler.
  45. */
  46. static void install_handler (unsigned* handler, unsigned* vector) {
  47.     volatile unsigned vec;
  48.    
  49.     /* calculate relative distance */
  50.     vec = ((unsigned)handler - (unsigned)vector - PREFETCH_OFFSET);
  51.    
  52.     /* word offset */
  53.     vec >>= 2;
  54.    
  55.     /* check if haven't jumped beyond 32 MB */
  56.     if ((vec & VALID_BRANCH_MASK) != 0) {
  57.         /*panic("exception handler beyond 32MB.");*/
  58.         return;
  59.     }
  60.    
  61.     /* make it branch instruction */
  62.     vec |= BRANCH_OPCODE;
  63.     *vector = vec;
  64.    
  65.     aux_printf("installed  handler to %p, to vector %p\n.", handler, vector);
  66. }
  67.  
  68. /* TODO add other exception handlers */
  69. static void dummy_exception(){
  70.     asm("bkpt");
  71. }
  72.  
  73. /** IRQ Exception handler */
  74. static void irq_exception(){
  75.     asm("bkpt");
  76. }
  77.  
  78. /** Fills exception vectors with appropriate exception handlers.
  79. */
  80. void install_exception_handlers(void) {
  81.     install_handler((unsigned*)dummy_exception, (unsigned*)EXC_RESET_VEC);
  82.     install_handler((unsigned*)dummy_exception, (unsigned*)EXC_UNDEF_INSTR_VEC);
  83.     install_handler((unsigned*)dummy_exception, (unsigned*)EXC_SWI_VEC);
  84.     install_handler((unsigned*)dummy_exception, (unsigned*)EXC_PREFETCH_ABORT_VEC);
  85.     install_handler((unsigned*)dummy_exception, (unsigned*)EXC_DATA_ABORT_VEC);
  86.     install_handler((unsigned*)irq_exception,   (unsigned*)EXC_IRQ_VEC);
  87.     install_handler((unsigned*)dummy_exception, (unsigned*)EXC_FIQ_VEC);
  88. }
  89.  
  90. /** Registers exceptions and their handlers to kernel exception dispatcher. */
  91. void exception_init(void){
  92.     /* TODO */
  93. }
  94.  
  95. /** @}
  96.  */
  97.