[Simh] Idle support for the 3B2 emulator

Mark Pizzolato Mark at infocomm.com
Sat Nov 18 14:06:10 EST 2017


On Saturday, November 18, 2017 at 10:28 AM, Seth Morabito wrote:
> I'm currently working on adding CPU idle support for the 3B2 emulator, but I
> may need some additional guidance.
> 
> The WE32100 CPU has a lovely WAIT instruction that pauses the CPU until the
> next interrupt. 

You should be fine just calling sim_idle (TMR_CLK, TRUE) in the middle of your WAIT instruction.

> It also has a main system timer that interrupts once every
> 10ms, so idling should be trivial. But there's one catch: The 10ms main system
> clock is programmable, and is started by the UNIX kernel at boot time, not by
> hardware.  The clock is also started and stopped with different frequencies a
> few times by system tests in the ROM, adding some complexity.
>
> I _think_ that the right thing to do, if hacky, is detect when the clock is set to
> 100Hz (0x03e8 in the divider register) and only then init the calibrated clock.
> Otherwise I have to deal with re-initializing it every time it's started, and I
> don't know if that's supported.
> 
> Is there a better strategy for this?

You're worrying about more things than you need to.  You should merely need to:

1) in your clock device reset routine:

    sim_rtcn_init_unit (&clk_unit, clk_unit.wait, TMR_CLK);/* init timer */
    sim_activate_after (&clk_unit, 1000000/clk_tps);    /* activate unit */

2) in your clock device unit service routine:

	sim_rtcn_calb (clk_tps, TMR_CLK);                   /* calibrate clock */
	sim_activate_after (&clk_unit, 1000000/clk_tps);        /* reactivate unit */

3) Change clk_tps to an appropriate value each time the clock interval is changed.
4) Keep track of whether the clock is supposed to be running, and only generate clock interrupts in the unit service routine when the clock is running.

Once you've got the above in your simulator, you may find that some devices 
that poll for data (i.e. console or other terminal devices) tend to interfere with
effective idling unless the polling activity is synchronized with when the clock
service routine is going to be running anyway.  A useful way to accommodate this
would be to call:

            sim_clock_coschedule_tmr (UNIT *uptr, int32 tmr, int32 ticks);

instead of directly calling sim_activate() in your console or terminal device 
unit service routine.

When you call this, tmr should be the above TMR_CLK value and ticks should be
the number of ticks between the local devices' polling.  With a 10ms tick size, 
a ticks value of 1 or 2 should be fine.

Feel free to contact me directly with questions or problems.

- Mark



More information about the Simh mailing list