Hi Folks,
I am new to the HCS12x and have a question regarding memory access and exceptions. If this is FAQ my apology upfront.
Setup
CodeWarrior 5.1, target is mc9s12xdt512 and FCS.
My question:
What happens to a memory write to a variable in a C program that is const and placed in onboard flash (READ_ONLY) segment C000? Does the program continue running or will it raise an exception and halt?
When I run the program on the target hardware it seems to run ok. But when I run it under the Full Chip Simulator (FCS) the simulator halts the program at the write call with error message "Protected at XXXX".
On x86 Windows/Linux a bad write like this would cause global protection fault/segmentation fault and core dump.
Will the physical mc9s12xdt512 allow/ignore this bad write but the simulator will stop and alert me?
thank you
bob
Solved! Go to Solution.
- What happens to a memory write to a variable in a C program that is const and placed in onboard flash (READ_ONLY) segment C000? Does the program continue running or will it raise an exception and halt?
It is uncommon to write to RO memory. On target S12XD program will continue running. But simulator can help you detecting reads from not initialized memory and writes to read only memories. Simulator allows to modify or create your own memory layout in which all or parts of the flash can be made RW and you won't see those write access errors.
S12XE has memory protection unit (MPU), which allows to restrict accesses to read and execute, read and write, or only read. On S12XD there's no MPU, you can only restrict write accesses to RAM, but not to flash.
- What happens to a memory write to a variable in a C program that is const and placed in onboard flash (READ_ONLY) segment C000? Does the program continue running or will it raise an exception and halt?
It is uncommon to write to RO memory. On target S12XD program will continue running. But simulator can help you detecting reads from not initialized memory and writes to read only memories. Simulator allows to modify or create your own memory layout in which all or parts of the flash can be made RW and you won't see those write access errors.
S12XE has memory protection unit (MPU), which allows to restrict accesses to read and execute, read and write, or only read. On S12XD there's no MPU, you can only restrict write accesses to RAM, but not to flash.
Agreed. Writing to RO segment in flash is not what we want and most likely a bug.
You answered my question - specifically that the physical processor will continue running but the sim will halt.
Thank you for the help.
bob