Altera_Forum
Honored Contributor
12 years agoSwitch to shadow register set - ea problem
Hi, all!
I can not switch to shadow register set. I am trying to do this in my main() function, outside any interrupt handler. I am using directions from the "Changing Register Sets" section of the Nios II Processor Reference Handbook (here is a link (http://www.altera.com/literature/hb/nios2/n2cpu_nii51003.pdf#page=28)). Directions are: If the processor is currently running in the normal register set, insert the new register set number in estatus.CRS, and execute eret. Here is my code, placed in the main() (project is created from Hello world template):
// prologue
asm("addi sp,sp,-8");
asm("stw r16,0(sp)");
asm("stw r17,4(sp)");
// estatus.CRS = 1
asm("movhi r16,0xffff");
asm("ori r16,r16,0x03ff");
asm("rdctl r17,status");
asm("and r17,r17,r16");
asm("ori r17,r17,0x0400");
asm("wrctl estatus,r17");
// switch
asm("eret"); // <------- processor hangs here
// wrap
asm("ldw r16,0(sp)");
asm("ldw r17,4(sp)");
asm("addi sp,sp,8");
The problem is that processor hangs on eret because ea - register with the return address - points to eret itself. I tried to change ea manually with something like addi ea,ea,8, but this does not help. Is there any way to properly adjust the ea before eret? And is it possible to change a register set in the main? I would appreciate any help or advice. With regards, Olga