OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [tools/] [src/] [tools/] [configtool/] [common/] [win32/] [SectionGeneralPage.cpp] - Blame information for rev 174

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.