/*
 * U-boot - ints.c Interrupt related routines
 *
 * Copyright (c) 2005-2007 Analog Devices Inc.
 *
 * This file is based on ints.c
 *
 * Apr18 2003, Changed by HuTao to support interrupt cascading for Blackfin
 *	drivers
 *
 * Copyright 1996 Roman Zippel
 * Copyright 1999 D. Jeff Dionne <jeff@uclinux.org>
 * Copyright 2000-2001 Lineo, Inc. D. Jefff Dionne <jeff@lineo.ca>
 * Copyright 2002 Arcturus Networks Inc. MaTed <mated@sympatico.ca>
 * Copyright 2003 Metrowerks/Motorola
 *
 * (C) Copyright 2000-2004
 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
 *
 * See file CREDITS for list of people who contributed to this
 * project.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
 * MA 02110-1301 USA
 */

#include <common.h>
#include <linux/stddef.h>
#include <asm/system.h>
#include <asm/traps.h>
#include <asm/io.h>
#include <asm/errno.h>
#include <asm/blackfin.h>
#include "cpu.h"

void blackfin_irq_panic(int reason, struct pt_regs *regs)
{
	printf("\n\nException: IRQ 0x%x entered\n", reason);
	printf("code=[0x%x], ", (unsigned int)(regs->seqstat & 0x3f));
	printf("stack frame=0x%x, ", (unsigned int)regs);
	printf("bad PC=0x%04x\n", (unsigned int)regs->pc);
	dump(regs);
	printf("Unhandled IRQ or exceptions!\n");
	printf("Please reset the board \n");
}

void blackfin_init_IRQ(void)
{
	*(unsigned volatile long *)(SICA_IMASK0) = 0;
#ifndef CONFIG_KGDB
	*(unsigned volatile long *)(EVT1) = 0x0;
#endif
	*(unsigned volatile long *)(EVT2) =
	    (unsigned volatile long)evt_nmi;
	*(unsigned volatile long *)(EVT3) =
	    (unsigned volatile long)trap;
	*(unsigned volatile long *)(EVT5) =
	    (unsigned volatile long)evt_ivhw;
	*(unsigned volatile long *)(EVT0) =
	    (unsigned volatile long)evt_rst;
	*(unsigned volatile long *)(EVT6) =
	    (unsigned volatile long)evt_timer;
	*(unsigned volatile long *)(EVT7) =
	    (unsigned volatile long)evt_evt7;
	*(unsigned volatile long *)(EVT8) =
	    (unsigned volatile long)evt_evt8;
	*(unsigned volatile long *)(EVT9) =
	    (unsigned volatile long)evt_evt9;
	*(unsigned volatile long *)(EVT10) =
	    (unsigned volatile long)evt_evt10;
	*(unsigned volatile long *)(EVT11) =
	    (unsigned volatile long)evt_evt11;
	*(unsigned volatile long *)(EVT12) =
	    (unsigned volatile long)evt_evt12;
	*(unsigned volatile long *)(EVT13) =
	    (unsigned volatile long)evt_evt13;
	*(unsigned volatile long *)(EVT14) =
	    (unsigned volatile long)evt_system_call;
	*(unsigned volatile long *)(EVT15) =
	    (unsigned volatile long)evt_soft_int1;
	*(volatile unsigned long *)ILAT = 0;
	asm("csync;");
	*(volatile unsigned long *)IMASK = 0xffbf;
	asm("csync;");
}

void exception_handle(void)
{
#if defined (CONFIG_PANIC_HANG)
	display_excp();
#else
	udelay(100000);		/* allow messages to go out */
	do_reset(NULL, 0, 0, NULL);
#endif
}

void display_excp(void)
{
	printf("Exception!\n");
}