Intrinsic Function Overwrite
Nios® II software operates on top of the board support package (BSP) for the Nios® II processor. BSP provides many useful application programming interfaces (APIs) which assist software to execute on the Nios® II processor and interact with hardware. For Nios® II software, the hardware interaction means reading from or writing to certain registers in a certain way. Therefore, the System Mock can intercept these read or write (RW) operations to model the Nios® II software interactions with hardware.
In the Nios® II BSP, there are macros defined for register RW. The commonly used ones are IORD, IORD_32DIRECT, IOWR, and IOWR_32DIRECT. These macros call built-in functions __builtin_ldwio and __builtin_stwio. System Mock can provide new definitions for these built-in functions. Overwrite the definitions of these built-in functions to redirect the memory access and augment it with side effects.
One caveat of this technique is that developers must write code in a certain way. All Avalon® memory-mapped interface RW operations must use function calls (for example: IORD/IOWR). Memory access through pointers is allowed in this unit-test framework. The prerequisite is that the System Mock has allocated a memory block and replaced the base address in Nios® II code appropriately. However, System Mock cannot intercept or augment these pointer-based memory access.