CharlyCst / miralis

Miralis is an experimental system that virtualises firmware
https://miralis-firmware.github.io/
MIT License
13 stars 0 forks source link

Add `test` virtual device #160

Closed CharlyCst closed 2 months ago

CharlyCst commented 2 months ago

We had support for virtual devices since we first introduced the virtual CLINT. Our support for virtual devices seems to work in practice but it is hard to test as the CLINT (like all real devices) has side effects when writing to it.

The goal of this issue is to write a new virtual device that can be used for testing. The virtual device should be called "TestVirtDevice" and should be backed by an array of, say, 32 bytes on which it is possible to read and write from a payload.

Then we can create a new test firmware that tries to read and write to the device (by doing simple loads and store to memory, devices are MMIO). At this stage we can discuss what should be the behavior of the device (e.g. incrementing a memory-mapped counter for instance) and how to test it properly.

Background:

A virtual device is an instance of the VirtDevice struct, the kind of device depends in the device_interface. The device_interface is a handle to a static device, usually behind a lock to prevent data races.

https://github.com/CharlyCst/miralis/blob/f3a62e80af9dcd96e4f96db698d829248a2d682c/src/device.rs#L49-L54

Devices are declared in the host Miralis context:

https://github.com/CharlyCst/miralis/blob/f3a62e80af9dcd96e4f96db698d829248a2d682c/src/host.rs#L29

They are protected by PMP, thus when a firmware tries to access a device it traps to Miralis. When Miralis detects a PMP fault it checks if the address corresponds to a device, and forward the read or write to the device.