I was trying to do custom exceptions handling for a xenomai task but
I had problem of erratic hangs so I've done an example program to
reproduce the behaviour.
The user xenomai task causes an exception #13 when try to execute a
read in the eax of dr7 program register. The exception handler will
only change the ip to the next instruction.
All seems to work but after some loops (from 50 to 10000...
not predictable) system hangs. I can't figure the problem...
if the problem isn't in my code maybe the problem is in adeos.
[x86 32 bit - Xenomai 2.4.5 - Linux kernel `vanilla` 2.6.24-7, gcc 4.1.3]
-------------------------
User program
-------------------------
#include <stdio.h>
#include <sys/mman.h>
#include <native/task.h>
#include <rtdk.h>
#define MODULE_TASK_NAME "xtask_user"
#define TASK_PRIO 99
#define TASK_MODE T_FPU|T_CPU(0)
#define TASK_STKSZ 4096
#define FIXED_PERIOD 2000000 /* 2 ms */
RT_TASK task_desc;
void xeno_task(void *cookie)
{
static long loop_count=0;
for (;;loop_count++) {
rt_task_wait_period(NULL);
rt_printf("Loop number: %ld\n", loop_count);
/* Let's raise an exception #13*/
__asm__ __volatile__("nop; movl %dr7, %eax;nop");
}
}
int main(int argc, char *argv[])
{
mlockall(MCL_CURRENT|MCL_FUTURE);
rt_print_auto_init(1);
rt_task_create(&task_desc, MODULE_TASK_NAME, TASK_STKSZ, TASK_PRIO,
TASK_MODE);
rt_task_set_periodic(&task_desc, TM_NOW, rt_timer_ns2ticks(FIXED_PERIOD));
rt_task_start(&task_desc,&xeno_task,NULL);
pause();
rt_task_delete(&task_desc);
}
-------------------------
Kernel module
-------------------------
#include <linux/module.h>
#include <rtdm/rtdm_driver.h>
#include <native/task.h>
#include <native/timer.h>
#include <native/intr.h>
MODULE_AUTHOR(xxx");
MODULE_DESCRIPTION("xxx");
MODULE_LICENSE("GPL");
static rthal_trap_handler_t old_trap_handler;
static int custom_trap_fault(unsigned event, unsigned domid, void *data)
{
volatile short *istr;
struct pt_regs *regs=data;
xnthread_t *thread;
if (event==13) {
if (!xnpod_active_p() ||
(!xnpod_interrupt_p() && xnpod_idle_p()))
goto xeno_handle;
if (!xnpod_shadow_p())
goto xeno_handle;
if (!xnpod_userspace_p())
goto xeno_handle;
thread = xnpod_current_thread();
if (!user_mode(regs)) /* not a user CS */
goto xeno_handle;
if (strcmp(thread->name,"xtask_user")!=0)
goto xeno_handle;
istr = (char *) (regs->x86reg_ip);
if (*istr == 0x210f && (*(istr+1) & 0xFF) == 0xf8) {
/* movl %dr7, %eax */
regs->x86reg_ip+=3;
return RTHAL_EVENT_STOP;
}
}
xeno_handle: /* Xenomai will handle the event */
return ((rthal_trap_handler_t) old_trap_handler)(event, domid, data);
}
int __init init_mymodule(void)
{
old_trap_handler = rthal_trap_catch(&custom_trap_fault);
return 0; // OK, adesso ho fatto!
}
void __exit cleanup_mymodule(void)
{
rthal_trap_catch(old_trap_handler);
}
module_init(init_mymodule);
module_exit(cleanup_mymodule);
Unisciti alla community di Io fotografo e video, il nuovo corso di
fotografia di Gazzetta dello sport:
http://www.flickr.com/groups/iofotografoevideo_______________________________________________
Xenomai-help mailing list
[email protected]
https://mail.gna.org/listinfo/xenomai-help