Path: chuka.playstation.co.uk!news From: Jim Newsgroups: scea.yaroze.programming.codewarrior Subject: Re: System memory Date: Thu, 07 Aug 1997 10:41:01 +0100 Organization: PlayStation Net Yaroze (SCEE) Lines: 54 Message-ID: <33E9982D.54A636C9@micronetics.com> References: <01bc957d$ffb78880$9fbf43ce@wkwerner> <33d63ee2.2608036@news.scea.sony.com> <01bca2b9$a16f32c0$69bf43ce@wkwerner> NNTP-Posting-Host: jim.micronetics.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 4.01 [en] (Win95; I) X-Priority: 3 (Normal) Wayne K. Werner wrote: > The easiest form of stack checking I can see for the NY is to run your > program in debug mode, stepping into each routine to the depth desired. Do > a register dump to see what the value of the stack pointer is. It will > have the address of the next location to be used for the next push. By > comparing this with (_end + _heap_size), you should have a fairly good idea > of what the stack is doing. You could also insert the above check into a > function to fprint the value at various points in your code or a macro to > do an assert type report and abort (enable and disable this with a stack > check #define). > This type of check, although not fool proof could prove quite useful. > I've not tryed this method but you could always write a macro called STACK_CHECK that would grab the sp and check it against a specific thresh hold. For example #ifdef (DEBUG) #define STACKTOP (0x801ffff4L) #define THRESHHOLD ((STACKTOP) - (4 * 1024)) #define STACK_CHECK \ { \ static long _stackcheck; \ __asm__ volatile ("sw $sp, _stackcheck"); \ if (_stackcheck < THREASHHOLD){ \ printf("stack exceeded limit. $sp = 0x%X\n", _stackcheck); \ exit(1); \ } #else #define STACK_CHECK #endif Just put STACK_CHECK; as the first line in your function. I've just grabbed this from the ether so I don't expect it to work without a bit of faffing around. But I think the theory is there. Remember that the stack moves down towards lower memory, also remember to set the threshhold sightly higher that required. Printf uses a lot of stack to do its thing. so if it is dangerously low printf may fail. Let me know how you get on with this. -JiM