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