• Re: Help needed: small piece of assembler code for IRAF

    From Andreas Schwab@21:1/5 to Ole Streicher on Thu Sep 19 00:10:01 2024
    On Sep 18 2024, Ole Streicher wrote:

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

    .text
    .globl _zsvjmp_

    JMPBUF = 4
    STATUS = 8

    _zsvjmp_: |# CALL ZSVJMP (JMPBUF, STATUS)
    movl sp@(JMPBUF),a0 |# set A0 to point to jmp_buf
    movl sp@(STATUS),a1 |# A1 = status variable
    movl a1,a0@ |# JB[0] = addr of status variable
    clrl a1@ |# return zero status
    addql #4,sp@(JMPBUF) |# skip first cell of jmp_buf
    jmp _setjmp |# let setjmp do the rest.

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

    Registers need to be prefixed with %, and assembler labels for C symbols
    do not have a _ prefix.

    --
    Andreas Schwab, schwab@linux-m68k.org
    GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1
    "And now for something completely different."

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Adam Sampson@21:1/5 to Ole Streicher on Thu Sep 19 01:00:01 2024
    Hi Ole,

    Ole Streicher <olebole@debian.org> writes:
    I created a small repository [4] that contains the assembler I
    collected so far as well as two test programs.

    The code you've written looks OK -- the only problem is that in
    glibc, sigsetjmp is a macro which calls the real function __sigsetjmp: https://sourceware.org/git/?p=glibc.git;a=blob;f=setjmp/setjmp.h;hb=HEAD#l72

    So you need "jra __sigsetjmp" (as you've done on other architectures),
    rather than "jra sigsetjmp". With that change, your tests work on an
    emulated m68k machine:

    $ git diff
    diff --git a/zsvjmp-m68k.s b/zsvjmp-m68k.s
    index 3b12e5d..43ca08c 100644
    --- a/zsvjmp-m68k.s
    +++ b/zsvjmp-m68k.s
    @@ -12,7 +12,7 @@ zsvjmp_:
    move.l %a1,(%a0)+
    clr.l 8(%sp)
    move.l %a0,4(%sp)
    - jra sigsetjmp
    + jra __sigsetjmp

    .size zsvjmp_, .-zsvjmp_
    .section .note.GNU-stack,"",@progbits

    $ make ARCH=m68k test
    gfortran -ff2c -g -c -o jmptest.o jmptest.f
    gcc -g -c -o zdojmp.o zdojmp.c
    as -o zsvjmp-m68k.o zsvjmp-m68k.s
    ar cr libzsvjmp.a zdojmp.o zsvjmp-m68k.o
    gfortran -o jmptest jmptest.o -L. -lzsvjmp
    gcc -g -c -o zzdebug.o zzdebug.c
    gcc -g -g -o zzdebug zzdebug.o -L. -lzsvjmp
    ./zzdebug
    Status = 0, step = 0
    Calling zdojmp
    Status = 1, step = 1
    All OK
    ./jmptest
    Status = 0 step = 0
    Calling zdojmp
    Status = 4294967296 step = 1
    All OK
    STOP 0

    Thanks,

    --
    Adam Sampson <ats@offog.org> <http://offog.org/>

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)