Added address space unit size to MemorySegment and MemorySegmentSection
Some recfactoring
This commit is contained in:
@@ -72,21 +72,21 @@ class Avr8TargetDescriptionFile extends TargetDescriptionFile
|
|||||||
|
|
||||||
$programMemorySegment = $this->getProgramMemorySegment();
|
$programMemorySegment = $this->getProgramMemorySegment();
|
||||||
if ($programMemorySegment instanceof MemorySegment) {
|
if ($programMemorySegment instanceof MemorySegment) {
|
||||||
$output->flashStartAddress = $programMemorySegment->startAddress;
|
$output->flashStartAddress = $programMemorySegment->addressRange->startAddress;
|
||||||
$output->flashSize = $programMemorySegment->size;
|
$output->flashSize = $programMemorySegment->size();
|
||||||
$output->flashPageSize = $programMemorySegment->pageSize;
|
$output->flashPageSize = $programMemorySegment->pageSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
$ramMemorySegment = $this->getRamSegment();
|
$ramMemorySegment = $this->getRamSegment();
|
||||||
if ($ramMemorySegment instanceof MemorySegment) {
|
if ($ramMemorySegment instanceof MemorySegment) {
|
||||||
$output->ramStartAddress = $ramMemorySegment->startAddress;
|
$output->ramStartAddress = $ramMemorySegment->addressRange->startAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
$output->bootSectionOptions = $this->getBootSectionOptions();
|
$output->bootSectionOptions = $this->getBootSectionOptions();
|
||||||
|
|
||||||
$eepromMemorySegment = $this->getEepromSegment();
|
$eepromMemorySegment = $this->getEepromSegment();
|
||||||
if ($eepromMemorySegment instanceof MemorySegment) {
|
if ($eepromMemorySegment instanceof MemorySegment) {
|
||||||
$output->eepromSize = $eepromMemorySegment->size;
|
$output->eepromSize = $eepromMemorySegment->size();
|
||||||
$output->eepromPageSize = $eepromMemorySegment->pageSize;
|
$output->eepromPageSize = $eepromMemorySegment->pageSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,21 +218,21 @@ class Avr8TargetDescriptionFile extends TargetDescriptionFile
|
|||||||
|
|
||||||
$programMemorySegment = $this->getProgramMemorySegment();
|
$programMemorySegment = $this->getProgramMemorySegment();
|
||||||
if ($programMemorySegment instanceof MemorySegment) {
|
if ($programMemorySegment instanceof MemorySegment) {
|
||||||
$output->flashStartAddress = $programMemorySegment->startAddress;
|
$output->flashStartAddress = $programMemorySegment->addressRange->startAddress;
|
||||||
$output->flashSize = $programMemorySegment->size;
|
$output->flashSize = $programMemorySegment->size();
|
||||||
$output->flashPageSize = $programMemorySegment->pageSize;
|
$output->flashPageSize = $programMemorySegment->pageSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
$ramMemorySegment = $this->getRamSegment();
|
$ramMemorySegment = $this->getRamSegment();
|
||||||
if ($ramMemorySegment instanceof MemorySegment) {
|
if ($ramMemorySegment instanceof MemorySegment) {
|
||||||
$output->ramStartAddress = $ramMemorySegment->startAddress;
|
$output->ramStartAddress = $ramMemorySegment->addressRange->startAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
$output->bootSectionOptions = $this->getBootSectionOptions();
|
$output->bootSectionOptions = $this->getBootSectionOptions();
|
||||||
|
|
||||||
$eepromMemorySegment = $this->getEepromSegment();
|
$eepromMemorySegment = $this->getEepromSegment();
|
||||||
if ($eepromMemorySegment instanceof MemorySegment) {
|
if ($eepromMemorySegment instanceof MemorySegment) {
|
||||||
$output->eepromSize = $eepromMemorySegment->size;
|
$output->eepromSize = $eepromMemorySegment->size();
|
||||||
$output->eepromPageSize = $eepromMemorySegment->pageSize;
|
$output->eepromPageSize = $eepromMemorySegment->pageSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -344,18 +344,18 @@ class Avr8TargetDescriptionFile extends TargetDescriptionFile
|
|||||||
|
|
||||||
$appSection = $programMemorySegment->getSection('app_section');
|
$appSection = $programMemorySegment->getSection('app_section');
|
||||||
if ($appSection instanceof MemorySegmentSection) {
|
if ($appSection instanceof MemorySegmentSection) {
|
||||||
$output->appSectionSize = $appSection->size;
|
$output->appSectionSize = $appSection->size();
|
||||||
}
|
}
|
||||||
|
|
||||||
$bootSection = $programMemorySegment->getSection('boot_section');
|
$bootSection = $programMemorySegment->getSection('boot_section');
|
||||||
if ($bootSection instanceof MemorySegmentSection) {
|
if ($bootSection instanceof MemorySegmentSection) {
|
||||||
$output->bootSectionSize = $bootSection->size;
|
$output->bootSectionSize = $bootSection->size();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$eepromMemorySegment = $this->getEepromSegment();
|
$eepromMemorySegment = $this->getEepromSegment();
|
||||||
if ($eepromMemorySegment instanceof MemorySegment) {
|
if ($eepromMemorySegment instanceof MemorySegment) {
|
||||||
$output->eepromSize = $eepromMemorySegment->size;
|
$output->eepromSize = $eepromMemorySegment->size();
|
||||||
$output->eepromPageSize = $eepromMemorySegment->pageSize;
|
$output->eepromPageSize = $eepromMemorySegment->pageSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -381,14 +381,14 @@ class Avr8TargetDescriptionFile extends TargetDescriptionFile
|
|||||||
|
|
||||||
$programMemorySegment = $this->getProgramMemorySegment();
|
$programMemorySegment = $this->getProgramMemorySegment();
|
||||||
if ($programMemorySegment instanceof MemorySegment) {
|
if ($programMemorySegment instanceof MemorySegment) {
|
||||||
$output->flashSize = $programMemorySegment->size;
|
$output->flashSize = $programMemorySegment->size();
|
||||||
$output->flashPageSize = $programMemorySegment->pageSize;
|
$output->flashPageSize = $programMemorySegment->pageSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
$eepromMemorySegment = $this->getEepromSegment();
|
$eepromMemorySegment = $this->getEepromSegment();
|
||||||
if ($eepromMemorySegment instanceof MemorySegment) {
|
if ($eepromMemorySegment instanceof MemorySegment) {
|
||||||
$output->eepromStartAddress = $eepromMemorySegment->startAddress;
|
$output->eepromStartAddress = $eepromMemorySegment->addressRange->startAddress;
|
||||||
$output->eepromSize = $eepromMemorySegment->size;
|
$output->eepromSize = $eepromMemorySegment->size();
|
||||||
$output->eepromPageSize = $eepromMemorySegment->pageSize;
|
$output->eepromPageSize = $eepromMemorySegment->pageSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -410,7 +410,7 @@ class Avr8TargetDescriptionFile extends TargetDescriptionFile
|
|||||||
);
|
);
|
||||||
|
|
||||||
if ($signatureMemorySegment instanceof MemorySegment) {
|
if ($signatureMemorySegment instanceof MemorySegment) {
|
||||||
$output->signatureSegmentStartAddress = $signatureMemorySegment->startAddress;
|
$output->signatureSegmentStartAddress = $signatureMemorySegment->addressRange->startAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
$fuseMemorySegment = $this->getMemorySegment(
|
$fuseMemorySegment = $this->getMemorySegment(
|
||||||
@@ -422,8 +422,8 @@ class Avr8TargetDescriptionFile extends TargetDescriptionFile
|
|||||||
);
|
);
|
||||||
|
|
||||||
if ($fuseMemorySegment instanceof MemorySegment) {
|
if ($fuseMemorySegment instanceof MemorySegment) {
|
||||||
$output->fuseSegmentSize = $fuseMemorySegment->size;
|
$output->fuseSegmentSize = $fuseMemorySegment->size();
|
||||||
$output->fuseSegmentStartAddress = $fuseMemorySegment->startAddress;
|
$output->fuseSegmentStartAddress = $fuseMemorySegment->addressRange->startAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
$lockbitsMemorySegment = $this->getMemorySegment(
|
$lockbitsMemorySegment = $this->getMemorySegment(
|
||||||
@@ -435,7 +435,7 @@ class Avr8TargetDescriptionFile extends TargetDescriptionFile
|
|||||||
);
|
);
|
||||||
|
|
||||||
if ($lockbitsMemorySegment instanceof MemorySegment) {
|
if ($lockbitsMemorySegment instanceof MemorySegment) {
|
||||||
$output->lockbitsSegmentStartAddress = $lockbitsMemorySegment->startAddress;
|
$output->lockbitsSegmentStartAddress = $lockbitsMemorySegment->addressRange->startAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $output;
|
return $output;
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ class ValidationService extends \Targets\TargetDescriptionFiles\Services\Validat
|
|||||||
if ($progAddressSpace === null) {
|
if ($progAddressSpace === null) {
|
||||||
$failures[] = 'Missing program memory address space';
|
$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
|
* 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.
|
* 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';
|
$failures[] = 'Missing "internal_ram" memory segment';
|
||||||
|
|
||||||
} else {
|
} 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.
|
* 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
|
* 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.
|
* 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';
|
$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';
|
$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.
|
* we assume that the offset has already been applied to the params. We confirm this here.
|
||||||
*/
|
*/
|
||||||
if (($ioMemorySegment = $tdf->getIoMemorySegment()) instanceof MemorySegment) {
|
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';
|
$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';
|
$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';
|
$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';
|
$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';
|
$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.
|
* we assume that the offset has already been applied to the params. We confirm this here.
|
||||||
*/
|
*/
|
||||||
if (($ioMemorySegment = $tdf->getIoMemorySegment()) instanceof MemorySegment) {
|
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';
|
$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';
|
$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';
|
$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';
|
$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';
|
$failures[] = 'EEDR address does not have IO memory segment offset applied';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,13 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Targets\TargetDescriptionFiles;
|
namespace Targets\TargetDescriptionFiles;
|
||||||
|
|
||||||
|
require_once __DIR__ . "/AddressRange.php";
|
||||||
require_once __DIR__ . "/MemorySegment.php";
|
require_once __DIR__ . "/MemorySegment.php";
|
||||||
|
|
||||||
class AddressSpace
|
class AddressSpace
|
||||||
{
|
{
|
||||||
public ?string $key = null;
|
public ?string $key = null;
|
||||||
public ?int $startAddress = null;
|
public ?AddressRange $addressRange = null;
|
||||||
public ?int $size = null;
|
|
||||||
public ?int $unitSize = null;
|
public ?int $unitSize = null;
|
||||||
public ?string $endianness = null;
|
public ?string $endianness = null;
|
||||||
|
|
||||||
@@ -17,12 +17,23 @@ class AddressSpace
|
|||||||
public function __construct(?string $key, ?int $startAddress, ?int $size, ?int $unitSize, ?string $endianness)
|
public function __construct(?string $key, ?int $startAddress, ?int $size, ?int $unitSize, ?string $endianness)
|
||||||
{
|
{
|
||||||
$this->key = $key;
|
$this->key = $key;
|
||||||
$this->startAddress = $startAddress;
|
$this->addressRange = is_numeric($startAddress) && is_numeric($size)
|
||||||
$this->size = $size;
|
? new AddressRange(
|
||||||
|
$startAddress,
|
||||||
|
$startAddress + ($size / ($unitSize ?? 1)) - 1
|
||||||
|
)
|
||||||
|
: null;
|
||||||
$this->unitSize = $unitSize;
|
$this->unitSize = $unitSize;
|
||||||
$this->endianness = $endianness;
|
$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
|
public function getMemorySegment(string $key): ?MemorySegment
|
||||||
{
|
{
|
||||||
foreach ($this->memorySegments as $segment) {
|
foreach ($this->memorySegments as $segment) {
|
||||||
@@ -38,27 +49,7 @@ class AddressSpace
|
|||||||
{
|
{
|
||||||
return array_sum(
|
return array_sum(
|
||||||
array_map(
|
array_map(
|
||||||
fn (MemorySegment $segment): int => (int) $segment->size,
|
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,
|
|
||||||
$this->memorySegments
|
$this->memorySegments
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@@ -77,9 +68,9 @@ class AddressSpace
|
|||||||
return array_filter(
|
return array_filter(
|
||||||
$this->memorySegments,
|
$this->memorySegments,
|
||||||
function (MemorySegment $segment) use ($startAddress, $endAddress) : bool {
|
function (MemorySegment $segment) use ($startAddress, $endAddress) : bool {
|
||||||
$segmentEndAddress = $segment->startAddress + $segment->size - 1;
|
$segmentEndAddress = $segment->addressRange->startAddress + $segment->size() - 1;
|
||||||
return ($startAddress <= $segment->startAddress && $endAddress >= $segment->startAddress)
|
return ($startAddress <= $segment->addressRange->startAddress && $endAddress >= $segment->addressRange->startAddress)
|
||||||
|| ($startAddress >= $segment->startAddress && $startAddress <= $segmentEndAddress);
|
|| ($startAddress >= $segment->addressRange->startAddress && $startAddress <= $segmentEndAddress);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Targets\TargetDescriptionFiles;
|
namespace Targets\TargetDescriptionFiles;
|
||||||
|
|
||||||
|
require_once __DIR__ . "/AddressRange.php";
|
||||||
require_once __DIR__ . "/MemorySegmentType.php";
|
require_once __DIR__ . "/MemorySegmentType.php";
|
||||||
require_once __DIR__ . "/MemorySegmentSection.php";
|
require_once __DIR__ . "/MemorySegmentSection.php";
|
||||||
|
|
||||||
@@ -9,8 +10,8 @@ class MemorySegment
|
|||||||
public ?string $key = null;
|
public ?string $key = null;
|
||||||
public ?string $name = null;
|
public ?string $name = null;
|
||||||
public ?MemorySegmentType $type = null;
|
public ?MemorySegmentType $type = null;
|
||||||
public ?int $startAddress = null;
|
public ?AddressRange $addressRange = null;
|
||||||
public ?int $size = null;
|
public ?int $addressSpaceUnitSize = null;
|
||||||
public ?int $pageSize = null;
|
public ?int $pageSize = null;
|
||||||
public ?string $access = null;
|
public ?string $access = null;
|
||||||
public ?bool $executable = null;
|
public ?bool $executable = null;
|
||||||
@@ -24,6 +25,7 @@ class MemorySegment
|
|||||||
?MemorySegmentType $type,
|
?MemorySegmentType $type,
|
||||||
?int $startAddress,
|
?int $startAddress,
|
||||||
?int $size,
|
?int $size,
|
||||||
|
?int $addressSpaceUnitSize,
|
||||||
?int $pageSize,
|
?int $pageSize,
|
||||||
?string $access,
|
?string $access,
|
||||||
array $sections,
|
array $sections,
|
||||||
@@ -32,14 +34,26 @@ class MemorySegment
|
|||||||
$this->key = $key;
|
$this->key = $key;
|
||||||
$this->name = $name;
|
$this->name = $name;
|
||||||
$this->type = $type;
|
$this->type = $type;
|
||||||
$this->startAddress = $startAddress;
|
$this->addressRange = is_numeric($startAddress) && is_numeric($size)
|
||||||
$this->size = $size;
|
? new AddressRange(
|
||||||
|
$startAddress,
|
||||||
|
$startAddress + ($size / ($addressSpaceUnitSize ?? 1)) - 1
|
||||||
|
)
|
||||||
|
: null;
|
||||||
|
$this->addressSpaceUnitSize = $addressSpaceUnitSize;
|
||||||
$this->pageSize = $pageSize;
|
$this->pageSize = $pageSize;
|
||||||
$this->access = $access;
|
$this->access = $access;
|
||||||
$this->sections = $sections;
|
$this->sections = $sections;
|
||||||
$this->executable = $executable;
|
$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
|
public function getSection(string $sectionId): ?MemorySegmentSection
|
||||||
{
|
{
|
||||||
foreach ($this->sections as $section) {
|
foreach ($this->sections as $section) {
|
||||||
@@ -53,11 +67,11 @@ class MemorySegment
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getInnermostSectionContainingAddressRange(int $startAddress, int $endAddress)
|
public function getInnermostSectionContainingAddressRange(AddressRange $range)
|
||||||
: ?MemorySegmentSection {
|
: ?MemorySegmentSection {
|
||||||
foreach ($this->sections as $section) {
|
foreach ($this->sections as $section) {
|
||||||
if ($section->containsAddressRange($startAddress, $endAddress)) {
|
if ($section->containsAddressRange($range)) {
|
||||||
return $section->getInnermostSubSectionContainingAddressRange($startAddress, $endAddress);
|
return $section->getInnermostSubSectionContainingAddressRange($range);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,34 +80,15 @@ class MemorySegment
|
|||||||
|
|
||||||
public function contains(MemorySegment $other): bool
|
public function contains(MemorySegment $other): bool
|
||||||
{
|
{
|
||||||
$endAddress = !is_null($this->startAddress) && !is_null($this->size)
|
return $this->addressRange instanceof AddressRange && $this->addressRange->contains($other->addressRange);
|
||||||
? ($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
|
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function intersectsWith(MemorySegment $other): bool
|
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
|
return
|
||||||
$this->startAddress !== null
|
$this->addressRange instanceof AddressRange
|
||||||
&& $endAddress !== null
|
&& $other->addressRange instanceof AddressRange
|
||||||
&& $other->startAddress !== null
|
&& $this->addressRange->intersectsWith($other->addressRange)
|
||||||
&& $otherEndAddress !== null
|
|
||||||
&& $this->startAddress <= $otherEndAddress && $other->startAddress <= $endAddress
|
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,7 +96,7 @@ class MemorySegment
|
|||||||
{
|
{
|
||||||
return array_sum(
|
return array_sum(
|
||||||
array_map(
|
array_map(
|
||||||
fn (MemorySegmentSection $section): int => (int) $section->size,
|
fn (MemorySegmentSection $section): int => (int) $section->size(),
|
||||||
$this->sections
|
$this->sections
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Targets\TargetDescriptionFiles;
|
namespace Targets\TargetDescriptionFiles;
|
||||||
|
|
||||||
|
require_once __DIR__ . "/AddressRange.php";
|
||||||
|
|
||||||
class MemorySegmentSection
|
class MemorySegmentSection
|
||||||
{
|
{
|
||||||
public ?string $key = null;
|
public ?string $key = null;
|
||||||
public ?string $name = null;
|
public ?string $name = null;
|
||||||
public ?int $startAddress = null;
|
public ?AddressRange $addressRange = null;
|
||||||
public ?int $size = null;
|
public ?int $addressSpaceUnitSize = null;
|
||||||
|
|
||||||
/** @var MemorySegmentSection[] */
|
/** @var MemorySegmentSection[] */
|
||||||
public array $subSections = [];
|
public array $subSections = [];
|
||||||
@@ -16,76 +18,59 @@ class MemorySegmentSection
|
|||||||
?string $name,
|
?string $name,
|
||||||
?int $startAddress,
|
?int $startAddress,
|
||||||
?int $size,
|
?int $size,
|
||||||
|
?int $addressSpaceUnitSize,
|
||||||
array $subSections
|
array $subSections
|
||||||
) {
|
) {
|
||||||
$this->key = $key;
|
$this->key = $key;
|
||||||
$this->name = $name;
|
$this->name = $name;
|
||||||
$this->startAddress = $startAddress;
|
$this->addressRange = is_numeric($startAddress) && is_numeric($size)
|
||||||
$this->size = $size;
|
? new AddressRange(
|
||||||
|
$startAddress,
|
||||||
|
$startAddress + ($size / ($addressSpaceUnitSize ?? 1)) - 1
|
||||||
|
)
|
||||||
|
: null;
|
||||||
|
$this->addressSpaceUnitSize = $addressSpaceUnitSize;
|
||||||
$this->subSections = $subSections;
|
$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 {
|
: ?MemorySegmentSection {
|
||||||
if ($this->containsAddressRange($startAddress, $endAddress)) {
|
if (!$this->containsAddressRange($range)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($this->subSections as $section) {
|
foreach ($this->subSections as $section) {
|
||||||
if ($section->containsAddressRange($startAddress, $endAddress)) {
|
if ($section->containsAddressRange($range)) {
|
||||||
return $section->getInnermostSubSectionContainingAddressRange($startAddress, $endAddress);
|
return $section->getInnermostSubSectionContainingAddressRange($range);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function contains(MemorySegment $other): bool
|
public function contains(MemorySegmentSection $other): bool
|
||||||
{
|
{
|
||||||
$endAddress = !is_null($this->startAddress) && !is_null($this->size)
|
return $this->addressRange instanceof AddressRange && $this->addressRange->contains($other->addressRange);
|
||||||
? ($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
|
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function containsAddressRange(int $subjectStartAddress, int $subjectEndAddress): bool
|
public function containsAddressRange(AddressRange $range): bool
|
||||||
{
|
{
|
||||||
$endAddress = !is_null($this->startAddress) && !is_null($this->size)
|
return $this->addressRange instanceof AddressRange && $this->addressRange->contains($range);
|
||||||
? ($this->startAddress + $this->size - 1) : null;
|
|
||||||
|
|
||||||
return
|
|
||||||
$this->startAddress !== null
|
|
||||||
&& $endAddress !== null
|
|
||||||
&& $this->startAddress <= $subjectStartAddress
|
|
||||||
&& $endAddress >= $subjectEndAddress
|
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function intersectsWith(MemorySegmentSection $other): bool
|
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
|
return
|
||||||
$this->startAddress !== null
|
$this->addressRange instanceof AddressRange
|
||||||
&& $endAddress !== null
|
&& $other->addressRange instanceof AddressRange
|
||||||
&& $other->startAddress !== null
|
&& $this->addressRange->intersectsWith($other->addressRange)
|
||||||
&& $otherEndAddress !== null
|
|
||||||
&& (
|
|
||||||
($other->startAddress <= $this->startAddress && $otherEndAddress >= $this->startAddress)
|
|
||||||
|| ($other->startAddress >= $this->startAddress && $other->startAddress <= $endAddress)
|
|
||||||
)
|
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ enum MemorySegmentType: string
|
|||||||
{
|
{
|
||||||
case ALIASED = 'aliased';
|
case ALIASED = 'aliased';
|
||||||
case GENERAL_PURPOSE_REGISTERS = 'gp_registers';
|
case GENERAL_PURPOSE_REGISTERS = 'gp_registers';
|
||||||
|
case REGISTERS = 'registers';
|
||||||
case EEPROM = 'eeprom';
|
case EEPROM = 'eeprom';
|
||||||
case FLASH = 'flash';
|
case FLASH = 'flash';
|
||||||
case FUSES = 'fuses';
|
case FUSES = 'fuses';
|
||||||
|
|||||||
@@ -397,13 +397,13 @@ class AtdfService
|
|||||||
new Property(
|
new Property(
|
||||||
'start_address',
|
'start_address',
|
||||||
'0x' . str_pad(
|
'0x' . str_pad(
|
||||||
strtoupper(dechex($segment->startAddress)),
|
strtoupper(dechex($segment->addressRange->startAddress)),
|
||||||
8,
|
8,
|
||||||
'0',
|
'0',
|
||||||
STR_PAD_LEFT
|
STR_PAD_LEFT
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
new Property('size', $segment->size),
|
new Property('size', $segment->size()),
|
||||||
new Property('page_size', $segment->pageSize),
|
new Property('page_size', $segment->pageSize),
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
@@ -491,8 +491,9 @@ class AtdfService
|
|||||||
$section = new MemorySegmentSection(
|
$section = new MemorySegmentSection(
|
||||||
$otherSegment->key,
|
$otherSegment->key,
|
||||||
$otherSegment->name,
|
$otherSegment->name,
|
||||||
$otherSegment->startAddress,
|
$otherSegment->addressRange->startAddress,
|
||||||
$otherSegment->size,
|
$otherSegment->size(),
|
||||||
|
null,
|
||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -501,11 +502,9 @@ class AtdfService
|
|||||||
* the segment.
|
* the segment.
|
||||||
*/
|
*/
|
||||||
if (
|
if (
|
||||||
$otherSegment->startAddress !== null
|
$otherSegment->addressRange !== null
|
||||||
&& $otherSegment->size !== null
|
|
||||||
&& ($parentSection = $segment->getInnermostSectionContainingAddressRange(
|
&& ($parentSection = $segment->getInnermostSectionContainingAddressRange(
|
||||||
$otherSegment->startAddress,
|
$otherSegment->addressRange
|
||||||
($otherSegment->startAddress + $otherSegment->size - 1)
|
|
||||||
)) !== null
|
)) !== null
|
||||||
) {
|
) {
|
||||||
$parentSection->subSections[] = $section;
|
$parentSection->subSections[] = $section;
|
||||||
@@ -542,22 +541,25 @@ class AtdfService
|
|||||||
'internal_program_memory',
|
'internal_program_memory',
|
||||||
'Internal FLASH',
|
'Internal FLASH',
|
||||||
MemorySegmentType::FLASH,
|
MemorySegmentType::FLASH,
|
||||||
$appSectionSegment->startAddress,
|
$appSectionSegment->addressRange->startAddress,
|
||||||
$appSectionSegment->size + $bootSectionSegment->size,
|
$appSectionSegment->size() + $bootSectionSegment->size(),
|
||||||
|
null,
|
||||||
$appSectionSegment->pageSize,
|
$appSectionSegment->pageSize,
|
||||||
$appSectionSegment->access,
|
$appSectionSegment->access,
|
||||||
[
|
[
|
||||||
new MemorySegmentSection(
|
new MemorySegmentSection(
|
||||||
'app_section',
|
'app_section',
|
||||||
'Application Section',
|
'Application Section',
|
||||||
$appSectionSegment->startAddress,
|
$appSectionSegment->addressRange->startAddress,
|
||||||
$appSectionSegment->size,
|
$appSectionSegment->size(),
|
||||||
|
null,
|
||||||
[
|
[
|
||||||
new MemorySegmentSection(
|
new MemorySegmentSection(
|
||||||
'app_table_section',
|
'app_table_section',
|
||||||
'Application Table Section',
|
'Application Table Section',
|
||||||
$appTableSection->startAddress,
|
$appTableSection->addressRange->startAddress,
|
||||||
$appTableSection->size,
|
$appTableSection->size(),
|
||||||
|
null,
|
||||||
[]
|
[]
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
@@ -565,8 +567,9 @@ class AtdfService
|
|||||||
new MemorySegmentSection(
|
new MemorySegmentSection(
|
||||||
'boot_section',
|
'boot_section',
|
||||||
'Boot Loader Section',
|
'Boot Loader Section',
|
||||||
$bootSectionSegment->startAddress,
|
$bootSectionSegment->addressRange->startAddress,
|
||||||
$bootSectionSegment->size,
|
$bootSectionSegment->size(),
|
||||||
|
null,
|
||||||
[]
|
[]
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
@@ -591,6 +594,7 @@ class AtdfService
|
|||||||
),
|
),
|
||||||
$this->stringService->tryStringToInt($attributes['start'] ?? null),
|
$this->stringService->tryStringToInt($attributes['start'] ?? null),
|
||||||
$this->stringService->tryStringToInt($attributes['size'] ?? null),
|
$this->stringService->tryStringToInt($attributes['size'] ?? null),
|
||||||
|
null,
|
||||||
$this->stringService->tryStringToInt($attributes['pagesize'] ?? null),
|
$this->stringService->tryStringToInt($attributes['pagesize'] ?? null),
|
||||||
$attributes['rw'] ?? null,
|
$attributes['rw'] ?? null,
|
||||||
[],
|
[],
|
||||||
|
|||||||
@@ -266,21 +266,21 @@ class ValidationService
|
|||||||
$failures = array_merge($failures, $this->validateKey($addressSpace->key));
|
$failures = array_merge($failures, $this->validateKey($addressSpace->key));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($addressSpace->startAddress === null) {
|
if ($addressSpace->addressRange === null) {
|
||||||
$failures[] = 'Missing start address';
|
$failures[] = 'Missing address range';
|
||||||
|
|
||||||
} elseif ($addressSpace->startAddress > 0xFFFFFFFF) {
|
} elseif ($addressSpace->addressRange->startAddress > 0xFFFFFFFF) {
|
||||||
$failures[] = 'Start address exceeds 32-bit unsigned integer';
|
$failures[] = 'Start address exceeds 32-bit unsigned integer';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($addressSpace->size === null) {
|
if ($addressSpace->size() === null) {
|
||||||
$failures[] = 'Missing size';
|
$failures[] = 'Missing size';
|
||||||
|
|
||||||
} elseif ($addressSpace->size > 0xFFFFFFFF) {
|
} elseif ($addressSpace->size() > 0xFFFFFFFF) {
|
||||||
$failures[] = 'Size exceeds 32-bit unsigned integer';
|
$failures[] = 'Size exceeds 32-bit unsigned integer';
|
||||||
|
|
||||||
} elseif ($addressSpace->size < 1) {
|
} elseif ($addressSpace->size() < 1) {
|
||||||
$failures[] = 'Invalid size (' . $addressSpace->size . ')';
|
$failures[] = 'Invalid size (' . $addressSpace->size() . ')';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($addressSpace->memorySegments)) {
|
if (empty($addressSpace->memorySegments)) {
|
||||||
@@ -309,9 +309,9 @@ class ValidationService
|
|||||||
}
|
}
|
||||||
|
|
||||||
$totalSegmentSize = $addressSpace->totalSegmentSize();
|
$totalSegmentSize = $addressSpace->totalSegmentSize();
|
||||||
if ($totalSegmentSize > $addressSpace->size) {
|
if ($totalSegmentSize > $addressSpace->size()) {
|
||||||
$failures[] = 'Total size of all contained segments (' . $totalSegmentSize . ' bytes) exceeds the total'
|
$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(
|
return array_map(
|
||||||
@@ -340,21 +340,21 @@ class ValidationService
|
|||||||
$failures[] = 'Missing/invalid type';
|
$failures[] = 'Missing/invalid type';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($segment->startAddress === null) {
|
if ($segment->addressRange === null) {
|
||||||
$failures[] = 'Missing start address';
|
$failures[] = 'Missing address range';
|
||||||
|
|
||||||
} elseif ($segment->startAddress > 0xFFFFFFFF) {
|
} elseif ($segment->addressRange->startAddress > 0xFFFFFFFF) {
|
||||||
$failures[] = 'Start address exceeds 32-bit unsigned integer';
|
$failures[] = 'Start address exceeds 32-bit unsigned integer';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($segment->size === null) {
|
if ($segment->size() === null) {
|
||||||
$failures[] = 'Missing size';
|
$failures[] = 'Missing size';
|
||||||
|
|
||||||
} elseif ($segment->size > 0xFFFFFFFF) {
|
} elseif ($segment->size() > 0xFFFFFFFF) {
|
||||||
$failures[] = 'Size exceeds 32-bit unsigned integer';
|
$failures[] = 'Size exceeds 32-bit unsigned integer';
|
||||||
|
|
||||||
} elseif ($segment->size < 1) {
|
} elseif ($segment->size() < 1) {
|
||||||
$failures[] = 'Invalid size (' . $segment->size . ')';
|
$failures[] = 'Invalid size (' . $segment->size() . ')';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($segment->executable === null) {
|
if ($segment->executable === null) {
|
||||||
@@ -383,9 +383,9 @@ class ValidationService
|
|||||||
}
|
}
|
||||||
|
|
||||||
$totalSectionSize = $segment->totalSectionSize();
|
$totalSectionSize = $segment->totalSectionSize();
|
||||||
if ($totalSectionSize > $segment->size) {
|
if ($totalSectionSize > $segment->size()) {
|
||||||
$failures[] = 'Total size of all contained sections (' . $totalSectionSize . ' bytes) exceeds the total'
|
$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(
|
return array_map(
|
||||||
@@ -410,15 +410,15 @@ class ValidationService
|
|||||||
$failures[] = 'Missing name';
|
$failures[] = 'Missing name';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($section->startAddress === null) {
|
if ($section->addressRange === null) {
|
||||||
$failures[] = 'Missing start address';
|
$failures[] = 'Missing address range';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($section->size === null) {
|
if ($section->size() === null) {
|
||||||
$failures[] = 'Missing size';
|
$failures[] = 'Missing size';
|
||||||
|
|
||||||
} elseif ($section->size < 1) {
|
} elseif ($section->size() < 1) {
|
||||||
$failures[] = 'Invalid size (' . $section->size . ')';
|
$failures[] = 'Invalid size (' . $section->size() . ')';
|
||||||
}
|
}
|
||||||
|
|
||||||
$processedSectionKeys = [];
|
$processedSectionKeys = [];
|
||||||
|
|||||||
@@ -127,14 +127,14 @@ class FromXmlService
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($childNode->nodeName === 'memory-segment') {
|
if ($childNode->nodeName === 'memory-segment') {
|
||||||
$output->memorySegments[] = $this->memorySegmentFromElement($childNode);
|
$output->memorySegments[] = $this->memorySegmentFromElement($childNode, $output->unitSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function memorySegmentFromElement(DOMElement $element): MemorySegment
|
public function memorySegmentFromElement(DOMElement $element, ?int $addressSpaceUnitSize): MemorySegment
|
||||||
{
|
{
|
||||||
$attributes = $this->getNodeAttributesByName($element);
|
$attributes = $this->getNodeAttributesByName($element);
|
||||||
|
|
||||||
@@ -144,6 +144,7 @@ class FromXmlService
|
|||||||
MemorySegmentType::tryFrom($attributes['type'] ?? null),
|
MemorySegmentType::tryFrom($attributes['type'] ?? null),
|
||||||
$this->stringService->tryStringToInt($attributes['start'] ?? null),
|
$this->stringService->tryStringToInt($attributes['start'] ?? null),
|
||||||
$this->stringService->tryStringToInt($attributes['size'] ?? null),
|
$this->stringService->tryStringToInt($attributes['size'] ?? null),
|
||||||
|
$addressSpaceUnitSize,
|
||||||
$this->stringService->tryStringToInt($attributes['page-size'] ?? null),
|
$this->stringService->tryStringToInt($attributes['page-size'] ?? null),
|
||||||
$attributes['access'] ?? null,
|
$attributes['access'] ?? null,
|
||||||
[],
|
[],
|
||||||
@@ -156,14 +157,14 @@ class FromXmlService
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($childNode->nodeName === 'section') {
|
if ($childNode->nodeName === 'section') {
|
||||||
$output->sections[] = $this->memorySegmentSectionFromElement($childNode);
|
$output->sections[] = $this->memorySegmentSectionFromElement($childNode, $addressSpaceUnitSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function memorySegmentSectionFromElement(DOMElement $element): MemorySegmentSection
|
public function memorySegmentSectionFromElement(DOMElement $element, ?int $addressSpaceUnitSize): MemorySegmentSection
|
||||||
{
|
{
|
||||||
$attributes = $this->getNodeAttributesByName($element);
|
$attributes = $this->getNodeAttributesByName($element);
|
||||||
|
|
||||||
@@ -172,6 +173,7 @@ class FromXmlService
|
|||||||
$attributes['name'] ?? null,
|
$attributes['name'] ?? null,
|
||||||
$this->stringService->tryStringToInt($attributes['start'] ?? null),
|
$this->stringService->tryStringToInt($attributes['start'] ?? null),
|
||||||
$this->stringService->tryStringToInt($attributes['size'] ?? null),
|
$this->stringService->tryStringToInt($attributes['size'] ?? null),
|
||||||
|
$addressSpaceUnitSize,
|
||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -181,7 +183,7 @@ class FromXmlService
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($childNode->nodeName === 'section') {
|
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 = $document->createElement('address-space');
|
||||||
$element->setAttribute('key', strtolower($addressSpace->key));
|
$element->setAttribute('key', strtolower($addressSpace->key));
|
||||||
$element->setAttribute('start', $this->stringService->tryIntToHex($addressSpace->startAddress, 8));
|
$element->setAttribute(
|
||||||
$element->setAttribute('size', $addressSpace->size);
|
'start',
|
||||||
|
$this->stringService->tryIntToHex($addressSpace->addressRange->startAddress, 8)
|
||||||
|
);
|
||||||
|
$element->setAttribute('size', $addressSpace->size());
|
||||||
|
|
||||||
if (!empty($addressSpace->unitSize)) {
|
if (!empty($addressSpace->unitSize)) {
|
||||||
$element->setAttribute('unit-size', $addressSpace->unitSize);
|
$element->setAttribute('unit-size', $addressSpace->unitSize);
|
||||||
@@ -92,8 +95,11 @@ class ToXmlService
|
|||||||
$element->setAttribute('key', strtolower($memorySegment->key));
|
$element->setAttribute('key', strtolower($memorySegment->key));
|
||||||
$element->setAttribute('name', $memorySegment->name);
|
$element->setAttribute('name', $memorySegment->name);
|
||||||
$element->setAttribute('type', $memorySegment->type->value ?? '');
|
$element->setAttribute('type', $memorySegment->type->value ?? '');
|
||||||
$element->setAttribute('start', $this->stringService->tryIntToHex($memorySegment->startAddress, 8));
|
$element->setAttribute(
|
||||||
$element->setAttribute('size', $memorySegment->size);
|
'start',
|
||||||
|
$this->stringService->tryIntToHex($memorySegment->addressRange->startAddress, 8)
|
||||||
|
);
|
||||||
|
$element->setAttribute('size', $memorySegment->size());
|
||||||
|
|
||||||
if (!empty($memorySegment->pageSize)) {
|
if (!empty($memorySegment->pageSize)) {
|
||||||
$element->setAttribute('page-size', $memorySegment->pageSize);
|
$element->setAttribute('page-size', $memorySegment->pageSize);
|
||||||
@@ -117,8 +123,8 @@ class ToXmlService
|
|||||||
$element = $document->createElement('section');
|
$element = $document->createElement('section');
|
||||||
$element->setAttribute('key', strtolower($section->key));
|
$element->setAttribute('key', strtolower($section->key));
|
||||||
$element->setAttribute('name', $section->name);
|
$element->setAttribute('name', $section->name);
|
||||||
$element->setAttribute('start', $this->stringService->tryIntToHex($section->startAddress, 8));
|
$element->setAttribute('start', $this->stringService->tryIntToHex($section->addressRange->startAddress, 8));
|
||||||
$element->setAttribute('size', $section->size);
|
$element->setAttribute('size', $section->size());
|
||||||
|
|
||||||
foreach ($section->subSections as $section) {
|
foreach ($section->subSections as $section) {
|
||||||
$element->append($this->memorySegmentSectionToXml($section, $document));
|
$element->append($this->memorySegmentSectionToXml($section, $document));
|
||||||
|
|||||||
Reference in New Issue
Block a user