[CRT]
authorTimo Kreuzer <timo.kreuzer@reactos.org>
Wed, 21 Jul 2010 00:26:51 +0000 (00:26 +0000)
committerTimo Kreuzer <timo.kreuzer@reactos.org>
Wed, 21 Jul 2010 00:26:51 +0000 (00:26 +0000)
- Add amd64 versions of setjmp / longjmp
- Add amd64 versions of chkstk_asm.s, seh.s to libcntpr

svn path=/trunk/; revision=48151

reactos/lib/sdk/crt/crt.rbuild
reactos/lib/sdk/crt/libcntpr.rbuild
reactos/lib/sdk/crt/setjmp/amd64/setjmp.s [new file with mode: 0644]

index 9821329..5100612 100644 (file)
                                <file>setjmp.s</file>
                        </directory>
                </if>
+               <if property="ARCH" value="amd64">
+                       <directory name="amd64">
+                               <file>setjmp.s</file>
+                       </directory>
+               </if>
        </directory>
        <directory name="signal">
                <file>signal.c</file>
index 6156fe0..198bdf5 100644 (file)
                                <file>seh.s</file>
                        </directory>
                </if>
+               <if property="ARCH" value="amd64">
+                       <directory name="amd64">
+                               <file>chkstk_asm.s</file>
+                               <file>seh.s</file>
+                       </directory>
+               </if>
                <if property="ARCH" value="powerpc">
                        <directory name="powerpc">
                                <file>chkstk_asm.s</file>
                                <file>setjmp.s</file>
                        </directory>
                </if>
+               <if property="ARCH" value="amd64">
+                       <directory name="amd64">
+                               <file>setjmp.s</file>
+                       </directory>
+               </if>
        </directory>
 
        <directory name="stdlib">
