info-mac@uw-beaver (info-mac) (07/19/84)
From: Bill Croft <croft@safe>
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