PAGFAULT.ASM 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. ;
  2. ; Command & Conquer(tm)
  3. ; Copyright 2025 Electronic Arts Inc.
  4. ;
  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 3 of the License, or
  8. ; (at your option) any later version.
  9. ;
  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.
  14. ;
  15. ; You should have received a copy of the GNU General Public License
  16. ; along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. ;
  18. ;***************************************************************************
  19. ;** 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 **
  20. ;***************************************************************************
  21. ;* *
  22. ;* Project Name : Library *
  23. ;* *
  24. ;* File Name : PAGFAULT.ASM *
  25. ;* *
  26. ;* Programmer : Julio R Jerez *
  27. ;* *
  28. ;* Date : April 25,1995 *
  29. ;* *
  30. ;*-------------------------------------------------------------------------*
  31. ;* Functions: *
  32. ;
  33. ; Here are prototypes for the routines defined within this module:
  34. ; VOID Install_Page_Fault_Handle (void) ;
  35. ;
  36. ; ----------------------------------------------------------------
  37. IDEAL ; the product runs in ideal mode
  38. P386 ; use 386 real mode instructions
  39. MODEL USE32 FLAT
  40. LOCALS ?? ; ?? is the symbol for a local
  41. WARN ; generate all warnings we can
  42. JUMPS ; optimize jumps if possible
  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. global C Install_Page_Fault_Handle : NEAR
  51. global C Set_Video_Mode : NEAR
  52. global C Remove_Mouse : NEAR
  53. global C Remove_Keyboard_Interrupt : NEAR
  54. global C Remove_Timer_Interrupt : NEAR
  55. DATASEG
  56. Old_Page_Fault_handle DF ?
  57. Page_Fault_SS DD ?
  58. Page_Fault_ESP DD ?
  59. Old_Div_Error_handle DF ?
  60. Div_Error_SS DD ?
  61. Div_Error_ESP DD ?
  62. CODESEG
  63. ;***************************************************************************
  64. ;* INSTALL_PAGE_FAULT_HANDLE -- Installs new page fault and div Error *
  65. ;* handles. *
  66. ;* This function will install a new page fault handle and Div Error *
  67. ;* so in the event that we have a program crash these handles will *
  68. ;* remove all interrupts and then will chain to the default Exception *
  69. ;* Handle *
  70. ;* *
  71. ;* INPUT: none *
  72. ;* *
  73. ;* *
  74. ;* OUTPUT: none *
  75. ;* *
  76. ;* PROTO: VOID Install_Page_Fault_Handle( void); *
  77. ;* *
  78. ;* HISTORY: 04/25/96 Created *
  79. ;*=========================================================================*
  80. PROC Install_Page_Fault_Handle C NEAR
  81. USES eax,ebx,ecx,edx,esi,edi
  82. ; Install_Page_Fault_Handle
  83. mov eax,0202h ; get address of exception handle
  84. mov bl,PAGE_FAULT
  85. int DPMI_INTR
  86. jc ??exit ; not action is taken
  87. ; save addrees of default handle
  88. mov [dword ptr Old_Page_Fault_handle],edx
  89. mov [word ptr Old_Page_Fault_handle+4],cx
  90. ; redirect default handle to a new Page Fault Handle
  91. mov eax,0203h
  92. mov bl,PAGE_FAULT
  93. mov cx,cs
  94. lea edx,[Page_Fault_Handle]
  95. int DPMI_INTR
  96. ; Install_Divide_Error_Handle
  97. mov eax,0202h ; get address of exception handle
  98. mov bl,DIVIDE_ERROR
  99. int DPMI_INTR
  100. jc ??exit ; not action is taken
  101. ; save addrees of default fault handle
  102. mov [dword ptr Old_Div_Error_handle],edx
  103. mov [word ptr Old_Div_Error_handle+4],cx
  104. ; redirect default handle to a new Divede Handle
  105. mov eax,0203h
  106. mov bl,DIVIDE_ERROR
  107. mov cx,cs
  108. lea edx,[Divide_Error_Handle]
  109. int DPMI_INTR
  110. ??exit:
  111. ret
  112. ENDP Install_Page_Fault_Handle
  113. ;***************************************************************************
  114. ;* PAGE_FAULT_HANDLE -- This *
  115. ;* *
  116. ;* *
  117. ;* *
  118. ;* HISTORY: 04/25/96 Created *
  119. ;*=========================================================================*
  120. PROC Page_Fault_Handle far
  121. ; preserve used registers
  122. push eax
  123. push ebx
  124. ; save Page Fault satck frame
  125. mov ax,ss
  126. mov [Page_Fault_SS],eax
  127. mov [Page_Fault_ESP],esp
  128. ; retrieve application original stack frame
  129. mov eax , [ esp + ( 6 + 2 ) * 4 ]
  130. mov ebx , [ esp + ( 7 + 2 ) * 4 ]
  131. mov ss , bx
  132. mov esp , eax
  133. ; set video mode to standard text mode
  134. push RESET_VIDEO_MODE
  135. call Set_Video_Mode
  136. pop eax
  137. call Remove_Mouse
  138. call Remove_Keyboard_Interrupt
  139. call Remove_Timer_Interrupt
  140. ; restore Page Fault stack frame
  141. mov eax,[Page_Fault_SS]
  142. mov ss , ax
  143. mov esp, [Page_Fault_ESP]
  144. ; restore used registers and chain to default Page Fault Handle
  145. pop ebx
  146. pop eax
  147. jmp [fword Old_Page_Fault_handle]
  148. ENDP Page_Fault_Handle
  149. ;***************************************************************************
  150. ;* Divide_Error -- *
  151. ;* *
  152. ;* *
  153. ;* *
  154. ;* HISTORY: 04/25/96 Created *
  155. ;*=========================================================================*
  156. PROC Divide_Error_Handle far
  157. ; preserve used registers
  158. push eax
  159. push ebx
  160. ; save Page Fault satck frame
  161. mov ax,ss
  162. mov [Div_Error_SS],eax
  163. mov [Div_Error_ESP],esp
  164. ; retrieve application original stack frame
  165. mov eax , [ esp + ( 6 + 2 ) * 4 ]
  166. mov ebx , [ esp + ( 7 + 2 ) * 4 ]
  167. mov ss , bx
  168. mov esp , eax
  169. ; set video mode to standard text mode
  170. push RESET_VIDEO_MODE
  171. call Set_Video_Mode
  172. pop eax
  173. call Remove_Mouse
  174. call Remove_Keyboard_Interrupt
  175. call Remove_Timer_Interrupt
  176. ; restore Fault stack frame
  177. mov eax,[Div_Error_SS]
  178. mov ss , ax
  179. mov esp, [Div_Error_ESP]
  180. ; restore used registers and chain to default Page Fault Handle
  181. pop ebx
  182. pop eax
  183. jmp [fword Old_Div_Error_handle]
  184. ENDP Divide_Error_Handle
  185. ;***************************************************************************
  186. ;* End of File. *
  187. ;***************************************************************************
  188. END