Added address space unit size to MemorySegment and MemorySegmentSection
Some recfactoring
This commit is contained in:
@@ -397,13 +397,13 @@ class AtdfService
|
||||
new Property(
|
||||
'start_address',
|
||||
'0x' . str_pad(
|
||||
strtoupper(dechex($segment->startAddress)),
|
||||
strtoupper(dechex($segment->addressRange->startAddress)),
|
||||
8,
|
||||
'0',
|
||||
STR_PAD_LEFT
|
||||
)
|
||||
),
|
||||
new Property('size', $segment->size),
|
||||
new Property('size', $segment->size()),
|
||||
new Property('page_size', $segment->pageSize),
|
||||
]
|
||||
);
|
||||
@@ -491,8 +491,9 @@ class AtdfService
|
||||
$section = new MemorySegmentSection(
|
||||
$otherSegment->key,
|
||||
$otherSegment->name,
|
||||
$otherSegment->startAddress,
|
||||
$otherSegment->size,
|
||||
$otherSegment->addressRange->startAddress,
|
||||
$otherSegment->size(),
|
||||
null,
|
||||
[]
|
||||
);
|
||||
|
||||
@@ -501,11 +502,9 @@ class AtdfService
|
||||
* the segment.
|
||||
*/
|
||||
if (
|
||||
$otherSegment->startAddress !== null
|
||||
&& $otherSegment->size !== null
|
||||
$otherSegment->addressRange !== null
|
||||
&& ($parentSection = $segment->getInnermostSectionContainingAddressRange(
|
||||
$otherSegment->startAddress,
|
||||
($otherSegment->startAddress + $otherSegment->size - 1)
|
||||
$otherSegment->addressRange
|
||||
)) !== null
|
||||
) {
|
||||
$parentSection->subSections[] = $section;
|
||||
@@ -542,22 +541,25 @@ class AtdfService
|
||||
'internal_program_memory',
|
||||
'Internal FLASH',
|
||||
MemorySegmentType::FLASH,
|
||||
$appSectionSegment->startAddress,
|
||||
$appSectionSegment->size + $bootSectionSegment->size,
|
||||
$appSectionSegment->addressRange->startAddress,
|
||||
$appSectionSegment->size() + $bootSectionSegment->size(),
|
||||
null,
|
||||
$appSectionSegment->pageSize,
|
||||
$appSectionSegment->access,
|
||||
[
|
||||
new MemorySegmentSection(
|
||||
'app_section',
|
||||
'Application Section',
|
||||
$appSectionSegment->startAddress,
|
||||
$appSectionSegment->size,
|
||||
$appSectionSegment->addressRange->startAddress,
|
||||
$appSectionSegment->size(),
|
||||
null,
|
||||
[
|
||||
new MemorySegmentSection(
|
||||
'app_table_section',
|
||||
'Application Table Section',
|
||||
$appTableSection->startAddress,
|
||||
$appTableSection->size,
|
||||
$appTableSection->addressRange->startAddress,
|
||||
$appTableSection->size(),
|
||||
null,
|
||||
[]
|
||||
)
|
||||
]
|
||||
@@ -565,8 +567,9 @@ class AtdfService
|
||||
new MemorySegmentSection(
|
||||
'boot_section',
|
||||
'Boot Loader Section',
|
||||
$bootSectionSegment->startAddress,
|
||||
$bootSectionSegment->size,
|
||||
$bootSectionSegment->addressRange->startAddress,
|
||||
$bootSectionSegment->size(),
|
||||
null,
|
||||
[]
|
||||
)
|
||||
],
|
||||
@@ -591,6 +594,7 @@ class AtdfService
|
||||
),
|
||||
$this->stringService->tryStringToInt($attributes['start'] ?? null),
|
||||
$this->stringService->tryStringToInt($attributes['size'] ?? null),
|
||||
null,
|
||||
$this->stringService->tryStringToInt($attributes['pagesize'] ?? null),
|
||||
$attributes['rw'] ?? null,
|
||||
[],
|
||||
|
||||
@@ -266,21 +266,21 @@ class ValidationService
|
||||
$failures = array_merge($failures, $this->validateKey($addressSpace->key));
|
||||
}
|
||||
|
||||
if ($addressSpace->startAddress === null) {
|
||||
$failures[] = 'Missing start address';
|
||||
if ($addressSpace->addressRange === null) {
|
||||
$failures[] = 'Missing address range';
|
||||
|
||||
} elseif ($addressSpace->startAddress > 0xFFFFFFFF) {
|
||||
} elseif ($addressSpace->addressRange->startAddress > 0xFFFFFFFF) {
|
||||
$failures[] = 'Start address exceeds 32-bit unsigned integer';
|
||||
}
|
||||
|
||||
if ($addressSpace->size === null) {
|
||||
if ($addressSpace->size() === null) {
|
||||
$failures[] = 'Missing size';
|
||||
|
||||
} elseif ($addressSpace->size > 0xFFFFFFFF) {
|
||||
} elseif ($addressSpace->size() > 0xFFFFFFFF) {
|
||||
$failures[] = 'Size exceeds 32-bit unsigned integer';
|
||||
|
||||
} elseif ($addressSpace->size < 1) {
|
||||
$failures[] = 'Invalid size (' . $addressSpace->size . ')';
|
||||
} elseif ($addressSpace->size() < 1) {
|
||||
$failures[] = 'Invalid size (' . $addressSpace->size() . ')';
|
||||
}
|
||||
|
||||
if (empty($addressSpace->memorySegments)) {
|
||||
@@ -309,9 +309,9 @@ class ValidationService
|
||||
}
|
||||
|
||||
$totalSegmentSize = $addressSpace->totalSegmentSize();
|
||||
if ($totalSegmentSize > $addressSpace->size) {
|
||||
if ($totalSegmentSize > $addressSpace->size()) {
|
||||
$failures[] = 'Total size of all contained segments (' . $totalSegmentSize . ' bytes) exceeds the total'
|
||||
. ' size of the address space (' . $addressSpace->size . ' bytes)';
|
||||
. ' size of the address space (' . $addressSpace->size() . ' bytes)';
|
||||
}
|
||||
|
||||
return array_map(
|
||||
@@ -340,21 +340,21 @@ class ValidationService
|
||||
$failures[] = 'Missing/invalid type';
|
||||
}
|
||||
|
||||
if ($segment->startAddress === null) {
|
||||
$failures[] = 'Missing start address';
|
||||
if ($segment->addressRange === null) {
|
||||
$failures[] = 'Missing address range';
|
||||
|
||||
} elseif ($segment->startAddress > 0xFFFFFFFF) {
|
||||
} elseif ($segment->addressRange->startAddress > 0xFFFFFFFF) {
|
||||
$failures[] = 'Start address exceeds 32-bit unsigned integer';
|
||||
}
|
||||
|
||||
if ($segment->size === null) {
|
||||
if ($segment->size() === null) {
|
||||
$failures[] = 'Missing size';
|
||||
|
||||
} elseif ($segment->size > 0xFFFFFFFF) {
|
||||
} elseif ($segment->size() > 0xFFFFFFFF) {
|
||||
$failures[] = 'Size exceeds 32-bit unsigned integer';
|
||||
|
||||
} elseif ($segment->size < 1) {
|
||||
$failures[] = 'Invalid size (' . $segment->size . ')';
|
||||
} elseif ($segment->size() < 1) {
|
||||
$failures[] = 'Invalid size (' . $segment->size() . ')';
|
||||
}
|
||||
|
||||
if ($segment->executable === null) {
|
||||
@@ -383,9 +383,9 @@ class ValidationService
|
||||
}
|
||||
|
||||
$totalSectionSize = $segment->totalSectionSize();
|
||||
if ($totalSectionSize > $segment->size) {
|
||||
if ($totalSectionSize > $segment->size()) {
|
||||
$failures[] = 'Total size of all contained sections (' . $totalSectionSize . ' bytes) exceeds the total'
|
||||
. ' size of the memory segment (' . $segment->size . ' bytes)';
|
||||
. ' size of the memory segment (' . $segment->size() . ' bytes)';
|
||||
}
|
||||
|
||||
return array_map(
|
||||
@@ -410,15 +410,15 @@ class ValidationService
|
||||
$failures[] = 'Missing name';
|
||||
}
|
||||
|
||||
if ($section->startAddress === null) {
|
||||
$failures[] = 'Missing start address';
|
||||
if ($section->addressRange === null) {
|
||||
$failures[] = 'Missing address range';
|
||||
}
|
||||
|
||||
if ($section->size === null) {
|
||||
if ($section->size() === null) {
|
||||
$failures[] = 'Missing size';
|
||||
|
||||
} elseif ($section->size < 1) {
|
||||
$failures[] = 'Invalid size (' . $section->size . ')';
|
||||
} elseif ($section->size() < 1) {
|
||||
$failures[] = 'Invalid size (' . $section->size() . ')';
|
||||
}
|
||||
|
||||
$processedSectionKeys = [];
|
||||
|
||||
@@ -127,14 +127,14 @@ class FromXmlService
|
||||
}
|
||||
|
||||
if ($childNode->nodeName === 'memory-segment') {
|
||||
$output->memorySegments[] = $this->memorySegmentFromElement($childNode);
|
||||
$output->memorySegments[] = $this->memorySegmentFromElement($childNode, $output->unitSize);
|
||||
}
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
public function memorySegmentFromElement(DOMElement $element): MemorySegment
|
||||
public function memorySegmentFromElement(DOMElement $element, ?int $addressSpaceUnitSize): MemorySegment
|
||||
{
|
||||
$attributes = $this->getNodeAttributesByName($element);
|
||||
|
||||
@@ -144,6 +144,7 @@ class FromXmlService
|
||||
MemorySegmentType::tryFrom($attributes['type'] ?? null),
|
||||
$this->stringService->tryStringToInt($attributes['start'] ?? null),
|
||||
$this->stringService->tryStringToInt($attributes['size'] ?? null),
|
||||
$addressSpaceUnitSize,
|
||||
$this->stringService->tryStringToInt($attributes['page-size'] ?? null),
|
||||
$attributes['access'] ?? null,
|
||||
[],
|
||||
@@ -156,14 +157,14 @@ class FromXmlService
|
||||
}
|
||||
|
||||
if ($childNode->nodeName === 'section') {
|
||||
$output->sections[] = $this->memorySegmentSectionFromElement($childNode);
|
||||
$output->sections[] = $this->memorySegmentSectionFromElement($childNode, $addressSpaceUnitSize);
|
||||
}
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
public function memorySegmentSectionFromElement(DOMElement $element): MemorySegmentSection
|
||||
public function memorySegmentSectionFromElement(DOMElement $element, ?int $addressSpaceUnitSize): MemorySegmentSection
|
||||
{
|
||||
$attributes = $this->getNodeAttributesByName($element);
|
||||
|
||||
@@ -172,6 +173,7 @@ class FromXmlService
|
||||
$attributes['name'] ?? null,
|
||||
$this->stringService->tryStringToInt($attributes['start'] ?? null),
|
||||
$this->stringService->tryStringToInt($attributes['size'] ?? null),
|
||||
$addressSpaceUnitSize,
|
||||
[]
|
||||
);
|
||||
|
||||
@@ -181,7 +183,7 @@ class FromXmlService
|
||||
}
|
||||
|
||||
if ($childNode->nodeName === 'section') {
|
||||
$output->subSections[] = $this->memorySegmentSectionFromElement($childNode);
|
||||
$output->subSections[] = $this->memorySegmentSectionFromElement($childNode, $addressSpaceUnitSize);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -68,8 +68,11 @@ class ToXmlService
|
||||
{
|
||||
$element = $document->createElement('address-space');
|
||||
$element->setAttribute('key', strtolower($addressSpace->key));
|
||||
$element->setAttribute('start', $this->stringService->tryIntToHex($addressSpace->startAddress, 8));
|
||||
$element->setAttribute('size', $addressSpace->size);
|
||||
$element->setAttribute(
|
||||
'start',
|
||||
$this->stringService->tryIntToHex($addressSpace->addressRange->startAddress, 8)
|
||||
);
|
||||
$element->setAttribute('size', $addressSpace->size());
|
||||
|
||||
if (!empty($addressSpace->unitSize)) {
|
||||
$element->setAttribute('unit-size', $addressSpace->unitSize);
|
||||
@@ -92,8 +95,11 @@ class ToXmlService
|
||||
$element->setAttribute('key', strtolower($memorySegment->key));
|
||||
$element->setAttribute('name', $memorySegment->name);
|
||||
$element->setAttribute('type', $memorySegment->type->value ?? '');
|
||||
$element->setAttribute('start', $this->stringService->tryIntToHex($memorySegment->startAddress, 8));
|
||||
$element->setAttribute('size', $memorySegment->size);
|
||||
$element->setAttribute(
|
||||
'start',
|
||||
$this->stringService->tryIntToHex($memorySegment->addressRange->startAddress, 8)
|
||||
);
|
||||
$element->setAttribute('size', $memorySegment->size());
|
||||
|
||||
if (!empty($memorySegment->pageSize)) {
|
||||
$element->setAttribute('page-size', $memorySegment->pageSize);
|
||||
@@ -117,8 +123,8 @@ class ToXmlService
|
||||
$element = $document->createElement('section');
|
||||
$element->setAttribute('key', strtolower($section->key));
|
||||
$element->setAttribute('name', $section->name);
|
||||
$element->setAttribute('start', $this->stringService->tryIntToHex($section->startAddress, 8));
|
||||
$element->setAttribute('size', $section->size);
|
||||
$element->setAttribute('start', $this->stringService->tryIntToHex($section->addressRange->startAddress, 8));
|
||||
$element->setAttribute('size', $section->size());
|
||||
|
||||
foreach ($section->subSections as $section) {
|
||||
$element->append($this->memorySegmentSectionToXml($section, $document));
|
||||
|
||||
Reference in New Issue
Block a user