History log of /openbsd-current/usr.sbin/vmd/i8253.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.39 09-Feb-2024 dv

Tuck vmd's i8253 reset debug logs behind DPRINTF.

It's super chatty and pollutes verbose logging.


# 1.38 25-Oct-2023 dv

vmd(8): stop toggling irq deassert for edge triggered devs.

For edge-triggered devices, there's no need to deassert an irq given
how vmd(8) emulates a pic. Deassertion grabs a lock and can trigger
the ioctl for toggling pending interrupts causing a race condition.
This results in a storm of vm-exits and guest vcpu becoming
unresponsive.

The original sign of this issue is guest "pauses" when pasting text
into a serial console connection in something like xterm(1).

Tested by mbuhl@, cheloha@, sashan@, kn@, and mlarkin@.

"go for it", mlarkin@


Revision tags: OPENBSD_7_4_BASE
# 1.37 14-Apr-2023 tb

Add two missing void to appease clang 15

There is another thing clang 15 is whining about - this will be resolved
in upcoming work by dv.

ok dv


Revision tags: OPENBSD_7_3_BASE
# 1.36 10-Nov-2022 mbuhl

Initialize data before passing it to get_input_data. Strictly
speaking this is not necessary as all used bits of the uint32_t are
zeroed.
ok mlarkin


Revision tags: OPENBSD_7_2_BASE
# 1.35 02-Sep-2022 cheloha

vmd(8): compute i8254 read-back command latch from singular timestamp

The intent of the i8254 read-back command is (most likely) to permit
simultaneously latching two or three counters at once along with their
statuses.

To simulate this, we should compute olatch from one timestamp per
read-back command, not one timestamp per counter.

Improved with a tweak by dv@.

Link: https://marc.info/?l=openbsd-tech&m=166213670605453&w=2

ok dv@ mlarkin@


Revision tags: OPENBSD_7_0_BASE OPENBSD_7_1_BASE
# 1.34 16-Jun-2021 dv

cleanup vmd(8) includes and header files

Lots of organic growth other the years lead to unnecessary includes
(proc.h everywhere) and odd dependencies between header files. This
cleans things up a bit to help with upcoming cleanup around dhcp
code.

No functional change.

"go for it" mlarkin@


Revision tags: OPENBSD_6_9_BASE
# 1.33 29-Mar-2021 dv

Cleanly teardown and restore emulated device state on vm send/receive.

This cleans up events on a pause or resume, but also fixes an issue
where the vm_pipe event channels are not properly reinitialized on a
received guest leading to broken serial console.

OK pd@, mlarkin@


Revision tags: OPENBSD_6_8_BASE
# 1.32 28-Jun-2020 pd

vmd(8): Eliminate libevent state corruption

libevent functions for com, pic and rtc are now only called on event_thread.
vcpu exit handlers send messages on a dev pipe and callbacks on these events do
the event management (event_add, evtimer_add, etc). Previously, libevent state
was mutated by two threads, event_thread, that runs all the callbacks and the
vcpu thread when running exit handlers. This could have lead to libevent state
corruption.

Patch from Dave Voutila <dave@sisu.io>

ok claudio@
tested by abieber@ and brynet@


Revision tags: OPENBSD_6_7_BASE
# 1.31 30-Nov-2019 mlarkin

Revert previous - the stability was not as improved as we had thought and
we ended up accidentally breaking vmctl. This will need more thought.

ok ori@


# 1.30 29-Nov-2019 mlarkin

Fix at least one cause of VMs spinning at 100% host CPU

After debugging with ori@, it looks like an event ends up on the wrong
libevent queue, and we end continually de-queueing and re-queueing the
event continually. While it's unclear exactly why this happened, a clue
on libevent's github issues page for the same problem pointed us to using
a different event base for the device events. This seems to have unstuck
ori@'s problematic VM, and I have also seen no more hangs after this.

We have not completely separated the queues; ori@ will work on setting
new libevent bases for those later. But those events are pretty
frequency.

with help from and ok ori@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.29 10-Dec-2018 claudio

No need to \n in log_debug. Part of a larger diff.
OK mlarkin@ ccardenas@


Revision tags: OPENBSD_6_4_BASE
# 1.28 12-Jul-2018 mlarkin

vmm(8)/vmm(4): send a copy of the guest register state to vmd on exit,
avoiding multiple readregs ioctls back to vmm in case register content
is needed subsequently.

ok phessler


# 1.27 09-Jul-2018 mlarkin

vmd(8): deassert interrupt pins in the PIC at the right times. Helps fix
situations where vmd gets stuck at 100% cpu usage because the guest VM
is constantly trying to ack interrupts that already occurred.

tested by phessler on a VM that used to exhibit the issue.

ok phessler


# 1.26 19-Jun-2018 reyk

knf


# 1.25 23-May-2018 mlarkin

vmd(8): revert r1.23 (unlatched PIT reads), this made time go too fast on
some machines. Will investigate and commit a proper fix later.


# 1.24 27-Apr-2018 mlarkin

vmd(8): allow counter state readback via misc port for square wave mode


# 1.23 27-Apr-2018 mlarkin

vmd(8): allow unlatch PIT reads

ok ccardenas


# 1.22 26-Apr-2018 mlarkin

vmd(8): fix some bugs in PIT mode setting

PIT modes are now properly handled, including INTTC mode. This fixes some
bootloader timeouts.

ok brynet


# 1.21 26-Apr-2018 mlarkin

vmd(8): some more long lines that got missed last time


# 1.20 26-Apr-2018 mlarkin

vmd(8): handle PIT channel 2 status readback via port 0x61

Allow PIT channel 2 status (fired/counting) readback via port 0x61
bit 5.

ok guenther@


# 1.19 26-Apr-2018 mlarkin

vmd(8): wrap some long lines


# 1.18 17-Apr-2018 cheloha

Drive i8253 with CLOCK_MONOTONIC.

Ensures that the olatch decrements uniformly, independent of system
wall clock jumps.

While here, roll the olatch computation in i8253_do_readback() into
a loop, and leverage the timespec macros in sys/time.h. Both make the
code a lot more readable.

ok mlarkin@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.17 14-Aug-2017 jasper

whitespace and fix a comment typo


# 1.16 09-Jul-2017 pd

vmd/vmctl: Add ability to pause / unpause vms

With help from Ashwin Agrawal

ok reyk@ mlarkin@


# 1.15 08-May-2017 reyk

Adds functions to read and write state of devices in vmd.

This is required for implementing vmctl send and vmctl receive. vmctl
send / receive are two new options that will support snapshotting VMs
and migrating VMs from one host to another. The atomicio files are
copied from usr.bin/ssh.

Patch from Pratik Vyas; this project was undertaken at San Jose State
University along with his three teammates, Ashwin, Harshada and Siri
with mlarkin@ as the advisor.

OK mlarkin@


# 1.14 28-Apr-2017 mlarkin

rename i8253 "counter" to "channel", a better name for what we are
emulating


# 1.13 08-Apr-2017 mlarkin

implement channels 1 and 2 of the legacy PIT.

ok otto, deraadt


Revision tags: OPENBSD_6_1_BASE
# 1.12 27-Mar-2017 deraadt

die whitespace die die die


# 1.11 25-Mar-2017 mlarkin

Last bits needed to get seabios + alpine linux working. This is enough
to get started and let more people help finding and fixing bugs.

ok kettenis, deraadt


# 1.10 25-Mar-2017 mlarkin

Introduce a new function to obtain properly sized input data, and convert
i8253/i8259/mc146818 emulation to use this.


# 1.9 24-Mar-2017 reyk

Backout mlarkin's previous commit while he is away:
The newly-used function get_input_data() is missing and broke the tree.


# 1.8 24-Mar-2017 mlarkin

Last bits of cleanup for linux/seabios support in i8253/i8259 emulation
code.


# 1.7 23-Mar-2017 mlarkin

Various i8253/i8254 implementation improvements - Fix an error that used
the wrong i/o latch index on reads (resulting in erratic counter values
possibly being read). Also do proper return size setting (don't clobber
%eax high bits).

This diff also implements counter readback mode, which is used in seabios.


# 1.6 19-Mar-2017 mlarkin

Emulated i8253 should not start out in TIMER_RATEGEN mode on boot
automatically. This worked for OpenBSD guests but breaks seabios as soon
as the first interrupt fires since it has not programmed the PIT to do
anything yet. And OpenBSD reprograms the clock to rategen mode as soon
as it boots anyway, so this still works with vmctl(8)'s -k option, as
well as the faux-bootloader implemented in vmd(8)


# 1.5 17-Jan-2017 krw

Nuke some whitespace that keeps poking me in the eye as I try to
steal code.


# 1.4 26-Oct-2016 mlarkin

vmd(8)/vmctl(8) for i386. Some ugliness in #ifdef __i386__ areas will be
fixed in tree, but the changes required were pretty minimal.

Note that i386 hosts are still presently limited to running i386 guests.

ok deraadt, stefan, jca


# 1.3 03-Oct-2016 mlarkin

add RCS tags


# 1.2 01-Sep-2016 mlarkin

change some log_warn to log_warnx and convert some integer literals to
enumerand values


# 1.1 01-Sep-2016 mlarkin

Add a set of emulated legacy devices (PIT, PIC, RTC)

discussed with stefan and deraadt


# 1.38 25-Oct-2023 dv

vmd(8): stop toggling irq deassert for edge triggered devs.

For edge-triggered devices, there's no need to deassert an irq given
how vmd(8) emulates a pic. Deassertion grabs a lock and can trigger
the ioctl for toggling pending interrupts causing a race condition.
This results in a storm of vm-exits and guest vcpu becoming
unresponsive.

The original sign of this issue is guest "pauses" when pasting text
into a serial console connection in something like xterm(1).

Tested by mbuhl@, cheloha@, sashan@, kn@, and mlarkin@.

"go for it", mlarkin@


Revision tags: OPENBSD_7_4_BASE
# 1.37 14-Apr-2023 tb

Add two missing void to appease clang 15

There is another thing clang 15 is whining about - this will be resolved
in upcoming work by dv.

ok dv


Revision tags: OPENBSD_7_3_BASE
# 1.36 10-Nov-2022 mbuhl

Initialize data before passing it to get_input_data. Strictly
speaking this is not necessary as all used bits of the uint32_t are
zeroed.
ok mlarkin


Revision tags: OPENBSD_7_2_BASE
# 1.35 02-Sep-2022 cheloha

vmd(8): compute i8254 read-back command latch from singular timestamp

The intent of the i8254 read-back command is (most likely) to permit
simultaneously latching two or three counters at once along with their
statuses.

To simulate this, we should compute olatch from one timestamp per
read-back command, not one timestamp per counter.

Improved with a tweak by dv@.

Link: https://marc.info/?l=openbsd-tech&m=166213670605453&w=2

ok dv@ mlarkin@


Revision tags: OPENBSD_7_0_BASE OPENBSD_7_1_BASE
# 1.34 16-Jun-2021 dv

cleanup vmd(8) includes and header files

Lots of organic growth other the years lead to unnecessary includes
(proc.h everywhere) and odd dependencies between header files. This
cleans things up a bit to help with upcoming cleanup around dhcp
code.

No functional change.

"go for it" mlarkin@


Revision tags: OPENBSD_6_9_BASE
# 1.33 29-Mar-2021 dv

Cleanly teardown and restore emulated device state on vm send/receive.

This cleans up events on a pause or resume, but also fixes an issue
where the vm_pipe event channels are not properly reinitialized on a
received guest leading to broken serial console.

OK pd@, mlarkin@


Revision tags: OPENBSD_6_8_BASE
# 1.32 28-Jun-2020 pd

vmd(8): Eliminate libevent state corruption

libevent functions for com, pic and rtc are now only called on event_thread.
vcpu exit handlers send messages on a dev pipe and callbacks on these events do
the event management (event_add, evtimer_add, etc). Previously, libevent state
was mutated by two threads, event_thread, that runs all the callbacks and the
vcpu thread when running exit handlers. This could have lead to libevent state
corruption.

Patch from Dave Voutila <dave@sisu.io>

ok claudio@
tested by abieber@ and brynet@


Revision tags: OPENBSD_6_7_BASE
# 1.31 30-Nov-2019 mlarkin

Revert previous - the stability was not as improved as we had thought and
we ended up accidentally breaking vmctl. This will need more thought.

