Thread: Restarting an ISR in a transaction-like style

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    2

    Restarting an ISR in a transaction-like style

    I am trying to implement restarting of an ISR from the beginning when it is interrupted by a higher priority handler (in Linux on an x86). To do so, I would like to set (while in the ISR) the instruction pointer (EIP) and offset (XCS) registers to point to the ISR so that it is restarted when it executes RET (It is ok to throw away the ISR's work). What is the best way to do this without erasing information about any handler that the IST itself has interrupted?

    Code:
     
               /* regs is a pointer to registers saved when the interrupt occured */
    void ISR(int irq, void *dev_id, struct pt_regs *regs)
    {
    /* do stuff here */
    
    /* disable all interrupts */
    if (was_interrupted) {
      long eip_;
      int xcs_;
      /* find where void ISR(...) is in memory (segment and offset) 
         and set registers on the stack */
      regs->eip = ?  /* BAD: this will rewrite saved data on the stack */
      regs->xcs = ?
                     /* perhaps jump to ISR? */
      }
    /* enable all interrupts */
    
    }
    Thank you.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > (It is ok to throw away the ISR's work).
    Exactly how much work are you planning to do?
    ISR's should be short-lived, get in get out, minimal amount of work necessary, without blocking on any resource kind of thing.

    How about
    Code:
    volatile int interrupted;
    void ISR(int irq, void *dev_id, struct pt_regs *regs)
    {
      do {
        interrupted = 0;
        // your work here
      } while ( interrupted );
    }
    Moved to Linux board.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Aug 2006
    Posts
    2
    > Exactly how much work are you planning to do?
    I am configuring a device and getting some data in a buffer. I want this to be atomic in the sense that I can be interrupted, and if I am, the higher level handler should run, but then I should restart my copying from the beginning.

    Your code is a good approximation, but it will continue to run the remaining work and THEN restart. Could I avoid this by, say, immediately jumping to ISR again after the ISR knows it has been interrupted.

    Code:
    volatile int interrupted;
    void ISR(int irq, void *dev_id, struct pt_regs *regs)
    {
      do {
        interrupted = 0;
        // your work here
      } while ( interrupted );
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BN_CLICKED, change button style
    By bennyandthejets in forum Windows Programming
    Replies: 13
    Last Post: 07-05-2010, 11:42 PM
  2. Problem with file
    By nevrax in forum C Programming
    Replies: 12
    Last Post: 04-23-2007, 06:18 PM
  3. WM_CAPTION causing CreateWindowEx() to fail.
    By Necrofear in forum Windows Programming
    Replies: 8
    Last Post: 04-06-2007, 08:23 AM
  4. Button handler
    By Nephiroth in forum Windows Programming
    Replies: 8
    Last Post: 03-12-2006, 06:23 AM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM