Custom trap functions

Forum related to ERIKA Enterprise and RT-Druid version 3

Moderator: paolo.gai

Post Reply
Alexanderv66
Newbie
Posts: 17
Joined: Sun Jun 30, 2019 6:13 pm

Custom trap functions

Post by Alexanderv66 » Fri Jul 19, 2019 1:19 pm

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?

e.guidieri
Full Member
Posts: 166
Joined: Tue May 10, 2011 2:05 pm

Re: Custom trap functions

Post by e.guidieri » Fri Jul 19, 2019 6:52 pm

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.

Code: Select all

__asm__ ("                                  \n\
  .section .traptab_cpu0, \"ax\", @progbits \n\
  .align 8                                  \n\
  .globl _exit                              \n\
  .globl __TRAPTAB                          \n\
__TRAPTAB:                                  \n\
");
Kind Regards,
Errico

Alexanderv66
Newbie
Posts: 17
Joined: Sun Jun 30, 2019 6:13 pm

Re: Custom trap functions

Post by Alexanderv66 » Mon Jul 22, 2019 8:02 am

I was modified the ee_tc_trapvec.c starting on line 1298 with that:

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 */
...
And added user code for this trap in main.c:

Code: Select all

void user_tc_trap_protection()
{
	logger->addMessage("protection trap occurred");
}
And user_tc_trap_protection() was successfully called when i artificially inject error as this:

Code: Select all

char* exc_pointer = NULL;
*exc_pointer = 100;
thank you

e.guidieri
Full Member
Posts: 166
Joined: Tue May 10, 2011 2:05 pm

Re: Custom trap functions

Post by e.guidieri » Mon Jul 22, 2019 9:47 am

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

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");
Regard

Alexanderv66
Newbie
Posts: 17
Joined: Sun Jun 30, 2019 6:13 pm

Re: Custom trap functions

Post by Alexanderv66 » Wed Jul 24, 2019 6:01 am

I missed the context save/restore operation and call instruction. And this omission led to context underrun trap. Thanks for useful clarification

Post Reply