Furquan Shaikh | 2af76f4 | 2014-04-28 16:39:40 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the libpayload project. |
| 3 | * |
| 4 | * Copyright 2013 Google Inc. |
| 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions |
| 8 | * are met: |
| 9 | * 1. Redistributions of source code must retain the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer. |
| 11 | * 2. 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 | * 3. 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 AND CONTRIBUTORS ``AS IS'' AND |
| 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
| 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 27 | * SUCH DAMAGE. |
| 28 | */ |
| 29 | |
| 30 | #ifndef _ARCH_EXCEPTION_H |
| 31 | #define _ARCH_EXCEPTION_H |
| 32 | |
Aaron Durbin | 4f89d97 | 2014-09-16 22:23:57 -0500 | [diff] [blame] | 33 | #include <arch/transition.h> |
| 34 | |
Aaron Durbin | cc17576 | 2014-08-27 16:45:12 -0500 | [diff] [blame] | 35 | /* Initialize the exception handling on the current CPU. */ |
Furquan Shaikh | 2af76f4 | 2014-04-28 16:39:40 -0700 | [diff] [blame] | 36 | void exception_init(void); |
Furquan Shaikh | 2af76f4 | 2014-04-28 16:39:40 -0700 | [diff] [blame] | 37 | |
Julius Werner | 66a476a | 2015-10-12 16:45:21 -0700 | [diff] [blame^] | 38 | /* Initialize VBAR and SP_EL3. */ |
| 39 | void exception_init_asm(void *exception_stack_end); |
| 40 | |
Aaron Durbin | 4f89d97 | 2014-09-16 22:23:57 -0500 | [diff] [blame] | 41 | /* |
| 42 | * Order matters for handling return values. The larger the value the higher |
| 43 | * the precedence. |
| 44 | */ |
| 45 | enum { |
| 46 | EXC_RET_IGNORED, |
| 47 | EXC_RET_ABORT, |
| 48 | EXC_RET_HANDLED, |
| 49 | EXC_RET_HANDLED_DUMP_STATE, |
| 50 | }; |
| 51 | |
| 52 | struct exception_handler { |
| 53 | int (*handler)(struct exc_state *state, uint64_t vector_id); |
| 54 | struct exception_handler *next; |
| 55 | }; |
| 56 | |
| 57 | |
| 58 | /* |
| 59 | * Register a handler provided with the associated vector id. Returns 0 on |
| 60 | * sucess, < 0 on error. Note that registration is not thread/interrupt safe. |
| 61 | */ |
| 62 | int exception_handler_register(uint64_t vid, struct exception_handler *h); |
| 63 | |
| 64 | /* |
| 65 | * Unregister a handler from the vector id. Return 0 on success, < 0 on error. |
| 66 | * Note that the unregistration is not thread/interrupt safe. |
| 67 | */ |
| 68 | int exception_handler_unregister(uint64_t vid, struct exception_handler *h); |
| 69 | |
Furquan Shaikh | 2af76f4 | 2014-04-28 16:39:40 -0700 | [diff] [blame] | 70 | #endif |