Nios® II Software Developer Handbook

ID 683525
Date 8/28/2023
Public
Document Table of Contents

10.3.1. Assembly Code to Initialize the Instruction Cache

Place the initi instruction in a loop that executes initi for each instruction cache line address.

Example 9–2. Assembly Code to Initialize the Instruction Cache

mov r4, r0
movhi r5, %hi(NIOS2_ICACHE_SIZE)
ori r5, r5, %lo(NIOS2_ICACHE_SIZE)
icache_init_loop:
initi r4
addi r4, r4, NIOS2_ICACHE_LINE_SIZE
bltu r4, r5, icache_init_loop

After the instruction cache is initialized, the data cache must also be initialized. The Nios® II initd instruction initializes a single data cache line. Do not use the flushd instruction for this purpose, because it writes dirty lines back to memory. The data cache is undefined after reset, including the cache line tags. Using flushd can cause unexpected writes of random data to random addresses. The initd instruction does not write back dirty data.