Custom trap functions
Moderator: paolo.gai
Custom trap functions
I need to create my own exception handling functions. In Erika, exceptions calls a trap function, such as osEE_tc_trap_bus, osEE_tc_trap_context and others. How to add custom function call into trap handler's?
Re: Custom trap functions
Unfortunately,
the support for custom exception handler's is not finished: the code would support it, but the generator does not support it yet.
But, since all erika's files are contained in a library, you could always override a symbols providing the implementation in a file in the application.
I suggest you to copy ee_tc_trapvec.c in your project and customize it in the way you want, the only thing that needs to be preserved is the header for the exception vector (line: 1272), if your are using Hightec.
Kind Regards,
Errico
the support for custom exception handler's is not finished: the code would support it, but the generator does not support it yet.
But, since all erika's files are contained in a library, you could always override a symbols providing the implementation in a file in the application.
I suggest you to copy ee_tc_trapvec.c in your project and customize it in the way you want, the only thing that needs to be preserved is the header for the exception vector (line: 1272), if your are using Hightec.
Code: Select all
__asm__ (" \n\
.section .traptab_cpu0, \"ax\", @progbits \n\
.align 8 \n\
.globl _exit \n\
.globl __TRAPTAB \n\
__TRAPTAB: \n\
");
Errico
Re: Custom trap functions
I was modified the ee_tc_trapvec.c starting on line 1298 with that:
And added user code for this trap in main.c:
And user_tc_trap_protection() was successfully called when i artificially inject error as this:
thank you
Code: Select all
...
#if (defined(OSEE_MEMORY_PROTECTION))
OSEE_TC_TRAP_DEFINITION(osEE_tc_trap_protection, osEE_tc_protection_handler)
#elif (defined(OSEE_TC_TRAP_PROT_TRAP))
OSEE_TC_TRAP_DEFINITION(osEE_tc_trap_protection, OSEE_TC_TRAP_PROT_TRAP)
#elif (defined(OSEE_TIMING_PROTECTION))
OSEE_TC_TRAP_DEFINITION_WITH_CALL(osEE_tc_trap_protection,
osEE_tc_default_trap_handler)
#else
//OSEE_TC_TRAP_DEFAULT(osEE_tc_trap_protection)
__asm__ (".globl " "osEE_tc_trap_protection"); \
__asm__ ("osEE_tc_trap_protection" ":"); \
__asm__ ("j " "user_tc_trap_protection"); \ <- jump to users trap processing function
__asm__ (".align 5");
#endif /* OSEE_TC_TRAP_PROT_TRAP */
...
Code: Select all
void user_tc_trap_protection()
{
logger->addMessage("protection trap occurred");
}
Code: Select all
char* exc_pointer = NULL;
*exc_pointer = 100;
Re: Custom trap functions
Hi,
Remember to save a lower context before calling C code, restore it after the call and return from the exception with rfe.
This would be a right wrapper to your user_tc_trap_protection
Regard
Remember to save a lower context before calling C code, restore it after the call and return from the exception with rfe.
This would be a right wrapper to your user_tc_trap_protection
Code: Select all
__asm__ (".globl " "osEE_tc_trap_protection"); \
__asm__ ("osEE_tc_trap_protection" ":"); \
__asm__ ("svlcx"); \
__asm__ ("call user_tc_trap_protection");
__asm__ ("rslcx"); \
__asm__ ("rfe"); \
__asm__ (".align 5");
Re: Custom trap functions
I missed the context save/restore operation and call instruction. And this omission led to context underrun trap. Thanks for useful clarification