Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/nix.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ jobs:
- uses: DeterminateSystems/magic-nix-cache-action@main
- name: Build
run: nix build .#packages.x86_64-linux.a653lib --print-build-logs
x86_64-linux---a653-wasmtime:
name: x86_64-linux.a653-wasmtime
runs-on:
- ubuntu-latest
needs: []
steps:
- uses: actions/checkout@v4
- uses: DeterminateSystems/nix-installer-action@main
- uses: DeterminateSystems/magic-nix-cache-action@main
- name: Build
run: nix build .#packages.x86_64-linux.a653-wasmtime --print-build-logs
x86_64-linux---a653lib-aarch64:
name: x86_64-linux.a653lib-aarch64
runs-on:
Expand Down
61 changes: 58 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#export COMMON_SWITCH = -D__LITTLE_ENDIAN -m32 -rdynamic
export COMMON_SWITCH = -D__LITTLE_ENDIAN -rdynamic

HOME ?= $(shell pwd)

# CC_PATH=/home/tools/gnat/bin/
CC_PATH=
Expand Down Expand Up @@ -38,16 +39,21 @@ export CC
OBJS = main.o
OBJS_A = partition_a.o init.o
OBJS_B = partition_b.o init.o
OBJS_WASM_BOOTSTRAP =


MY_BUILD_DIR = $(BUILD_DIR)
TARGET = $(BIN_DIR)/a653_main
TARGET_A = $(BIN_DIR)/partition_a
TARGET_A_WASM = $(BIN_DIR)/partition_a.wasm
TARGET_B = $(BIN_DIR)/partition_b
TARGET_B_WASM = $(BIN_DIR)/partition_b.wasm
TARGET_WASMTIME_CLI = $(BIN_DIR)/p_wasmtime
TARGET_WAMR_CLI = $(BIN_DIR)/p_wamr



all: clean mk_build_dir alib amain part_a part_b
all: mk_build_dir alib amain part_a part_b
@echo done!


Expand All @@ -64,12 +70,61 @@ part_b: $(OBJS_B)
cd $(MY_BUILD_DIR); $(CC) $(CFLAGS) $(LDFLAGS) -o $(TARGET_B) $(OBJS_B) ./liba653.a $(LDLIBS)


alib:
make -e -C $(SRC_DIR)/a653_lib
# $ yay -S clang lld wasi-libc wasi-compiler-rt # guest compilation
# $ yay -S libwasmtime iwasm # host libraries
all_wasm: mk_build_dir alib amain_wasm part_wasmtime part_wamr $(TARGET_A_WASM) $(TARGET_B_WASM)
# set a default runtime, change link to p_wamr if wamr desired
cd $(BIN_DIR); ln -s p_wasmtime wasm32_rt

amain_wasm: CFLAGS += -D__WASM_RT__
amain_wasm: $(OBJS)
@echo build dir $(MY_BUILD_DIR)
cd $(MY_BUILD_DIR); $(CC) $(CFLAGS) $(LDFLAGS) -o $(TARGET)_wasm $(OBJS) ./liba653.a $(LDLIBS)

part_wasmtime: mk_build_dir alib amain_wasm
make -e -C $(SRC_DIR)/a653_lib_wasm32 $(TARGET_WASMTIME_CLI)

part_wamr: mk_build_dir alib amain_wasm
make -e -C $(SRC_DIR)/a653_lib_wasm32 $(TARGET_WAMR_CLI)

part_wasm_guest: $(TARGET_A_WASM) $(TARGET_B_WASM)

WASI_SYSROOT ?= /usr/share/wasi-sysroot

%.wasm: alib
@echo build dir $(MY_BUILD_DIR)
# 1. we use the wasm32-wasi to include the stdlib (thus having __start() and main() support).
# however, long term for avionics it would make sense to drop and go to wasm32-unknown with likely -Wl,-export=_start or similar
# 2. --allow-undefined is required for symbols (such as WIT functions) that are not yet defined.
cd $(MY_BUILD_DIR); clang -I$(MY_BUILD_DIR)/a653_inc --target=wasm32-wasi -Wl,--export-table -Wl,--allow-undefined --sysroot=$(WASI_SYSROOT) -o $@ $(SRC_DIR)/$(basename $(notdir $@)).c 1> $(basename $(notdir $@)).wasm32_struct_layout.txt # ../../wasm_guest_trampoline.c

