Listening for Notifications

In additional to the normal timed and stacked events, it is possible to add modules that listen to special notifications. Such notifications include for example bus traffic notifications (which can be used to tap some of the bus models), and trap taken and return from trap notifications. Normally, notifications are disabled, but they can be enabled using certain programming interfaces.

Notification listening can be handle in plug-ins (plug-ins do not need to register any models) or they can be added in your own program that drives the emulator (see Embedding TEMU in a Simulator). As an example, in order to handle traps and rett instructions (return from trap), you can register to receive two notifications as follows:

static void
trapEntry(void *arg, temu_Object *source, void *notinfo)
{
  (void)arg;
  temu_TrapEventInfo *info = (temu_TrapEventInfo *)notinfo;
  temu_logInfo(source, "trap taken %x", info->TrapId);
}
static void
trapExit(void *arg, temu_Object *source, void *notinfo)
{
  (void)arg;
  (void)notinfo;
  temu_logInfo(source, "rett executed");
}

Note that the actual type for the notinfo pointer should be documented in the respective manuals and it differ depending on the type of notification. The actual registration for subscription can be done as follows:

  void *board0_cpu = temu_objectForName("board0-cpu");
  temu_CpuIface *iface = temu_getInterface(board0_cpu, "CpuIface", 0);
  if (iface && iface->enableTrapEvents) {
    iface->enableTrapEvents(board0_cpu);
  }
  temu_subscribeNotification("temu.cpuTrapEntry", board0_cpu, NULL, trapEntry);
  temu_subscribeNotification("temu.cpuTrapExit", board0_cpu, NULL, trapExit);

In the example, a plug-in that registers no classes does this from its initialisation function. The CPU must exist by then, so import the plug-in after the project has created board0:

temu> import notifications
temu> sched.start workers=1
temu> step cpuidx=0 steps=4
0.0:info: board0-cpu : trap taken 85
0.0:info: board0-cpu : rett executed

The output above is for a program that takes a software trap and returns from it; the Python chapter shows how to set one up. Trap events can also be enabled from the command line, with cpu-enable-trap-events cpu=board0-cpu.

There is a command to list all published notifications and possible source objects. Type "notification-list" in the command line to see these.

Note that notifications are in a global namespace (unlike timed events, which are associated with an object). This allows you to for example listen to all notifications with a certain event, without specifying the source object.