Commit | Line | Data |
---|---|---|
505bf312 KB |
1 | /*- |
2 | * Copyright (c) 1980 The Regents of the University of California. | |
3 | * All rights reserved. | |
4 | * | |
5 | * %sccs.include.redist.c% | |
f644bb55 | 6 | */ |
18e2a93b | 7 | |
f644bb55 | 8 | #ifndef lint |
505bf312 KB |
9 | static char sccsid[] = "@(#)entry.c 5.2 (Berkeley) %G%"; |
10 | #endif /* not lint */ | |
11 | ||
18e2a93b ML |
12 | /* |
13 | * routines to deal with the entry addresses of blocks | |
14 | */ | |
15 | ||
16 | #include "defs.h" | |
17 | #include "runtime.h" | |
18 | #include "frame.rep" | |
19 | #include "machine.h" | |
20 | #include "process.h" | |
21 | #include "sym.h" | |
22 | #include "source.h" | |
23 | #include "object.h" | |
24 | #include "process/pxinfo.h" | |
25 | #include "process/process.rep" | |
26 | ||
27 | /* | |
28 | * Return the address of the beginning of the procedure/function | |
29 | * associated with the given frame. | |
30 | */ | |
31 | ||
32 | ADDRESS entry(frp) | |
33 | register FRAME *frp; | |
34 | { | |
35 | return(frp->blockp - 2 - ENDOFF); | |
36 | } | |
37 | ||
38 | /* | |
39 | * Find the entry address of the caller of the current block. | |
40 | * This is only called in connection with breakpoints. | |
41 | * | |
42 | * This routine assumes it is at the very beginning of the block. | |
43 | */ | |
44 | ||
45 | ADDRESS caller_addr() | |
46 | { | |
47 | FRAME *frp; | |
48 | ||
49 | if ((frp = curframe()) == NIL) { | |
50 | panic("caller_addr(main program)"); | |
51 | } | |
52 | frp = nextframe(frp); | |
53 | if (frp == NIL) { | |
54 | return(codeloc(program)); | |
55 | } else { | |
56 | return(entry(frp)); | |
57 | } | |
58 | } | |
59 | ||
60 | /* | |
61 | * Find the return address of the current procedure/function. | |
62 | * | |
63 | * There are two special cases: | |
64 | * | |
65 | * we're right at the beginning of the main program | |
66 | * we're right at the beginning of some procedure or function | |
67 | * | |
68 | * The first one is handled by returning the last instruction in | |
69 | * the object code. In the second case, we get the return address | |
70 | * directly from the process' stack. | |
71 | */ | |
72 | ||
73 | ADDRESS return_addr() | |
74 | { | |
75 | ADDRESS addr; | |
76 | FRAME *frp, frame; | |
77 | ||
78 | if (pc == codeloc(program)) { | |
79 | addr = lastaddr(); | |
80 | } else { | |
81 | frp = curframe(); | |
82 | if (frp == NIL) { | |
83 | dread(&frame, (ADDRESS) process->sp, sizeof(FRAME)); | |
84 | addr = frame.save_pc - ENDOFF; | |
85 | } else { | |
86 | addr = frp->save_pc; | |
87 | } | |
88 | } | |
89 | return addr; | |
90 | } | |
91 | ||
92 | /* | |
93 | * Calculate the entry address for a procedure or function parameter, | |
94 | * given the address of the descriptor. | |
95 | */ | |
96 | ||
97 | ADDRESS fparamaddr(a) | |
98 | ADDRESS a; | |
99 | { | |
100 | ADDRESS r; | |
101 | ||
102 | dread(&r, a, sizeof(r)); | |
103 | return (r - ENDOFF); | |
104 | } |