Re: Help needed for small assembler script for the iraf package
Hi Ole,
Em qui, 18 de out de 2018 às 09:15, Ole Streicher <olebole@debian.org> escreveu:
>
> Dear riscv specialists,
>
> triggered by the recent announcement of the riscv64,
Actually, this happened back in March/April, it's only that the "misc
news for devels" didn't get published until last week... :D
> I would like to get
> my "IRAF" package [1] working on that platform. IRAF is a quite old (>30
> years) package for astrophysics that still serves as a reference.
> 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:
> [...]
Note: Credit to Stefan O'Rear who came up with almost the same code,
and helped to guide to a successful solution with the compiler.
Also, writing assembly is not my forte, so hopefully someone else in
the list can double-check and stamp the seal... and hopefully this
code is not used for anything critical without more testing :-P
That said...
With the given C code (but note the name of the function):
===========================================
==> test.c <==
int zsvjmp_( long *buf, long *status ) {
*status = 0;
((long **)buf)[0] = status;
return sigsetjmp_placeholder ((void *)((long **)buf+1),0);
}
===========================================
and with this command: gcc -c -O2 -ffreestanding -S test.c
We get to this:
===========================================
==> test.s <==
.file "test.c"
.option pic
.text
.align 1
.globl zsvjmp_
.type zsvjmp_, @function
zsvjmp_:
sd zero,0(a1)
sd a1,0(a0)
li a1,0
addi a0,a0,8
tail sigsetjmp_placeholder@plt
.size zsvjmp_, .-zsvjmp_
.ident "GCC: (Debian 8.2.0-7) 8.2.0"
===========================================
> I created a small repository [2] that contains the assembler I collected
> so far as well as two test programs. The function of the Fortran test
> program is still not so important since IRAF uses its own Fortran
> calling interface.
...and changing the name of the funtion in the assembly to
__sigsetjmp@plt and the name of the file to zsvjmp-riscv64.s (*):
===========================================
.../zsvjmp $ make test
as -o zsvjmp-riscv64.o zsvjmp-riscv64.s
ar cr libzsvjmp.a zdojmp.o zsvjmp-riscv64.o
gfortran -o jmptest jmptest.o -L. -lzsvjmp
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 = 1 step = 1
All OK
STOP 0
===========================================
(*) Literally:
$ sed 's/sigsetjmp_placeholder@plt/__sigsetjmp@plt/g' test.s >
zsvjmp-riscv64.s
And I also had to change "uname -p" in the Makefile to "uname -m"
("uname -p" said "unknown"), "arch" should also work.
> However, I have no idea how to write the same for the 64-bit platform
> riscv64. Maybe someone could help me here? Preferably under the IRAF
> license [3], so that it can be included upstream later.
It's output from the compiler for code that you posted, so I'd say
"sure" without even looking to the text of the license...
Cheers.
--
Manuel A. Fernandez Montecelo <manuel.montezelo@gmail.com>
Reply to: