Altera_Forum
Honored Contributor
15 years agoException Handler for misaligned data memory access
Hi All,
I'm after some help... Does anybody have available or point me in the direction of a worked example of an exception handler which processes NIOS2_EXCEPTION_MISALIGNED_DATA_ADDR exception cause. I have many packed data structures (in our 10'000s lines of existing code) which I access using pointers. As way of explaining what I need to achieve, struct PackedStruct { alt_u8 A; alt_u16 B; // not aligned }__attribute((__packed__)) ; struct PackedStruct Packed; int main() { alt_u16 *u16ptr; alt_u16 Value; // register my exception handler alt_instruction_exception_register (MisalignedServiceRoutine); u16ptr = Packed.B; Value = *u16ptr; // this generates an exception } I don't know how to code my exception handler so that I can do a byte memcpy and then resume. I guess I need to look to see if the instruction which caused the exception was a Load or a Store unsigned/signed half word, full word. Then do the memory copy. The problem is I don't know how to do this. Can anybody help. Just to confirm, I have generated a SOF with the a nios II/f with misaligned memory access and extra exception information options checked under Excpetion checking. My NIOS SBT project works to the point whereby my exception handler is run when a misaligned data memory access occurs. Thanks in advance. Ade