1*22518Sdist /* 2*22518Sdist * Copyright (c) 1980 Regents of the University of California. 3*22518Sdist * All rights reserved. The Berkeley software License Agreement 4*22518Sdist * specifies the terms and conditions for redistribution. 5*22518Sdist */ 65516Slinton 7*22518Sdist #ifndef lint 8*22518Sdist static char sccsid[] = "@(#)entry.c 5.1 (Berkeley) 06/06/85"; 9*22518Sdist #endif not lint 105516Slinton /* 115516Slinton * routines to deal with the entry addresses of blocks 125516Slinton */ 135516Slinton 145516Slinton #include "defs.h" 155516Slinton #include "runtime.h" 165516Slinton #include "frame.rep" 175516Slinton #include "machine.h" 185516Slinton #include "process.h" 195516Slinton #include "sym.h" 205516Slinton #include "source.h" 215516Slinton #include "object.h" 225516Slinton #include "process/pxinfo.h" 235516Slinton #include "process/process.rep" 245516Slinton 255516Slinton /* 265516Slinton * Return the address of the beginning of the procedure/function 275516Slinton * associated with the given frame. 285516Slinton */ 295516Slinton 305516Slinton ADDRESS entry(frp) 315516Slinton register FRAME *frp; 325516Slinton { 335516Slinton return(frp->blockp - 2 - ENDOFF); 345516Slinton } 355516Slinton 365516Slinton /* 375516Slinton * Find the entry address of the caller of the current block. 385516Slinton * This is only called in connection with breakpoints. 395516Slinton * 405516Slinton * This routine assumes it is at the very beginning of the block. 415516Slinton */ 425516Slinton 435516Slinton ADDRESS caller_addr() 445516Slinton { 455516Slinton FRAME *frp; 465516Slinton 475516Slinton if ((frp = curframe()) == NIL) { 485516Slinton panic("caller_addr(main program)"); 495516Slinton } 505516Slinton frp = nextframe(frp); 515516Slinton if (frp == NIL) { 525516Slinton return(codeloc(program)); 535516Slinton } else { 545516Slinton return(entry(frp)); 555516Slinton } 565516Slinton } 575516Slinton 585516Slinton /* 595516Slinton * Find the return address of the current procedure/function. 605516Slinton * 615516Slinton * There are two special cases: 625516Slinton * 635516Slinton * we're right at the beginning of the main program 645516Slinton * we're right at the beginning of some procedure or function 655516Slinton * 665516Slinton * The first one is handled by returning the last instruction in 675516Slinton * the object code. In the second case, we get the return address 685516Slinton * directly from the process' stack. 695516Slinton */ 705516Slinton 715516Slinton ADDRESS return_addr() 725516Slinton { 735516Slinton ADDRESS addr; 745516Slinton FRAME *frp, frame; 755516Slinton 765516Slinton if (pc == codeloc(program)) { 775516Slinton addr = lastaddr(); 785516Slinton } else { 795516Slinton frp = curframe(); 805516Slinton if (frp == NIL) { 815516Slinton dread(&frame, (ADDRESS) process->sp, sizeof(FRAME)); 825516Slinton addr = frame.save_pc - ENDOFF; 835516Slinton } else { 845516Slinton addr = frp->save_pc; 855516Slinton } 865516Slinton } 875516Slinton return addr; 885516Slinton } 895516Slinton 905516Slinton /* 915516Slinton * Calculate the entry address for a procedure or function parameter, 925516Slinton * given the address of the descriptor. 935516Slinton */ 945516Slinton 955516Slinton ADDRESS fparamaddr(a) 965516Slinton ADDRESS a; 975516Slinton { 985516Slinton ADDRESS r; 995516Slinton 1005516Slinton dread(&r, a, sizeof(r)); 1015516Slinton return (r - ENDOFF); 1025516Slinton } 103