00001 /* 00002 * loader.h - program loader interfaces 00003 * 00004 * This file is a part of the SimpleScalar tool suite written by 00005 * Todd M. Austin as a part of the Multiscalar Research Project. 00006 * 00007 * The tool suite is currently maintained by Doug Burger and Todd M. Austin. 00008 * 00009 * Copyright (C) 1994, 1995, 1996, 1997, 1998 by Todd M. Austin 00010 * 00011 * This source file is distributed "as is" in the hope that it will be 00012 * useful. The tool set comes with no warranty, and no author or 00013 * distributor accepts any responsibility for the consequences of its 00014 * use. 00015 * 00016 * Everyone is granted permission to copy, modify and redistribute 00017 * this tool set under the following conditions: 00018 * 00019 * This source code is distributed for non-commercial use only. 00020 * Please contact the maintainer for restrictions applying to 00021 * commercial use. 00022 * 00023 * Permission is granted to anyone to make or distribute copies 00024 * of this source code, either as received or modified, in any 00025 * medium, provided that all copyright notices, permission and 00026 * nonwarranty notices are preserved, and that the distributor 00027 * grants the recipient permission for further redistribution as 00028 * permitted by this document. 00029 * 00030 * Permission is granted to distribute this file in compiled 00031 * or executable form under the same conditions that apply for 00032 * source code, provided that either: 00033 * 00034 * A. it is accompanied by the corresponding machine-readable 00035 * source code, 00036 * B. it is accompanied by a written offer, with no time limit, 00037 * to give anyone a machine-readable copy of the corresponding 00038 * source code in return for reimbursement of the cost of 00039 * distribution. This written offer must permit verbatim 00040 * duplication by anyone, or 00041 * C. it is distributed by someone who received only the 00042 * executable form, and is accompanied by a copy of the 00043 * written offer of source code that they received concurrently. 00044 * 00045 * In other words, you are welcome to use, share and improve this 00046 * source file. You are forbidden to forbid anyone else to use, share 00047 * and improve what you give them. 00048 * 00049 * INTERNET: dburger@cs.wisc.edu 00050 * US Mail: 1210 W. Dayton Street, Madison, WI 53706 00051 * 00052 * $Id: loader.h,v 1.1.1.1 2003/09/18 00:57:54 panalyzer Exp $ 00053 * 00054 * $Log: loader.h,v $ 00055 * Revision 1.1.1.1 2003/09/18 00:57:54 panalyzer 00056 * 00057 * 00058 * Revision 1.1.1.1 2003/09/18 00:18:43 panalyzer 00059 * 00060 * 00061 * Revision 1.1.1.1 2003/09/16 18:48:14 gdm 00062 * 00063 * 00064 * Revision 1.1.1.1 2000/11/29 14:53:54 cu-cs 00065 * Grand unification of arm sources. 00066 * 00067 * 00068 * Revision 1.1.1.1.2.1 2000/07/28 21:37:08 taustin 00069 * Added ld_text_bound and ld_data_bound to loader exports. 00070 * 00071 * Revision 1.1.1.1 2000/05/26 15:18:58 taustin 00072 * SimpleScalar Tool Set 00073 * 00074 * 00075 * Revision 1.6 1998/08/27 16:44:14 taustin 00076 * implemented host interface description in host.h 00077 * added target interface support 00078 * added support for register and memory contexts 00079 * 00080 * Revision 1.5 1997/03/11 01:13:20 taustin 00081 * updated copyright 00082 * 00083 * Revision 1.4 1997/01/06 16:00:03 taustin 00084 * ld_prog_fname variable exported 00085 * 00086 * Revision 1.3 1996/12/27 15:52:06 taustin 00087 * updated comments 00088 * 00089 * Revision 1.1 1996/12/05 18:50:23 taustin 00090 * Initial revision 00091 * 00092 * 00093 */ 00094 00095 #ifndef LOADER_H 00096 #define LOADER_H 00097 00098 #include <stdio.h> 00099 00100 #include "host.h" 00101 #include "misc.h" 00102 #include "machine.h" 00103 #include "regs.h" 00104 #include "memory.h" 00105 00106 /* 00107 * This module implements program loading. The program text (code) and 00108 * initialized data are first read from the program executable. Next, the 00109 * program uninitialized data segment is initialized to all zero's. Finally, 00110 * the program stack is initialized with command line arguments and 00111 * environment variables. The format of the top of stack when the program 00112 * starts execution is as follows: 00113 * 00114 * 0x7fffffff +----------+ 00115 * | unused | 00116 * 0x7fffc000 +----------+ 00117 * | envp | 00118 * | strings | 00119 * +----------+ 00120 * | argv | 00121 * | strings | 00122 * +----------+ 00123 * | envp | 00124 * | array | 00125 * +----------+ 00126 * | argv | 00127 * | array | 00128 * +----------+ 00129 * | argc | 00130 * regs_R[29] +----------+ 00131 * (stack ptr) 00132 * 00133 * NOTE: the start of envp is computed in crt0.o (C startup code) using the 00134 * value of argc and the computed size of the argv array, the envp array size 00135 * is not specified, but rather it is NULL terminated, so the startup code 00136 * has to scan memory for the end of the string. 00137 */ 00138 00139 /* 00140 * program segment ranges, valid after calling ld_load_prog() 00141 */ 00142 00143 /* program text (code) segment base */ 00144 extern md_addr_t ld_text_base; 00145 extern md_addr_t ld_text_bound; 00146 00147 /* program text (code) size in bytes */ 00148 extern unsigned int ld_text_size; 00149 00150 /* program initialized data segment base */ 00151 extern md_addr_t ld_data_base; 00152 extern md_addr_t ld_data_bound; 00153 00154 /* program initialized ".data" and uninitialized ".bss" size in bytes */ 00155 extern unsigned int ld_data_size; 00156 00157 /* top of the data segment */ 00158 extern md_addr_t ld_brk_point; 00159 00160 /* program stack segment base (highest address in stack) */ 00161 extern md_addr_t ld_stack_base; 00162 00163 /* program initial stack size */ 00164 extern unsigned int ld_stack_size; 00165 00166 /* lowest address accessed on the stack */ 00167 extern md_addr_t ld_stack_min; 00168 00169 /* program file name */ 00170 extern char *ld_prog_fname; 00171 00172 /* program entry point (initial PC) */ 00173 extern md_addr_t ld_prog_entry; 00174 00175 /* program environment base address address */ 00176 extern md_addr_t ld_environ_base; 00177 00178 /* target executable endian-ness, non-zero if big endian */ 00179 extern int ld_target_big_endian; 00180 00181 /* register simulator-specific statistics */ 00182 void 00183 ld_reg_stats(struct stat_sdb_t *sdb); /* stats data base */ 00184 00185 /* load program text and initialized data into simulated virtual memory 00186 space and initialize program segment range variables */ 00187 void 00188 ld_load_prog(char *fname, /* program to load */ 00189 int argc, char **argv, /* simulated program cmd line args */ 00190 char **envp, /* simulated program environment */ 00191 struct regs_t *regs, /* registers to initialize for load */ 00192 struct mem_t *mem, /* memory space to load prog into */ 00193 int zero_bss_segs); /* zero uninit data segment? */ 00194 00195 #endif /* LOADER_H */