Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory map constants as defines #161

Merged
merged 3 commits into from
Mar 19, 2024
Merged

Memory map constants as defines #161

merged 3 commits into from
Mar 19, 2024

Conversation

mchack-work
Copy link
Member

@mchack-work mchack-work commented Mar 4, 2024

Turning on -W pedantic shows us that our memory constants can't fit in an enum in ISO C. Not a real problem for GNU99 but makes it hard to run -W pedantic to find other problems.

I propose we change the memory constants from an enum into pre-processor defines instead and use simple direct values for the memory addresses instead of computing them.

We also turn on pedantic warnings but allow inline asm as the GNU extension we mostly use and fix missing void parameter declarations that pedantic warned us about.

Please review carefully that have all the addresses defined.

Also note that tk1_mem.h is also used in tkey-libs and qemu.

Closes #159

@mchack-work mchack-work requested review from secworks and dehanj March 4, 2024 15:05
Copy link
Member

@dehanj dehanj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The addresses seems to be correct, just a few comments on inconsistency. For example if we have the *_BASE included or not. Should they be included? I guess they are not used anymore since the prime usage before was to derive the addresses for a particular module.

hw/application_fpga/fw/tk1_mem.h Show resolved Hide resolved
hw/application_fpga/fw/tk1_mem.h Show resolved Hide resolved
hw/application_fpga/fw/tk1_mem.h Show resolved Hide resolved
hw/application_fpga/fw/tk1_mem.h Show resolved Hide resolved
hw/application_fpga/fw/tk1_mem.h Show resolved Hide resolved
@mchack-work
Copy link
Member Author

We actually don't know if someone is using _BASE. We don't, but someone else might. Better to include them. Nice catch.

@mchack-work mchack-work force-pushed the memory_map branch 5 times, most recently from 7424098 to 3725d03 Compare March 18, 2024 16:18
Instead of putting  memory constant into an enum we use defines.

Use the direct memory address instead of ORing constants together to
compute the address.

An enum in ISO C is a signed int. Some of are memory addresses are to
large to fit in a signed int. This is not a problem since we're not
using ISO C (-std=gnu99) but it doesn't look very nice if you turn on
pedantic warnings. Also, if someone would use another compiler which
at least supports the inline assembly we use, but possible not other
GNU extensions, things would probably break.
Use pedantic warnings but still allow inline assembly, so turn off
language-extension-token warnings.
@dehanj
Copy link
Member

dehanj commented Mar 19, 2024

Rebased on main, and removed a trailing whitespace.
Will merge when CI goes through.

@dehanj dehanj merged commit 746d7f0 into main Mar 19, 2024
1 check passed
@dehanj dehanj deleted the memory_map branch March 19, 2024 08:30
@dehanj dehanj restored the memory_map branch March 19, 2024 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Memory addresses in memory map outside of enum range
3 participants