[comp.sys.hp] Xtank port and jmp_buf puzzle

hounsell@chekov.UU.NET (Rob Hounsell) (06/01/90)

Folks,

  I may be doing this the hard way, but.....

  A friend sent me the source for xtank a while back. Unfortunately, it had no
HPUX port in it, so off I went to port it myself. Things seem fine, EXCEPT for
a section in thread.c (which controls the robot tanks) like so:

    /* Modify current state's stack pointer in jmp_buf state */
    bufend = (unsigned int)buf + bufsize - 1 - sizeof(thd->state);

    /* Set stack pointer in jmp_buf to bufend.
     * This is extremely machine and OS dependent.
     * Often you can find out what register of the jmp_buf has the
     * stack pointer by looking in /usr/include/setjmp.h on your machine.
     */
#ifdef vax  /* Vaxen */
    bufend -= sizeof(Thread);
    thd->state[0] = bufend;
#endif
#if	(defined(ibm032) || defined(ibm370)) /* IBM RT */
    thd->state[0] = bufend;
#endif
 etc.....

  The setjump.h for HPUX 6.5 running on HP300 series workstations does NOT give
a clue what register to use, or how to set bufend. Can anyone suggest the
correct values??

Rob
+-----------------------------------------------------------------------------+
|  Rob Hounsell                      |                                        |
|  UUNET:  ...!chekov!mcrae!hounsell |  "You guys start coding, and I'll go   |
|  BNR WAN:  hounsell@nmerh6         |   see what it is they need."           |
|  PHONE: (613) 765-2904             |                                        |
|  ESN: 395-2904                     |   Anon.                                |
+-----------------------------------------------------------------------------+

tml@hemuli.tik.vtt.fi (Tor Lillqvist) (06/02/90)

In article <3160@bnr-rsc.UUCP> uunet!chekov!hounsell writes:
-    /* Modify current state's stack pointer in jmp_buf state */
-    bufend = (unsigned int)buf + bufsize - 1 - sizeof(thd->state);

-    /* Set stack pointer in jmp_buf to bufend.
-     * This is extremely machine and OS dependent.
-     * Often you can find out what register of the jmp_buf has the
-     * stack pointer by looking in /usr/include/setjmp.h on your machine.
-     */
-#ifdef vax  /* Vaxen */
-    bufend -= sizeof(Thread);
-    thd->state[0] = bufend;
-#endif
-#if	(defined(ibm032) || defined(ibm370)) /* IBM RT */
-    thd->state[0] = bufend;
-#endif

-  The setjump.h for HPUX 6.5 running on HP300 series workstations does NOT give
-a clue what register to use, or how to set bufend. Can anyone suggest the
-correct values??

I did once port xtank to the hp9000 series 800, but I haven't tried
porting it to the series 300.  However, the best way to understand
setjmp is to use your friendly machine level debugger adb: Compile
some small dummy program that uses setjmp/longjmp and disassemble it,
and step through its execution instruction by instruction.  This
should give you enough information to know how to proceed.
Specifically, look where the stack pointer register is stored in the
jmp_buf.

Btw, the port to the series 800 was a bit different because the stack
on the series 800 grows upward.  Most other machines with Unix seem to
have downward-growing stacks.  The stack direction of course doesn't
matter to portable code, but I had to give up on porting XView (Sun's
freely available SunView compatibility package for X), which does very
dirty tricks with varargs.
-- 
Tor Lillqvist,
working, but not speaking, for the Technical Research Centre of Finland