home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / sys / amiga / programm / 17411 < prev    next >
Encoding:
Text File  |  1992-12-15  |  4.7 KB  |  141 lines

  1. Newsgroups: comp.sys.amiga.programmer
  2. Path: sparky!uunet!think.com!sdd.hp.com!elroy.jpl.nasa.gov!jato!jdickson
  3. From: jdickson@jato.jpl.nasa.gov (Jeff Dickson)
  4. Subject: Re: InputHandler debugging (long)
  5. Message-ID: <1992Dec16.033508.9417@jato.jpl.nasa.gov>
  6. Organization: Jet Propulsion Laboratory
  7. References: <tomme.724365078@Minsk>
  8. Date: Wed, 16 Dec 1992 03:35:08 GMT
  9. Lines: 130
  10.  
  11. tomme@Minsk.docs.uu.se (Thomas Holmstr|m) writes:
  12.  
  13.  
  14.  
  15.  
  16. >I am having some trouble with a piece of code which will be hooked into
  17. >the input handler list. The program always crash on the Signal() (1*) in the
  18. >handler routine when I push a key. It works fine if I comment out the
  19. >Signal() (ie. it doesn't do *anything* until I break it). I can send the
  20. >task the signal from Xoper and that works fine.
  21. >    Part of the problem is that I cannot find a good way of debugging
  22. >interrupts. I don't have any streams to write info to, do I? I've looked
  23. >at similar code hooking into the input handler list and I think I do
  24. >that the right way. Sorry for the somewhat log posting, I don't think
  25. >I could make it any shorter and still keep the relevant parts in.
  26. >    I'm using Dice, the registered version, and since it supports
  27. >registered arguments I really would like to use that instead of an
  28. >assembler routine, but when I declare the function as __regargs the reference
  29. >at (2*) uses _InputHandler (or _C_InputHandler) when it should be
  30. >@InputHandler. I've tried to redefined the Interrupt struct as
  31. >> struct Interrupt {
  32. >>    struct  Node is_Node;
  33. >>    APTR    is_Data;
  34. >>    VOID    (__regargs)(*is_Code)();}
  35. >or something like that (I'm not at my computer right now). How to do this?
  36.  
  37.  
  38. >Thanks in advance for any comments and/or suggestions.
  39.  
  40.  
  41. >The program:
  42. >/************************* Global declarations ***************************/
  43. >struct HandlerData {
  44. >  struct MsgPort *parentport;
  45. >  struct Task *parenttask;
  46. >  ULONG unblanksig;
  47. >} handlerdata;
  48. >struct Process *process;
  49. >ULONG handlersig, timersig, unblanksig;
  50.  
  51. >/*********************** Main function ************************/
  52. >void main(void) {
  53. >  init();
  54. >  while(locked) {
  55. >    ULONG wsigs = handlersig | timersig | unblanksig | SIGBREAKF_CTRL_C;
  56. >    signals = Wait(wsigs);
  57. >    if(signals & SIGBREAKF_CTRL_C) {
  58. >    /* Cleanup and exit */
  59. >    }
  60. >    if(signals & handlersig) {
  61. >    /* Handle message */
  62. >    }
  63. >    if(signals & timersig) blank();
  64. >    if(signals & unblanksig) unblank();
  65. >  }
  66. >  cleanup();
  67. >}
  68.  
  69. >/*********************** Init code **************************/
  70. >[...]
  71. >  if(!(process = (struct Process *)FindTask(NULL))) {
  72. >    /* Error */
  73. >  }
  74. >[...]
  75. >  if(!(handlerport = CreatePort(HPORT_NAME, HPORT_PRI))) {
  76. >    /* Error */
  77. >  }
  78. >  handlersig = (1 << (handlerport->mp_SigBit));
  79. >[...]
  80. >  if((usignr = AllocSignal(-1)) == -1) {
  81. >    /* Error */
  82. >  }
  83. >  unblanksig = (1 << usignr);
  84. >[...]
  85. >  inputreq->io_Command = IND_ADDHANDLER;
  86. >  inputreq->io_Data = &interrupt;
  87. >  interrupt.is_Node.ln_Pri = HANDLER_PRI;    /* #defined as 10 */
  88. >  handlerdata.parentport = handlerport;
  89. >  handlerdata.parenttask = &(process->pr_Task);
  90. >  handlerdata.unblanksig = unblanksig;
  91. >  interrupt.is_Data = &handlerdata;
  92. >  interrupt.is_Code = InputHandler; /* InputHandler calls C_InputHandler (2*) */
  93. >  if(DoIO(inputreq)) {
  94. >    /* Error */
  95. >  }
  96.  
  97. >/*********** Input handler, called with stack-arguments ***************/
  98. >struct InputEvent *
  99. >    C_InputHandler(struct InputEvent *ev, struct HandlerData *data) {
  100. >  struct InputEvent *currev, *retev, *procev, *tmpev;
  101. >  currev = ev; retev = procev = NULL;
  102. >  while(currev) {
  103. >    tmpev = currev->ie_NextEvent;
  104. >    switch(currev->ie_Class) {
  105. >      case IECLASS_RAWKEY :
  106. >      case IECLASS_RAWMOUSE :
  107. >    Signal(data->parenttask, data->unblanksig);  /* Crash here!! (1*) */
  108. >    break;
  109. >      default :
  110. >    }
  111. >    currev = tmpev;
  112. >  }
  113. >  return ev;
  114. >}
  115.  
  116. >/*********** _InputHandler called with register arguments *************/
  117. >        xref    _C_InputHandler
  118. >        xdef    _InputHandler
  119. >_InputHandler:    movem.l    A0/A1,-(A7)
  120. >        jsr     _C_InputHandler
  121. >        addq.l    #8,A7
  122. >        rts
  123. >        end
  124. >--
  125. >_/_/_/_/_/   _/    _/         Thomas  Holmstr|m
  126. >   _/       _/_/_/_/        tomme@Student.docs.uu.se
  127. >  _/       _/    _/            +46 18 261628
  128. > _/       _/    _/   DVL, University of Uppsala, Sweden
  129.  
  130.     The one thing I notice off the bat is that you are not restoring
  131. the data segment in the Input handler code. The function Signal(), for
  132. example, needs the base of the exec library and the stub code (or what-
  133. ever) expects to find it in the global variable _SysBase. The variable
  134. SysBase is known to the compiler as some offset from the base of the
  135. data segment. Since you're not restoring it in the Input handler code,
  136. Signal() is assuming absolute garbage as the pointer to the base of the
  137. exec library and hence - CABLOOEY!
  138.  
  139. Jeff
  140.  
  141.