Commit Graph

71 Commits

Author SHA1 Message Date
Gerwin Klein
eaed120175 util: provide FNSPEC for __unreachable
Adding a spec with precondition False means verification has to show
that the function is not called.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2025-10-10 14:36:43 +11:00
Gerwin Klein
6d8b1eaeec utils: wrap config_set for verification
Wrap config_set macro in a static inline function so that verification
automation does not simplify away dead code branches based on it, but
the compiler still does.

In most parts of the proofs we want to pretend that we don't know the
config value yet and consider both options. This makes the proofs more
independent on the config value that is selected.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2025-03-28 10:53:48 +11:00
Axel Heider
c673f1cded make macro ARRAY_SIZE() handle corner cases
Put the parameter in brackets to ensure it is an atom. This makes the
macro work as expected in corner cases like ARRAY_SIZE(foo + 3) also.

Signed-off-by: Axel Heider <axelheider@gmx.de>
2022-03-10 18:16:00 +11:00
Bin Meng
2082aa4e30 trivial: Convert UTF-8 character to ASCII
When building seL4 on a host whose default encoding is not UTF-8,
tools/bitfield_gen.py complains, as with the following log from
Python 3.6 on a Ubuntu 18.04 host says:

  Traceback (most recent call last):
    File "tools/bitfield_gen.py",
  line 2773, in <module>
      string = f.read()
    File "/usr/lib/python3.6/encodings/ascii.py", line 26, in decode
      return codecs.ascii_decode(input, self.errors)[0]
  UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position
  607543: ordinal not in range(128)

As the Python 3 doc for open() [1] says the default encoding is
platform dependent, such build error may happen on some hosts.
We can either updating tools/bitfield_gen.py to call open() with
an explicit encoding="utf-8" parameter, or avoiding UTF-8 characters
in the source codes.

After inspecting the two places in current source tree that use UTF-8
characters, none of them is absolutely necessary. Let's convert them
to ASCII characters.

[1] https://docs.python.org/3.6/library/functions.html#open

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
2022-02-25 18:55:33 +11:00
Axel Heider
fcbb15ce3f trivial: fix typos and copy/paste fragments
Signed-off-by: Axel Heider <axelheider@gmx.de>
2021-11-28 14:49:55 +11:00
Axel Heider
e542a2a0ea add missing include and improve comments
- Since uint32_t and uint64_t are used, stdint.h needs to be included.
- Improve comments about GCC/LLVM internals.

Co-authored-by: Matthew Brecknell <matthew@brecknell.net>
Signed-off-by: Axel Heider <axelheider@gmx.de>
2021-11-17 11:15:53 +11:00
Axel Heider
54ae03f951 trivial: improve style for code and comments
Signed-off-by: Axel Heider <axelheider@gmx.de>
2021-08-31 10:53:31 +10:00
Axel Heider
e20652f664 make definition for NULL generic
Make the definition for NULL generic, so it can be used in constants
that are shared by C and assembly code.

Signed-off-by: Axel Heider <axelheider@gmx.de>
2021-07-19 10:45:20 +10:00
Axel Heider
fec1b90ef8 provide and use macro ULL_CONST()
- Provide the macro ULL_CONST() for 'unsigned long long' constants, and
  use it where applicable.
- Add a verbose explanation why the 'unsigned long long' type is used
  for time constants.

Signed-off-by: Axel Heider <axelheider@gmx.de>
2021-07-19 10:45:20 +10:00
Axel Heider
974458fde1 reorder and consolidate macro definitions
- Reorder the macro definitions to ensure things are define before they
  are used.
- provide a verbose explanation why the UL_CONST() macro is needed.
- make BIT() macro is defined generic by using UL_CONST().

