This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch releases/12.7
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit a23ed77782302898787441605c46ecb6810382ac
Author: chenxiaoyi <[email protected]>
AuthorDate: Tue Jul 9 09:57:24 2024 +0800

    sim: add windows64 setjmp/longjmp support
    
    Signed-off-by: chenxiaoyi <[email protected]>
---
 libs/libc/machine/sim/CMakeLists.txt         |  6 +-
 libs/libc/machine/sim/arch_setjmp_x86_64.asm | 85 ++++++++++++++++++++++++++++
 2 files changed, 90 insertions(+), 1 deletion(-)

diff --git a/libs/libc/machine/sim/CMakeLists.txt 
b/libs/libc/machine/sim/CMakeLists.txt
index 22ccff0bdb..4cdcf8cfda 100644
--- a/libs/libc/machine/sim/CMakeLists.txt
+++ b/libs/libc/machine/sim/CMakeLists.txt
@@ -40,7 +40,11 @@ if(CONFIG_HOST_X86_64)
       list(APPEND SRCS arch_elf64.c)
     endif()
     if(CONFIG_ARCH_SETJMP_H)
-      list(APPEND SRCS arch_setjmp_x86_64.S)
+      if(WIN32)
+        list(APPEND SRCS arch_setjmp_x86_64.asm)
+      else()
+        list(APPEND SRCS arch_setjmp_x86_64.S)
+      endif()
     endif()
   endif()
 
diff --git a/libs/libc/machine/sim/arch_setjmp_x86_64.asm 
b/libs/libc/machine/sim/arch_setjmp_x86_64.asm
new file mode 100644
index 0000000000..2ef7f529fd
--- /dev/null
+++ b/libs/libc/machine/sim/arch_setjmp_x86_64.asm
@@ -0,0 +1,85 @@
+;***************************************************************************
+; libs/libc/machine/sim/arch_setjmp_x86_64.asm
+;
+; Licensed to the Apache Software Foundation (ASF) under one or more
+; contributor license agreements.  See the NOTICE file distributed with
+; this work for additional information regarding copyright ownership.  The
+; ASF licenses this file to you under the Apache License, Version 2.0 (the
+; "License"); you may not use this file except in compliance with the
+; License.  You may obtain a copy of the License at
+;
+;   http://www.apache.org/licenses/LICENSE-2.0
+;
+; Unless required by applicable law or agreed to in writing, software
+; distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+; WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+; License for the specific language governing permissions and limitations
+; under the License.
+;
+;***************************************************************************
+
+;***************************************************************************
+; Public Functions
+;***************************************************************************
+
+.code
+
+public setjmp
+public longjmp
+
+setjmp:
+
+       ; Get the return address, adjusting the stack pointer
+
+       pop rsi
+
+       ; Set up the return value
+
+       xor rax, rax
+
+       ; Save 1: rbx
+
+       mov [rcx], rbx
+
+       ; Save 2: Value of the rsp *after* returning
+
+       mov [rcx+8], rsp
+
+       ; Fix up the return stack
+
+       push rsi
+
+       ; Save registers
+       ; Storage order: %rbx, %rsp, %rbp, %r12, %r13, %r14, %r15, %rip
+
+       mov [rcx+10h], rbp
+       mov [rcx+18h], r12
+       mov [rcx+20h], r13
+       mov [rcx+28h], r14
+       mov [rcx+30h], r15
+       mov [rcx+38h], rsi
+
+       ret
+
+longjmp:
+
+       ; Setup return value
+
+       mov rax, rdx
+
+       ; Restore registers
+
+       mov rbx, [rcx]
+       mov rsp, [rcx+8]
+       mov rbp, [rcx+10h]
+       mov r12, [rcx+18h]
+       mov r13, [rcx+20h]
+       mov r14, [rcx+28h]
+       mov r15, [rcx+30h]
+
+       ; Jump to the saved return address (rsi)
+
+       jmp qword ptr [rcx+38h]
+
+end
+

Reply via email to