📄 memmap.cpp
字号:
region_list.erase (region); map_modified_flag = true; return true; } } return false;}///////////////////////////////////////////////////////////////////// set_map_size() sets the maximum permitted address for the end// of any memory regionbool mem_map::set_map_size (mem_address new_map_size){ // check that the new size is sufficient for all previously defined memory regions for (list <mem_region>::iterator region = region_list.begin (); region != region_list.end (); ++region) { if (region->address + region->size > new_map_size) return false; // the new map size is too small } // set the map size map_size = new_map_size; return true;}////////////////////////////////////////////////////////////////////// edit_memory_section() edits an item to the memory section mapint mem_map::edit_memory_section (string old_section_name, string new_section_name, mem_address section_size, mem_address section_alignment, mem_anchor initial_section_anchor, string initial_anchor_section_name, mem_address initial_anchor_address, mem_anchor final_section_anchor, string final_anchor_section_name, mem_address final_anchor_address, bool relocates, bool anchor_to_initial_location, bool linker_defined, string note){ // do all the parameter validation if (new_section_name == "") // the new section name must be specified return ERR_MEMMAP_SECTION_NONAME; if ((new_section_name != old_section_name) && (find_memory_section (new_section_name) != NULL)) return ERR_MEMMAP_SECTION_NAMEINUSE; // the new section name is not unique list <mem_section>::iterator section = find_memory_section (old_section_name); if (section == NULL) return ERR_MEMMAP_SECTION_NOTFOUND; // the specified old section name could not be found // check that the LMA (if absolute) is within a memory region list <mem_region>::iterator region; if (initial_section_anchor == absolute) { region = find_region_by_address (initial_anchor_address); if (region == NULL) return ERR_MEMMAP_SECTION_LMA_NOTINREGION; // section LMA is not within a memory region if ((section_size > 0) && (initial_anchor_address + section_size > region->address + region->size)) return ERR_MEMMAP_SECTION_LMA_NOTINREGION; // end of section is not within the memory region if (relocates && (region->type == read_write)) return ERR_MEMMAP_SECTION_LMA_READWRITE; // section LMA must be in a read-only memory region } // check that the VMA (if absolute) is within a memory region if (final_section_anchor == absolute) { region = find_region_by_address (final_anchor_address); if (region == NULL) return ERR_MEMMAP_SECTION_VMA_NOTINREGION; // section VMA is not within a memory region if ((section_size > 0) && (final_anchor_address + section_size > region->address + region->size)) return ERR_MEMMAP_SECTION_VMA_NOTINREGION; // end of section is not within the memory region if (relocates && (region->type == read_only)) return ERR_MEMMAP_SECTION_VMA_READONLY; // section VMA must be in a read/write memory region } // check relative location information as appropriate if (relocates) // only check the initial parent section if the section relocates { if (initial_section_anchor == relative) { list <mem_section>::iterator parent_section = find_memory_section (initial_anchor_section_name); if (parent_section == section_list.end ()) return ERR_MEMMAP_SECTION_LMA_ANCHORNOTFOUND; // initial anchor name not found if ((parent_section->initial_location->following_section != section) && (parent_section->initial_location->following_section != NULL)) return ERR_MEMMAP_SECTION_LMA_ANCHORNOTAVAIL; // initial anchor specified has changed and is unavailable if ((parent_section->size == 0) && (! parent_section->linker_defined)) return ERR_MEMMAP_SECTION_LMA_ANCHORNOTAVAIL; // initial anchor specified expands to fit available space if (find_region_by_section (parent_section, initial_location)->type == read_write) return ERR_MEMMAP_SECTION_LMA_READWRITE; // initial anchor must be in a read-only memory region } } if (final_section_anchor == relative) { list <mem_section>::iterator parent_section = find_memory_section (final_anchor_section_name); if (parent_section == NULL) return ERR_MEMMAP_SECTION_VMA_ANCHORNOTFOUND; // final anchor name not found if ((parent_section->size == 0) && (! parent_section->linker_defined)) return ERR_MEMMAP_SECTION_VMA_ANCHORNOTAVAIL; // final anchor specified expands to fit available space if ((!relocates) && anchor_to_initial_location) // final anchor to initial location of parent section { if ((parent_section->initial_location->following_section != section) && (parent_section->initial_location->following_section != NULL)) return ERR_MEMMAP_SECTION_VMA_ANCHORNOTAVAIL; // final anchor specified has changed and is unavailable } else { if ((parent_section->final_location->following_section != section) && (parent_section->final_location->following_section != NULL)) return ERR_MEMMAP_SECTION_VMA_ANCHORNOTAVAIL; // final anchor specified has changed and is unavailable } if (relocates && (find_region_by_section (parent_section, final_location)->type == read_only)) return ERR_MEMMAP_SECTION_VMA_READONLY; // final anchor of relocating section must be in a read/write memory region } // check for a non-relocating section changing to relocating where the final // location moves from a read_only region to a read_write region and there // is a following non-relocating section if (relocates && (! section->relocates) && (find_region_by_section (section, fixed_location)->type == read_only) && (section->final_location->following_section != NULL) && (! section->final_location->following_section->relocates)) { return ERR_MEMMAP_SECTION_ILLEGAL_RELOCATION; } // FIXME check for overlap of absolute sections // modify the initial section location data if (section->initial_location->anchor == relative) // initial section anchor was relative find_preceding_section (section, true)->initial_location->following_section = NULL; if (initial_section_anchor == absolute) // initial location now absolute section->initial_location->address = initial_anchor_address; else // initial location now relative { list <mem_section>::iterator initial_parent = find_memory_section (initial_anchor_section_name); if (relocates || (! initial_parent->relocates)) initial_parent->initial_location->following_section = section; } // modify the final section location data if (section->final_location->anchor == relative) // final section anchor was relative find_preceding_section (section, false)->final_location->following_section = NULL; if (final_section_anchor == absolute) // final location now absolute section->final_location->address = final_anchor_address; else // final location now relative { list <mem_section>::iterator final_parent = find_memory_section (final_anchor_section_name); final_parent->final_location->following_section = section; } // handle relocation changes if (relocates && (! section->relocates)) // section was non-relocating but now relocates { if (find_region_by_section (section, fixed_location)->type == read_only) // the section was in a read_only region section->final_location->following_section = NULL; // there is now no section following the final location else section->initial_location->following_section = NULL; // there is now no section following the initial location } else if ((! relocates) && section->relocates) // section was relocating but is now non-relocating { // determine the type of memory region in which the section now resides mem_type type; if ((final_section_anchor == relative) && anchor_to_initial_location) type = find_region_by_section (find_memory_section (final_anchor_section_name), initial_location)->type; else if (final_section_anchor == relative) // anchored to final location of preceding section type = find_region_by_section (find_memory_section (final_anchor_section_name), final_location)->type; else // final_section_anchor must be absolute type = find_region_by_address (final_anchor_address)->type; if (type == read_only) // the section is now in a read-only memory region { if ((section->initial_location->following_section != NULL) && ! section->initial_location->following_section->relocates) section->final_location->following_section = section->initial_location->following_section; else section->final_location->following_section = NULL; } else // the section is now in a read-write memory region { if ((section->final_location->following_section != NULL) && ! section->final_location->following_section->relocates) section->initial_location->following_section = section->final_location->following_section; else section->initial_location->following_section = NULL; } } // modify the remaining section data section->name = new_section_name; section->size = section_size; section->alignment = section_alignment; section->relocates = relocates; section->note = note; section->linker_defined = linker_defined; section->initial_location->anchor = initial_section_anchor; section->final_location->anchor = final_section_anchor; // recalculate section lists for all regions calc_section_lists (); map_modified_flag = true; return 0;}////////////////////////////////////////////////////////////////////// create_memory_section() adds a new item to the memory section map// either a section name (for relative locations) or an anchor address// (for absolute locations) must be specifiedint mem_map::create_memory_section (string section_name, mem_address section_size, mem_address section_alignment, mem_anchor initial_section_anchor, string initial_anchor_section_name, mem_address initial_anchor_address, mem_anchor final_section_anchor, string final_anchor_section_name, mem_address final_anchor_address, bool relocates, bool anchor_to_initial_location, bool linker_defined, string note){ list <mem_region>::iterator region; // check that the new section name is specified if (section_name == "") return ERR_MEMMAP_SECTION_NONAME; // the new section name must be specified // check that the new section name is unique if (find_memory_section (section_name) != NULL) return ERR_MEMMAP_SECTION_NAMEINUSE; // the new section name is not unique // check that the LMA (if absolute) is within a memory region if (initial_section_anchor == absolute) { region = find_region_by_address (initial_anchor_address); if (region == NULL) return ERR_MEMMAP_SECTION_LMA_NOTINREGION; // section LMA is not within a memory region if ((section_size > 0) && (initial_anchor_address + section_size > region->address + region->size)) return ERR_MEMMAP_SECTION_LMA_NOTINREGION; // end of section is not within the memory region if (relocates && (region->type == read_write)) return ERR_MEMMAP_SECTION_LMA_READWRITE; // section LMA must be in a read-only memory region } // check that the VMA (if absolute) is within a memory region if (final_section_anchor == absolute) { region = find_region_by_address (final_anchor_address); if (region == NULL) return ERR_MEMMAP_SECTION_VMA_NOTINREGION; // section VMA is not within a memory region if ((section_size > 0) && (final_anchor_address + section_size > region->address + region->size)) return ERR_MEMMAP_SECTION_VMA_NOTINREGION; // end of section is not within the memory region if (relocates && (region->type == read_only)) return ERR_MEMMAP_SECTION_VMA_READONLY; // section VMA must be in a read/write memory region } // FIXME check for overlap of absolute sections // check that specified parent(s) (for relative anchors) are available if (relocates) // only check the initial parent section if the section relocates { if (initial_section_anchor == relative) { list <mem_section>::iterator parent_section = find_memory_section (initial_anchor_section_name); if (parent_section == section_list.end ()) return ERR_MEMMAP_SECTION_LMA_ANCHORNOTFOUND; // initial anchor name not found/* if (parent_section->initial_location->following_section != NULL) return ERR_MEMMAP_SECTION_LMA_ANCHORNOTAVAIL; // initial anchor specified is unavailable*/ if ((parent_section->size == 0) && (! parent_section->linker_defined)) return ERR_MEMMAP_SECTION_LMA_ANCHORNOTAVAIL; // initial anchor specified expands to fit available space if (find_region_by_section (parent_section, initial_location)->type == read_write) return ERR_MEMMAP_SECTION_LMA_READWRITE; // initial anchor must be in a read-only memory region } } if (final_section_anchor == relative) { list <mem_section>::iterator parent_section = find_memory_section (final_anchor_section_name); if (parent_section == NULL) return ERR_MEMMAP_SECTION_VMA_ANCHORNOTFOUND; // final anchor name not found if ((parent_section->size == 0) && (! parent_section->linker_defined)) return ERR_MEMMAP_SECTION_VMA_ANCHORNOTAVAIL; // final anchor specified expands to fit available space/* if ((!relocates) && anchor_to_initial_location) // final anchor to initial location of parent section { if (parent_section->initial_location->following_section != NULL) return ERR_MEMMAP_SECTION_VMA_ANCHORNOTAVAIL; // final anchor specified is unavailable } else { if (parent_section->final_location->following_section != NULL) return ERR_MEMMAP_SECTION_VMA_ANCHORNOTAVAIL; // final anchor specified is unavailable }*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -