sim: igen: tighten up build output
[binutils-gdb.git] / sim / mips / dv-tx3904tmr.c
index b27e9b0bfbf654d27103d950df32cb82f625c1af..5b5d8ac97f797382cffca6360fa7f07c5e24ce1f 100644 (file)
@@ -1,24 +1,25 @@
 /*  This file is part of the program GDB, the GNU debugger.
     
-    Copyright (C) 1998 Free Software Foundation, Inc.
+    Copyright (C) 1998-2021 Free Software Foundation, Inc.
     Contributed by Cygnus Solutions.
     
     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
+    the Free Software Foundation; either version 3 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
     
     */
 
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include "sim-main.h"
 #include "hw-main.h"
@@ -151,6 +152,7 @@ struct tx3904tmr {
   signed_8 last_ticks; /* time at last deliver_*_tick call */
   signed_8 roundoff_ticks; /* sim ticks unprocessed during last tick call */
   int ff; /* pulse generator flip-flop value: 1/0 */
+  struct hw_event* event; /* last scheduled event */
 
   unsigned_4 tcr;
 #define GET_TCR_TCE(c)      (((c)->tcr & 0x80) >> 7)
@@ -265,6 +267,8 @@ tx3904tmr_finish (struct hw *me)
     controller->trr = 0;
   controller->cpra = controller->cprb = 0x00FFFFFF;
   controller->ff = 0;
+  controller->last_ticks = controller->roundoff_ticks = 0;
+  controller->event = NULL;
 }
 
 
@@ -297,6 +301,10 @@ tx3904tmr_port_event (struct hw *me,
          controller->tisr = 
          controller->trr = 0;
        controller->cpra = controller->cprb = 0x00FFFFFF;
+       controller->last_ticks = controller->roundoff_ticks = 0;
+       if(controller->event != NULL)
+         hw_event_queue_deschedule(me, controller->event);
+       controller->event = NULL;
        break;
       }
 
@@ -365,11 +373,9 @@ tx3904tmr_io_write_buffer (struct hw *me,
   for (byte = 0; byte < nr_bytes; byte++)
     {
       address_word address = base + byte;
-      unsigned_1 write_byte = ((char*) source)[byte];
+      unsigned_1 write_byte = ((const char*) source)[byte];
       int reg_number = (address - controller->base_address) / 4;
       int reg_offset = 3 - (address - controller->base_address) % 4;
-      unsigned_4* register_ptr;
-      unsigned_4 register_value;
 
       /* fill in entire register_value word */
       switch (reg_number)
@@ -491,15 +497,27 @@ deliver_tx3904tmr_tick (struct hw *me,
   SIM_DESC sd = hw_system (me);
   signed_8 this_ticks = sim_events_time(sd);
 
-  /* compute simulation ticks between last tick and this tick */
-  signed_8 warp = this_ticks - controller->last_ticks + controller->roundoff_ticks;
+  signed_8 warp;
   signed_8 divisor;
-  signed_8 quotient, reminder;
+  signed_8 quotient, remainder;
+
+  /* compute simulation ticks between last tick and this tick */
+  if(controller->last_ticks != 0)
+    warp = this_ticks - controller->last_ticks + controller->roundoff_ticks;
+  else
+    {
+      controller->last_ticks = this_ticks; /* initialize */
+      warp = controller->roundoff_ticks;
+    }
+
+  if(controller->event != NULL)
+    hw_event_queue_deschedule(me, controller->event);
+  controller->event = NULL;
 
   /* Check whether the timer ticking is enabled at this moment.  This
      largely a function of the TCE bit, but is also slightly
      mode-dependent. */
-  switch(GET_TCR_TMODE(controller))
+  switch((int) GET_TCR_TMODE(controller))
     {
     case 0: /* interval */
       /* do not advance counter if TCE = 0 or if holding at count = CPRA */
@@ -537,27 +555,27 @@ deliver_tx3904tmr_tick (struct hw *me,
     {
       /* apply internal clock divider */
       if(GET_TCR_CCDE(controller)) /* divisor circuit enabled? */
-       divisor = controller->ext_ticks * (1 << (1 + GET_CCDR_CDR(controller)));
+       divisor = controller->clock_ticks * (1 << (1 + GET_CCDR_CDR(controller)));
       else
-       divisor = controller->ext_ticks;
+       divisor = controller->clock_ticks;
     }
   else
     {
-      divisor = controller->clock_ticks;
+      divisor = controller->ext_ticks;
     }
 
   /* how many times to increase counter? */
   quotient = warp / divisor;
-  reminder = warp % divisor;
+  remainder = warp % divisor;
 
   /* NOTE: If the event rescheduling code works properly, the quotient
      should never be larger than 1.  That is, we should receive events
      here at least as frequently as the simulated counter is supposed
-     to decrement.  So the reminder (-> roundoff_ticks) will slowly
+     to decrement.  So the remainder (-> roundoff_ticks) will slowly
      accumulate, with the quotient == 0.  Once in a while, quotient
      will equal 1. */
 
-  controller->roundoff_ticks = reminder;
+  controller->roundoff_ticks = remainder;
   controller->last_ticks = this_ticks;
   while(quotient > 0) /* Is it time to increment counter? */
     {
@@ -565,7 +583,7 @@ deliver_tx3904tmr_tick (struct hw *me,
       unsigned_4 next_trr = (controller->trr + 1) % (1 << 24);
       quotient --;
       
-      switch(GET_TCR_TMODE(controller))
+      switch((int) GET_TCR_TMODE(controller))
        {
        case 0: /* interval timer mode */
          {
@@ -658,17 +676,19 @@ deliver_tx3904tmr_tick (struct hw *me,
 
        case 3: /* disabled */
        default:
+         break;
        }
 
       /* update counter and report */
       controller->trr = next_trr;
-      HW_TRACE ((me, "counter trr %d tisr %x", controller->trr, controller->tisr));
+      /* HW_TRACE ((me, "counter trr %ld tisr %lx",
+        (long) controller->trr, (long) controller->tisr)); */
     } /* end quotient loop */
 
   /* Reschedule a timer event in near future, so we can increment the
      counter again.  Set the event about 75% of divisor time away, so
      we will experience roughly 1.3 events per counter increment. */
-  hw_event_queue_schedule(me, divisor*3/4, deliver_tx3904tmr_tick, NULL);
+  controller->event = hw_event_queue_schedule(me, divisor*3/4, deliver_tx3904tmr_tick, NULL);
 }