|
|
1.1 root 1: //////////
2: / MWC86 runtime.
3: / Nonlocal goto.
4: //////////
5:
6: #include <larges.h>
7:
8: ////////
9: / #include <setjmp.h>
10: /
11: / int
12: / setjmp(env);
13: / jmp_buf env;
14: /
15: / The header <setjmp.h> defines jmp_buf, an array of int used to save
16: / the current frame pointer, stack pointer and return address.
17: / setjmp(env) saves BP, SP and RA in env and returns 0.
18: ////////
19:
20: env = 0
21: savebp = 0 / offset of saved BP in environment
22: savesp = 2 / offset of saved SP
23: savera = 4 / offset of saved return address
24: saveseg = 6 / offset of saved ra segment (LARGE model)
25:
26: .globl setjmp_
27:
28: setjmp_:
29: pop ax / Return address offset to AX
30: #if LARGECODE
31: pop dx / and segment to DX.
32: #endif
33: mov bx, sp
34:
35: Lds bx, Pss env(bx) / Environment pointer to DS:BX.
36: mov savebp(bx), bp / Save frame.
37: mov savesp(bx), sp / Save SP with return address popped.
38: mov savera(bx), ax / Save return address offset
39: #if LARGECODE
40: mov saveseg(bx), dx / and segment.
41: #endif
42:
43: sub ax, ax
44: Gijmp savera(bx) / Return 0.
45:
46: ////////
47: / int
48: / longjmp(env, value);
49: / jmp_buf env;
50: / int value;
51: /
52: / longjmp(env, value) restores the environment saved in "env" and
53: / causes the setjmp() call to return again, this time returning "value".
54: ////////
55:
56: env = RASIZE
57: value = env+PTRSIZE
58:
59: .globl longjmp_
60:
61: longjmp_:
62: mov bx, sp
63: mov ax, Pss value(bx) / Return value to AX.
64: Lds bx, Pss env(bx) / Environment pointer to DS:BX.
65: mov cx, savebp(bx) / Desired BP to CX.
66:
67: L0: cmp cx, 0(bp) / Is the current frame correct?
68: je L1 / Yes.
69: mov bp, 0(bp) / Unwind a frame.
70: or bp, bp / Have we hit the top frame?
71: jne L0 / No, unwind another.
72:
73: mov bp, cx / We hit the top, just take a stab at
74: jmp L2 / restoring the frame.
75:
76: L1: mov sp, bp / Reset stack to correct place
77: pop bp / and restore frame
78: pop di / and the two
79: pop si / register variables.
80:
81: L2: mov sp, savesp(bx) / Restore SP and
82: Gijmp savera(bx) / return from the setjmp.
83:
84: / end of setjmp.m
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.