Discussion:
Help needed: small piece of assembler code for IRAF
(too old to reply)
Andreas Schwab
2024-09-18 22:10:01 UTC
Permalink
As IRAF is a 40-year old package, there was already some assembler that
.text
.globl _zsvjmp_
JMPBUF = 4
STATUS = 8
_zsvjmp_: |# CALL ZSVJMP (JMPBUF, STATUS)
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, ***@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1
"And now for something completely different."
Adam Sampson
2024-09-18 23:00:01 UTC
Permalink
Hi Ole,
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 <***@offog.org> <http://offog.org/>
Loading...