Skip to content

Commit 6693ed0

Browse files
Merge pull request #37 from GaloisInc/11-implement-component-mission-protection-system
11 implement component mission protection system
2 parents 0f8b183 + 63bc224 commit 6693ed0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+4798
-4
lines changed

.gitmodules

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
[submodule "components/mission_protection_system/HARDENS"]
2-
path = components/mission_protection_system/HARDENS
3-
url = [email protected]:GaloisInc/HARDENS.git
41
[submodule "src/pkvm_setup/linux-pkvm"]
52
path = src/pkvm_setup/linux-pkvm
63
url = https://github.com/rems-project/linux
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
*/#*#
2+
*/.*
3+
*.o
4+
*.a
5+
*.bc
6+
*.ll
7+
*.elf
8+
*.asm
9+
.vscode
10+
src/wp-session/
11+
src/generated/SystemVerilog/verilator/
12+
src/handwritten/SystemVerilog/verilator/
13+
src/self_test_data/
14+
src/rts*
15+
saw/*.v
16+
Assurance.pdf
17+
README.pdf
18+
Toolchain.pdf
19+
Specifications.pdf
20+
hardware/SoC/design.*
21+
tests/__pycache__/
This file was deleted.

components/mission_protection_system/README.md

+13
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,16 @@ The system is connected to two temperature sensors and two fuel pressure sensors
4343
* V.4 MPS shall demonstrate Independence among the two trains of actuation logic (inability for the behavior of one train to interfere or adversely affect the performance another)
4444
* V.5 MPS shall demonstrate Completion of actuation whenever coincidence logic is satisfied or manual actuation is initiated
4545
* V.6 MPS shall demonstrate Independence between periodic self-test functions and trip functions (inability for the behavior of the self-testing to interfere or adversely affect the trip functions)
46+
47+
## Porting Notes
48+
49+
The MPS is being adapted from a high-assurance model reactor control system (HARDENS) which includes converting the Frama-C ACSL specifications to CN specifications.
50+
Many C features are not yet supported by CN, the ones that most seriously affect the MPS are lack of variadic functions (all logging printfs) and lack of unions (the instrumentation_command struct).
51+
ACSL constructs mostly have direct analogs in CN:
52+
53+
- `requires` and `ensures` are the same
54+
- `\valid` should become `Owned`, not `Block`, it requires reading and writing ability.
55+
- `assigns` means the value in that location can change. Other locations can be written as long as they are restored before the function exits. It doesn't make any demand on the value in the location, so it is taking and returning an `Owned`.
56+
- `<==>` between predicates can be replaced with `==`, it is equivalence on booleans instead of predicates.
57+
58+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
// File from: https://github.com/mpaland/printf
2+
///////////////////////////////////////////////////////////////////////////////
3+
// \author (c) Marco Paland ([email protected])
4+
// 2014-2019, PALANDesign Hannover, Germany
5+
//
6+
// \license The MIT License (MIT)
7+
//
8+
// Permission is hereby granted, free of charge, to any person obtaining a copy
9+
// of this software and associated documentation files (the "Software"), to deal
10+
// in the Software without restriction, including without limitation the rights
11+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
// copies of the Software, and to permit persons to whom the Software is
13+
// furnished to do so, subject to the following conditions:
14+
//
15+
// The above copyright notice and this permission notice shall be included in
16+
// all copies or substantial portions of the Software.
17+
//
18+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
// THE SOFTWARE.
25+
//
26+
// \brief Tiny printf, sprintf and snprintf implementation, optimized for speed on
27+
// embedded systems with a very limited resources.
28+
// Use this instead of bloated standard/newlib printf.
29+
// These routines are thread safe and reentrant.
30+
//
31+
///////////////////////////////////////////////////////////////////////////////
32+
33+
#ifndef _PRINTF_H_
34+
#define _PRINTF_H_
35+
36+
#include <stdarg.h>
37+
#include <stddef.h>
38+
39+
40+
#ifdef __cplusplus
41+
extern "C" {
42+
#endif
43+
44+
45+
/**
46+
* Output a character to a custom device like UART, used by the printf() function
47+
* This function is declared here only. You have to write your custom implementation somewhere
48+
* \param character Character to output
49+
*/
50+
void _putchar(char character);
51+
52+
53+
/**
54+
* Tiny printf implementation
55+
* You have to implement _putchar if you use printf()
56+
* To avoid conflicts with the regular printf() API it is overridden by macro defines
57+
* and internal underscore-appended functions like printf_() are used
58+
* \param format A string that specifies the format of the output
59+
* \return The number of characters that are written into the array, not counting the terminating null character
60+
*/
61+
#define printf printf_
62+
#if !WAR_NO_VARIADICS
63+
int printf_(const char* format, ...);
64+
#endif
65+
66+
67+
/**
68+
* Tiny sprintf implementation
69+
* Due to security reasons (buffer overflow) YOU SHOULD CONSIDER USING (V)SNPRINTF INSTEAD!
70+
* \param buffer A pointer to the buffer where to store the formatted string. MUST be big enough to store the output!
71+
* \param format A string that specifies the format of the output
72+
* \return The number of characters that are WRITTEN into the buffer, not counting the terminating null character
73+
*/
74+
#define sprintf sprintf_
75+
#if !WAR_NO_VARIADICS
76+
int sprintf_(char* buffer, const char* format, ...);
77+
#endif
78+
79+
80+
/**
81+
* Tiny snprintf/vsnprintf implementation
82+
* \param buffer A pointer to the buffer where to store the formatted string
83+
* \param count The maximum number of characters to store in the buffer, including a terminating null character
84+
* \param format A string that specifies the format of the output
85+
* \param va A value identifying a variable arguments list
86+
* \return The number of characters that COULD have been written into the buffer, not counting the terminating
87+
* null character. A value equal or larger than count indicates truncation. Only when the returned value
88+
* is non-negative and less than count, the string has been completely written.
89+
*/
90+
#define snprintf snprintf_
91+
#define vsnprintf vsnprintf_
92+
#if !WAR_NO_VARIADICS
93+
int snprintf_(char* buffer, size_t count, const char* format, ...);
94+
#endif
95+
int vsnprintf_(char* buffer, size_t count, const char* format, va_list va);
96+
97+
98+
/**
99+
* Tiny vprintf implementation
100+
* \param format A string that specifies the format of the output
101+
* \param va A value identifying a variable arguments list
102+
* \return The number of characters that are WRITTEN into the buffer, not counting the terminating null character
103+
*/
104+
#define vprintf vprintf_
105+
int vprintf_(const char* format, va_list va);
106+
107+
108+
/**
109+
* printf with output function
110+
* You may use this as dynamic alternative to printf() with its fixed _putchar() output
111+
* \param out An output function which takes one character and an argument pointer
112+
* \param arg An argument pointer for user data passed to output function
113+
* \param format A string that specifies the format of the output
114+
* \return The number of characters that are sent to the output function, not counting the terminating null character
115+
*/
116+
#if !WAR_NO_VARIADICS
117+
int fctprintf(void (*out)(char character, void* arg), void* arg, const char* format, ...);
118+
#endif
119+
120+
121+
#ifdef __cplusplus
122+
}
123+
#endif
124+
125+
126+
#endif // _PRINTF_H_
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env sh
2+
3+
cd src/components || exit 1
4+
5+
files=( actuator.c )
6+
#instrumentation_common.c
7+
#actuation_unit.c
8+
#instrumentation.c
9+
10+
cn -I ../include -I ../../hardware/SoC/firmware/ --include=../include/wars.h "${files[@]}"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#! /usr/bin/env bash
2+
set -e
3+
4+
sudo docker run -v ${PWD}:/HARDENS -it \
5+
framac/frama-c:dev \
6+
make -C /HARDENS/src -f frama_c.mk

0 commit comments

Comments
 (0)