From: Gabriele Moabiti <gabmoa@domain.hid>
To: Xenomai help <xenomai@xenomai.org>
Subject: [Xenomai-help] the exception saga - system hangs
Date: Thu, 6 Nov 2008 10:21:16 +0000 (GMT) [thread overview]
Message-ID: <442698.30595.qm@domain.hid> (raw)
[-- Attachment #1: Type: text/plain, Size: 3327 bytes --]
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
[-- Attachment #2: Type: text/html, Size: 4875 bytes --]
next reply other threads:[~2008-11-06 10:21 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-11-06 10:21 Gabriele Moabiti [this message]
2008-11-06 13:16 ` [Xenomai-help] the exception saga - system hangs Gilles Chanteperdrix
2008-11-07 14:20 ` Gabriele Moabiti
-- strict thread matches above, loose matches on Subject: below --
2008-11-06 14:02 Gabriele Moabiti
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=442698.30595.qm@domain.hid \
--to=gabmoa@domain.hid \
--cc=xenomai@xenomai.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.