ok ori@


# 1.30 29-Nov-2019 mlarkin

Fix at least one cause of VMs spinning at 100% host CPU

After debugging with ori@, it looks like an event ends up on the wrong
libevent queue, and we end continually de-queueing and re-queueing the
event continually. While it's unclear exactly why this happened, a clue
on libevent's github issues page for the same problem pointed us to using
a different event base for the device events. This seems to have unstuck
ori@'s problematic VM, and I have also seen no more hangs after this.

We have not completely separated the queues; ori@ will work on setting
new libevent bases for those later. But those events are pretty
frequency.

with help from and ok ori@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.29 10-Dec-2018 claudio

No need to \n in log_debug. Part of a larger diff.
OK mlarkin@ ccardenas@


Revision tags: OPENBSD_6_4_BASE
# 1.28 12-Jul-2018 mlarkin

vmm(8)/vmm(4): send a copy of the guest register state to vmd on exit,
avoiding multiple readregs ioctls back to vmm in case register content
is needed subsequently.

ok phessler


# 1.27 09-Jul-2018 mlarkin

vmd(8): deassert interrupt pins in the PIC at the right times. Helps fix
situations where vmd gets stuck at 100% cpu usage because the guest VM
is constantly trying to ack interrupts that already occurred.

tested by phessler on a VM that used to exhibit the issue.

ok phessler


# 1.26 19-Jun-2018 reyk

knf


# 1.25 23-May-2018 mlarkin

vmd(8): revert r1.23 (unlatched PIT reads), this made time go too fast on
some machines. Will investigate and commit a proper fix later.


# 1.24 27-Apr-2018 mlarkin

vmd(8): allow counter state readback via misc port for square wave mode


# 1.23 27-Apr-2018 mlarkin

vmd(8): allow unlatch PIT reads

ok ccardenas


# 1.22 26-Apr-2018 mlarkin

vmd(8): fix some bugs in PIT mode setting

PIT modes are now properly handled, including INTTC mode. This fixes some
bootloader timeouts.

ok brynet


# 1.21 26-Apr-2018 mlarkin

vmd(8): some more long lines that got missed last time


# 1.20 26-Apr-2018 mlarkin

vmd(8): handle PIT channel 2 status readback via port 0x61

Allow PIT channel 2 status (fired/counting) readback via port 0x61
bit 5.

ok guenther@


# 1.19 26-Apr-2018 mlarkin

vmd(8): wrap some long lines


# 1.18 17-Apr-2018 cheloha

Drive i8253 with CLOCK_MONOTONIC.

Ensures that the olatch decrements uniformly, independent of system
wall clock jumps.

While here, roll the olatch computation in i8253_do_readback() into
a loop, and leverage the timespec macros in sys/time.h. Both make the
code a lot more readable.

ok mlarkin@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.17 14-Aug-2017 jasper

whitespace and fix a comment typo


# 1.16 09-Jul-2017 pd

vmd/vmctl: Add ability to pause / unpause vms

With help from Ashwin Agrawal

ok reyk@ mlarkin@


# 1.15 08-May-2017 reyk

Adds functions to read and write state of devices in vmd.

This is required for implementing vmctl send and vmctl receive. vmctl
send / receive are two new options that will support snapshotting VMs
and migrating VMs from one host to another. The atomicio files are
copied from usr.bin/ssh.

Patch from Pratik Vyas; this project was undertaken at San Jose State
University along with his three teammates, Ashwin, Harshada and Siri
with mlarkin@ as the advisor.

OK mlarkin@


# 1.14 28-Apr-2017 mlarkin

rename i8253 "counter" to "channel", a better name for what we are
emulating


# 1.13 08-Apr-2017 mlarkin

implement channels 1 and 2 of the legacy PIT.

ok otto, deraadt


Revision tags: OPENBSD_6_1_BASE
# 1.12 27-Mar-2017 deraadt

die whitespace die die die


# 1.11 25-Mar-2017 mlarkin

Last bits needed to get seabios + alpine linux working. This is enough
to get started and let more people help finding and fixing bugs.

ok kettenis, deraadt


# 1.10 25-Mar-2017 mlarkin

Introduce a new function to obtain properly sized input data, and convert
i8253/i8259/mc146818 emulation to use this.


# 1.9 24-Mar-2017 reyk

Backout mlarkin's previous commit while he is away:
The newly-used function get_input_data() is missing and broke the tree.


# 1.8 24-Mar-2017 mlarkin

Last bits of cleanup for linux/seabios support in i8253/i8259 emulation
code.


# 1.7 23-Mar-2017 mlarkin

Various i8253/i8254 implementation improvements - Fix an error that used
the wrong i/o latch index on reads (resulting in erratic counter values
possibly being read). Also do proper return size setting (don't clobber
%eax high bits).

This diff also implements counter readback mode, which is used in seabios.


# 1.6 19-Mar-2017 mlarkin

Emulated i8253 should not start out in TIMER_RATEGEN mode on boot
automatically. This worked for OpenBSD guests but breaks seabios as soon
as the first interrupt fires since it has not programmed the PIT to do
anything yet. And OpenBSD reprograms the clock to rategen mode as soon
as it boots anyway, so this still works with vmctl(8)'s -k option, as
well as the faux-bootloader implemented in vmd(8)


# 1.5 17-Jan-2017 krw

Nuke some whitespace that keeps poking me in the eye as I try to
steal code.


# 1.4 26-Oct-2016 mlarkin

vmd(8)/vmctl(8) for i386. Some ugliness in #ifdef __i386__ areas will be
fixed in tree, but the changes required were pretty minimal.

Note that i386 hosts are still presently limited to running i386 guests.

ok deraadt, stefan, jca


# 1.3 03-Oct-2016 mlarkin

add RCS tags


# 1.2 01-Sep-2016 mlarkin

change some log_warn to log_warnx and convert some integer literals to
enumerand values


# 1.1 01-Sep-2016 mlarkin

Add a set of emulated legacy devices (PIT, PIC, RTC)

discussed with stefan and deraadt


# 1.37 14-Apr-2023 tb

Add two missing void to appease clang 15

There is another thing clang 15 is whining about - this will be resolved
in upcoming work by dv.

ok dv


Revision tags: OPENBSD_7_3_BASE
# 1.36 10-Nov-2022 mbuhl

Initialize data before passing it to get_input_data. Strictly
speaking this is not necessary as all used bits of the uint32_t are
zeroed.
ok mlarkin


Revision tags: OPENBSD_7_2_BASE
# 1.35 02-Sep-2022 cheloha

vmd(8): compute i8254 read-back command latch from singular timestamp

The intent of the i8254 read-back command is (most likely) to permit
simultaneously latching two or three counters at once along with their
statuses.

To simulate this, we should compute olatch from one timestamp per
read-back command, not one timestamp per counter.

Improved with a tweak by dv@.

Link: https://marc.info/?l=openbsd-tech&m=166213670605453&w=2

ok dv@ mlarkin@


Revision tags: OPENBSD_7_0_BASE OPENBSD_7_1_BASE
# 1.34 16-Jun-2021 dv

cleanup vmd(8) includes and header files

Lots of organic growth other the years lead to unnecessary includes
(proc.h everywhere) and odd dependencies between header files. This
cleans things up a bit to help with upcoming cleanup around dhcp
code.

No functional change.

"go for it" mlarkin@


Revision tags: OPENBSD_6_9_BASE
# 1.33 29-Mar-2021 dv

Cleanly teardown and restore emulated device state on vm send/receive.

This cleans up events on a pause or resume, but also fixes an issue
where the vm_pipe event channels are not properly reinitialized on a
received guest leading to broken serial console.

OK pd@, mlarkin@


Revision tags: OPENBSD_6_8_BASE
# 1.32 28-Jun-2020 pd

vmd(8): Eliminate libevent state corruption

libevent functions for com, pic and rtc are now only called on event_thread.
vcpu exit handlers send messages on a dev pipe and callbacks on these events do
the event management (event_add, evtimer_add, etc). Previously, libevent state
was mutated by two threads, event_thread, that runs all the callbacks and the
vcpu thread when running exit handlers. This could have lead to libevent state
corruption.

Patch from Dave Voutila <dave@sisu.io>

ok claudio@
tested by abieber@ and brynet@


Revision tags: OPENBSD_6_7_BASE
# 1.31 30-Nov-2019 mlarkin

Revert previous - the stability was not as improved as we had thought and
we ended up accidentally breaking vmctl. This will need more thought.

ok ori@


# 1.30 29-Nov-2019 mlarkin

Fix at least one cause of VMs spinning at 100% host CPU

After debugging with ori@, it looks like an event ends up on the wrong
libevent queue, and we end continually de-queueing and re-queueing the
event continually. While it's unclear exactly why this happened, a clue
on libevent's github issues page for the same problem pointed us to using
a different event base for the device events. This seems to have unstuck
ori@'s problematic VM, and I have also seen no more hangs after this.

We have not completely separated the queues; ori@ will work on setting
new libevent bases for those later. But those events are pretty
frequency.

with help from and ok ori@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.29 10-Dec-2018 claudio

No need to \n in log_debug. Part of a larger diff.
OK mlarkin@ ccardenas@


Revision tags: OPENBSD_6_4_BASE
# 1.28 12-Jul-2018 mlarkin

vmm(8)/vmm(4): send a copy of the guest register state to vmd on exit,
avoiding multiple readregs ioctls back to vmm in case register content
is needed subsequently.

ok phessler


# 1.27 09-Jul-2018 mlarkin

vmd(8): deassert interrupt pins in the PIC at the right times. Helps fix
situations where vmd gets stuck at 100% cpu usage because the guest VM
is constantly trying to ack interrupts that already occurred.

tested by phessler on a VM that used to exhibit the issue.

ok phessler


# 1.26 19-Jun-2018 reyk

knf


# 1.25 23-May-2018 mlarkin

vmd(8): revert r1.23 (unlatched PIT reads), this made time go too fast on
some machines. Will investigate and commit a proper fix later.


# 1.24 27-Apr-2018 mlarkin

vmd(8): allow counter state readback via misc port for square wave mode


# 1.23 27-Apr-2018 mlarkin

vmd(8): allow unlatch PIT reads

ok ccardenas


# 1.22 26-Apr-2018 mlarkin

vmd(8): fix some bugs in PIT mode setting

PIT modes are now properly handled, including INTTC mode. This fixes some
bootloader timeouts.

ok brynet


# 1.21 26-Apr-2018 mlarkin

vmd(8): some more long lines that got missed last time


# 1.20 26-Apr-2018 mlarkin

vmd(8): handle PIT channel 2 status readback via port 0x61

Allow PIT channel 2 status (fired/counting) readback via port 0x61
bit 5.

ok guenther@


# 1.19 26-Apr-2018 mlarkin

vmd(8): wrap some long lines


# 1.18 17-Apr-2018 cheloha

Drive i8253 with CLOCK_MONOTONIC.

Ensures that the olatch decrements uniformly, independent of system
wall clock jumps.

While here, roll the olatch computation in i8253_do_readback() into
a loop, and leverage the timespec macros in sys/time.h. Both make the
code a lot more readable.

ok mlarkin@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.17 14-Aug-2017 jasper

whitespace and fix a comment typo


# 1.16 09-Jul-2017 pd

vmd/vmctl: Add ability to pause / unpause vms

With help from Ashwin Agrawal

ok reyk@ mlarkin@


# 1.15 08-May-2017 reyk

Adds functions to read and write state of devices in vmd.

This is required for implementing vmctl send and vmctl receive. vmctl
send / receive are two new options that will support snapshotting VMs
and migrating VMs from one host to another. The atomicio files are
copied from usr.bin/ssh.

Patch from Pratik Vyas; this project was undertaken at San Jose State
University along with his three teammates, Ashwin, Harshada and Siri
with mlarkin@ as the advisor.

OK mlarkin@


# 1.14 28-Apr-2017 mlarkin

rename i8253 "counter" to "channel", a better name for what we are
emulating


# 1.13 08-Apr-2017 mlarkin

implement channels 1 and 2 of the legacy PIT.

ok otto, deraadt


Revision tags: OPENBSD_6_1_BASE
# 1.12 27-Mar-2017 deraadt

die whitespace die die die


# 1.11 25-Mar-2017 mlarkin

Last bits needed to get seabios + alpine linux working. This is enough
to get started and let more people help finding and fixing bugs.

