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 |
|
|
// SectionGeneralPage.cpp
|
25 |
|
|
//
|
26 |
|
|
// Memory Layout Tool section general property page class
|
27 |
|
|
//
|
28 |
|
|
//=================================================================
|
29 |
|
|
//#####DESCRIPTIONBEGIN####
|
30 |
|
|
//
|
31 |
|
|
// Author(s): John Dallaway
|
32 |
|
|
// Contact(s): jld
|
33 |
|
|
// Date: 1998/07/29 $RcsDate$ {or whatever}
|
34 |
|
|
// Version: 0.00+ $RcsVersion$ {or whatever}
|
35 |
|
|
// Purpose: Provides a derivation of the MFC CeCosPropertyPage class for
|
36 |
|
|
// general section property selection
|
37 |
|
|
// See also: SectionGeneralPage.h
|
38 |
|
|
// Known bugs: <UPDATE_ME_AT_RELEASE_TIME>
|
39 |
|
|
//
|
40 |
|
|
//####DESCRIPTIONEND####
|
41 |
|
|
|
42 |
|
|
#include "stdafx.h"
|
43 |
|
|
#include "ConfigtoolDoc.h"
|
44 |
|
|
#include "SectionGeneralPage.h"
|
45 |
|
|
#include "ConfigTool.h"
|
46 |
|
|
#include "CTUtils.h"
|
47 |
|
|
|
48 |
|
|
|
49 |
|
|
#include "memmap.h"
|
50 |
|
|
|
51 |
|
|
#ifdef _DEBUG
|
52 |
|
|
#define new DEBUG_NEW
|
53 |
|
|
#undef THIS_FILE
|
54 |
|
|
static char THIS_FILE[] = __FILE__;
|
55 |
|
|
#endif
|
56 |
|
|
|
57 |
|
|
/////////////////////////////////////////////////////////////////////////////
|
58 |
|
|
// CSectionGeneralPage property page
|
59 |
|
|
|
60 |
|
|
IMPLEMENT_DYNCREATE(CSectionGeneralPage, CeCosPropertyPage)
|
61 |
|
|
|
62 |
|
|
CSectionGeneralPage::CSectionGeneralPage() : CeCosPropertyPage(CSectionGeneralPage::IDD)
|
63 |
|
|
{
|
64 |
|
|
//{{AFX_DATA_INIT(CSectionGeneralPage)
|
65 |
|
|
m_strFinalRelativeName = _T("");
|
66 |
|
|
m_strNameUser = _T("");
|
67 |
|
|
m_strNameLinker = _T("");
|
68 |
|
|
m_nAlignment = 0;
|
69 |
|
|
m_strFinalAddress = _T("");
|
70 |
|
|
m_strSectionSize = _T("");
|
71 |
|
|
//}}AFX_DATA_INIT
|
72 |
|
|
m_bFinalAbsolute = TRUE;
|
73 |
|
|
}
|
74 |
|
|
|
75 |
|
|
CSectionGeneralPage::~CSectionGeneralPage()
|
76 |
|
|
{
|
77 |
|
|
}
|
78 |
|
|
|
79 |
|
|
void CSectionGeneralPage::DoDataExchange(CDataExchange* pDX)
|
80 |
|
|
{
|
81 |
|
|
CeCosPropertyPage::DoDataExchange(pDX);
|
82 |
|
|
//{{AFX_DATA_MAP(CSectionGeneralPage)
|
83 |
|
|
DDX_Control(pDX, IDC_SECTION_GENERAL_ALIGNMENT, m_cboAlignment);
|
84 |
|
|
DDX_Control(pDX, IDC_SECTION_GENERAL_NAME_USER, m_edtNameUser);
|
85 |
|
|
DDX_Control(pDX, IDC_SECTION_GENERAL_NAME_LINKER, m_cboNameLinker);
|
86 |
|
|
DDX_Control(pDX, IDC_SECTION_GENERAL_FINAL_ABSOLUTE_ADDRESS, m_edtFinalAddress);
|
87 |
|
|
DDX_Control(pDX, IDC_SECTION_GENERAL_FINAL_RELATIVE_NAME, m_cboFinalRelativeName);
|
88 |
|
|
DDX_Control(pDX, IDC_SECTION_GENERAL_KNOWN_SIZE, m_btnSectionSizeKnown);
|
89 |
|
|
DDX_Control(pDX, IDC_SECTION_GENERAL_SIZE, m_edtSectionSize);
|
90 |
|
|
DDX_Control(pDX, IDC_SECTION_GENERAL_FINAL_RELATIVE, m_btnFinalRelative);
|
91 |
|
|
DDX_Control(pDX, IDC_SECTION_GENERAL_FINAL_ABSOLUTE, m_btnFinalAbsolute);
|
92 |
|
|
DDX_Control(pDX, IDC_SECTION_GENERAL_NAME_LINKER_DEFINED, m_btnNameLinkerDefined);
|
93 |
|
|
DDX_Control(pDX, IDC_SECTION_GENERAL_NAME_USER_DEFINED, m_btnNameUserDefined);
|
94 |
|
|
DDX_CBString(pDX, IDC_SECTION_GENERAL_FINAL_RELATIVE_NAME, m_strFinalRelativeName);
|
95 |
|
|
DDX_Text(pDX, IDC_SECTION_GENERAL_NAME_USER, m_strNameUser);
|
96 |
|
|
DDX_CBString(pDX, IDC_SECTION_GENERAL_NAME_LINKER, m_strNameLinker);
|
97 |
|
|
DDX_CBIndex(pDX, IDC_SECTION_GENERAL_ALIGNMENT, m_nAlignment);
|
98 |
|
|
DDX_Text(pDX, IDC_SECTION_GENERAL_FINAL_ABSOLUTE_ADDRESS, m_strFinalAddress);
|
99 |
|
|
DDX_Text(pDX, IDC_SECTION_GENERAL_SIZE, m_strSectionSize);
|
100 |
|
|
//}}AFX_DATA_MAP
|
101 |
|
|
}
|
102 |
|
|
|
103 |
|
|
|
104 |
|
|
BEGIN_MESSAGE_MAP(CSectionGeneralPage, CeCosPropertyPage)
|
105 |
|
|
//{{AFX_MSG_MAP(CSectionGeneralPage)
|
106 |
|
|
ON_BN_CLICKED(IDC_SECTION_GENERAL_KNOWN_SIZE, OnSectionSizeKnown)
|
107 |
|
|
ON_BN_CLICKED(IDC_SECTION_GENERAL_FINAL_RELATIVE, OnSectionGeneralFinalType)
|
108 |
|
|
ON_BN_CLICKED(IDC_SECTION_GENERAL_NAME_LINKER_DEFINED, OnSectionGeneralNameType)
|
109 |
|
|
ON_BN_CLICKED(IDC_SECTION_GENERAL_FINAL_ABSOLUTE, OnSectionGeneralFinalType)
|
110 |
|
|
ON_BN_CLICKED(IDC_SECTION_GENERAL_NAME_USER_DEFINED, OnSectionGeneralNameType)
|
111 |
|
|
//}}AFX_MSG_MAP
|
112 |
|
|
END_MESSAGE_MAP()
|
113 |
|
|
|
114 |
|
|
/////////////////////////////////////////////////////////////////////////////
|
115 |
|
|
// CSectionGeneralPage message handlers
|
116 |
|
|
|
117 |
|
|
void CSectionGeneralPage::OnSectionSizeKnown()
|
118 |
|
|
{
|
119 |
|
|
// enable size edit box according to 'size known' check box
|
120 |
|
|
|
121 |
|
|
m_edtSectionSize.EnableWindow (m_btnSectionSizeKnown.GetCheck () && (! m_bNameLinkerDefined));
|
122 |
|
|
}
|
123 |
|
|
|
124 |
|
|
void CSectionGeneralPage::OnSectionGeneralFinalType()
|
125 |
|
|
{
|
126 |
|
|
// enable/disable dialog controls according to absolute/relative radio button state
|
127 |
|
|
|
128 |
|
|
m_bFinalAbsolute = m_btnFinalAbsolute.GetCheck();
|
129 |
|
|
|
130 |
|
|
m_edtFinalAddress.EnableWindow (m_bFinalAbsolute);
|
131 |
|
|
m_cboFinalRelativeName.EnableWindow (! m_bFinalAbsolute);
|
132 |
|
|
// m_cboFinalRelativeVMA.EnableWindow (! m_bFinalAbsolute); FIXME disabled for now (remove ?)
|
133 |
|
|
if (m_cboAlignment.IsWindowEnabled () && m_bFinalAbsolute)
|
134 |
|
|
m_cboAlignment.SetCurSel (0); // reset to 1 byte alignment
|
135 |
|
|
m_cboAlignment.EnableWindow (! m_bFinalAbsolute);
|
136 |
|
|
}
|
137 |
|
|
|
138 |
|
|
BOOL CSectionGeneralPage::OnInitDialog()
|
139 |
|
|
{
|
140 |
|
|
using namespace std;
|
141 |
|
|
CeCosPropertyPage::OnInitDialog();
|
142 |
|
|
|
143 |
|
|
mem_map * lpMemoryMap = & CConfigTool::GetConfigToolDoc()->MemoryMap;
|
144 |
|
|
|
145 |
|
|
// copy current and unused section names into the linker-defined section names combo box
|
146 |
|
|
|
147 |
|
|
for (list <string>::iterator name = lpMemoryMap->linker_defined_section_list.begin (); name != lpMemoryMap->linker_defined_section_list.end (); ++name)
|
148 |
|
|
if (! lpMemoryMap->section_exists (name->c_str ()) || // section name is unused
|
149 |
|
|
(m_bNameLinkerDefined && (m_strNameLinker == name->c_str ()))) // or section name is that of the current section
|
150 |
|
|
m_cboNameLinker.AddString (CString(name->c_str ()));
|
151 |
|
|
|
152 |
|
|
// select the initial name in the combo box
|
153 |
|
|
|
154 |
|
|
if (m_bNameLinkerDefined && (m_strNameLinker != _T(""))) // the current selection is linker defined
|
155 |
|
|
m_cboNameLinker.SetCurSel (m_cboNameLinker.FindString (-1, m_strNameLinker));
|
156 |
|
|
else if (m_cboNameLinker.GetCount () > 0) // there are names in the combo box
|
157 |
|
|
m_cboNameLinker.SetCurSel (0); // select the first name
|
158 |
|
|
else // there are no names in the combo
|
159 |
|
|
m_btnNameLinkerDefined.EnableWindow (FALSE); // disable the linker-defined section radio button
|
160 |
|
|
|
161 |
|
|
// select the initial section name type radio button
|
162 |
|
|
|
163 |
|
|
if ((! m_bNameLinkerDefined) || (m_cboNameLinker.GetCount () == 0))
|
164 |
|
|
{
|
165 |
|
|
m_btnNameUserDefined.SetCheck (1); // user-defined section
|
166 |
|
|
if (m_bNameLinkerDefined)
|
167 |
|
|
m_dwSectionSize = 0; // default section size for new sections
|
168 |
|
|
m_btnSectionSizeKnown.SetCheck (m_dwSectionSize > 0); // of known size
|
169 |
|
|
}
|
170 |
|
|
else
|
171 |
|
|
m_btnNameLinkerDefined.SetCheck (1); // linker-defined section
|
172 |
|
|
|
173 |
|
|
OnSectionGeneralNameType (); // refresh the state of other controls
|
174 |
|
|
|
175 |
|
|
// copy section names into the relative name combo box
|
176 |
|
|
|
177 |
|
|
for (list <mem_section>::iterator section = lpMemoryMap->section_list.begin (); section != lpMemoryMap->section_list.end (); ++section)
|
178 |
|
|
if ((((section->size !=0) || (section->linker_defined)) && // eliminate user-defined sections of unknown size
|
179 |
|
|
((m_bNameLinkerDefined && (m_strNameLinker == _T(""))) || // if not a new section
|
180 |
|
|
((section->final_location->following_section == NULL) && // eliminate sections with used anchors
|
181 |
|
|
((section->relocates) || (section->initial_location->following_section == NULL)))) && // eliminate sections already used as final anchors unless a new section
|
182 |
|
|
(section->name.c_str () != m_strNameLinker) && // eliminate the current section
|
183 |
|
|
(section->name.c_str () != m_strNameUser)) || // eliminate the current section
|
184 |
|
|
((!m_bFinalAbsolute) && (m_strFinalRelativeName == section->name.c_str()))) // or section name is the current final relative name
|
185 |
|
|
m_cboFinalRelativeName.AddString (CString(section->name.c_str ()));
|
186 |
|
|
|
187 |
|
|
// select the initial name in the combo box
|
188 |
|
|
|
189 |
|
|
if ((! m_bFinalAbsolute) && (m_strFinalRelativeName != _T("")))
|
190 |
|
|
m_cboFinalRelativeName.SetCurSel (m_cboFinalRelativeName.FindString (-1, m_strFinalRelativeName));
|
191 |
|
|
else if (m_cboFinalRelativeName.GetCount () > 0) // there are names in the combo box
|
192 |
|
|
m_cboFinalRelativeName.SetCurSel (0); // select the first name
|
193 |
|
|
else
|
194 |
|
|
m_btnFinalRelative.EnableWindow (FALSE); // disable the relative type radio button
|
195 |
|
|
|
196 |
|
|
// select the initial final location type radio button
|
197 |
|
|
|
198 |
|
|
if (m_bFinalAbsolute)
|
199 |
|
|
m_btnFinalAbsolute.SetCheck (1);
|
200 |
|
|
else
|
201 |
|
|
m_btnFinalRelative.SetCheck (1);
|
202 |
|
|
|
203 |
|
|
OnSectionGeneralFinalType (); // refresh the state of the other controls
|
204 |
|
|
|
205 |
|
|
return TRUE; // return TRUE unless you set the focus to a control
|
206 |
|
|
// EXCEPTION: OCX Property Pages should return FALSE
|
207 |
|
|
}
|
208 |
|
|
|
209 |
|
|
void CSectionGeneralPage::OnSectionGeneralNameType()
|
210 |
|
|
{
|
211 |
|
|
// enable/disable dialog controls according to linker/user defined radio button state
|
212 |
|
|
|
213 |
|
|
m_bNameLinkerDefined = m_btnNameLinkerDefined.GetCheck ();
|
214 |
|
|
|
215 |
|
|
m_cboNameLinker.EnableWindow (m_bNameLinkerDefined);
|
216 |
|
|
m_edtNameUser.EnableWindow (! m_bNameLinkerDefined);
|
217 |
|
|
m_btnSectionSizeKnown.EnableWindow (! m_bNameLinkerDefined);
|
218 |
|
|
OnSectionSizeKnown (); // update state of section size edit box
|
219 |
|
|
}
|
220 |
|
|
|
221 |
|
|
BOOL CSectionGeneralPage::OnKillActive()
|
222 |
|
|
{
|
223 |
|
|
using namespace std;
|
224 |
|
|
if (! UpdateData (TRUE))
|
225 |
|
|
return FALSE;
|
226 |
|
|
|
227 |
|
|
if (! m_bNameLinkerDefined)
|
228 |
|
|
{
|
229 |
|
|
if ((m_strNameUser == _T("")) || (m_strNameUser.FindOneOf (LD_ILLEGAL_CHARS) != -1))
|
230 |
|
|
{
|
231 |
|
|
AfxMessageBox (IDS_VALIDATE_SECTION_NAME);
|
232 |
|
|
m_edtNameUser.SetFocus ();
|
233 |
|
|
return FALSE;
|
234 |
|
|
}
|
235 |
|
|
|
236 |
|
|
mem_map * lpMemoryMap = & CConfigTool::GetConfigToolDoc()->MemoryMap;
|
237 |
|
|
for (list <string>::iterator name = lpMemoryMap->linker_defined_section_list.begin (); name != lpMemoryMap->linker_defined_section_list.end (); ++name)
|
238 |
|
|
if (m_strNameUser == name->c_str ()) // the user-defined name clashes with a linker-defined name
|
239 |
|
|
{
|
240 |
|
|
AfxMessageBox (IDS_VALIDATE_SECTION_NAME_CLASH);
|
241 |
|
|
m_edtNameUser.SetFocus ();
|
242 |
|
|
m_edtNameUser.SetSel (0, -1); // select all text
|
243 |
|
|
return FALSE;
|
244 |
|
|
}
|
245 |
|
|
}
|
246 |
|
|
|
247 |
|
|
// convert address and alignment information to a DWORD representation
|
248 |
|
|
|
249 |
|
|
CString strAlignment;
|
250 |
|
|
m_cboAlignment.GetLBText (m_nAlignment, strAlignment);
|
251 |
|
|
_stscanf (strAlignment, _T("%lx"), &m_dwAlignment);
|
252 |
|
|
|
253 |
|
|
if (m_bFinalAbsolute)
|
254 |
|
|
{
|
255 |
|
|
TCHAR lpszDummy [2];
|
256 |
|
|
if (_stscanf (m_strFinalAddress, _T("%lx%1s"), &m_dwFinalAddress, lpszDummy) != 1)
|
257 |
|
|
{
|
258 |
|
|
AfxMessageBox (IDS_VALIDATE_SECTION_START_ADDRESS);
|
259 |
|
|
m_edtFinalAddress.SetFocus ();
|
260 |
|
|
m_edtFinalAddress.SetSel (0, -1); // select all text
|
261 |
|
|
return FALSE;
|
262 |
|
|
}
|
263 |
|
|
}
|
264 |
|
|
|
265 |
|
|
// convert section size to a DWORD representation
|
266 |
|
|
|
267 |
|
|
if ((! m_bNameLinkerDefined) && m_btnSectionSizeKnown.GetCheck ())
|
268 |
|
|
{
|
269 |
|
|
TCHAR lpszDummy [2];
|
270 |
|
|
if (_stscanf (m_strSectionSize, _T("%lx%1s"), &m_dwSectionSize, lpszDummy) != 1)
|
271 |
|
|
{
|
272 |
|
|
AfxMessageBox (IDS_VALIDATE_SECTION_SIZE);
|
273 |
|
|
m_edtSectionSize.SetFocus ();
|
274 |
|
|
m_edtSectionSize.SetSel (0, -1); // select all text
|
275 |
|
|
return FALSE;
|
276 |
|
|
}
|
277 |
|
|
}
|
278 |
|
|
else
|
279 |
|
|
m_dwSectionSize = 0;
|
280 |
|
|
|
281 |
|
|
return CeCosPropertyPage::OnKillActive();
|
282 |
|
|
}
|
283 |
|
|
|
284 |
|
|
|
285 |
|
|
BOOL CSectionGeneralPage::OnSetActive()
|
286 |
|
|
{
|
287 |
|
|
// generate hex strings for display
|
288 |
|
|
|
289 |
|
|
if ((m_bNameLinkerDefined && (m_strNameLinker == _T(""))) ||
|
290 |
|
|
((! m_bNameLinkerDefined) && (m_strNameUser == _T("")))) // a new section
|
291 |
|
|
{
|
292 |
|
|
m_strFinalAddress = _T("");
|
293 |
|
|
m_strSectionSize = _T("");
|
294 |
|
|
}
|
295 |
|
|
else if (m_bFinalAbsolute)
|
296 |
|
|
m_strFinalAddress.Format (_T("%08lX"), m_dwFinalAddress);
|
297 |
|
|
|
298 |
|
|
if (m_bNameLinkerDefined || (m_dwSectionSize == 0))
|
299 |
|
|
m_strSectionSize == _T("");
|
300 |
|
|
else
|
301 |
|
|
m_strSectionSize.Format (_T("%lX"), m_dwSectionSize);
|
302 |
|
|
|
303 |
|
|
if (m_bFinalAbsolute)
|
304 |
|
|
m_nAlignment = 0;
|
305 |
|
|
else
|
306 |
|
|
{
|
307 |
|
|
CString strAlignment;
|
308 |
|
|
strAlignment.Format (_T("%08lX"), m_dwAlignment);
|
309 |
|
|
m_nAlignment = m_cboAlignment.FindString (-1, strAlignment);
|
310 |
|
|
}
|
311 |
|
|
|
312 |
|
|
if (! UpdateData (FALSE))
|
313 |
|
|
return FALSE;
|
314 |
|
|
|
315 |
|
|
return CeCosPropertyPage::OnSetActive();
|
316 |
|
|
}
|
317 |
|
|
|