"I am a person who works hard and plays hard."

Yuan Wei
Second Year Graduate Student Department of Computer Science
University of Virginia Charlottesville, VA 22903
Email: yw3f@cs.virginia.edu


Source Code Analysis

Main Page   Compound List   File List   Compound Members   File Members  

loader.c File Reference

#include <stdio.h>
#include <stdlib.h>
#include "host.h"
#include "misc.h"
#include "machine.h"
#include "endian.h"
#include "regs.h"
#include "memory.h"
#include "sim.h"
#include "eio.h"
#include "loader.h"
#include "target-alpha/ecoff.h"

Include dependency graph for loader.c:

Include dependency graph

Go to the source code of this file.

Defines

Functions

Variables


Define Documentation

#define TEXT_TAIL_PADDING   0
 

Definition at line 112 of file loader.c.

Referenced by ld_load_prog().


Function Documentation

void ld_load_prog char *    fname,
int    argc,
char **    argv,
char **    envp,
struct regs_t   regs,
struct mem_t   mem,
int    zero_bss_segs
 

Definition at line 192 of file loader.c.

References ecoff_aouthdr::bsize, counter_t, ecoff_aouthdr::data_start, debug(), ecoff_aouthdr::dsize, ECOFF_STYP_FINI, ECOFF_STYP_INIT, ECOFF_STYP_LIT4, ECOFF_STYP_LIT8, ECOFF_STYP_LITA, ECOFF_STYP_PDATA, ECOFF_STYP_RCONST, ECOFF_STYP_XDATA, eio_fast_forward(), eio_open(), eio_read_chkpt(), eio_valid(), endian_host_byte_order(), endian_host_word_order(), endian_target_byte_order(), endian_target_word_order(), ecoff_aouthdr::entry, ecoff_filehdr::f_magic, ecoff_filehdr::f_nscns, ecoff_filehdr::f_opthdr, FALSE, fatal(), ecoff_aouthdr::gp_value, ld_brk_point, ld_data_base, ld_data_size, ld_environ_base, ld_prog_entry, ld_prog_fname, ld_stack_base, ld_stack_min, ld_stack_size, ld_target_big_endian, ld_text_base, ld_text_size, MD_DATA_BASE, MD_STACK_BASE, MD_SWAPH, MD_SWAPQ, MD_SWAPW, MD_TEXT_BASE, mem_access(), mem_bcopy(), mem_bzero(), mem_strcpy(), myfprintf(), mystrdup(), regs_t::regs_PC, regs_t::regs_R, ROUND_DOWN, ROUND_UP, ecoff_scnhdr::s_flags, ecoff_scnhdr::s_name, ecoff_scnhdr::s_scnptr, ecoff_scnhdr::s_size, ecoff_scnhdr::s_vaddr, ecoff_aouthdr::text_start, TEXT_TAIL_PADDING, ecoff_aouthdr::tsize, warn(), and Write.

00198 {
00199   int i;
00200   qword_t temp;
00201   md_addr_t sp, data_break = 0, null_ptr = 0, argv_addr, envp_addr;
00202 
00203   if (eio_valid(fname))
00204     {
00205       if (argc != 1)
00206         {
00207           fprintf(stderr, "error: EIO file has arguments\n");
00208           exit(1);
00209         }
00210 
00211       fprintf(stderr, "sim: loading EIO file: %s\n", fname);
00212 
00213       sim_eio_fname = mystrdup(fname);
00214 
00215       /* open the EIO file stream */
00216       sim_eio_fd = eio_open(fname);
00217 
00218       /* load initial state checkpoint */
00219       if (eio_read_chkpt(regs, mem, sim_eio_fd) != -1)
00220         fatal("bad initial checkpoint in EIO file");
00221 
00222       /* load checkpoint? */
00223       if (sim_chkpt_fname != NULL)
00224         {
00225           counter_t restore_icnt;
00226 
00227           FILE *chkpt_fd;
00228 
00229           fprintf(stderr, "sim: loading checkpoint file: %s\n",
00230                   sim_chkpt_fname);
00231 
00232           if (!eio_valid(sim_chkpt_fname))
00233             fatal("file `%s' does not appear to be a checkpoint file",
00234                   sim_chkpt_fname);
00235 
00236           /* open the checkpoint file */
00237           chkpt_fd = eio_open(sim_chkpt_fname);
00238 
00239           /* load the state image */
00240           restore_icnt = eio_read_chkpt(regs, mem, chkpt_fd);
00241 
00242           /* fast forward the baseline EIO trace to checkpoint location */
00243           myfprintf(stderr, "sim: fast forwarding to instruction %n\n",
00244                     restore_icnt);
00245           eio_fast_forward(sim_eio_fd, restore_icnt);
00246         }
00247 
00248       /* computed state... */
00249       ld_environ_base = regs->regs_R[MD_REG_SP];
00250       ld_prog_entry = regs->regs_PC;
00251 
00252       /* fini... */
00253       return;
00254     }
00255 #ifdef MD_CROSS_ENDIAN
00256   else
00257     {
00258       warn("endian of `%s' does not match host", fname);
00259       warn("running with experimental cross-endian execution support");
00260       warn("****************************************");
00261       warn("**>> please check results carefully <<**");
00262       warn("****************************************");
00263 #if 0
00264       fatal("SimpleScalar/Alpha only supports binary execution on\n"
00265             "       little-endian hosts, use EIO files on big-endian hosts");
00266 #endif
00267     }
00268 #endif /* MD_CROSS_ENDIAN */
00269 
00270   if (sim_chkpt_fname != NULL)
00271     fatal("checkpoints only supported while EIO tracing");
00272 
00273 #ifdef BFD_LOADER
00274 
00275   {
00276     bfd *abfd;
00277     asection *sect;
00278 
00279     /* set up a local stack pointer, this is where the argv and envp
00280        data is written into program memory */
00281     ld_stack_base = MD_STACK_BASE;
00282     sp = ROUND_DOWN(MD_STACK_BASE - MD_MAX_ENVIRON, sizeof(MD_DOUBLE_TYPE));
00283     ld_stack_size = ld_stack_base - sp;
00284 
00285     /* initial stack pointer value */
00286     ld_environ_base = sp;
00287 
00288     /* load the program into memory, try both endians */
00289     if (!(abfd = bfd_openr(argv[0], "ss-coff-big")))
00290       if (!(abfd = bfd_openr(argv[0], "ss-coff-little")))
00291         fatal("cannot open executable `%s'", argv[0]);
00292 
00293     /* this call is mainly for its side effect of reading in the sections.
00294        we follow the traditional behavior of `strings' in that we don't
00295        complain if we don't recognize a file to be an object file.  */
00296     if (!bfd_check_format(abfd, bfd_object))
00297       {
00298         bfd_close(abfd);
00299         fatal("cannot open executable `%s'", argv[0]);
00300       }
00301 
00302     /* record profile file name */
00303     ld_prog_fname = argv[0];
00304 
00305     /* record endian of target */
00306     ld_target_big_endian = abfd->xvec->byteorder_big_p;
00307 
00308     debug("processing %d sections in `%s'...",
00309           bfd_count_sections(abfd), argv[0]);
00310 
00311     /* read all sections in file */
00312     for (sect=abfd->sections; sect; sect=sect->next)
00313       {
00314         char *p;
00315 
00316         debug("processing section `%s', %d bytes @ 0x%08x...",
00317               bfd_section_name(abfd, sect), bfd_section_size(abfd, sect),
00318               bfd_section_vma(abfd, sect));
00319 
00320         /* read the section data, if allocated and loadable and non-NULL */
00321         if ((bfd_get_section_flags(abfd, sect) & SEC_ALLOC)
00322             && (bfd_get_section_flags(abfd, sect) & SEC_LOAD)
00323             && bfd_section_vma(abfd, sect)
00324             && bfd_section_size(abfd, sect))
00325           {
00326             /* allocate a section buffer */
00327             p = calloc(bfd_section_size(abfd, sect), sizeof(char));
00328             if (!p)
00329               fatal("cannot allocate %d bytes for section `%s'",
00330                     bfd_section_size(abfd, sect),
00331                     bfd_section_name(abfd, sect));
00332 
00333             if (!bfd_get_section_contents(abfd, sect, p, (file_ptr)0,
00334                                           bfd_section_size(abfd, sect)))
00335               fatal("could not read entire `%s' section from executable",
00336                     bfd_section_name(abfd, sect));
00337 
00338             /* copy program section it into simulator target memory */
00339             mem_bcopy(mem_fn, Write, bfd_section_vma(abfd, sect),
00340                       p, bfd_section_size(abfd, sect));
00341 
00342             /* release the section buffer */
00343             free(p);
00344           }
00345         /* zero out the section if it is loadable but not allocated in exec */
00346         else if (zero_bss_segs
00347                  && (bfd_get_section_flags(abfd, sect) & SEC_LOAD)
00348                  && bfd_section_vma(abfd, sect)
00349                  && bfd_section_size(abfd, sect))
00350           {
00351             /* zero out the section region */
00352             mem_bzero(mem_fn,
00353                       bfd_section_vma(abfd, sect),
00354                       bfd_section_size(abfd, sect));
00355           }
00356         else
00357           {
00358             /* else do nothing with this section, it's probably debug data */
00359             debug("ignoring section `%s' during load...",
00360                   bfd_section_name(abfd, sect));
00361           }
00362 
00363         /* expected text section */
00364         if (!strcmp(bfd_section_name(abfd, sect), ".text"))
00365           {
00366             /* .text section processing */
00367             ld_text_size =
00368               ((bfd_section_vma(abfd, sect) + bfd_section_size(abfd, sect))
00369                - MD_TEXT_BASE)
00370                 + /* for speculative fetches/decodes */TEXT_TAIL_PADDING;
00371 
00372             /* create tail padding and copy into simulator target memory */
00373 #if 0
00374             mem_bzero(mem_fn,
00375                       bfd_section_vma(abfd, sect)
00376                       + bfd_section_size(abfd, sect),
00377                       TEXT_TAIL_PADDING);
00378 #endif
00379           }
00380         /* expected data sections */
00381         else if (!strcmp(bfd_section_name(abfd, sect), ".rdata")
00382                  || !strcmp(bfd_section_name(abfd, sect), ".data")
00383                  || !strcmp(bfd_section_name(abfd, sect), ".sdata")
00384                  || !strcmp(bfd_section_name(abfd, sect), ".bss")
00385                  || !strcmp(bfd_section_name(abfd, sect), ".sbss"))
00386           {
00387             /* data section processing */
00388             if (bfd_section_vma(abfd, sect) + bfd_section_size(abfd, sect) >
00389                 data_break)
00390               data_break = (bfd_section_vma(abfd, sect) +
00391                             bfd_section_size(abfd, sect));
00392           }
00393         else
00394           {
00395             /* what is this section??? */
00396             fatal("encountered unknown section `%s', %d bytes @ 0x%08x",
00397                   bfd_section_name(abfd, sect), bfd_section_size(abfd, sect),
00398                   bfd_section_vma(abfd, sect));
00399           }
00400       }
00401 
00402     /* compute data segment size from data break point */
00403     ld_text_base = MD_TEXT_BASE;
00404     ld_data_base = MD_DATA_BASE;
00405     ld_prog_entry = bfd_get_start_address(abfd);
00406     ld_data_size = data_break - ld_data_base;
00407 
00408     /* done with the executable, close it */
00409     if (!bfd_close(abfd))
00410       fatal("could not close executable `%s'", argv[0]);
00411   }
00412 
00413 #else /* !BFD_LOADER, i.e., standalone loader */
00414 
00415   {
00416     FILE *fobj;
00417     long floc;
00418     struct ecoff_filehdr fhdr;
00419     struct ecoff_aouthdr ahdr;
00420     struct ecoff_scnhdr shdr;
00421 
00422     /* record profile file name */
00423     ld_prog_fname = argv[0];
00424 
00425     /* load the program into memory, try both endians */
00426 #if defined(__CYGWIN32__) || defined(_MSC_VER)
00427     fobj = fopen(argv[0], "rb");
00428 #else
00429     fobj = fopen(argv[0], "r");
00430 #endif
00431     if (!fobj)
00432       fatal("cannot open executable `%s'", argv[0]);
00433 
00434     if (fread(&fhdr, sizeof(struct ecoff_filehdr), 1, fobj) < 1)
00435       fatal("cannot read header from executable `%s'", argv[0]);
00436 
00437     /* record endian of target */
00438     if (fhdr.f_magic == MD_SWAPH(ECOFF_ALPHAMAGIC))
00439       ld_target_big_endian = FALSE;
00440     else if (fhdr.f_magic == MD_SWAPH(ECOFF_EB_MAGIC)
00441              || fhdr.f_magic == MD_SWAPH(ECOFF_EL_MAGIC)
00442              || fhdr.f_magic == MD_SWAPH(ECOFF_EB_OTHER)
00443              || fhdr.f_magic == MD_SWAPH(ECOFF_EL_OTHER))
00444       fatal("Alpha simulator cannot run PISA binary `%s'", argv[0]);
00445     else
00446       fatal("bad magic number in executable `%s' (not an executable)",
00447             argv[0]);
00448 
00449     if (fread(&ahdr, sizeof(struct ecoff_aouthdr), 1, fobj) < 1)
00450       fatal("cannot read AOUT header from executable `%s'", argv[0]);
00451 
00452     ld_text_base = MD_SWAPQ(ahdr.text_start);
00453     ld_text_size = MD_SWAPQ(ahdr.tsize);
00454     ld_prog_entry = MD_SWAPQ(ahdr.entry);
00455     ld_data_base = MD_SWAPQ(ahdr.data_start);
00456     ld_data_size = MD_SWAPQ(ahdr.dsize) + MD_SWAPQ(ahdr.bsize);
00457     regs->regs_R[MD_REG_GP] = MD_SWAPQ(ahdr.gp_value);
00458 
00459     /* compute data segment size from data break point */
00460     data_break = ld_data_base + ld_data_size;
00461 
00462     /* seek to the beginning of the first section header, the file header comes
00463        first, followed by the optional header (this is the aouthdr), the size
00464        of the aouthdr is given in Fdhr.f_opthdr */
00465     fseek(fobj, sizeof(struct ecoff_filehdr) + MD_SWAPH(fhdr.f_opthdr), 0);
00466 
00467     debug("processing %d sections in `%s'...",
00468           MD_SWAPH(fhdr.f_nscns), argv[0]);
00469 
00470     /* loop through the section headers */
00471     floc = ftell(fobj);
00472     for (i = 0; i < MD_SWAPH(fhdr.f_nscns); i++)
00473       {
00474         char *p;
00475 
00476         if (fseek(fobj, floc, 0) == -1)
00477           fatal("could not reset location in executable");
00478         if (fread(&shdr, sizeof(struct ecoff_scnhdr), 1, fobj) < 1)
00479           fatal("could not read section %d from executable", i);
00480         floc = ftell(fobj);
00481 
00482         switch (MD_SWAPW(shdr.s_flags))
00483           {
00484           case ECOFF_STYP_TEXT:
00485             p = calloc(MD_SWAPQ(shdr.s_size), sizeof(char));
00486             if (!p)
00487               fatal("out of virtual memory");
00488 
00489             if (fseek(fobj, MD_SWAPQ(shdr.s_scnptr), 0) == -1)
00490               fatal("could not read `.text' from executable", i);
00491             if (fread(p, MD_SWAPQ(shdr.s_size), 1, fobj) < 1)
00492               fatal("could not read text section from executable");
00493 
00494             /* copy program section into simulator target memory */
00495             mem_bcopy(mem_access, mem, Write,
00496                       MD_SWAPQ(shdr.s_vaddr), p, MD_SWAPQ(shdr.s_size));
00497 
00498 #if 0
00499             /* create tail padding and copy into simulator target memory */
00500             mem_bzero(mem_access, mem,
00501                       MD_SWAPQ(shdr.s_vaddr) + MD_SWAPQ(shdr.s_size),
00502                       TEXT_TAIL_PADDING);
00503 #endif
00504 
00505             /* release the section buffer */
00506             free(p);
00507 
00508 #if 0
00509             Text_seek = MD_SWAPQ(shdr.s_scnptr);
00510             Text_start = MD_SWAPQ(shdr.s_vaddr);
00511             Text_size = MD_SWAPQ(shdr.s_size) / 4;
00512             /* there is a null routine after the supposed end of text */
00513             Text_size += 10;
00514             Text_end = Text_start + Text_size * 4;
00515             /* create_text_reloc(shdr.s_relptr, shdr.s_nreloc); */
00516 #endif
00517             break;
00518 
00519           case ECOFF_STYP_INIT:
00520           case ECOFF_STYP_FINI:
00521             if (MD_SWAPQ(shdr.s_size) > 0)
00522               {
00523                 p = calloc(MD_SWAPQ(shdr.s_size), sizeof(char));
00524                 if (!p)
00525                   fatal("out of virtual memory");
00526                 
00527                 if (fseek(fobj, MD_SWAPQ(shdr.s_scnptr), 0) == -1)
00528                   fatal("could not read `.text' from executable", i);
00529                 if (fread(p, MD_SWAPQ(shdr.s_size), 1, fobj) < 1)
00530                   fatal("could not read text section from executable");
00531                 
00532                 /* copy program section into simulator target memory */
00533                 mem_bcopy(mem_access, mem,
00534                           Write, MD_SWAPQ(shdr.s_vaddr),
00535                           p, MD_SWAPQ(shdr.s_size));
00536                 
00537                 /* release the section buffer */
00538                 free(p);
00539               }
00540             else
00541               warn("section `%s' is empty...", shdr.s_name);
00542             break;
00543 
00544           case ECOFF_STYP_LITA:
00545           case ECOFF_STYP_LIT8:
00546           case ECOFF_STYP_LIT4:
00547           case ECOFF_STYP_XDATA:
00548           case ECOFF_STYP_PDATA:
00549           case ECOFF_STYP_RCONST:
00550             /* fall through */
00551 
00552           case ECOFF_STYP_RDATA:
00553             /* The .rdata section is sometimes placed before the text
00554              * section instead of being contiguous with the .data section.
00555              */
00556 #if 0
00557             Rdata_start = MD_SWAPQ(shdr.s_vaddr);
00558             Rdata_size = MD_SWAPQ(shdr.s_size);
00559             Rdata_seek = MD_SWAPQ(shdr.s_scnptr);
00560 #endif
00561             /* fall through */
00562           case ECOFF_STYP_DATA:
00563 #if 0
00564             Data_seek = MD_SWAPQ(shdr.s_scnptr);
00565 #endif
00566             /* fall through */
00567           case ECOFF_STYP_SDATA:
00568 #if 0
00569             Sdata_seek = MD_SWAPQ(shdr.s_scnptr);
00570 #endif
00571             if (MD_SWAPQ(shdr.s_size) > 0)
00572               {
00573                 p = calloc(MD_SWAPQ(shdr.s_size), sizeof(char));
00574                 if (!p)
00575                   fatal("out of virtual memory");
00576 
00577                 if (fseek(fobj, MD_SWAPQ(shdr.s_scnptr), 0) == -1)
00578                   fatal("could not read `.text' from executable", i);
00579                 if (fread(p, MD_SWAPQ(shdr.s_size), 1, fobj) < 1)
00580                   fatal("could not read text section from executable");
00581 
00582                 /* copy program section it into simulator target memory */
00583                 mem_bcopy(mem_access, mem,
00584                           Write, MD_SWAPQ(shdr.s_vaddr),
00585                           p, MD_SWAPQ(shdr.s_size));
00586 
00587                 /* release the section buffer */
00588                 free(p);
00589               }
00590             else
00591               warn("section `%s' is empty...", shdr.s_name);
00592           break;
00593 
00594           case ECOFF_STYP_BSS:
00595           case ECOFF_STYP_SBSS:
00596             /* no data to read... */
00597             break;
00598 
00599           default:
00600             warn("section `%s' ignored...", shdr.s_name);
00601           }
00602       }
00603 
00604     /* done with the executable, close it */
00605     if (fclose(fobj))
00606       fatal("could not close executable `%s'", argv[0]);
00607   }
00608 
00609 #endif /* BFD_LOADER */
00610 
00611   /* perform sanity checks on segment ranges */
00612   if (!ld_text_base || !ld_text_size)
00613     fatal("executable is missing a `.text' section");
00614   if (!ld_data_base || !ld_data_size)
00615     fatal("executable is missing a `.data' section");
00616   if (!ld_prog_entry)
00617     fatal("program entry point not specified");
00618 
00619   /* determine byte/words swapping required to execute on this host */
00620   sim_swap_bytes = (endian_host_byte_order() != endian_target_byte_order());
00621   if (sim_swap_bytes)
00622     {
00623 #if 0 /* FIXME: disabled until further notice... */
00624       /* cross-endian is never reliable, why this is so is beyond the scope
00625          of this comment, e-mail me for details... */
00626       fprintf(stderr, "sim: *WARNING*: swapping bytes to match host...\n");
00627       fprintf(stderr, "sim: *WARNING*: swapping may break your program!\n");
00628       /* #else */
00629       fatal("binary endian does not match host endian");
00630 #endif
00631     }
00632   sim_swap_words = (endian_host_word_order() != endian_target_word_order());
00633   if (sim_swap_words)
00634     {
00635 #if 0 /* FIXME: disabled until further notice... */
00636       /* cross-endian is never reliable, why this is so is beyond the scope
00637          of this comment, e-mail me for details... */
00638       fprintf(stderr, "sim: *WARNING*: swapping words to match host...\n");
00639       fprintf(stderr, "sim: *WARNING*: swapping may break your program!\n");
00640       /* #else */
00641       fatal("binary endian does not match host endian");
00642 #endif
00643     }
00644 
00645   /* set up a local stack pointer, this is where the argv and envp
00646      data is written into program memory */
00647   ld_stack_base = ld_text_base - (409600+4096);
00648 #if 0
00649   sp = ROUND_DOWN(ld_stack_base - MD_MAX_ENVIRON, sizeof(MD_DOUBLE_TYPE));
00650 #endif
00651   sp = ld_stack_base - MD_MAX_ENVIRON;
00652   ld_stack_size = ld_stack_base - sp;
00653 
00654   /* initial stack pointer value */
00655   ld_environ_base = sp;
00656 
00657   /* write [argc] to stack */
00658   temp = MD_SWAPQ(argc);
00659   mem_access(mem, Write, sp, &temp, sizeof(qword_t));
00660   regs->regs_R[MD_REG_A0] = temp;
00661   sp += sizeof(qword_t);
00662 
00663   /* skip past argv array and NULL */
00664   argv_addr = sp;
00665   regs->regs_R[MD_REG_A1] = argv_addr;
00666   sp = sp + (argc + 1) * sizeof(md_addr_t);
00667 
00668   /* save space for envp array and NULL */
00669   envp_addr = sp;
00670   for (i=0; envp[i]; i++)
00671     sp += sizeof(md_addr_t);
00672   sp += sizeof(md_addr_t);
00673 
00674   /* fill in the argv pointer array and data */
00675   for (i=0; i<argc; i++)
00676     {
00677       /* write the argv pointer array entry */
00678       temp = MD_SWAPQ(sp);
00679       mem_access(mem, Write, argv_addr + i*sizeof(md_addr_t),
00680                  &temp, sizeof(md_addr_t));
00681       /* and the data */
00682       mem_strcpy(mem_access, mem, Write, sp, argv[i]);
00683       sp += strlen(argv[i])+1;
00684     }
00685   /* terminate argv array with a NULL */
00686   mem_access(mem, Write, argv_addr + i*sizeof(md_addr_t),
00687              &null_ptr, sizeof(md_addr_t));
00688 
00689   /* write envp pointer array and data to stack */
00690   for (i = 0; envp[i]; i++)
00691     {
00692       /* write the envp pointer array entry */
00693       temp = MD_SWAPQ(sp);
00694       mem_access(mem, Write, envp_addr + i*sizeof(md_addr_t),
00695                  &temp, sizeof(md_addr_t));
00696       /* and the data */
00697       mem_strcpy(mem_access, mem, Write, sp, envp[i]);
00698       sp += strlen(envp[i]) + 1;
00699     }
00700   /* terminate the envp array with a NULL */
00701   mem_access(mem, Write, envp_addr + i*sizeof(md_addr_t),
00702              &null_ptr, sizeof(md_addr_t));
00703 
00704   /* did we tromp off the stop of the stack? */
00705   if (sp > ld_stack_base)
00706     {
00707       /* we did, indicate to the user that MD_MAX_ENVIRON must be increased,
00708          alternatively, you can use a smaller environment, or fewer
00709          command line arguments */
00710       fatal("environment overflow, increase MD_MAX_ENVIRON in alpha.h");
00711     }
00712 
00713   /* initialize the bottom of heap to top of data segment */
00714   ld_brk_point = ROUND_UP(ld_data_base + ld_data_size, MD_PAGE_SIZE);
00715 
00716   /* set initial minimum stack pointer value to initial stack value */
00717   ld_stack_min = regs->regs_R[MD_REG_SP];
00718 
00719   regs->regs_R[MD_REG_SP] = ld_environ_base;
00720   regs->regs_PC = ld_prog_entry;
00721 
00722   debug("ld_text_base: 0x%08x  ld_text_size: 0x%08x",
00723         ld_text_base, ld_text_size);
00724   debug("ld_data_base: 0x%08x  ld_data_size: 0x%08x",
00725         ld_data_base, ld_data_size);
00726   debug("ld_stack_base: 0x%08x  ld_stack_size: 0x%08x",
00727         ld_stack_base, ld_stack_size);
00728   debug("ld_prog_entry: 0x%08x", ld_prog_entry);
00729 }

