[Cryptech Tech] Keeping magic numbers in sync between Verilog and C

Joachim Strömbergson joachim at secworks.se
Thu Oct 1 09:35:22 UTC 2015


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Aloha!

Pavel Shatov wrote:
> I see, that right now every core has a wrapper, and this wrapper 
> contains an array of localparams. Many of these localparams are
> repeated in different cores, since we decided, that similar cores
> should have similar address space layout. I think, an elegant
> solution will be to move all magic localparams into a separate .v
> file. This file will contain only localparams, and every core will
> then `include this .v file and get access to magic constants.

Having constants/params in separate definition files is the right way to
go about it. But if we move all magic localparams we will have to start
prefixing parameters (AES_FOO). It will also be cumbersome to maintain a
single file. So we want to collect the common defines - typically addresses.

Each core could then have its own module specific header and include the
common cryptech.vh with appropriate include guard. In this way, the
updates to the common file is minimized. Prefixing will be needed anyway
if we are collecting definitions in some way into a common c header.

Rob, do you see it as a hard problem to grep out and consume miltiple
header files - i.e. is a single common file crucial?


> Converting .v file with localparams into .h file with #defines in 
> another question. I faced the same problem several times in previous 
> projects, but I still don't have any good enough solution. The first 
> annoying thing is that numbers in Verilog are like 16'hABCD and like 
> 0xABCD in C.

It is usually quite easy to do in Python as long as its just a question
of parameters with symbolic names modulo one or a few levels of
indirection. I've written such scripts several times and can probably
dig one up.

- -- 
Med vänlig hälsning, Yours

Joachim Strömbergson - Alltid i harmonisk svängning.
========================================================================
 Joachim Strömbergson          Secworks AB          joachim at secworks.se
========================================================================
-----BEGIN PGP SIGNATURE-----
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQIcBAEBCAAGBQJWDP5aAAoJEF3cfFQkIuyNuIMQANbRi5kvLtBIV18PauphG7ox
mxFCeZUqRYe9ABwsnt4Qbnc/+xmLOY7nTdKeI1H2JeTGFFUi7oT96LYezCAixfWw
r7aImfrtnL679IvsBAS0f+hyiksrszd4cnO9vPPz3irXgsCkL7PU/sgHipv4Dzer
Oj7JOPW/iQcgExxN3F3v8Q0Bt05QcJ+6JRtQJsMqRE5J5HqZMvaHpXZkX2Sml+vR
5AO9CQh5C0PQHPleBzuPt6lW2vxT0CG/6kXcSayTeBI1mnZB6HWcSDdud3M6d6+C
EjLkvUxaUsxdfIF6lOzi+eRuw9JcigFayIqMqDz6ChRO6nKL5BN2mixfXVBZwncb
MwNlelmAxKIDXabLfBuAP4X+356AjmfGuYBXSH/9OARWUeOLpmKnpAedPaulh6Cp
tCAdqyk1bo3MwBJgcEztBPC+Kak4VP9JW2HvgNRhYgFDRO7srb12ZXgsY4FFazPP
/ro+d9l5y0YvuwsirdX0ne4fbkhhhtCSpEBs/mSWL6U/35LhbQsvw0AMyAmdy3hC
+4Zrqg0aRXJZaaC6NPv1iWtmNvv2bvLCq+8G3td/I5+5LYgKoFXhTxVfam0yJtr1
dr2MdDBfN3Qszrc6pBQ7Y5c7yGyF+JhYQDuX0IyebmHDmxeidZUbAnTTiB4qNxei
crGMf9Xfs4vQiX+D/IEo
=6v0I
-----END PGP SIGNATURE-----


More information about the Tech mailing list