Skip to content
Open
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
20 changes: 12 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 /
Expand All @@ -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 /
Expand All @@ -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 /
Expand All @@ -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 /
Expand All @@ -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 /
Expand All @@ -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 /
Expand All @@ -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 /
Expand All @@ -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 /
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ exclude = [
"examples/mps3-an536",
"examples/mps3-an536-smp",
"examples/mps3-an536-el2",
"examples/c-code",
]
members = [
"aarch32-cpu",
Expand Down
10 changes: 10 additions & 0 deletions examples/c-code/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "c-code"
version = "0.1.0"
edition = "2024"

[dependencies]

[build-dependencies]
bindgen = "0.72.1"
cc = "1.2.64"
5 changes: 5 additions & 0 deletions examples/c-code/README.md
Original file line number Diff line number Diff line change
@@ -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.
19 changes: 19 additions & 0 deletions examples/c-code/build.rs
Original file line number Diff line number Diff line change
@@ -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");
}
5 changes: 5 additions & 0 deletions examples/c-code/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#![no_std]
#![allow(non_camel_case_types)]
#![allow(non_upper_case_globals)]

include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
98 changes: 98 additions & 0 deletions examples/c-code/src/library.c
Original file line number Diff line number Diff line change
@@ -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
*/
80 changes: 80 additions & 0 deletions examples/c-code/src/library.h
Original file line number Diff line number Diff line change
@@ -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
*/
2 changes: 1 addition & 1 deletion examples/mps3-an536-el2/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down
2 changes: 1 addition & 1 deletion examples/mps3-an536-smp/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down
1 change: 1 addition & 0 deletions examples/mps3-an536/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion examples/mps3-an536/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down
15 changes: 15 additions & 0 deletions examples/mps3-an536/reference/c_test-armv8r-none-eabihf.out
Original file line number Diff line number Diff line change
@@ -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 }
15 changes: 15 additions & 0 deletions examples/mps3-an536/reference/c_test-thumbv8r-none-eabihf.out
Original file line number Diff line number Diff line change
@@ -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 }
Loading
Loading