rust-vmm / vm-superio

Emulation for legacy devices
Apache License 2.0
30 stars 25 forks source link

Add save/restore for Serial device #73

Closed sabin-rapan closed 2 years ago

sabin-rapan commented 2 years ago

Add support for saving and restoring the state (registers) of the serial device. This follows the same pattern in RTC (https://github.com/rust-vmm/vm-superio/pull/65) by adding SerialState and SerialStateSer structs, where the former is a plain container for the data and the later mirrors it and derives Serialize, Deserialize and Versionize. Both structures gives the caller full access to their fields. Apart from handling input buffers larger than FIFO_SIZE and retriggering interrupts that haven't been consumed by the driver, the current proposal makes no sanity checks on the fields in the state struct. This means, for example, one could set the upper four bits in IER register which is invalid. If such sanity checks are desired, we can adjust the PR with a follow-up commit.