📄 memmap.cpp
字号:
section1->initial_location->address + section1->size == section2->initial_location->address)) return true; // check if final section locations meet if ((section1->final_location->anchor == absolute) && ((section2->final_location->anchor == absolute) && section1->final_location->address + section1->size == section2->final_location->address)) return true; return false;}//////////////////////////////////////////////////////////////// at_start_of_region() determines whether the specified section// is located at the very start of the specified regionbool mem_map::at_start_of_region (list <mem_section>::iterator section, list <mem_region>::iterator region){ // check initial section location if ((section->initial_location->anchor == absolute) && (section->initial_location->address == region->address)) return true; // check final section location if ((section->final_location->anchor == absolute) && (section->final_location->address == region->address)) return true; return false;}//////////////////////////////////////////////////////////////// at_end_of_region() determines whether the specified section// is located at the very end of the specified regionbool mem_map::at_end_of_region (list <mem_section>::iterator section, list <mem_region>::iterator region){ if (section->size == 0) // size of section is unknown return false; // check initial section location if ((section->initial_location->anchor == absolute) && section->initial_location->address + section->size == region->address + region->size) return true; // check final section location if ((section->final_location->anchor == absolute) && section->final_location->address + section->size == region->address + region->size) return true; return false;}////////////////////////////////////////////////////////////////////////// find_preceding_section() finds the preceding section in the// memory section listlist <mem_section>::iterator mem_map::find_preceding_section (list <mem_section>::iterator reference_section, bool initial_location){ for (list <mem_section>::iterator section = section_list.begin (); section != section_list.end (); ++section) { if (reference_section == (reference_section->relocates && initial_location ? section->initial_location->following_section : section->final_location->following_section)) // if preceding section found return section; // return the section iterator } return NULL; // section not found}////////////////////////////////////////////////////////////////////////// find_memory_section() finds an existing section in the// memory section listlist <mem_section>::iterator mem_map::find_memory_section (string section_name){ for (list <mem_section>::iterator section = section_list.begin (); section != section_list.end (); ++section) if (section->name == section_name) // if section found return section; // return the section iterator return NULL; // section not found}////////////////////////////////////////////////////////////////////////// find_memory_region() finds an existing region in the// memory region listlist <mem_region>::iterator mem_map::find_memory_region (string region_name){ for (list <mem_region>::iterator region = region_list.begin (); region != region_list.end (); ++region) if (region->name == region_name) // if region found return region; // return the region iterator return NULL; // region not found}////////////////////////////////////////////////////////////////////////// delete_memory_section() removes an existing item from the// memory section mapbool mem_map::delete_memory_section (string name){ // make sure that the section exists list <mem_section>::iterator section = find_memory_section (name); if (section == NULL) return false; // there is no section with this name/* // make sure that there are no sections defined relative to this section before deleting it if (section->initial_location->following_section != NULL) return false; if (section->final_location->following_section != NULL) return false;*/ // if section is absolute, copy the initial and final location information to // the following sections (if any) if ((section->initial_location->anchor == absolute) && (section->initial_location->following_section != NULL)) { section->initial_location->following_section->initial_location->anchor = absolute; section->initial_location->following_section->initial_location->address = section->initial_location->address; // FIXME adjust new address of following section for alignment here } if ((section->final_location->anchor == absolute) && (section->final_location->following_section != NULL)) { section->final_location->following_section->final_location->anchor = absolute; section->final_location->following_section->final_location->address = section->final_location->address; // FIXME adjust new address of following section for alignment here } // if section is relative, find the initial and final sections to which it is attached // and set their pointers to the sections following the one to be deleted (if any) list <mem_section>::iterator related_section; if (section->initial_location->anchor == relative) for (related_section = section_list.begin (); related_section != section_list.end (); ++related_section) if (related_section->initial_location->following_section == section) related_section->initial_location->following_section = section->initial_location->following_section; if (section->final_location->anchor == relative) for (related_section = section_list.begin (); related_section != section_list.end (); ++related_section) if (related_section->final_location->following_section == section) related_section->final_location->following_section = section->final_location->following_section; // delete the section deleteZ(section->initial_location); deleteZ(section->final_location); section_list.erase (section); // recalculate section lists for all regions calc_section_lists (); map_modified_flag = true; return true;}////////////////////////////////////////////////////////////////////////// delete_memory_sections() deletes all memory sections in preparation// for layout loading or application closurebool mem_map::delete_all_memory_sections (){ // deleteZ(each section in turn) while (section_list.size () > 0) { list <mem_section>::iterator section = section_list.begin (); deleteZ(section->initial_location); deleteZ(section->final_location); section_list.erase (section); }// section_list.clear (); // recalculate section view lists for all regions calc_section_lists (); map_modified_flag = true; return true;}////////////////////////////////////////////////////////////////////////// export_sections() exports section-related info for regions of the// specified type to the linker script fragment and header filebool mem_map::export_sections (FILE * script_stream, FILE * header_stream, mem_type type){ for (list <mem_region>::iterator region = region_list.begin (); region != region_list.end(); ++region) if (region->type == type) { for (list <mem_section_view>::iterator section_view = region->section_view_list.begin (); section_view != region->section_view_list.end (); ++section_view) { if ((section_view->section != NULL) && (section_view->section_location != initial_location)) { if (section_view->section->linker_defined) // section is linker-defined { // output section name and region name fprintf (script_stream, " SECTION_%s (%s, ", encode_section_name (section_view->section->name).c_str (), region->name.c_str ()); // output VMA if (section_view->section->final_location->anchor == absolute) // an absolute VMA fprintf (script_stream, "%#lx, ", section_view->section->final_location->address); // specify absolute address else // a relative VMA fprintf (script_stream, "ALIGN (%#lx), ", section_view->section->alignment); // specify alignment // output LMA if (! section_view->section->relocates) // section does not relocate so LMA == VMA fprintf (script_stream, "LMA_EQ_VMA)"); else if (section_view->section->initial_location->anchor == absolute) // an absolute LMA fprintf (script_stream, "AT (%#lx))", section_view->section->initial_location->address); else // a relative LMA { list <mem_section>::iterator parent_section; for (parent_section = section_list.begin (); parent_section != section_list.end (); ++parent_section) if (parent_section->initial_location->following_section == section_view->section) break; if (parent_section->linker_defined) // parent section is linker-defined fprintf (script_stream, "FOLLOWING (.%s))", parent_section->name.c_str ()); else // parent section is user-defined fprintf (script_stream, "AT (__%s + %#lx))", parent_section->name.c_str (), parent_section->size); } } else // section is user-defined { // output section symbol if (section_view->section->final_location->anchor == absolute) // an absolute VMA fprintf (script_stream, " __%s = %#lx;", section_view->section->name.c_str (), section_view->section->final_location->address); else // a relative VMA fprintf (script_stream, " __%s = ALIGN (%#lx);", section_view->section->name.c_str (), section_view->section->alignment); // update current location pointer if (section_view->section->size != 0) // size is known fprintf (script_stream, " . = __%s + %#lx;", section_view->section->name.c_str (), section_view->section->size); // output reference to symbol in header file fprintf (header_stream, "extern char CYG_LABEL_NAME (_%s) [];\n", section_view->section->name.c_str ()); fprintf (header_stream, "#define CYGMEM_SECTION_%s (CYG_LABEL_NAME (_%s))\n", section_view->section->name.c_str (), section_view->section->name.c_str ()); if (section_view->section->size == 0) // a section of unknown size { mem_address section_end_address; ++section_view; // move to next section_view if (section_view == region->section_view_list.end ()) // section continues to end of region section_end_address = region->address + region->size; else // section continues to next section with an absolute location section_end_address = section_view->section->final_location->address; --section_view; // move back to previous section view fprintf (header_stream, "#define CYGMEM_SECTION_%s_SIZE (%#lx - (size_t) CYG_LABEL_NAME (_%s))\n", section_view->section->name.c_str (), section_end_address, section_view->section->name.c_str ()); } else // a section of known size fprintf (header_stream, "#define CYGMEM_SECTION_%s_SIZE (%#lx)\n", section_view->section->name.c_str (), section_view->section->size); } // end of section description fprintf (script_stream, "\n"); // new line } } } return true;}////////////////////////////////////////////////////////////////////////// export_files() creates a fragment of linker script and a header file// describing the memory layoutbool mem_map::export_files (LPCTSTR script_name, LPCTSTR header_name){ FILE * script_stream; FILE * header_stream; list <mem_region>::iterator region; // do not export files if the memory layout is empty // assume that there are default LDI files available if (region_list.size () == 0) return false; // open the script fragment file for writing script_stream = _tfopen (script_name, _T("wt")); if (script_stream == NULL) return false; // open the header file for writing header_stream = _tfopen (header_name, _T("wt")); if (header_stream == NULL) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -