AdaCore / svd2ada

An Ada binding generator from SVD descriptions for bare board ARM devices.
GNU General Public License v3.0
64 stars 36 forks source link

`range check failed` because type `Natural` is used for address values #99

Open luzidchris opened 1 year ago

luzidchris commented 1 year ago

Some of the SVD files in CMSIS_SVD lead to CONSTRAINT_ERROR exceptions because type Natural is too small to store address values. This can be reproduced for example with M1AGL.svd.

The following error is raised by svd2ada:

raised CONSTRAINT_ERROR : base_types.adb:218 range check failed

In my system (linux 64-bit), type Natural has a max value of 2147483647, i.e. 0x7FFFFFFF. As a result of this, svd2ada fails to process address or size values which are greater than this upper limit.

Fabien-Chouteau commented 1 year ago

Thanks @luzidchris, do you know if SVD defines limits for the types of those values?

luzidchris commented 1 year ago

Hi,

I've unfortunately not found any constraints. I assume this is not defined by SVD format because memory mapping is pretty target-specific.

In my case, the Constraint_Error was raised while calculating an absolute address and therefore my initial idea was to align data types to Unsigned (defined by Base_Types if I remember correctly). The type is already used for some of the address-related calculations, it's in svd2ada. And it should ensure that calculations work for all (or at least 99,9999 %) of the existing target architectures (incl. 64-bit).

Fabien-Chouteau commented 1 year ago

Maybe we should switch to the Ada2022 Big_Numbers for those values.