Signed-off-by: Axel Heider <axelheider@gmx.de>
2021-07-19 10:45:20 +10:00
Axel Heider
93ab556e0c style: add spaces around the operator
Signed-off-by: Axel Heider <axelheider@gmx.de>
2021-07-19 10:45:20 +10:00
Axel Heider
72547433df trivial: remove superfluous empty line
Signed-off-by: Axel Heider <axelheider@gmx.de>
2021-07-19 10:45:20 +10:00
blackqbit
7a9cf4de10 Update util.h
delete #define FASTCALL     __attribute__((fastcall)) duplication
2021-06-20 12:02:04 +10:00
Matthew Brecknell
14f2ed7650 riscv: fix CLZ and CTZ for riscv32 builds (#325)
A previous commit (9ec5df5f) to provide more efficient CLZ (count
leading zeros) and CTZ (count trailing zeros) removed the `__clzsi2` and
`__ctzsi2` symbols, due to a misunderstanding of the types of these and
other library functions expected by GCC's intrinsics. 9ec5df5f broke the
riscv32 build.

This commit corrects the misunderstanding:
- `__clzsi2` and `__ctzsi2` are reinstated with correct types.
- The types of `__clzdi2` and `__ctzdi2` are corrected.
- `__clzti2` and `__ctzti2` are removed, since seL4 contains no compiler
  intrinsics that would require them.
- `clzl` and `ctzl` dispatch to the appropriate library functions based
  on the size of `unsigned long`.
- Configuration options are updated to ensure that the library functions
  are included in the kernel binary only when needed.

Signed-off-by: Matthew Brecknell <Matthew.Brecknell@data61.csiro.au>
2021-03-30 13:17:16 +11:00
Matthew Brecknell
9ec5df5fa8 riscv: more efficient clz and ctz
For RISC-V platforms that do not provide machine instructions to count
leading and trailing zeros, this commit includes more efficient library
functions. For verification, we expose the bodies of the functions to
the proofs.

Kernel config options `CLZ_BUILTIN` and `CTZ_BUILTIN` allow selection of
whether compiler builtin functions should be used. These are only
supported on platforms where the builtin compiles to inline assembly. By
default, the options are on for all platforms except RISC-V.

Signed-off-by: Matthew Brecknell <Matthew.Brecknell@data61.csiro.au>
2021-03-23 14:43:34 +11:00
Curtis Millar
301f36359c trivial: Use UL_CONST in assembler macros
Signed-off-by: Curtis Millar <curtis.millar@data61.csiro.au>
2020-05-22 12:26:13 +10:00
Qian Ge
512a0200de replacing all ifndef with pargma once
All the kernel header files now use pargma once rather than the ifndef,
as the pre-processed C files do not change while header files
are protected with pargma once. This will also solve any naming issues
caused by ifndef.
2020-03-23 11:04:46 +11: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
Rafal Kolanski
e04dbb9594 mcs: verification spec for clzll
This is required for the proofs.
2019-08-22 11:22:37 +10:00
Anna Lyons
acfc3c5257 mcs: tickless driver for x86
Add a tickless timer driver for x86. The driver defaults to using
TSC_DEADLINE mode, but falls back to the apic if that feature is not
available.
2019-08-22 11:22:34 +10:00
Anna Lyons
7124449936 mcs: tickless scheduler implementation
This changes the budget/remaining fields in scheduling contexts
to contain timer ticks, not number of abstract sel4ticks.

seL4_SchedControl_Configure now takes microseconds, not ticks.

This commit is plat-independant - the platform and arch specific
timer code follows in later commits.
2019-08-22 11:22:34 +10:00
Anna Lyons
761006e03b style: consistently align pointer with name
Run astyle with align-pointer=name
2019-03-19 14:04:54 +11:00
Anna Lyons
3d10ef0c4d style: correct parenthesis padding
Use astyle's unpad-paren to unpad all parentheses that are not included
by pad-header, pad-oper, and pad-comma.
2019-03-19 14:02:59 +11:00
Jasper Lowell
7262cb87e6 Treat optimize attribute as gcc specific
Clang doesn't provide support for __attribute__((optimize ...)). There
are alternatives to provide the same functionality but due to how rarely
the kernel is compiled without optimisations, this can be added on
demand.
2019-03-18 14:11:07 +11:00
Anna Lyons
ffbb278305 trivial: move MS_IN_S to utils.h 2018-09-18 10:05:26 +10:00
Adrian Danis
679c0b09ed Remove strlen
This is not suitable for verification and strnlen must be used instead.
2018-04-18 10:10:14 +10:00
Adrian Danis
43e1705280 Remove strcmp
This function causes difficulties for verification and strncmp should be used instead.
2018-04-18 10:10:14 +10:00
Adrian Danis
5ac36bcefb riscv: Move strcmp to util 2018-04-18 10:10:14 +10:00
Adrian Danis
c083919796 riscv: Move strlen to util 2018-04-18 10:10:14 +10:00
Anna Lyons
00cae0baed riscv: move STRINGIFY et al to util.h 2018-04-18 10:10:14 +10:00
Adrian Danis
80303364e8 riscv: Move implementations into c file
Function implementations belong in source files, not header files.
2018-04-18 10:10:14 +10:00
Hesham Almatary
83ba084713 [SELFOUR-1156] RISC-V Port
Experimental release that supports both RV32 and RV64
2018-04-18 10:10:14 +10:00
Bruce Mitchener
b942a50441 Fix trivial comment typos. 2018-03-27 10:51:26 +11:00
Sebastian Holzapfel
60aac65c99 ARM/v7-a: Force -O2 compilation of idle thread
This fixes a problem with -O0 SMP builds on ARM visible as kernel
data aborts whenever the idle thread executes.

The idle thread receives no stack pointer. At -O2, this is fine
as the wfi() call is inlined and stack operations in idle_thread
are optimized out. At -O0, the stack operations remain and wfi()
is not inlined, resulting in stack accesses in the idle thread
that cause data aborts.

Forcing -O2 behaviour was deemed the simplest solution for now.
Giving the idle thread a stack would have had larger verification
ramifications for what is now a fairly uncommon use case.
2018-03-13 13:09:47 +11:00
Adrian Danis
5247240a09 Implement UL_CONST macro for assembly and C
The UL_CONST macro provides a way to declare a constant that may or may not have a UL
suffix. In the case of assembly the UL suffix will be an error to many assemblers and
is not needed.
2018-01-09 14:13:41 +11:00
Adrian Danis
8d0b13c640 Token pasting helper
Adds utility macro for creating new tokens by token pasting
2018-01-09 14:13:41 +11:00
Adrian Danis
d43b717ef1 Move PAD_TO_NEXT_CACHE_LN to util.h
This utility macro is useful beyond just SMP code
2018-01-09 10:10:16 +11:00
Hesham Almatary
3aa244cc14 Verification: popcount- Avoid conflict variable names/types 2017-06-29 13:35:30 +10:00
Hesham Almatary
13e32a295d trivial: fixes to popcountl implementation 2017-06-29 10:43:48 +10:00
Hesham Almatary
0645a9ddb3 util.h: implement popcount for architectures that don't have HW inst for it 2017-06-29 10:15:00 +10:00
Adrian Danis
5552c6c6d9 mark memset and memcpy as VISIBLE
When compiling the kernel as a whole program it is possible that these functions may
be inlined and not emitted in the resulting binary. However at the same time the
compiler may itself emit calls to these functions. Marking these functions as
externally visible tells the compiler that there may be more usages of them than
it sees immediately in the source code, in this cases usages that the compiler
itself is going to generate
2017-06-16 14:25:50 +10:00
Hesham Almatary
f1ef8b3a55 ARM: Fix assembler error with BIT definition 2017-06-02 10:56:15 +10:00
Hesham Almatary
1930cf2e44 Fix: Allow util.h to be included in assembly files 2017-05-29 15:45:22 +10:00
Adrian Danis
f8606c86ad Provide spec for CTZL
Provides a spec for the __builtin_ctzl function and changes existing
code to use this wrapper
2017-02-22 17:22:17 +11:00
Thomas Sewell
117785483a Mark halt as no-inline and no-return.
This actually leads to better code. Copies of the halt loop inlined
in various places will instead be single instructions 'bl halt'. It's
also important for the translation validation to avoid having
pointless loops everywhere, especially inside the bodies of other
loops.
2016-12-12 17:30:50 +11:00
Thomas Sewell
9b7435718f Prototype compiler builtins.
Add compatible prototypes for compiler builtins
__builtin_unreachable, __builtin_ctzl, __builtin_clzl,
and __builtin_popcountl.

The compiler ignores these, but they are necessary for the Isabelle
C parser to handle them. This is needed to drop DONT_TRANSLATE markers
from various functions which call these builtins.
2016-12-12 17:30:49 +11:00
Adrian Danis
e7d0a88664 x86: Rewrite config_default as config_ternary for FPU
config_default was intended to either evaluated to the passed configuration
value, or the a default value if the config didn't exist. For integer values
this does not actually work, and the default value always gets returned.
This commit reimplements the desired functionality as config_ternary, which
takes 3 arguments, a config to switch on and a desired true and false expansion
2016-11-25 14:44:08 +11:00
Adrian Danis
859100e0a1 Merge pull request #288 in SEL4/sel4 from ~ALYONS/sel4:arch-fault to master
* commit 'ed95f84a438aea6365762a180cc493113e9282e0':
  SELFOUR-413: changes for verification
  SELFOUR-567: use seL4_CapRights_t from libsel4
  SELFOUR-413: refactor libsel4 fault API
  Split fault types into arch/generic
2016-11-25 14:31:09 +11:00
amrzar
08bc937f21 add DONT_TRANSLATE for popcount builtin 2016-11-25 14:04:46 +11:00
Anna Lyons
ed95f84a43 SELFOUR-413: changes for verification
Avoid using ptrs to arrays at all

Another macrofull change brought to your by verification. This should
avoid nasty proofs about const pointers.
2016-11-25 12:30:29 +11:00