Co-simulation requires two concurrent processes: QEMU (the hardware/software emulator) and the SystemC simulator (the hardware model).
Terminal 1: QEMU
Run QEMU using the virt-cosim machine and point it to the modified virt.dtb. You must also configure a remote-port-net device to connect to the co-sim engine.
Terminal 2: SystemC
Run the compiled LMAC demo binary, pointing it to the socket created by QEMU in /tmp/machine-riscv64/.
Verification:
When Linux boots, check the kernel logs. You should see a message indicating the discovery of the LMAC device:
lmac2 28030000.lmac2: Lewiz at 0x28030000 mapped to 0xFFFFFFFF44020000, tx-irq=9 rx-irq=11
# Terminal 1: QEMU
mkdir /tmp/machine-riscv64/
qemu-system-riscv64 -M virt-cosim -smp 4 -serial stdio -display none -m 2G \
-dtb virt.dtb -bios opensbi-riscv64-virt-fw_jump.bin -kernel Image \
-append "root=/dev/vda ro console=ttyS0" \
-drive file=rootfs.ext2,format=raw,id=hd0 \
-device virtio-blk-device,drive=hd0 \
-object rng-random,filename=/dev/urandom,id=rng0 \
-device virtio-rng-device,rng=rng0 \
-device virtio-net-device,netdev=usernet -netdev user,id=usernet \
-netdev user,id=net4 \
-device remote-port-net,rp-adaptor0=/machine/cosim,rp-chan0=256,rp-chan1=266,netdev=net4 \
-machine-path /tmp/machine-riscv64
# Terminal 2: SystemC
riscv_virt_lmac2_demo unix:/tmp/machine-riscv64/qemu-rport-_machine_cosim 10000