ok kettenis, deraadt


# 1.10 25-Mar-2017 mlarkin

Introduce a new function to obtain properly sized input data, and convert
i8253/i8259/mc146818 emulation to use this.


# 1.9 24-Mar-2017 reyk

Backout mlarkin's previous commit while he is away:
The newly-used function get_input_data() is missing and broke the tree.


# 1.8 24-Mar-2017 mlarkin

Last bits of cleanup for linux/seabios support in i8253/i8259 emulation
code.


# 1.7 23-Mar-2017 mlarkin

Various i8253/i8254 implementation improvements - Fix an error that used
the wrong i/o latch index on reads (resulting in erratic counter values
possibly being read). Also do proper return size setting (don't clobber
%eax high bits).

This diff also implements counter readback mode, which is used in seabios.


# 1.6 19-Mar-2017 mlarkin

Emulated i8253 should not start out in TIMER_RATEGEN mode on boot
automatically. This worked for OpenBSD guests but breaks seabios as soon
as the first interrupt fires since it has not programmed the PIT to do
anything yet. And OpenBSD reprograms the clock to rategen mode as soon
as it boots anyway, so this still works with vmctl(8)'s -k option, as
well as the faux-bootloader implemented in vmd(8)


# 1.5 17-Jan-2017 krw

Nuke some whitespace that keeps poking me in the eye as I try to
steal code.


# 1.4 26-Oct-2016 mlarkin

vmd(8)/vmctl(8) for i386. Some ugliness in #ifdef __i386__ areas will be
fixed in tree, but the changes required were pretty minimal.

Note that i386 hosts are still presently limited to running i386 guests.

ok deraadt, stefan, jca


# 1.3 03-Oct-2016 mlarkin

add RCS tags


# 1.2 01-Sep-2016 mlarkin

change some log_warn to log_warnx and convert some integer literals to
enumerand values


# 1.1 01-Sep-2016 mlarkin

Add a set of emulated legacy devices (PIT, PIC, RTC)

discussed with stefan and deraadt


# 1.36 10-Nov-2022 mbuhl

Initialize data before passing it to get_input_data. Strictly
speaking this is not necessary as all used bits of the uint32_t are
zeroed.
ok mlarkin


Revision tags: OPENBSD_7_2_BASE
# 1.35 02-Sep-2022 cheloha

vmd(8): compute i8254 read-back command latch from singular timestamp

The intent of the i8254 read-back command is (most likely) to permit
simultaneously latching two or three counters at once along with their
statuses.

To simulate this, we should compute olatch from one timestamp per
read-back command, not one timestamp per counter.

Improved with a tweak by dv@.

Link: https://marc.info/?l=openbsd-tech&m=166213670605453&w=2

ok dv@ mlarkin@


Revision tags: OPENBSD_7_0_BASE OPENBSD_7_1_BASE
# 1.34 16-Jun-2021 dv

cleanup vmd(8) includes and header files

Lots of organic growth other the years lead to unnecessary includes
(proc.h everywhere) and odd dependencies between header files. This
cleans things up a bit to help with upcoming cleanup around dhcp
code.

No functional change.

"go for it" mlarkin@


Revision tags: OPENBSD_6_9_BASE
# 1.33 29-Mar-2021 dv

Cleanly teardown and restore emulated device state on vm send/receive.

This cleans up events on a pause or resume, but also fixes an issue
where the vm_pipe event channels are not properly reinitialized on a
received guest leading to broken serial console.

OK pd@, mlarkin@


Revision tags: OPENBSD_6_8_BASE
# 1.32 28-Jun-2020 pd

vmd(8): Eliminate libevent state corruption

libevent functions for com, pic and rtc are now only called on event_thread.
vcpu exit handlers send messages on a dev pipe and callbacks on these events do
the event management (event_add, evtimer_add, etc). Previously, libevent state
was mutated by two threads, event_thread, that runs all the callbacks and the
vcpu thread when running exit handlers. This could have lead to libevent state
corruption.

Patch from Dave Voutila <dave@sisu.io>

ok claudio@
tested by abieber@ and brynet@


Revision tags: OPENBSD_6_7_BASE
# 1.31 30-Nov-2019 mlarkin

Revert previous - the stability was not as improved as we had thought and
we ended up accidentally breaking vmctl. This will need more thought.

ok ori@


# 1.30 29-Nov-2019 mlarkin

Fix at least one cause of VMs spinning at 100% host CPU

After debugging with ori@, it looks like an event ends up on the wrong
libevent queue, and we end continually de-queueing and re-queueing the
event continually. While it's unclear exactly why this happened, a clue
on libevent's github issues page for the same problem pointed us to using
a different event base for the device events. This seems to have unstuck
ori@'s problematic VM, and I have also seen no more hangs after this.

We have not completely separated the queues; ori@ will work on setting
new libevent bases for those later. But those events are pretty
frequency.

with help from and ok ori@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.29 10-Dec-2018 claudio

No need to \n in log_debug. Part of a larger diff.
OK mlarkin@ ccardenas@


Revision tags: OPENBSD_6_4_BASE
# 1.28 12-Jul-2018 mlarkin

vmm(8)/vmm(4): send a copy of the guest register state to vmd on exit,
avoiding multiple readregs ioctls back to vmm in case register content
is needed subsequently.

ok phessler


# 1.27 09-Jul-2018 mlarkin

vmd(8): deassert interrupt pins in the PIC at the right times. Helps fix
situations where vmd gets stuck at 100% cpu usage because the guest VM
is constantly trying to ack interrupts that already occurred.

tested by phessler on a VM that used to exhibit the issue.

ok phessler


# 1.26 19-Jun-2018 reyk

knf


# 1.25 23-May-2018 mlarkin

vmd(8): revert r1.23 (unlatched PIT reads), this made time go too fast on
some machines. Will investigate and commit a proper fix later.


# 1.24 27-Apr-2018 mlarkin

vmd(8): allow counter state readback via misc port for square wave mode


# 1.23 27-Apr-2018 mlarkin

vmd(8): allow unlatch PIT reads

ok ccardenas


# 1.22 26-Apr-2018 mlarkin

vmd(8): fix some bugs in PIT mode setting

PIT modes are now properly handled, including INTTC mode. This fixes some
bootloader timeouts.

ok brynet


# 1.21 26-Apr-2018 mlarkin

vmd(8): some more long lines that got missed last time


# 1.20 26-Apr-2018 mlarkin

vmd(8): handle PIT channel 2 status readback via port 0x61

Allow PIT channel 2 status (fired/counting) readback via port 0x61
bit 5.

ok guenther@


# 1.19 26-Apr-2018 mlarkin

vmd(8): wrap some long lines


# 1.18 17-Apr-2018 cheloha

Drive i8253 with CLOCK_MONOTONIC.

Ensures that the olatch decrements uniformly, independent of system
wall clock jumps.

While here, roll the olatch computation in i8253_do_readback() into
a loop, and leverage the timespec macros in sys/time.h. Both make the
code a lot more readable.

ok mlarkin@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.17 14-Aug-2017 jasper

whitespace and fix a comment typo


# 1.16 09-Jul-2017 pd

vmd/vmctl: Add ability to pause / unpause vms

With help from Ashwin Agrawal

ok reyk@ mlarkin@


# 1.15 08-May-2017 reyk

Adds functions to read and write state of devices in vmd.

This is required for implementing vmctl send and vmctl receive. vmctl
send / receive are two new options that will support snapshotting VMs
and migrating VMs from one host to another. The atomicio files are
copied from usr.bin/ssh.

Patch from Pratik Vyas; this project was undertaken at San Jose State
University along with his three teammates, Ashwin, Harshada and Siri
with mlarkin@ as the advisor.

OK mlarkin@


# 1.14 28-Apr-2017 mlarkin

rename i8253 "counter" to "channel", a better name for what we are
emulating


# 1.13 08-Apr-2017 mlarkin

implement channels 1 and 2 of the legacy PIT.

ok otto, deraadt


Revision tags: OPENBSD_6_1_BASE
# 1.12 27-Mar-2017 deraadt

die whitespace die die die


# 1.11 25-Mar-2017 mlarkin

Last bits needed to get seabios + alpine linux working. This is enough
to get started and let more people help finding and fixing bugs.

ok kettenis, deraadt


# 1.10 25-Mar-2017 mlarkin

Introduce a new function to obtain properly sized input data, and convert
i8253/i8259/mc146818 emulation to use this.


# 1.9 24-Mar-2017 reyk

Backout mlarkin's previous commit while he is away:
The newly-used function get_input_data() is missing and broke the tree.


# 1.8 24-Mar-2017 mlarkin

Last bits of cleanup for linux/seabios support in i8253/i8259 emulation
code.


# 1.7 23-Mar-2017 mlarkin

Various i8253/i8254 implementation improvements - Fix an error that used
the wrong i/o latch index on reads (resulting in erratic counter values
possibly being read). Also do proper return size setting (don't clobber
%eax high bits).

This diff also implements counter readback mode, which is used in seabios.


# 1.6 19-Mar-2017 mlarkin

Emulated i8253 should not start out in TIMER_RATEGEN mode on boot
automatically. This worked for OpenBSD guests but breaks seabios as soon
as the first interrupt fires since it has not programmed the PIT to do
anything yet. And OpenBSD reprograms the clock to rategen mode as soon
as it boots anyway, so this still works with vmctl(8)'s -k option, as
well as the faux-bootloader implemented in vmd(8)


# 1.5 17-Jan-2017 krw

Nuke some whitespace that keeps poking me in the eye as I try to
steal code.


# 1.4 26-Oct-2016 mlarkin

vmd(8)/vmctl(8) for i386. Some ugliness in #ifdef __i386__ areas will be
fixed in tree, but the changes required were pretty minimal.

Note that i386 hosts are still presently limited to running i386 guests.

ok deraadt, stefan, jca


# 1.3 03-Oct-2016 mlarkin

add RCS tags


# 1.2 01-Sep-2016 mlarkin

change some log_warn to log_warnx and convert some integer literals to
enumerand values


# 1.1 01-Sep-2016 mlarkin

Add a set of emulated legacy devices (PIT, PIC, RTC)

discussed with stefan and deraadt


# 1.35 02-Sep-2022 cheloha

vmd(8): compute i8254 read-back command latch from singular timestamp

The intent of the i8254 read-back command is (most likely) to permit
simultaneously latching two or three counters at once along with their
statuses.

To simulate this, we should compute olatch from one timestamp per
read-back command, not one timestamp per counter.

Improved with a tweak by dv@.

Link: https://marc.info/?l=openbsd-tech&m=166213670605453&w=2

ok dv@ mlarkin@


Revision tags: OPENBSD_7_0_BASE OPENBSD_7_1_BASE
# 1.34 16-Jun-2021 dv

cleanup vmd(8) includes and header files

Lots of organic growth other the years lead to unnecessary includes
(proc.h everywhere) and odd dependencies between header files. This
cleans things up a bit to help with upcoming cleanup around dhcp
code.

No functional change.

"go for it" mlarkin@


Revision tags: OPENBSD_6_9_BASE
# 1.33 29-Mar-2021 dv

Cleanly teardown and restore emulated device state on vm send/receive.

This cleans up events on a pause or resume, but also fixes an issue
where the vm_pipe event channels are not properly reinitialized on a
received guest leading to broken serial console.

OK pd@, mlarkin@


Revision tags: OPENBSD_6_8_BASE
# 1.32 28-Jun-2020 pd

vmd(8): Eliminate libevent state corruption

libevent functions for com, pic and rtc are now only called on event_thread.
vcpu exit handlers send messages on a dev pipe and callbacks on these events do
the event management (event_add, evtimer_add, etc). Previously, libevent state
was mutated by two threads, event_thread, that runs all the callbacks and the
vcpu thread when running exit handlers. This could have lead to libevent state
corruption.

Patch from Dave Voutila <dave@sisu.io>

ok claudio@
tested by abieber@ and brynet@


Revision tags: OPENBSD_6_7_BASE
# 1.31 30-Nov-2019 mlarkin

Revert previous - the stability was not as improved as we had thought and
we ended up accidentally breaking vmctl. This will need more thought.

ok ori@


# 1.30 29-Nov-2019 mlarkin

Fix at least one cause of VMs spinning at 100% host CPU

