From mboxrd@z Thu Jan 1 00:00:00 1970 Date: Thu, 6 Nov 2008 10:21:16 +0000 (GMT) From: Gabriele Moabiti MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="0-1776528731-1225966876=:30595" Message-ID: <442698.30595.qm@domain.hid> Subject: [Xenomai-help] the exception saga - system hangs List-Id: Help regarding installation and common use of Xenomai List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Xenomai help --0-1776528731-1225966876=:30595 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable =0AI was trying to do custom exceptions handling for a xenomai task but=0AI= had problem of erratic hangs so I've done an example program to=0Areproduc= e the behaviour.=0AThe user xenomai task causes an exception #13 when try t= o execute a=0Aread in the eax of dr7 program register. The exception handle= r will=0Aonly change the ip to the next instruction.=0A=0AAll seems to work= but after some loops (from 50 to 10000...=0Anot predictable) system hangs.= I can't figure the problem...=0Aif the problem isn't in my code maybe the = problem is in adeos.=0A=0A[x86 32 bit - Xenomai 2.4.5 - Linux kernel `vanil= la` 2.6.24-7, gcc 4.1.3]=0A-------------------------=0A =0AUser program=0A-= ------------------------=0A#include =0A#include =0A#in= clude =0A#include =0A=0A#define MODULE_TASK_NAME = "xtask_user"=0A#define TASK_PRIO 99=0A#define TASK_MODE T_FPU|T_CPU(0)=0A= #define TASK_STKSZ 4096=0A#define FIXED_PERIOD 2000000 /* 2 ms */= =0A=0ART_TASK task_desc;=0A=0Avoid xeno_task(void *cookie)=0A{=0A static l= ong loop_count=3D0;=0A for (;;loop_count++) {=0A rt_task_wait_period(NU= LL);=0A rt_printf("Loop number: %ld\n", loop_count);=0A /* Let's rais= e an exception #13*/=0A __asm__ __volatile__("nop; movl %dr7, %eax;nop")= ;=0A }=0A}=0A =0Aint main(int argc, char *argv[])=0A{=0A mlockall(MCL_C= URRENT|MCL_FUTURE);=0A rt_print_auto_init(1);=0A rt_task_create(&task= _desc, MODULE_TASK_NAME, TASK_STKSZ, TASK_PRIO, TASK_MODE);=0A rt_task_s= et_periodic(&task_desc, TM_NOW, rt_timer_ns2ticks(FIXED_PERIOD));=0A rt_= task_start(&task_desc,&xeno_task,NULL);=0A pause();=0A rt_task_delete= (&task_desc);=0A}=0A-------------------------=0A Kernel module=0A----------= ---------------=0A#include =0A#include = =0A#include =0A#include =0A#include =0A=0AMODULE_AUTHOR(xxx");=0AMODULE_DESCRIPTION("xxx");=0AMODULE_LIC= ENSE("GPL"); =0A=0Astatic rthal_trap_handler_t old_tra= p_handler;=0A=0Astatic int custom_trap_fault(unsigned event, unsigned domid= , void *data)=0A{=0A volatile short *istr;=0A struct pt_regs *regs=3Ddata= ;=0A xnthread_t *thread;=0A if (event=3D=3D13) {=0A if (!xnpod_active_= p() ||=0A (!xnpod_interrupt_p() && xnpod_idle_p()))=0A goto xeno_= handle; =0A if (!xnpod_shadow_p()) =0A goto xeno_handle; =0A = if (!xnpod_userspace_p())=0A goto xeno_handle; =0A thread =3D= xnpod_current_thread(); =0A if (!user_mode(regs)) /* not a user CS */= =0A goto xeno_handle;=0A if (strcmp(thread->name,"xtask_user")!=3D0= )=0A goto xeno_handle;=0A istr =3D (char *) (regs->x86reg_ip);=0A = if (*istr =3D=3D 0x210f && (*(istr+1) & 0xFF) =3D=3D 0xf8) {=0A /* m= ovl %dr7, %eax */=0A regs->x86reg_ip+=3D3; =0A return RTHAL_EVENT= _STOP;=0A } =0A }=0Axeno_handle: /* Xenomai will handle the event */=0A= return ((rthal_trap_handler_t) old_trap_handler)(event, domid, data);= =0A}=0A=0Aint __init init_mymodule(void)=0A{=0A old_trap_handler =3D rthal= _trap_catch(&custom_trap_fault);=0A return 0; // OK, adesso ho fatto! =0A}= =0Avoid __exit cleanup_mymodule(void)=0A{=0A rthal_trap_catch(old_trap_h= andler);=0A}=0Amodule_init(init_mymodule);=0Amodule_exit(cleanup_mymodule);= =0A=0A=0A Unisciti alla community di Io fotografo e video, il nuovo co= rso di fotografia di Gazzetta dello sport:=0Ahttp://www.flickr.com/groups/i= ofotografoevideo --0-1776528731-1225966876=:30595 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable

