Altera_Forum
Honored Contributor
20 years agoamazing error
Hi!
I submitted a similar error time ago, but now the "ghosts" have appeared again. I have a program calls a function many times. This function has a static variable called "gState" (mapped in ram, static), which is initialized at the beginning of the program. When the function is called, the variable has the correct value, but after some calls, apparently the value of the variable has changed and the function returns error. So I have debugged it, and the fact is that if I look at the RAM address where the variable is mapped, the value is correct, but it seems that the ldw instruction has not loaded the correct value! So the address of the variable is 0x83c954. At the beginnig of the program, this address has a value of 0. After initialization, it changes to 1 (STATE_OPEN) and 2 (STATE_OPERATIVE). This should be the correct value, and should not change. The check I have is: if (gState != NVRAM_STATE_OPERATIVE) assert(0); If I put the breakpoint in the "if", I see that at that point, the RAM address has a correct value, and the r4 register, which is assigned the value of the variable, is also correct. (Assignation of r4 to the value of the variable) 0x00802450 <NvramGetData+56>: ldw r4,-32240(gp) // (gp is 0x844744 -> gp - 32240 = 0x83c954) But if I put the breakpoint in the assert, in order to see when it fails, I find that when the program stops, the value of the address 0x83c954 is still 2, but r4 value is 0!!!! Also, if I point to the value with the mouse in the debugger, it says that the value is NVRAM_STATE_OPERATIVE!!!! From the assignation of r4 to the assert there's no other assignation 0x00802450 <NvramGetData+56>: ldw r4,-32240(gp) (ASSIGNATION) 0x00802454 <NvramGetData+60>: movi r5,6 0x00802458 <NvramGetData+64>: addi r6,fp,4 0x0080245c <NvramGetData+68>: cmpeqi r3,r4,2 0x00802460 <NvramGetData+72>: bne r3,zero,0x802490 <NvramGetData+120> (BREAKPOINT) and the only IRQ present is the one from the TIMER. That interrupt should be saving and restoring r4 (from vectors.S, it does), so shouldn't be corrupted. the fact is that if I change the software (add printfs or othe instructions) the problems may disappear, but later they appear at other point. After that... some clues about what's happening? Ii don't think it's a bad pointer, because no other threads are active. And I don't think also the stack is been corrupted, as I have only this thread, and the timer IRQ. Help or suggestions will be accepted... aLeX