non local returns in SUMacC using setjmp/longjmp

Info-Mac discussion from 1984 - 2002.
Locked
User avatar
Info-Mac
Administrator
Posts:13716
Joined:December 21st, 1988, 11:00 am
non local returns in SUMacC using setjmp/longjmp

Post by Info-Mac » August 28th, 1984, 6:07 am

Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10 UW 5/3/83; site uw-beaver
Path: utzoo!watmath!clyde!burl!ulysses!mhuxl!houxm!houxa!vax135!cornell!uw-beaver!info-mac
From: info-mac@uw-beaver (info-mac)
Newsgroups: fa.info-mac
Subject: non local returns in SUMacC using setjmp/longjmp
Message-ID:
Date: Thu, 19-Jul-84 14:11:20 EDT
Article-I.D.: uw-beaver>.1257
Posted: Thu Jul 19 14:11:20 1984
Date-Received: Fri, 20-Jul-84 04:36:43 EDT
Sender: daemon@uw-beave
Organization: U of Washington Computer Science
Lines: 58

From: Bill Croft
The "libc.a" provided on the SUMacC distribution contains a setjmp/longjmp.
The calling sequence is the same as for 4.2BSD (and most other UNIXes).
Your program must declare a "type" jmp_buf:

typedef int jmp_buf[13];
jmp_buf environ;
...
if (setjmp(&environ) != 0) { /* abort */ }
...
longjmp(&environ,1); /* return to toplevel */

Here's the assembler in case you're curious:

|setjmp, longjmp
|
| longjmp(a, v)
|causes a "return(v)" from the
|last call to
|
| setjmp(v)
|by restoring all the registers and
|adjusting the stack
|
|jmp_buf is set up as:
|
| _________________
| | pc |
| -----------------
| | d2 |
| -----------------
| | ... |
| -----------------
| | d7 |
| -----------------
| | a2 |
| -----------------
| | ... |
| -----------------
| | a7 |
| -----------------

.globl setjmp, longjmp
.text

setjmp:
movl sp@(4.),a0 |pointer to jmp_buf
movl sp@,a0@ |pc
moveml #/FCFC,a0@(4.) |d2-d7, a2-a7
clrl d0 |return 0
rts

longjmp:
movl sp@(4.),a0 |pointer to jmp_buf
movl sp@(8.),d0 |value returned
moveml a0@(4.),#/FCFC |restore d2-d7, a2-a7
movl a0@,sp@ |restore pc of call to setjmp to stack
rts
Locked