1 /* The common simulator framework for GDB, the GNU Debugger.
3 Copyright 2002-2015 Free Software Foundation, Inc.
5 Contributed by Andrew Cagney and Red Hat.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #ifndef _SIM_EVENTS_C_
24 #define _SIM_EVENTS_C_
27 #include "sim-assert.h"
41 #include <signal.h> /* For SIGPROCMASK et al. */
46 /* core - target byte order */
51 /* core - big-endian */
56 /* core - little-endian */
62 /* sim - host byte order */
67 /* sim - big-endian */
72 /* sim - little-endian */
83 } sim_event_watchpoints;
87 sim_event_watchpoints watching;
89 sim_event_handler *handler;
91 signed64 time_of_event;
92 /* watch wallclock event */
94 /* watch core address */
95 address_word core_addr;
99 /* watch core/sim range */
100 int is_within; /* 0/1 */
105 /* trace info (if any) */
112 /* The event queue maintains a single absolute time using two
115 TIME_OF_EVENT: this holds the time at which the next event is ment
116 to occur. If no next event it will hold the time of the last
119 TIME_FROM_EVENT: The current distance from TIME_OF_EVENT. A value
120 <= 0 (except when poll-event is being processed) indicates that
121 event processing is due. This variable is decremented once for
122 each iteration of a clock cycle.
124 Initially, the clock is started at time one (0) with TIME_OF_EVENT
125 == 0 and TIME_FROM_EVENT == 0 and with NR_TICKS_TO_PROCESS == 1.
127 Clearly there is a bug in that this code assumes that the absolute
128 time counter will never become greater than 2^62.
130 To avoid the need to use 64bit arithmetic, the event queue always
131 contains at least one event scheduled every 16 000 ticks. This
132 limits the time from event counter to values less than
136 #if !defined (SIM_EVENTS_POLL_RATE)
137 #define SIM_EVENTS_POLL_RATE 0x1000
141 #define _ETRACE sd, NULL
144 #define ETRACE(ARGS) \
147 if (STRACE_EVENTS_P (sd)) \
149 if (STRACE_DEBUG_P (sd)) \
152 SIM_FILTER_PATH (file, __FILE__); \
153 trace_printf (sd, NULL, "%s:%d: ", file, __LINE__); \
161 /* event queue iterator - don't iterate over the held queue. */
163 #if EXTERN_SIM_EVENTS_P
165 next_event_queue (SIM_DESC sd,
169 return &STATE_EVENTS (sd)->queue;
170 else if (queue == &STATE_EVENTS (sd)->queue)
171 return &STATE_EVENTS (sd)->watchpoints;
172 else if (queue == &STATE_EVENTS (sd)->watchpoints)
173 return &STATE_EVENTS (sd)->watchedpoints;
174 else if (queue == &STATE_EVENTS (sd)->watchedpoints)
177 sim_io_error (sd, "next_event_queue - bad queue");
183 STATIC_INLINE_SIM_EVENTS\
185 sim_events_poll (SIM_DESC sd,
188 /* just re-schedule in 1000 million ticks time */
189 sim_events_schedule (sd, SIM_EVENTS_POLL_RATE, sim_events_poll, sd);
190 sim_io_poll_quit (sd);
194 /* "events" module install handler.
195 This is called via sim_module_install to install the "events" subsystem
196 into the simulator. */
198 #if EXTERN_SIM_EVENTS_P
199 STATIC_SIM_EVENTS (MODULE_UNINSTALL_FN) sim_events_uninstall;
200 STATIC_SIM_EVENTS (MODULE_INIT_FN) sim_events_init;
201 STATIC_SIM_EVENTS (MODULE_RESUME_FN) sim_events_resume;
202 STATIC_SIM_EVENTS (MODULE_SUSPEND_FN) sim_events_suspend;
205 #if EXTERN_SIM_EVENTS_P
207 sim_events_install (SIM_DESC sd)
209 SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
210 sim_module_add_uninstall_fn (sd, sim_events_uninstall);
211 sim_module_add_init_fn (sd, sim_events_init);
212 sim_module_add_resume_fn (sd, sim_events_resume);
213 sim_module_add_suspend_fn (sd, sim_events_suspend);
219 /* Suspend/resume the event queue manager when the simulator is not
222 #if EXTERN_SIM_EVENTS_P
224 sim_events_resume (SIM_DESC sd)
226 sim_events *events = STATE_EVENTS (sd);
227 SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
228 SIM_ASSERT (events->resume_wallclock == 0);
229 events->resume_wallclock = sim_elapsed_time_get ();
234 #if EXTERN_SIM_EVENTS_P
236 sim_events_suspend (SIM_DESC sd)
238 sim_events *events = STATE_EVENTS (sd);
239 SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
240 SIM_ASSERT (events->resume_wallclock != 0);
241 events->elapsed_wallclock += sim_elapsed_time_since (events->resume_wallclock);
242 events->resume_wallclock = 0;
248 /* Uninstall the "events" subsystem from the simulator. */
250 #if EXTERN_SIM_EVENTS_P
252 sim_events_uninstall (SIM_DESC sd)
254 SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
255 /* FIXME: free buffers, etc. */
262 #if EXTERN_SIM_EVENTS_P
264 sim_events_zalloc (SIM_DESC sd)
266 sim_events *events = STATE_EVENTS (sd);
267 sim_event *new = events->free_list;
270 events->free_list = new->next;
271 memset (new, 0, sizeof (*new));
275 #if defined (HAVE_SIGPROCMASK) && defined (SIG_SETMASK)
279 sigfillset (&new_mask);
280 sigprocmask (SIG_SETMASK, &new_mask, &old_mask);
282 new = ZALLOC (sim_event);
283 #if defined (HAVE_SIGPROCMASK) && defined (SIG_SETMASK)
285 sigprocmask (SIG_SETMASK, &old_mask, NULL);
292 STATIC_INLINE_SIM_EVENTS\
294 sim_events_free (SIM_DESC sd,
297 sim_events *events = STATE_EVENTS (sd);
298 dead->next = events->free_list;
299 events->free_list = dead;
300 if (dead->trace != NULL)
302 free (dead->trace); /* NB: asprintf returns a `free' buf */
308 /* Initialize the simulator event manager */
310 #if EXTERN_SIM_EVENTS_P
312 sim_events_init (SIM_DESC sd)
314 sim_events *events = STATE_EVENTS (sd);
316 /* drain the interrupt queue */
318 if (events->held == NULL)
319 events->held = NZALLOC (sim_event, MAX_NR_SIGNAL_SIM_EVENTS);
321 /* drain the normal queues */
323 sim_event **queue = NULL;
324 while ((queue = next_event_queue (sd, queue)) != NULL)
326 if (queue == NULL) break;
327 while (*queue != NULL)
329 sim_event *dead = *queue;
331 sim_events_free (sd, dead);
337 /* wind time back to zero */
338 events->nr_ticks_to_process = 1; /* start by doing queue */
339 events->time_of_event = 0;
340 events->time_from_event = 0;
341 events->elapsed_wallclock = 0;
342 events->resume_wallclock = 0;
344 /* schedule our initial counter event */
345 sim_events_schedule (sd, 0, sim_events_poll, sd);
347 /* from now on, except when the large-int event is being processed
348 the event queue is non empty */
349 SIM_ASSERT (events->queue != NULL);
358 sim_events_time (SIM_DESC sd)
360 sim_events *events = STATE_EVENTS (sd);
361 return (events->time_of_event - events->time_from_event);
367 sim_events_elapsed_time (SIM_DESC sd)
369 unsigned long elapsed = STATE_EVENTS (sd)->elapsed_wallclock;
371 /* Are we being called inside sim_resume?
372 (Is there a simulation in progress?) */
373 if (STATE_EVENTS (sd)->resume_wallclock != 0)
374 elapsed += sim_elapsed_time_since (STATE_EVENTS (sd)->resume_wallclock);
380 /* Returns the time that remains before the event is raised. */
383 sim_events_remain_time (SIM_DESC sd, sim_event *event)
388 return (event->time_of_event - sim_events_time (sd));
393 STATIC_INLINE_SIM_EVENTS\
395 update_time_from_event (SIM_DESC sd)
397 sim_events *events = STATE_EVENTS (sd);
398 signed64 current_time = sim_events_time (sd);
399 if (events->queue != NULL)
401 events->time_of_event = events->queue->time_of_event;
402 events->time_from_event = (events->queue->time_of_event - current_time);
406 events->time_of_event = current_time - 1;
407 events->time_from_event = -1;
409 if (STRACE_EVENTS_P (sd))
413 for (event = events->queue, i = 0;
415 event = event->next, i++)
418 "event time-from-event - time %ld, delta %ld - event %d, tag 0x%lx, time %ld, handler 0x%lx, data 0x%lx%s%s\n",
420 (long)events->time_from_event,
423 (long)event->time_of_event,
424 (long)event->handler,
426 (event->trace != NULL) ? ", " : "",
427 (event->trace != NULL) ? event->trace : ""));
430 SIM_ASSERT (current_time == sim_events_time (sd));
434 #if EXTERN_SIM_EVENTS_P
436 insert_sim_event (SIM_DESC sd,
437 sim_event *new_event,
440 sim_events *events = STATE_EVENTS (sd);
443 signed64 time_of_event;
446 sim_io_error (sd, "what is past is past!\n");
448 /* compute when the event should occur */
449 time_of_event = sim_events_time (sd) + delta;
451 /* find the queue insertion point - things are time ordered */
452 prev = &events->queue;
453 curr = events->queue;
454 while (curr != NULL && time_of_event >= curr->time_of_event)
456 SIM_ASSERT (curr->next == NULL
457 || curr->time_of_event <= curr->next->time_of_event);
461 SIM_ASSERT (curr == NULL || time_of_event < curr->time_of_event);
464 new_event->next = curr;
466 new_event->time_of_event = time_of_event;
468 /* adjust the time until the first event */
469 update_time_from_event (sd);
474 #if EXTERN_SIM_EVENTS_P
476 sim_events_schedule (SIM_DESC sd,
478 sim_event_handler *handler,
482 memset (&dummy, 0, sizeof dummy);
483 return sim_events_schedule_vtracef (sd, delta_time, handler, data,
489 #if EXTERN_SIM_EVENTS_P
491 sim_events_schedule_tracef (SIM_DESC sd,
493 sim_event_handler *handler,
498 sim_event *new_event;
501 new_event = sim_events_schedule_vtracef (sd, delta_time, handler, data, fmt, ap);
508 #if EXTERN_SIM_EVENTS_P
510 sim_events_schedule_vtracef (SIM_DESC sd,
512 sim_event_handler *handler,
517 sim_event *new_event = sim_events_zalloc (sd);
518 new_event->data = data;
519 new_event->handler = handler;
520 new_event->watching = watch_timer;
521 if (fmt == NULL || !STRACE_EVENTS_P (sd) || vasprintf (&new_event->trace, fmt, ap) < 0)
522 new_event->trace = NULL;
523 insert_sim_event (sd, new_event, delta_time);
525 "event scheduled at %ld - tag 0x%lx - time %ld, handler 0x%lx, data 0x%lx%s%s\n",
526 (long)sim_events_time (sd),
528 (long)new_event->time_of_event,
529 (long)new_event->handler,
530 (long)new_event->data,
531 (new_event->trace != NULL) ? ", " : "",
532 (new_event->trace != NULL) ? new_event->trace : ""));
538 #if EXTERN_SIM_EVENTS_P
540 sim_events_schedule_after_signal (SIM_DESC sd,
542 sim_event_handler *handler,
545 sim_events *events = STATE_EVENTS (sd);
546 sim_event *new_event;
547 #if defined (HAVE_SIGPROCMASK) && defined (SIG_SETMASK)
551 sigfillset (&new_mask);
552 sigprocmask (SIG_SETMASK, &new_mask, &old_mask);
555 /* allocate an event entry from the signal buffer */
556 new_event = &events->held [events->nr_held];
558 if (events->nr_held > MAX_NR_SIGNAL_SIM_EVENTS)
560 sim_engine_abort (NULL, NULL, NULL_CIA,
561 "sim_events_schedule_after_signal - buffer overflow");
564 new_event->data = data;
565 new_event->handler = handler;
566 new_event->time_of_event = delta_time; /* work it out later */
567 new_event->next = NULL;
569 events->work_pending = 1; /* notify main process */
571 #if defined (HAVE_SIGPROCMASK) && defined (SIG_SETMASK)
573 sigprocmask (SIG_SETMASK, &old_mask, NULL);
577 "signal scheduled at %ld - tag 0x%lx - time %ld, handler 0x%lx, data 0x%lx\n",
578 (long)sim_events_time (sd),
580 (long)new_event->time_of_event,
581 (long)new_event->handler,
582 (long)new_event->data));
587 #if EXTERN_SIM_EVENTS_P
589 sim_events_watch_clock (SIM_DESC sd,
590 unsigned delta_ms_time,
591 sim_event_handler *handler,
594 sim_events *events = STATE_EVENTS (sd);
595 sim_event *new_event = sim_events_zalloc (sd);
597 new_event->watching = watch_clock;
599 new_event->data = data;
600 new_event->handler = handler;
602 if (events->resume_wallclock == 0)
603 new_event->wallclock = (events->elapsed_wallclock + delta_ms_time);
605 new_event->wallclock = (events->elapsed_wallclock
606 + sim_elapsed_time_since (events->resume_wallclock)
609 new_event->next = events->watchpoints;
610 events->watchpoints = new_event;
611 events->work_pending = 1;
613 "event watching clock at %ld - tag 0x%lx - wallclock %ld, handler 0x%lx, data 0x%lx\n",
614 (long)sim_events_time (sd),
616 (long)new_event->wallclock,
617 (long)new_event->handler,
618 (long)new_event->data));
624 #if EXTERN_SIM_EVENTS_P
626 sim_events_watch_sim (SIM_DESC sd,
633 sim_event_handler *handler,
636 sim_events *events = STATE_EVENTS (sd);
637 sim_event *new_event = sim_events_zalloc (sd);
644 case 1: new_event->watching = watch_sim_host_1; break;
645 case 2: new_event->watching = watch_sim_host_2; break;
646 case 4: new_event->watching = watch_sim_host_4; break;
647 case 8: new_event->watching = watch_sim_host_8; break;
648 default: sim_io_error (sd, "sim_events_watch_sim - invalid nr bytes");
654 case 1: new_event->watching = watch_sim_be_1; break;
655 case 2: new_event->watching = watch_sim_be_2; break;
656 case 4: new_event->watching = watch_sim_be_4; break;
657 case 8: new_event->watching = watch_sim_be_8; break;
658 default: sim_io_error (sd, "sim_events_watch_sim - invalid nr bytes");
664 case 1: new_event->watching = watch_sim_le_1; break;
665 case 2: new_event->watching = watch_sim_le_2; break;
666 case 4: new_event->watching = watch_sim_le_4; break;
667 case 8: new_event->watching = watch_sim_le_8; break;
668 default: sim_io_error (sd, "sim_events_watch_sim - invalid nr bytes");
672 sim_io_error (sd, "sim_events_watch_sim - invalid byte order");
675 new_event->data = data;
676 new_event->handler = handler;
678 new_event->host_addr = host_addr;
680 new_event->lb64 = lb;
682 new_event->ub64 = ub;
683 new_event->is_within = (is_within != 0);
685 new_event->next = events->watchpoints;
686 events->watchpoints = new_event;
687 events->work_pending = 1;
689 "event watching host at %ld - tag 0x%lx - host-addr 0x%lx, 0x%lx..0x%lx, handler 0x%lx, data 0x%lx\n",
690 (long)sim_events_time (sd),
692 (long)new_event->host_addr,
695 (long)new_event->handler,
696 (long)new_event->data));
702 #if EXTERN_SIM_EVENTS_P
704 sim_events_watch_core (SIM_DESC sd,
705 address_word core_addr,
712 sim_event_handler *handler,
715 sim_events *events = STATE_EVENTS (sd);
716 sim_event *new_event = sim_events_zalloc (sd);
723 case 1: new_event->watching = watch_core_targ_1; break;
724 case 2: new_event->watching = watch_core_targ_2; break;
725 case 4: new_event->watching = watch_core_targ_4; break;
726 case 8: new_event->watching = watch_core_targ_8; break;
727 default: sim_io_error (sd, "sim_events_watch_core - invalid nr bytes");
733 case 1: new_event->watching = watch_core_be_1; break;
734 case 2: new_event->watching = watch_core_be_2; break;
735 case 4: new_event->watching = watch_core_be_4; break;
736 case 8: new_event->watching = watch_core_be_8; break;
737 default: sim_io_error (sd, "sim_events_watch_core - invalid nr bytes");
743 case 1: new_event->watching = watch_core_le_1; break;
744 case 2: new_event->watching = watch_core_le_2; break;
745 case 4: new_event->watching = watch_core_le_4; break;
746 case 8: new_event->watching = watch_core_le_8; break;
747 default: sim_io_error (sd, "sim_events_watch_core - invalid nr bytes");
751 sim_io_error (sd, "sim_events_watch_core - invalid byte order");
754 new_event->data = data;
755 new_event->handler = handler;
757 new_event->core_addr = core_addr;
758 new_event->core_map = core_map;
760 new_event->lb64 = lb;
762 new_event->ub64 = ub;
763 new_event->is_within = (is_within != 0);
765 new_event->next = events->watchpoints;
766 events->watchpoints = new_event;
767 events->work_pending = 1;
769 "event watching host at %ld - tag 0x%lx - host-addr 0x%lx, 0x%lx..0x%lx, handler 0x%lx, data 0x%lx\n",
770 (long)sim_events_time (sd),
772 (long)new_event->host_addr,
775 (long)new_event->handler,
776 (long)new_event->data));
782 #if EXTERN_SIM_EVENTS_P
784 sim_events_deschedule (SIM_DESC sd,
785 sim_event *event_to_remove)
787 sim_events *events = STATE_EVENTS (sd);
788 sim_event *to_remove = (sim_event*)event_to_remove;
789 if (event_to_remove != NULL)
791 sim_event **queue = NULL;
792 while ((queue = next_event_queue (sd, queue)) != NULL)
794 sim_event **ptr_to_current;
795 for (ptr_to_current = queue;
796 *ptr_to_current != NULL && *ptr_to_current != to_remove;
797 ptr_to_current = &(*ptr_to_current)->next);
798 if (*ptr_to_current == to_remove)
800 sim_event *dead = *ptr_to_current;
801 *ptr_to_current = dead->next;
803 "event/watch descheduled at %ld - tag 0x%lx - time %ld, handler 0x%lx, data 0x%lx%s%s\n",
804 (long) sim_events_time (sd),
805 (long) event_to_remove,
806 (long) dead->time_of_event,
807 (long) dead->handler,
809 (dead->trace != NULL) ? ", " : "",
810 (dead->trace != NULL) ? dead->trace : ""));
811 sim_events_free (sd, dead);
812 update_time_from_event (sd);
813 SIM_ASSERT ((events->time_from_event >= 0) == (events->queue != NULL));
819 "event/watch descheduled at %ld - tag 0x%lx - not found\n",
820 (long) sim_events_time (sd),
821 (long) event_to_remove));
826 STATIC_INLINE_SIM_EVENTS\
828 sim_watch_valid (SIM_DESC sd,
831 switch (to_do->watching)
834 #define WATCH_CORE(N,OP,EXT) \
836 unsigned_##N word = 0; \
837 int nr_read = sim_core_read_buffer (sd, NULL, to_do->core_map, &word, \
838 to_do->core_addr, sizeof (word)); \
840 ok = (nr_read == sizeof (unsigned_##N) \
841 && (to_do->is_within \
842 == (word >= to_do->lb##EXT \
843 && word <= to_do->ub##EXT)));
845 case watch_core_targ_1:
847 WATCH_CORE (1, T2H,);
850 case watch_core_targ_2:
852 WATCH_CORE (2, T2H,);
855 case watch_core_targ_4:
857 WATCH_CORE (4, T2H,);
860 case watch_core_targ_8:
862 WATCH_CORE (8, T2H,64);
866 case watch_core_be_1:
868 WATCH_CORE (1, BE2H,);
871 case watch_core_be_2:
873 WATCH_CORE (2, BE2H,);
876 case watch_core_be_4:
878 WATCH_CORE (4, BE2H,);
881 case watch_core_be_8:
883 WATCH_CORE (8, BE2H,64);
887 case watch_core_le_1:
889 WATCH_CORE (1, LE2H,);
892 case watch_core_le_2:
894 WATCH_CORE (2, LE2H,);
897 case watch_core_le_4:
899 WATCH_CORE (4, LE2H,);
902 case watch_core_le_8:
904 WATCH_CORE (8, LE2H,64);
909 #define WATCH_SIM(N,OP,EXT) \
911 unsigned_##N word = *(unsigned_##N*)to_do->host_addr; \
913 ok = (to_do->is_within \
914 == (word >= to_do->lb##EXT \
915 && word <= to_do->ub##EXT));
917 case watch_sim_host_1:
919 WATCH_SIM (1, word = ,);
922 case watch_sim_host_2:
924 WATCH_SIM (2, word = ,);
927 case watch_sim_host_4:
929 WATCH_SIM (4, word = ,);
932 case watch_sim_host_8:
934 WATCH_SIM (8, word = ,64);
940 WATCH_SIM (1, BE2H,);
945 WATCH_SIM (2, BE2H,);
950 WATCH_SIM (4, BE2H,);
955 WATCH_SIM (8, BE2H,64);
961 WATCH_SIM (1, LE2H,);
966 WATCH_SIM (1, LE2H,);
971 WATCH_SIM (1, LE2H,);
976 WATCH_SIM (1, LE2H,64);
981 case watch_clock: /* wallclock */
983 unsigned long elapsed_time = sim_events_elapsed_time (sd);
984 return (elapsed_time >= to_do->wallclock);
988 sim_io_error (sd, "sim_watch_valid - bad switch");
998 sim_events_tick (SIM_DESC sd)
1000 sim_events *events = STATE_EVENTS (sd);
1002 /* this should only be called after the previous ticks have been
1005 /* Advance the time but *only* if there is nothing to process */
1006 if (events->work_pending
1007 || events->time_from_event == 0)
1009 events->nr_ticks_to_process += 1;
1014 events->time_from_event -= 1;
1022 sim_events_tickn (SIM_DESC sd,
1025 sim_events *events = STATE_EVENTS (sd);
1028 /* this should only be called after the previous ticks have been
1031 /* Advance the time but *only* if there is nothing to process */
1032 if (events->work_pending || events->time_from_event < n)
1034 events->nr_ticks_to_process += n;
1039 events->time_from_event -= n;
1047 sim_events_slip (SIM_DESC sd,
1050 sim_events *events = STATE_EVENTS (sd);
1051 SIM_ASSERT (slip > 0);
1053 /* Flag a ready event with work_pending instead of number of ticks
1054 to process so that the time continues to be correct */
1055 if (events->time_from_event < slip)
1057 events->work_pending = 1;
1059 events->time_from_event -= slip;
1065 sim_events_preprocess (SIM_DESC sd,
1066 int events_were_last,
1067 int events_were_next)
1069 sim_events *events = STATE_EVENTS (sd);
1070 if (events_were_last)
1072 /* Halted part way through event processing */
1073 ASSERT (events->nr_ticks_to_process != 0);
1074 /* The external world can't tell if the event that stopped the
1075 simulator was the last event to process. */
1076 ASSERT (events_were_next);
1077 sim_events_process (sd);
1079 else if (events_were_next)
1081 /* Halted by the last processor */
1082 if (sim_events_tick (sd))
1083 sim_events_process (sd);
1090 sim_events_process (SIM_DESC sd)
1092 sim_events *events = STATE_EVENTS (sd);
1093 signed64 event_time = sim_events_time (sd);
1095 /* Clear work_pending before checking nr_held. Clearing
1096 work_pending after nr_held (with out a lock could loose an
1098 events->work_pending = 0;
1100 /* move any events that were asynchronously queued by any signal
1101 handlers onto the real event queue. */
1102 if (events->nr_held > 0)
1106 #if defined(HAVE_SIGPROCMASK) && defined(SIG_SETMASK)
1110 sigfillset (&new_mask);
1111 sigprocmask (SIG_SETMASK, &new_mask, &old_mask);
1114 for (i = 0; i < events->nr_held; i++)
1116 sim_event *entry = &events->held [i];
1117 sim_events_schedule (sd,
1118 entry->time_of_event,
1122 events->nr_held = 0;
1124 #if defined(HAVE_SIGPROCMASK) && defined(SIG_SETMASK)
1126 sigprocmask (SIG_SETMASK, &old_mask, NULL);
1131 /* Process any watchpoints. Be careful to allow a watchpoint to
1132 appear/disappear under our feet.
1133 To ensure that watchpoints are processed only once per cycle,
1134 they are moved onto a watched queue, this returned to the
1135 watchpoint queue when all queue processing has been
1137 while (events->watchpoints != NULL)
1139 sim_event *to_do = events->watchpoints;
1140 events->watchpoints = to_do->next;
1141 if (sim_watch_valid (sd, to_do))
1143 sim_event_handler *handler = to_do->handler;
1144 void *data = to_do->data;
1146 "event issued at %ld - tag 0x%lx - handler 0x%lx, data 0x%lx%s%s\n",
1151 (to_do->trace != NULL) ? ", " : "",
1152 (to_do->trace != NULL) ? to_do->trace : ""));
1153 sim_events_free (sd, to_do);
1158 to_do->next = events->watchedpoints;
1159 events->watchedpoints = to_do;
1163 /* consume all events for this or earlier times. Be careful to
1164 allow an event to appear/disappear under our feet */
1165 while (events->queue->time_of_event <
1166 (event_time + events->nr_ticks_to_process))
1168 sim_event *to_do = events->queue;
1169 sim_event_handler *handler = to_do->handler;
1170 void *data = to_do->data;
1171 events->queue = to_do->next;
1172 update_time_from_event (sd);
1174 "event issued at %ld - tag 0x%lx - handler 0x%lx, data 0x%lx%s%s\n",
1179 (to_do->trace != NULL) ? ", " : "",
1180 (to_do->trace != NULL) ? to_do->trace : ""));
1181 sim_events_free (sd, to_do);
1185 /* put things back where they belong ready for the next iteration */
1186 events->watchpoints = events->watchedpoints;
1187 events->watchedpoints = NULL;
1188 if (events->watchpoints != NULL)
1189 events->work_pending = 1;
1191 /* advance the time */
1192 SIM_ASSERT (events->time_from_event >= events->nr_ticks_to_process);
1193 SIM_ASSERT (events->queue != NULL); /* always poll event */
1194 events->time_from_event -= events->nr_ticks_to_process;
1196 /* this round of processing complete */
1197 events->nr_ticks_to_process = 0;