3 * Copyright (C) 2000 David Welch <welch@cwcom.net>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 /* $Id: syscall.S,v 1.6 2002/07/04 19:56:36 dwelch Exp $
21 * FILE: ntoskrnl/hal/x86/syscall.s
22 * PURPOSE: 2E trap handler
23 * PROGRAMMER: David Welch (david.welch@seh.ox.ac.uk)
28 #include <ddk/status.h>
29 #include <internal/i386/segment.h>
30 #include <internal/ps.h>
31 #include <ddk/defines.h>
36 .globl KeReturnFromSystemCall
37 .globl _interrupt_handler2e
40 /* Construct a trap frame on the stack */
49 /* Load PCR selector into fs */
50 movl $PCR_SELECTOR, %ebx
53 /* Save the old exception list */
54 movl %fs:KPCR_EXCEPTION_LIST, %ebx
56 /* Set the exception handler chain terminator */
57 movl $0xffffffff, %fs:KPCR_EXCEPTION_LIST
58 /* Get a pointer to the current thread */
59 movl %fs:KPCR_CURRENT_THREAD, %esi
60 /* Save the old previous mode */
62 movb %ss:KTHREAD_PREVIOUS_MODE(%esi), %bl
64 /* Set the new previous mode based on the saved CS selector */
66 andl $0x0000FFFF, %ebx
69 movb $KernelMode, %ss:KTHREAD_PREVIOUS_MODE(%esi)
72 movb $UserMode, %ss:KTHREAD_PREVIOUS_MODE(%esi)
75 /* Save other registers */
88 pushl $0 /* XXX: TempESP */
89 pushl $0 /* XXX: TempCS */
90 pushl $0 /* XXX: DebugPointer */
91 pushl $0 /* XXX: DebugArgMark */
93 pushl %ebx /* DebugEIP */
94 pushl %ebp /* DebugEBP */
96 /* Load the segment registers */
103 * Save the old trap frame pointer over where we would save the EDX
106 movl KTHREAD_TRAP_FRAME(%esi), %ebx
107 movl %ebx, 0x3C(%esp)
109 /* Save a pointer to the trap frame in the TCB */
110 movl %esp, KTHREAD_TRAP_FRAME(%esi)
112 /* Set ES to kernel segment */
116 /* Allocate new Kernel stack frame */
119 /* Users's current stack frame pointer is source */
122 /* Determine system service table to use */
124 ja new_useShadowTable
126 /* Check to see if EAX is valid/inrange */
127 cmpl %es:_KeServiceDescriptorTable + 8, %eax
128 jbe new_serviceInRange
129 movl $STATUS_INVALID_SYSTEM_SERVICE, %eax
130 jmp KeReturnFromSystemCall
134 /* Allocate room for argument list from kernel stack */
135 movl %es:_KeServiceDescriptorTable + 12, %ecx
136 movl %es:(%ecx, %eax, 4), %ecx
139 /* Copy the arguments from the user stack to the kernel stack */
143 /* DS is now also kernel segment */
146 /* Call system call hook */
148 call _KiSystemCallHook
151 /* Make the system service call */
152 movl %es:_KeServiceDescriptorTable, %ecx
153 movl %es:(%ecx, %eax, 4), %eax
157 /* Bump Service Counter */
160 /* Deallocate the kernel stack frame */
163 /* Call the post system call hook and deliver any pending APCs */
166 call _KiAfterSystemCallHook
169 jmp KeReturnFromSystemCall
175 /* Check to see if EAX is valid/inrange */
176 cmpl %es:_KeServiceDescriptorTableShadow + 24, %eax
177 jbe new_shadowServiceInRange
178 movl $STATUS_INVALID_SYSTEM_SERVICE, %eax
179 jmp KeReturnFromSystemCall
181 new_shadowServiceInRange:
183 /* Allocate room for argument list from kernel stack */
184 movl %es:_KeServiceDescriptorTableShadow + 28, %ecx
185 movl %es:(%ecx, %eax, 4), %ecx
188 /* Copy the arguments from the user stack to the kernel stack */
192 /* DS is now also kernel segment */
195 /* Call system call hook */
197 call _KiSystemCallHook
200 /* Make the system service call */
201 movl %es:_KeServiceDescriptorTableShadow + 16, %ecx
202 movl %es:(%ecx, %eax, 4), %eax
206 /* Bump Service Counter */
209 /* Deallocate the kernel stack frame */
212 /* Call the post system call hook and deliver any pending APCs */
215 call _KiAfterSystemCallHook
218 KeReturnFromSystemCall:
220 /* Restore the user context */
221 /* Get a pointer to the current thread */
224 /* Restore the old trap frame pointer */
225 movl 0x3c(%esp), %ebx
226 movl %ebx, KTHREAD_TRAP_FRAME(%esi)
228 /* Skip debug information and unsaved registers */
235 addl $0x4, %esp /* Don't restore eax */
237 /* Restore the old previous mode */
239 movb %bl, %ss:KTHREAD_PREVIOUS_MODE(%esi)
241 /* Restore the old exception handler list */
243 movl %ebx, %fs:KPCR_EXCEPTION_LIST
250 addl $0x4, %esp /* Ignore error code */