1 //####COPYRIGHTBEGIN####
3 // ----------------------------------------------------------------------------
4 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
6 // This program is part of the eCos host tools.
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)
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
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.
22 // ----------------------------------------------------------------------------
24 //####COPYRIGHTEND####
25 //=================================================================
27 // SectionRelocationPage.cpp
29 // Memory Layout Tool section relocation property page class
31 //=================================================================
32 //#####DESCRIPTIONBEGIN####
34 // Author(s): John Dallaway
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 // relocation section property selection
40 // See also: SectionRelocationPage.h
41 // Known bugs: <UPDATE_ME_AT_RELEASE_TIME>
43 //####DESCRIPTIONEND####
46 #include "ConfigtoolDoc.h"
47 #include "SectionRelocationPage.h"
48 #include "ConfigTool.h"
57 static char THIS_FILE[] = __FILE__;
60 /////////////////////////////////////////////////////////////////////////////
61 // CSectionRelocationPage property page
63 IMPLEMENT_DYNCREATE(CSectionRelocationPage, CeCosPropertyPage)
65 CSectionRelocationPage::CSectionRelocationPage() : CeCosPropertyPage(CSectionRelocationPage::IDD)
67 //{{AFX_DATA_INIT(CSectionRelocationPage)
69 m_strInitialRelativeName = _T("");
70 m_strInitialAddress = _T("");
72 m_bNewSection = FALSE;
76 CSectionRelocationPage::~CSectionRelocationPage()
81 void CSectionRelocationPage::DoDataExchange(CDataExchange* pDX)
83 CeCosPropertyPage::DoDataExchange(pDX);
84 //{{AFX_DATA_MAP(CSectionRelocationPage)
85 DDX_Control(pDX, IDC_SECTION_RELOCATION_RELOCATES, m_btnRelocates);
86 DDX_Control(pDX, IDC_SECTION_RELOCATION_INITIAL_RELATIVE, m_btnInitialRelative);
87 DDX_Control(pDX, IDC_SECTION_RELOCATION_INITIAL_ABSOLUTE, m_btnInitialAbsolute);
88 DDX_Control(pDX, IDC_SECTION_RELOCATION_INITIAL_ABSOLUTE_ADDRESS, m_edtInitialAddress);
89 DDX_Control(pDX, IDC_SECTION_RELOCATION_INITIAL_RELATIVE_NAME, m_cboInitialRelativeName);
90 DDX_Check(pDX, IDC_SECTION_RELOCATION_RELOCATES, m_bRelocates);
91 DDX_CBString(pDX, IDC_SECTION_RELOCATION_INITIAL_RELATIVE_NAME, m_strInitialRelativeName);
92 DDX_Text(pDX, IDC_SECTION_RELOCATION_INITIAL_ABSOLUTE_ADDRESS, m_strInitialAddress);
97 BEGIN_MESSAGE_MAP(CSectionRelocationPage, CeCosPropertyPage)
98 //{{AFX_MSG_MAP(CSectionRelocationPage)
99 ON_BN_CLICKED(IDC_SECTION_RELOCATION_RELOCATES, OnSectionRelocationRelocates)
100 ON_BN_CLICKED(IDC_SECTION_RELOCATION_INITIAL_RELATIVE, OnSectionRelocationInitialType)
101 ON_BN_CLICKED(IDC_SECTION_RELOCATION_INITIAL_ABSOLUTE, OnSectionRelocationInitialType)
105 /////////////////////////////////////////////////////////////////////////////
106 // CSectionRelocationPage message handlers
108 void CSectionRelocationPage::OnSectionRelocationRelocates()
110 OnSectionRelocationInitialType ();
114 void CSectionRelocationPage::OnSectionRelocationInitialType()
116 const BOOL bRelocates = m_btnRelocates.GetState() & 0x0003;
118 m_bInitialAbsolute = m_btnInitialAbsolute.GetState() & 0x0003;
120 m_btnInitialAbsolute.EnableWindow (bRelocates);
121 m_btnInitialRelative.EnableWindow (bRelocates && (m_cboInitialRelativeName.GetCount () > 0));
122 m_edtInitialAddress.EnableWindow (m_bInitialAbsolute && bRelocates);
123 m_cboInitialRelativeName.EnableWindow (bRelocates && ! m_bInitialAbsolute);
127 BOOL CSectionRelocationPage::OnInitDialog()
130 CeCosPropertyPage::OnInitDialog();
132 m_btnInitialAbsolute.SetCheck (1);
134 mem_map * lpMemoryMap = & CConfigTool::GetConfigToolDoc()->MemoryMap;
136 // copy section names into the relative name combo box
138 for (list <mem_region>::iterator region = lpMemoryMap->region_list.begin (); region != lpMemoryMap->region_list.end (); ++region)
139 if (region->type == read_only) // initial location of relocating section must be in a read-only region
140 for (list <mem_section_view>::iterator section_view = region->section_view_list.begin (); section_view != region->section_view_list.end (); ++section_view)
141 if ((section_view->section != NULL) && (section_view->section_location != final_location) && // not the final location of a relocating section
142 ((section_view->section->size !=0) || (section_view->section->linker_defined)) && // eliminate user-defined sections of unknown size
143 (m_bNewSection || (section_view->section->initial_location->following_section == NULL)) || // eliminate sections already used as initial anchors unless a new section
144 ((section_view->section != NULL) && (!m_bInitialAbsolute) && (m_strInitialRelativeName == section_view->section->name.c_str()))) // or section name is the current initial relative name
145 m_cboInitialRelativeName.AddString (CString(section_view->section->name.c_str ()));
147 if (m_cboInitialRelativeName.GetCount () > 0) // there are anchor sections available
148 m_cboInitialRelativeName.SetCurSel (0); // select the first item in the combo box (if any)
149 else // there are no anchor sections available
150 m_btnInitialRelative.EnableWindow (FALSE); // disable the relative section radio button
152 m_btnRelocates.SetCheck (m_bRelocates);
153 m_btnInitialAbsolute.SetCheck (m_bInitialAbsolute);
154 m_btnInitialRelative.SetCheck (! m_bInitialAbsolute);
155 OnSectionRelocationRelocates ();
157 if ((! m_bInitialAbsolute) && (m_bRelocates))
158 m_cboInitialRelativeName.SetCurSel (m_cboInitialRelativeName.FindString (-1, m_strInitialRelativeName));
159 else if (m_cboInitialRelativeName.GetCount () > 0) // there are names in the combo box
160 m_cboInitialRelativeName.SetCurSel (0); // select the first name
162 m_btnInitialRelative.EnableWindow (FALSE); // disable the relative type radio button
164 return TRUE; // return TRUE unless you set the focus to a control
165 // EXCEPTION: OCX Property Pages should return FALSE
169 BOOL CSectionRelocationPage::OnKillActive()
171 if (! UpdateData (TRUE))
174 // convert address to a DWORD representation
176 if (m_bRelocates && m_bInitialAbsolute)
179 if (_stscanf (m_strInitialAddress, _T("%lx%1s"), &m_dwInitialAddress, lpszDummy) != 1)
181 AfxMessageBox (IDS_VALIDATE_SECTION_START_ADDRESS);
182 m_edtInitialAddress.SetFocus ();
183 m_edtInitialAddress.SetSel (0, -1); // select all text
188 return CeCosPropertyPage::OnKillActive();
192 BOOL CSectionRelocationPage::OnSetActive()
194 if (m_bRelocates && m_bInitialAbsolute)
195 m_strInitialAddress.Format (_T("%08lX"), m_dwInitialAddress);
197 m_strInitialAddress = _T("");
199 if (! UpdateData (FALSE))
202 return CeCosPropertyPage::OnSetActive();