After debugging with ori@, it looks like an event ends up on the wrong
libevent queue, and we end continually de-queueing and re-queueing the
event continually. While it's unclear exactly why this happened, a clue
on libevent's github issues page for the same problem pointed us to using
a different event base for the device events. This seems to have unstuck
ori@'s problematic VM, and I have also seen no more hangs after this.

We have not completely separated the queues; ori@ will work on setting
new libevent bases for those later. But those events are pretty
frequency.

with help from and ok ori@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.29 10-Dec-2018 claudio

No need to \n in log_debug. Part of a larger diff.
OK mlarkin@ ccardenas@


Revision tags: OPENBSD_6_4_BASE
# 1.28 12-Jul-2018 mlarkin

vmm(8)/vmm(4): send a copy of the guest register state to vmd on exit,
avoiding multiple readregs ioctls back to vmm in case register content
is needed subsequently.

ok phessler


# 1.27 09-Jul-2018 mlarkin

vmd(8): deassert interrupt pins in the PIC at the right times. Helps fix
situations where vmd gets stuck at 100% cpu usage because the guest VM
is constantly trying to ack interrupts that already occurred.

tested by phessler on a VM that used to exhibit the issue.

ok phessler


# 1.26 19-Jun-2018 reyk

knf


# 1.25 23-May-2018 mlarkin

vmd(8): revert r1.23 (unlatched PIT reads), this made time go too fast on
some machines. Will investigate and commit a proper fix later.


# 1.24 27-Apr-2018 mlarkin

vmd(8): allow counter state readback via misc port for square wave mode


# 1.23 27-Apr-2018 mlarkin

vmd(8): allow unlatch PIT reads

ok ccardenas


# 1.22 26-Apr-2018 mlarkin

vmd(8): fix some bugs in PIT mode setting

PIT modes are now properly handled, including INTTC mode. This fixes some
bootloader timeouts.

ok brynet


# 1.21 26-Apr-2018 mlarkin

vmd(8): some more long lines that got missed last time


# 1.20 26-Apr-2018 mlarkin

vmd(8): handle PIT channel 2 status readback via port 0x61

Allow PIT channel 2 status (fired/counting) readback via port 0x61
bit 5.

ok guenther@


# 1.19 26-Apr-2018 mlarkin

vmd(8): wrap some long lines


# 1.18 17-Apr-2018 cheloha

Drive i8253 with CLOCK_MONOTONIC.

Ensures that the olatch decrements uniformly, independent of system
wall clock jumps.

While here, roll the olatch computation in i8253_do_readback() into
a loop, and leverage the timespec macros in sys/time.h. Both make the
code a lot more readable.

ok mlarkin@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.17 14-Aug-2017 jasper

whitespace and fix a comment typo


# 1.16 09-Jul-2017 pd

vmd/vmctl: Add ability to pause / unpause vms

With help from Ashwin Agrawal

ok reyk@ mlarkin@


# 1.15 08-May-2017 reyk

Adds functions to read and write state of devices in vmd.

This is required for implementing vmctl send and vmctl receive. vmctl
send / receive are two new options that will support snapshotting VMs
and migrating VMs from one host to another. The atomicio files are
copied from usr.bin/ssh.

Patch from Pratik Vyas; this project was undertaken at San Jose State
University along with his three teammates, Ashwin, Harshada and Siri
with mlarkin@ as the advisor.

OK mlarkin@


# 1.14 28-Apr-2017 mlarkin

rename i8253 "counter" to "channel", a better name for what we are
emulating


# 1.13 08-Apr-2017 mlarkin

implement channels 1 and 2 of the legacy PIT.

ok otto, deraadt


Revision tags: OPENBSD_6_1_BASE
# 1.12 27-Mar-2017 deraadt

die whitespace die die die


# 1.11 25-Mar-2017 mlarkin

Last bits needed to get seabios + alpine linux working. This is enough
to get started and let more people help finding and fixing bugs.

ok kettenis, deraadt


# 1.10 25-Mar-2017 mlarkin

Introduce a new function to obtain properly sized input data, and convert
i8253/i8259/mc146818 emulation to use this.


# 1.9 24-Mar-2017 reyk

Backout mlarkin's previous commit while he is away:
The newly-used function get_input_data() is missing and broke the tree.


# 1.8 24-Mar-2017 mlarkin

Last bits of cleanup for linux/seabios support in i8253/i8259 emulation
code.


# 1.7 23-Mar-2017 mlarkin

Various i8253/i8254 implementation improvements - Fix an error that used
the wrong i/o latch index on reads (resulting in erratic counter values
possibly being read). Also do proper return size setting (don't clobber
%eax high bits).

This diff also implements counter readback mode, which is used in seabios.


# 1.6 19-Mar-2017 mlarkin

Emulated i8253 should not start out in TIMER_RATEGEN mode on boot
automatically. This worked for OpenBSD guests but breaks seabios as soon
as the first interrupt fires since it has not programmed the PIT to do
anything yet. And OpenBSD reprograms the clock to rategen mode as soon
as it boots anyway, so this still works with vmctl(8)'s -k option, as
well as the faux-bootloader implemented in vmd(8)


# 1.5 17-Jan-2017 krw

Nuke some whitespace that keeps poking me in the eye as I try to
steal code.


# 1.4 26-Oct-2016 mlarkin

vmd(8)/vmctl(8) for i386. Some ugliness in #ifdef __i386__ areas will be
fixed in tree, but the changes required were pretty minimal.

Note that i386 hosts are still presently limited to running i386 guests.

ok deraadt, stefan, jca


# 1.3 03-Oct-2016 mlarkin

add RCS tags


# 1.2 01-Sep-2016 mlarkin

change some log_warn to log_warnx and convert some integer literals to
enumerand values


# 1.1 01-Sep-2016 mlarkin

Add a set of emulated legacy devices (PIT, PIC, RTC)

discussed with stefan and deraadt


# 1.34 16-Jun-2021 dv

cleanup vmd(8) includes and header files

Lots of organic growth other the years lead to unnecessary includes
(proc.h everywhere) and odd dependencies between header files. This
cleans things up a bit to help with upcoming cleanup around dhcp
code.

No functional change.

"go for it" mlarkin@


Revision tags: OPENBSD_6_9_BASE
# 1.33 29-Mar-2021 dv

Cleanly teardown and restore emulated device state on vm send/receive.

This cleans up events on a pause or resume, but also fixes an issue
where the vm_pipe event channels are not properly reinitialized on a
received guest leading to broken serial console.

OK pd@, mlarkin@


Revision tags: OPENBSD_6_8_BASE
# 1.32 28-Jun-2020 pd

vmd(8): Eliminate libevent state corruption

libevent functions for com, pic and rtc are now only called on event_thread.
vcpu exit handlers send messages on a dev pipe and callbacks on these events do
the event management (event_add, evtimer_add, etc). Previously, libevent state
was mutated by two threads, event_thread, that runs all the callbacks and the
vcpu thread when running exit handlers. This could have lead to libevent state
corruption.

Patch from Dave Voutila <dave@sisu.io>

ok claudio@
tested by abieber@ and brynet@


Revision tags: OPENBSD_6_7_BASE
# 1.31 30-Nov-2019 mlarkin

Revert previous - the stability was not as improved as we had thought and
we ended up accidentally breaking vmctl. This will need more thought.

ok ori@


# 1.30 29-Nov-2019 mlarkin

Fix at least one cause of VMs spinning at 100% host CPU

After debugging with ori@, it looks like an event ends up on the wrong
libevent queue, and we end continually de-queueing and re-queueing the
event continually. While it's unclear exactly why this happened, a clue
on libevent's github issues page for the same problem pointed us to using
a different event base for the device events. This seems to have unstuck
ori@'s problematic VM, and I have also seen no more hangs after this.

We have not completely separated the queues; ori@ will work on setting
new libevent bases for those later. But those events are pretty
frequency.

with help from and ok ori@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.29 10-Dec-2018 claudio

No need to \n in log_debug. Part of a larger diff.
OK mlarkin@ ccardenas@


Revision tags: OPENBSD_6_4_BASE
# 1.28 12-Jul-2018 mlarkin

vmm(8)/vmm(4): send a copy of the guest register state to vmd on exit,
avoiding multiple readregs ioctls back to vmm in case register content
is needed subsequently.

ok phessler


# 1.27 09-Jul-2018 mlarkin

vmd(8): deassert interrupt pins in the PIC at the right times. Helps fix
situations where vmd gets stuck at 100% cpu usage because the guest VM
is constantly trying to ack interrupts that already occurred.

tested by phessler on a VM that used to exhibit the issue.

ok phessler


# 1.26 19-Jun-2018 reyk

knf


# 1.25 23-May-2018 mlarkin

vmd(8): revert r1.23 (unlatched PIT reads), this made time go too fast on
some machines. Will investigate and commit a proper fix later.


# 1.24 27-Apr-2018 mlarkin

vmd(8): allow counter state readback via misc port for square wave mode


# 1.23 27-Apr-2018 mlarkin

vmd(8): allow unlatch PIT reads

ok ccardenas


# 1.22 26-Apr-2018 mlarkin

vmd(8): fix some bugs in PIT mode setting

PIT modes are now properly handled, including INTTC mode. This fixes some
bootloader timeouts.

ok brynet


# 1.21 26-Apr-2018 mlarkin

vmd(8): some more long lines that got missed last time


# 1.20 26-Apr-2018 mlarkin

vmd(8): handle PIT channel 2 status readback via port 0x61

Allow PIT channel 2 status (fired/counting) readback via port 0x61
bit 5.

ok guenther@


# 1.19 26-Apr-2018 mlarkin

vmd(8): wrap some long lines


# 1.18 17-Apr-2018 cheloha

Drive i8253 with CLOCK_MONOTONIC.

Ensures that the olatch decrements uniformly, independent of system
wall clock jumps.

While here, roll the olatch computation in i8253_do_readback() into
a loop, and leverage the timespec macros in sys/time.h. Both make the
code a lot more readable.

ok mlarkin@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.17 14-Aug-2017 jasper

whitespace and fix a comment typo


# 1.16 09-Jul-2017 pd

vmd/vmctl: Add ability to pause / unpause vms

With help from Ashwin Agrawal

ok reyk@ mlarkin@


# 1.15 08-May-2017 reyk

Adds functions to read and write state of devices in vmd.

This is required for implementing vmctl send and vmctl receive. vmctl
send / receive are two new options that will support snapshotting VMs
and migrating VMs from one host to another. The atomicio files are
copied from usr.bin/ssh.

Patch from Pratik Vyas; this project was undertaken at San Jose State
University along with his three teammates, Ashwin, Harshada and Siri
with mlarkin@ as the advisor.

OK mlarkin@


# 1.14 28-Apr-2017 mlarkin

rename i8253 "counter" to "channel", a better name for what we are
emulating


# 1.13 08-Apr-2017 mlarkin

implement channels 1 and 2 of the legacy PIT.

ok otto, deraadt


Revision tags: OPENBSD_6_1_BASE
# 1.12 27-Mar-2017 deraadt

die whitespace die die die


# 1.11 25-Mar-2017 mlarkin

Last bits needed to get seabios + alpine linux working. This is enough
to get started and let more people help finding and fixing bugs.

ok kettenis, deraadt


# 1.10 25-Mar-2017 mlarkin

Introduce a new function to obtain properly sized input data, and convert
i8253/i8259/mc146818 emulation to use this.


# 1.9 24-Mar-2017 reyk

Backout mlarkin's previous commit while he is away:
The newly-used function get_input_data() is missing and broke the tree.


# 1.8 24-Mar-2017 mlarkin

Last bits of cleanup for linux/seabios support in i8253/i8259 emulation
code.


# 1.7 23-Mar-2017 mlarkin

Various i8253/i8254 implementation improvements - Fix an error that used
the wrong i/o latch index on reads (resulting in erratic counter values
possibly being read). Also do proper return size setting (don't clobber
%eax high bits).

This diff also implements counter readback mode, which is used in seabios.


# 1.6 19-Mar-2017 mlarkin

Emulated i8253 should not start out in TIMER_RATEGEN mode on boot
automatically. This worked for OpenBSD guests but breaks seabios as soon
as the first interrupt fires since it has not programmed the PIT to do
anything yet. And OpenBSD reprograms the clock to rategen mode as soon
as it boots anyway, so this still works with vmctl(8)'s -k option, as
well as the faux-bootloader implemented in vmd(8)


