1 ;; -----------------------------------------------------------------------
3 ;; Copyright 1994-2009 H. Peter Anvin - All Rights Reserved
4 ;; Copyright 2009 Intel Corporation; author: H. Peter Anvin
6 ;; This program is free software; you can redistribute it and/or modify
7 ;; it under the terms of the GNU General Public License as published by
8 ;; the Free Software Foundation, Inc., 53 Temple Place Ste 330,
9 ;; Boston MA 02111-1307, USA; either version 2 of the License, or
10 ;; (at your option) any later version; incorporated herein by reference.
12 ;; -----------------------------------------------------------------------
17 ;; Callbacks from 32-bit mode to 16-bit mode
21 ; 16-bit intcall/farcall handling code
31 ; Intcall/farcall invocation. We manifest a structure on the real-mode stack,
32 ; containing the com32sys_t structure from <com32.h> as well as
33 ; the following entries (from low to high address):
37 ; - Return segment (== real mode cs == 0)
42 mov eax,[esp+1*4] ; CS:IP
47 movzx eax,byte [esp+1*4] ; INT number
48 mov eax,[eax*4] ; Get CS:IP from low memory
51 pushfd ; Save IF among other things...
56 push dword [CallbackSP]
60 movzx edi,word [word RealModeSSSP]
61 movzx ebx,word [word RealModeSSSP+2]
62 sub edi,54 ; Allocate 54 bytes
63 mov [word RealModeSSSP],di
65 add edi,ebx ; Create linear address
67 mov esi,[esp+8*4] ; Source regs
69 mov cl,11 ; 44 bytes to copy
72 ; EAX is already set up to be CS:IP
73 stosd ; Save in stack frame
74 mov eax,.rm_return ; Return seg:offs
75 stosd ; Save in stack frame
76 mov eax,[edi-12] ; Return flags
77 and eax,0x200cd7 ; Mask (potentially) unsafe flags
78 mov [edi-12],eax ; Primary flags entry
82 jmp enter_rm ; Go to real mode
93 mov [cs:CallbackSP],sp
97 ; We clean up SP here because we don't know if the
98 ; routine returned with RET, RETF or IRET
99 mov sp,[cs:CallbackSP]
109 ; On return, the 44-byte return structure is on the
110 ; real-mode stack, plus the 10 additional bytes used
111 ; by the target address (see above.)
115 movzx esi,word [word RealModeSSSP]
116 movzx eax,word [word RealModeSSSP+2]
117 mov edi,[esp+9*4] ; Dest regs
119 add esi,eax ; Create linear address
120 and edi,edi ; NULL pointer?
122 .no_copy: mov edi,esi ; Do a dummy copy-to-self
123 .do_copy: xor ecx,ecx
125 rep movsd ; Copy register block
127 add dword [word RealModeSSSP],54
130 pop dword [CallbackSP]
136 ret ; Return to 32-bit program
139 ; Cfarcall invocation. We copy the stack frame to the real-mode stack,
140 ; followed by the return CS:IP and the CS:IP of the target function.
144 pushfd ; Save IF among other things...
149 push dword [CallbackSP]
152 mov ecx,[esp+9*4] ; Size of stack frame
154 movzx edi,word [word RealModeSSSP]
155 movzx ebx,word [word RealModeSSSP+2]
156 mov [word CallbackSP],di
157 sub edi,ecx ; Allocate space for stack frame
159 sub edi,4*2 ; Return pointer, return value
160 mov [word RealModeSSSP],di
162 add edi,ebx ; Create linear address
164 mov eax,[esp+7*4] ; CS:IP
165 stosd ; Save to stack frame
166 mov eax,.rm_return ; Return seg:off
168 mov esi,[esp+8*4] ; Stack frame
169 mov eax,ecx ; Copy the stack frame
184 mov sp,[cs:CallbackSP]
193 ; EDX already set up to be the RM return value
194 pop dword [CallbackSP]
205 CallbackSP resd 1 ; SP saved during callback