1: /*
2: * Copyright (c) 1987 Regents of the University of California.
3: * All rights reserved. The Berkeley software License Agreement
4: * specifies the terms and conditions for redistribution.
5: */
6:
7: #ifdef LIBC_SCCS
8: <@(#)_setjmp.s 1.2 (Berkeley) 1/5/87\0>
9: .even
10: #endif LIBC_SCCS
11:
12: /*
13: * val = _setjmp(env)
14: * int val;
15: * jmp_buf *env;
16: *
17: * _longjmp(env, val)
18: * jmp_buf *env;
19: * int val;
20: *
21: * Overlaid version of _setjmp and _longjmp. MUST BE LOADED IN BASE SEGMENT!!!
22: *
23: * _Longjmp(env,val) will generate a "return(val)" from the last call to
24: * _setjmp(env) by restoring the general registers r2, r3, and r4 from the
25: * stack, rolling back the frame pointer (r5) to the env constructed by
26: * _setjmp.
27: *
28: * For the overlaid _setjmp/_longjmp pair, the jmp_buf looks like:
29: *
30: * -------------------------
31: * | overlay number |
32: * |-----------------------|
33: * | frame pointer |
34: * |-----------------------|
35: * | stack pointer |
36: * |-----------------------|
37: * | return address |
38: * -------------------------
39: */
40: #include "DEFS.h"
41:
42: emt = 0104000 / overlay switch - ovno in r0
43: .globl __ovno
44:
45: ENTRY(_setjmp)
46: mov 2(sp),r0 / r0 = env
47: mov __ovno,(r0)+ / save caller's current overlay
48: mov r5,(r0)+ / and frame pointer
49: mov sp,(r0) / calculate caller's pre jsr pc,
50: add $2,(r0)+ / _setjmp sp as (sp + ret addr)
51: mov (sp),(r0) / save return pc
52: clr r0 / and return a zero
53: rts pc
54:
55: /*
56: * Note that no qualification for returning to the base segment is made in
57: * _longjmp (to avoid a posible superfluous overlay switch request) as cret
58: * does. The problem is the routine being returned to in the base could
59: * easily be one which doesn't use cret itself to return (like a system call
60: * from the library) which on its own return might be returning to a different
61: * overlay than the one currently loaded.
62: *
63: */
64: .globl rollback
65: ENTRY(_longjmp)
66: mov 2(sp),r1 / r1 = env
67: mov (r1)+,r0 / r0 = env[overlay number]
68: beq 1f / zero implies no overlay switches yet
69: cmp r0,__ovno / same overlay currently loaded?
70: beq 1f / yes, nothing to do
71: emt / no, request overlay load
72: mov r0,__ovno / and indicate new overlay
73:
74: / The last two instructions represent a potential race condition ...
75: 1:
76: mov (r1)+,r0 / r0 = env[frame pointer]
77: jsr pc,rollback / attempt stack frame rollback
78: mov 4(sp),r0 / r0 = val
79: bne 2f / if (val == 0)
80: inc r0 / r0 = 1
81: 2:
82: mov (r1)+,sp / restore stack pointer
83: jmp *(r1) / and simulate return
Defined functions
emt
defined in line
42; used 1 times