sim: m68hc11: clean up pointer casts
[binutils-gdb.git] / sim / m68hc11 / dv-m68hc11tim.c
index 0456f67891271e0b342f21ec8c4bc57e96efb97e..08604d3144352286a9f72b75a6c81e7243ec1b21 100644 (file)
@@ -1,5 +1,5 @@
 /*  dv-m68hc11tim.c -- Simulation of the 68HC11 timer devices.
-    Copyright (C) 1999, 2000, 2002, 2003 Free Software Foundation, Inc.
+    Copyright (C) 1999-2021 Free Software Foundation, Inc.
     Written by Stephane Carrez (stcarrez@nerim.fr)
     (From a driver model Contributed by Cygnus Solutions.)
 
@@ -7,20 +7,21 @@
     
     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 vertimn 2 of the License, or
-    (at your option) any later vertimn.
-    
+    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"
@@ -237,7 +238,7 @@ enum event_type
   COMPARE_EVENT
 };
 
-void
+static void
 m68hc11tim_timer_event (struct hw *me, void *data)
 {
   SIM_DESC sd;
@@ -259,7 +260,7 @@ m68hc11tim_timer_event (struct hw *me, void *data)
   controller = hw_data (me);
   sd         = hw_system (me);
   cpu        = STATE_CPU (sd, 0);
-  type       = (enum event_type) ((long) data) & 0x0FF;
+  type       = (enum event_type) ((uintptr_t) data) & 0x0FF;
   events     = STATE_EVENTS (sd);
 
   delay = 0;
@@ -279,7 +280,7 @@ m68hc11tim_timer_event (struct hw *me, void *data)
       eventp = &controller->rti_timer_event;
       delay  = controller->rti_prev_interrupt + controller->rti_delay;
       
-      if (((long) (data) & 0x0100) == 0)
+      if (((uintptr_t) data & 0x0100) == 0)
         {
           cpu->ios[M6811_TFLG2] |= M6811_RTIF;
           check_interrupt = 1;
@@ -307,7 +308,7 @@ m68hc11tim_timer_event (struct hw *me, void *data)
       delay += events->nr_ticks_to_process;
 
       eventp = &controller->tof_timer_event;
-      if (((long) (data) & 0x100) == 0)
+      if (((uintptr_t) data & 0x100) == 0)
         {
           cpu->ios[M6811_TFLG2] |= M6811_TOF;
           check_interrupt = 1;
@@ -480,7 +481,8 @@ cycle_to_string (sim_cpu *cpu, signed64 t, int flags)
 {
   char time_buf[32];
   char cycle_buf[32];
-  static char buf[64];
+  /* Big enough to handle 64-bit t, time_buf, and cycle_buf.  */
+  static char buf[128];
 
   time_buf[0] = 0;
   cycle_buf[0] = 0;
@@ -501,10 +503,7 @@ cycle_to_string (sim_cpu *cpu, signed64 t, int flags)
     sprintf (cycle_buf, " cycle%s",
              (t > 1 ? "s" : ""));
 
-  if (t < LONG_MAX)
-    sprintf (buf, "%9lu%s%s", (unsigned long) t, cycle_buf, time_buf);
-  else
-    sprintf (buf, "%llu%s%s", t, cycle_buf, time_buf);
+  sprintf (buf, "%9" PRIi64 "%s%s", t, cycle_buf, time_buf);
   return buf;
 }
 
@@ -522,7 +521,7 @@ m68hc11tim_print_timer (struct hw *me, const char *name,
   else
     {
       signed64 t;
-      sim_cpucpu;
+      sim_cpu *cpu;
 
       cpu = STATE_CPU (sd, 0);