home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / gdb-4.9 / sim / h8300 / perifs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-12  |  2.2 KB  |  99 lines

  1. /* perfipheral simulation
  2.  
  3.    Written by Steve Chamberlain of Cygnus Support.
  4.    sac@cygnus.com
  5.  
  6.    This file is part of H8/300 sim
  7.  
  8.  
  9.         THIS SOFTWARE IS NOT COPYRIGHTED
  10.  
  11.    Cygnus offers the following for use in the public domain.  Cygnus
  12.    makes no warranty with regard to the software or it's performance
  13.    and the user accepts the software "AS IS" with all faults.
  14.  
  15.    CYGNUS DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED, WITH REGARD TO
  16.    THIS SOFTWARE INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17.    MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  18.  
  19. */
  20.  
  21. /* Fake peripherals for the H8/330 */
  22. #include "state.h"
  23.  
  24. /* This routine is called every few instructions to see if some sort
  25.   of hardware event is needed */
  26.  
  27. perifs( )
  28. {
  29.   int interrupt = 0;
  30.   int lval;
  31.   int tmp;
  32.   /* What to do about the 16 bit timer */
  33.  
  34.  
  35.   /* Free running counter same as reg a */
  36.   if (saved_state.reg[OCRA] == saved_state.reg[FRC])
  37.   {
  38.     /* Set the counter A overflow bit */
  39.     saved_state.reg[TCSR] |= OCFA;
  40.  
  41.     if (saved_state.reg[TCSR] & CCLRA) 
  42.     {
  43.       saved_state.reg[FRC] = 0;
  44.     }
  45.  
  46.     if (saved_state.reg[TIER] & OCIEA) 
  47.     {
  48.       interrupt = 16;
  49.     }
  50.   }
  51.  
  52.   /* Free running counter same as reg b */
  53.   if (saved_state.reg[OCRB] == saved_state.reg[FRC])
  54.   {
  55.     saved_state.reg[TCSR] |= OCFB;
  56.     if (saved_state.reg[TIER] & OCIEB) 
  57.     {
  58.       interrupt = 17;
  59.     }
  60.   }
  61.  
  62.   /* inc free runnning counter */
  63.   saved_state.reg[FRC]++;
  64.   
  65.   if (saved_state.reg[FRC] == 0) 
  66.   {
  67.     /* Must have overflowed */
  68.     saved_state.reg[TCSR] |=  OVF;
  69.     if (BYTE_MEM(TIER) & OVIE)
  70.      interrupt = 18;
  71.   }
  72.  
  73.   /* If we've had an interrupt and the bit is on */
  74.   if (interrupt && saved_state.ienable) 
  75.   {
  76.  
  77.     int  ccr;
  78.  
  79.     saved_state.ienable = 0;    
  80.     ccr = saved_state.reg[CCR];
  81.     lval = WORD_MEM((interrupt)<<1);
  82.     lval = WORD_MEM(lval);
  83.    {
  84.      /* Push PC */
  85.      saved_state.reg[7] -= 2;
  86.      tmp = saved_state.reg[7];
  87.      SET_WORD_MEM (tmp, saved_state.reg[PC]);
  88.      /* Push CCR twice */
  89.      saved_state.reg[7] -=2 ;
  90.      tmp =  saved_state.reg[7];
  91.      SET_BYTE_MEM(tmp,ccr);
  92.      SET_BYTE_MEM(tmp+1,ccr);
  93.  
  94.      /* Set pc to point to first instruction of i vector */
  95.      saved_state.reg[PC] = lval;
  96.    }
  97.   }
  98. }
  99.