alib: $(TMP_DIR)/download/a653Blackboard.h $(TMP_DIR)/download/a653Buffer.h $(TMP_DIR)/download/a653Event.h $(TMP_DIR)/download/a653Mutex.h
cp -r $(SRC_DIR)/a653_inc $(MY_BUILD_DIR)
cp $^ $(MY_BUILD_DIR)/a653_inc
# cp -r $(SRC_DIR)/a653_ada $(MY_BUILD_DIR)
# relies on the above headers
make -e -C $(SRC_DIR)/a653_lib


# rule to download the ARINC headerfiles
$(TMP_DIR)/download/arinc653.h.zip:
@mkdir -p -- $(@D)
test -f $@ || curl --user-agent 'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:41.0) Gecko/20100101 Firefox/41.0' \
--location --output-dir $(TMP_DIR)/download --remote-name-all \
https://brx-content.fullsight.org/site/binaries/content/assets/itc/content/support-files/arinc653.h.zip

# rule to extract the ARINC headerfiles
$(TMP_DIR)/download/ARINC653.h: $(TMP_DIR)/download/arinc653.h.zip
@mkdir -p -- $(@D)
test -f $@ || echo $^ | xargs --max-args=1 bsdtar -x --cd $(TMP_DIR)/download --modification-time --file

# rule to generate our Wasm header file, by making every open type a 32 Bit integer
$(TMP_DIR)/download/ARINC653_patched.h: $(TMP_DIR)/download/ARINC653.h
@mkdir -p -- $(@D)
awk -f $(SRC_DIR)/scripts/process-arinc-header.awk $< > $@

$(TMP_DIR)/download/a653Blackboard.h $(TMP_DIR)/download/a653Buffer.h $(TMP_DIR)/download/a653Event.h $(TMP_DIR)/download/a653Mutex.h &: $(TMP_DIR)/download/ARINC653_patched.h
cd $(TMP_DIR)/download; awk -f $(SRC_DIR)/scripts/split-arinc-header.awk $<


gcc_version:
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,7 @@ pid: 578773 <1702486050.349254883>: > taskset --cpu-list 1 ./partition_b & :
## Tests debugging

## Build with Make

## Links

