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...
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,0x200ed7 ; Mask (potentially) unsafe flags
78 mov [edi-12],eax ; Primary flags entry
82 jmp enter_rm ; Go to real mode
99 ; We clean up SP here because we don't know if the
100 ; routine returned with RET, RETF or IRET
101 mov sp,[cs:CallbackSP]
111 ; On return, the 44-byte return structure is on the
112 ; real-mode stack, plus the 10 additional bytes used
113 ; by the target address (see above.)
117 movzx esi,word [word RealModeSSSP]
118 movzx eax,word [word RealModeSSSP+2]
119 mov edi,[esp+9*4] ; Dest regs
121 add esi,eax ; Create linear address
122 and edi,edi ; NULL pointer?
124 .no_copy: mov edi,esi ; Do a dummy copy-to-self
125 .do_copy: xor ecx,ecx
127 rep movsd ; Copy register block
129 add dword [word RealModeSSSP],54
132 pop dword [CallbackSP]
138 ret ; Return to 32-bit program
141 ; Cfarcall invocation. We copy the stack frame to the real-mode stack,
142 ; followed by the return CS:IP and the CS:IP of the target function.
143 ; The value of IF is copied from the calling routine.
145 global core_cfarcall:function hidden
147 pushfd ; Save IF among other things...
152 push dword [CallbackSP]
155 mov ecx,[esp+9*4] ; Size of stack frame
157 movzx edi,word [word RealModeSSSP]
158 movzx ebx,word [word RealModeSSSP+2]
159 mov [word CallbackSP],di
160 sub edi,ecx ; Allocate space for stack frame
162 sub edi,4*3 ; Return pointer, return value, EFLAGS
163 mov [word RealModeSSSP],di
165 add edi,ebx ; Create linear address
167 mov eax,[esp+5*4] ; EFLAGS from entry
168 and eax,0x202 ; IF only
170 mov eax,[esp+7*4] ; CS:IP
171 stosd ; Save to stack frame
172 mov eax,.rm_return ; Return seg:off
174 mov esi,[esp+8*4] ; Stack frame
175 mov eax,ecx ; Copy the stack frame
191 mov sp,[cs:CallbackSP]
200 ; EDX already set up to be the RM return value
201 pop dword [CallbackSP]
212 CallbackSP resd 1 ; SP saved during callback