Skip to content

Commit 3957e15

Browse files
author
Fox Snowpatch
committed
1 parent 25ce7a5 commit 3957e15

File tree

6 files changed

+27
-7
lines changed

6 files changed

+27
-7
lines changed

Documentation/rust/arch-support.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Architecture Level of support Constraints
1818
``arm`` Maintained ARMv7 Little Endian only.
1919
``arm64`` Maintained Little Endian only.
2020
``loongarch`` Maintained \-
21+
``powerpc`` Maintained 32-bit Big Endian only.
2122
``riscv`` Maintained ``riscv64`` and LLVM/Clang only.
2223
``um`` Maintained \-
2324
``x86`` Maintained ``x86_64`` only.

arch/powerpc/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ config PPC
283283
select HAVE_REGS_AND_STACK_ACCESS_API
284284
select HAVE_RELIABLE_STACKTRACE
285285
select HAVE_RSEQ
286+
select HAVE_RUST if PPC32
286287
select HAVE_SAMPLE_FTRACE_DIRECT if HAVE_DYNAMIC_FTRACE_WITH_DIRECT_CALLS
287288
select HAVE_SAMPLE_FTRACE_DIRECT_MULTI if HAVE_DYNAMIC_FTRACE_WITH_DIRECT_CALLS
288289
select HAVE_SETUP_PER_CPU_AREA if PPC64

arch/powerpc/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ else
6161
KBUILD_LDFLAGS_MODULE += $(objtree)/arch/powerpc/lib/crtsavres.o
6262
endif
6363

64+
KBUILD_RUSTFLAGS += --target=powerpc-unknown-linux-gnu
65+
6466
ifdef CONFIG_CPU_LITTLE_ENDIAN
6567
KBUILD_CPPFLAGS += -mlittle-endian
6668
KBUILD_LDFLAGS += -EL

arch/powerpc/include/asm/jump_label.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,18 @@
1515
#define JUMP_ENTRY_TYPE stringify_in_c(FTR_ENTRY_LONG)
1616
#define JUMP_LABEL_NOP_SIZE 4
1717

18+
/* This macro is also expanded on the Rust side. */
19+
#define ARCH_STATIC_BRANCH_ASM(key, label) \
20+
"1:\n\t" \
21+
"nop # arch_static_branch\n\t" \
22+
".pushsection __jump_table, \"aw\"\n\t" \
23+
".long 1b - ., " label " - .\n\t" \
24+
JUMP_ENTRY_TYPE key " - .\n\t" \
25+
".popsection \n\t"
26+
1827
static __always_inline bool arch_static_branch(struct static_key *key, bool branch)
1928
{
20-
asm goto("1:\n\t"
21-
"nop # arch_static_branch\n\t"
22-
".pushsection __jump_table, \"aw\"\n\t"
23-
".long 1b - ., %l[l_yes] - .\n\t"
24-
JUMP_ENTRY_TYPE "%c0 - .\n\t"
25-
".popsection \n\t"
29+
asm goto(ARCH_STATIC_BRANCH_ASM("%c0", "%l[l_yes]")
2630
: : "i" (&((char *)key)[branch]) : : l_yes);
2731

2832
return false;

rust/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,13 +383,15 @@ bindgen_skip_c_flags := -mno-fp-ret-in-387 -mpreferred-stack-boundary=% \
383383
-fno-inline-functions-called-once -fsanitize=bounds-strict \
384384
-fstrict-flex-arrays=% -fmin-function-alignment=% \
385385
-fzero-init-padding-bits=% -mno-fdpic \
386-
--param=% --param asan-% -fno-isolate-erroneous-paths-dereference
386+
--param=% --param asan-% -fno-isolate-erroneous-paths-dereference \
387+
-ffixed-r2 -mmultiple -mno-readonly-in-sdata
387388

388389
# Derived from `scripts/Makefile.clang`.
389390
BINDGEN_TARGET_x86 := x86_64-linux-gnu
390391
BINDGEN_TARGET_arm64 := aarch64-linux-gnu
391392
BINDGEN_TARGET_arm := arm-linux-gnueabi
392393
BINDGEN_TARGET_loongarch := loongarch64-linux-gnusf
394+
BINDGEN_TARGET_powerpc := powerpc-linux-gnu
393395
BINDGEN_TARGET_um := $(BINDGEN_TARGET_$(SUBARCH))
394396
BINDGEN_TARGET := $(BINDGEN_TARGET_$(SRCARCH))
395397

scripts/generate_rust_target.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,16 @@ fn main() {
188188
panic!("arm uses the builtin rustc target");
189189
} else if cfg.has("ARM64") {
190190
panic!("arm64 uses the builtin rustc aarch64-unknown-none target");
191+
} else if cfg.has("PPC32") {
192+
ts.push("arch", "powerpc");
193+
ts.push("data-layout", "E-m:e-p:32:32-Fn32-i64:64-n32");
194+
ts.push("features", "+soft-float");
195+
ts.push("llvm-target", "powerpc-unknown-eabi");
196+
if cfg.rustc_version_atleast(1, 91, 0) {
197+
ts.push("target-pointer-width", 32);
198+
} else {
199+
ts.push("target-pointer-width", "32");
200+
}
191201
} else if cfg.has("RISCV") {
192202
if cfg.has("64BIT") {
193203
panic!("64-bit RISC-V uses the builtin rustc riscv64-unknown-none-elf target");

0 commit comments

Comments
 (0)