Hi Ole,

Attached is PA 1.1 zsvjmp.s code generated by gcc.  I then hacked the code to 
remove
the stack frame and added some comments.  See zsvjmp_.s file.  The resulting 
code is
slightly more optimal than your old assembly fragment.

It assembles okay with current binutils assembler.

Hope this helps,
Dave Anglin

On 2024-09-18 2:31 p.m., Ole Streicher wrote:
Dear m68k enthusiasts,

I am the maintainer of the "iraf" package [1]. Although most of the code is portable, it needs one piece of assembler code for each platform that provides a (sort of) setjmp for FORTRAN.

A "C" implementation for this looks like:

#include <setjmp.h>

int zsvjmp_( long *buf, long *status ) {
  *status = 0;
  ((long **)buf)[0] = status;
  return sigsetjmp ((void *)((long **)buf+1),0);
}

however this does not work, since the "sigsetjmp" call needs to be replaced by 
a jump to sigsetjmp instead.

As IRAF is a 40-year old package, there was already some assembler that was 
used ~35 years ago [2]:

-------------------------------8<-----------------------------------
    .proc
    .import setjmp
    .export zsvjmp
    .callinfo
zsvjmp
;
;    save address to status word in jmp_buf[0]
;
    stw     arg1,0(0,arg0)
    ldi    0,1
    stws    1,0(0,arg1)
;
;    call setjmp with jmp_buf[1]..jmp_buf[51]
;
    addi    4,arg0,arg0
    b    setjmp
    nop
;
;    setjmp will return directly to the caller of zsvjmp at this
;    point, so the next statement will never be reached.
;
    nop
    .procend
-------------------------------8<-----------------------------------

However, just including this does not work because assembler syntax changed [3].

I created a small repository [4] that contains the assembler I collected
so far as well as two test programs.

As I am not familiar with HP assembler I have no idea how to adopt the assembler code. Maybe someone could help me here? Preferably under the IRAF license [5], so that it can be included upstream later.

One way that worked for other platforms was to compute the C snipped above (having the sigsetjmp function name by something else) with an optimizing compiler.

There is no request from the users to have this ported to hppa, and I
doubt that ever will. My main motivation to get it ported is to check
the package for hidden problems on "unusual" architectures.

Best regards

Ole


[1] https://tracker.debian.org/pkg/iraf
[2] 
https://github.com/iraf-community/iraf/blob/v2.16.1/unix/portkit/zsvjmp.s.HP800
[3] 
https://buildd.debian.org/status/fetch.php?pkg=iraf&arch=hppa&ver=2.18.1%7Erc1-3%7E2&stamp=1726682218&raw=0
[4] https://github.com/olebole/zsvjmp
[5] https://iraf-community.github.io/COPYRIGHT.html



--
John David Anglin  [email protected]
        .LEVEL 1.1
        .text
        .align 4
.globl zsvjmp_
        .type   zsvjmp_, @function
zsvjmp_:
        .PROC
        .CALLINFO FRAME=64,CALLS,SAVE_RP
        .ENTRY
        stw %r2,-20(%r30)
        copy %r25,%r28
        ldo 64(%r30),%r30
        stw %r0,0(%r25)
        ldo 4(%r26),%r26
        ldi 0,%r25
        bl __sigsetjmp,%r2
        stw %r28,-4(%r26)
        ldw -84(%r30),%r2
        bv %r0(%r2)
        ldo -64(%r30),%r30
        .EXIT
        .PROCEND
        .size   zsvjmp_, .-zsvjmp_
        .ident  "GCC: (Debian 14.2.0-4) 14.2.0"
        .section        .note.GNU-stack,"",@progbits
        .LEVEL 1.1
        .text
        .align 4
.globl zsvjmp_
        .type   zsvjmp_, @function
zsvjmp_:
        .PROC
; We don't need a frame
        .CALLINFO
        .ENTRY
        copy %r25,%r28
;
;       *status = 0
;
        stw %r0,0(%r25)
;
;       arg0++
;
        ldo 4(%r26),%r26
        ldi 0,%r25
        b __sigsetjmp
;
;       ((long **)buf)[0] = status;
;
        stw %r28,-4(%r26)
;
;       __sigsetjmp will return directly to the caller of zsvjmp at this
;       point, so the next statement will never be reached.
;
        nop
        .EXIT
        .PROCEND
        .size   zsvjmp_, .-zsvjmp_
        .ident  "GCC: (Debian 14.2.0-4) 14.2.0"
        .section        .note.GNU-stack,"",@progbits

Reply via email to