Forum Discussion
Altera_Forum
Honored Contributor
15 years agoFor those of you masking your pointers with | 0x80000000 please use the cache remapping functions for your pointers instead. Sometimes what you are doing is safe but if you do that with a memory location that is already cached you may (probably) run into a cache coherency issue where your code attempts to bypass a location that is already cached!
The cache remapping functions perform a cache flush to ensure the locations you may be accessing are truly flushed from the cache and safe to access directly. For example if I did this in my code (not clean just proving a point....): int * my_ptr = (int *)malloc (4); IOWR_32DIRECT((unsigned long)my_ptr, 0, 0xdeadbeef); You would expect 0xdeadbeef to be written out to memory with whatever location malloc returned. Not necessarily..... If for example the location returned by malloc contained data that was already cached (taken from the heap), this IOWR at a hardware level will cause the cached value to be written out instead of the software intended 0xdeadbeef. If you are thinking "well that's a hardware bug".... well not really because if 0xdeadbeef went out like you want, eventually a cache line miss at this location will occur and whatever was in the cache will get flushed out eventually (blowing away 0xdeadbeef). Cache coherency problems like these are a big pain to debug so my recommendation is to write clean code using the proper software APIs provided to you and then you won't have to debug issues like these later.