1/** 2 * \file 3 * \brief Exception handling. 4 */ 5 6/* 7 * Copyright (c) 2011, ETH Zurich. 8 * All rights reserved. 9 * 10 * This file is distributed under the terms in the attached LICENSE file. 11 * If you do not find this file, copies can be found by writing to: 12 * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group. 13 */ 14 15#ifndef LIBBARRELFISH_EXCEPT_H 16#define LIBBARRELFISH_EXCEPT_H 17 18#include <sys/cdefs.h> 19#include <barrelfish_kpi/registers_arch.h> 20 21__BEGIN_DECLS 22 23enum exception_type { 24 EXCEPT_NULL = 0, 25 EXCEPT_PAGEFAULT, ///< Page fault (or other memory access fault) 26 EXCEPT_BREAKPOINT, ///< Software breakpoint 27 EXCEPT_SINGLESTEP, ///< Single-step execution 28 // TODO: illegal instruction, divide by zero, etc. 29 EXCEPT_OTHER 30}; 31 32/// Subtype for page fault exceptions 33enum pagefault_exception_type { 34 PAGEFLT_NULL = 0, 35 PAGEFLT_READ, ///< Read page fault 36 PAGEFLT_WRITE, ///< Write page fault 37 PAGEFLT_EXEC, ///< Execute (instruction fetch) page fault 38}; 39 40/** 41 * \brief Exception handler function 42 * 43 * \param type Exception type 44 * \param subtype Exception subtype 45 * \param addr Exception address 46 * \param regs Register state at time of exception 47 * \param fpuregs FPU state at time of exception. NULL if unused. 48 * 49 * \return If this function returns, the register state specified in 50 * regs/fpuregs will be resumed. 51 */ 52typedef void (*exception_handler_fn)(enum exception_type type, int subtype, 53 void *addr, arch_registers_state_t *regs); 54 55errval_t thread_set_exception_handler(exception_handler_fn newhandler, 56 exception_handler_fn *oldhandler, 57 void *new_stack_base, void *new_stack_top, 58 void **old_stack_base, void **old_stack_top); 59 60__END_DECLS 61 62#endif 63