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)
40 global core_farcall:function hidden
42 mov eax,[esp+1*4] ; CS:IP
45 global core_intcall:function hidden
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...
52 inc dword [CallbackCtr]
57 push dword [CallbackSP]
61 movzx edi,word [word RealModeSSSP]
62 movzx ebx,word [word RealModeSSSP+2]
63 sub edi,54 ; Allocate 54 bytes
64 mov [word RealModeSSSP],di
66 add edi,ebx ; Create linear address
68 mov esi,[esp+8*4] ; Source regs
70 mov cl,11 ; 44 bytes to copy
73 ; EAX is already set up to be CS:IP
74 stosd ; Save in stack frame
75 mov eax,.rm_return ; Return seg:offs
76 stosd ; Save in stack frame
77 mov eax,[edi-12] ; Return flags
78 and eax,0x200ed7 ; Mask (potentially) unsafe flags
79 mov [edi-12],eax ; Primary flags entry
83 jmp enter_rm ; Go to real mode
100 ; We clean up SP here because we don't know if the
101 ; routine returned with RET, RETF or IRET
102 mov sp,[cs:CallbackSP]
112 ; On return, the 44-byte return structure is on the
113 ; real-mode stack, plus the 10 additional bytes used
114 ; by the target address (see above.)
118 movzx esi,word [word RealModeSSSP]
119 movzx eax,word [word RealModeSSSP+2]
120 mov edi,[esp+9*4] ; Dest regs
122 add esi,eax ; Create linear address
123 and edi,edi ; NULL pointer?
125 .no_copy: mov edi,esi ; Do a dummy copy-to-self
126 .do_copy: xor ecx,ecx
128 rep movsd ; Copy register block
130 add dword [word RealModeSSSP],54
133 pop dword [CallbackSP]
134 dec dword [CallbackCtr]
143 ret ; Return to 32-bit program
146 ; Cfarcall invocation. We copy the stack frame to the real-mode stack,
147 ; followed by the return CS:IP and the CS:IP of the target function.
148 ; The value of IF is copied from the calling routine.
150 global core_cfarcall:function hidden
152 pushfd ; Save IF among other things...
153 inc dword [CallbackCtr]
158 push dword [CallbackSP]
161 mov ecx,[esp+9*4] ; Size of stack frame
163 movzx edi,word [word RealModeSSSP]
164 movzx ebx,word [word RealModeSSSP+2]
165 mov [word CallbackSP],di
166 sub edi,ecx ; Allocate space for stack frame
168 sub edi,4*3 ; Return pointer, return value, EFLAGS
169 mov [word RealModeSSSP],di
171 add edi,ebx ; Create linear address
173 mov eax,[esp+5*4] ; EFLAGS from entry
174 and eax,0x202 ; IF only
176 mov eax,[esp+7*4] ; CS:IP
177 stosd ; Save to stack frame
178 mov eax,.rm_return ; Return seg:off
180 mov esi,[esp+8*4] ; Stack frame
181 mov eax,ecx ; Copy the stack frame
197 mov sp,[cs:CallbackSP]
206 ; EDX already set up to be the RM return value
207 pop dword [CallbackSP]
208 dec dword [CallbackCtr]
222 CallbackSP resd 1 ; SP saved during callback