Skip to content

Commit 6d32ccc

Browse files
committed
feat(port_std): support AArch64
1 parent f2d38b0 commit 6d32ccc

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- `r3_port_std`'s POSIX backend now supports AArch64.
13+
1014
### Fixed
1115

1216
- Fixed: Wrap const generic arguments in braces, fixing builds on the latest compiler version

src/r3_port_std/src/threading_unix.rs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,53 @@ fn catch_longjmp<F: FnOnce(JmpBuf)>(cb: F) {
376376
lateout("r15") _,
377377
);
378378
}
379+
380+
#[cfg(target_arch = "aarch64")]
381+
() => {
382+
asm!(
383+
"
384+
# push context
385+
adr x2, 0f
386+
str x2, [sp, #-32]!
387+
stp x29, x30, [sp, #16]
388+
389+
# do f(ctx, jmp_buf)
390+
# [rdi = ctx, rsp = jmp_buf]
391+
mov x1, sp
392+
blr {f}
393+
394+
b 1f
395+
0:
396+
# longjmp called. restore context
397+
ldp x29, x30, [sp, #16]
398+
399+
1:
400+
# discard context
401+
add sp, sp, #32
402+
",
403+
f = inlateout(reg) f => _,
404+
inlateout("x0") ctx => _,
405+
// AArch64 callee-saved registers
406+
lateout("x19") _,
407+
lateout("x20") _,
408+
lateout("x21") _,
409+
lateout("x22") _,
410+
lateout("x23") _,
411+
lateout("x24") _,
412+
lateout("x25") _,
413+
lateout("x26") _,
414+
lateout("x27") _,
415+
lateout("x28") _,
416+
lateout("d8") _,
417+
lateout("d9") _,
418+
lateout("d10") _,
419+
lateout("d11") _,
420+
lateout("d12") _,
421+
lateout("d13") _,
422+
lateout("d14") _,
423+
lateout("d15") _,
424+
);
425+
}
379426
}
380427
}
381428
}
@@ -417,6 +464,19 @@ unsafe fn longjmp(jmp_buf: JmpBuf) -> ! {
417464
options(noreturn),
418465
);
419466
}
467+
468+
#[cfg(target_arch = "aarch64")]
469+
() => {
470+
asm!(
471+
"
472+
mov sp, {}
473+
ldr x0, [sp, #0]
474+
br x0
475+
",
476+
in(reg) jmp_buf.sp.as_ptr(),
477+
options(noreturn),
478+
);
479+
}
420480
}
421481
}
422482
}

0 commit comments

Comments
 (0)