[libc-commits] [libc] [libc][arm] implement a basic setjmp/longjmp (PR #93220)

Nick Desaulniers via libc-commits libc-commits at lists.llvm.org
Fri May 31 15:16:32 PDT 2024


================
@@ -0,0 +1,59 @@
+//===-- Implementation of setjmp ------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/__support/common.h"
+#include "src/setjmp/setjmp_impl.h"
+
+namespace LIBC_NAMESPACE {
+
+#if defined(__thumb__) && __ARM_ARCH_ISA_THUMB == 1
+
+[[gnu::naked, gnu::target("thumb")]]
+LLVM_LIBC_FUNCTION(int, setjmp, (__jmp_buf * buf)) {
+  asm(R"(
+      # Store r4, r5, r6, and r7 into buf.
+      stmia r0!, {r4-r7}
+
+      # Store r8, r9, r10, r11, sp, and lr into buf. Thumb(1) doesn't support
+      # the high registers > r7 in stmia, so move them into lower GPRs first.
+      # Thumb(1) also doesn't support using str with sp or lr, move them
+      # together with the rest.
+      mov r2, r8
+      mov r3, r9
+      mov r4, r10
----------------
nickdesaulniers wrote:

good catch! 349e87430cfd

https://github.com/llvm/llvm-project/pull/93220


More information about the libc-commits mailing list