- Fix a bad bug in the system call handler and interrupt/trap exit code which was causing a jump to the incorrect epilogue if V86 mode was detected.

- Replaced most of the trap prolog code by the KiDebugService entry trap code from syscall.S. Eventually, after remaining bugs are fixed, the code will be shared across all traps and not duplicated anymore. (For documnetation's sake, changing the prolog has the following effects: DR registers are not saved anymore (they will be later), DS/ES are set to RPL3 DATA, not RPL0 DATA, GS is not touched (it shoudl be 0, not RPL0_DATA). PreviousMode is not touched at all, the Debug Trap Frame header is properly setup).

svn path=/trunk/; revision=20918
This commit is contained in:
Alex Ionescu 2006-01-16 19:32:55 +00:00
parent 707ff20f85
commit 4334f8a57f
2 changed files with 61 additions and 87 deletions

View file

@ -742,7 +742,7 @@ V86_Exit2:
pop edx pop edx
pop ecx pop ecx
pop eax pop eax
jmp V86_Exit_Return jmp V86_Exit_Return2
EditedFrame2: EditedFrame2:
/* Restore real CS value */ /* Restore real CS value */
@ -887,6 +887,7 @@ NotUserMode:
/* Exit through common routine */ /* Exit through common routine */
jmp Kei386EoiHelper@0 jmp Kei386EoiHelper@0
.globl Kei386EoiHelper@0
Kei386EoiHelper@0: Kei386EoiHelper@0:
/* Disable interrupts */ /* Disable interrupts */
@ -992,7 +993,7 @@ V86_Exit3:
pop edx pop edx
pop ecx pop ecx
pop eax pop eax
jmp V86_Exit_Return jmp V86_Exit_Return3
EditedFrame3: EditedFrame3:
/* Restore real CS value */ /* Restore real CS value */

View file

@ -15,6 +15,12 @@
#define KernelMode 0 #define KernelMode 0
#define UserMode 1 #define UserMode 1
/* NOTES:
* The epilog will be replaced by a call to Ki386EoiHelper when bugs are fixed.
* The prologue is currently a duplication of the trap enter code in KiDebugService.
* It will be made a macro and shared later.
*/
/* FUNCTIONS *****************************************************************/ /* FUNCTIONS *****************************************************************/
/* /*
@ -69,79 +75,62 @@ _KiTrapProlog2:
pushl %edi pushl %edi
pushl %fs pushl %fs
/* Make room for the previous mode and the exception list */ .intel_syntax noprefix
subl $8, %esp /* Load the PCR selector into fs */
mov edi, KGDT_R0_PCR
mov fs, di
/* Save other registers */ /* Push exception list and previous mode (invalid) */
pushl %eax push fs:[KPCR_EXCEPTION_LIST]
pushl %ecx push -1
pushl %edx
pushl %ds
pushl %es
pushl %gs
movl %dr7, %eax
pushl %eax /* Dr7 */
/* 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 0x64(%esp), %eax
pushl %eax /* XXX: TempESP */
pushl %ss /* XXX: TempSS */
pushl $0 /* XXX: DebugPointer */
pushl $0 /* XXX: DebugArgMark */
movl 0x60(%esp), %eax
pushl %eax /* XXX: DebugEIP */
pushl %ebp /* XXX: DebugEBP */
/* Load the segment registers */
movl $KGDT_R0_DATA, %eax
movl %eax, %ds
movl %eax, %es
movl %eax, %gs
/* save the trap frame */
movl %esp, %ebp
/* Load the PCR selector into fs */
movl $KGDT_R0_PCR, %eax
movl %eax, %fs
/* Save the old exception list */ /* Push volatiles and segments */
movl %fs:KPCR_EXCEPTION_LIST, %eax push eax
movl %eax, KTRAP_FRAME_EXCEPTION_LIST(%ebp) push ecx
push edx
/* Get a pointer to the current thread */ push ds
movl %fs:KPCR_CURRENT_THREAD, %edi push es
push gs
/* The current thread may be NULL early in the boot process */ /* Set the R3 data segment */
cmpl $0, %edi mov ax, KGDT_R3_DATA + RPL_MASK
je .L4
/* Skip debug registers and debug stuff */
/* Save the old previous mode */ sub esp, 0x30
movl $0, %eax
movb KTHREAD_PREVIOUS_MODE(%edi), %al /* Load the segment registers */
movl %eax, KTRAP_FRAME_PREVIOUS_MODE(%ebp) mov ds, ax
mov es, ax
/* Set the new previous mode based on the saved CS selector */
movl KTRAP_FRAME_CS(%ebp), %eax /* Set up frame */
andl $0x0000FFFF, %eax mov ebp, esp
/* Check if this was from V86 Mode */
test dword ptr [ebp+KTRAP_FRAME_EFLAGS], X86_EFLAGS_VM
//jnz V86_kids
/* Get current thread */
mov ecx, [fs:KPCR_CURRENT_THREAD]
cld
/* Flush DR7 */
and dword ptr [ebp+KTRAP_FRAME_DR7], 0
/* Check if the thread was being debugged */
//test byte ptr [ecx+KTHREAD_DEBUG_ACTIVE], 0xFF
//jnz Dr_kids
/* Get the Debug Trap Frame EBP/EIP */
mov ecx, [ebp+KTRAP_FRAME_EBP]
mov edi, [ebp+KTRAP_FRAME_EIP]
/* Write the debug data */
mov [ebp+KTRAP_FRAME_DEBUGPOINTER], edx
mov dword ptr [ebp+KTRAP_FRAME_DEBUGARGMARK], 0xBADB0D00
mov [ebp+KTRAP_FRAME_DEBUGEBP], ecx
mov [ebp+KTRAP_FRAME_DEBUGEIP], edi
.att_syntax
/* Save the old trap frame. */
movl KTHREAD_TRAP_FRAME(%edi), %edx
pushl %edx
/* Save a pointer to the trap frame in the current KTHREAD */
movl %ebp, KTHREAD_TRAP_FRAME(%edi)
.L6: .L6:
/* Call the C exception handler */ /* Call the C exception handler */
@ -150,25 +139,9 @@ _KiTrapProlog2:
call *%ebx call *%ebx
addl $8, %esp addl $8, %esp
/* Get a pointer to the current thread */
movl %fs:KPCR_CURRENT_THREAD, %esi
/* Restore the old trap frame pointer */
popl %ebx
cmpl $0, %esi
je _KiTrapEpilog
movl %ebx, KTHREAD_TRAP_FRAME(%esi)
/* Return to the caller */ /* Return to the caller */
jmp _KiTrapEpilog jmp _KiTrapEpilog
/* Handle the no-thread case out of line */
.L4:
movl $0, %eax /* previous mode */
movl %eax, KTRAP_FRAME_PREVIOUS_MODE(%ebp)
pushl %eax /* old trap frame */
jmp .L6
.globl _KiTrap0 .globl _KiTrap0
_KiTrap0: _KiTrap0:
/* No error code */ /* No error code */