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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_34/] [or1ksim/] [cpu/] [or1k/] [except.c] - Diff between revs 133 and 139

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 133 Rev 139
Line 23... Line 23...
 
 
#include "abstract.h"
#include "abstract.h"
#include "except.h"
#include "except.h"
#include "sprs.h"
#include "sprs.h"
 
 
 
static void except_handle_backend(int,unsigned long,unsigned long);
 
 
extern int cont_run;
extern int cont_run;
extern struct iqueue_entry iqueue[20];
extern struct iqueue_entry iqueue[20];
extern unsigned long pc;
extern unsigned long pc;
extern unsigned long pcnext;
extern unsigned long pcnext;
extern unsigned long pc_phy;
extern unsigned long pc_phy;
extern struct iqueue_entry iqueue[];
extern struct iqueue_entry iqueue[];
 
 
extern int delay_insn;
extern int delay_insn;
int cycle_delay = 0;  /* Added by CZ 27/05/01 */
int cycle_delay = 0;  /* Added by CZ 27/05/01 */
 
 
 
static struct {
 
  int valid;
 
  int type;
 
  unsigned long address;
 
  unsigned long saved;
 
} pending;
 
 
 
void ClearPendingException()
 
{
 
  if(pending.valid && pending.type != EXCEPT_RESET)
 
    {
 
      pending.valid = 0;
 
      pending.type = 0;
 
      pending.address = 0;
 
      pending.saved = 0;
 
    }
 
}
 
 
 
/* The delayed_pc and delayed_pcnext are fields which hold
 
   the original value of the PC across breakpoint exceptions
 
   in the case of a development interface. Due to an implementation
 
   issues, DIR injected instructions can modify these values
 
   when in fact they should not. So we save and restore them
 
   later on. */
 
static unsigned long delayed_pc = 0;
 
static unsigned long delayed_pcnext = 0;
 
static int delayed_pc_valid = 0;
 
 
 
void PrepareExceptionPC(unsigned long t_pc,unsigned long t_pcnext)
 
{
 
  /* If a real exception occurred which has stalled
 
     the CPU, we are expecting to halt before the end
 
     of the instruction. Otherwise, if it is a single
 
     step that has caused the halt, we are expected to
 
     complete the entire instruction and stop after
 
     it is finished. */
 
 
 
  if(pending.valid)
 
    {
 
      delayed_pc = t_pc;
 
      delayed_pcnext = t_pcnext;
 
      delayed_pc_valid = 1;
 
    }
 
  else
 
    _execute_update_pc(t_pc,t_pcnext);
 
}
 
 
 
void PrepareException()
 
{
 
  if(delayed_pc_valid)
 
    {
 
      pc = delayed_pc;
 
      pcnext = delayed_pcnext;
 
      pc_phy = simulate_ic_mmu_fetch(pc);
 
      if ((pc_phy < MEMORY_START) || (pc_phy > MEMORY_START + MEMORY_LEN))
 
        except_handle(EXCEPT_BUSERR, pc);
 
      delayed_pc_valid = delayed_pc = delayed_pcnext = 0;
 
    }
 
 
 
  if(pending.valid)
 
    except_handle_backend(pending.type,pending.address,pending.saved);
 
}
 
 
/* Handle OR1K exceptions. */
/* Handle OR1K exceptions. */
void except_handle(int except, unsigned long ea)
void except_handle(int except, unsigned long ea)
{
{
        unsigned long pc_saved;
 
 
 
        printf("Exception 0x%x (%s): ", except, EXCEPT_NAME(except));
        printf("Exception 0x%x (%s): ", except, EXCEPT_NAME(except));
        printf("Iqueue[0].insn_addr: 0x%x  Eff ADDR: 0x%x\n",  iqueue[0].insn_addr, ea);
        printf("Iqueue[0].insn_addr: 0x%x  Eff ADDR: 0x%x\n",  iqueue[0].insn_addr, ea);
        printf("  pc: 0x%x  pcnext: 0x%x\n",  pc, pcnext);
        printf("  pc: 0x%x  pcnext: 0x%x\n",  pc, pcnext);
 
 
 
  pending.valid = 1;
 
  pending.type = except;
 
  pending.address = ea;
 
  pending.saved = pc;
 
 
 
  if(DebugCheckException(except))
 
    {
 
      pending.valid = 0;
 
      pending.type = 0;
 
      pending.address = 0;
 
      pending.saved = 0;
 
    }
 
 
 
  cycle_delay = 0;  /* An exception stalls the CPU 0 clock cycles */
 
}
 
 
 
static void except_handle_backend(int except, unsigned long ea, unsigned long pc_saved)
 
{
 
      pending.valid = 0;
 
      pending.type = 0;
 
      pending.address = 0;
 
      pending.saved = 0;
 
 
#if ONLY_VIRTUAL_MACHINE
#if ONLY_VIRTUAL_MACHINE
        printf("WARNING: No exception processing while ONLY_VIRTUAL_MACHINE is defined.\n");
        printf("WARNING: No exception processing while ONLY_VIRTUAL_MACHINE is defined.\n");
        cont_run = 0;
        cont_run = 0;
#else
#else
 
 
Line 79... Line 165...
 
 
        mtspr(SPR_SR, mfspr(SPR_SR) | SPR_SR_SUPV);     /* SUPV mode */
        mtspr(SPR_SR, mfspr(SPR_SR) | SPR_SR_SUPV);     /* SUPV mode */
        mtspr(SPR_SR, mfspr(SPR_SR) & ~SPR_SR_EXR);     /* Disable except. */
        mtspr(SPR_SR, mfspr(SPR_SR) & ~SPR_SR_EXR);     /* Disable except. */
        pc = (unsigned long)except;
        pc = (unsigned long)except;
 
 
 
        /* This has been removed. All exceptions (not just SYSCALL) suffer
 
           from the same problem. The solution is to continue just like
 
           the pipeline would, and issue the exception on the next
 
           clock cycle. We assume now that this function is being called
 
           ->BEFORE<- the instruction fetch and after the previous update
 
           which always yields the correct behavior. This has the added
 
           advantage that a debugger can prevent an exception from
 
           taking place by resetting the pc. */
 
#if 0
        /* MM: We do pc update after the execute (in the simulator), so we
        /* MM: We do pc update after the execute (in the simulator), so we
           decrease it by 4 so that next instruction points to first exception
           decrease it by 4 so that next instruction points to first exception
           instruction. */
           instruction. */
        if (except == EXCEPT_SYSCALL)
        if (except == EXCEPT_SYSCALL)
          pc -= 4;
          pc -= 4;
 
#endif
 
 
        pcnext = pc+4;
        pcnext = pc+4;
 
 
        /* Added by CZ 27/05/01 */
        /* Added by CZ 27/05/01 */
        pc_phy = pc;
        pc_phy = pc;      /* An exception always turns off the MMU, so
        cycle_delay = 7;  /* An exception stalls the CPU 7 clock cycles */
                             pc is always pc_phy */
 
 
#endif
#endif
}
}
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

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