hardware software co-simulation in HDL simulator
There is no concept of hardware software co-simulation on a general purpose, average CPU, since the CPU does not have the processing power to emulate hardware real-time in a fashion that is timing-accurate. You want to emulate hardware in a fashion that is timing-accurate since you want the software to run on the hardware and be able to debug it a timing-accurate fashion.
A more appropriate term would be Hardware-Software Co-Verification to describe the process of verifying that the software correctly runs on the hardware.
In practice, 3 options are used for hardware-software co-verification:

Emulation: Specialised hardware called an emulator or emulation-box is used. The software runs on the hardware using an emulation box. Emulators usually provide high visibility of the system, so you can step through the C program and debug it.

Hardware co-simulation using an FPGA: This is also known as Hardware in the loop simulation. It is supported by some FPGA vendors like Xilinx. The basic idea is that instead of simulating hardware, you synthesize it on an FPGA. The debugging of the system can be done by connecting the FPGA to a CPU using PCIe. The FPGA communicates with the CPU in real time.

Use a Transaction-Level or functional Model: The idea is &quot;Things which are equal to the same thing are equal to one another.&quot; A transaction-level model is at a higher abstraction than RTL, so it can be simulated on a CPU much faster than RTL. A transaction level model can be functional, cycle-accurate etc.  To do hardware software co-verification, first verify the working of the software by running it on the Transaction-Level model. This can be done on a CPU, since it is not timing accurate. Then verify the validity of the transaction-level model by co-simulating it with the HDL simulator, using DPI for SystemVerilog or VHPI for VHDL. The transaction-level model can be written in C, C++ or SystemC. Alternatively gem5 or QEMU can also be used to co-simulate with the RTL model.