# 1.5 17-Jan-2017 krw

Nuke some whitespace that keeps poking me in the eye as I try to
steal code.


# 1.4 26-Oct-2016 mlarkin

vmd(8)/vmctl(8) for i386. Some ugliness in #ifdef __i386__ areas will be
fixed in tree, but the changes required were pretty minimal.

Note that i386 hosts are still presently limited to running i386 guests.

ok deraadt, stefan, jca


# 1.3 03-Oct-2016 mlarkin

add RCS tags


# 1.2 01-Sep-2016 mlarkin

change some log_warn to log_warnx and convert some integer literals to
enumerand values


# 1.1 01-Sep-2016 mlarkin

Add a set of emulated legacy devices (PIT, PIC, RTC)

discussed with stefan and deraadt


# 1.33 29-Mar-2021 dv

Cleanly teardown and restore emulated device state on vm send/receive.

This cleans up events on a pause or resume, but also fixes an issue
where the vm_pipe event channels are not properly reinitialized on a
received guest leading to broken serial console.

OK pd@, mlarkin@


Revision tags: OPENBSD_6_8_BASE
# 1.32 28-Jun-2020 pd

vmd(8): Eliminate libevent state corruption

libevent functions for com, pic and rtc are now only called on event_thread.
vcpu exit handlers send messages on a dev pipe and callbacks on these events do
the event management (event_add, evtimer_add, etc). Previously, libevent state
was mutated by two threads, event_thread, that runs all the callbacks and the
vcpu thread when running exit handlers. This could have lead to libevent state
corruption.

Patch from Dave Voutila <dave@sisu.io>

ok claudio@
tested by abieber@ and brynet@


Revision tags: OPENBSD_6_7_BASE
# 1.31 30-Nov-2019 mlarkin

Revert previous - the stability was not as improved as we had thought and
we ended up accidentally breaking vmctl. This will need more thought.

ok ori@


# 1.30 29-Nov-2019 mlarkin

Fix at least one cause of VMs spinning at 100% host CPU

After debugging with ori@, it looks like an event ends up on the wrong
libevent queue, and we end continually de-queueing and re-queueing the
event continually. While it's unclear exactly why this happened, a clue
on libevent's github issues page for the same problem pointed us to using
a different event base for the device events. This seems to have unstuck
ori@'s problematic VM, and I have also seen no more hangs after this.

We have not completely separated the queues; ori@ will work on setting
new libevent bases for those later. But those events are pretty
frequency.

with help from and ok ori@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.29 10-Dec-2018 claudio

No need to \n in log_debug. Part of a larger diff.
OK mlarkin@ ccardenas@


Revision tags: OPENBSD_6_4_BASE
# 1.28 12-Jul-2018 mlarkin

vmm(8)/vmm(4): send a copy of the guest register state to vmd on exit,
avoiding multiple readregs ioctls back to vmm in case register content
is needed subsequently.

ok phessler


# 1.27 09-Jul-2018 mlarkin

vmd(8): deassert interrupt pins in the PIC at the right times. Helps fix
situations where vmd gets stuck at 100% cpu usage because the guest VM
is constantly trying to ack interrupts that already occurred.

tested by phessler on a VM that used to exhibit the issue.

ok phessler


# 1.26 19-Jun-2018 reyk

knf


# 1.25 23-May-2018 mlarkin

vmd(8): revert r1.23 (unlatched PIT reads), this made time go too fast on
some machines. Will investigate and commit a proper fix later.


# 1.24 27-Apr-2018 mlarkin

vmd(8): allow counter state readback via misc port for square wave mode


# 1.23 27-Apr-2018 mlarkin

vmd(8): allow unlatch PIT reads

ok ccardenas


# 1.22 26-Apr-2018 mlarkin

vmd(8): fix some bugs in PIT mode setting

PIT modes are now properly handled, including INTTC mode. This fixes some
bootloader timeouts.

ok brynet


# 1.21 26-Apr-2018 mlarkin

vmd(8): some more long lines that got missed last time


# 1.20 26-Apr-2018 mlarkin

vmd(8): handle PIT channel 2 status readback via port 0x61

Allow PIT channel 2 status (fired/counting) readback via port 0x61
bit 5.

ok guenther@


# 1.19 26-Apr-2018 mlarkin

vmd(8): wrap some long lines


# 1.18 17-Apr-2018 cheloha

Drive i8253 with CLOCK_MONOTONIC.

Ensures that the olatch decrements uniformly, independent of system
wall clock jumps.

While here, roll the olatch computation in i8253_do_readback() into
a loop, and leverage the timespec macros in sys/time.h. Both make the
code a lot more readable.

ok mlarkin@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.17 14-Aug-2017 jasper

whitespace and fix a comment typo


# 1.16 09-Jul-2017 pd

vmd/vmctl: Add ability to pause / unpause vms

With help from Ashwin Agrawal

ok reyk@ mlarkin@


# 1.15 08-May-2017 reyk

Adds functions to read and write state of devices in vmd.

This is required for implementing vmctl send and vmctl receive. vmctl
send / receive are two new options that will support snapshotting VMs
and migrating VMs from one host to another. The atomicio files are
copied from usr.bin/ssh.

Patch from Pratik Vyas; this project was undertaken at San Jose State
University along with his three teammates, Ashwin, Harshada and Siri
with mlarkin@ as the advisor.

OK mlarkin@


# 1.14 28-Apr-2017 mlarkin

rename i8253 "counter" to "channel", a better name for what we are
emulating


# 1.13 08-Apr-2017 mlarkin

implement channels 1 and 2 of the legacy PIT.

ok otto, deraadt


Revision tags: OPENBSD_6_1_BASE
# 1.12 27-Mar-2017 deraadt

die whitespace die die die


# 1.11 25-Mar-2017 mlarkin

Last bits needed to get seabios + alpine linux working. This is enough
to get started and let more people help finding and fixing bugs.

ok kettenis, deraadt


# 1.10 25-Mar-2017 mlarkin

Introduce a new function to obtain properly sized input data, and convert
i8253/i8259/mc146818 emulation to use this.


# 1.9 24-Mar-2017 reyk

Backout mlarkin's previous commit while he is away:
The newly-used function get_input_data() is missing and broke the tree.


# 1.8 24-Mar-2017 mlarkin

Last bits of cleanup for linux/seabios support in i8253/i8259 emulation
code.


# 1.7 23-Mar-2017 mlarkin

Various i8253/i8254 implementation improvements - Fix an error that used
the wrong i/o latch index on reads (resulting in erratic counter values
possibly being read). Also do proper return size setting (don't clobber
%eax high bits).

This diff also implements counter readback mode, which is used in seabios.


# 1.6 19-Mar-2017 mlarkin

Emulated i8253 should not start out in TIMER_RATEGEN mode on boot
automatically. This worked for OpenBSD guests but breaks seabios as soon
as the first interrupt fires since it has not programmed the PIT to do
anything yet. And OpenBSD reprograms the clock to rategen mode as soon
as it boots anyway, so this still works with vmctl(8)'s -k option, as
well as the faux-bootloader implemented in vmd(8)


# 1.5 17-Jan-2017 krw

Nuke some whitespace that keeps poking me in the eye as I try to
steal code.


# 1.4 26-Oct-2016 mlarkin

vmd(8)/vmctl(8) for i386. Some ugliness in #ifdef __i386__ areas will be
fixed in tree, but the changes required were pretty minimal.

Note that i386 hosts are still presently limited to running i386 guests.

ok deraadt, stefan, jca


# 1.3 03-Oct-2016 mlarkin

add RCS tags


# 1.2 01-Sep-2016 mlarkin

change some log_warn to log_warnx and convert some integer literals to
enumerand values


# 1.1 01-Sep-2016 mlarkin

Add a set of emulated legacy devices (PIT, PIC, RTC)

discussed with stefan and deraadt


# 1.32 28-Jun-2020 pd

vmd(8): Eliminate libevent state corruption

libevent functions for com, pic and rtc are now only called on event_thread.
vcpu exit handlers send messages on a dev pipe and callbacks on these events do
the event management (event_add, evtimer_add, etc). Previously, libevent state
was mutated by two threads, event_thread, that runs all the callbacks and the
vcpu thread when running exit handlers. This could have lead to libevent state
corruption.

Patch from Dave Voutila <dave@sisu.io>

ok claudio@
tested by abieber@ and brynet@


Revision tags: OPENBSD_6_7_BASE
# 1.31 30-Nov-2019 mlarkin

Revert previous - the stability was not as improved as we had thought and
we ended up accidentally breaking vmctl. This will need more thought.

ok ori@


# 1.30 29-Nov-2019 mlarkin

Fix at least one cause of VMs spinning at 100% host CPU

After debugging with ori@, it looks like an event ends up on the wrong
libevent queue, and we end continually de-queueing and re-queueing the
event continually. While it's unclear exactly why this happened, a clue
on libevent's github issues page for the same problem pointed us to using
a different event base for the device events. This seems to have unstuck
ori@'s problematic VM, and I have also seen no more hangs after this.

We have not completely separated the queues; ori@ will work on setting
new libevent bases for those later. But those events are pretty
frequency.

with help from and ok ori@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.29 10-Dec-2018 claudio

No need to \n in log_debug. Part of a larger diff.
OK mlarkin@ ccardenas@


Revision tags: OPENBSD_6_4_BASE
# 1.28 12-Jul-2018 mlarkin

vmm(8)/vmm(4): send a copy of the guest register state to vmd on exit,
avoiding multiple readregs ioctls back to vmm in case register content
is needed subsequently.

ok phessler


# 1.27 09-Jul-2018 mlarkin

vmd(8): deassert interrupt pins in the PIC at the right times. Helps fix
situations where vmd gets stuck at 100% cpu usage because the guest VM
is constantly trying to ack interrupts that already occurred.

tested by phessler on a VM that used to exhibit the issue.

ok phessler


# 1.26 19-Jun-2018 reyk

knf


# 1.25 23-May-2018 mlarkin

vmd(8): revert r1.23 (unlatched PIT reads), this made time go too fast on
some machines. Will investigate and commit a proper fix later.


# 1.24 27-Apr-2018 mlarkin

vmd(8): allow counter state readback via misc port for square wave mode


# 1.23 27-Apr-2018 mlarkin

vmd(8): allow unlatch PIT reads

ok ccardenas


# 1.22 26-Apr-2018 mlarkin

vmd(8): fix some bugs in PIT mode setting

PIT modes are now properly handled, including INTTC mode. This fixes some
bootloader timeouts.

ok brynet


# 1.21 26-Apr-2018 mlarkin

vmd(8): some more long lines that got missed last time


# 1.20 26-Apr-2018 mlarkin

vmd(8): handle PIT channel 2 status readback via port 0x61

Allow PIT channel 2 status (fired/counting) readback via port 0x61
bit 5.

ok guenther@


# 1.19 26-Apr-2018 mlarkin

vmd(8): wrap some long lines


# 1.18 17-Apr-2018 cheloha

Drive i8253 with CLOCK_MONOTONIC.

Ensures that the olatch decrements uniformly, independent of system
wall clock jumps.

While here, roll the olatch computation in i8253_do_readback() into
a loop, and leverage the timespec macros in sys/time.h. Both make the
code a lot more readable.

ok mlarkin@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.17 14-Aug-2017 jasper

whitespace and fix a comment typo


# 1.16 09-Jul-2017 pd

vmd/vmctl: Add ability to pause / unpause vms

With help from Ashwin Agrawal

ok reyk@ mlarkin@


# 1.15 08-May-2017 reyk

Adds functions to read and write state of devices in vmd.

This is required for implementing vmctl send and vmctl receive. vmctl
send / receive are two new options that will support snapshotting VMs
and migrating VMs from one host to another. The atomicio files are
copied from usr.bin/ssh.

Patch from Pratik Vyas; this project was undertaken at San Jose State
University along with his three teammates, Ashwin, Harshada and Siri
with mlarkin@ as the advisor.

OK mlarkin@


# 1.14 28-Apr-2017 mlarkin

rename i8253 "counter" to "channel", a better name for what we are
emulating


# 1.13 08-Apr-2017 mlarkin

implement channels 1 and 2 of the legacy PIT.

ok otto, deraadt


