osWritebackDCache (function)

osWritebackDCache, osWritebackDCacheAll

Writes back CPU data cache lines to physical memory


#include <ultra64.h>        /* os.h */
void osWritebackDCache(void *vaddr, s32 nbytes);
void osWritebackDCacheAll(void);


The MIPS R4300 CPU implements an 8 Kbyte direct-mapped data cache with a line size of 16 bytes. This cache uses a "write back" format. This means that, usually data stores are done only to a cache. When a cache miss occurs the cache is written back to memory for the first time, once the cache line is replaced. Thus, the content of the cache and the physical memory do not always agree. Due to this fact, if you are going to use rewritten memory you must write back the data cache content to memory.

osWritebackDCache function writes back all data cache lines that contain the region [vaddr, vaddr + nbytes- 1]. The argument address vaddr must be a CPU virtual address, either direct mapped or mapped via the CPU TLB. If vaddr is not aligned to the cache line boundary, and nbytes is not a multiple of the cache line size, a slightly larger region may be written back to memory.

osWritebackDCacheAll function writes back all cached locations to physical memory.

This function is used in the situation where a direct memory access (DMA) device needs to read data in the memory, but the data is still stored in the cache. In this case, the memory is out of date with respect to the cache, and the cache lines must be written back prior to performing the DMA operation.

Additional Description

The osWritebackDCacheAll and osWritebackDCachel functions do the following operations.

Writes back all data cache lines and invalidates them.

If nbytes < 8192: writes back data cache lines that contain the region of [vaddr, vaddr+nbytes- 1]. (does not invalidate them.)
If nbytes >= 8192: writes back all data cache lines and invalidates them.

See Also

osMapTLB, osInvalDCache, osInvalICache

Revision History

04/30/1999 Changed Format

11/05/1999 Retranslated "Description." Added "Additional Description."