sim: m68hc11: clean up pointer casts
[binutils-gdb.git] / sim / m68hc11 / dv-m68hc11tim.c
index 17553b1c4a71c8b80158e7122f2e6be6fb4af1b6..08604d3144352286a9f72b75a6c81e7243ec1b21 100644 (file)
@@ -1,5 +1,5 @@
 /*  dv-m68hc11tim.c -- Simulation of the 68HC11 timer devices.
-    Copyright (C) 1999-2016 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.)
 
@@ -20,6 +20,8 @@
     
     */
 
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include "sim-main.h"
 #include "hw-main.h"
@@ -258,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;
@@ -278,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;
@@ -306,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;
@@ -479,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;
@@ -500,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;
 }