Hello, I'm trying to implement a simple stack checking mechanism in an MSP430 multi-task environment (task scheduling/switching is subject to a custom "OS").
Each task has its own stack space, but since there's a single address space and the memory is small, tasks can easily overflow their stack and corrupt "foreign" data. The best idea I came up with for checking the overflow is adding some explicit checking code at the beginning of each function - actually at the end of the preamble, when SP is already lowered to reserve space for local variables. It would be very nice though if the compiler could generate that code itself, for instance when the "-fstack-check" is specified on the command line. I tracked down the preamble generation to the expand_prologue() function (file msp430-function.c). The global variable "flag_stack_check" is visible and automatically set to 1 by (generic) gcc when "-fstack-check" is specified on the command line. The best I could do was identify the code that generates "push" instructions for all clobbered registers and the code that explicitly lowers SP by the required amount. My code goes next to this. However, I'm new to gcc internals and most of my attempts to produce the check code ended up with gcc reporting an internal bug and bailing out. I would really appreciate any suggestions or directions for implementing this. The resulting code should be as simple as comparing R1 to a variable (contents of a fixed memory location) that holds the stack base address and conditionally jump to a handling routine. To my (limited) MSP430 asm knowledge, it shoud look like this: push r15 mov #__stack_base, r15 cmp r1, 0(r15) jge .Lsomething br #_handling_routine .Lsomething pop r15 Best regards, Radu Rendec ------------------------------------------------------------------------------ EMC VNX: the world's simplest storage, starting under $10K The only unified storage solution that offers unified management Up to 160% more powerful than alternatives and 25% more efficient. Guaranteed. http://p.sf.net/sfu/emc-vnx-dev2dev _______________________________________________ Mspgcc-users mailing list Mspgcc-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mspgcc-users