| 1 | ; $Id: d32Events.asm,v 1.2 2001-02-23 02:57:53 bird Exp $ | 
|---|
| 2 | ; | 
|---|
| 3 | ; d32Events - Code for overriding system events. | 
|---|
| 4 | ; | 
|---|
| 5 | ; Copyright (c) 2000-2001 knut st. osmundsen (knut.stange.osmundsen@mynd.no) | 
|---|
| 6 | ; | 
|---|
| 7 | ; Project Odin Software License can be found in LICENSE.TXT | 
|---|
| 8 | ; | 
|---|
| 9 | .386p | 
|---|
| 10 |  | 
|---|
| 11 | ; | 
|---|
| 12 | ; Include files | 
|---|
| 13 | ; | 
|---|
| 14 | include devsegdf.inc | 
|---|
| 15 | include devhlp.inc | 
|---|
| 16 |  | 
|---|
| 17 |  | 
|---|
| 18 | ; | 
|---|
| 19 | ; Exported symbols | 
|---|
| 20 | ; | 
|---|
| 21 |  | 
|---|
| 22 |  | 
|---|
| 23 | ; | 
|---|
| 24 | ; Externs | 
|---|
| 25 | ; | 
|---|
| 26 | extrn   aSysEventsOverrides:dword | 
|---|
| 27 | extrn    _TKSSBase16:dword | 
|---|
| 28 | extrn   dh_SendEvent:near | 
|---|
| 29 | extrn   dh_SendEvent_sel:word | 
|---|
| 30 | extrn   RASRST:near | 
|---|
| 31 | extrn   _Device_Help:dword | 
|---|
| 32 |  | 
|---|
| 33 | CODE16 segment | 
|---|
| 34 | ASSUME CS:CODE16, DS:NOTHING, ES:NOTHING, SS:NOTHING | 
|---|
| 35 |  | 
|---|
| 36 |  | 
|---|
| 37 | ;; | 
|---|
| 38 | ; Function overriding the dh_SendEvent DevHelp function. If we | 
|---|
| 39 | ; are overriding the event send, we'll post the semphore registered. | 
|---|
| 40 | ; @returns  CF set on error, clear on success. | 
|---|
| 41 | ; @param    ah  Event being signalled. One of the following values (defined in devhlp.inc): | 
|---|
| 42 | ;                   event_SM_Mou       (0)   event was Session Manager (mouse) | 
|---|
| 43 | ;                   event_CtrlBrk      (1)   event was Ctrl-Break | 
|---|
| 44 | ;                   event_CtrlC        (2)   event was Ctrl-C | 
|---|
| 45 | ;                   event_CtrlScrLk    (3)   event was Ctrl-ScrollLock | 
|---|
| 46 | ;                   event_CtrlPrtSc    (4)   event was Ctrl-PrtSc | 
|---|
| 47 | ;                   event_ShftPrtSc    (5)   event was Shift-PrtSc | 
|---|
| 48 | ;                   event_SM_Kbd       (6)   event was Session Manager (keyboard) | 
|---|
| 49 | ;                   event_SM_CAD       (7)   event was Ctl-Alt-Del | 
|---|
| 50 | ;                   event_HOT_PLUG     (8)   Keyboard Hot Plug/Reset | 
|---|
| 51 | ;                   event_POWER        (9)   Power suspend event | 
|---|
| 52 | ;                   event_POWEROFF     (10)  Power off event | 
|---|
| 53 | ; @param    bx  Event argument. | 
|---|
| 54 | ; @uses | 
|---|
| 55 | ; @sketch | 
|---|
| 56 | ; @status | 
|---|
| 57 | ; @author   knut st. osmundsen (knut.stange.osmundsen@mynd.no) | 
|---|
| 58 | ; @remark | 
|---|
| 59 | mydh_SendEvent PROC FAR | 
|---|
| 60 | ; Preserve some registers. | 
|---|
| 61 | push    ax | 
|---|
| 62 | push    ds | 
|---|
| 63 | push    ebx | 
|---|
| 64 |  | 
|---|
| 65 | ; | 
|---|
| 66 | ; Check range of the event id. | 
|---|
| 67 | ; | 
|---|
| 68 | cmp     ah, event_POWEROFF | 
|---|
| 69 | jg      mydse_OS_event              ; Jump if event id is greater than event_POWEROFF | 
|---|
| 70 |  | 
|---|
| 71 | ; | 
|---|
| 72 | ; Check if we will handle this event or not. | 
|---|
| 73 | ;   This is done by checking the entry for this eventid (ah) in | 
|---|
| 74 | ;   aSysEventsOverrides (k32HandleSystemEvent.cpp). | 
|---|
| 75 | ; | 
|---|
| 76 | push    seg FLAT:CODE32 | 
|---|
| 77 | pop     ds | 
|---|
| 78 | ASSUME  ds:FLAT | 
|---|
| 79 | movzx   ebx, ah | 
|---|
| 80 | shl     ebx, 3                      ; entry size is 8 bytes. 2^3 is 8. | 
|---|
| 81 | cmp     byte ptr aSysEventsOverrides[ebx+4], 0 ; check bad flag for this entry. | 
|---|
| 82 | jnz     mydse_ErrorReturn           ; If the entry is bad we'll fail. | 
|---|
| 83 |  | 
|---|
| 84 | cmp     dword ptr aSysEventsOverrides[ebx], 0 ; check the hev if it's NULLHANDLE. | 
|---|
| 85 | jz      mydse_OS_event | 
|---|
| 86 |  | 
|---|
| 87 |  | 
|---|
| 88 | ; | 
|---|
| 89 | ; Post semaphore handle. | 
|---|
| 90 | ; | 
|---|
| 91 | call    PostEventSem | 
|---|
| 92 |  | 
|---|
| 93 |  | 
|---|
| 94 | ; | 
|---|
| 95 | ; Return to the caller. (dirty hack) | 
|---|
| 96 | ;   On the stack we have a 16-bit near return address in the | 
|---|
| 97 | ;   same segment as dh_SendEvent. To do a far return as we have to | 
|---|
| 98 | ;   do we'll have to change this into an far 16-bit pointer. | 
|---|
| 99 | ;       0. restore ebx and save bp (since we can't use sp directly). | 
|---|
| 100 | ;       1. reserve a 16-bit word. This is allready done when pushing ax in the prolog. | 
|---|
| 101 | ;       2. move near return to word from step 1. (sp+0) | 
|---|
| 102 | ;       3. get the selector of the dh_SendEvent segment. | 
|---|
| 103 | ;       4. move the selector of the dh_SendEvent segment to | 
|---|
| 104 | ;          the near return word. (sp+2) | 
|---|
| 105 | ;       5. Restore bp and ds, and return far. | 
|---|
| 106 | mydse_ret: | 
|---|
| 107 | pop     ebx                         ; 0 | 
|---|
| 108 | push    bp                          ; 0 | 
|---|
| 109 | mov     bp, sp                      ; 0 | 
|---|
| 110 | push    eax                         ; Save eax value (error code) | 
|---|
| 111 | mov     ax, ss:[bp+6]               ; Fetch return offset. | 
|---|
| 112 | mov     ss:[bp+4], ax               ; Write over the original ax value pushed at function start. | 
|---|
| 113 | push    DATA16                      ; 3 | 
|---|
| 114 | pop     ds                          ; 3 | 
|---|
| 115 | ASSUME  ds:DATA16                   ; 3 | 
|---|
| 116 | mov     ax, cs:dh_SendEvent_sel     ; 3 | 
|---|
| 117 | mov     ss:[bp+6], ax               ; 4 | 
|---|
| 118 | pop     eax                         ; restore eax. | 
|---|
| 119 | pop     bp                          ; 5 | 
|---|
| 120 | pop     ds                          ; 5 | 
|---|
| 121 | retf                                ; 5 | 
|---|
| 122 |  | 
|---|
| 123 |  | 
|---|
| 124 | ; | 
|---|
| 125 | ; We failed to send the signal or the hev is bad. | 
|---|
| 126 | ; | 
|---|
| 127 | mydse_ErrorReturn: | 
|---|
| 128 | stc                                 ; set carry flag. | 
|---|
| 129 | jmp     mydse_ret | 
|---|
| 130 |  | 
|---|
| 131 |  | 
|---|
| 132 | ; | 
|---|
| 133 | ; Let OS/2 take care of this event. | 
|---|
| 134 | ; | 
|---|
| 135 | mydse_OS_event: | 
|---|
| 136 | pop     ebx | 
|---|
| 137 | pop     ds | 
|---|
| 138 | pop     ax | 
|---|
| 139 | jmp     dh_SendEvent | 
|---|
| 140 | mydh_SendEvent ENDP | 
|---|
| 141 |  | 
|---|
| 142 |  | 
|---|
| 143 |  | 
|---|
| 144 | ;; | 
|---|
| 145 | ; | 
|---|
| 146 | ; @returns  Not expected to return, but keyboard code handles that quite well it seems. | 
|---|
| 147 | ; @param | 
|---|
| 148 | ; @uses | 
|---|
| 149 | ; @equiv | 
|---|
| 150 | ; @time | 
|---|
| 151 | ; @sketch | 
|---|
| 152 | ; @status | 
|---|
| 153 | ; @author   knut st. osmundsen (knut.stange.osmundsen@mynd.no) | 
|---|
| 154 | ; @remark   Assumes that caller is kdbbase.sys and it is called far. | 
|---|
| 155 | myRASRST PROC FAR | 
|---|
| 156 | ASSUME ds:nothing, ss:nothing | 
|---|
| 157 |  | 
|---|
| 158 | ; Preserve some registers. | 
|---|
| 159 | push    ds | 
|---|
| 160 | push    ebx | 
|---|
| 161 |  | 
|---|
| 162 |  | 
|---|
| 163 | ; | 
|---|
| 164 | ; Check if we're going to override this dump request. | 
|---|
| 165 | ; | 
|---|
| 166 | push    seg FLAT:CODE32 | 
|---|
| 167 | pop     ds | 
|---|
| 168 | ASSUME  ds:FLAT | 
|---|
| 169 | mov     ebx, 8 * 0ah                ; Entry of the Ctrl-Alt-2xNumLock event. | 
|---|
| 170 | cmp     byte ptr aSysEventsOverrides[ebx+4], 0 ; check bad flag for this entry. | 
|---|
| 171 | jnz     myRASRST_ret                ; If the entry is bad we'll fail. | 
|---|
| 172 |  | 
|---|
| 173 | cmp     dword ptr aSysEventsOverrides[ebx], 0 ; check the hev if it's NULLHANDLE. | 
|---|
| 174 | jz      myRASRST_dump | 
|---|
| 175 |  | 
|---|
| 176 | ; | 
|---|
| 177 | ; TODO - add check if we're actually being called from kbdbase.sys! | 
|---|
| 178 | ;        If not called from kbdbase.sys we should do the dump. | 
|---|
| 179 |  | 
|---|
| 180 |  | 
|---|
| 181 | ; | 
|---|
| 182 | ; Post semaphore handle. | 
|---|
| 183 | ; | 
|---|
| 184 | call    PostEventSem | 
|---|
| 185 |  | 
|---|
| 186 | ; | 
|---|
| 187 | ; Return - here we assume return far to the keybase.sys driver. | 
|---|
| 188 | ; | 
|---|
| 189 | myRASRST_ret: | 
|---|
| 190 | pop     ebx | 
|---|
| 191 | pop     ds | 
|---|
| 192 | retf | 
|---|
| 193 |  | 
|---|
| 194 |  | 
|---|
| 195 | ; | 
|---|
| 196 | ; Call the real RASRST. | 
|---|
| 197 | ; | 
|---|
| 198 | myRASRST_dump: | 
|---|
| 199 | pop     ebx | 
|---|
| 200 | pop     ds | 
|---|
| 201 | jmp     RASRST | 
|---|
| 202 | myRASRST ENDP | 
|---|
| 203 |  | 
|---|
| 204 |  | 
|---|
| 205 | ;; | 
|---|
| 206 | ; Internal function which posts the semaphore of a given entry. | 
|---|
| 207 | ; @returns  Return from dh_PostEventSem. | 
|---|
| 208 | ;               CF clear on success. | 
|---|
| 209 | ;               CF set on error, with errorcode in eax. | 
|---|
| 210 | ; @param    ebx     Offset of event entry to post. | 
|---|
| 211 | ; @uses     eax. | 
|---|
| 212 | PostEventSem PROC NEAR | 
|---|
| 213 | push    esi                         ; Save registers - can't be too carefull... paranoia | 
|---|
| 214 | push    edi | 
|---|
| 215 | push    edx | 
|---|
| 216 | push    ecx | 
|---|
| 217 | push    ebx | 
|---|
| 218 | push    ebp | 
|---|
| 219 | push    es | 
|---|
| 220 | push    ds | 
|---|
| 221 |  | 
|---|
| 222 | mov     eax, aSysEventsOverrides[ebx] ; Get hev from the entry. | 
|---|
| 223 | mov     dh, DevHlp_PostEventSem     ; Post event sem dev help. | 
|---|
| 224 | call    [_Device_Help] | 
|---|
| 225 |  | 
|---|
| 226 | pop     ds                          ; Restore registers. | 
|---|
| 227 | pop     es | 
|---|
| 228 | pop     ebp | 
|---|
| 229 | pop     ebx | 
|---|
| 230 | pop     ecx | 
|---|
| 231 | pop     edx | 
|---|
| 232 | pop     edi | 
|---|
| 233 | pop     esi | 
|---|
| 234 |  | 
|---|
| 235 | jnc     post_ok                     ; Check for errors | 
|---|
| 236 | ; Post returned errorcode. We'll ignore ERROR_ALREADY_POSTED and ERROR_TOO_MANY_POSTS. | 
|---|
| 237 | cmp     eax, 299 ;(ERROR_ALREADY_POSTED) | 
|---|
| 238 | je      post_ok | 
|---|
| 239 | cmp     eax, 298 ;(ERROR_TOO_MANY_POSTS) | 
|---|
| 240 | je      post_ok | 
|---|
| 241 |  | 
|---|
| 242 | ; | 
|---|
| 243 | ; Failed to post semaphore - set bad flag to true. | 
|---|
| 244 | ; | 
|---|
| 245 | mov     byte ptr aSysEventsOverrides[ebx+4], 1 ; check bad flag for this entry. | 
|---|
| 246 |  | 
|---|
| 247 | post_ok: | 
|---|
| 248 | ret | 
|---|
| 249 | PostEventSem ENDP | 
|---|
| 250 |  | 
|---|
| 251 |  | 
|---|
| 252 | CODE16 ends | 
|---|
| 253 |  | 
|---|
| 254 |  | 
|---|
| 255 | CODE32 segment | 
|---|
| 256 | CODE32START label byte | 
|---|
| 257 |  | 
|---|
| 258 | CODE32 ends | 
|---|
| 259 |  | 
|---|
| 260 | END | 
|---|
| 261 |  | 
|---|
| 262 |  | 
|---|