SAS-C and Interrupts

SAS-C and Interrupts

Post by Espen Bernts » Wed, 07 Feb 1996 04:00:00



How do you call a C routine from an interrupt in sas-c??

Whenever I try to do it, the machine locks up.

the C routine looks like this:

----- cut ---
LONG Counter = 0;

void VBLRoutine(void)
{
        Counter++;

Quote:}

----- cut -----

and the assembly vertical blank interrupt like this :

----- cut -----
; some includes, don't remember precicely

        XDEF _VBLRoutine
VertBlankServer
        jsr _VBLRoutine
        moveq   #0,d0
        rts
----- cut -----

Now, when I don't call the C routine, but increase the Counter by using
(a1), everything is fine. But when I call the C routine. the machine just
locks.

Now, the VBL is not supposed to just add a counter, it is just a test :-)

--


===========================================================================
Fighting for peace is like *ing for *ity.

 
 
 

SAS-C and Interrupts

Post by IAN J. EINM » Thu, 08 Feb 1996 04:00:00


__interrupt __saveds IRoutine(void)
{
   blah blah blah++

Quote:}

The __interrupt insures SAS will set the CCR on return, and disables stackchecking.
Be sure that stack extension is turned off.

Finally, the __saveds is desperately needed if you try to access variables.  The
C code will access your variables as an offset from A4.

For example,

   count += 5;

would become

   addq.l #5,_count(a4)

The problem is this.  Without __saveds, your program (C-code) will not have a4 set.

Imagine this

assembly code:
   move.l a3,a4
   lea 24(a4),a0  (just misc code)
   addq.l #1,d0
   jsr _interrupt(pc)
   move.l d0,(a3)+
   rts

C code
{
   count++;           addq.l #1,count(a4)

Quote:}                     rts

This will crash, since A4 was tampered with in the Asm part previously.  The __saveds
keyword will change the "interrupt"routine to look more like this:

C code
__saveds interrupt(void)
{
                      move.l __saveds(pc),a4
   count ++;          addq.l #1,count(a4)

Quote:}                     rts

Hope this helps.

Ian J. Einman


 
 
 

SAS-C and Interrupts

Post by Ruud van Ga » Thu, 08 Feb 1996 04:00:00



Quote:>How do you call a C routine from an interrupt in sas-c??

>Whenever I try to do it, the machine locks up.

>the C routine looks like this:

>----- cut ---
>LONG Counter = 0;

>void VBLRoutine(void)
>{
>    Counter++;
>}
>----- cut -----

For SAS C:
void __interrupt __saveds VBLRoutine(void)
{...}

__interrupt disable any stack checking (if not disabled at all), __saveds
gets A4 to point at your local data.

--
Ruud van Gaal
MarketGraph Visual Automation

DoomShell 4.5 homepage: http://www.xs4all.nl/~jwkorver
"...Works fascinates me. I could sit and watch it for hours..."

 
 
 

SAS-C and Interrupts

Post by Doug Walk » Tue, 13 Feb 1996 04:00:00




>How do you call a C routine from an interrupt in sas-c??

>Whenever I try to do it, the machine locks up.

>the C routine looks like this:

>----- cut ---
>LONG Counter = 0;

>void VBLRoutine(void)
>{
>    Counter++;
>}

Use the __saveds keyword to set up your global data pointer (A4).
Or, put __far on the Counter variable's definition.  Or compile
with DATA=FAR.  Or compile with SAVEDS.

Please read your SAS/C manual for information about when you should
use  __saveds or related options and keywords.

--

 *|_o_o|\\     Doug Walker<  BIX, Portal: djwalker
 *|. o.| ||                \ AOL: weissblau
  | o  |//    
  ======
Any opinions expressed are mine, not those of SAS Institute, Inc.

 
 
 

1. interrupt in SAS/C 6.51

Greetings,

I just received my upgrade to SAS/C 6.50 and thought I'd try whipping up a
few programs. One of the programs I have created uses AddIntServer to add
a vertical blank interrupt. Here is the set up in the C code:

        struct Interrupt *vbint;

        vbint = (struct Interrupt *)AllocMem(sizeof(struct Interrupt),
                MEMF_CLEAR | MEMF_PUBLIC);
        if(!(vbint))
        {
                exit(20);
        }

        vbint->is_Node.ln_Type = NT_INTERRUPT;
        vbint->is_Node.ln_Pri  = -60;
        vbint->is_Node.ln_Name = "vbint";
        vbint->is_Code = VertBServer;

        AddIntServer(INTB_VERTB, vbint);

Now if I create the function VertBServer using assembler I can get this to
work fine but what I would like to do (and this is just for experimental
purposes) is create the function VertBServer using C language. The code
for VertBServer is simply:

        Signal(task, SIGBREAKF_CTRL_F);

The variable task is a global variable initialized by the main code using:

        task = FindTask(NULL);

I've read some stuff about __interrupt in the SAS/C manual but it is not
entirely clear. I think I am probably not setting the Z flag when exiting
the VertBServer function. References to the manuals would actually be
appreciated.

2. Modem on Sync port

3. SAS-C bug

4. 4800 bps?

5. SAS-C: Big problem with old link lib

6. Multi Column Combo Box

7. SAS-C, stackcheck&ddebug.lib

8. SpartaDOS X Start Address?

9. SAS-C bug ?

10. SAS-C: CXERR 460351

11. (~0) in Sas-C and AddPart()

12. POWERPC chip and SAS-C

13. sorting of struct type with sas-c