| 1 | ; $Id: devfirst.asm,v 1.9 2001-07-10 05:19:34 bird Exp $ | 
|---|
| 2 | ; | 
|---|
| 3 | ; DevFirst - entrypoint and segment definitions | 
|---|
| 4 | ; | 
|---|
| 5 | ; Copyright (c) 1999 knut st. osmundsen | 
|---|
| 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 sas.inc | 
|---|
| 16 |  | 
|---|
| 17 | ; | 
|---|
| 18 | ; Exported symbols | 
|---|
| 19 | ; | 
|---|
| 20 | public CODE16START | 
|---|
| 21 | public CODE16_INITSTART | 
|---|
| 22 | public DATA16START | 
|---|
| 23 | public DATA16START | 
|---|
| 24 | public DATA16_BSSSTART | 
|---|
| 25 | public DATA16_CONSTSTART | 
|---|
| 26 | public DATA16_INITSTART | 
|---|
| 27 | public CODE16START | 
|---|
| 28 | public CODE32START | 
|---|
| 29 | public DATA32START | 
|---|
| 30 | public BSS32START | 
|---|
| 31 | public CONST32_ROSTART | 
|---|
| 32 | public _VFTSTART | 
|---|
| 33 | public EH_DATASTART | 
|---|
| 34 |  | 
|---|
| 35 |  | 
|---|
| 36 | public _strategyAsm0 | 
|---|
| 37 | public _strategyAsm1 | 
|---|
| 38 | public _CallGetKernelInfo32 | 
|---|
| 39 | public _CallElfIOCtl | 
|---|
| 40 | public _CallWin32kIOCtl | 
|---|
| 41 | public _CallWin32kOpen | 
|---|
| 42 | public _CallWin32kClose | 
|---|
| 43 | public _SSToDS_16a | 
|---|
| 44 | public GetOS2KrnlMTE | 
|---|
| 45 | public x86DisableWriteProtect | 
|---|
| 46 | public x86RestoreWriteProtect | 
|---|
| 47 |  | 
|---|
| 48 |  | 
|---|
| 49 | ; | 
|---|
| 50 | ; Externs | 
|---|
| 51 | ; | 
|---|
| 52 | extrn _TKSSBase16:dword | 
|---|
| 53 | extrn GETKERNELINFO32:FAR | 
|---|
| 54 | extrn ELFIOCTL:FAR | 
|---|
| 55 | extrn WIN32KIOCTL:FAR | 
|---|
| 56 | extrn WIN32KOPEN:FAR | 
|---|
| 57 | extrn WIN32KCLOSE:FAR | 
|---|
| 58 | .286p | 
|---|
| 59 | extrn h_POST_SIGNAL:FAR | 
|---|
| 60 | extrn _strategy:near | 
|---|
| 61 |  | 
|---|
| 62 |  | 
|---|
| 63 | CODE16 segment | 
|---|
| 64 | ASSUME CS:CODE16, DS:DATA16, ES:NOTHING, SS:NOTHING | 
|---|
| 65 |  | 
|---|
| 66 | CODE16START label byte | 
|---|
| 67 |  | 
|---|
| 68 | .286p | 
|---|
| 69 | ;$win32ki entry point | 
|---|
| 70 | _strategyAsm0: | 
|---|
| 71 | ;    int 3 | 
|---|
| 72 | push    0 | 
|---|
| 73 | jmp     _strategyAsm | 
|---|
| 74 |  | 
|---|
| 75 | ;$win32k entry point | 
|---|
| 76 | _strategyAsm1: | 
|---|
| 77 | ;    int 3 | 
|---|
| 78 | push    1 | 
|---|
| 79 | jmp     _strategyAsm | 
|---|
| 80 |  | 
|---|
| 81 | ;; | 
|---|
| 82 | ; Stub which pushes parameters onto the stack and call the 16-bit C strategy routine. | 
|---|
| 83 | ; @returns   returns the return value of strategy(...) | 
|---|
| 84 | ; @author    knut st. osmundsen | 
|---|
| 85 | _strategyAsm proc far | 
|---|
| 86 | push    es | 
|---|
| 87 | push    bx | 
|---|
| 88 | push    ds | 
|---|
| 89 | pop     es | 
|---|
| 90 | call    _strategy | 
|---|
| 91 | pop     bx | 
|---|
| 92 | pop     es | 
|---|
| 93 | mov     word ptr es:[bx+3], ax | 
|---|
| 94 | add     sp, 2 | 
|---|
| 95 | retf | 
|---|
| 96 | _strategyAsm endp | 
|---|
| 97 |  | 
|---|
| 98 |  | 
|---|
| 99 | .386p | 
|---|
| 100 | ;; | 
|---|
| 101 | ; Thunk procedure for R0Init32. | 
|---|
| 102 | ; @cproto    USHORT NEAR CallGetKernelInfo32(ULONG addressKrnlInfoBuf); | 
|---|
| 103 | ; @returns   Same as GetKernelInfo32. | 
|---|
| 104 | ; @param     addressKrnlInfoBuf  32-bit pointer to request data on stack. | 
|---|
| 105 | ; @status    completely implemented. | 
|---|
| 106 | ; @author    knut st. osmundsen | 
|---|
| 107 | _CallGetKernelInfo32 PROC NEAR | 
|---|
| 108 | ASSUME CS:CODE16 | 
|---|
| 109 | push    ds | 
|---|
| 110 | push    word ptr [esp+6]            ; push high word. | 
|---|
| 111 | push    word ptr [esp+6]            ; push low word. | 
|---|
| 112 | call    far ptr FLAT:GETKERNELINFO32 | 
|---|
| 113 | pop     ds | 
|---|
| 114 | ret | 
|---|
| 115 | _CallGetKernelInfo32 ENDP | 
|---|
| 116 |  | 
|---|
| 117 |  | 
|---|
| 118 |  | 
|---|
| 119 |  | 
|---|
| 120 | ;; | 
|---|
| 121 | ; Thunk procedure for . | 
|---|
| 122 | ; @cproto    USHORT NEAR CallElfIOCtl(void); | 
|---|
| 123 | ; @returns   Same as ElfIOCtl | 
|---|
| 124 | ; @param     address of IOCtl request packet (32-bit pointer). | 
|---|
| 125 | ; @status    completely implemented. | 
|---|
| 126 | ; @author    knut st. osmundsen | 
|---|
| 127 | _CallElfIOCtl PROC NEAR | 
|---|
| 128 | ASSUME CS:CODE16 | 
|---|
| 129 | push    ds | 
|---|
| 130 | push    word ptr [esp+6]            ; push high word. | 
|---|
| 131 | push    word ptr [esp+6]            ; push low word. | 
|---|
| 132 | call    far ptr FLAT:ELFIOCTL | 
|---|
| 133 | pop     ds | 
|---|
| 134 | retn | 
|---|
| 135 | _CallElfIOCtl ENDP | 
|---|
| 136 |  | 
|---|
| 137 | ;; | 
|---|
| 138 | ; Thunk procedure for . | 
|---|
| 139 | ; @cproto    USHORT NEAR CallWin32kIOCtl(void); | 
|---|
| 140 | ; @returns   Same as Win32kIOCtl | 
|---|
| 141 | ; @param     address of IOCtl request packet (32-bit pointer). | 
|---|
| 142 | ; @status    completely implemented. | 
|---|
| 143 | ; @author    knut st. osmundsen | 
|---|
| 144 | _CallWin32kIOCtl PROC NEAR | 
|---|
| 145 | ASSUME CS:CODE16 | 
|---|
| 146 | push    ds | 
|---|
| 147 | push    word ptr [esp+6]            ; push high word. | 
|---|
| 148 | push    word ptr [esp+6]            ; push low word. | 
|---|
| 149 | call    far ptr FLAT:WIN32KIOCTL | 
|---|
| 150 | pop     ds | 
|---|
| 151 | retn | 
|---|
| 152 | _CallWin32kIOCtl ENDP | 
|---|
| 153 |  | 
|---|
| 154 |  | 
|---|
| 155 | ;; | 
|---|
| 156 | ; Thunk procedure for . | 
|---|
| 157 | ; @cproto    USHORT NEAR CallWin32kOpen(LIN); | 
|---|
| 158 | ; @returns   Same as Win32kOpen | 
|---|
| 159 | ; @param     address of Open request packet (32-bit pointer). | 
|---|
| 160 | ; @status    completely implemented. | 
|---|
| 161 | ; @author    knut st. osmundsen | 
|---|
| 162 | _CallWin32kOpen PROC NEAR | 
|---|
| 163 | ASSUME CS:CODE16 | 
|---|
| 164 | push    ds | 
|---|
| 165 | push    word ptr [esp+6]            ; push high word. | 
|---|
| 166 | push    word ptr [esp+6]            ; push low word. | 
|---|
| 167 | call    far ptr FLAT:WIN32KOPEN | 
|---|
| 168 | pop     ds | 
|---|
| 169 | retn | 
|---|
| 170 | _CallWin32kOpen ENDP | 
|---|
| 171 |  | 
|---|
| 172 |  | 
|---|
| 173 | ;; | 
|---|
| 174 | ; Thunk procedure for strategy close. | 
|---|
| 175 | ; @cproto    USHORT NEAR CallWin32kClose(LIN); | 
|---|
| 176 | ; @returns   Same as Win32kIOCtl | 
|---|
| 177 | ; @param     address of Open request packet (32-bit pointer). | 
|---|
| 178 | ; @status    completely implemented. | 
|---|
| 179 | ; @author    knut st. osmundsen | 
|---|
| 180 | _CallWin32kClose PROC NEAR | 
|---|
| 181 | ASSUME CS:CODE16 | 
|---|
| 182 | push    ds | 
|---|
| 183 | push    word ptr [esp+6]            ; push high word. | 
|---|
| 184 | push    word ptr [esp+6]            ; push low word. | 
|---|
| 185 | call    far ptr FLAT:WIN32KCLOSE | 
|---|
| 186 | pop     ds | 
|---|
| 187 | retn | 
|---|
| 188 | _CallWin32kClose ENDP | 
|---|
| 189 |  | 
|---|
| 190 |  | 
|---|
| 191 |  | 
|---|
| 192 | ;; | 
|---|
| 193 | ; SSToDS - stack pointer to Flat pointer. | 
|---|
| 194 | ; @cproto    extern LIN   SSToDS_16a(void NEAR *pStackVar); | 
|---|
| 195 | ; @returns   ax:dx  makes up a 32-bit flat pointer to stack. | 
|---|
| 196 | ; @param     pStackVar  Stack pointer which is to be made a flat pointer. | 
|---|
| 197 | ; @equiv     SSToDS in 32-bit code. | 
|---|
| 198 | ; @sketch    Get Flat CS | 
|---|
| 199 | ;            Get TKSSBase address. (FLAT) | 
|---|
| 200 | ;            return *TKSSBase + pStackVar. | 
|---|
| 201 | ; @status    completely  implemented. | 
|---|
| 202 | ; @author    knut st. osmundsen | 
|---|
| 203 | ; @remark    es is cs, not ds! | 
|---|
| 204 | _SSToDS_16a proc NEAR | 
|---|
| 205 | assume CS:CODE16, DS:DATA16, ES:NOTHING | 
|---|
| 206 | mov     edx, ds:_TKSSBase16         ; get pointer held by _TKSSBase16 (pointer to stack base) | 
|---|
| 207 | call    far ptr FLAT:far_getCS      ; get flat selector. | 
|---|
| 208 | push    es | 
|---|
| 209 | mov     es,  ax | 
|---|
| 210 | assume  es:FLAT | 
|---|
| 211 | mov     eax, es:[edx]               ; get pointer to stack base | 
|---|
| 212 | pop     es | 
|---|
| 213 | movzx   edx, word ptr ss:[esp + 2]  ; 16-bit stack pointer (parameter) | 
|---|
| 214 | add     eax, edx                    ; 32-bit stack pointer in eax | 
|---|
| 215 | mov     edx, eax | 
|---|
| 216 | shr     edx, 16                     ; dx high 16-bit of 32-bit stack pointer. | 
|---|
| 217 | retn | 
|---|
| 218 | _SSToDS_16a endp | 
|---|
| 219 |  | 
|---|
| 220 | CODE16 ends | 
|---|
| 221 |  | 
|---|
| 222 |  | 
|---|
| 223 | ; | 
|---|
| 224 | ; all segments have a <segmentname>START label at the start of the segment. | 
|---|
| 225 | ; | 
|---|
| 226 |  | 
|---|
| 227 | CODE32 segment | 
|---|
| 228 | CODE32START label byte | 
|---|
| 229 |  | 
|---|
| 230 | ;; | 
|---|
| 231 | ; Gets the current cs. | 
|---|
| 232 | ; @cproto    none. | 
|---|
| 233 | ; @returns   CS | 
|---|
| 234 | ; @author    knut st. osmundsen | 
|---|
| 235 | ; @remark    internal method. called from 16-bit code... | 
|---|
| 236 | far_getCS proc far | 
|---|
| 237 | ASSUME DS:nothing, ES:nothing | 
|---|
| 238 | mov     ax,  cs | 
|---|
| 239 | retf | 
|---|
| 240 | far_getCS endp | 
|---|
| 241 |  | 
|---|
| 242 |  | 
|---|
| 243 |  | 
|---|
| 244 | ;; | 
|---|
| 245 | ; Gets the a 32-bit flat pointer to the OS/2 Kernel MTE. | 
|---|
| 246 | ; @cproto    extern PMTE _System GetOS2KrnlMTE(void); | 
|---|
| 247 | ; @returns   Pointer to kernel MTE. | 
|---|
| 248 | ; @status    completely implemented. | 
|---|
| 249 | ; @author    knut st. osmundsen | 
|---|
| 250 | GetOS2KrnlMTE PROC NEAR | 
|---|
| 251 | push    es | 
|---|
| 252 |  | 
|---|
| 253 | mov     ax,  SAS_selector               ;70h - Read-only SAS selector. | 
|---|
| 254 | mov     es,  ax | 
|---|
| 255 | xor     ebx, ebx | 
|---|
| 256 | assume  ebx: PTR SAS | 
|---|
| 257 | mov     bx,  es:[ebx].SAS_vm_data       ;SAS_vm_data (0ch) | 
|---|
| 258 | assume  ebx: PTR SAS_vm_section | 
|---|
| 259 | mov     eax, es:[ebx].SAS_vm_krnl_mte   ;SAS_vm_krnl_mte (0ch) | 
|---|
| 260 |  | 
|---|
| 261 | pop     es | 
|---|
| 262 | ret | 
|---|
| 263 | GetOS2KrnlMTE ENDP | 
|---|
| 264 |  | 
|---|
| 265 |  | 
|---|
| 266 | ;; | 
|---|
| 267 | ; Disables the ring-0 write protection. | 
|---|
| 268 | ; It's used to help us write to readonly code segments and objects. | 
|---|
| 269 | ; @cproto   extern ULONG    _Optlink x86DisableWriteProtect(void); | 
|---|
| 270 | ; @return   Previous write protection flag setting. | 
|---|
| 271 | ; @uses     eax, edx | 
|---|
| 272 | ; @status   completely implemented. | 
|---|
| 273 | ; @author   knut st. osmundsen (knut.stange.osmundsen@mynd.no) | 
|---|
| 274 | ; @remark   Used by importTabInit. | 
|---|
| 275 | x86DisableWriteProtect proc near | 
|---|
| 276 | cli | 
|---|
| 277 | mov     edx, cr0                    ; Get current cr0 | 
|---|
| 278 | test    edx, 000010000h             ; Test for the WriteProtect flag (bit 16) | 
|---|
| 279 | setnz   al | 
|---|
| 280 | movzx   eax, al                     ; Old flag setting in eax (return value) | 
|---|
| 281 | and     edx, 0fffeffffh             ; Clear the 16th (WP) bit. | 
|---|
| 282 | mov     cr0, edx                    ; | 
|---|
| 283 | sti | 
|---|
| 284 | ret                                 ; return eax holds previous WP value. | 
|---|
| 285 | x86DisableWriteProtect endp | 
|---|
| 286 |  | 
|---|
| 287 |  | 
|---|
| 288 | ;; | 
|---|
| 289 | ; Restore the WP flag of CR0 to it's previous state. | 
|---|
| 290 | ; The call is intent only to be called with the result from x86DisableWriteProtect, | 
|---|
| 291 | ; and will hence only enable the WP flag. | 
|---|
| 292 | ; @cproto   extern ULONG    _Optlink x86RestoreWriteProtect(ULONG flWP); | 
|---|
| 293 | ; @return   Previous write protection flag setting. | 
|---|
| 294 | ; @param    eax - flWP  Boolean value. (1 = WP was set, 0 WP was clear) | 
|---|
| 295 | ; @uses     eax | 
|---|
| 296 | ; @status   completely implemented. | 
|---|
| 297 | ; @author   knut st. osmundsen (knut.stange.osmundsen@mynd.no) | 
|---|
| 298 | ; @remark   Used by importTabInit. | 
|---|
| 299 | x86RestoreWriteProtect proc near | 
|---|
| 300 | test    eax, eax                    ; Check if the flag was previously clear | 
|---|
| 301 | jnz     x86RWP_set                  ; If set Then Set it back. | 
|---|
| 302 | jmp     x86RWP_end                  ; If clear Then nothing to do. | 
|---|
| 303 | x86RWP_set: | 
|---|
| 304 | cli | 
|---|
| 305 | mov     eax, cr0                    ; Get current cr0. | 
|---|
| 306 | or      eax, 000010000h             ; The the 16-bit (WP) bit. | 
|---|
| 307 | mov     cr0, eax                    ; Update cr0. | 
|---|
| 308 | sti | 
|---|
| 309 |  | 
|---|
| 310 | x86RWP_end: | 
|---|
| 311 | ret | 
|---|
| 312 | x86RestoreWriteProtect endp | 
|---|
| 313 |  | 
|---|
| 314 |  | 
|---|
| 315 | ;; | 
|---|
| 316 | ; Post signal to one or more processes. | 
|---|
| 317 | ; @cproto   extern ULONG POST_SIGNAL32(USHORT usSignal, USHORT usAction, USHORT usSignalArg, USHORT usPIDSGR); | 
|---|
| 318 | ; @returns  NO_ERROR on success. | 
|---|
| 319 | ;           On error ERROR_NOT_DESCENDANT, ERROR_SIGNAL_REFUSED, | 
|---|
| 320 | ;           ERROR_INVALID_PROCID, ERROR_ZOMBIE_PROCESS, ERROR_SIGNAL_PENDING. (it seems) | 
|---|
| 321 | ; @param    ax          Signal number. | 
|---|
| 322 | ; @param    dx          Action. | 
|---|
| 323 | ;                       0 - the process and all children. | 
|---|
| 324 | ;                       1 - only the process | 
|---|
| 325 | ;                       2 - the process and all it's decendants. | 
|---|
| 326 | ;                       3 - all processes in that screen group. | 
|---|
| 327 | ; @param    cx          Signal argument. | 
|---|
| 328 | ; @param    [ebp+14h]   Process Id or Screen Group Id. | 
|---|
| 329 | ; @uses     eax, edx, ecx | 
|---|
| 330 | ; @status   completely implemented. | 
|---|
| 331 | ; @author   knut st. osmundsen (knut.stange.osmundsen@mynd.no) | 
|---|
| 332 | ; @remark   Used by importTabInit. | 
|---|
| 333 | POST_SIGNAL32 proc near | 
|---|
| 334 | push    ebp | 
|---|
| 335 | mov     ebp, esp | 
|---|
| 336 | push    ebx | 
|---|
| 337 |  | 
|---|
| 338 | movzx   eax, ax                     ; signal | 
|---|
| 339 | movzx   ebx, dx                     ; action | 
|---|
| 340 | movzx   ecx, cx                     ; argument | 
|---|
| 341 | movzx   edx, word ptr [ebp+14h]     ; pid | 
|---|
| 342 |  | 
|---|
| 343 | jmp     far ptr CODE16:Thunk16_POST_SIGNAL32 | 
|---|
| 344 | Thunk32_POST_SIGNAL32:: | 
|---|
| 345 | jc      cps_error                   ; jump on error | 
|---|
| 346 | xor     eax, eax                    ; just to make sure it's all empty. | 
|---|
| 347 | jmp     cps_end | 
|---|
| 348 |  | 
|---|
| 349 | cps_error: | 
|---|
| 350 | movzx   eax, ax                     ; make sure upper part is empty as well. | 
|---|
| 351 |  | 
|---|
| 352 | cps_end: | 
|---|
| 353 | pop     ebx | 
|---|
| 354 | leave | 
|---|
| 355 | ret | 
|---|
| 356 | POST_SIGNAL32 endp | 
|---|
| 357 | CODE32 ends | 
|---|
| 358 |  | 
|---|
| 359 | CODE16 segment | 
|---|
| 360 | Thunk16_POST_SIGNAL32:: | 
|---|
| 361 | call    far ptr h_POST_SIGNAL | 
|---|
| 362 | jmp     far ptr FLAT:Thunk32_POST_SIGNAL32 | 
|---|
| 363 | CODE16 ends | 
|---|
| 364 |  | 
|---|
| 365 |  | 
|---|
| 366 |  | 
|---|
| 367 |  | 
|---|
| 368 | CODE16_INIT segment | 
|---|
| 369 | CODE16_INITSTART label byte | 
|---|
| 370 | CODE16_INIT ends | 
|---|
| 371 |  | 
|---|
| 372 | DATA16 segment | 
|---|
| 373 | DATA16START label byte | 
|---|
| 374 | DATA16 ends | 
|---|
| 375 |  | 
|---|
| 376 | DATA16_BSS segment | 
|---|
| 377 | DATA16_BSSSTART label byte | 
|---|
| 378 | DATA16_BSS ends | 
|---|
| 379 |  | 
|---|
| 380 | DATA16_CONST segment | 
|---|
| 381 | DATA16_CONSTSTART label byte | 
|---|
| 382 | DATA16_CONST ends | 
|---|
| 383 |  | 
|---|
| 384 | DATA16_INIT segment | 
|---|
| 385 | DATA16_INITSTART label byte | 
|---|
| 386 | DATA16_INIT ends | 
|---|
| 387 |  | 
|---|
| 388 | DATA32 segment | 
|---|
| 389 | DATA32START label byte | 
|---|
| 390 | DATA32 ends | 
|---|
| 391 |  | 
|---|
| 392 | BSS32 segment | 
|---|
| 393 | BSS32START label byte | 
|---|
| 394 | BSS32 ends | 
|---|
| 395 |  | 
|---|
| 396 | CONST32_RO segment | 
|---|
| 397 | CONST32_ROSTART label byte | 
|---|
| 398 | CONST32_RO ends | 
|---|
| 399 |  | 
|---|
| 400 | _VFT segment | 
|---|
| 401 | _VFTSTART LABEL BYTE | 
|---|
| 402 | _VFT ends | 
|---|
| 403 |  | 
|---|
| 404 | EH_DATA segment | 
|---|
| 405 | EH_DATASTART LABEL BYTE | 
|---|
| 406 | EH_DATA ends | 
|---|
| 407 |  | 
|---|
| 408 | END | 
|---|
| 409 |  | 
|---|