[comp.sys.apollo] Looking for detailed runtime info.

wjw@ebh.eb.ele.tue.nl (Willem Jan Withagen) (05/30/91)

                                           
I must admit that I haven't scanned the manuals yet. But I want to know the
following.

When executing a program all (local) variables are allocated in the data-segment
the stack has a separate segment? Yes?
                                      
How do I find the start and end point of these segments at runtime?
This for PIC-code and absolute code.
I could include two variables for the data-segment, and test the
sp a program start to find the bottom, but I'd like something beter.

Under sr9.7 I just used an empirical tested value, which has never proven
me wrong on our DN{3,4}000. But now I got slapped in the face. :{

Thanx,
	Willem Jan
-- 
Eindhoven University of Technology   DomainName:  wjw@eb.ele.tue.nl    
Digital Systems Group, Room EH 10.10 
P.O. 513                             Tel: +31-40-473401
5600 MB Eindhoven                    The Netherlands

jjw1@harvey.gte.com (James J. Walker) (05/31/91)

In article <1199@eba.eb.ele.tue.nl> wjw@eb.ele.tue.nl writes:

>I must admit that I haven't scanned the manuals yet. But I want to know the
>following.
>
>When executing a program all (local) variables are allocated in the data-segment
>the stack has a separate segment? Yes?
>                                      
>How do I find the start and end point of these segments at runtime?
>This for PIC-code and absolute code.
>I could include two variables for the data-segment, and test the
>sp a program start to find the bottom, but I'd like something beter.
>
>Under sr9.7 I just used an empirical tested value, which has never proven
>me wrong on our DN{3,4}000. But now I got slapped in the face. :{
>
>Thanx,
>	Willem Jan
>-- 
>Eindhoven University of Technology   DomainName:  wjw@eb.ele.tue.nl    
>Digital Systems Group, Room EH 10.10 
>P.O. 513                             Tel: +31-40-473401
>5600 MB Eindhoven                    The Netherlands


Well, I have done some of this before.  The following is some extracted
code (without error-checking) to find the start and end addresses of
some segments.  It should be easy to modify this to find the addresses
for any segments that you are interested in.  Oh, and the current stack
address can be had by taking the address of an auto variable (is this
really a portable way to find the current stack pointer?).

-----

#include <apollo/base.h>
#include <apollo/proc2.h>
#include <apollo/loader.h>


unsigned long stack_limit;

unsigned long data_start;
unsigned long data_limit;

unsigned long bss_start;
unsigned long bss_limit;


int
main (int argc, char **argv)
  {
    uid_$t me;
    proc2_$info_t info;
    loader_$handle_t handle = 0;
    loader_$image image;
    loader_$section section;
    unsigned long i;
    status_$t st;

    proc2_$who_am_i (&me);
    proc2_$get_info (me, &info, sizeof (info), &st);

    stack_limit = info.stack_base;

    loader_$inquire_image (handle, &image, &st);
    for (i = 1; i <= image.nsects; i++)
      {
        loader_$inquire_section (image.handle, i, &section, &st);

        if (strncmp (section.name, ".data", section.name_len) == 0)
          {
            data_start = section.addr;
            data_limit = section.addr + section.len;
          }

        if (strncmp (section.name, ".bss", section.name_len) == 0)
          {
            bss_start = section.addr;
            bss_limit = section.addr + section.len;
          }
      }
  }

-----

N.B...  I do not remember why the loop goes from 1 to image.nsects.
According to the documentation, index 0 should be the first section.
Oh well, so much for my failing bits :-)


Good luck...
...Walker

--------
James Walker  <jjw1@gte.com>
GTE Laboratories, Waltham, MA
--
--------
James Walker  <jjw1@gte.com>
GTE Laboratories, Waltham, MA