/*
    Exception.h, Copyright (c) by Silvio Dragone & David Reist,
    Swiss Federal Institute of Technology,
    Computer Engineering and Networks Laboratory.
 
    TOPSY -- A Teachable Operating System.
             Implementation of a tiny and simple
             micro kernel for teaching purposes.
 
    For further information, please visit http://www.tik.ee.ethz.ch/~topsy
 
    This software is provided under the terms of the GNU General Public Licence.
 
    A full copy of the GNU GPL is provided in the file COPYING found in the 
    development root of Topsy.
*/

#ifndef _EXCEPTION_H_
#define _EXCEPTION_H_

#include "cpu.h"

#define CAUSE_IP_MASK 0x1fc
#define CAUSE_IP_SHIFT 0x02

typedef enum { // FIQ Identities
  MBZ_F   = -1,  // Must be zero
  UART_F  = 6,  // FIQ interrupt generated by the UART
  SDRAM_F = 5,  // FIQ interrupt generated by SDRAM Unit
  RTC_F   = 4,  // FIQ interrupt generated by the Real Time Clock
  SRAM_F  = 3,  // FIQ interrupt generated by SRAM Unit
  UENG_F  = 2,  // FIQ interrupt generated by one of the 24 Microengine threads
  CINT_F  = 1,  // FIQ interrupt generated by a device on the CINT pin
  PCI_F   = 0,  // FIQ interrupt generated by the PCI Unit
  // IRQ Identities
  MBZ_I   = -1,  // Must be zero
  UART_I  = 6,  // IRQ interrupt generated by the UART
  SDRAM_I = 5,  // IRQ interrupt generated by SDRAM Unit
  RTC_I   = 4,  // IRQ interrupt generated by the Real Time Clock
  SRAM_I  = 3,  // IRQ interrupt generated by SRAM Unit
  UENG_I  = 2,  // IRQ interrupt generated by one of the 24 Microengine threads
  CINT_I  = 1,  // IRQ interrupt generated by a device on the CINT pin
  PCI_I   = 0   // IRQ interrupt generated by the PCI Unit
} InterruptId;

/* defined in cpu.h */
typedef enum {
  RESET = EXC_RESET,
  UNDEF_INSTR = EXC_UNDEF_INSTR,
  SOFT_INTR = EXC_SOFT_INTR,
  ABORT_PREFETCH = EXC_ABORT_PREFETCH,
  ABORT_DATA = EXC_ABORT_DATA,
  IRQ_INTR = EXC_IRQ_INTR,
  FIQ_INTR = EXC_FIQ_INTR
} ExceptionId;

/* Undefined instructions exception handler */
extern void UND_exception(void);

/* Prefetch abort (instruction fetch memory abort) exception handler */
extern void APF_exception(void);

/* Data abort (data access memory abort) exception handler */
extern void ADA_exception(void);


/* [SD] Experiment!! */
extern void dummyMBZ(void);
extern void dummyUART(void);
extern void dummySDRAM(void);
extern void dummyRTC(void);
extern void dummySRAM(void);
extern void dummyUENG(void);
extern void dummyCINT(void);
extern void dummyPCI(void);

#endif
