My best bet is that
A) you have forgotten to connect the data-bus to the processor. You do that in sopc builder.
Second posibilty is the cache..
B) Change your pointer to..
char *on_chip_memory = ((char *)(0x80000000 | ONCHIP_MEMORY_0_BASE) );
Setting MSB of the address bypasses the cache.
C) Optimizer is too 'clever' in this case. Depending on your code and optimization level, you may get this kind of seemingly 'strange' results because the optimizer has seen that you effectively are not doing anything with the data. It simply removes the code. Set optimization to off in nios IDE. You can also counteract optimization by using volatile intermediate variables.
volatile char vChar;
vChar = on_chip_memory;
on_chip_memory = vChar;
But I recall to have read somewhere that
volatile char *on_chip_memory = ((char *)ONCHIP_MEMORY_0_BASE);
does NOT help with this kind of cache problems. In this case its the pointer which is volatile, not the data. Maybe someone else could comment on this?
D) You are right not to change the .rodata and .rwdata. This wont help for what you are doing.