Added address space unit size to MemorySegment and MemorySegmentSection

Some recfactoring
This commit is contained in:
Nav
2024-12-27 01:53:02 +00:00
parent 7aeb2ddf08
commit 00c4cee6c2
11 changed files with 202 additions and 186 deletions

View File

@@ -72,21 +72,21 @@ class Avr8TargetDescriptionFile extends TargetDescriptionFile
$programMemorySegment = $this->getProgramMemorySegment();
if ($programMemorySegment instanceof MemorySegment) {
$output->flashStartAddress = $programMemorySegment->startAddress;
$output->flashSize = $programMemorySegment->size;
$output->flashStartAddress = $programMemorySegment->addressRange->startAddress;
$output->flashSize = $programMemorySegment->size();
$output->flashPageSize = $programMemorySegment->pageSize;
}
$ramMemorySegment = $this->getRamSegment();
if ($ramMemorySegment instanceof MemorySegment) {
$output->ramStartAddress = $ramMemorySegment->startAddress;
$output->ramStartAddress = $ramMemorySegment->addressRange->startAddress;
}
$output->bootSectionOptions = $this->getBootSectionOptions();
$eepromMemorySegment = $this->getEepromSegment();
if ($eepromMemorySegment instanceof MemorySegment) {
$output->eepromSize = $eepromMemorySegment->size;
$output->eepromSize = $eepromMemorySegment->size();
$output->eepromPageSize = $eepromMemorySegment->pageSize;
}
@@ -218,21 +218,21 @@ class Avr8TargetDescriptionFile extends TargetDescriptionFile
$programMemorySegment = $this->getProgramMemorySegment();
if ($programMemorySegment instanceof MemorySegment) {
$output->flashStartAddress = $programMemorySegment->startAddress;
$output->flashSize = $programMemorySegment->size;
$output->flashStartAddress = $programMemorySegment->addressRange->startAddress;
$output->flashSize = $programMemorySegment->size();
$output->flashPageSize = $programMemorySegment->pageSize;
}
$ramMemorySegment = $this->getRamSegment();
if ($ramMemorySegment instanceof MemorySegment) {
$output->ramStartAddress = $ramMemorySegment->startAddress;
$output->ramStartAddress = $ramMemorySegment->addressRange->startAddress;
}
$output->bootSectionOptions = $this->getBootSectionOptions();
$eepromMemorySegment = $this->getEepromSegment();
if ($eepromMemorySegment instanceof MemorySegment) {
$output->eepromSize = $eepromMemorySegment->size;
$output->eepromSize = $eepromMemorySegment->size();
$output->eepromPageSize = $eepromMemorySegment->pageSize;
}
@@ -344,18 +344,18 @@ class Avr8TargetDescriptionFile extends TargetDescriptionFile
$appSection = $programMemorySegment->getSection('app_section');
if ($appSection instanceof MemorySegmentSection) {
$output->appSectionSize = $appSection->size;
$output->appSectionSize = $appSection->size();
}
$bootSection = $programMemorySegment->getSection('boot_section');
if ($bootSection instanceof MemorySegmentSection) {
$output->bootSectionSize = $bootSection->size;
$output->bootSectionSize = $bootSection->size();
}
}
$eepromMemorySegment = $this->getEepromSegment();
if ($eepromMemorySegment instanceof MemorySegment) {
$output->eepromSize = $eepromMemorySegment->size;
$output->eepromSize = $eepromMemorySegment->size();
$output->eepromPageSize = $eepromMemorySegment->pageSize;
}
@@ -381,14 +381,14 @@ class Avr8TargetDescriptionFile extends TargetDescriptionFile
$programMemorySegment = $this->getProgramMemorySegment();
if ($programMemorySegment instanceof MemorySegment) {
$output->flashSize = $programMemorySegment->size;
$output->flashSize = $programMemorySegment->size();
$output->flashPageSize = $programMemorySegment->pageSize;
}
$eepromMemorySegment = $this->getEepromSegment();
if ($eepromMemorySegment instanceof MemorySegment) {
$output->eepromStartAddress = $eepromMemorySegment->startAddress;
$output->eepromSize = $eepromMemorySegment->size;
$output->eepromStartAddress = $eepromMemorySegment->addressRange->startAddress;
$output->eepromSize = $eepromMemorySegment->size();
$output->eepromPageSize = $eepromMemorySegment->pageSize;
}
@@ -410,7 +410,7 @@ class Avr8TargetDescriptionFile extends TargetDescriptionFile
);
if ($signatureMemorySegment instanceof MemorySegment) {
$output->signatureSegmentStartAddress = $signatureMemorySegment->startAddress;
$output->signatureSegmentStartAddress = $signatureMemorySegment->addressRange->startAddress;
}
$fuseMemorySegment = $this->getMemorySegment(
@@ -422,8 +422,8 @@ class Avr8TargetDescriptionFile extends TargetDescriptionFile
);
if ($fuseMemorySegment instanceof MemorySegment) {
$output->fuseSegmentSize = $fuseMemorySegment->size;
$output->fuseSegmentStartAddress = $fuseMemorySegment->startAddress;
$output->fuseSegmentSize = $fuseMemorySegment->size();
$output->fuseSegmentStartAddress = $fuseMemorySegment->addressRange->startAddress;
}
$lockbitsMemorySegment = $this->getMemorySegment(
@@ -435,7 +435,7 @@ class Avr8TargetDescriptionFile extends TargetDescriptionFile
);
if ($lockbitsMemorySegment instanceof MemorySegment) {
$output->lockbitsSegmentStartAddress = $lockbitsMemorySegment->startAddress;
$output->lockbitsSegmentStartAddress = $lockbitsMemorySegment->addressRange->startAddress;
}
return $output;

