OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [bootloaders/] [orpmon/] [drivers/] [int.c] - Diff between revs 406 and 419

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 406 Rev 419
/* This file is part of test microkernel for OpenRISC 1000. */
/* This file is part of test microkernel for OpenRISC 1000. */
/* (C) 2001 Simon Srot, srot@opencores.org */
/* (C) 2001 Simon Srot, srot@opencores.org */
 
 
#include "common.h"
#include "common.h"
#include "support.h"
#include "support.h"
#include "spr-defs.h"
#include "spr-defs.h"
#include "int.h"
#include "int.h"
 
 
#ifdef OR1K
#ifdef OR1K
 
 
/* Interrupt handlers table */
/* Interrupt handlers table */
struct ihnd int_handlers[MAX_INT_HANDLERS];
struct ihnd int_handlers[MAX_INT_HANDLERS];
 
 
/* Initialize routine */
/* Initialize routine */
int int_init()
int int_init()
{
{
  int i;
  int i;
 
 
  for(i = 0; i < MAX_INT_HANDLERS; i++) {
  for(i = 0; i < MAX_INT_HANDLERS; i++) {
    int_handlers[i].handler = 0;
    int_handlers[i].handler = 0;
  }
  }
 
 
  return 0;
  return 0;
}
}
 
 
/* Add interrupt handler */
/* Add interrupt handler */
int int_add(unsigned long vect, void (* handler)(void))
int int_add(unsigned long vect, void (* handler)(void))
{
{
  if(vect >= MAX_INT_HANDLERS) return -1;
  if(vect >= MAX_INT_HANDLERS) return -1;
 
 
  int_handlers[vect].handler = handler;
  int_handlers[vect].handler = handler;
  debug ("int_add %i: %08lx\n", vect, int_handlers[vect].handler);
  debug ("int_add %i: %08lx\n", vect, int_handlers[vect].handler);
 
 
  mtspr(SPR_PICMR, mfspr(SPR_PICMR) | (0x00000001L << vect));
  mtspr(SPR_PICMR, mfspr(SPR_PICMR) | (0x00000001L << vect));
  return 0;
  return 0;
}
}
 
 
/* Disable interrupt */
/* Disable interrupt */
int int_disable(unsigned long vect)
int int_disable(unsigned long vect)
{
{
  if(vect >= MAX_INT_HANDLERS) return -1;
  if(vect >= MAX_INT_HANDLERS) return -1;
 
 
  mtspr(SPR_PICMR, mfspr(SPR_PICMR) & ~(0x00000001L << vect));
  mtspr(SPR_PICMR, mfspr(SPR_PICMR) & ~(0x00000001L << vect));
 
 
  return 0;
  return 0;
}
}
 
 
/* Enable interrupt */
/* Enable interrupt */
int int_enable(unsigned long vect)
int int_enable(unsigned long vect)
{
{
  if(vect >= MAX_INT_HANDLERS) return -1;
  if(vect >= MAX_INT_HANDLERS) return -1;
 
 
  mtspr(SPR_PICMR, mfspr(SPR_PICMR) | (0x00000001L << vect));
  mtspr(SPR_PICMR, mfspr(SPR_PICMR) | (0x00000001L << vect));
 
 
  return 0;
  return 0;
}
}
 
 
/* Main interrupt handler */
/* Main interrupt handler */
void int_main(void)
void int_main(void)
{
{
  unsigned long picsr = mfspr(SPR_PICSR);
  unsigned long picsr = mfspr(SPR_PICSR);
  unsigned long i = 0;
  unsigned long i = 0;
 
 
  mtspr(SPR_PICSR, 0);
  mtspr(SPR_PICSR, 0);
  //printf ("int :%08lx\n", picsr);
  //printf ("int :%08lx\n", picsr);
 
 
  while(i < 32) {
  while(i < 32) {
    if((picsr & (0x01L << i)) && (int_handlers[i].handler != 0)) {
    if((picsr & (0x01L << i)) && (int_handlers[i].handler != 0)) {
      (*int_handlers[i].handler)();
      (*int_handlers[i].handler)();
      mtspr(SPR_PICSR, mfspr(SPR_PICSR) & ~(0x00000001L << i));
      mtspr(SPR_PICSR, mfspr(SPR_PICSR) & ~(0x00000001L << i));
    }
    }
    i++;
    i++;
  }
  }
}
}
 
 
 
 
void
void
int_error(int vect)
int_error(int vect, unsigned long epcr)
{
{
  printf("\n\nERROR - ");
  printf("\n\nERROR - ");
  switch(vect)
  switch(vect)
    {
    {
    case 2:
    case 2:
      printf("BUS ERROR (0x200)\n");
      printf("BUS ERROR (0x200)\n");
      break;
      break;
    case 6:
    case 6:
      printf("ALIGN ERROR (0x600)\n");
      printf("ALIGN ERROR (0x600)\n");
      break;
      break;
    case 7:
    case 7:
      printf("ILLEGAL INSN ERROR (0x700)\n");
      printf("ILLEGAL INSN ERROR (0x700)\n");
      break;
      break;
    default:
    default:
      printf("UNKNOWN ERROR (%d)\n",vect);
      printf("UNKNOWN ERROR (%d)\n",vect);
      break;
      break;
    }
    }
 
 
 
  printf("EPCR: 0x%.8x\n",epcr);
 
 
  printf("\n");
  printf("\n");
 
 
  // TODO - print some more diagnostics here
  // TODO - print some more diagnostics here
 
 
  printf("Attemping to reset...\n\n");
  printf("Attemping to reset...\n\n");
 
 
  asm volatile("l.ori r3, r0, 0x100");
  asm volatile("l.ori r3, r0, 0x100");
  asm volatile("l.jr r3");
  asm volatile("l.jr r3");
  asm volatile("l.nop");
  asm volatile("l.nop");
 
 
  // Stay here forever. 
  // Stay here forever. 
  //while(1);
  //while(1);
 
 
}
}
 
 
#endif
#endif
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.