I was trying to do custom exceptions handling for a xenomai task butI had problem of erratic hangs so I've done an example program to
repr= oduce 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 seem= s to work but after some loops (from 50 to 10000...
not predictable) sys= tem hangs. I can't figure the problem...
if the problem isn't in my code= maybe the problem is in adeos.

=0A[x86 32 bit - Xenomai 2.4.5 - Lin= ux kernel `vanilla` 2.6.24-7, gcc 4.1.3]
-------------------------
&n= bsp;=0AUser program
=0A-------------------------
=0A#include <stdi= o.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 &= nbsp;        /* 2 ms */

RT_TASK t= ask_desc;

void xeno_task(void *cookie)
{
  static long lo= op_count=3D0;
  for (;;loop_count++) {
    rt_tas= k_wait_period(NULL);
    rt_printf("Loop number: %ld\n", = loop_count);
    /* Let's raise an exception #13*/
 &n= bsp;  __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,=0A MODULE_TASK_NAME, T= ASK_STKSZ, TASK_PRIO, TASK_MODE);
    rt_task_set_periodi= c(&task_desc, TM_NOW, rt_timer_ns2ticks(FIXED_PERIOD));
  =   rt_task_start(&task_desc,&xeno_task,NULL);
  &n= bsp; pause();
    rt_task_delete(&task_desc);
}-------------------------
 Kernel module
----------------------= ---
#include <linux/module.h>
#include <rtdm/rtdm_driver.h&g= t;
#include <native/task.h>
#include <native/timer.h>
= #include <native/intr.h>

MODULE_AUTHOR(xxx");
MODULE_DESCRI= PTION("xxx");
MODULE_LICENSE("GPL");      =             &nb= sp;  

static rthal_trap_handler_t old_trap_handler;
static int custom_trap_fault(unsigned event, unsigned domid, void *data)<= br>{
  volatile short *istr;
 =0A struct pt_regs *regs=3Dda= ta;
  xnthread_t *thread;
  if (event=3D=3D13) {
 &= nbsp;  if (!xnpod_active_p() ||
      (!xn= pod_interrupt_p() && xnpod_idle_p()))
    &n= bsp; goto xeno_handle;   
    if (!xnpod_= shadow_p())
      goto xeno_handle;  = ; 
    if (!xnpod_userspace_p())
  &nb= sp;   goto xeno_handle;   
    = thread =3D xnpod_current_thread(); 
    if (!user_m= ode(regs)) /* not a user CS */
      goto xeno_= handle;
    if (strcmp(thread->name,"xtask_user")!=3D0= )
      goto xeno_handle;
   = istr =3D (char *) (regs->x86reg_ip);
    if (*istr = =3D=3D 0x210f && (*(istr+1) & 0xFF) =3D=3D 0xf8)=0A {
 =      /* movl %dr7, %eax */
    &= nbsp; regs->x86reg_ip+=3D3;=0A
      return = RTHAL_EVENT_STOP;
    }=0A
  }
xeno_handle: /*= Xenomai will handle the event */
    return ((rthal_trap= _handler_t) old_trap_handler)(event, domid, data);
}

int __init i= nit_mymodule(void)
{
  old_trap_handler =3D rthal_trap_catch(&am= p;custom_trap_fault);
  return 0; // OK, adesso ho fatto!
}
= void __exit cleanup_mymodule(void)
{
    rthal_trap_ca= tch(old_trap_handler);
}
module_init(init_mymodule);
module_exit(c= leanup_mymodule);


=0A=0A=0A=0A
Scopri la community di Io fotografo e video=0AIl nuovo corso di Gazzetta dell= o sport per diventare veri fotografi! --0-1776528731-1225966876=:30595--