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