Author: tkreuzer
Date: Sat Dec 19 01:04:37 2009
New Revision: 44652
URL:
http://svn.reactos.org/svn/reactos?rev=44652&view=rev
Log:
[KDBG]
Port KdbEnter to amd64 assembly. Untested.
Added:
branches/ros-amd64-bringup/reactos/ntoskrnl/kdbg/amd64/kdb_help.S
- copied, changed from r44597,
branches/ros-amd64-bringup/reactos/ntoskrnl/kdbg/i386/kdb_help.S
Copied: branches/ros-amd64-bringup/reactos/ntoskrnl/kdbg/amd64/kdb_help.S (from r44597,
branches/ros-amd64-bringup/reactos/ntoskrnl/kdbg/i386/kdb_help.S)
URL:
http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/ntosk…
==============================================================================
--- branches/ros-amd64-bringup/reactos/ntoskrnl/kdbg/i386/kdb_help.S [iso-8859-1]
(original)
+++ branches/ros-amd64-bringup/reactos/ntoskrnl/kdbg/amd64/kdb_help.S [iso-8859-1] Sat Dec
19 01:04:37 2009
@@ -1,140 +1,127 @@
-#include <ndk/asm.h>
-.text
+#include <ndk/amd64/asm.h>
+#include <ndk/amd64/asmmacro.S>
.globl _KdbEnter
_KdbEnter:
- /*
- * Set up a trap frame
- */
- pushfl /* Eflags */
- pushl %cs /* Cs */
- pushl $0 /* ErrorCode */
- pushl %ebp /* Ebp */
- pushl %ebx /* Ebx */
- movl 20(%esp), %ebp /* Eip */
- movl 16(%esp), %ebx /* Eflags */
- movl %ebx, 20(%esp)
- movl 12(%esp), %ebx /* Cs */
- movl %ebx, 16(%esp)
- movl %ebp, 12(%esp)
- pushl %esi /* Esi */
- pushl %edi /* Edi */
- pushl %fs /* Fs */
- pushl $0 /* ExceptionList */
- pushl $0 /* PreviousMode */
- pushl %eax /* Eax */
- pushl %ecx /* Ecx */
- pushl %edx /* Edx */
- pushl %ds /* Ds */
- pushl %es /* Es */
- pushl %gs /* Gs */
- movl %dr7, %eax
- pushl %eax /* Dr7 */
+
+ /* save flags */
+ pushfq
+
+ /* Make room for a KTRAP_FRAME */
+ sub rsp, SIZE_KTRAP_FRAME
+ .allocstack SIZE_KTRAP_FRAME
+
+ /* Save rbp */
+ mov [rsp + KTRAP_FRAME_Rbp], rbp
+
+ /* Save non-volatile registers */
+ mov [rsp + KTRAP_FRAME_Rbx], rbx
+ mov [rsp + KTRAP_FRAME_Rdi], rdi
+ mov [rsp + KTRAP_FRAME_Rsi], rsi
+
+ /* Save volatile registers */
+ mov [rsp + KTRAP_FRAME_Rax], rax
+ mov [rsp + KTRAP_FRAME_Rcx], rcx
+ mov [rsp + KTRAP_FRAME_Rdx], rdx
+ mov [rsp + KTRAP_FRAME_R8], r8
+ mov [rsp + KTRAP_FRAME_R9], r9
+ mov [rsp + KTRAP_FRAME_R10], r10
+ mov [rsp + KTRAP_FRAME_R11], r11
+
+ /* Save xmm registers */
+// movdqa [rbp + KTRAP_FRAME_Xmm0], xmm0
+// movdqa [rbp + KTRAP_FRAME_Xmm1], xmm1
+// movdqa [rbp + KTRAP_FRAME_Xmm2], xmm2
+// movdqa [rbp + KTRAP_FRAME_Xmm3], xmm3
+// movdqa [rbp + KTRAP_FRAME_Xmm4], xmm4
+// movdqa [rbp + KTRAP_FRAME_Xmm5], xmm5
+
+ /* Save cs and previous mode */
+ mov ax, cs
+ mov [rsp + KTRAP_FRAME_SegCs], ax
+ and ax, 1
+ mov [rsp + KTRAP_FRAME_PreviousMode], al
+
+ /* Save segment selectors */
+ mov ax, ds
+ mov [rbp + KTRAP_FRAME_SegDs], ax
+ mov ax, es
+ mov [rbp + KTRAP_FRAME_SegEs], ax
+ mov ax, fs
+ mov [rbp + KTRAP_FRAME_SegFs], ax
+ mov ax, gs
+ mov [rbp + KTRAP_FRAME_SegGs], ax
+
+ /* Save previous irql */
+ mov rax, cr8
+ mov [rsp + KTRAP_FRAME_PreviousIrql], al
+
+ /* Save debug registers */
+ mov rax, dr0
+ mov [rsp + KTRAP_FRAME_Dr0], rax
+ mov rax, dr1
+ mov [rsp + KTRAP_FRAME_Dr1], rax
+ mov rax, dr2
+ mov [rsp + KTRAP_FRAME_Dr2], rax
+ mov rax, dr3
+ mov [rsp + KTRAP_FRAME_Dr3], rax
+ mov rax, dr6
+ mov [rsp + KTRAP_FRAME_Dr6], rax
+ mov rax, dr7
+ mov [rsp + KTRAP_FRAME_Dr7], rax
+
+ /* Point rbp, where rsp was initially */
+ lea rbp, [rsp + SIZE_KTRAP_FRAME + 8]
+ mov [rsp + KTRAP_FRAME_Rsp], rbp
+
+ /* Store the EFLAGS we previously pushed on the stack */
+ mov rax, [rbp]
+ mov [rsp + KTRAP_FRAME_EFlags], rax
+
+ /* Get RIP from the stack */
+ mov rax, [rbp + 8]
+ mov [rsp + KTRAP_FRAME_Rip], rax
+
+ /* Make sure the direction flag is cleared */
+ cld
/* Clear all breakpoint enables in dr7. */
- andl $0xFFFF0000, %eax
- movl %eax, %dr7
- movl %dr6, %eax
- pushl %eax /* Dr6 */
- movl %dr3, %eax
- pushl %eax /* Dr3 */
- movl %dr2, %eax
- pushl %eax /* Dr2 */
- movl %dr1, %eax
- pushl %eax /* Dr1 */
- movl %dr0, %eax
- pushl %eax /* Dr0 */
- leal 0x58(%esp), %eax
- pushl %eax /* TempEsp */
- pushl %ss /* TempSegSs */
- pushl $0 /* DebugPointer */
- pushl $3 /* DebugArgMark (Exception number) */
- pushl 0x60(%esp) /* DebugEip */
- pushl %ebp /* DebugEbp */
+ mov rax, dr7
+ and rax, 0xFFFF0000
+ mov dr7, rax
- /*
- * Call KDB
- */
- movl %esp, %eax
- pushl $1 /* FirstChance */
- pushl %eax /* Push a pointer to the trap frame */
- pushl $0 /* Context */
- pushl $0 /* PreviousMode (KernelMode) */
- pushl $0 /* ExceptionRecord */
- call _KdbEnterDebuggerException
+ /* Call KDB */
+ mov byte ptr [rsp + KTRAP_FRAME_P5], 1 /* FirstChance */
+ mov r9, rsp /* Pointer to the trap frame */
+ mov r8, 0 /* Context */
+ mov dl, 0 /* PreviousMode (KernelMode) */
+ mov rcx, 0 /* ExceptionRecord */
+ call _KdbEnterDebuggerException
- /*
- * Pop the arguments and unused portions of the trap frame:
- * DebugEbp
- * DebugEip
- * DebugArgMark
- * DebugPointer
- * TempSegSs
- * TempEsp
- */
- addl $(11*4), %esp
+ /* Restore segment selectors */
+ mov ax, [rsp + KTRAP_FRAME_SegDs]
+ mov ds, ax
+ mov ax, [rsp + KTRAP_FRAME_SegEs]
+ mov es, ax
+ mov ax, [rsp + KTRAP_FRAME_SegFs]
+ mov fs, ax
- /*
- * Restore/update debugging registers.
- */
- popl %eax /* Dr0 */
- movl %eax, %dr0
- popl %eax /* Dr1 */
- movl %eax, %dr1
- popl %eax /* Dr2 */
- movl %eax, %dr2
- popl %eax /* Dr3 */
- movl %eax, %dr3
- popl %eax /* Dr6 */
- movl %eax, %dr6
- popl %eax /* Dr7 */
- movl %eax, %dr7
+ /* Restore non-volatile registers */
+ mov rbx, [rsp + KTRAP_FRAME_Rbx]
+ mov rdi, [rsp + KTRAP_FRAME_Rdi]
+ mov rsi, [rsp + KTRAP_FRAME_Rsi]
- /*
- * Restore registers including any that might have been changed
- * inside the debugger.
- */
- popl %gs /* Gs */
- popl %es /* Es */
- popl %ds /* Ds */
- popl %edx /* Edx */
- popl %ecx /* Ecx */
- popl %eax /* Eax */
- addl $8, %esp /* PreviousMode, ExceptionList */
- popl %fs /* Fs */
- popl %edi /* Edi */
- popl %esi /* Esi */
- popl %ebx /* Ebx */
- popl %ebp /* Ebp */
- addl $4, %esp /* ErrorCode */
+ /* Restore volatile registers */
+ mov rax, [rsp + KTRAP_FRAME_Rax]
+ mov rcx, [rsp + KTRAP_FRAME_Rcx]
+ mov rdx, [rsp + KTRAP_FRAME_Rdx]
+ mov r8, [rsp + KTRAP_FRAME_R8]
+ mov r9, [rsp + KTRAP_FRAME_R9]
+ mov r10, [rsp + KTRAP_FRAME_R10]
+ mov r11, [rsp + KTRAP_FRAME_R11]
- /*
- * Return to the caller.
- */
+ /* Restore RSP */
+ mov rsp, [rsp + KTRAP_FRAME_Rsp]
+
iret
-
-
-.globl _KdbpStackSwitchAndCall@8
-_KdbpStackSwitchAndCall@8:
- pushl %ebp
- movl %esp, %ebp
-
- movl 0x8(%esp), %eax /* New stack */
- movl 0xC(%esp), %ecx /* Function to call */
- movl %esp, %edx /* Old stack */
-
- /* Switch stack */
- movl %eax, %esp
- pushl %edx
-
- /* Call function */
- call *%ecx
-
- /* Switch back to old stack */
- popl %esp
-
- /* Return */
- popl %ebp
- ret $8
-