AnsweredAssumed Answered

Trap use of NULL pointer, memory access exception, on MCF54418 ColdFire V4 using MMU?

Question asked by colin on Oct 17, 2014
Latest reply on Feb 17, 2015 by TomE

Is there a way to trigger an exception on access to an invalid memory address?  The most important special case of this is accesses caused by deferencing a NULL pointer: accessing address zero.


It seems like if we enable the MMU and then put a couple of static entries in the TLB, we can achieve the goal.  We want to say that memory near address zero is not readable, not writable, and not executable.  I haven't been able to find any example code that does this.  Yet it seems extremely useful, since otherwise NULL pointer access (both read and write operations) can go unnoticed for a long time, and the program will behave unpredictably in a later execution context.  This makes it tremendously difficult to identify the source of the problem since no exception handler gets triggered where the NULL pointer is used.


In the ColdFire V4 MCF54418 memory map, address zero is a valid address, but is mapped to FlexBus and our application does not use that address range for FlexBus purposes.


I see that there are two main features of the ColdFire V4 MMU: first, access control registers (ACRs), of which there are four; and second, the translation lookaside buffer (TLB) entries. The MQX 4.0.2 we are using has apparently very limited MMU support.  Basically it just allows setting up the ACRs but doesn't even fully support all features of the ACRs (e.g. it doesn't allow setting "not readable" flag).


Or, is there any other way to trap use of NULL pointers so we can catch the program errors early in the development process and stomp these bugs?  Thanks for any help!!