/*
 * exception.h
 *
 * Copyright (C) 2015 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef _EXCEPTION_H_
#define _EXCEPTION_H_

#define __MONOLITIHUM_KERNEL_MODE__

#include <common.h>
#include <interrupt.h>
#include <sdk/exception.h>
#include <thread.h>

#define KERNEL_CRASH(message) kernel_crash((message), NULL, __FILE__, __LINE__)
#define KERNEL_CRASH_WITH_REGS(message, regs) kernel_crash((message), (regs), __FILE__, __LINE__)
#define ASSERT(test) (test) ? 0 : KERNEL_CRASH("Assertion \"" #test "\" failed");

extern void __attribute__((noreturn)) exception_return(registers_t regs);
extern int __attribute__((returns_twice)) save_kernel_handler(exception_handler_t *old_handler);

void __attribute__((noreturn)) kernel_crash(const char *message, registers_t *regs, const char *filename, int line);
void exceptions_init();

#endif
