Hi,

On 04/01/18 10:22, Ole Streicher wrote:
> Dear MIPS specialists,
> 
> I just got the "IRAF" package accepted into Debian [1]. Although the
> code is claimed to be portable, it needs a piece  of assembler
> code for each platform that provides a (sort of) setjmp() to their
> Fortran variant.
> 
> 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.
> 
> For the 32 bit platforms, I asked this already 3 years ago [2], and got
> an implementation by David Kuehling:
> 
[...]
> The "zdojmp" counterpart is a portable C function.
> 
> I created a small repository [3] that contains the assembler I collected
> so far as well as two test programs.
> 
> However, I have no idea how to write the same for the 64-bit platform
> mips64el. Maybe someone could help me here? Preferably under the IRAF
> license [4], so that it can be included upstream later.

I think the attached code will work for all MIPS variants (32-bit and
64-bit). To do this it uses some headers from glibc and therefore needs
to be compiled using "gcc" instead of "as" (arguably userspace apps
should never use "as" directly anyway).

Thanks,
James
#include <sys/asm.h>
#include <sys/regdef.h>

/*
 * Copyright (c) 2018 James Cowgill <jcowgill AT debian TOD org>
 * Distributable under the same license as IRAF
 */

        .file   "zsvjmp.s"
        .text

LEAF(zsvjmp_)
        SETUP_GP                        /* Load gp (needed for PTR_LA) */
        SETUP_GP64(v0, zsvjmp_)

        PTR_S a1, 0(a0)                 /* buf[0] = status */
        LONG_S zero, 0(a1)              /* *status = 0 */
        PTR_ADDIU a0, a0, PTRSIZE       /* a0 = &buf[1], 1st arg for sigsetjmp 
*/
        move a1, zero                   /* a1 = 0, 2nd arg */

        PTR_LA t9, __sigsetjmp          /* t9 = address of sigsetjmp */
        RESTORE_GP64                    /* Restore gp */
        jr t9                           /* Tail call sigsetjmp */
END(zsvjmp_)

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

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to