diff --git a/reactos/lib/sdk/crt/setjmp/amd64/setjmp.s b/reactos/lib/sdk/crt/setjmp/amd64/setjmp.s
new file mode 100644 (file)
index 0000000..56459ae
--- /dev/null
@@ -0,0 +1,158 @@
+/*
+ * COPYRIGHT:         See COPYING in the top level directory
+ * PROJECT:           ReactOS system libraries
+ * PURPOSE:           Implementation of _setjmp/longjmp
+ * FILE:              lib/sdk/crt/setjmp/amd64/setjmp.s
+ * PROGRAMMER:        Timo Kreuzer (timo.kreuzer@reactos.org)
+ */
+
+/* INCLUDES ******************************************************************/
+
+#include <reactos/asm.h>
+#include <ndk/amd64/asm.h>
+
+#define JUMP_BUFFER_Frame 0x00
+#define JUMP_BUFFER_Rbx   0x08
+#define JUMP_BUFFER_Rsp   0x10
+#define JUMP_BUFFER_Rbp   0x18
+#define JUMP_BUFFER_Rsi   0x20
+#define JUMP_BUFFER_Rdi   0x28
+#define JUMP_BUFFER_R12   0x30
+#define JUMP_BUFFER_R13   0x38
+#define JUMP_BUFFER_R14   0x40
+#define JUMP_BUFFER_R15   0x48
+#define JUMP_BUFFER_Rip   0x50
+#define JUMP_BUFFER_Spare 0x58
+#define JUMP_BUFFER_Xmm6  0x60
+#define JUMP_BUFFER_Xmm7  0x70
+#define JUMP_BUFFER_Xmm8  0x80
+#define JUMP_BUFFER_Xmm9  0x90
+#define JUMP_BUFFER_Xmm10 0xa0
+#define JUMP_BUFFER_Xmm11 0xb0
+#define JUMP_BUFFER_Xmm12 0xc0
+#define JUMP_BUFFER_Xmm13 0xd0
+#define JUMP_BUFFER_Xmm14 0xe0
+#define JUMP_BUFFER_Xmm15 0xf0
+
+
+/* FUNCTIONS ******************************************************************/
+
+/*
+ * int _setjmp(jmp_buf env);
+ *
+ * Parameters: <rcx> - jmp_buf env
+ * Returns:    0
+ * Notes:      Sets up the jmp_buf
+ */
+PUBLIC _setjmp
+.proc _setjmp
+    /* Load rsp as it was before the call into rax */
+    lea rax, [rsp + 8]
+    /* Load return address into r8 */
+    mov r8, [rsp]
+    mov qword ptr [rcx + JUMP_BUFFER_Frame], 0
+    mov [rcx + JUMP_BUFFER_Rbx], rbx
+    mov [rcx + JUMP_BUFFER_Rbp], rbp
+    mov [rcx + JUMP_BUFFER_Rsi], rsi
+    mov [rcx + JUMP_BUFFER_Rdi], rdi
+    mov [rcx + JUMP_BUFFER_R12], r12
+    mov [rcx + JUMP_BUFFER_R13], r13
+    mov [rcx + JUMP_BUFFER_R14], r14
+    mov [rcx + JUMP_BUFFER_R15], r15
+    mov [rcx + JUMP_BUFFER_Rsp], rax
+    mov [rcx + JUMP_BUFFER_Rip], r8
+    movdqa [rcx + JUMP_BUFFER_Xmm6], xmm6
+    movdqa [rcx + JUMP_BUFFER_Xmm7], xmm7
+    movdqa [rcx + JUMP_BUFFER_Xmm8], xmm8
+    movdqa [rcx + JUMP_BUFFER_Xmm9], xmm9
+    movdqa [rcx + JUMP_BUFFER_Xmm10], xmm10
+    movdqa [rcx + JUMP_BUFFER_Xmm11], xmm11
+    movdqa [rcx + JUMP_BUFFER_Xmm12], xmm12
+    movdqa [rcx + JUMP_BUFFER_Xmm13], xmm13
+    movdqa [rcx + JUMP_BUFFER_Xmm14], xmm14
+    movdqa [rcx + JUMP_BUFFER_Xmm15], xmm15
+    xor rax, rax
+    ret
+.endp setjmp
+
+/*
+ * int _setjmpex(jmp_buf _Buf,void *_Ctx);
+ *
+ * Parameters: <rcx> - jmp_buf env
+ *             <rdx> - frame
+ * Returns:    0
+ * Notes:      Sets up the jmp_buf
+ */
+PUBLIC _setjmpex
+.proc _setjmpex
+    /* Load rsp as it was before the call into rax */
+    lea rax, [rsp + 8]
+    /* Load return address into r8 */
+    mov r8, [rsp]
+    mov [rcx + JUMP_BUFFER_Frame], rdx
+    mov [rcx + JUMP_BUFFER_Rbx], rbx
+    mov [rcx + JUMP_BUFFER_Rbp], rbp
+    mov [rcx + JUMP_BUFFER_Rsi], rsi
+    mov [rcx + JUMP_BUFFER_Rdi], rdi
+    mov [rcx + JUMP_BUFFER_R12], r12
+    mov [rcx + JUMP_BUFFER_R13], r13
+    mov [rcx + JUMP_BUFFER_R14], r14
+    mov [rcx + JUMP_BUFFER_R15], r15
+    mov [rcx + JUMP_BUFFER_Rsp], rax
+    mov [rcx + JUMP_BUFFER_Rip], r8
+    movdqa [rcx + JUMP_BUFFER_Xmm6], xmm6
+    movdqa [rcx + JUMP_BUFFER_Xmm7], xmm7
+    movdqa [rcx + JUMP_BUFFER_Xmm8], xmm8
+    movdqa [rcx + JUMP_BUFFER_Xmm9], xmm9
+    movdqa [rcx + JUMP_BUFFER_Xmm10], xmm10
+    movdqa [rcx + JUMP_BUFFER_Xmm11], xmm11
+    movdqa [rcx + JUMP_BUFFER_Xmm12], xmm12
+    movdqa [rcx + JUMP_BUFFER_Xmm13], xmm13
+    movdqa [rcx + JUMP_BUFFER_Xmm14], xmm14
+    movdqa [rcx + JUMP_BUFFER_Xmm15], xmm15
+    xor rax, rax
+    ret
+.endp setjmpex
+
+
+/*
+ * void longjmp(jmp_buf env, int value);
+ *
+ * Parameters: <rcx> - jmp_buf setup by _setjmp
+ *             <rdx> - int     value to return
+ * Returns:    Doesn't return
+ * Notes:      Non-local goto
+ */
+PUBLIC longjmp
+.proc longjmp
+
+    // FIXME: handle frame
+
+    mov rbx, [rcx + JUMP_BUFFER_Rbx]
+    mov rbp, [rcx + JUMP_BUFFER_Rbp]
+    mov rsi, [rcx + JUMP_BUFFER_Rsi]
+    mov rdi, [rcx + JUMP_BUFFER_Rdi]
+    mov r12, [rcx + JUMP_BUFFER_R12]
+    mov r13, [rcx + JUMP_BUFFER_R13]
+    mov r14, [rcx + JUMP_BUFFER_R14]
+    mov r15, [rcx + JUMP_BUFFER_R15]
+    mov rsp, [rcx + JUMP_BUFFER_Rsp]
+    mov r8, [rcx + JUMP_BUFFER_Rip]
+    movdqa xmm6, [rcx + JUMP_BUFFER_Xmm6]
+    movdqa xmm7, [rcx + JUMP_BUFFER_Xmm7]
+    movdqa xmm8, [rcx + JUMP_BUFFER_Xmm8]
+    movdqa xmm9, [rcx + JUMP_BUFFER_Xmm9]
+    movdqa xmm10, [rcx + JUMP_BUFFER_Xmm10]
+    movdqa xmm11, [rcx + JUMP_BUFFER_Xmm11]
+    movdqa xmm12, [rcx + JUMP_BUFFER_Xmm12]
+    movdqa xmm13, [rcx + JUMP_BUFFER_Xmm13]
+    movdqa xmm14, [rcx + JUMP_BUFFER_Xmm14]
+    movdqa xmm15, [rcx + JUMP_BUFFER_Xmm15]
+
+    /* return param2 or 1 if it was 0 */
+    mov rax, rdx
+    test rax, rax
+    jnz 2f
+    inc rax
+2:  jmp r8
+.endp longjmp