Revision tags: OPENBSD_6_1_BASE
# 1.12 27-Mar-2017 deraadt

die whitespace die die die


# 1.11 25-Mar-2017 mlarkin

Last bits needed to get seabios + alpine linux working. This is enough
to get started and let more people help finding and fixing bugs.

ok kettenis, deraadt


# 1.10 25-Mar-2017 mlarkin

Introduce a new function to obtain properly sized input data, and convert
i8253/i8259/mc146818 emulation to use this.


# 1.9 24-Mar-2017 reyk

Backout mlarkin's previous commit while he is away:
The newly-used function get_input_data() is missing and broke the tree.


# 1.8 24-Mar-2017 mlarkin

Last bits of cleanup for linux/seabios support in i8253/i8259 emulation
code.


# 1.7 23-Mar-2017 mlarkin

Various i8253/i8254 implementation improvements - Fix an error that used
the wrong i/o latch index on reads (resulting in erratic counter values
possibly being read). Also do proper return size setting (don't clobber
%eax high bits).

This diff also implements counter readback mode, which is used in seabios.


# 1.6 19-Mar-2017 mlarkin

Emulated i8253 should not start out in TIMER_RATEGEN mode on boot
automatically. This worked for OpenBSD guests but breaks seabios as soon
as the first interrupt fires since it has not programmed the PIT to do
anything yet. And OpenBSD reprograms the clock to rategen mode as soon
as it boots anyway, so this still works with vmctl(8)'s -k option, as
well as the faux-bootloader implemented in vmd(8)


# 1.5 17-Jan-2017 krw

Nuke some whitespace that keeps poking me in the eye as I try to
steal code.


# 1.4 26-Oct-2016 mlarkin

vmd(8)/vmctl(8) for i386. Some ugliness in #ifdef __i386__ areas will be
fixed in tree, but the changes required were pretty minimal.

Note that i386 hosts are still presently limited to running i386 guests.

ok deraadt, stefan, jca


# 1.3 03-Oct-2016 mlarkin

add RCS tags


# 1.2 01-Sep-2016 mlarkin

change some log_warn to log_warnx and convert some integer literals to
enumerand values


# 1.1 01-Sep-2016 mlarkin

Add a set of emulated legacy devices (PIT, PIC, RTC)

discussed with stefan and deraadt


# 1.31 30-Nov-2019 mlarkin

Revert previous - the stability was not as improved as we had thought and
we ended up accidentally breaking vmctl. This will need more thought.

ok ori@


# 1.30 29-Nov-2019 mlarkin

Fix at least one cause of VMs spinning at 100% host CPU

After debugging with ori@, it looks like an event ends up on the wrong
libevent queue, and we end continually de-queueing and re-queueing the
event continually. While it's unclear exactly why this happened, a clue
on libevent's github issues page for the same problem pointed us to using
a different event base for the device events. This seems to have unstuck
ori@'s problematic VM, and I have also seen no more hangs after this.

We have not completely separated the queues; ori@ will work on setting
new libevent bases for those later. But those events are pretty
frequency.

with help from and ok ori@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.29 10-Dec-2018 claudio

No need to \n in log_debug. Part of a larger diff.
OK mlarkin@ ccardenas@


Revision tags: OPENBSD_6_4_BASE
# 1.28 12-Jul-2018 mlarkin

vmm(8)/vmm(4): send a copy of the guest register state to vmd on exit,
avoiding multiple readregs ioctls back to vmm in case register content
is needed subsequently.

ok phessler


# 1.27 09-Jul-2018 mlarkin

vmd(8): deassert interrupt pins in the PIC at the right times. Helps fix
situations where vmd gets stuck at 100% cpu usage because the guest VM
is constantly trying to ack interrupts that already occurred.

tested by phessler on a VM that used to exhibit the issue.

ok phessler


# 1.26 19-Jun-2018 reyk

knf


# 1.25 23-May-2018 mlarkin

vmd(8): revert r1.23 (unlatched PIT reads), this made time go too fast on
some machines. Will investigate and commit a proper fix later.


# 1.24 27-Apr-2018 mlarkin

vmd(8): allow counter state readback via misc port for square wave mode


# 1.23 27-Apr-2018 mlarkin

vmd(8): allow unlatch PIT reads

ok ccardenas


# 1.22 26-Apr-2018 mlarkin

vmd(8): fix some bugs in PIT mode setting

PIT modes are now properly handled, including INTTC mode. This fixes some
bootloader timeouts.

ok brynet


# 1.21 26-Apr-2018 mlarkin

vmd(8): some more long lines that got missed last time


# 1.20 26-Apr-2018 mlarkin

vmd(8): handle PIT channel 2 status readback via port 0x61

Allow PIT channel 2 status (fired/counting) readback via port 0x61
bit 5.

ok guenther@


# 1.19 26-Apr-2018 mlarkin

vmd(8): wrap some long lines


# 1.18 17-Apr-2018 cheloha

Drive i8253 with CLOCK_MONOTONIC.

Ensures that the olatch decrements uniformly, independent of system
wall clock jumps.

While here, roll the olatch computation in i8253_do_readback() into
a loop, and leverage the timespec macros in sys/time.h. Both make the
code a lot more readable.

ok mlarkin@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.17 14-Aug-2017 jasper

whitespace and fix a comment typo


# 1.16 09-Jul-2017 pd

vmd/vmctl: Add ability to pause / unpause vms

With help from Ashwin Agrawal

ok reyk@ mlarkin@


# 1.15 08-May-2017 reyk

Adds functions to read and write state of devices in vmd.

This is required for implementing vmctl send and vmctl receive. vmctl
send / receive are two new options that will support snapshotting VMs
and migrating VMs from one host to another. The atomicio files are
copied from usr.bin/ssh.

Patch from Pratik Vyas; this project was undertaken at San Jose State
University along with his three teammates, Ashwin, Harshada and Siri
with mlarkin@ as the advisor.

OK mlarkin@


# 1.14 28-Apr-2017 mlarkin

rename i8253 "counter" to "channel", a better name for what we are
emulating


# 1.13 08-Apr-2017 mlarkin

implement channels 1 and 2 of the legacy PIT.

ok otto, deraadt


Revision tags: OPENBSD_6_1_BASE
# 1.12 27-Mar-2017 deraadt

die whitespace die die die


# 1.11 25-Mar-2017 mlarkin

Last bits needed to get seabios + alpine linux working. This is enough
to get started and let more people help finding and fixing bugs.

ok kettenis, deraadt


# 1.10 25-Mar-2017 mlarkin

Introduce a new function to obtain properly sized input data, and convert
i8253/i8259/mc146818 emulation to use this.


# 1.9 24-Mar-2017 reyk

Backout mlarkin's previous commit while he is away:
The newly-used function get_input_data() is missing and broke the tree.


# 1.8 24-Mar-2017 mlarkin

Last bits of cleanup for linux/seabios support in i8253/i8259 emulation
code.


# 1.7 23-Mar-2017 mlarkin

Various i8253/i8254 implementation improvements - Fix an error that used
the wrong i/o latch index on reads (resulting in erratic counter values
possibly being read). Also do proper return size setting (don't clobber
%eax high bits).

This diff also implements counter readback mode, which is used in seabios.


# 1.6 19-Mar-2017 mlarkin

Emulated i8253 should not start out in TIMER_RATEGEN mode on boot
automatically. This worked for OpenBSD guests but breaks seabios as soon
as the first interrupt fires since it has not programmed the PIT to do
anything yet. And OpenBSD reprograms the clock to rategen mode as soon
as it boots anyway, so this still works with vmctl(8)'s -k option, as
well as the faux-bootloader implemented in vmd(8)


# 1.5 17-Jan-2017 krw

Nuke some whitespace that keeps poking me in the eye as I try to
steal code.


# 1.4 26-Oct-2016 mlarkin

vmd(8)/vmctl(8) for i386. Some ugliness in #ifdef __i386__ areas will be
fixed in tree, but the changes required were pretty minimal.

Note that i386 hosts are still presently limited to running i386 guests.

ok deraadt, stefan, jca


# 1.3 03-Oct-2016 mlarkin

add RCS tags


# 1.2 01-Sep-2016 mlarkin

change some log_warn to log_warnx and convert some integer literals to
enumerand values


# 1.1 01-Sep-2016 mlarkin

Add a set of emulated legacy devices (PIT, PIC, RTC)

discussed with stefan and deraadt


# 1.30 29-Nov-2019 mlarkin

Fix at least one cause of VMs spinning at 100% host CPU

After debugging with ori@, it looks like an event ends up on the wrong
libevent queue, and we end continually de-queueing and re-queueing the
event continually. While it's unclear exactly why this happened, a clue
on libevent's github issues page for the same problem pointed us to using
a different event base for the device events. This seems to have unstuck
ori@'s problematic VM, and I have also seen no more hangs after this.

We have not completely separated the queues; ori@ will work on setting
new libevent bases for those later. But those events are pretty
frequency.

with help from and ok ori@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.29 10-Dec-2018 claudio

No need to \n in log_debug. Part of a larger diff.
OK mlarkin@ ccardenas@


Revision tags: OPENBSD_6_4_BASE
# 1.28 12-Jul-2018 mlarkin

vmm(8)/vmm(4): send a copy of the guest register state to vmd on exit,
avoiding multiple readregs ioctls back to vmm in case register content
is needed subsequently.

ok phessler


# 1.27 09-Jul-2018 mlarkin

vmd(8): deassert interrupt pins in the PIC at the right times. Helps fix
situations where vmd gets stuck at 100% cpu usage because the guest VM
is constantly trying to ack interrupts that already occurred.

tested by phessler on a VM that used to exhibit the issue.

ok phessler


# 1.26 19-Jun-2018 reyk

knf


# 1.25 23-May-2018 mlarkin

vmd(8): revert r1.23 (unlatched PIT reads), this made time go too fast on
some machines. Will investigate and commit a proper fix later.


# 1.24 27-Apr-2018 mlarkin

vmd(8): allow counter state readback via misc port for square wave mode


# 1.23 27-Apr-2018 mlarkin

vmd(8): allow unlatch PIT reads

ok ccardenas


# 1.22 26-Apr-2018 mlarkin

vmd(8): fix some bugs in PIT mode setting

PIT modes are now properly handled, including INTTC mode. This fixes some
bootloader timeouts.

ok brynet


# 1.21 26-Apr-2018 mlarkin

vmd(8): some more long lines that got missed last time


# 1.20 26-Apr-2018 mlarkin

vmd(8): handle PIT channel 2 status readback via port 0x61

Allow PIT channel 2 status (fired/counting) readback via port 0x61
bit 5.

ok guenther@


# 1.19 26-Apr-2018 mlarkin

vmd(8): wrap some long lines


# 1.18 17-Apr-2018 cheloha

Drive i8253 with CLOCK_MONOTONIC.

Ensures that the olatch decrements uniformly, independent of system
wall clock jumps.

While here, roll the olatch computation in i8253_do_readback() into
a loop, and leverage the timespec macros in sys/time.h. Both make the
code a lot more readable.

ok mlarkin@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.17 14-Aug-2017 jasper

whitespace and fix a comment typo


# 1.16 09-Jul-2017 pd

vmd/vmctl: Add ability to pause / unpause vms

With help from Ashwin Agrawal

ok reyk@ mlarkin@


# 1.15 08-May-2017 reyk

Adds functions to read and write state of devices in vmd.

This is required for implementing vmctl send and vmctl receive. vmctl
send / receive are two new options that will support snapshotting VMs
and migrating VMs from one host to another. The atomicio files are
copied from usr.bin/ssh.

Patch from Pratik Vyas; this project was undertaken at San Jose State
University along with his three teammates, Ashwin, Harshada and Siri
with mlarkin@ as the advisor.

OK mlarkin@


# 1.14 28-Apr-2017 mlarkin

rename i8253 "counter" to "channel", a better name for what we are
emulating


# 1.13 08-Apr-2017 mlarkin

implement channels 1 and 2 of the legacy PIT.

ok otto, deraadt


Revision tags: OPENBSD_6_1_BASE
# 1.12 27-Mar-2017 deraadt

die whitespace die die die


# 1.11 25-Mar-2017 mlarkin

Last bits needed to get seabios + alpine linux working. This is enough
to get started and let more people help finding and fixing bugs.

ok kettenis, deraadt


# 1.10 25-Mar-2017 mlarkin

