Path: utzoo!attcan!telly!lethe!yunexus!ists!helios.physics.utoronto.ca!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!indetech!daver!bungi.com!news From: jkp@sauna.hut.fi (Jyrki Kuoppala) Newsgroups: comp.sys.nsc.32k Subject: Bug in minix library setjmp.s; lots of GNU tools diffs available Message-ID: <9102060029.AA11466@cs.hut.fi> Date: 6 Feb 91 00:29:49 GMT Sender: news@daver.bungi.com Organization: Helsinki University of Technology, Finland. Lines: 140 Approved: news@daver.bungi.com When porting emacs to pc532-Minix, I noticed there's a bug in the setjmp library routine - it doesn't save registers r3-r7 (and f4-f7) which I think it should do. This seems like a serious bug and I'm surprised it has caused so little trouble when compiling all the other software I have on the pc532. At the end of this message there's a fixed setjmp.s (it's in gas format as I just moved to use GNU tools, but converting to Bruce syntax shouldn't be difficult) and a test program to test the functioning of setjmp. I now have a complete environment (including libc) working with the GNU tools: gcc 1.39 with patches, gas 1.38.1 with patches, GNU binutils with patches, GNU make 3.59, emacs 18.57 (subprocesses don't work yet), bash 1.05.1, GNU fileutils etc. G++ will be easy now when gas and GNU ld are used; gdb is next on my list. Most of the diffs to get these up are (or will be soon) available for anon. ftp from nic.funet.fi in directory pub/misc/pc532/GNU-hut. They're still not very pretty to look at, but they work, mostly. I think some programs require kernel additions like some more support for flags of open(2) and non-blocking I/O, fcntl flags etc. Gas and binutils didn't cope with the ns32k family properly without some fixing. Bootstrapping with the broken Minix programs was also painful. If there's interest, I could perhaps make the binaries available (hmm, I don't know what the various copyright restrictions with Minix and GNU software have to say to that). I'd like to scrap all the Minix library routines (except the syscalls, of course - they'll have to wait until we get free Mach 3.0) for a free libc. Any good free library sources out there ? Here's setjmp.s: #APP # # jkp@cs.hut.fi added saving & restoring of r3-r7 & f4-f7 5 Feb 1991 sj_fp=0 sj_sp=4 sj_pc=8 sj_r3=12 sj_r4=16 sj_r5=20 sj_r6=24 sj_r7=28 sj_f4=32 sj_f5=36 sj_f6=40 sj_f7=44 .text .globl _setjmp _setjmp: movd 4(sp),r0 #ptr to struct addr 0(fp),sj_fp(r0) #save fp addr 0(sp),sj_sp(r0) #save sp addr 0(r3),sj_r3(r0) #save r3 addr 0(r4),sj_r4(r0) #save r4 addr 0(r5),sj_r5(r0) #save r5 addr 0(r6),sj_r6(r0) #save r6 addr 0(r7),sj_r7(r0) #save r7 addr 0(f4),sj_f4(r0) #save f4 addr 0(f5),sj_f5(r0) #save f5 addr 0(f6),sj_f6(r0) #save f6 addr 0(f7),sj_f7(r0) #save f7 movd 0(sp),sj_pc(r0) #save return address movqd 0,r0 #return 0 ret 0 .globl _longjmp _longjmp: movd 8(sp),r0 #return value cmpqd 0,r0 #never return 0 bne longjmp1 movqd 1,r0 longjmp1: movd 4(sp),r1 #pointer to env movd sj_f7(r1),f7 #restore f7 movd sj_f6(r1),f6 #restore f6 movd sj_f5(r1),f5 #restore f5 movd sj_f4(r1),f4 #restore f4 movd sj_r7(r1),r7 #restore r7 movd sj_r6(r1),r6 #restore r6 movd sj_r5(r1),r5 #restore r5 movd sj_r4(r1),r4 #restore r4 movd sj_r3(r1),r3 #restore r3 lprd sp,sj_sp(r1) #restore sp lprd fp,sj_fp(r1) #restore fp movd sj_pc(r1),0(sp) #restore return adr ret 0 Remember to change _JBLEN from 3 to 12 in /usr/include/setjmp.h Here's the test program: #include #include jmp_buf env; void foo() { register int b = 2; fprintf (stderr, "b = %d\n", b); } void bar() { register int c = 3; fprintf (stderr, "c = %d\n", 3); longjmp(env, 1); } main() { register int a = 1; foo(); if (setjmp (env)) fprintf (stderr, "a = %d\n", a); else { bar(); } } It outputs: b = 2 c = 3 a = 1 when everything is OK, but b = 2 c = 3 a = 3 when the bug exists. //Jyrki