[Openec] 8051 reentrancy

pgf at laptop.org pgf at laptop.org
Thu Jul 31 17:02:26 EDT 2008


frieder wrote:
 > Hi,
 > 
 > pgf at laptop.org schrieb:
 > > [ beware -- list-crosspost ]
 > > 
 > > it seems that at least some of the instability that i've been
 > > seeing is that the interrupt routines (and/or some of the
 > > routines they call) weren't reentrant, when i thought they would
 > 
 > Could the cause of this "instability" be related to stack overflow?
 > 
 > Does a "stack cookie" remain untouched? you could check like this:

good thought.  i'll try that.  i've also been running in the j51
emulator, and while i'm not at the point where the code needs full
hardware to run correctly, the stack in the emulator has never come
close to overflowing.  but that's not necessarily a good check anymore.

 > Which kind of "instability" do you observe?
 > 

i have indicators in place for both interrupt activity and main loop
processing, in the form of blinking leds, in addition to a certain
amount of console output.  in some cases, the code crashes or locks
up completely -- all indicators cease.  in other cases the main loop
keeps running, but no interrupt activity seems to occur.  however, in
the latter case, printing IE during the main loop still shows a sane
value in place (i was expecting it to be zero'd out).

paul

 > 
 > 
 > 
 > -------8<-------------------------------------------
 > #define STACK_COOKIE (0xabcd)
 > 
 > static volatile unsigned int irq_count;
 > 
 > void init_this(){}
 > void init_that(){}
 > 
 > bit do_this(){ return 1; }
 > bit do_that(){ return 0; }
 > 
 > 
 > bit all_up_and_well()
 > {
 >      return STACK_COOKIE == *(unsigned int __idata *)0x7e;
 > }
 > 
 > 
 > void core_dump(){}
 > 
 > 
 > void irq_routine1(void) __interrupt (1)
 > {
 >      irq_count++;
 >      irq_count %= 1024;
 > }
 > 
 > 
 > void main(void)
 > {
 >      *(unsigned int __idata *)0x7e = STACK_COOKIE; // place cookie near or at 
 > top of stack
 > 
 >      init_this();
 >      init_that();
 > 
 >      while(1)
 >      {
 >          do_this();
 >          do_that();
 > 
 >          if( !all_up_and_well() )
 >              core_dump();
 >      }
 > }
 > ------->8-------------------------------------------
 > 
 > 
 > Greetings,
 > Frieder

=---------------------
 paul fox, pgf at laptop.org


More information about the Openec mailing list