Introduce a new function to obtain properly sized input data, and convert
i8253/i8259/mc146818 emulation to use this.


# 1.9 24-Mar-2017 reyk

Backout mlarkin's previous commit while he is away:
The newly-used function get_input_data() is missing and broke the tree.


# 1.8 24-Mar-2017 mlarkin

Last bits of cleanup for linux/seabios support in i8253/i8259 emulation
code.


# 1.7 23-Mar-2017 mlarkin

Various i8253/i8254 implementation improvements - Fix an error that used
the wrong i/o latch index on reads (resulting in erratic counter values
possibly being read). Also do proper return size setting (don't clobber
%eax high bits).

This diff also implements counter readback mode, which is used in seabios.


# 1.6 19-Mar-2017 mlarkin

Emulated i8253 should not start out in TIMER_RATEGEN mode on boot
automatically. This worked for OpenBSD guests but breaks seabios as soon
as the first interrupt fires since it has not programmed the PIT to do
anything yet. And OpenBSD reprograms the clock to rategen mode as soon
as it boots anyway, so this still works with vmctl(8)'s -k option, as
well as the faux-bootloader implemented in vmd(8)


# 1.5 17-Jan-2017 krw

Nuke some whitespace that keeps poking me in the eye as I try to
steal code.


# 1.4 26-Oct-2016 mlarkin

vmd(8)/vmctl(8) for i386. Some ugliness in #ifdef __i386__ areas will be
fixed in tree, but the changes required were pretty minimal.

Note that i386 hosts are still presently limited to running i386 guests.

ok deraadt, stefan, jca


# 1.3 03-Oct-2016 mlarkin

add RCS tags


# 1.2 01-Sep-2016 mlarkin

change some log_warn to log_warnx and convert some integer literals to
enumerand values


# 1.1 01-Sep-2016 mlarkin

Add a set of emulated legacy devices (PIT, PIC, RTC)

discussed with stefan and deraadt


# 1.29 10-Dec-2018 claudio

No need to \n in log_debug. Part of a larger diff.
OK mlarkin@ ccardenas@


Revision tags: OPENBSD_6_4_BASE
# 1.28 12-Jul-2018 mlarkin

vmm(8)/vmm(4): send a copy of the guest register state to vmd on exit,
avoiding multiple readregs ioctls back to vmm in case register content
is needed subsequently.

ok phessler


# 1.27 09-Jul-2018 mlarkin

vmd(8): deassert interrupt pins in the PIC at the right times. Helps fix
situations where vmd gets stuck at 100% cpu usage because the guest VM
is constantly trying to ack interrupts that already occurred.

tested by phessler on a VM that used to exhibit the issue.

ok phessler


# 1.26 19-Jun-2018 reyk

knf


# 1.25 23-May-2018 mlarkin

vmd(8): revert r1.23 (unlatched PIT reads), this made time go too fast on
some machines. Will investigate and commit a proper fix later.


# 1.24 27-Apr-2018 mlarkin

vmd(8): allow counter state readback via misc port for square wave mode


# 1.23 27-Apr-2018 mlarkin

vmd(8): allow unlatch PIT reads

ok ccardenas


# 1.22 26-Apr-2018 mlarkin

vmd(8): fix some bugs in PIT mode setting

PIT modes are now properly handled, including INTTC mode. This fixes some
bootloader timeouts.

ok brynet


# 1.21 26-Apr-2018 mlarkin

vmd(8): some more long lines that got missed last time


# 1.20 26-Apr-2018 mlarkin

vmd(8): handle PIT channel 2 status readback via port 0x61

Allow PIT channel 2 status (fired/counting) readback via port 0x61
bit 5.

ok guenther@


# 1.19 26-Apr-2018 mlarkin

vmd(8): wrap some long lines


# 1.18 17-Apr-2018 cheloha

Drive i8253 with CLOCK_MONOTONIC.

Ensures that the olatch decrements uniformly, independent of system
wall clock jumps.

While here, roll the olatch computation in i8253_do_readback() into
a loop, and leverage the timespec macros in sys/time.h. Both make the
code a lot more readable.

ok mlarkin@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.17 14-Aug-2017 jasper

whitespace and fix a comment typo


# 1.16 09-Jul-2017 pd

vmd/vmctl: Add ability to pause / unpause vms

With help from Ashwin Agrawal

ok reyk@ mlarkin@


# 1.15 08-May-2017 reyk

Adds functions to read and write state of devices in vmd.

This is required for implementing vmctl send and vmctl receive. vmctl
send / receive are two new options that will support snapshotting VMs
and migrating VMs from one host to another. The atomicio files are
copied from usr.bin/ssh.

Patch from Pratik Vyas; this project was undertaken at San Jose State
University along with his three teammates, Ashwin, Harshada and Siri
with mlarkin@ as the advisor.

OK mlarkin@


# 1.14 28-Apr-2017 mlarkin

rename i8253 "counter" to "channel", a better name for what we are
emulating


# 1.13 08-Apr-2017 mlarkin

implement channels 1 and 2 of the legacy PIT.

ok otto, deraadt


Revision tags: OPENBSD_6_1_BASE
# 1.12 27-Mar-2017 deraadt

die whitespace die die die


# 1.11 25-Mar-2017 mlarkin

Last bits needed to get seabios + alpine linux working. This is enough
to get started and let more people help finding and fixing bugs.

ok kettenis, deraadt


# 1.10 25-Mar-2017 mlarkin

Introduce a new function to obtain properly sized input data, and convert
i8253/i8259/mc146818 emulation to use this.


# 1.9 24-Mar-2017 reyk

Backout mlarkin's previous commit while he is away:
The newly-used function get_input_data() is missing and broke the tree.


# 1.8 24-Mar-2017 mlarkin

Last bits of cleanup for linux/seabios support in i8253/i8259 emulation
code.


# 1.7 23-Mar-2017 mlarkin

Various i8253/i8254 implementation improvements - Fix an error that used
the wrong i/o latch index on reads (resulting in erratic counter values
possibly being read). Also do proper return size setting (don't clobber
%eax high bits).

This diff also implements counter readback mode, which is used in seabios.


# 1.6 19-Mar-2017 mlarkin

Emulated i8253 should not start out in TIMER_RATEGEN mode on boot
automatically. This worked for OpenBSD guests but breaks seabios as soon
as the first interrupt fires since it has not programmed the PIT to do
anything yet. And OpenBSD reprograms the clock to rategen mode as soon
as it boots anyway, so this still works with vmctl(8)'s -k option, as
well as the faux-bootloader implemented in vmd(8)


# 1.5 17-Jan-2017 krw

Nuke some whitespace that keeps poking me in the eye as I try to
steal code.


# 1.4 26-Oct-2016 mlarkin

vmd(8)/vmctl(8) for i386. Some ugliness in #ifdef __i386__ areas will be
fixed in tree, but the changes required were pretty minimal.

Note that i386 hosts are still presently limited to running i386 guests.

ok deraadt, stefan, jca


# 1.3 03-Oct-2016 mlarkin

add RCS tags


# 1.2 01-Sep-2016 mlarkin

change some log_warn to log_warnx and convert some integer literals to
enumerand values


# 1.1 01-Sep-2016 mlarkin

Add a set of emulated legacy devices (PIT, PIC, RTC)

discussed with stefan and deraadt


# 1.28 12-Jul-2018 mlarkin

vmm(8)/vmm(4): send a copy of the guest register state to vmd on exit,
avoiding multiple readregs ioctls back to vmm in case register content
is needed subsequently.

ok phessler


# 1.27 09-Jul-2018 mlarkin

vmd(8): deassert interrupt pins in the PIC at the right times. Helps fix
situations where vmd gets stuck at 100% cpu usage because the guest VM
is constantly trying to ack interrupts that already occurred.

tested by phessler on a VM that used to exhibit the issue.

ok phessler


# 1.26 19-Jun-2018 reyk

knf


# 1.25 23-May-2018 mlarkin

vmd(8): revert r1.23 (unlatched PIT reads), this made time go too fast on
some machines. Will investigate and commit a proper fix later.


# 1.24 27-Apr-2018 mlarkin

vmd(8): allow counter state readback via misc port for square wave mode


# 1.23 27-Apr-2018 mlarkin

vmd(8): allow unlatch PIT reads

ok ccardenas


# 1.22 26-Apr-2018 mlarkin

vmd(8): fix some bugs in PIT mode setting

PIT modes are now properly handled, including INTTC mode. This fixes some
bootloader timeouts.

ok brynet


# 1.21 26-Apr-2018 mlarkin

vmd(8): some more long lines that got missed last time


# 1.20 26-Apr-2018 mlarkin

vmd(8): handle PIT channel 2 status readback via port 0x61

Allow PIT channel 2 status (fired/counting) readback via port 0x61
bit 5.

ok guenther@


# 1.19 26-Apr-2018 mlarkin

vmd(8): wrap some long lines


# 1.18 17-Apr-2018 cheloha

Drive i8253 with CLOCK_MONOTONIC.

Ensures that the olatch decrements uniformly, independent of system
wall clock jumps.

While here, roll the olatch computation in i8253_do_readback() into
a loop, and leverage the timespec macros in sys/time.h. Both make the
code a lot more readable.

ok mlarkin@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.17 14-Aug-2017 jasper

whitespace and fix a comment typo


# 1.16 09-Jul-2017 pd

vmd/vmctl: Add ability to pause / unpause vms

With help from Ashwin Agrawal

ok reyk@ mlarkin@


# 1.15 08-May-2017 reyk

Adds functions to read and write state of devices in vmd.

This is required for implementing vmctl send and vmctl receive. vmctl
send / receive are two new options that will support snapshotting VMs
and migrating VMs from one host to another. The atomicio files are
copied from usr.bin/ssh.

Patch from Pratik Vyas; this project was undertaken at San Jose State
University along with his three teammates, Ashwin, Harshada and Siri
with mlarkin@ as the advisor.

OK mlarkin@


# 1.14 28-Apr-2017 mlarkin

rename i8253 "counter" to "channel", a better name for what we are
emulating


# 1.13 08-Apr-2017 mlarkin

implement channels 1 and 2 of the legacy PIT.

ok otto, deraadt


Revision tags: OPENBSD_6_1_BASE
# 1.12 27-Mar-2017 deraadt

die whitespace die die die


# 1.11 25-Mar-2017 mlarkin

Last bits needed to get seabios + alpine linux working. This is enough
to get started and let more people help finding and fixing bugs.

ok kettenis, deraadt


# 1.10 25-Mar-2017 mlarkin

Introduce a new function to obtain properly sized input data, and convert
i8253/i8259/mc146818 emulation to use this.


# 1.9 24-Mar-2017 reyk

Backout mlarkin's previous commit while he is away:
The newly-used function get_input_data() is missing and broke the tree.


# 1.8 24-Mar-2017 mlarkin

Last bits of cleanup for linux/seabios support in i8253/i8259 emulation
code.


# 1.7 23-Mar-2017 mlarkin

Various i8253/i8254 implementation improvements - Fix an error that used
the wrong i/o latch index on reads (resulting in erratic counter values
possibly being read). Also do proper return size setting (don't clobber
%eax high bits).

This diff also implements counter readback mode, which is used in seabios.


# 1.6 19-Mar-2017 mlarkin

Emulated i8253 should not start out in TIMER_RATEGEN mode on boot
automatically. This worked for OpenBSD guests but breaks seabios as soon
as the first interrupt fires since it has not programmed the PIT to do
anything yet. And OpenBSD reprograms the clock to rategen mode as soon
as it boots anyway, so this still works with vmctl(8)'s -k option, as
well as the faux-bootloader implemented in vmd(8)


# 1.5 17-Jan-2017 krw

Nuke some whitespace that keeps poking me in the eye as I try to
steal code.


# 1.4 26-Oct-2016 mlarkin

vmd(8)/vmctl(8) for i386. Some ugliness in #ifdef __i386__ areas will be
fixed in tree, but the changes required were pretty minimal.

Note that i386 hosts are still presently limited to running i386 guests.

ok deraadt, stefan, jca


# 1.3 03-Oct-2016 mlarkin

add RCS tags


# 1.2 01-Sep-2016 mlarkin

change some log_warn to log_warnx and convert some integer literals to
enumerand values


# 1.1 01-Sep-2016 mlarkin

Add a set of emulated legacy devices (PIT, PIC, RTC)

