1 |
786 |
skrzyp |
// ####ECOSHOSTGPLCOPYRIGHTBEGIN####
|
2 |
|
|
// -------------------------------------------
|
3 |
|
|
// This file is part of the eCos host tools.
|
4 |
|
|
// Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
|
5 |
|
|
//
|
6 |
|
|
// This program is free software; you can redistribute it and/or modify
|
7 |
|
|
// it under the terms of the GNU General Public License as published by
|
8 |
|
|
// the Free Software Foundation; either version 2 or (at your option) any
|
9 |
|
|
// later version.
|
10 |
|
|
//
|
11 |
|
|
// This program is distributed in the hope that it will be useful, but
|
12 |
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 |
|
|
// General Public License for more details.
|
15 |
|
|
//
|
16 |
|
|
// You should have received a copy of the GNU General Public License
|
17 |
|
|
// along with this program; if not, write to the
|
18 |
|
|
// Free Software Foundation, Inc., 51 Franklin Street,
|
19 |
|
|
// Fifth Floor, Boston, MA 02110-1301, USA.
|
20 |
|
|
// -------------------------------------------
|
21 |
|
|
// ####ECOSHOSTGPLCOPYRIGHTEND####
|
22 |
|
|
//=================================================================
|
23 |
|
|
//
|
24 |
|
|
// memmap.h
|
25 |
|
|
//
|
26 |
|
|
// Memory Layout Tool map data structure manipulation interface
|
27 |
|
|
//
|
28 |
|
|
//=================================================================
|
29 |
|
|
//=================================================================
|
30 |
|
|
//#####DESCRIPTIONBEGIN####
|
31 |
|
|
//
|
32 |
|
|
// Author(s): John Dallaway
|
33 |
|
|
// Contact(s): jld
|
34 |
|
|
// Date: 1998/07/29 $RcsDate$ {or whatever}
|
35 |
|
|
// Version: 0.00+ $RcsVersion$ {or whatever}
|
36 |
|
|
// Purpose: Provides an interface to create and destroy memory
|
37 |
|
|
// regions and sections within the memory map. Exposes
|
38 |
|
|
// data structures for the presentation of this data
|
39 |
|
|
// by external code.
|
40 |
|
|
// See also: memmap.cpp
|
41 |
|
|
// Known bugs: <UPDATE_ME_AT_RELEASE_TIME>
|
42 |
|
|
// WARNING: Do not modify data structures other than by using the
|
43 |
|
|
// provided functions
|
44 |
|
|
// Usage: #include "memmap.h"
|
45 |
|
|
// ...
|
46 |
|
|
// status = set_map_size (0x8000);
|
47 |
|
|
//
|
48 |
|
|
//####DESCRIPTIONEND####
|
49 |
|
|
|
50 |
|
|
#if !defined(AFX_MEMMAP_H__75497C90_17F4_11D2_BFBB_00A0C9554250__INCLUDED_)
|
51 |
|
|
#define AFX_MEMMAP_H__75497C90_17F4_11D2_BFBB_00A0C9554250__INCLUDED_
|
52 |
|
|
|
53 |
|
|
/*
|
54 |
|
|
|
55 |
|
|
#if _MSC_VER >= 1000
|
56 |
|
|
#pragma once
|
57 |
|
|
#endif // _MSC_VER >= 1000
|
58 |
|
|
|
59 |
|
|
#ifdef _AFXDLL
|
60 |
|
|
#include "stdafx.h"
|
61 |
|
|
#define INCLUDEFILE <list>
|
62 |
|
|
#include "IncludeSTL.h"
|
63 |
|
|
#define INCLUDEFILE <map>
|
64 |
|
|
#include "IncludeSTL.h"
|
65 |
|
|
#define INCLUDEFILE <string>
|
66 |
|
|
#include "IncludeSTL.h"
|
67 |
|
|
#define INCLUDEFILE <algorithm>
|
68 |
|
|
#include "IncludeSTL.h"
|
69 |
|
|
#else
|
70 |
|
|
#include <list>
|
71 |
|
|
#include <map>
|
72 |
|
|
#include <string>
|
73 |
|
|
#include <algorithm>
|
74 |
|
|
#endif
|
75 |
|
|
|
76 |
|
|
*/
|
77 |
|
|
|
78 |
|
|
#include <time.h>
|
79 |
|
|
|
80 |
|
|
#define ERR_MEMMAP_REGION_NONAME 1
|
81 |
|
|
#define ERR_MEMMAP_REGION_MAPSIZE 2
|
82 |
|
|
#define ERR_MEMMAP_REGION_INTERSECT 3 /* region name returned in error_info */
|
83 |
|
|
#define ERR_MEMMAP_REGION_NAMEINUSE 4
|
84 |
|
|
#define ERR_MEMMAP_REGION_NOTFOUND 5
|
85 |
|
|
#define ERR_MEMMAP_REGION_SIZE 6
|
86 |
|
|
#define ERR_MEMMAP_ALLOC 7
|
87 |
|
|
#define ERR_MEMMAP_SECTION_NONAME 8
|
88 |
|
|
#define ERR_MEMMAP_SECTION_NAMEINUSE 9
|
89 |
|
|
#define ERR_MEMMAP_SECTION_LMA_NOTINREGION 10
|
90 |
|
|
#define ERR_MEMMAP_SECTION_VMA_NOTINREGION 11
|
91 |
|
|
#define ERR_MEMMAP_SECTION_LMA_ANCHORNOTFOUND 12
|
92 |
|
|
#define ERR_MEMMAP_SECTION_LMA_ANCHORNOTAVAIL 13
|
93 |
|
|
#define ERR_MEMMAP_SECTION_VMA_ANCHORNOTFOUND 14
|
94 |
|
|
#define ERR_MEMMAP_SECTION_VMA_ANCHORNOTAVAIL 15
|
95 |
|
|
#define ERR_MEMMAP_SECTION_NOTFOUND 17
|
96 |
|
|
#define ERR_MEMMAP_SECTION_VMA_READONLY 18
|
97 |
|
|
#define ERR_MEMMAP_SECTION_LMA_READWRITE 19
|
98 |
|
|
#define ERR_MEMMAP_SECTION_ILLEGAL_RELOCATION 20
|
99 |
|
|
|
100 |
|
|
#define LD_ILLEGAL_CHARS _T(" ,.")
|
101 |
|
|
#define MLT_FILE_VERSION 0
|
102 |
|
|
#define MLT_GENERATED_WARNING "// This is a generated file - do not edit"
|
103 |
|
|
|
104 |
|
|
typedef unsigned long mem_address; // FIXME: is a 32-bit memory address sufficient?
|
105 |
|
|
typedef struct tag_mem_location mem_location; // forward declaration for struct tag_mem_location
|
106 |
|
|
|
107 |
|
|
// the location of each section is specified either relative to another
|
108 |
|
|
// section or using an absolute memory address, either the start or end
|
109 |
|
|
// address may be specified
|
110 |
|
|
|
111 |
|
|
typedef enum mem_anchor {relative, absolute};
|
112 |
|
|
|
113 |
|
|
// each section view item may represent either the initial location of
|
114 |
|
|
// the section, the final location, or both locations if the section does
|
115 |
|
|
// not relocate
|
116 |
|
|
|
117 |
|
|
typedef enum section_location_type {initial_location, final_location, fixed_location};
|
118 |
|
|
|
119 |
|
|
// a memory region may be either ROM (read-only) or RAM (read-write).
|
120 |
|
|
|
121 |
|
|
typedef enum mem_type {read_only, read_write};
|
122 |
|
|
|
123 |
|
|
// the memory section structure describes the initial and final locations
|
124 |
|
|
// of a section, its size and relocation information
|
125 |
|
|
|
126 |
|
|
class mem_section
|
127 |
|
|
{
|
128 |
|
|
public:
|
129 |
|
|
std::string name; // the name of the section
|
130 |
|
|
bool relocates; // if the memory section relocates
|
131 |
|
|
bool linker_defined; // if the memory section is linker-defined
|
132 |
|
|
mem_address alignment; // the section alignment
|
133 |
|
|
mem_address size; // memory section size (zero if unknown)
|
134 |
|
|
mem_location * final_location; // the final memory section location (always defined)
|
135 |
|
|
mem_location * initial_location; // the initial memory section location (always defined)
|
136 |
|
|
std::string note; // comment lines
|
137 |
|
|
mem_section ();
|
138 |
|
|
~mem_section ();
|
139 |
|
|
};
|
140 |
|
|
|
141 |
|
|
// the memory location structure describes the way in which the section is
|
142 |
|
|
// anchored, the absolute address of the anchor (if any) and the names of
|
143 |
|
|
// the preceding and following relative sections (if any)
|
144 |
|
|
|
145 |
|
|
typedef struct tag_mem_location
|
146 |
|
|
{
|
147 |
|
|
mem_anchor anchor; // type of anchor
|
148 |
|
|
mem_address address; // the absolute anchor address (if any)
|
149 |
|
|
std::list <mem_section>::iterator following_section; // the section declared as following this one
|
150 |
|
|
} mem_location;
|
151 |
|
|
|
152 |
|
|
// the section view structure consists of the section name (which is used
|
153 |
|
|
// as a key to look up section information in the section map) and an enum
|
154 |
|
|
// describing the state of the section which it represents
|
155 |
|
|
|
156 |
|
|
typedef struct tag_mem_section_view
|
157 |
|
|
{
|
158 |
|
|
std::list <mem_section>::iterator section; // unused section if NULL
|
159 |
|
|
section_location_type section_location;
|
160 |
|
|
} mem_section_view;
|
161 |
|
|
|
162 |
|
|
// the memory region structure describes the region name, size, address,
|
163 |
|
|
// RAM/ROM status and a list of section views which reside in the region
|
164 |
|
|
|
165 |
|
|
typedef struct tag_mem_region
|
166 |
|
|
{
|
167 |
|
|
std::string name; // the name of the region
|
168 |
|
|
mem_address size; // the size of the memory region in bytes
|
169 |
|
|
mem_address address; // the absolute location of the memory region
|
170 |
|
|
mem_type type; // ROM or RAM
|
171 |
|
|
std::list <mem_section_view> section_view_list;
|
172 |
|
|
std::string note; // comment lines
|
173 |
|
|
} mem_region;
|
174 |
|
|
|
175 |
|
|
|
176 |
|
|
class mem_map
|
177 |
|
|
{
|
178 |
|
|
public:
|
179 |
|
|
bool delete_memory_section (std::string name);
|
180 |
|
|
int edit_memory_section (std::string old_name,
|
181 |
|
|
std::string new_name,
|
182 |
|
|
mem_address section_size,
|
183 |
|
|
mem_address section_alignment,
|
184 |
|
|
mem_anchor initial_section_anchor,
|
185 |
|
|
std::string initial_anchor_section_name,
|
186 |
|
|
mem_address initial_anchor_address,
|
187 |
|
|
mem_anchor final_section_anchor,
|
188 |
|
|
std::string final_anchor_section_name,
|
189 |
|
|
mem_address final_anchor_address,
|
190 |
|
|
bool relocates,
|
191 |
|
|
bool anchor_to_initial_location,
|
192 |
|
|
bool linker_defined,
|
193 |
|
|
std::string note);
|
194 |
|
|
int create_memory_section (std::string section_name,
|
195 |
|
|
mem_address section_size,
|
196 |
|
|
mem_address section_alignment,
|
197 |
|
|
mem_anchor initial_section_anchor,
|
198 |
|
|
std::string initial_anchor_section_name,
|
199 |
|
|
mem_address initial_anchor_address,
|
200 |
|
|
mem_anchor final_section_anchor,
|
201 |
|
|
std::string final_anchor_section_name,
|
202 |
|
|
mem_address final_anchor_address,
|
203 |
|
|
bool relocates,
|
204 |
|
|
bool anchor_to_initial_location,
|
205 |
|
|
bool linker_defined,
|
206 |
|
|
std::string note);
|
207 |
|
|
bool set_map_size (mem_address size);
|
208 |
|
|
bool delete_memory_region (std::string name);
|
209 |
|
|
bool get_memory_region (std::string region_name,
|
210 |
|
|
mem_address * region_address,
|
211 |
|
|
mem_address * region_size,
|
212 |
|
|
mem_type * region_type,
|
213 |
|
|
std::string * note);
|
214 |
|
|
int create_memory_region (std::string name, mem_address location,
|
215 |
|
|
mem_address size, mem_type type, std::string note);
|
216 |
|
|
int edit_memory_region (std::string old_name, std::string new_name, mem_address new_location,
|
217 |
|
|
mem_address new_size, mem_type new_type, std::string note);
|
218 |
|
|
bool delete_all_memory_sections ();
|
219 |
|
|
bool export_files (const wxChar* script_name, const wxChar* header_name);
|
220 |
|
|
bool import_linker_defined_sections (const wxChar* filename);
|
221 |
|
|
bool save_memory_layout (const wxChar* filename);
|
222 |
|
|
bool load_memory_layout (const wxChar* filename);
|
223 |
|
|
bool new_memory_layout ();
|
224 |
|
|
bool map_modified () { return map_modified_flag; };
|
225 |
|
|
bool section_exists (std::string section_name);
|
226 |
|
|
std::list <mem_section>::iterator find_memory_section (std::string section_name);
|
227 |
|
|
std::list <mem_section>::iterator find_preceding_section (std::list <mem_section>::iterator section, bool initial_location);
|
228 |
|
|
std::string error_info;
|
229 |
|
|
std::list <mem_region> region_list; // ordered list of memory regions
|
230 |
|
|
std::list <mem_section> section_list; // list of memory sections
|
231 |
|
|
std::list <std::string> linker_defined_section_list; // list of linker-defined sections
|
232 |
|
|
|
233 |
|
|
mem_map();
|
234 |
|
|
virtual ~mem_map();
|
235 |
|
|
|
236 |
|
|
private:
|
237 |
|
|
std::list <mem_region>::iterator find_memory_region (std::string);
|
238 |
|
|
std::list <mem_region>::iterator find_region_by_address (mem_address);
|
239 |
|
|
std::list <mem_region>::iterator find_region_by_section (std::list <mem_section>::iterator section, section_location_type location_type);
|
240 |
|
|
mem_address map_size; // total size of memory map
|
241 |
|
|
bool add_absolute_section_to_list (std::list <mem_region>::iterator region,
|
242 |
|
|
std::list <mem_section>::iterator additional_section,
|
243 |
|
|
section_location_type location_type);
|
244 |
|
|
bool add_relative_sections_to_list (std::list <mem_region>::iterator region,
|
245 |
|
|
std::list <mem_section_view>::iterator section_view,
|
246 |
|
|
section_location_type location_type);
|
247 |
|
|
bool calc_section_list (std::list <mem_region>::iterator region);
|
248 |
|
|
bool calc_section_lists ();
|
249 |
|
|
bool at_start_of_region (std::list <mem_section>::iterator section,
|
250 |
|
|
std::list <mem_region>::iterator region);
|
251 |
|
|
bool at_end_of_region (std::list <mem_section>::iterator section,
|
252 |
|
|
std::list <mem_region>::iterator region);
|
253 |
|
|
bool absolute_sections_meet (std::list <mem_section>::iterator section1,
|
254 |
|
|
std::list <mem_section>::iterator section2);
|
255 |
|
|
bool load_memory_section_1 (FILE * stream);
|
256 |
|
|
bool load_memory_section_2 (FILE * stream);
|
257 |
|
|
bool export_sections (FILE *, FILE *, mem_type);
|
258 |
|
|
bool map_modified_flag;
|
259 |
|
|
std::string encode_note (std::string);
|
260 |
|
|
std::string decode_note (std::string);
|
261 |
|
|
std::string encode_section_name (std::string);
|
262 |
|
|
std::string decode_section_name (std::string);
|
263 |
|
|
};
|
264 |
|
|
|
265 |
|
|
#endif // !defined(AFX_MEMMAP_H__75497C90_17F4_11D2_BFBB_00A0C9554250__INCLUDED_)
|