From 6a3820dc4cb77f644e35013b2e0b0b677482301e Mon Sep 17 00:00:00 2001 From: Jonathan Pallant Date: Mon, 8 Jun 2026 16:04:32 +0100 Subject: [PATCH 1/6] Fix typos in build script comments. --- examples/mps3-an536-el2/build.rs | 2 +- examples/mps3-an536-smp/build.rs | 2 +- examples/mps3-an536/build.rs | 2 +- examples/versatileab/build.rs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/mps3-an536-el2/build.rs b/examples/mps3-an536-el2/build.rs index b0b9f098..0ae57894 100644 --- a/examples/mps3-an536-el2/build.rs +++ b/examples/mps3-an536-el2/build.rs @@ -9,7 +9,7 @@ use std::io::Write; fn main() { arm_targets::process(); write("memory.x", include_bytes!("memory.x")); - // Use the cortex-m-rt linker script + // Use the aarch32-rt linker script println!("cargo:rustc-link-arg=-Tlink.x"); } diff --git a/examples/mps3-an536-smp/build.rs b/examples/mps3-an536-smp/build.rs index b0b9f098..0ae57894 100644 --- a/examples/mps3-an536-smp/build.rs +++ b/examples/mps3-an536-smp/build.rs @@ -9,7 +9,7 @@ use std::io::Write; fn main() { arm_targets::process(); write("memory.x", include_bytes!("memory.x")); - // Use the cortex-m-rt linker script + // Use the aarch32-rt linker script println!("cargo:rustc-link-arg=-Tlink.x"); } diff --git a/examples/mps3-an536/build.rs b/examples/mps3-an536/build.rs index b0b9f098..0ae57894 100644 --- a/examples/mps3-an536/build.rs +++ b/examples/mps3-an536/build.rs @@ -9,7 +9,7 @@ use std::io::Write; fn main() { arm_targets::process(); write("memory.x", include_bytes!("memory.x")); - // Use the cortex-m-rt linker script + // Use the aarch32-rt linker script println!("cargo:rustc-link-arg=-Tlink.x"); } diff --git a/examples/versatileab/build.rs b/examples/versatileab/build.rs index 7871f45e..ef2fdada 100644 --- a/examples/versatileab/build.rs +++ b/examples/versatileab/build.rs @@ -9,7 +9,7 @@ use std::io::Write; fn main() { arm_targets::process(); write("memory.x", include_bytes!("memory.x")); - // Use the cortex-m-rt linker script + // Use the aarch32-rt linker script println!("cargo:rustc-link-arg=-Tlink.x"); } From 8c43fc9c55567f57c745e8d0826fec21e4123e16 Mon Sep 17 00:00:00 2001 From: Jonathan Pallant Date: Mon, 8 Jun 2026 16:13:47 +0100 Subject: [PATCH 2/6] Add some example C code. This does a very basic EABI check. We don't examine all the details, but it's enough to see whether we agree on short-enums, or the hard-float ABI. CI updated to install GCC (for cc-rs) and libclang1 (for bindgen). cc-rs doesn't currently support all our targets, so this will fail. --- .github/workflows/build.yml | 20 ++-- Cargo.toml | 1 + examples/c-code/Cargo.toml | 10 ++ examples/c-code/README.md | 5 + examples/c-code/build.rs | 19 ++++ examples/c-code/src/lib.rs | 5 + examples/c-code/src/library.c | 98 +++++++++++++++++++ examples/c-code/src/library.h | 80 +++++++++++++++ examples/versatileab/.cargo/config.toml | 33 +++++++ examples/versatileab/Cargo.toml | 1 + .../reference/c_test-armv4t-none-eabi.out | 15 +++ .../reference/c_test-armv5te-none-eabi.out | 15 +++ .../reference/c_test-armv6-none-eabi.out | 15 +++ .../reference/c_test-armv6-none-eabihf.out | 15 +++ .../reference/c_test-armv7a-none-eabi.out | 15 +++ .../reference/c_test-armv7a-none-eabihf.out | 15 +++ .../reference/c_test-armv7r-none-eabi.out | 15 +++ .../reference/c_test-armv7r-none-eabihf.out | 15 +++ .../reference/c_test-thumbv4t-none-eabi.out | 15 +++ .../reference/c_test-thumbv5te-none-eabi.out | 15 +++ .../reference/c_test-thumbv6-none-eabi.out | 15 +++ .../reference/c_test-thumbv7a-none-eabi.out | 15 +++ .../reference/c_test-thumbv7a-none-eabihf.out | 15 +++ .../reference/c_test-thumbv7r-none-eabi.out | 15 +++ .../reference/c_test-thumbv7r-none-eabihf.out | 15 +++ examples/versatileab/src/bin/c_test.rs | 73 ++++++++++++++ 26 files changed, 562 insertions(+), 8 deletions(-) create mode 100644 examples/c-code/Cargo.toml create mode 100644 examples/c-code/README.md create mode 100644 examples/c-code/build.rs create mode 100644 examples/c-code/src/lib.rs create mode 100644 examples/c-code/src/library.c create mode 100644 examples/c-code/src/library.h create mode 100644 examples/versatileab/reference/c_test-armv4t-none-eabi.out create mode 100644 examples/versatileab/reference/c_test-armv5te-none-eabi.out create mode 100644 examples/versatileab/reference/c_test-armv6-none-eabi.out create mode 100644 examples/versatileab/reference/c_test-armv6-none-eabihf.out create mode 100644 examples/versatileab/reference/c_test-armv7a-none-eabi.out create mode 100644 examples/versatileab/reference/c_test-armv7a-none-eabihf.out create mode 100644 examples/versatileab/reference/c_test-armv7r-none-eabi.out create mode 100644 examples/versatileab/reference/c_test-armv7r-none-eabihf.out create mode 100644 examples/versatileab/reference/c_test-thumbv4t-none-eabi.out create mode 100644 examples/versatileab/reference/c_test-thumbv5te-none-eabi.out create mode 100644 examples/versatileab/reference/c_test-thumbv6-none-eabi.out create mode 100644 examples/versatileab/reference/c_test-thumbv7a-none-eabi.out create mode 100644 examples/versatileab/reference/c_test-thumbv7a-none-eabihf.out create mode 100644 examples/versatileab/reference/c_test-thumbv7r-none-eabi.out create mode 100644 examples/versatileab/reference/c_test-thumbv7r-none-eabihf.out create mode 100644 examples/versatileab/src/bin/c_test.rs diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 78a1cb70..cb7d6807 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -224,6 +224,10 @@ jobs: uses: actions/checkout@v4 - name: Install Just uses: taiki-e/install-action@just + - name: Install GCC and libclang1 + run: | + sudo apt-get update + sudo apt-get install -y gcc-arm-none-eabi libclang1 - name: Install Rust run: | rustup toolchain install 1.92 @@ -288,7 +292,7 @@ jobs: - name: Install Dependencies run: | sudo apt-get -y update - sudo apt-get -y install libpixman-1-0 libfdt1 libglib2.0-0t64 + sudo apt-get -y install libpixman-1-0 libfdt1 libglib2.0-0t64 gcc-arm-none-eabi libclang1 - name: Install custom QEMU into /opt run: | curl -sSL https://github.com/jonathanpallant/qemu9-for-ubuntu-2404/releases/download/qemu-9.2.3%2Bbuild0/qemu-9.2.3-ubuntu-24.04.tar.gz | sudo tar xvzf - -C / @@ -310,7 +314,7 @@ jobs: - name: Install Dependencies run: | sudo apt-get -y update - sudo apt-get -y install libpixman-1-0 libfdt1 libglib2.0-0t64 + sudo apt-get -y install libpixman-1-0 libfdt1 libglib2.0-0t64 gcc-arm-none-eabi libclang1 - name: Install custom QEMU into /opt run: | curl -sSL https://github.com/jonathanpallant/qemu9-for-ubuntu-2404/releases/download/qemu-9.2.3%2Bbuild0/qemu-9.2.3-ubuntu-24.04.tar.gz | sudo tar xvzf - -C / @@ -332,7 +336,7 @@ jobs: - name: Install Dependencies run: | sudo apt-get -y update - sudo apt-get -y install libpixman-1-0 libfdt1 libglib2.0-0t64 + sudo apt-get -y install libpixman-1-0 libfdt1 libglib2.0-0t64 gcc-arm-none-eabi libclang1 - name: Install custom QEMU into /opt run: | curl -sSL https://github.com/jonathanpallant/qemu9-for-ubuntu-2404/releases/download/qemu-9.2.3%2Bbuild0/qemu-9.2.3-ubuntu-24.04.tar.gz | sudo tar xvzf - -C / @@ -354,7 +358,7 @@ jobs: - name: Install Dependencies run: | sudo apt-get -y update - sudo apt-get -y install libpixman-1-0 libfdt1 libglib2.0-0t64 + sudo apt-get -y install libpixman-1-0 libfdt1 libglib2.0-0t64 gcc-arm-none-eabi libclang1 - name: Install custom QEMU into /opt run: | curl -sSL https://github.com/jonathanpallant/qemu9-for-ubuntu-2404/releases/download/qemu-9.2.3%2Bbuild0/qemu-9.2.3-ubuntu-24.04.tar.gz | sudo tar xvzf - -C / @@ -376,7 +380,7 @@ jobs: - name: Install Dependencies run: | sudo apt-get -y update - sudo apt-get -y install libpixman-1-0 libfdt1 libglib2.0-0t64 + sudo apt-get -y install libpixman-1-0 libfdt1 libglib2.0-0t64 gcc-arm-none-eabi libclang1 - name: Install custom QEMU into /opt run: | curl -sSL https://github.com/jonathanpallant/qemu9-for-ubuntu-2404/releases/download/qemu-9.2.3%2Bbuild0/qemu-9.2.3-ubuntu-24.04.tar.gz | sudo tar xvzf - -C / @@ -398,7 +402,7 @@ jobs: - name: Install Dependencies run: | sudo apt-get -y update - sudo apt-get -y install libpixman-1-0 libfdt1 libglib2.0-0t64 + sudo apt-get -y install libpixman-1-0 libfdt1 libglib2.0-0t64 gcc-arm-none-eabi libclang1 - name: Install custom QEMU into /opt run: | curl -sSL https://github.com/jonathanpallant/qemu9-for-ubuntu-2404/releases/download/qemu-9.2.3%2Bbuild0/qemu-9.2.3-ubuntu-24.04.tar.gz | sudo tar xvzf - -C / @@ -420,7 +424,7 @@ jobs: - name: Install Dependencies run: | sudo apt-get -y update - sudo apt-get -y install libpixman-1-0 libfdt1 libglib2.0-0t64 + sudo apt-get -y install libpixman-1-0 libfdt1 libglib2.0-0t64 gcc-arm-none-eabi libclang1 - name: Install custom QEMU into /opt run: | curl -sSL https://github.com/jonathanpallant/qemu9-for-ubuntu-2404/releases/download/qemu-9.2.3%2Bbuild0/qemu-9.2.3-ubuntu-24.04.tar.gz | sudo tar xvzf - -C / @@ -442,7 +446,7 @@ jobs: - name: Install Dependencies run: | sudo apt-get -y update - sudo apt-get -y install libpixman-1-0 libfdt1 libglib2.0-0t64 + sudo apt-get -y install libpixman-1-0 libfdt1 libglib2.0-0t64 gcc-arm-none-eabi libclang1 - name: Install custom QEMU into /opt run: | curl -sSL https://github.com/jonathanpallant/qemu9-for-ubuntu-2404/releases/download/qemu-9.2.3%2Bbuild0/qemu-9.2.3-ubuntu-24.04.tar.gz | sudo tar xvzf - -C / diff --git a/Cargo.toml b/Cargo.toml index 61edd8f7..028ebb6a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,5 +10,6 @@ members = [ "aarch32-cpu", "aarch32-rt", "aarch32-rt-macros", + "examples/c-code", ] resolver = "2" diff --git a/examples/c-code/Cargo.toml b/examples/c-code/Cargo.toml new file mode 100644 index 00000000..32da2539 --- /dev/null +++ b/examples/c-code/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "c-code" +version = "0.1.0" +edition = "2024" + +[dependencies] + +[build-dependencies] +bindgen = "0.72.1" +cc = "1.2.63" diff --git a/examples/c-code/README.md b/examples/c-code/README.md new file mode 100644 index 00000000..0a3baef0 --- /dev/null +++ b/examples/c-code/README.md @@ -0,0 +1,5 @@ +# Example C Code + +This folder contains some example C code, which the other examples will link against and call. + +This tests the EABI support in Rust/LLVM. diff --git a/examples/c-code/build.rs b/examples/c-code/build.rs new file mode 100644 index 00000000..2bf92c66 --- /dev/null +++ b/examples/c-code/build.rs @@ -0,0 +1,19 @@ +fn main() { + // Build the C code into libc_code.a + cc::Build::new().file("src/library.c").compile("c_code"); + // Ensure the C library isn't stale + println!("cargo:rerun-if-changed=src/library.c"); + println!("cargo:rerun-if-changed=src/library.h"); + // Make Rust bindings to library.h + let bindings = bindgen::Builder::default() + .header("src/library.h") + .parse_callbacks(Box::new(bindgen::CargoCallbacks::new())) + .use_core() + .clang_arg("-fshort-enums") + .generate() + .expect("Unable to generate bindings"); + let out_path = std::path::PathBuf::from(std::env::var("OUT_DIR").unwrap()); + bindings + .write_to_file(out_path.join("bindings.rs")) + .expect("Couldn't write bindings.rs"); +} diff --git a/examples/c-code/src/lib.rs b/examples/c-code/src/lib.rs new file mode 100644 index 00000000..f43437e6 --- /dev/null +++ b/examples/c-code/src/lib.rs @@ -0,0 +1,5 @@ +#![no_std] +#![allow(non_camel_case_types)] +#![allow(non_upper_case_globals)] + +include!(concat!(env!("OUT_DIR"), "/bindings.rs")); diff --git a/examples/c-code/src/library.c b/examples/c-code/src/library.c new file mode 100644 index 00000000..ec6d041b --- /dev/null +++ b/examples/c-code/src/library.c @@ -0,0 +1,98 @@ +/** +Example C functions for testing Rust/C integration. +*/ + +#include "library.h" + +char c_code_char_check(char x) { + return x + 1; +} + +signed char c_code_signed_char_check(signed char x) { + return x + 1; +} + +unsigned char c_code_unsigned_char_check(unsigned char x) { + return x + 1; +} + +short c_code_short_check(short x) { + return x + 1; +} + +unsigned short c_code_unsigned_short_check(unsigned short x) { + return x + 1; +} + +int c_code_int_check(int x) { + return x + 1; +} + +unsigned int c_code_unsigned_int_check(unsigned int x) { + return x + 1; +} + +long c_code_long_check(long x) { + return x + 1; +} + +unsigned long c_code_unsigned_long_check(unsigned long x) { + return x + 1; +} + +int* c_code_int_ptr_check(int* p) { + return p + 1; +} + +float c_code_float_check(float x) { + return x * 2.0; +} + +double c_code_double_check(double x) { + return x * 2.0; +} + +/* +The enum check function converts ITEM_ONE to ITEM_TWO, ITEM_TWO to ITEM_THREE and ITEM_THREE to ITEM_ONE. +*/ + +enum c_code_sample_enum_t c_code_enum_rotate(enum c_code_sample_enum_t x) { + if (x == ITEM_ONE) { + return ITEM_TWO; + } else if (x == ITEM_TWO) { + return ITEM_THREE; + } else { + return ITEM_ONE; + } +} + +struct c_code_data_t c_code_struct_check(struct c_code_data_t x) { + struct c_code_data_t result = { + .c = c_code_char_check(x.c), + .s = c_code_short_check(x.s), + .i = c_code_int_check(x.i), + .l = c_code_long_check(x.l), + .f = c_code_float_check(x.f), + .d = c_code_double_check(x.d), + .e = c_code_enum_rotate(x.e), + }; + return result; +} + +/* +This struct check function adds one to every field in the structure, by modifying the given structure. +*/ + +void c_code_struct_ref_check(struct c_code_data_t* p) { + p->c = c_code_char_check(p->c); + p->s = c_code_short_check(p->s); + p->i = c_code_int_check(p->i); + p->l = c_code_long_check(p->l); + p->f = c_code_float_check(p->f); + p->d = c_code_double_check(p->d); + p->e = c_code_enum_rotate(p->e); +} + +/* +End of file +*/ diff --git a/examples/c-code/src/library.h b/examples/c-code/src/library.h new file mode 100644 index 00000000..02084d03 --- /dev/null +++ b/examples/c-code/src/library.h @@ -0,0 +1,80 @@ +/** +Example C functions for testing Rust/C integration. + +All functions start with `c_code_`. +*/ + +/* +These types are used in the functions below +*/ + +enum c_code_sample_enum_t { + ITEM_ONE, + ITEM_TWO, + ITEM_THREE +}; + +struct c_code_data_t { + char c; + short s; + int i; + long l; + float f; + double d; + enum c_code_sample_enum_t e; +}; + +/* +These integer `c_code_xxx_check` functions take a value and return `value + 1`. +*/ + +char c_code_char_check(char x); +signed char c_code_signed_char_check(signed char x); +unsigned char c_code_unsigned_char_check(unsigned char x); +short c_code_short_check(short x); +unsigned short c_code_unsigned_short_check(unsigned short x); +int c_code_int_check(int x); +unsigned int c_code_unsigned_int_check(unsigned int x); +long c_code_long_check(long x); +unsigned long c_code_unsigned_long_check(unsigned long x); + +/* +This pointer check function takes a pointer to two ints, and returns a pointer to the second. + +If passed NULL, it returns NULL. + +If passed a pointer to one int, the result is undefined. +*/ + +int* c_code_int_ptr_check(int* p); + +/* +These floating-point `c_code_xxx_check` functions take a value and return `value * 2.0`. +*/ + +float c_code_float_check(float x); +double c_code_double_check(double x); + +/* +The enum check function converts ITEM_ONE to ITEM_TWO, ITEM_TWO to ITEM_THREE and ITEM_THREE to ITEM_ONE. +*/ + +enum c_code_sample_enum_t c_code_enum_rotate(enum c_code_sample_enum_t x); + +/* +This struct check function adds one to every field in the structure, and returns a new structure. +*/ + + + +struct c_code_data_t c_code_struct_check(struct c_code_data_t x); + +/* +This struct check function adds one to every field in the structure, by modifying the given structure. +*/ + +void c_code_struct_ref_check(struct c_code_data_t* p); + +/* +End of file +*/ diff --git a/examples/versatileab/.cargo/config.toml b/examples/versatileab/.cargo/config.toml index a8c961ed..d74ac2c3 100644 --- a/examples/versatileab/.cargo/config.toml +++ b/examples/versatileab/.cargo/config.toml @@ -49,3 +49,36 @@ runner = "qemu-system-arm -machine versatileab -cpu arm926 -semihosting -nograph [build] target = "armv7r-none-eabihf" + +[env] +CC_armv7r_none_eabihf = "arm-none-eabi-gcc" +CC_thumbv7r_none_eabihf = "arm-none-eabi-gcc" +CC_armv7r_none_eabi = "arm-none-eabi-gcc" +CC_thumbv7r_none_eabi = "arm-none-eabi-gcc" +CC_armv7a_none_eabihf = "arm-none-eabi-gcc" +CC_thumbv7a_none_eabihf = "arm-none-eabi-gcc" +CC_armv7a_none_eabi = "arm-none-eabi-gcc" +CC_thumbv7a_none_eabi = "arm-none-eabi-gcc" +CC_armv6_none_eabihf = "arm-none-eabi-gcc" +CC_armv6_none_eabi = "arm-none-eabi-gcc" +CC_thumbv6_none_eabi = "arm-none-eabi-gcc" +CC_armv5te_none_eabi = "arm-none-eabi-gcc" +CC_thumbv5te_none_eabi = "arm-none-eabi-gcc" +CC_armv4t_none_eabi = "arm-none-eabi-gcc" +CC_thumbv4t_none_eabi = "arm-none-eabi-gcc" + +AR_armv7r_none_eabihf = "arm-none-eabi-ar" +AR_thumbv7r_none_eabihf = "arm-none-eabi-ar" +AR_armv7r_none_eabi = "arm-none-eabi-ar" +AR_thumbv7r_none_eabi = "arm-none-eabi-ar" +AR_armv7a_none_eabihf = "arm-none-eabi-ar" +AR_thumbv7a_none_eabihf = "arm-none-eabi-ar" +AR_armv7a_none_eabi = "arm-none-eabi-ar" +AR_thumbv7a_none_eabi = "arm-none-eabi-ar" +AR_armv6_none_eabihf = "arm-none-eabi-ar" +AR_armv6_none_eabi = "arm-none-eabi-ar" +AR_thumbv6_none_eabi = "arm-none-eabi-ar" +AR_armv5te_none_eabi = "arm-none-eabi-ar" +AR_thumbv5te_none_eabi = "arm-none-eabi-ar" +AR_armv4t_none_eabi = "arm-none-eabi-ar" +AR_thumbv4t_none_eabi = "arm-none-eabi-ar" \ No newline at end of file diff --git a/examples/versatileab/Cargo.toml b/examples/versatileab/Cargo.toml index d46ab1bb..e6737849 100644 --- a/examples/versatileab/Cargo.toml +++ b/examples/versatileab/Cargo.toml @@ -18,6 +18,7 @@ version = "0.0.0" aarch32-cpu = { path = "../../aarch32-cpu", features = ["critical-section-single-core"] } aarch32-rt = { path = "../../aarch32-rt" } arbitrary-int = "2.1.1" +c-code = { version = "0.1.0", path = "../c-code" } derive-mmio = "0.6.1" libm = "0.2.15" pl190-vic = "0.1.2" diff --git a/examples/versatileab/reference/c_test-armv4t-none-eabi.out b/examples/versatileab/reference/c_test-armv4t-none-eabi.out new file mode 100644 index 00000000..4c625b69 --- /dev/null +++ b/examples/versatileab/reference/c_test-armv4t-none-eabi.out @@ -0,0 +1,15 @@ +c_code_char_check(p) -> 2 +c_code_unsigned_char_check(p) -> 2 +c_code_signed_char_check(p) -> 2 +c_code_short_check(p) -> 2 +c_code_unsigned_short_check(p) -> 2 +c_code_int_check(p) -> 2 +c_code_unsigned_int_check(p) -> 2 +c_code_long_check(p) -> 2 +c_code_unsigned_long_check(p) -> 2 +c_code_int_ptr_check(p) -> 2 +c_code_float_check(p) -> 2 +c_code_double_check(p) -> 2 +data_in: c_code_data_t { c: 1, s: 1, i: 1, l: 1, f: 1.0, d: 1.0, e: 1 } +c_code_struct_check(data_in) -> c_code_data_t { c: 2, s: 2, i: 2, l: 2, f: 2.0, d: 2.0, e: 2 } +called c_code_struct_ref_check, data_in is c_code_data_t { c: 2, s: 2, i: 2, l: 2, f: 2.0, d: 2.0, e: 2 } diff --git a/examples/versatileab/reference/c_test-armv5te-none-eabi.out b/examples/versatileab/reference/c_test-armv5te-none-eabi.out new file mode 100644 index 00000000..4c625b69 --- /dev/null +++ b/examples/versatileab/reference/c_test-armv5te-none-eabi.out @@ -0,0 +1,15 @@ +c_code_char_check(p) -> 2 +c_code_unsigned_char_check(p) -> 2 +c_code_signed_char_check(p) -> 2 +c_code_short_check(p) -> 2 +c_code_unsigned_short_check(p) -> 2 +c_code_int_check(p) -> 2 +c_code_unsigned_int_check(p) -> 2 +c_code_long_check(p) -> 2 +c_code_unsigned_long_check(p) -> 2 +c_code_int_ptr_check(p) -> 2 +c_code_float_check(p) -> 2 +c_code_double_check(p) -> 2 +data_in: c_code_data_t { c: 1, s: 1, i: 1, l: 1, f: 1.0, d: 1.0, e: 1 } +c_code_struct_check(data_in) -> c_code_data_t { c: 2, s: 2, i: 2, l: 2, f: 2.0, d: 2.0, e: 2 } +called c_code_struct_ref_check, data_in is c_code_data_t { c: 2, s: 2, i: 2, l: 2, f: 2.0, d: 2.0, e: 2 } diff --git a/examples/versatileab/reference/c_test-armv6-none-eabi.out b/examples/versatileab/reference/c_test-armv6-none-eabi.out new file mode 100644 index 00000000..4c625b69 --- /dev/null +++ b/examples/versatileab/reference/c_test-armv6-none-eabi.out @@ -0,0 +1,15 @@ +c_code_char_check(p) -> 2 +c_code_unsigned_char_check(p) -> 2 +c_code_signed_char_check(p) -> 2 +c_code_short_check(p) -> 2 +c_code_unsigned_short_check(p) -> 2 +c_code_int_check(p) -> 2 +c_code_unsigned_int_check(p) -> 2 +c_code_long_check(p) -> 2 +c_code_unsigned_long_check(p) -> 2 +c_code_int_ptr_check(p) -> 2 +c_code_float_check(p) -> 2 +c_code_double_check(p) -> 2 +data_in: c_code_data_t { c: 1, s: 1, i: 1, l: 1, f: 1.0, d: 1.0, e: 1 } +c_code_struct_check(data_in) -> c_code_data_t { c: 2, s: 2, i: 2, l: 2, f: 2.0, d: 2.0, e: 2 } +called c_code_struct_ref_check, data_in is c_code_data_t { c: 2, s: 2, i: 2, l: 2, f: 2.0, d: 2.0, e: 2 } diff --git a/examples/versatileab/reference/c_test-armv6-none-eabihf.out b/examples/versatileab/reference/c_test-armv6-none-eabihf.out new file mode 100644 index 00000000..4c625b69 --- /dev/null +++ b/examples/versatileab/reference/c_test-armv6-none-eabihf.out @@ -0,0 +1,15 @@ +c_code_char_check(p) -> 2 +c_code_unsigned_char_check(p) -> 2 +c_code_signed_char_check(p) -> 2 +c_code_short_check(p) -> 2 +c_code_unsigned_short_check(p) -> 2 +c_code_int_check(p) -> 2 +c_code_unsigned_int_check(p) -> 2 +c_code_long_check(p) -> 2 +c_code_unsigned_long_check(p) -> 2 +c_code_int_ptr_check(p) -> 2 +c_code_float_check(p) -> 2 +c_code_double_check(p) -> 2 +data_in: c_code_data_t { c: 1, s: 1, i: 1, l: 1, f: 1.0, d: 1.0, e: 1 } +c_code_struct_check(data_in) -> c_code_data_t { c: 2, s: 2, i: 2, l: 2, f: 2.0, d: 2.0, e: 2 } +called c_code_struct_ref_check, data_in is c_code_data_t { c: 2, s: 2, i: 2, l: 2, f: 2.0, d: 2.0, e: 2 } diff --git a/examples/versatileab/reference/c_test-armv7a-none-eabi.out b/examples/versatileab/reference/c_test-armv7a-none-eabi.out new file mode 100644 index 00000000..4c625b69 --- /dev/null +++ b/examples/versatileab/reference/c_test-armv7a-none-eabi.out @@ -0,0 +1,15 @@ +c_code_char_check(p) -> 2 +c_code_unsigned_char_check(p) -> 2 +c_code_signed_char_check(p) -> 2 +c_code_short_check(p) -> 2 +c_code_unsigned_short_check(p) -> 2 +c_code_int_check(p) -> 2 +c_code_unsigned_int_check(p) -> 2 +c_code_long_check(p) -> 2 +c_code_unsigned_long_check(p) -> 2 +c_code_int_ptr_check(p) -> 2 +c_code_float_check(p) -> 2 +c_code_double_check(p) -> 2 +data_in: c_code_data_t { c: 1, s: 1, i: 1, l: 1, f: 1.0, d: 1.0, e: 1 } +c_code_struct_check(data_in) -> c_code_data_t { c: 2, s: 2, i: 2, l: 2, f: 2.0, d: 2.0, e: 2 } +called c_code_struct_ref_check, data_in is c_code_data_t { c: 2, s: 2, i: 2, l: 2, f: 2.0, d: 2.0, e: 2 } diff --git a/examples/versatileab/reference/c_test-armv7a-none-eabihf.out b/examples/versatileab/reference/c_test-armv7a-none-eabihf.out new file mode 100644 index 00000000..4c625b69 --- /dev/null +++ b/examples/versatileab/reference/c_test-armv7a-none-eabihf.out @@ -0,0 +1,15 @@ +c_code_char_check(p) -> 2 +c_code_unsigned_char_check(p) -> 2 +c_code_signed_char_check(p) -> 2 +c_code_short_check(p) -> 2 +c_code_unsigned_short_check(p) -> 2 +c_code_int_check(p) -> 2 +c_code_unsigned_int_check(p) -> 2 +c_code_long_check(p) -> 2 +c_code_unsigned_long_check(p) -> 2 +c_code_int_ptr_check(p) -> 2 +c_code_float_check(p) -> 2 +c_code_double_check(p) -> 2 +data_in: c_code_data_t { c: 1, s: 1, i: 1, l: 1, f: 1.0, d: 1.0, e: 1 } +c_code_struct_check(data_in) -> c_code_data_t { c: 2, s: 2, i: 2, l: 2, f: 2.0, d: 2.0, e: 2 } +called c_code_struct_ref_check, data_in is c_code_data_t { c: 2, s: 2, i: 2, l: 2, f: 2.0, d: 2.0, e: 2 } diff --git a/examples/versatileab/reference/c_test-armv7r-none-eabi.out b/examples/versatileab/reference/c_test-armv7r-none-eabi.out new file mode 100644 index 00000000..4c625b69 --- /dev/null +++ b/examples/versatileab/reference/c_test-armv7r-none-eabi.out @@ -0,0 +1,15 @@ +c_code_char_check(p) -> 2 +c_code_unsigned_char_check(p) -> 2 +c_code_signed_char_check(p) -> 2 +c_code_short_check(p) -> 2 +c_code_unsigned_short_check(p) -> 2 +c_code_int_check(p) -> 2 +c_code_unsigned_int_check(p) -> 2 +c_code_long_check(p) -> 2 +c_code_unsigned_long_check(p) -> 2 +c_code_int_ptr_check(p) -> 2 +c_code_float_check(p) -> 2 +c_code_double_check(p) -> 2 +data_in: c_code_data_t { c: 1, s: 1, i: 1, l: 1, f: 1.0, d: 1.0, e: 1 } +c_code_struct_check(data_in) -> c_code_data_t { c: 2, s: 2, i: 2, l: 2, f: 2.0, d: 2.0, e: 2 } +called c_code_struct_ref_check, data_in is c_code_data_t { c: 2, s: 2, i: 2, l: 2, f: 2.0, d: 2.0, e: 2 } diff --git a/examples/versatileab/reference/c_test-armv7r-none-eabihf.out b/examples/versatileab/reference/c_test-armv7r-none-eabihf.out new file mode 100644 index 00000000..4c625b69 --- /dev/null +++ b/examples/versatileab/reference/c_test-armv7r-none-eabihf.out @@ -0,0 +1,15 @@ +c_code_char_check(p) -> 2 +c_code_unsigned_char_check(p) -> 2 +c_code_signed_char_check(p) -> 2 +c_code_short_check(p) -> 2 +c_code_unsigned_short_check(p) -> 2 +c_code_int_check(p) -> 2 +c_code_unsigned_int_check(p) -> 2 +c_code_long_check(p) -> 2 +c_code_unsigned_long_check(p) -> 2 +c_code_int_ptr_check(p) -> 2 +c_code_float_check(p) -> 2 +c_code_double_check(p) -> 2 +data_in: c_code_data_t { c: 1, s: 1, i: 1, l: 1, f: 1.0, d: 1.0, e: 1 } +c_code_struct_check(data_in) -> c_code_data_t { c: 2, s: 2, i: 2, l: 2, f: 2.0, d: 2.0, e: 2 } +called c_code_struct_ref_check, data_in is c_code_data_t { c: 2, s: 2, i: 2, l: 2, f: 2.0, d: 2.0, e: 2 } diff --git a/examples/versatileab/reference/c_test-thumbv4t-none-eabi.out b/examples/versatileab/reference/c_test-thumbv4t-none-eabi.out new file mode 100644 index 00000000..4c625b69 --- /dev/null +++ b/examples/versatileab/reference/c_test-thumbv4t-none-eabi.out @@ -0,0 +1,15 @@ +c_code_char_check(p) -> 2 +c_code_unsigned_char_check(p) -> 2 +c_code_signed_char_check(p) -> 2 +c_code_short_check(p) -> 2 +c_code_unsigned_short_check(p) -> 2 +c_code_int_check(p) -> 2 +c_code_unsigned_int_check(p) -> 2 +c_code_long_check(p) -> 2 +c_code_unsigned_long_check(p) -> 2 +c_code_int_ptr_check(p) -> 2 +c_code_float_check(p) -> 2 +c_code_double_check(p) -> 2 +data_in: c_code_data_t { c: 1, s: 1, i: 1, l: 1, f: 1.0, d: 1.0, e: 1 } +c_code_struct_check(data_in) -> c_code_data_t { c: 2, s: 2, i: 2, l: 2, f: 2.0, d: 2.0, e: 2 } +called c_code_struct_ref_check, data_in is c_code_data_t { c: 2, s: 2, i: 2, l: 2, f: 2.0, d: 2.0, e: 2 } diff --git a/examples/versatileab/reference/c_test-thumbv5te-none-eabi.out b/examples/versatileab/reference/c_test-thumbv5te-none-eabi.out new file mode 100644 index 00000000..4c625b69 --- /dev/null +++ b/examples/versatileab/reference/c_test-thumbv5te-none-eabi.out @@ -0,0 +1,15 @@ +c_code_char_check(p) -> 2 +c_code_unsigned_char_check(p) -> 2 +c_code_signed_char_check(p) -> 2 +c_code_short_check(p) -> 2 +c_code_unsigned_short_check(p) -> 2 +c_code_int_check(p) -> 2 +c_code_unsigned_int_check(p) -> 2 +c_code_long_check(p) -> 2 +c_code_unsigned_long_check(p) -> 2 +c_code_int_ptr_check(p) -> 2 +c_code_float_check(p) -> 2 +c_code_double_check(p) -> 2 +data_in: c_code_data_t { c: 1, s: 1, i: 1, l: 1, f: 1.0, d: 1.0, e: 1 } +c_code_struct_check(data_in) -> c_code_data_t { c: 2, s: 2, i: 2, l: 2, f: 2.0, d: 2.0, e: 2 } +called c_code_struct_ref_check, data_in is c_code_data_t { c: 2, s: 2, i: 2, l: 2, f: 2.0, d: 2.0, e: 2 } diff --git a/examples/versatileab/reference/c_test-thumbv6-none-eabi.out b/examples/versatileab/reference/c_test-thumbv6-none-eabi.out new file mode 100644 index 00000000..4c625b69 --- /dev/null +++ b/examples/versatileab/reference/c_test-thumbv6-none-eabi.out @@ -0,0 +1,15 @@ +c_code_char_check(p) -> 2 +c_code_unsigned_char_check(p) -> 2 +c_code_signed_char_check(p) -> 2 +c_code_short_check(p) -> 2 +c_code_unsigned_short_check(p) -> 2 +c_code_int_check(p) -> 2 +c_code_unsigned_int_check(p) -> 2 +c_code_long_check(p) -> 2 +c_code_unsigned_long_check(p) -> 2 +c_code_int_ptr_check(p) -> 2 +c_code_float_check(p) -> 2 +c_code_double_check(p) -> 2 +data_in: c_code_data_t { c: 1, s: 1, i: 1, l: 1, f: 1.0, d: 1.0, e: 1 } +c_code_struct_check(data_in) -> c_code_data_t { c: 2, s: 2, i: 2, l: 2, f: 2.0, d: 2.0, e: 2 } +called c_code_struct_ref_check, data_in is c_code_data_t { c: 2, s: 2, i: 2, l: 2, f: 2.0, d: 2.0, e: 2 } diff --git a/examples/versatileab/reference/c_test-thumbv7a-none-eabi.out b/examples/versatileab/reference/c_test-thumbv7a-none-eabi.out new file mode 100644 index 00000000..4c625b69 --- /dev/null +++ b/examples/versatileab/reference/c_test-thumbv7a-none-eabi.out @@ -0,0 +1,15 @@ +c_code_char_check(p) -> 2 +c_code_unsigned_char_check(p) -> 2 +c_code_signed_char_check(p) -> 2 +c_code_short_check(p) -> 2 +c_code_unsigned_short_check(p) -> 2 +c_code_int_check(p) -> 2 +c_code_unsigned_int_check(p) -> 2 +c_code_long_check(p) -> 2 +c_code_unsigned_long_check(p) -> 2 +c_code_int_ptr_check(p) -> 2 +c_code_float_check(p) -> 2 +c_code_double_check(p) -> 2 +data_in: c_code_data_t { c: 1, s: 1, i: 1, l: 1, f: 1.0, d: 1.0, e: 1 } +c_code_struct_check(data_in) -> c_code_data_t { c: 2, s: 2, i: 2, l: 2, f: 2.0, d: 2.0, e: 2 } +called c_code_struct_ref_check, data_in is c_code_data_t { c: 2, s: 2, i: 2, l: 2, f: 2.0, d: 2.0, e: 2 } diff --git a/examples/versatileab/reference/c_test-thumbv7a-none-eabihf.out b/examples/versatileab/reference/c_test-thumbv7a-none-eabihf.out new file mode 100644 index 00000000..4c625b69 --- /dev/null +++ b/examples/versatileab/reference/c_test-thumbv7a-none-eabihf.out @@ -0,0 +1,15 @@ +c_code_char_check(p) -> 2 +c_code_unsigned_char_check(p) -> 2 +c_code_signed_char_check(p) -> 2 +c_code_short_check(p) -> 2 +c_code_unsigned_short_check(p) -> 2 +c_code_int_check(p) -> 2 +c_code_unsigned_int_check(p) -> 2 +c_code_long_check(p) -> 2 +c_code_unsigned_long_check(p) -> 2 +c_code_int_ptr_check(p) -> 2 +c_code_float_check(p) -> 2 +c_code_double_check(p) -> 2 +data_in: c_code_data_t { c: 1, s: 1, i: 1, l: 1, f: 1.0, d: 1.0, e: 1 } +c_code_struct_check(data_in) -> c_code_data_t { c: 2, s: 2, i: 2, l: 2, f: 2.0, d: 2.0, e: 2 } +called c_code_struct_ref_check, data_in is c_code_data_t { c: 2, s: 2, i: 2, l: 2, f: 2.0, d: 2.0, e: 2 } diff --git a/examples/versatileab/reference/c_test-thumbv7r-none-eabi.out b/examples/versatileab/reference/c_test-thumbv7r-none-eabi.out new file mode 100644 index 00000000..4c625b69 --- /dev/null +++ b/examples/versatileab/reference/c_test-thumbv7r-none-eabi.out @@ -0,0 +1,15 @@ +c_code_char_check(p) -> 2 +c_code_unsigned_char_check(p) -> 2 +c_code_signed_char_check(p) -> 2 +c_code_short_check(p) -> 2 +c_code_unsigned_short_check(p) -> 2 +c_code_int_check(p) -> 2 +c_code_unsigned_int_check(p) -> 2 +c_code_long_check(p) -> 2 +c_code_unsigned_long_check(p) -> 2 +c_code_int_ptr_check(p) -> 2 +c_code_float_check(p) -> 2 +c_code_double_check(p) -> 2 +data_in: c_code_data_t { c: 1, s: 1, i: 1, l: 1, f: 1.0, d: 1.0, e: 1 } +c_code_struct_check(data_in) -> c_code_data_t { c: 2, s: 2, i: 2, l: 2, f: 2.0, d: 2.0, e: 2 } +called c_code_struct_ref_check, data_in is c_code_data_t { c: 2, s: 2, i: 2, l: 2, f: 2.0, d: 2.0, e: 2 } diff --git a/examples/versatileab/reference/c_test-thumbv7r-none-eabihf.out b/examples/versatileab/reference/c_test-thumbv7r-none-eabihf.out new file mode 100644 index 00000000..4c625b69 --- /dev/null +++ b/examples/versatileab/reference/c_test-thumbv7r-none-eabihf.out @@ -0,0 +1,15 @@ +c_code_char_check(p) -> 2 +c_code_unsigned_char_check(p) -> 2 +c_code_signed_char_check(p) -> 2 +c_code_short_check(p) -> 2 +c_code_unsigned_short_check(p) -> 2 +c_code_int_check(p) -> 2 +c_code_unsigned_int_check(p) -> 2 +c_code_long_check(p) -> 2 +c_code_unsigned_long_check(p) -> 2 +c_code_int_ptr_check(p) -> 2 +c_code_float_check(p) -> 2 +c_code_double_check(p) -> 2 +data_in: c_code_data_t { c: 1, s: 1, i: 1, l: 1, f: 1.0, d: 1.0, e: 1 } +c_code_struct_check(data_in) -> c_code_data_t { c: 2, s: 2, i: 2, l: 2, f: 2.0, d: 2.0, e: 2 } +called c_code_struct_ref_check, data_in is c_code_data_t { c: 2, s: 2, i: 2, l: 2, f: 2.0, d: 2.0, e: 2 } diff --git a/examples/versatileab/src/bin/c_test.rs b/examples/versatileab/src/bin/c_test.rs new file mode 100644 index 00000000..84c4dc84 --- /dev/null +++ b/examples/versatileab/src/bin/c_test.rs @@ -0,0 +1,73 @@ +//! EABI checking example program + +#![no_std] +#![no_main] + +use aarch32_rt::entry; +use semihosting::println; +use versatileab as _; + +/// The entry-point to the Rust application. +/// +/// It is called by the start-up. +#[entry] +fn my_main() -> ! { + versatileab::init(); + println!("c_code_char_check(p) -> {}", unsafe { + c_code::c_code_char_check(1) + }); + println!("c_code_unsigned_char_check(p) -> {}", unsafe { + c_code::c_code_unsigned_char_check(1) + }); + println!("c_code_signed_char_check(p) -> {}", unsafe { + c_code::c_code_signed_char_check(1) + }); + println!("c_code_short_check(p) -> {}", unsafe { + c_code::c_code_short_check(1) + }); + println!("c_code_unsigned_short_check(p) -> {}", unsafe { + c_code::c_code_unsigned_short_check(1) + }); + println!("c_code_int_check(p) -> {}", unsafe { + c_code::c_code_int_check(1) + }); + println!("c_code_unsigned_int_check(p) -> {}", unsafe { + c_code::c_code_unsigned_int_check(1) + }); + println!("c_code_long_check(p) -> {}", unsafe { + c_code::c_code_long_check(1) + }); + println!("c_code_unsigned_long_check(p) -> {}", unsafe { + c_code::c_code_unsigned_long_check(1) + }); + let mut integers = [1, 2]; + println!("c_code_int_ptr_check(p) -> {}", unsafe { + *c_code::c_code_int_ptr_check(integers.as_mut_ptr()) + }); + println!("c_code_float_check(p) -> {}", unsafe { + c_code::c_code_float_check(1.0) + }); + println!("c_code_double_check(p) -> {}", unsafe { + c_code::c_code_double_check(1.0) + }); + + let mut data_in = c_code::c_code_data_t { + c: 1, + s: 1, + i: 1, + l: 1, + f: 1.0, + d: 1.0, + e: c_code::c_code_sample_enum_t_ITEM_TWO, + }; + println!("data_in: {:x?}", data_in); + + println!("c_code_struct_check(data_in) -> {:x?}", unsafe { + c_code::c_code_struct_check(data_in) + }); + + unsafe { c_code::c_code_struct_ref_check(&mut data_in) }; + println!("called c_code_struct_ref_check, data_in is {:x?}", data_in); + + versatileab::exit(0); +} From c46bdd7a546a15ffddd99f4f8e98342973a7d3a5 Mon Sep 17 00:00:00 2001 From: Jonathan Pallant Date: Mon, 8 Jun 2026 16:22:16 +0100 Subject: [PATCH 3/6] Exclude c-code example from top-level build. It requires a C compiler and most CI jobs don't have one. --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 028ebb6a..45251816 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,11 +5,11 @@ exclude = [ "examples/mps3-an536", "examples/mps3-an536-smp", "examples/mps3-an536-el2", + "examples/c-code", ] members = [ "aarch32-cpu", "aarch32-rt", "aarch32-rt-macros", - "examples/c-code", ] resolver = "2" From 783ee7e4e3f02f173c24a16b6765ec8319969a45 Mon Sep 17 00:00:00 2001 From: Jonathan Pallant Date: Tue, 9 Jun 2026 16:30:57 +0100 Subject: [PATCH 4/6] Use fixed version of cc-rs --- examples/c-code/Cargo.toml | 2 +- examples/versatileab/.cargo/config.toml | 33 ------------------------- 2 files changed, 1 insertion(+), 34 deletions(-) diff --git a/examples/c-code/Cargo.toml b/examples/c-code/Cargo.toml index 32da2539..a1357bbf 100644 --- a/examples/c-code/Cargo.toml +++ b/examples/c-code/Cargo.toml @@ -7,4 +7,4 @@ edition = "2024" [build-dependencies] bindgen = "0.72.1" -cc = "1.2.63" +cc = { git = "https://github.com/jonathanpallant/cc-rs/", rev = "fa1aa64" } diff --git a/examples/versatileab/.cargo/config.toml b/examples/versatileab/.cargo/config.toml index d74ac2c3..a8c961ed 100644 --- a/examples/versatileab/.cargo/config.toml +++ b/examples/versatileab/.cargo/config.toml @@ -49,36 +49,3 @@ runner = "qemu-system-arm -machine versatileab -cpu arm926 -semihosting -nograph [build] target = "armv7r-none-eabihf" - -[env] -CC_armv7r_none_eabihf = "arm-none-eabi-gcc" -CC_thumbv7r_none_eabihf = "arm-none-eabi-gcc" -CC_armv7r_none_eabi = "arm-none-eabi-gcc" -CC_thumbv7r_none_eabi = "arm-none-eabi-gcc" -CC_armv7a_none_eabihf = "arm-none-eabi-gcc" -CC_thumbv7a_none_eabihf = "arm-none-eabi-gcc" -CC_armv7a_none_eabi = "arm-none-eabi-gcc" -CC_thumbv7a_none_eabi = "arm-none-eabi-gcc" -CC_armv6_none_eabihf = "arm-none-eabi-gcc" -CC_armv6_none_eabi = "arm-none-eabi-gcc" -CC_thumbv6_none_eabi = "arm-none-eabi-gcc" -CC_armv5te_none_eabi = "arm-none-eabi-gcc" -CC_thumbv5te_none_eabi = "arm-none-eabi-gcc" -CC_armv4t_none_eabi = "arm-none-eabi-gcc" -CC_thumbv4t_none_eabi = "arm-none-eabi-gcc" - -AR_armv7r_none_eabihf = "arm-none-eabi-ar" -AR_thumbv7r_none_eabihf = "arm-none-eabi-ar" -AR_armv7r_none_eabi = "arm-none-eabi-ar" -AR_thumbv7r_none_eabi = "arm-none-eabi-ar" -AR_armv7a_none_eabihf = "arm-none-eabi-ar" -AR_thumbv7a_none_eabihf = "arm-none-eabi-ar" -AR_armv7a_none_eabi = "arm-none-eabi-ar" -AR_thumbv7a_none_eabi = "arm-none-eabi-ar" -AR_armv6_none_eabihf = "arm-none-eabi-ar" -AR_armv6_none_eabi = "arm-none-eabi-ar" -AR_thumbv6_none_eabi = "arm-none-eabi-ar" -AR_armv5te_none_eabi = "arm-none-eabi-ar" -AR_thumbv5te_none_eabi = "arm-none-eabi-ar" -AR_armv4t_none_eabi = "arm-none-eabi-ar" -AR_thumbv4t_none_eabi = "arm-none-eabi-ar" \ No newline at end of file From 4510bd1853071bb69007d114be27de932c2cd94b Mon Sep 17 00:00:00 2001 From: Jonathan Pallant Date: Tue, 9 Jun 2026 16:32:30 +0100 Subject: [PATCH 5/6] Add EABI tests to mps3-an536 examples. --- examples/mps3-an536/Cargo.toml | 1 + .../reference/c_test-armv8r-none-eabihf.out | 15 ++++ .../reference/c_test-thumbv8r-none-eabihf.out | 15 ++++ examples/mps3-an536/src/bin/c_test.rs | 73 +++++++++++++++++++ 4 files changed, 104 insertions(+) create mode 100644 examples/mps3-an536/reference/c_test-armv8r-none-eabihf.out create mode 100644 examples/mps3-an536/reference/c_test-thumbv8r-none-eabihf.out create mode 100644 examples/mps3-an536/src/bin/c_test.rs diff --git a/examples/mps3-an536/Cargo.toml b/examples/mps3-an536/Cargo.toml index 835f500f..c02c6bad 100644 --- a/examples/mps3-an536/Cargo.toml +++ b/examples/mps3-an536/Cargo.toml @@ -18,6 +18,7 @@ version = "0.0.0" aarch32-cpu = { path = "../../aarch32-cpu", features = ["critical-section-multi-core"] } aarch32-rt = { path = "../../aarch32-rt" } arm-gic = "0.8.1" +c-code = { version = "0.1.0", path = "../c-code" } critical-section = "1.2.0" heapless = "0.9.1" libm = "0.2.15" diff --git a/examples/mps3-an536/reference/c_test-armv8r-none-eabihf.out b/examples/mps3-an536/reference/c_test-armv8r-none-eabihf.out new file mode 100644 index 00000000..4c625b69 --- /dev/null +++ b/examples/mps3-an536/reference/c_test-armv8r-none-eabihf.out @@ -0,0 +1,15 @@ +c_code_char_check(p) -> 2 +c_code_unsigned_char_check(p) -> 2 +c_code_signed_char_check(p) -> 2 +c_code_short_check(p) -> 2 +c_code_unsigned_short_check(p) -> 2 +c_code_int_check(p) -> 2 +c_code_unsigned_int_check(p) -> 2 +c_code_long_check(p) -> 2 +c_code_unsigned_long_check(p) -> 2 +c_code_int_ptr_check(p) -> 2 +c_code_float_check(p) -> 2 +c_code_double_check(p) -> 2 +data_in: c_code_data_t { c: 1, s: 1, i: 1, l: 1, f: 1.0, d: 1.0, e: 1 } +c_code_struct_check(data_in) -> c_code_data_t { c: 2, s: 2, i: 2, l: 2, f: 2.0, d: 2.0, e: 2 } +called c_code_struct_ref_check, data_in is c_code_data_t { c: 2, s: 2, i: 2, l: 2, f: 2.0, d: 2.0, e: 2 } diff --git a/examples/mps3-an536/reference/c_test-thumbv8r-none-eabihf.out b/examples/mps3-an536/reference/c_test-thumbv8r-none-eabihf.out new file mode 100644 index 00000000..4c625b69 --- /dev/null +++ b/examples/mps3-an536/reference/c_test-thumbv8r-none-eabihf.out @@ -0,0 +1,15 @@ +c_code_char_check(p) -> 2 +c_code_unsigned_char_check(p) -> 2 +c_code_signed_char_check(p) -> 2 +c_code_short_check(p) -> 2 +c_code_unsigned_short_check(p) -> 2 +c_code_int_check(p) -> 2 +c_code_unsigned_int_check(p) -> 2 +c_code_long_check(p) -> 2 +c_code_unsigned_long_check(p) -> 2 +c_code_int_ptr_check(p) -> 2 +c_code_float_check(p) -> 2 +c_code_double_check(p) -> 2 +data_in: c_code_data_t { c: 1, s: 1, i: 1, l: 1, f: 1.0, d: 1.0, e: 1 } +c_code_struct_check(data_in) -> c_code_data_t { c: 2, s: 2, i: 2, l: 2, f: 2.0, d: 2.0, e: 2 } +called c_code_struct_ref_check, data_in is c_code_data_t { c: 2, s: 2, i: 2, l: 2, f: 2.0, d: 2.0, e: 2 } diff --git a/examples/mps3-an536/src/bin/c_test.rs b/examples/mps3-an536/src/bin/c_test.rs new file mode 100644 index 00000000..ecbeac73 --- /dev/null +++ b/examples/mps3-an536/src/bin/c_test.rs @@ -0,0 +1,73 @@ +//! EABI checking example program + +#![no_std] +#![no_main] + +use aarch32_rt::entry; +use semihosting::println; + +use mps3_an536 as _; + +/// The entry-point to the Rust application. +/// +/// It is called by the start-up code in `aarch32-rt`. +#[entry] +fn main() -> ! { + println!("c_code_char_check(p) -> {}", unsafe { + c_code::c_code_char_check(1) + }); + println!("c_code_unsigned_char_check(p) -> {}", unsafe { + c_code::c_code_unsigned_char_check(1) + }); + println!("c_code_signed_char_check(p) -> {}", unsafe { + c_code::c_code_signed_char_check(1) + }); + println!("c_code_short_check(p) -> {}", unsafe { + c_code::c_code_short_check(1) + }); + println!("c_code_unsigned_short_check(p) -> {}", unsafe { + c_code::c_code_unsigned_short_check(1) + }); + println!("c_code_int_check(p) -> {}", unsafe { + c_code::c_code_int_check(1) + }); + println!("c_code_unsigned_int_check(p) -> {}", unsafe { + c_code::c_code_unsigned_int_check(1) + }); + println!("c_code_long_check(p) -> {}", unsafe { + c_code::c_code_long_check(1) + }); + println!("c_code_unsigned_long_check(p) -> {}", unsafe { + c_code::c_code_unsigned_long_check(1) + }); + let mut integers = [1, 2]; + println!("c_code_int_ptr_check(p) -> {}", unsafe { + *c_code::c_code_int_ptr_check(integers.as_mut_ptr()) + }); + println!("c_code_float_check(p) -> {}", unsafe { + c_code::c_code_float_check(1.0) + }); + println!("c_code_double_check(p) -> {}", unsafe { + c_code::c_code_double_check(1.0) + }); + + let mut data_in = c_code::c_code_data_t { + c: 1, + s: 1, + i: 1, + l: 1, + f: 1.0, + d: 1.0, + e: c_code::c_code_sample_enum_t_ITEM_TWO, + }; + println!("data_in: {:x?}", data_in); + + println!("c_code_struct_check(data_in) -> {:x?}", unsafe { + c_code::c_code_struct_check(data_in) + }); + + unsafe { c_code::c_code_struct_ref_check(&mut data_in) }; + println!("called c_code_struct_ref_check, data_in is {:x?}", data_in); + + mps3_an536::exit(0); +} From 59aea55bf599c3684427b8fe47a775bcf6df41ba Mon Sep 17 00:00:00 2001 From: Jonathan Pallant Date: Fri, 12 Jun 2026 16:11:12 +0100 Subject: [PATCH 6/6] Use latest cc-rs release --- examples/c-code/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/c-code/Cargo.toml b/examples/c-code/Cargo.toml index a1357bbf..c8fe3335 100644 --- a/examples/c-code/Cargo.toml +++ b/examples/c-code/Cargo.toml @@ -7,4 +7,4 @@ edition = "2024" [build-dependencies] bindgen = "0.72.1" -cc = { git = "https://github.com/jonathanpallant/cc-rs/", rev = "fa1aa64" } +cc = "1.2.64"