discussed with stefan and deraadt


# 1.26 19-Jun-2018 reyk

knf


# 1.25 23-May-2018 mlarkin

vmd(8): revert r1.23 (unlatched PIT reads), this made time go too fast on
some machines. Will investigate and commit a proper fix later.


# 1.24 27-Apr-2018 mlarkin

vmd(8): allow counter state readback via misc port for square wave mode


# 1.23 27-Apr-2018 mlarkin

vmd(8): allow unlatch PIT reads

ok ccardenas


# 1.22 26-Apr-2018 mlarkin

vmd(8): fix some bugs in PIT mode setting

PIT modes are now properly handled, including INTTC mode. This fixes some
bootloader timeouts.

ok brynet


# 1.21 26-Apr-2018 mlarkin

vmd(8): some more long lines that got missed last time


# 1.20 26-Apr-2018 mlarkin

vmd(8): handle PIT channel 2 status readback via port 0x61

Allow PIT channel 2 status (fired/counting) readback via port 0x61
bit 5.

ok guenther@


# 1.19 26-Apr-2018 mlarkin

vmd(8): wrap some long lines


# 1.18 17-Apr-2018 cheloha

Drive i8253 with CLOCK_MONOTONIC.

Ensures that the olatch decrements uniformly, independent of system
wall clock jumps.

While here, roll the olatch computation in i8253_do_readback() into
a loop, and leverage the timespec macros in sys/time.h. Both make the
code a lot more readable.

ok mlarkin@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.17 14-Aug-2017 jasper

whitespace and fix a comment typo


# 1.16 09-Jul-2017 pd

vmd/vmctl: Add ability to pause / unpause vms

With help from Ashwin Agrawal

ok reyk@ mlarkin@


# 1.15 08-May-2017 reyk

Adds functions to read and write state of devices in vmd.

This is required for implementing vmctl send and vmctl receive. vmctl
send / receive are two new options that will support snapshotting VMs
and migrating VMs from one host to another. The atomicio files are
copied from usr.bin/ssh.

Patch from Pratik Vyas; this project was undertaken at San Jose State
University along with his three teammates, Ashwin, Harshada and Siri
with mlarkin@ as the advisor.

OK mlarkin@


# 1.14 28-Apr-2017 mlarkin

rename i8253 "counter" to "channel", a better name for what we are
emulating


# 1.13 08-Apr-2017 mlarkin

implement channels 1 and 2 of the legacy PIT.

ok otto, deraadt


Revision tags: OPENBSD_6_1_BASE
# 1.12 27-Mar-2017 deraadt

die whitespace die die die


# 1.11 25-Mar-2017 mlarkin

Last bits needed to get seabios + alpine linux working. This is enough
to get started and let more people help finding and fixing bugs.

ok kettenis, deraadt


# 1.10 25-Mar-2017 mlarkin

Introduce a new function to obtain properly sized input data, and convert
i8253/i8259/mc146818 emulation to use this.


# 1.9 24-Mar-2017 reyk

Backout mlarkin's previous commit while he is away:
The newly-used function get_input_data() is missing and broke the tree.


# 1.8 24-Mar-2017 mlarkin

Last bits of cleanup for linux/seabios support in i8253/i8259 emulation
code.


# 1.7 23-Mar-2017 mlarkin

Various i8253/i8254 implementation improvements - Fix an error that used
the wrong i/o latch index on reads (resulting in erratic counter values
possibly being read). Also do proper return size setting (don't clobber
%eax high bits).

This diff also implements counter readback mode, which is used in seabios.


# 1.6 19-Mar-2017 mlarkin

Emulated i8253 should not start out in TIMER_RATEGEN mode on boot
automatically. This worked for OpenBSD guests but breaks seabios as soon
as the first interrupt fires since it has not programmed the PIT to do
anything yet. And OpenBSD reprograms the clock to rategen mode as soon
as it boots anyway, so this still works with vmctl(8)'s -k option, as
well as the faux-bootloader implemented in vmd(8)


# 1.5 17-Jan-2017 krw

Nuke some whitespace that keeps poking me in the eye as I try to
steal code.


# 1.4 26-Oct-2016 mlarkin

vmd(8)/vmctl(8) for i386. Some ugliness in #ifdef __i386__ areas will be
fixed in tree, but the changes required were pretty minimal.

Note that i386 hosts are still presently limited to running i386 guests.

ok deraadt, stefan, jca


# 1.3 03-Oct-2016 mlarkin

add RCS tags


# 1.2 01-Sep-2016 mlarkin

change some log_warn to log_warnx and convert some integer literals to
enumerand values


# 1.1 01-Sep-2016 mlarkin

Add a set of emulated legacy devices (PIT, PIC, RTC)

discussed with stefan and deraadt


# 1.24 27-Apr-2018 mlarkin

vmd(8): allow counter state readback via misc port for square wave mode


# 1.23 27-Apr-2018 mlarkin

vmd(8): allow unlatch PIT reads

ok ccardenas


# 1.22 26-Apr-2018 mlarkin

vmd(8): fix some bugs in PIT mode setting

PIT modes are now properly handled, including INTTC mode. This fixes some
bootloader timeouts.

ok brynet


# 1.21 26-Apr-2018 mlarkin

vmd(8): some more long lines that got missed last time


# 1.20 26-Apr-2018 mlarkin

vmd(8): handle PIT channel 2 status readback via port 0x61

Allow PIT channel 2 status (fired/counting) readback via port 0x61
bit 5.

ok guenther@


# 1.19 26-Apr-2018 mlarkin

vmd(8): wrap some long lines


# 1.18 17-Apr-2018 cheloha

Drive i8253 with CLOCK_MONOTONIC.

Ensures that the olatch decrements uniformly, independent of system
wall clock jumps.

While here, roll the olatch computation in i8253_do_readback() into
a loop, and leverage the timespec macros in sys/time.h. Both make the
code a lot more readable.

ok mlarkin@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.17 14-Aug-2017 jasper

whitespace and fix a comment typo


# 1.16 09-Jul-2017 pd

vmd/vmctl: Add ability to pause / unpause vms

With help from Ashwin Agrawal

ok reyk@ mlarkin@


# 1.15 08-May-2017 reyk

Adds functions to read and write state of devices in vmd.

This is required for implementing vmctl send and vmctl receive. vmctl
send / receive are two new options that will support snapshotting VMs
and migrating VMs from one host to another. The atomicio files are
copied from usr.bin/ssh.

Patch from Pratik Vyas; this project was undertaken at San Jose State
University along with his three teammates, Ashwin, Harshada and Siri
with mlarkin@ as the advisor.

OK mlarkin@


# 1.14 28-Apr-2017 mlarkin

rename i8253 "counter" to "channel", a better name for what we are
emulating


# 1.13 08-Apr-2017 mlarkin

implement channels 1 and 2 of the legacy PIT.

ok otto, deraadt


Revision tags: OPENBSD_6_1_BASE
# 1.12 27-Mar-2017 deraadt

die whitespace die die die


# 1.11 25-Mar-2017 mlarkin

Last bits needed to get seabios + alpine linux working. This is enough
to get started and let more people help finding and fixing bugs.

ok kettenis, deraadt


# 1.10 25-Mar-2017 mlarkin

Introduce a new function to obtain properly sized input data, and convert
i8253/i8259/mc146818 emulation to use this.


# 1.9 24-Mar-2017 reyk

Backout mlarkin's previous commit while he is away:
The newly-used function get_input_data() is missing and broke the tree.


# 1.8 24-Mar-2017 mlarkin

Last bits of cleanup for linux/seabios support in i8253/i8259 emulation
code.


# 1.7 23-Mar-2017 mlarkin

Various i8253/i8254 implementation improvements - Fix an error that used
the wrong i/o latch index on reads (resulting in erratic counter values
possibly being read). Also do proper return size setting (don't clobber
%eax high bits).

This diff also implements counter readback mode, which is used in seabios.


# 1.6 19-Mar-2017 mlarkin

Emulated i8253 should not start out in TIMER_RATEGEN mode on boot
automatically. This worked for OpenBSD guests but breaks seabios as soon
as the first interrupt fires since it has not programmed the PIT to do
anything yet. And OpenBSD reprograms the clock to rategen mode as soon
as it boots anyway, so this still works with vmctl(8)'s -k option, as
well as the faux-bootloader implemented in vmd(8)


# 1.5 17-Jan-2017 krw

Nuke some whitespace that keeps poking me in the eye as I try to
steal code.


# 1.4 26-Oct-2016 mlarkin

vmd(8)/vmctl(8) for i386. Some ugliness in #ifdef __i386__ areas will be
fixed in tree, but the changes required were pretty minimal.

Note that i386 hosts are still presently limited to running i386 guests.

ok deraadt, stefan, jca


# 1.3 03-Oct-2016 mlarkin

add RCS tags


# 1.2 01-Sep-2016 mlarkin

change some log_warn to log_warnx and convert some integer literals to
enumerand values


# 1.1 01-Sep-2016 mlarkin

Add a set of emulated legacy devices (PIT, PIC, RTC)

discussed with stefan and deraadt


Revision tags: OPENBSD_6_2_BASE
# 1.17 14-Aug-2017 jasper

whitespace and fix a comment typo


# 1.16 09-Jul-2017 pd

vmd/vmctl: Add ability to pause / unpause vms

With help from Ashwin Agrawal

ok reyk@ mlarkin@


# 1.15 08-May-2017 reyk

Adds functions to read and write state of devices in vmd.

This is required for implementing vmctl send and vmctl receive. vmctl
send / receive are two new options that will support snapshotting VMs
and migrating VMs from one host to another. The atomicio files are
copied from usr.bin/ssh.

Patch from Pratik Vyas; this project was undertaken at San Jose State
University along with his three teammates, Ashwin, Harshada and Siri
with mlarkin@ as the advisor.

OK mlarkin@


# 1.14 28-Apr-2017 mlarkin

rename i8253 "counter" to "channel", a better name for what we are
emulating


# 1.13 08-Apr-2017 mlarkin

implement channels 1 and 2 of the legacy PIT.

ok otto, deraadt


Revision tags: OPENBSD_6_1_BASE
# 1.12 27-Mar-2017 deraadt

die whitespace die die die


# 1.11 25-Mar-2017 mlarkin

Last bits needed to get seabios + alpine linux working. This is enough
to get started and let more people help finding and fixing bugs.

ok kettenis, deraadt


# 1.10 25-Mar-2017 mlarkin

Introduce a new function to obtain properly sized input data, and convert
i8253/i8259/mc146818 emulation to use this.


# 1.9 24-Mar-2017 reyk

Backout mlarkin's previous commit while he is away:
The newly-used function get_input_data() is missing and broke the tree.


# 1.8 24-Mar-2017 mlarkin

Last bits of cleanup for linux/seabios support in i8253/i8259 emulation
code.


# 1.7 23-Mar-2017 mlarkin

Various i8253/i8254 implementation improvements - Fix an error that used
the wrong i/o latch index on reads (resulting in erratic counter values
possibly being read). Also do proper return size setting (don't clobber
%eax high bits).

This diff also implements counter readback mode, which is used in seabios.


# 1.6 19-Mar-2017 mlarkin

Emulated i8253 should not start out in TIMER_RATEGEN mode on boot
automatically. This worked for OpenBSD guests but breaks seabios as soon
as the first interrupt fires since it has not programmed the PIT to do
anything yet. And OpenBSD reprograms the clock to rategen mode as soon
as it boots anyway, so this still works with vmctl(8)'s -k option, as
well as the faux-bootloader implemented in vmd(8)


# 1.5 17-Jan-2017 krw

Nuke some whitespace that keeps poking me in the eye as I try to
steal code.


# 1.4 26-Oct-2016 mlarkin

vmd(8)/vmctl(8) for i386. Some ugliness in #ifdef __i386__ areas will be
fixed in tree, but the changes required were pretty minimal.

Note that i386 hosts are still presently limited to running i386 guests.

ok deraadt, stefan, jca


# 1.3 03-Oct-2016 mlarkin

add RCS tags


# 1.2 01-Sep-2016 mlarkin

change some log_warn to log_warnx and convert some integer literals to
enumerand values


# 1.1 01-Sep-2016 mlarkin

Add a set of emulated legacy devices (PIT, PIC, RTC)

discussed with stefan and deraadt