Commit graph

67 commits

Author SHA1 Message Date
Gerwin Klein
e9c89bcac0 bfgen: add field_ptr(align) name size
Add the new block command

    field_ptr(align) name size

as an abbreviation for

    padding size - canonical + align
    field_high name canonical - align

The (align) part is optional. If left out, align is 0.

This is useful for removing #ifdefs for pointer storage that are trying
to achieve constant size over different canonical bit representations.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2026-01-09 09:00:43 +11:00
Gerwin Klein
29b63be21d bfgen: allow simple arithmetic integer expressions
Allow arithmetic integer expressions in all places where previously
only integer literals were allowed.

The operators +, -, *, / and % are supported. Additionally, in field,
field_high, and padding specifications, the constants "word_size" and
"canonical" are available.

This enables more readable bitfield specifications without changing
any of the code and proof generation. Produces identical output to
before.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2026-01-09 09:00:43 +11:00
julia
1c50485c9a bitfield_gen: apply style fixes
Signed-off-by: julia <git.ts@trainwit.ch>
2025-08-04 12:28:20 +01:00
julia
9a4cdabcd5 bitfield_gen: improve readability of union funcs
Before:

    static inline uint64_t PURE
    pte_pte_table_ptr_get_pt_base_address(pte_t *pte_ptr) {
        uint64_t ret;
        assert(((pte_ptr->words[0] >> 0) & 0x400000000000003) ==
               0x3ull);

After:

    static inline uint64_t PURE
    pte_pte_table_ptr_get_pt_base_address(pte_t *pte_ptr) {
        uint64_t ret;
        /* fail if union does not have the expected tag */
        assert(((pte_ptr->words[0] >> 0) & 0x400000000000003) ==
               0x3ull /* sliced tag pte_pte_table */);

Signed-off-by: julia <git.ts@trainwit.ch>
2025-08-04 12:28:20 +01:00
julia
eca86cff19 treewide: typo fixes
Signed-off-by: julia <git.ts@trainwit.ch>
2025-04-14 12:05:16 +10:00
Gerwin Klein
ddeb18a015 bitfield_gen: properly escape backslash
Replace "\<"" in strings with "\\<". Until recently python did not
complain about this illegal escape sequence, but now it warns.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2024-05-27 14:34:00 +10:00
Ben Leslie
4d7fc32a24 Remove python2 support for core build tools
Depedencies on Python2/3 cross support (such as six, past and future)
are removed as only Python3 is supported at this point. Fewer
external deps is a good thing.

Signed-off-by: Ben Leslie <benno@brkawy.com>
Signed-off-by: Ivan Velickovic <i.velickovic@unsw.edu.au>
2024-05-02 02:11:29 +01:00
Gerwin Klein
449c9089ad
bitfield_gen: remove obsolete options, add help
* Add help texts for all CLI options.

* Point to the manual in file header.

* Remove obsolete `--multifile_base` and `--c_defs` options. The former
  is unused and the logic for it was removed in the previous commit.
  The latter is not referenced in the code and has no effect. `

* Remove unused `mode` variable.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-05-01 12:35:48 +10:00
Gerwin Klein
ebea422f86
bitfield_gen: remove unused --multifile_base logic
The `--multifile_base` option is unused in the seL4 build and has
comments indicating that it is broken.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-05-01 12:35:38 +10:00
Gerwin Klein
886fcec2b6 trivial: fix typo
Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-04-27 13:13:13 +10:00
Axel Heider
525d14ccfc python: include config.h first in generated files
Including the configuration first ensure consistent behavior.

Signed-off-by: Axel Heider <axelheider@gmx.de>
2023-04-24 23:02:12 +10:00
Axel Heider
8eec7ad207 python: include sel4/config.h and not autoconf.h
Include sel4/config.h instead of autoconf.h in the generated code.

Signed-off-by: Axel Heider <axelheider@gmx.de>
2023-04-24 23:02:12 +10:00
Gerwin Klein
57c46bc8d0 bitfield_gen: comment for original source file
Add a `--form_file <file>` option to the bitfield generator for
printing a `/* generated from <file> */` message in a comment.

Use this option in cmake to provide the original source .bf file before
preprocessing so it's easier to find out where the corresponding
definitions are.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-04-10 15:46:00 +10:00
Bin Meng
3179add042 tools/bitfield_gen: ensure UTF-8 encoding
There are cases that reasonably require non-ASCII characters in the
source code, hence tools/bitfield_gen.py must be able to handle them
correctly. This commit makes sure the bitfield generator consistently
opens all files with UTF-8 encoding.

Co-authored-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
2022-06-03 14:19:24 +10:00
Axel Heider
83a02a96fc python: use '#paragma once' include guard
Signed-off-by: Axel Heider <axelheider@gmx.de>
2022-03-23 17:28:07 +11:00
Gerwin Klein
0c9952f90a trivial: proof style fixes for bitfield_gen
Bring up-to-date with current proof style, make style consistent,
slightly increase proof parallelism.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2022-03-22 11:06:34 +11:00
Gerwin Klein
9f9ceddc18 bitfield_gen: allow non-contiguous tag fields
A tagged union can now optionally use multiple fields to indicate the
tag. These are called "sliced" tags in the code. The tag fields have to
be at the same position and width in each block of the tagged unions,
and all tag fields have to be within the same word.

When sliced tags are used, tag class masks cannot be used at the same
time for this tagged union.

In the `tagged_union` declaration, the values of such sliced tags
become tuples. For instance, if `x` and `y` are tag fields (declared in
blocks not shown here) with width 1 and 2, we can write:

    tagged_union ex exType(x,y) {
        tag ex1 (0,2)
        tag ex2 (1,3)
    }

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2022-03-21 17:43:37 +11:00
Gerwin Klein
b5e48eb787 bitfield_gen: prep for Isabelle2021
Isabelle2021 sometimes gets further with mask_simps, so this commit
makes them optional. Also removes a duplicate simp-rule warning.

Signed-off-by: Gerwin Klein <gerwin.klein@data61.csiro.au>
2021-01-24 18:42:27 +11:00
Matthew Brecknell
5362c6b26a bitfield_gen: update proofs to support RISC-V MCS
Signed-off-by: Matthew Brecknell <Matthew.Brecknell@data61.csiro.au>
2020-08-12 16:31:13 +10:00
Matthew Brecknell
a09d6f023a bitfield_gen: emit fields in visible order
Signed-off-by: Matthew Brecknell <Matthew.Brecknell@data61.csiro.au>
2020-08-12 16:31:13 +10:00
Edward Pierzchalski
4c0f16c7b8 bitfield_gen: fixups for MCS
Changes the 'size suffix map' to be useful in more places. In general,
when we use the 'short name' of a variable in these generated proofs, we
run the risk of a change in variable declaration order breaking the
resulting proofs (since declaration order is how the C parser chooses
which variables get the short name). Best practice is to use the long
names whenever possible.

Uses the suffix map for some generated proofs.

Removes an unnecessary simp step.

Signed-off-by: Edward Pierzchalski <ed.pierzchalski@data61.csiro.au>
2020-07-28 17:49:19 +10:00
Gerwin Klein
79da079239 Convert license tags to SPDX identifiers
This commit also converts our own copyright headers to directly use
SPDX, but leaves all other copyright header intact, only adding the
SPDX ident. As far as possible this commit also merges multiple
Data61 copyright statements/headers into one for consistency.
2020-03-09 13:21:49 +08:00
Luca(Wei) Chen
047ab9271a bitfield_gen: explicit branch predications
gcc8 might get wrong branch predications on these condition checks,
and it could break the code layout.
2020-03-02 13:32:35 +11:00
Matthew
5ebe5526fd Add the suffix to the bitfield generation
Clang complains about shifting signed numbers so we need to make sure it
knows it is unsigned
2020-02-12 16:08:35 +11:00
Edward Pierzchalski
cfc544ab49 bitfields: Specify iteration order over dicts
In Python 3, dict value iterators aren't deterministic between runs,
which causes nondeterministic definition output order. Some L4V proofs
are sensitive to this order.

Use sorted keys to guarantee order when iterating over values.
2019-08-08 10:19:24 +10:00
Anna Lyons
bc61a7f3bd python2 --> python3
Update all scripts and build system to call python3, given python2's
upcoming doom. Use sys.maxsize instead of sys.maxint in one script
(maxint does not exist in python3).
2019-08-08 10:19:24 +10:00
Anna Lyons
cf57914c7f style: run autopep8 on python files 2019-03-27 10:43:58 +11:00
Edward Pierzchalski
1283345bfd bitfield_gen: merge clarsimp/simp in generated proofs
The old generated proofs would fail if a simp set change made
`clarsimp` discharge what `simp` simplified.
2018-10-02 14:41:21 +10:00
Kent McLeod
880686dd22 bitfield_gen: Improve prune list generation time
Previously this would create a very big regex to parse the input
sources. This didn't scale as well on architectures with more bitfield
objects
2018-08-24 16:57:31 +10:00
Matthew Brecknell
fe955b5ba3 Improve generated bitfield proofs
For bitfields requiring sign extension, the generated specs are nicer to
work with in proofs. The proofs also support an updated `sign_extend`
specification (in the l4v repository) which has nicer properties.

This change also speeds up some bitfield proofs.
2017-12-21 18:01:55 +11:00
Gerwin Klein
960881d07e tools bitfield_gen: proof updates for new base + sign-extension mechanism 2017-09-20 22:01:13 +10:00
Gerwin Klein
3b330f9a6a tools bitfield_gen: use hex literals in proofs and specs 2017-09-20 22:01:13 +10:00
Gerwin Klein
38ba9e405b tools bitfield_gen: simplify theory imports; conform to style 2017-09-20 22:01:13 +10:00
Gerwin Klein
0a99d7d4d8 tools bitfield_gen: remove obsolete mask comments
(These masks existed in earlier versions of the bitfield proofs, removed
because the statements were stronger without them.)
2017-09-20 22:01:13 +10:00
Gerwin Klein
c57ea38874 tools bitfield_gen: use generic base instead of word32 in proofs 2017-09-20 22:01:13 +10:00
Anna Lyons
64cf2308ac tools: fix licenses 2017-06-22 15:27:30 +10:00
Anna Lyons
07f948331f libsel4: fix licenses
- some were incorrectly marked GPL (libsel4 is BSD)
- update NICTA --> DATA61 etc
- fix tags D61 --> DATA61
- update year to 2017
2017-06-22 15:27:29 +10:00
Matthew Brecknell
943f1ab0ba bitfield_gen: generate more efficient *_new and *_ptr_new functions
For blocks and unions, generate only one write for each word, rather
than an update for each bitfield.

For verification, this speeds up some automatically generated proofs.
2017-06-21 17:47:04 +10:00
Luke Mondy
85a0e441e7 By not writing a parse.py table, we avoid the parallel build issue of corrupted parse.py files 2017-05-08 10:30:07 +10:00
Stephen Sherratt
8c93b71c1c Import reduce from functools in python scripts 2017-02-22 12:19:58 +11:00
Jeff Waugh
803dd5c2ae libsel4: Optional public symbols for external interfaces
CONFIG_LIB_SEL4_PUBLIC_SYMBOLS=y will disable inlining for external
interfaces (except deprecated functions), thereby providing public
symbols for easy linkage with other languages.
2016-12-06 18:08:39 +11:00
Stephen Sherratt
79610f4c2b Bitfields generated with ply rather than yacc 2016-11-30 16:09:06 +11:00
Thomas Sewell
13ad834ace Generated bitfield proofs: use hrs_mem_update.
This is a technical change to the proof mode of the bitfield
generator included in the seL4 source.

The postconditions of the generated specifications of the
*_ptr_set and *_ptr_new functions now describe the entire new
heap via (new_heap = hrs_mem_update (...) old_heap).
Previously they described the contents of various projections
of the heap, which is less precise.
2016-11-01 16:18:02 +11:00
Japheth Lim
c517dba449 bitfield_gen: write output files atomically 2016-06-19 21:32:49 +10:00
Matthew Fernandez
7a9b81d237 Revert "bf gen: Add a backend for AutoCorres."
This reverts commit 5ee3971563. This backend was
previously used in an experiment towards libsel4 verification. That project has
since adopted a different strategy and this backend is now unused. Meanwhile
the backend has lagged behind breaking changes to AutoCorres. This commit
removes the backend to avoid confusion from users who believe it to be
functional.
2016-06-06 16:55:41 +10:00
Thomas Sewell
bea92de3b9 Verification: adjust use of new bf proof features.
Apologies, some final adjustments got lost in the previous pull
request round. This version actually works.
2016-03-21 18:14:40 +11:00
Thomas Sewell
13715658aa Verification: bf: use new proof features.
The plan here is to move some of the proof script complexity embedded
in the text of the bitfield_gen utility into generic proof helpers in the
l4v repository that bitfield_gen can use more modularly. This is a simple
first step.
2016-03-21 10:45:41 +11:00
Corey Richardson
41d98e45c0
tools: bitfield_gen: use six to access range (py3) or xrange (py2) 2016-01-25 15:56:33 +11:00
Corey Richardson
8ab5e037d5
tools: bitfield_gen: use itertools.chain instead of concatenating lists
This isn't efficient in Python, and moreover in python3 these methods
return iterables, not lists.
2016-01-25 15:56:33 +11:00
Corey Richardson
486aefc266
tools: bitfield_gen: use integral (//) instead of duck-typed division (/) 2016-01-25 15:56:32 +11:00