View File

@@ -27,7 +27,7 @@ class ValidationService extends \Targets\TargetDescriptionFiles\Services\Validat
if ($progAddressSpace === null) {
$failures[] = 'Missing program memory address space';
} elseif ($progAddressSpace->size > 1000000) {
} elseif ($progAddressSpace->size() > 1000000) {
/*
* For program memory cache, Bloom currently allocates a buffer equal to the size of the program memory
* address space. This can become a problem if the address space is huge.
@@ -53,7 +53,7 @@ class ValidationService extends \Targets\TargetDescriptionFiles\Services\Validat
$failures[] = 'Missing "internal_ram" memory segment';
} else {
$sramEndAddress = $sramSegment->startAddress + $sramSegment->size - 1;
$sramEndAddress = $sramSegment->addressRange->startAddress + $sramSegment->size() - 1;
/*
* The GPR and IO segments must not come after the SRAM segment in the data address space.
@@ -61,11 +61,11 @@ class ValidationService extends \Targets\TargetDescriptionFiles\Services\Validat
* There are some places in Bloom's codebase where we have made this assumption, which is why we confirm
* it here as part of TDF validation.
*/
if ($gprSegment !== null && $gprSegment->startAddress > $sramEndAddress) {
if ($gprSegment !== null && $gprSegment->addressRange->startAddress > $sramEndAddress) {
$failures[] = 'The GPR memory segment comes after the SRAM segment';
}
if ($ioSegment !== null && $ioSegment->startAddress > $sramEndAddress) {
if ($ioSegment !== null && $ioSegment->addressRange->startAddress > $sramEndAddress) {
$failures[] = 'The IO memory segment comes after the SRAM segment';
}
}
@@ -390,23 +390,23 @@ class ValidationService extends \Targets\TargetDescriptionFiles\Services\Validat
* we assume that the offset has already been applied to the params. We confirm this here.
*/
if (($ioMemorySegment = $tdf->getIoMemorySegment()) instanceof MemorySegment) {
if ($parameters->osccalAddress < $ioMemorySegment->startAddress) {
if ($parameters->osccalAddress < $ioMemorySegment->addressRange->startAddress) {
$failures[] = 'OSCCAL address does not have IO memory segment offset applied';
}
if ($parameters->eearAddressLow < $ioMemorySegment->startAddress) {
if ($parameters->eearAddressLow < $ioMemorySegment->addressRange->startAddress) {
$failures[] = 'EEARL address does not have IO memory segment offset applied';
}
if ($parameters->eearAddressHigh < $ioMemorySegment->startAddress) {
if ($parameters->eearAddressHigh < $ioMemorySegment->addressRange->startAddress) {
$failures[] = 'EEARH address does not have IO memory segment offset applied';
}
if ($parameters->eecrAddress < $ioMemorySegment->startAddress) {
if ($parameters->eecrAddress < $ioMemorySegment->addressRange->startAddress) {
$failures[] = 'EECR address does not have IO memory segment offset applied';
}
if ($parameters->eedrAddress < $ioMemorySegment->startAddress) {
if ($parameters->eedrAddress < $ioMemorySegment->addressRange->startAddress) {
$failures[] = 'EEDR address does not have IO memory segment offset applied';
}
@@ -580,23 +580,23 @@ class ValidationService extends \Targets\TargetDescriptionFiles\Services\Validat
* we assume that the offset has already been applied to the params. We confirm this here.
*/
if (($ioMemorySegment = $tdf->getIoMemorySegment()) instanceof MemorySegment) {
if ($parameters->osccalAddress < $ioMemorySegment->startAddress) {
if ($parameters->osccalAddress < $ioMemorySegment->addressRange->startAddress) {
$failures[] = 'OSCCAL address does not have IO memory segment offset applied';
}
if ($parameters->eearAddressLow < $ioMemorySegment->startAddress) {
if ($parameters->eearAddressLow < $ioMemorySegment->addressRange->startAddress) {
$failures[] = 'EEARL address does not have IO memory segment offset applied';
}
if ($parameters->eearAddressHigh < $ioMemorySegment->startAddress) {
if ($parameters->eearAddressHigh < $ioMemorySegment->addressRange->startAddress) {
$failures[] = 'EEARH address does not have IO memory segment offset applied';
}
if ($parameters->eecrAddress < $ioMemorySegment->startAddress) {
if ($parameters->eecrAddress < $ioMemorySegment->addressRange->startAddress) {
$failures[] = 'EECR address does not have IO memory segment offset applied';
}
if ($parameters->eedrAddress < $ioMemorySegment->startAddress) {
if ($parameters->eedrAddress < $ioMemorySegment->addressRange->startAddress) {
$failures[] = 'EEDR address does not have IO memory segment offset applied';
}

View File

@@ -0,0 +1,32 @@
<?php
namespace Targets\TargetDescriptionFiles;
class AddressRange
{
public int $startAddress;
public int $endAddress;
public function __construct(int $startAddress, int $endAddress)
{
$this->startAddress = $startAddress;
$this->endAddress = $endAddress;
}
public function size(): int
{
return $this->endAddress - $this->startAddress + 1;
}
public function contains(AddressRange $other): bool
{
return $this->startAddress <= $other->startAddress && $this->endAddress >= $other->endAddress;
}
public function intersectsWith(AddressRange $other): bool
{
return
($other->startAddress <= $this->startAddress && $other->endAddress >= $this->startAddress)
|| ($other->startAddress >= $this->startAddress && $other->startAddress <= $this->endAddress)
;
}
}

View File

@@ -1,13 +1,13 @@
<?php
namespace Targets\TargetDescriptionFiles;
require_once __DIR__ . "/AddressRange.php";
require_once __DIR__ . "/MemorySegment.php";
class AddressSpace
{
public ?string $key = null;
public ?int $startAddress = null;
public ?int $size = null;
public ?AddressRange $addressRange = null;
public ?int $unitSize = null;
public ?string $endianness = null;
@@ -17,12 +17,23 @@ class AddressSpace
public function __construct(?string $key, ?int $startAddress, ?int $size, ?int $unitSize, ?string $endianness)
{
$this->key = $key;
$this->startAddress = $startAddress;
$this->size = $size;
$this->addressRange = is_numeric($startAddress) && is_numeric($size)
? new AddressRange(
$startAddress,
$startAddress + ($size / ($unitSize ?? 1)) - 1
)
: null;
$this->unitSize = $unitSize;
$this->endianness = $endianness;
}
public function size(): ?int
{
return $this->addressRange instanceof AddressRange
? $this->addressRange->size() * ($this->unitSize ?? 1)
: null;
}
public function getMemorySegment(string $key): ?MemorySegment
{
foreach ($this->memorySegments as $segment) {
@@ -38,27 +49,7 @@ class AddressSpace
{
return array_sum(
array_map(
fn (MemorySegment $segment): int => (int) $segment->size,
$this->memorySegments
)
);
}
public function segmentStartAddress(): int
{
return min(
array_map(
fn (MemorySegment $segment): int => (int) $segment->startAddress,
$this->memorySegments
)
);
}
public function segmentEndAddress(): int
{
return max(
array_map(
fn (MemorySegment $segment): int => (int) $segment->startAddress + $segment->size - 1,
fn (MemorySegment $segment): int => (int) $segment->size(),
$this->memorySegments
)
);
@@ -77,9 +68,9 @@ class AddressSpace
return array_filter(
$this->memorySegments,
function (MemorySegment $segment) use ($startAddress, $endAddress) : bool {
$segmentEndAddress = $segment->startAddress + $segment->size - 1;
return ($startAddress <= $segment->startAddress && $endAddress >= $segment->startAddress)
|| ($startAddress >= $segment->startAddress && $startAddress <= $segmentEndAddress);
$segmentEndAddress = $segment->addressRange->startAddress + $segment->size() - 1;
return ($startAddress <= $segment->addressRange->startAddress && $endAddress >= $segment->addressRange->startAddress)
|| ($startAddress >= $segment->addressRange->startAddress && $startAddress <= $segmentEndAddress);
}
);
}

View File

@@ -1,6 +1,7 @@
<?php
namespace Targets\TargetDescriptionFiles;
require_once __DIR__ . "/AddressRange.php";
require_once __DIR__ . "/MemorySegmentType.php";
require_once __DIR__ . "/MemorySegmentSection.php";
@@ -9,8 +10,8 @@ class MemorySegment
public ?string $key = null;
public ?string $name = null;
public ?MemorySegmentType $type = null;
public ?int $startAddress = null;
public ?int $size = null;
public ?AddressRange $addressRange = null;
public ?int $addressSpaceUnitSize = null;
public ?int $pageSize = null;
public ?string $access = null;
public ?bool $executable = null;
@@ -24,6 +25,7 @@ class MemorySegment
?MemorySegmentType $type,
?int $startAddress,
?int $size,
?int $addressSpaceUnitSize,
?int $pageSize,
?string $access,
array $sections,
@@ -32,14 +34,26 @@ class MemorySegment
$this->key = $key;
$this->name = $name;
$this->type = $type;
$this->startAddress = $startAddress;
$this->size = $size;
$this->addressRange = is_numeric($startAddress) && is_numeric($size)
? new AddressRange(
$startAddress,
$startAddress + ($size / ($addressSpaceUnitSize ?? 1)) - 1
)
: null;
$this->addressSpaceUnitSize = $addressSpaceUnitSize;
$this->pageSize = $pageSize;
$this->access = $access;
$this->sections = $sections;
$this->executable = $executable;
}
public function size(): ?int
{
return $this->addressRange instanceof AddressRange
? $this->addressRange->size() * ($this->addressSpaceUnitSize ?? 1)
: null;
}
public function getSection(string $sectionId): ?MemorySegmentSection
{
foreach ($this->sections as $section) {
@@ -53,11 +67,11 @@ class MemorySegment
return null;
}
public function getInnermostSectionContainingAddressRange(int $startAddress, int $endAddress)
public function getInnermostSectionContainingAddressRange(AddressRange $range)
: ?MemorySegmentSection {
foreach ($this->sections as $section) {
if ($section->containsAddressRange($startAddress, $endAddress)) {
return $section->getInnermostSubSectionContainingAddressRange($startAddress, $endAddress);
if ($section->containsAddressRange($range)) {
return $section->getInnermostSubSectionContainingAddressRange($range);
}
}
@@ -66,34 +80,15 @@ class MemorySegment
public function contains(MemorySegment $other): bool
{
$endAddress = !is_null($this->startAddress) && !is_null($this->size)
? ($this->startAddress + $this->size - 1) : null;
$otherEndAddress = !is_null($other->startAddress) && !is_null($other->size)
? ($other->startAddress + $other->size - 1) : null;
return
$this->startAddress !== null
&& $endAddress !== null
&& $other->startAddress !== null
&& $otherEndAddress !== null
&& $this->startAddress <= $other->startAddress
&& $endAddress >= $otherEndAddress
;
return $this->addressRange instanceof AddressRange && $this->addressRange->contains($other->addressRange);
}
public function intersectsWith(MemorySegment $other): bool
{
$endAddress = !is_null($this->startAddress) && !is_null($this->size)
? ($this->startAddress + $this->size - 1) : null;
$otherEndAddress = !is_null($other->startAddress) && !is_null($other->size)
? ($other->startAddress + $other->size - 1) : null;
return
$this->startAddress !== null
&& $endAddress !== null
&& $other->startAddress !== null
&& $otherEndAddress !== null
&& $this->startAddress <= $otherEndAddress && $other->startAddress <= $endAddress
$this->addressRange instanceof AddressRange
&& $other->addressRange instanceof AddressRange
&& $this->addressRange->intersectsWith($other->addressRange)
;
}
@@ -101,7 +96,7 @@ class MemorySegment
{
return array_sum(
array_map(
fn (MemorySegmentSection $section): int => (int) $section->size,
fn (MemorySegmentSection $section): int => (int) $section->size(),
$this->sections
)
);

View File

@@ -1,12 +1,14 @@
<?php
namespace Targets\TargetDescriptionFiles;
require_once __DIR__ . "/AddressRange.php";
class MemorySegmentSection
{
public ?string $key = null;
public ?string $name = null;
public ?int $startAddress = null;
public ?int $size = null;
public ?AddressRange $addressRange = null;
public ?int $addressSpaceUnitSize = null;
/** @var MemorySegmentSection[] */
public array $subSections = [];
@@ -16,76 +18,59 @@ class MemorySegmentSection
?string $name,
?int $startAddress,
?int $size,
?int $addressSpaceUnitSize,
array $subSections
) {
$this->key = $key;
$this->name = $name;
$this->startAddress = $startAddress;
$this->size = $size;
$this->addressRange = is_numeric($startAddress) && is_numeric($size)
? new AddressRange(
$startAddress,
$startAddress + ($size / ($addressSpaceUnitSize ?? 1)) - 1
)
: null;
$this->addressSpaceUnitSize = $addressSpaceUnitSize;
$this->subSections = $subSections;
}
public function getInnermostSubSectionContainingAddressRange(int $startAddress, int $endAddress)
public function size(): ?int
{
return $this->addressRange instanceof AddressRange
? $this->addressRange->size() * ($this->addressSpaceUnitSize ?? 1)
: null;
}
public function getInnermostSubSectionContainingAddressRange(AddressRange $range)
: ?MemorySegmentSection {
if ($this->containsAddressRange($startAddress, $endAddress)) {
if (!$this->containsAddressRange($range)) {
return null;
}
foreach ($this->subSections as $section) {
if ($section->containsAddressRange($startAddress, $endAddress)) {
return $section->getInnermostSubSectionContainingAddressRange($startAddress, $endAddress);
if ($section->containsAddressRange($range)) {
return $section->getInnermostSubSectionContainingAddressRange($range);
}
}
return $this;
}
public function contains(MemorySegment $other): bool
public function contains(MemorySegmentSection $other): bool
{
$endAddress = !is_null($this->startAddress) && !is_null($this->size)
? ($this->startAddress + $this->size - 1) : null;
$otherEndAddress = !is_null($other->startAddress) && !is_null($other->size)
? ($other->startAddress + $other->size - 1) : null;
return
$this->startAddress !== null
&& $endAddress !== null
&& $other->startAddress !== null
&& $otherEndAddress !== null
&& $this->startAddress <= $other->startAddress
&& $endAddress >= $otherEndAddress
;
return $this->addressRange instanceof AddressRange && $this->addressRange->contains($other->addressRange);
}
public function containsAddressRange(int $subjectStartAddress, int $subjectEndAddress): bool
public function containsAddressRange(AddressRange $range): bool
{
$endAddress = !is_null($this->startAddress) && !is_null($this->size)
? ($this->startAddress + $this->size - 1) : null;
return
$this->startAddress !== null
&& $endAddress !== null
&& $this->startAddress <= $subjectStartAddress
&& $endAddress >= $subjectEndAddress
;
return $this->addressRange instanceof AddressRange && $this->addressRange->contains($range);
}
public function intersectsWith(MemorySegmentSection $other): bool
{
$endAddress = !is_null($this->startAddress) && !is_null($this->size)
? ($this->startAddress + $this->size - 1) : null;
$otherEndAddress = !is_null($other->startAddress) && !is_null($other->size)
? ($other->startAddress + $other->size - 1) : null;
return
$this->startAddress !== null
&& $endAddress !== null
&& $other->startAddress !== null
&& $otherEndAddress !== null
&& (
($other->startAddress <= $this->startAddress && $otherEndAddress >= $this->startAddress)
|| ($other->startAddress >= $this->startAddress && $other->startAddress <= $endAddress)
)
$this->addressRange instanceof AddressRange
&& $other->addressRange instanceof AddressRange
&& $this->addressRange->intersectsWith($other->addressRange)
;
}
}

View File

@@ -5,6 +5,7 @@ enum MemorySegmentType: string
{
case ALIASED = 'aliased';
case GENERAL_PURPOSE_REGISTERS = 'gp_registers';
case REGISTERS = 'registers';
case EEPROM = 'eeprom';
case FLASH = 'flash';
case FUSES = 'fuses';

View File

@@ -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,
[],

View File

@@ -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 = [];

View File

@@ -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);
}
}

View File

@@ -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));