void ld_reg_stats struct stat_sdb_t   sdb
 

Definition at line 152 of file loader.c.

References ld_data_base, ld_data_size, ld_environ_base, ld_prog_entry, ld_stack_base, ld_stack_min, ld_stack_size, ld_target_big_endian, ld_text_base, ld_text_size, stat_reg_addr, stat_reg_int(), and stat_reg_uint().

00153 {
00154   stat_reg_addr(sdb, "ld_text_base",
00155                 "program text (code) segment base",
00156                 &ld_text_base, ld_text_base, "0x%010p");
00157   stat_reg_uint(sdb, "ld_text_size",
00158                 "program text (code) size in bytes",
00159                 &ld_text_size, ld_text_size, NULL);
00160   stat_reg_addr(sdb, "ld_data_base",
00161                 "program initialized data segment base",
00162                 &ld_data_base, ld_data_base, "0x%010p");
00163   stat_reg_uint(sdb, "ld_data_size",
00164                 "program init'ed `.data' and uninit'ed `.bss' size in bytes",
00165                 &ld_data_size, ld_data_size, NULL);
00166   stat_reg_addr(sdb, "ld_stack_base",
00167                 "program stack segment base (highest address in stack)",
00168                 &ld_stack_base, ld_stack_base, "0x%010p");
00169 #if 0 /* FIXME: broken... */
00170   stat_reg_addr(sdb, "ld_stack_min",
00171                 "program stack segment lowest address",
00172                 &ld_stack_min, ld_stack_min, "0x%010p");
00173 #endif
00174   stat_reg_uint(sdb, "ld_stack_size",
00175                 "program initial stack size",
00176                 &ld_stack_size, ld_stack_size, NULL);
00177   stat_reg_addr(sdb, "ld_prog_entry",
00178                 "program entry point (initial PC)",
00179                 &ld_prog_entry, ld_prog_entry, "0x%010p");
00180   stat_reg_addr(sdb, "ld_environ_base",
00181                 "program environment base address address",
00182                 &ld_environ_base, ld_environ_base, "0x%010p");
00183   stat_reg_int(sdb, "ld_target_big_endian",
00184                "target executable endian-ness, non-zero if big endian",
00185                &ld_target_big_endian, ld_target_big_endian, NULL);
00186 }


Variable Documentation

md_addr_t ld_brk_point = 0
 

Definition at line 124 of file loader.c.

Referenced by ld_load_prog().

md_addr_t ld_data_base = 0
 

Definition at line 121 of file loader.c.

Referenced by ld_load_prog(), and ld_reg_stats().

unsigned int ld_data_size = 0
 

Definition at line 127 of file loader.c.

Referenced by ld_load_prog(), and ld_reg_stats().

md_addr_t ld_environ_base = 0
 

Definition at line 145 of file loader.c.

Referenced by ld_load_prog(), and ld_reg_stats().

md_addr_t ld_prog_entry = 0
 

Definition at line 142 of file loader.c.

Referenced by ld_load_prog(), and ld_reg_stats().

char* ld_prog_fname = NULL
 

Definition at line 139 of file loader.c.

Referenced by ld_load_prog().

md_addr_t ld_stack_base = 0
 

Definition at line 130 of file loader.c.

Referenced by ld_load_prog(), and ld_reg_stats().

md_addr_t ld_stack_min = -1
 

Definition at line 136 of file loader.c.

Referenced by ld_load_prog(), and ld_reg_stats().

unsigned int ld_stack_size = 0
 

Definition at line 133 of file loader.c.

Referenced by ld_load_prog(), and ld_reg_stats().

int ld_target_big_endian
 

Definition at line 148 of file loader.c.

Referenced by ld_load_prog(), and ld_reg_stats().

md_addr_t ld_text_base = 0
 

Definition at line 115 of file loader.c.

Referenced by ld_load_prog(), and ld_reg_stats().

unsigned int ld_text_size = 0
 

Definition at line 118 of file loader.c.

Referenced by ld_load_prog(), and ld_reg_stats().



UVa CS Department of Computer Science
School of Engineering, University of Virginia
151 Engineer's Way, P.O. Box 400740
Charlottesville, Virginia 22904-4740

(434) 982-2200  Fax: (434) 982-2214