PAGFAULT.ASM (7573B)
1 ; 2 ; Copyright 2020 Electronic Arts Inc. 3 ; 4 ; TiberianDawn.DLL and RedAlert.dll and corresponding source code is free 5 ; software: you can redistribute it and/or modify it under the terms of 6 ; the GNU General Public License as published by the Free Software Foundation, 7 ; either version 3 of the License, or (at your option) any later version. 8 9 ; TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed 10 ; in the hope that it will be useful, but with permitted additional restrictions 11 ; under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT 12 ; distributed with this program. You should have received a copy of the 13 ; GNU General Public License along with permitted additional restrictions 14 ; with this program. If not, see [https://github.com/electronicarts/CnC_Remastered_Collection]>. 15 16 ;*************************************************************************** 17 ;** C O N F I D E N T I A L --- W E S T W O O D A S S O C I A T E S ** 18 ;*************************************************************************** 19 ;* * 20 ;* Project Name : Library * 21 ;* * 22 ;* File Name : PAGFAULT.ASM * 23 ;* * 24 ;* Programmer : Julio R Jerez * 25 ;* * 26 ;* Date : April 25,1995 * 27 ;* * 28 ;*-------------------------------------------------------------------------* 29 ;* Functions: * 30 ; 31 ; Here are prototypes for the routines defined within this module: 32 ; VOID Install_Page_Fault_Handle (void) ; 33 ; 34 ; ---------------------------------------------------------------- 35 36 IDEAL ; the product runs in ideal mode 37 P386 ; use 386 real mode instructions 38 MODEL USE32 FLAT 39 LOCALS ?? ; ?? is the symbol for a local 40 WARN ; generate all warnings we can 41 JUMPS ; optimize jumps if possible 42 43 ;--------------------------------------------------------------------------- 44 ; Make some general equates for easy compatability 45 ;--------------------------------------------------------------------------- 46 DPMI_INTR EQU 31h 47 PAGE_FAULT equ 0eh 48 DIVIDE_ERROR equ 00h 49 RESET_VIDEO_MODE equ -1 50 51 global C Install_Page_Fault_Handle : NEAR 52 global C Set_Video_Mode : NEAR 53 global C Remove_Mouse : NEAR 54 global C Remove_Keyboard_Interrupt : NEAR 55 global C Remove_Timer_Interrupt : NEAR 56 57 DATASEG 58 Old_Page_Fault_handle DF ? 59 Page_Fault_SS DD ? 60 Page_Fault_ESP DD ? 61 62 Old_Div_Error_handle DF ? 63 Div_Error_SS DD ? 64 Div_Error_ESP DD ? 65 66 67 CODESEG 68 ;*************************************************************************** 69 ;* INSTALL_PAGE_FAULT_HANDLE -- Installs new page fault and div Error * 70 ;* handles. * 71 ;* This function will install a new page fault handle and Div Error * 72 ;* so in the event that we have a program crash these handles will * 73 ;* remove all interrupts and then will chain to the default Exception * 74 ;* Handle * 75 ;* * 76 ;* INPUT: none * 77 ;* * 78 ;* * 79 ;* OUTPUT: none * 80 ;* * 81 ;* PROTO: VOID Install_Page_Fault_Handle( void); * 82 ;* * 83 ;* HISTORY: 04/25/96 Created * 84 ;*=========================================================================* 85 PROC Install_Page_Fault_Handle C NEAR 86 USES eax,ebx,ecx,edx,esi,edi 87 88 ; Install_Page_Fault_Handle 89 mov eax,0202h ; get address of exception handle 90 mov bl,PAGE_FAULT 91 int DPMI_INTR 92 jc ??exit ; not action is taken 93 94 ; save addrees of default handle 95 mov [dword ptr Old_Page_Fault_handle],edx 96 mov [word ptr Old_Page_Fault_handle+4],cx 97 98 ; redirect default handle to a new Page Fault Handle 99 mov eax,0203h 100 mov bl,PAGE_FAULT 101 mov cx,cs 102 lea edx,[Page_Fault_Handle] 103 int DPMI_INTR 104 105 106 ; Install_Divide_Error_Handle 107 mov eax,0202h ; get address of exception handle 108 mov bl,DIVIDE_ERROR 109 int DPMI_INTR 110 jc ??exit ; not action is taken 111 112 ; save addrees of default fault handle 113 mov [dword ptr Old_Div_Error_handle],edx 114 mov [word ptr Old_Div_Error_handle+4],cx 115 116 ; redirect default handle to a new Divede Handle 117 mov eax,0203h 118 mov bl,DIVIDE_ERROR 119 mov cx,cs 120 lea edx,[Divide_Error_Handle] 121 int DPMI_INTR 122 123 ??exit: 124 125 126 ret 127 ENDP Install_Page_Fault_Handle 128 129 130 ;*************************************************************************** 131 ;* PAGE_FAULT_HANDLE -- This * 132 ;* * 133 ;* * 134 ;* * 135 ;* HISTORY: 04/25/96 Created * 136 ;*=========================================================================* 137 PROC Page_Fault_Handle far 138 139 ; preserve used registers 140 push eax 141 push ebx 142 ; save Page Fault satck frame 143 mov ax,ss 144 mov [Page_Fault_SS],eax 145 mov [Page_Fault_ESP],esp 146 147 ; retrieve application original stack frame 148 mov eax , [ esp + ( 6 + 2 ) * 4 ] 149 mov ebx , [ esp + ( 7 + 2 ) * 4 ] 150 mov ss , bx 151 mov esp , eax 152 153 ; set video mode to standard text mode 154 push RESET_VIDEO_MODE 155 call Set_Video_Mode 156 pop eax 157 call Remove_Mouse 158 call Remove_Keyboard_Interrupt 159 call Remove_Timer_Interrupt 160 161 ; restore Page Fault stack frame 162 mov eax,[Page_Fault_SS] 163 mov ss , ax 164 mov esp, [Page_Fault_ESP] 165 166 ; restore used registers and chain to default Page Fault Handle 167 pop ebx 168 pop eax 169 jmp [fword Old_Page_Fault_handle] 170 171 ENDP Page_Fault_Handle 172 173 174 175 ;*************************************************************************** 176 ;* Divide_Error -- * 177 ;* * 178 ;* * 179 ;* * 180 ;* HISTORY: 04/25/96 Created * 181 ;*=========================================================================* 182 PROC Divide_Error_Handle far 183 184 ; preserve used registers 185 push eax 186 push ebx 187 ; save Page Fault satck frame 188 mov ax,ss 189 mov [Div_Error_SS],eax 190 mov [Div_Error_ESP],esp 191 192 ; retrieve application original stack frame 193 mov eax , [ esp + ( 6 + 2 ) * 4 ] 194 mov ebx , [ esp + ( 7 + 2 ) * 4 ] 195 mov ss , bx 196 mov esp , eax 197 198 ; set video mode to standard text mode 199 push RESET_VIDEO_MODE 200 call Set_Video_Mode 201 pop eax 202 call Remove_Mouse 203 call Remove_Keyboard_Interrupt 204 call Remove_Timer_Interrupt 205 206 ; restore Fault stack frame 207 mov eax,[Div_Error_SS] 208 mov ss , ax 209 mov esp, [Div_Error_ESP] 210 211 ; restore used registers and chain to default Page Fault Handle 212 pop ebx 213 pop eax 214 jmp [fword Old_Div_Error_handle] 215 216 ENDP Divide_Error_Handle 217 218 219 ;*************************************************************************** 220 ;* End of File. * 221 ;*************************************************************************** 222 END