[Required Services](https://www.aviation-ia.com/support-files/arinc653h)
5 changes: 5 additions & 0 deletions a653_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@

#define D_TIME_SLICE 1000000ll /* 1000000ns = 1ms */

#ifdef __WASM_RT__
#define PART_NAME_A "wasm32_rt partition_a.wasm"
#define PART_NAME_B "wasm32_rt partition_b.wasm"
#else
#define PART_NAME_A "partition_a"
#define PART_NAME_B "partition_b"
#endif


#define A653_PARTITION_CONFIG_DEF { \
Expand Down
5 changes: 5 additions & 0 deletions a653_inc/a653Error.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,26 +72,31 @@ typedef

/* function declarations */

WASM_IMPORT_MODULE("arinc653")
extern void REPORT_APPLICATION_MESSAGE (
/*in */ MESSAGE_ADDR_TYPE MESSAGE_ADDR,
/*in */ MESSAGE_SIZE_TYPE LENGTH,
/*out*/ RETURN_CODE_TYPE *RETURN_CODE );

WASM_IMPORT_MODULE("arinc653")
extern void CREATE_ERROR_HANDLER (
/*in */ SYSTEM_ADDRESS_TYPE ENTRY_POINT,
/*in */ STACK_SIZE_TYPE STACK_SIZE,
/*out*/ RETURN_CODE_TYPE *RETURN_CODE );

WASM_IMPORT_MODULE("arinc653")
extern void GET_ERROR_STATUS (
/*out*/ ERROR_STATUS_TYPE *ERROR_STATUS,
/*out*/ RETURN_CODE_TYPE *RETURN_CODE );

WASM_IMPORT_MODULE("arinc653")
extern void RAISE_APPLICATION_ERROR (
/*in */ ERROR_CODE_TYPE ERROR_CODE,
/*in */ MESSAGE_ADDR_TYPE MESSAGE_ADDR,
/*in */ ERROR_MESSAGE_SIZE_TYPE LENGTH,
/*out*/ RETURN_CODE_TYPE *RETURN_CODE );

WASM_IMPORT_MODULE("arinc653")
extern void CONFIGURE_ERROR_HANDLER (
/*in */ ERROR_HANDLER_CONCURRENCY_CONTROL_TYPE CONCURRENCY_CONTROL,
/*in */ PROCESSOR_CORE_ID_TYPE PROCESSOR_CORE_ID,
Expand Down
4 changes: 4 additions & 0 deletions a653_inc/a653Init.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#ifndef __A653INIT_H__
#define __A653INIT_H__

#ifndef __wasm__ /* Do not expose non ARINC653 functions into WebAssembly */

#include "a653Type.h"

//#define S_TRACE 1
Expand Down Expand Up @@ -114,4 +116,6 @@ void a653_i_update_partitions(void);
void setDebug(int level);
void printDebug(int level,const char *format, ... );

#endif /* #ifndef __wasm__ */

#endif /* __A653INIT_H__ */
11 changes: 8 additions & 3 deletions a653_inc/a653Lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,33 @@

/* a653 includes */
#include <a653Type.h>
//#include <a653Blackboard.h>
#include <a653Blackboard.h>
//#include <a653MemoryBlock.h>
//#include <a653Buffer.h>
#include <a653Buffer.h>
#include <a653Error.h>
//#include <a653Event.h>
#include <a653Event.h>
#include <a653Partition.h>
#include <a653Process.h>
#include <a653Queuing.h>
#include <a653Sampling.h>
#include <a653Semaphore.h>
#include <a653Time.h>
#include <a653Mutex.h>

#ifndef __wasm__ /* Do not expose non ARINC653 functions into WebAssembly */
#include <a653Init.h>
#endif /* #ifndef __wasm__ */

/* defines */

/* externs */

/* function declarations */

#ifndef __wasm__ /* Do not expose non ARINC653 functions into WebAssembly */
extern int a653LibInit ();
extern int a653MinimalLibInit ();
#endif /* #ifndef __wasm__ */


#endif /* __A653_LIB_H */
2 changes: 2 additions & 0 deletions a653_inc/a653Partition.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ typedef
NUM_CORES_TYPE NUM_ASSIGNED_CORES;
} PARTITION_STATUS_TYPE;

WASM_IMPORT_MODULE("arinc653")
extern void GET_PARTITION_STATUS (
/*out*/ PARTITION_STATUS_TYPE *PARTITION_STATUS,
/*out*/ RETURN_CODE_TYPE *RETURN_CODE );

WASM_IMPORT_MODULE("arinc653")
extern void SET_PARTITION_MODE (
/*in */ OPERATING_MODE_TYPE OPERATING_MODE,
/*out*/ RETURN_CODE_TYPE *RETURN_CODE );
Expand Down
20 changes: 19 additions & 1 deletion a653_inc/a653Process.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@

typedef NAME_TYPE PROCESS_NAME_TYPE; /* process name type */
typedef A653_INTEGER PROCESS_INDEX_TYPE;
typedef A653_INTEGER PRIORITY_TYPE; /* priority type */

/* process state type */
typedef
Expand Down Expand Up @@ -75,79 +74,97 @@ typedef

/* function declarations */

WASM_IMPORT_MODULE("arinc653")
extern void CREATE_PROCESS (
/*in */ PROCESS_ATTRIBUTE_TYPE *ATTRIBUTES,
/*out*/ PROCESS_ID_TYPE *PROCESS_ID,
/*out*/ RETURN_CODE_TYPE *RETURN_CODE );

WASM_IMPORT_MODULE("arinc653")
extern void SET_PRIORITY (
/*in */ PROCESS_ID_TYPE PROCESS_ID,
/*in */ PRIORITY_TYPE PRIORITY,
/*out*/ RETURN_CODE_TYPE *RETURN_CODE );

WASM_IMPORT_MODULE("arinc653")
extern void SUSPEND_SELF (
/*in */ SYSTEM_TIME_TYPE TIME_OUT,
/*out*/ RETURN_CODE_TYPE *RETURN_CODE );

WASM_IMPORT_MODULE("arinc653")
extern void SUSPEND (
/*in */ PROCESS_ID_TYPE PROCESS_ID,
/*out*/ RETURN_CODE_TYPE *RETURN_CODE );

WASM_IMPORT_MODULE("arinc653")
extern void RESUME (
/*in */ PROCESS_ID_TYPE PROCESS_ID,
/*out*/ RETURN_CODE_TYPE *RETURN_CODE );

WASM_IMPORT_MODULE("arinc653")
extern void STOP_SELF (void);

WASM_IMPORT_MODULE("arinc653")
extern void STOP (
/*in */ PROCESS_ID_TYPE PROCESS_ID,
/*out*/ RETURN_CODE_TYPE *RETURN_CODE );

WASM_IMPORT_MODULE("arinc653")
extern void START (
/*in */ PROCESS_ID_TYPE PROCESS_ID,
/*out*/ RETURN_CODE_TYPE *RETURN_CODE );

WASM_IMPORT_MODULE("arinc653")
extern void DELAYED_START (
/*in */ PROCESS_ID_TYPE PROCESS_ID,
/*in */ SYSTEM_TIME_TYPE DELAY_TIME,
/*out*/ RETURN_CODE_TYPE *RETURN_CODE );

WASM_IMPORT_MODULE("arinc653")
extern void LOCK_PREEMPTION (
/*out*/ LOCK_LEVEL_TYPE *LOCK_LEVEL,
/*out*/ RETURN_CODE_TYPE *RETURN_CODE );

WASM_IMPORT_MODULE("arinc653")
extern void UNLOCK_PREEMPTION (
/*out*/ LOCK_LEVEL_TYPE *LOCK_LEVEL,
/*out*/ RETURN_CODE_TYPE *RETURN_CODE );

WASM_IMPORT_MODULE("arinc653")
extern void GET_MY_ID (
/*out*/ PROCESS_ID_TYPE *PROCESS_ID,
/*out*/ RETURN_CODE_TYPE *RETURN_CODE );

WASM_IMPORT_MODULE("arinc653")
extern void GET_PROCESS_ID (
/*in */ PROCESS_NAME_TYPE PROCESS_NAME,
/*out*/ PROCESS_ID_TYPE *PROCESS_ID,
/*out*/ RETURN_CODE_TYPE *RETURN_CODE );

WASM_IMPORT_MODULE("arinc653")
extern void GET_PROCESS_STATUS (
/*in */ PROCESS_ID_TYPE PROCESS_ID,
/*out*/ PROCESS_STATUS_TYPE *PROCESS_STATUS,
/*out*/ RETURN_CODE_TYPE *RETURN_CODE );

WASM_IMPORT_MODULE("arinc653")
extern void INITIALIZE_PROCESS_CORE_AFFINITY (
/*in */ PROCESS_ID_TYPE PROCESS_ID,
/*in */ PROCESSOR_CORE_ID_TYPE PROCESSOR_CORE_ID,
/*out*/ RETURN_CODE_TYPE *RETURN_CODE );

WASM_IMPORT_MODULE("arinc653")
extern void GET_MY_PROCESSOR_CORE_ID (
/*out*/ PROCESSOR_CORE_ID_TYPE *PROCESSOR_CORE_ID,
/*out*/ RETURN_CODE_TYPE *RETURN_CODE );

WASM_IMPORT_MODULE("arinc653")
extern void GET_MY_INDEX (
/*out*/ PROCESS_INDEX_TYPE *PROCESS_INDEX,
/*out*/ RETURN_CODE_TYPE *RETURN_CODE );


#ifndef __wasm__ /* Do not expose non ARINC653 functions into WebAssembly */
int a653_prcs_init(void);

int a653_sync_prcs(void);
Expand All @@ -160,5 +177,6 @@ extern void a653TimeMonitorProcGet (PROCESS_ID_TYPE PROCESS_ID,
RETURN_CODE_TYPE * RETURN_CODE);
extern PROCESS_ID_TYPE procIdFromTaskIdGet (int taskId);
extern int taskIdFromProcIdGet (PROCESS_ID_TYPE procId);
#endif /* #ifndef */

#endif /* A653_PROCESS_H */
Loading
Loading