old-cross-binutils/sim/common/sim-events.h

244 lines
5.9 KiB
C
Raw Normal View History

/* This file is part of the program psim.
Copyright (C) 1994-1997, Andrew Cagney <cagney@highland.com.au>
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
(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.
*/
#ifndef _SIM_EVENTS_H_
#define _SIM_EVENTS_H_
1997-05-12 04:57:49 +00:00
/* Notes:
1997-05-12 04:57:49 +00:00
When scheduling an event, the a delta of zero/one refers to the
timeline as follows:
epoch 0|1 1|2 2|3 3|
**queue**|--insn--|*queue*|--insn--|*queue*|--insn--|*queue*|
| ^ ^ | ^ ^
`- +0 ------------ +1 --.. `----- +0 ------------- +1 --..
When the queue is initialized, the time is set to zero with a
number of initialization events scheduled. Consequently, as also
illustrated above, the event queue should be processed before the
first instruction. That instruction being executed during tick 1.
The simulator main loop may take a form similar to:
1997-05-12 04:57:49 +00:00
if (halt-/restart-setjmp)
{
1997-05-12 04:57:49 +00:00
.... // Determine who should go next
last-cpu-nr = get-last-cpu-nr (sd);
next-cpu-nr = get-next-cpu-nr (sd);
events-were-last? = (last-cpu-nr >= nr-cpus);
events-were-next? = (next-cpu-nr >= nr-cpus);
1997-05-12 04:57:49 +00:00
.... // process any outstanding events
sim_events_preprocess (sd, events-were-last?, events-were-next?);
if (events-were-next)
next-cpu-nr = 0;
.... // prime main loop
while (1)
{
.... // model one insn of next-cpu-nr .. nr-cpus
if (sim_events_tick (sd))
sim_events_process (sd);
next-cpu-nr = 0
}
}
NB. In the above pseudo code it is assumed that any cpu-nr >=
nr-cpus is a marker for the event queue. */
typedef void sim_event_handler(SIM_DESC sd, void *data);
1997-05-12 04:57:49 +00:00
typedef struct _sim_event sim_event;
1997-05-12 04:57:49 +00:00
typedef struct _sim_events sim_events;
struct _sim_events {
1997-05-21 06:54:13 +00:00
int nr_ticks_to_process;
1997-05-12 04:57:49 +00:00
sim_event *queue;
sim_event *watchpoints;
sim_event *watchedpoints;
1997-05-21 06:54:13 +00:00
sim_event *free_list;
/* flag additional work needed */
volatile int work_pending;
/* the asynchronous event queue */
1997-05-21 06:54:13 +00:00
#ifndef MAX_NR_SIGNAL_SIM_EVENTS
#define MAX_NR_SIGNAL_SIM_EVENTS 2
#endif
sim_event *held;
volatile int nr_held;
/* timekeeping */
unsigned long elapsed_wallclock;
SIM_ELAPSED_TIME resume_wallclock;
signed64 time_of_event;
1997-05-12 04:57:49 +00:00
int time_from_event;
int trace;
};
/* Install the "events" module. */
EXTERN_SIM_EVENTS\
(SIM_RC) sim_events_install (SIM_DESC sd);
1997-05-12 04:57:49 +00:00
/* Set Tracing Level */
EXTERN_SIM_EVENTS\
1997-05-12 04:57:49 +00:00
(void) sim_events_set_trace
(SIM_DESC sd,
int level);
1997-05-12 04:57:49 +00:00
/* Schedule an event DELTA_TIME ticks into the future */
EXTERN_SIM_EVENTS\
1997-05-12 04:57:49 +00:00
(sim_event *) sim_events_schedule
(SIM_DESC sd,
signed64 delta_time,
1997-05-12 04:57:49 +00:00
sim_event_handler *handler,
void *data);
EXTERN_SIM_EVENTS\
1997-05-21 06:54:13 +00:00
(void) sim_events_schedule_after_signal
1997-05-12 04:57:49 +00:00
(SIM_DESC sd,
signed64 delta_time,
1997-05-12 04:57:49 +00:00
sim_event_handler *handler,
void *data);
1997-05-12 04:57:49 +00:00
1997-05-21 06:54:13 +00:00
/* Schedule an event milli-seconds from NOW. The exact interpretation
of wallclock is host dependant. */
1997-05-12 04:57:49 +00:00
EXTERN_SIM_EVENTS\
(sim_event *) sim_events_watch_clock
1997-05-12 04:57:49 +00:00
(SIM_DESC sd,
1997-05-21 06:54:13 +00:00
unsigned delta_ms_time,
1997-05-12 04:57:49 +00:00
sim_event_handler *handler,
void *data);
/* Schedule an event when the test (IS_WITHIN == (VAL >= LB && VAL <=
UB)) of the NR_BYTES value at HOST_ADDR with BYTE_ORDER endian is
true.
1997-05-12 04:57:49 +00:00
HOST_ADDR: pointer into the host address space.
BYTE_ORDER: 0 - host endian; BIG_ENDIAN; LITTLE_ENDIAN */
EXTERN_SIM_EVENTS\
(sim_event*) sim_events_watch_sim
1997-05-12 04:57:49 +00:00
(SIM_DESC sd,
void *host_addr,
int nr_bytes,
int byte_order,
int is_within,
1997-05-12 04:57:49 +00:00
unsigned64 lb,
unsigned64 ub,
sim_event_handler *handler,
void *data);
/* Schedule an event when the test (IS_WITHIN == (VAL >= LB && VAL <=
UB)) of the NR_BYTES value at CORE_ADDR in BYTE_ORDER endian is
true.
1997-05-12 04:57:49 +00:00
CORE_ADDR/MAP: pointer into the target address space.
BYTE_ORDER: 0 - current target endian; BIG_ENDIAN; LITTLE_ENDIAN */
EXTERN_SIM_EVENTS\
(sim_event*) sim_events_watch_core
1997-05-12 04:57:49 +00:00
(SIM_DESC sd,
address_word core_addr,
sim_core_maps core_map,
int nr_bytes,
int byte_order,
int is_within,
1997-05-12 04:57:49 +00:00
unsigned64 lb,
unsigned64 ub,
sim_event_handler *handler,
void *data);
/* Deschedule the specified event */
EXTERN_SIM_EVENTS\
1997-05-12 04:57:49 +00:00
(void) sim_events_deschedule
(SIM_DESC sd,
sim_event *event_to_remove);
/* Prepare for main simulator loop. Ensure that the next thing to do
is not event processing.
If the simulator halted part way through event processing then both
EVENTS_WERE_LAST and EVENTS_WERE_FIRST shall be true.
If the simulator halted after processing the last cpu, then only
EVENTS_WERE_NEXT shall be true. */
INLINE_SIM_EVENTS\
(void) sim_events_preprocess
(SIM_DESC sd,
int events_were_last,
int events_were_next);
/* Progress time - separated into two parts so that the main loop can
1997-05-21 06:54:13 +00:00
save its context before the event queue is processed.
sim_events_tickn advances the clock by N cycles (1..MAXINT) */
INLINE_SIM_EVENTS\
1997-05-12 04:57:49 +00:00
(int) sim_events_tick
(SIM_DESC sd);
1997-05-21 06:54:13 +00:00
INLINE_SIM_EVENTS\
(int) sim_events_tickn
(SIM_DESC sd,
int n);
1997-05-21 06:54:13 +00:00
INLINE_SIM_EVENTS\
1997-05-12 04:57:49 +00:00
(void) sim_events_process
(SIM_DESC sd);
1997-05-21 06:54:13 +00:00
/* Progress time such that an event shall occure upon the next call to
sim_events tick */
#if 0
INLINE_SIM_EVENTS\
(void) sim_events_timewarp
(SIM_DESC sd);
#endif
/* local concept of time */
INLINE_SIM_EVENTS\
1997-05-12 04:57:49 +00:00
(signed64) sim_events_time
(SIM_DESC sd);
#endif