(solved) Can't get timer.device interrupt working
  • Order of the Butterfly
    Order of the Butterfly
    ChrisH
    Posts: 167 from 2009/11/26
    My final (?) problem on MorphOS is that I cannot get a timer.device-based repeating interrupt to work, it simply crashes the whole machine. Very similar code works fine on AROS, OS4 & OS3, which suggests that the MOS-specific code is probably at fault...
    http://cshandley.co.uk/temp/MOS_TimerTest.cpp

    It appears to crash on or after the first SendIO() call, probably at the point the timer expires. This suggest that the gate/isr wrapper is to blame. Additionally, the only MOS-specific code is the gate/isr wrapper (and how it is used), again suggesting this is the likely cause. Sadly I can't see anything wrong :(

    I found a related discussion, but so far it hasn't helped me:
    https://morph.zone/modules/newbb_plus/viewtopic.php?topic_id=7681&forum=12

    Any suggestions appreciated.

    [ Edited by ChrisH 26.10.2011 - 18:40 ]
    Author of the PortablE programming language.
    It is pitch black. You are likely to be eaten by a grue...
  • »26.10.11 - 16:58
    Profile Visit Website
  • MorphOS Developer
    Piru
    Posts: 576 from 2003/2/24
    From: finland, the l...
    Your custom newList routine is bogus. That will cause a horrible crash. On MorphOS you can use NEWLIST macro or use NewList from libabox. There's no need to write your own.

    If you really must use a custom newList, add the &'s where needed:
    Code:

    lh->lh_Head=&lh->lh_Tail;
    lh->lh_Tail=(struct Node*) NULL;
    lh->lh_TailPred=&lh->lh_Head;


    [ Edited by Piru 26.10.2011 - 19:58 ]
  • »26.10.11 - 17:15
    Profile
  • Order of the Butterfly
    Order of the Butterfly
    ChrisH
    Posts: 167 from 2009/11/26
    @piru
    That fixed it, thanks!

    I have no understanding of Exec lists, so that code was copied from somewhere (or possibly badly translated from some hacky AmigaE code). Strange it seemed to work on AROS & OS3 (but I discovered that the automatically generated code uses something different for OS4).

    [ Edited by ChrisH 26.10.2011 - 18:20 ]
    Author of the PortablE programming language.
    It is pitch black. You are likely to be eaten by a grue...
  • »26.10.11 - 18:16
    Profile Visit Website
  • MorphOS Developer
    Piru
    Posts: 576 from 2003/2/24
    From: finland, the l...
    Quote:

    Strange it seemed to work on AROS & OS3

    Not that strange really. If the MsgPort mp_MsgList is initialized as all zeros the result will be that address 0 will be used as temporary storage:

    1. When the exec IO call finishes the iorequest will be ReplyMsg()d.
    2. ReplyMsg() PutMsg() the message to message's mn_ReplyPort (ln_Type is also changed to NT_REPLYMSG).
    3. PutMsg() AddTail() the message node to port's mp_MsgList
    …now it gets interesting…

    Lets assume that the mp_MsgList has been initialized as all zero (as was the case with your buggy code). Here is what happens at AddTail():
    Code:

    struct Node *oldpredn = l->lh_TailPred; // 0
    n->ln_Succ = (struct Node *) &l->lh_Tail;
    n->ln_Pred = oldpredn; // 0
    oldpredn->ln_Succ = n; // write to 0
    l->lh_TailPred = n;

    So address 0 will be written to. If you're not running Enforcer or similar, no exception will be thrown.

    4. Finally when processing the reply, eventually the message will be removed from the list. Usually this happens by RemHead() call. This is what happens:
    Code:

    struct Node *rn = l->lh_Head->ln_Succ; // read from address 0, contains the n from the earlier AddTail!
    if (rn)
    {
    l->lh_Head = rn->ln_Succ;
    l->lh_Head->ln_Pred = (struct Node *) &l->lh_Head;
    }


    So this works, assuming you're not running Enforcer and address 0 is writable. Also this depends on this being the only buggy application writing to address 0 (if something else writes there bogus value is returned at RemHead).

    I hope this explains why it appeared to "work".
  • »26.10.11 - 20:02
    Profile
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    Tcheko
    Posts: 510 from 2003/2/25
    From: France
    ChrisH,
    Quote:

    I have no understanding of Exec lists, ...

    http://gega.homelinux.net/AmigaDevDocs/lib_23.html
    Quelque soit le chemin que tu prendras dans la vie, sache que tu auras des ampoules aux pieds.
    -------
    I need to practice my Kung Fu.
  • »27.10.11 - 05:18
    Profile Visit Website
  • MorphOS Developer
    Krashan
    Posts: 1107 from 2003/6/11
    From: Białystok...
    Tcheko,

    I may also add that I'm writing an article about exec lists for the MorphZone library. Should be finished this week.
  • »27.10.11 - 08:49
    Profile Visit Website
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    Tcheko
    Posts: 510 from 2003/2/25
    From: France
    @Krashan,

    Definitly a worthy content to read for anyone learning MorphOS (AmigaOS) coding. Lists are everywhere in system and used quite often in developement.

    Waiting to read your article. :)

    ++
    Quelque soit le chemin que tu prendras dans la vie, sache que tu auras des ampoules aux pieds.
    -------
    I need to practice my Kung Fu.
  • »27.10.11 - 19:41
    Profile Visit Website