sage.asm
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 15k
Category:

Windows Kernel

Development Platform:

Visual C++

  1. PAGE 58,132
  2. ;******************************************************************************
  3. TITLE SAGE - SAGE VxD
  4. ;******************************************************************************
  5. ;
  6. ;   Title:      SAGE.ASM - SAGE VxD
  7. ;
  8. ;   Version:    0.060
  9. ;
  10. ;   Date:       04/18/95
  11. ;
  12. ;   Author:     Bob Eichenlaub    
  13. ;
  14. ;------------------------------------------------------------------------------
  15. ;
  16. ;   Change log:
  17. ;
  18. ;      DATE     REV                 DESCRIPTION
  19. ;   ----------- --- -----------------------------------------------------------
  20. ;     04/18/95      Initial version - be
  21. ;     07/06/95      serial IRQ detection - be; credit to rjc for the basic approach
  22. ;     05/23/97      [darrenmi] major clean-up and support multiple clients
  23. ;                   for IE4
  24. ;
  25. ;==============================================================================
  26.         .386p
  27. ;******************************************************************************
  28. ;                             I N C L U D E S
  29. ;******************************************************************************
  30.         .XLIST
  31.         INCLUDE VMM.Inc
  32.         INCLUDE VWIN32.Inc
  33.         INCLUDE VPICD.Inc
  34.         INCLUDE SHELL.Inc
  35.         INCLUDE VXDLDR.Inc
  36.         INCLUDE regdef.Inc
  37.         INCLUDE Debug.Inc
  38.         INCLUDE Sage.Inc
  39.         .LIST
  40. ;public SAGE_Update_User_Activity
  41. ;******************************************************************************
  42. ;              V I R T U A L   D E V I C E   D E C L A R A T I O N
  43. ;------------------------------------------------------------------------------
  44. ; The VxD declaration statement defines the VxD name, version number,
  45. ; control proc entry point, VxD ID, initialization order, and VM API 
  46. ; entry points.
  47. ;
  48. ; - Defined VxD ID: See VXDID.TXT for more information
  49. ; - Init order: If serial port detection is enabled then this Vxd MUST loaded
  50. ;               before VCOMM.VxD and after VPICD.VxD,
  51. ;               See VMM.INC for the complete
  52. ;               definition of the init order of the standard devices.
  53. ;               
  54. ;******************************************************************************
  55. Declare_Virtual_Device sage, 1, 0, SAGE_Control, VSageID, UNDEFINED_INIT_ORDER
  56. ;******************************************************************************
  57. ;                                D A T A
  58. ;******************************************************************************
  59. ;
  60. ; Locked data
  61. ;
  62. VxD_LOCKED_DATA_SEG
  63. Window_List             dd  0, 0, 0, 0, 0, 0, 0, 0
  64. cClients                dd  0       ; number of valid windows in window list
  65. Time_Out_Idle           dd  10000   ; the interval between message posts
  66. Time_Out_Handle         dd  0       ; Handle to the global time out we create
  67. Last_Activity           dd  0       ; ticks that last activity occured at
  68. Hooked_Proc             dd  0       ; shell's user_activity entry that we hooked
  69. fUser_Active            dd  0       ; did user do anything?
  70. fHooked_Service         dd  0       ; did we ever hook the service?
  71. VxD_LOCKED_DATA_ENDS
  72. ;******************************************************************************
  73. ;                               C O D E
  74. ;------------------------------------------------------------------------------
  75. ; The 'body' of the VxD is in the standard code segment.
  76. ;******************************************************************************
  77. VxD_CODE_SEG
  78. BeginProc SAGE_Start_Idle_Timer
  79.         push    esi
  80.         ; check to see if we've already got a timer
  81.         mov     esi, [Time_Out_Handle]
  82.         test    esi, esi
  83.         jnz     start1
  84.         ; get a timer
  85.         mov     eax, [Time_Out_Idle]
  86.         mov     esi, OFFSET32 SAGE_User_Idle_Check
  87.         VMMCall Set_Global_Time_Out
  88.         mov     [Time_Out_Handle], esi
  89. start1:
  90.         pop     esi
  91.         ret
  92. EndProc SAGE_Start_Idle_Timer
  93. BeginProc SAGE_Stop_Idle_Timer
  94.         push    esi
  95.         ; check to see if we have a timer
  96.         mov     esi, [Time_Out_Handle]
  97.         test    esi, esi
  98.         jz      stop1
  99.         ; kill it
  100.         VMMCall Cancel_Time_Out
  101.         xor     esi, esi
  102.         mov     [Time_Out_Handle], esi
  103. stop1:
  104.         pop     esi
  105.         ret
  106. EndProc SAGE_Stop_Idle_Timer
  107. ;******************************************************************************
  108. ;
  109. ;   SAGE_Device_IO
  110. ;
  111. ;   DESCRIPTION:
  112. ;       This is the routine that is called when the CreateFile or
  113. ;       DeviceIoControl is made
  114. ;
  115. ;   ENTRY:
  116. ;       ESI = Pointer to args (see VWIN32.INC for struct definition)
  117. ;
  118. ;   EXIT:
  119. ;       EAX = return value
  120. ;
  121. ;   USES:
  122. ;       flags
  123. ;
  124. ;==============================================================================
  125. BeginProc SAGE_Device_IO
  126.         mov     ecx, [esi.dwIOControlCode]
  127.         test    ecx, ecx
  128.         jnz     next1
  129.         ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  130.         ;
  131.         ; DIOC_GETVERSION
  132.         ;
  133.         ; hook activity service if necessary
  134.         bts     [fHooked_Service], 0
  135.         jc      getver1
  136.         ; hook activity service
  137.         mov     esi, offset32 SAGE_Update_User_Activity
  138.         GetVxDServiceOrdinal eax, SHELL_Update_User_Activity
  139.         VMMCall Hook_Device_Service
  140. getver1:
  141.         xor     eax, eax                    ; success
  142.         ret
  143. next1:
  144.         cmp     ecx,-1
  145.         jne     next2
  146.         ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  147.         ;
  148.         ; DIOC_CLOSE
  149.         ;
  150.         ; see if we have clients to close
  151.         cmp     [cClients], 0
  152.         jz      close1
  153.         ; we do... see if it's the last one...
  154.         dec     [cClients]
  155.         cmp     [cClients], 0
  156.         jnz     close1
  157.         ; last client going away - clean up
  158.         call    SAGE_Stop_Idle_Timer
  159.         btr     [fHooked_Service], 0
  160.         jnc     close1
  161.         ; unhook activity service
  162.         GetVxDServiceOrdinal    eax,SHELL_Update_User_Activity
  163.         mov     esi, offset32 SAGE_Update_User_Activity
  164.         VMMCall Unhook_Device_Service
  165. close1:
  166.         xor     eax,eax     ; success
  167.         ret
  168. next2:
  169.         cmp     ecx,1
  170.         jne     next3
  171.         ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  172.         ;
  173.         ; Set handle and timeout
  174.         ;
  175.         mov     ebx, [esi.lpvInBuffer]
  176.         ; Try to find window handle
  177.         mov     eax, [ebx]
  178.         mov     ecx, [cClients]
  179.         test    ecx, ecx
  180.         jz      addtolist
  181. ioloop:
  182.         cmp     eax, [Window_List + 4 * ecx - 4]
  183.         je      timeout
  184.         dec     ecx
  185.         jnz     ioloop
  186.         ; Can't find it - add it to window list
  187.         mov     ecx, [cClients]
  188.         cmp     ecx, 8
  189.         jnl     timeout
  190. addtolist:
  191.         inc     [cClients]
  192.         mov     [Window_List + 4 * ecx], eax
  193. timeout:
  194.         ; update timeout if specified
  195.         mov     eax, [ebx+8]
  196.         test    eax, eax
  197.         jz      config1
  198.         mov     [Time_Out_Idle], eax
  199. config1:
  200.         call    SAGE_Start_Idle_Timer
  201.         xor     eax, eax    ; success
  202.         ret
  203. next3:
  204.         cmp     ecx, 2
  205.         jne     next4
  206.         ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  207.         ;
  208.         ; Query last activity
  209.         ;
  210.         mov     ebx, [esi.lpvInBuffer]
  211.         mov     eax, [Last_Activity]
  212.         mov     [ebx], eax
  213.         xor     eax, eax
  214.         ret
  215. next4:
  216.         ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  217.         ;
  218.         ; some unsupported value...
  219.         ;
  220.         mov     eax, ERROR_NOT_SUPPORTED
  221.         ret
  222. EndProc SAGE_Device_IO
  223. VxD_CODE_ENDS
  224. ;******************************************************************************
  225. ;                      P A G E   L O C K E D   C O D E
  226. ;------------------------------------------------------------------------------
  227. ;       Memory is a scarce resource. Use this only where necessary.
  228. ;******************************************************************************
  229. VxD_LOCKED_CODE_SEG
  230. ;******************************************************************************
  231. ;
  232. ;   SAGE_Control
  233. ;
  234. ;   DESCRIPTION:
  235. ;
  236. ;       This is a call-back routine to handle the messages that are sent
  237. ;       to VxD's to control system operation. Every VxD needs this function
  238. ;       regardless if messages are processed or not. The control proc must
  239. ;       be in the LOCKED code segment.
  240. ;
  241. ;       The Control_Dispatch macro used in this procedure simplifies
  242. ;       the handling of messages. To handle a particular message, add
  243. ;       a Control_Dispatch statement with the message name, followed
  244. ;       by the procedure that should handle the message. 
  245. ;
  246. ;   ENTRY:
  247. ;       EAX = Message number
  248. ;       EBX = VM Handle
  249. ;
  250. ;==============================================================================
  251. BeginProc SAGE_Control
  252.         Control_Dispatch W32_DEVICEIOCONTROL, SAGE_Device_IO
  253.         clc
  254.         ret
  255. EndProc SAGE_Control
  256. BeginDoc
  257. ;******************************************************************************
  258. ;
  259. ; SAGE_Update_User_Activity
  260. ;
  261. ; DESCRIPTION:
  262. ;
  263. ;   This service is called by VMD, VKD to tell us that user input occured
  264. ; ENTRY:    None
  265. ; EXIT:     None
  266. ; USES:     NONE
  267. ;==============================================================================
  268. EndDoc
  269. BeginProc SAGE_Update_User_Activity, HOOK_PROC, Hooked_Proc
  270.     push    eax
  271.     ; flag something happened
  272.     inc     [fUser_Active]
  273.     ; save off the time
  274.     VMMCall Get_Last_Updated_System_Time
  275.     mov     [Last_Activity], eax
  276.     pop     eax
  277.     jmp     Hooked_Proc
  278. EndProc SAGE_Update_User_Activity
  279. VxD_LOCKED_CODE_ENDS
  280. VxD_PAGEABLE_CODE_SEG
  281. ;******************************************************************************
  282. ;
  283. ; SAGE_User_Idle_Check
  284. ;
  285. ; DESCRIPTION:
  286. ;
  287. ;   This checks if key/mouse or serial port (comm) event has occurred.
  288. ;
  289. ; Entry:
  290. ;   None
  291. ; Exit:
  292. ;   None
  293. ; Uses:
  294. ;   ALL
  295. ;******************************************************************************
  296. BeginProc SAGE_User_Idle_Check,High_Freq,PUBLIC                                 
  297.                                                                                 
  298.     ;                                                                           
  299.     ; clear handle                                                              
  300.     ;                                                                           
  301.     xor     ecx, ecx                                                            
  302.     mov     [Time_Out_Handle], ecx                                              
  303.                                                                                 
  304.     ;                                                                           
  305.     ; check for idleness                                                        
  306.     ;                                                                           
  307.     xchg    ecx, [fUser_Active]
  308.     test    ecx, ecx                                                            
  309.     jz      ResetTimer                                                          
  310.                                                                                 
  311.     ;                                                                           
  312.     ; Not idle so post a message to all clients who want to know
  313.     ;                     
  314.     xor     eax, eax                                                            
  315.     mov     ecx, [cClients]
  316.     test    ecx, ecx                                                            
  317.     jz      ResetTimer                                                          
  318. loop0:
  319.     ; get next window
  320.     mov     ebx, [4 * ecx + Window_List - 4]
  321.     ; skip if it's -1
  322.     cmp     ebx, -1
  323.     je      loop1
  324.                                                                                 
  325.     ; post message
  326.     push    ecx
  327.     VxDCall _SHELL_PostMessage, <ebx, WM_SAGE_MSG, eax, eax, eax, eax>          
  328.     pop     ecx
  329. loop1:
  330.     dec     ecx
  331.     jnz     loop0
  332.     ;                                                                           
  333.     ; reset the timer so we check again later                                   
  334.     ;                                                                           
  335. ResetTimer:                                                                     
  336.     call    SAGE_Start_Idle_Timer
  337.     ret                                                                         
  338.                                                                                 
  339. EndProc SAGE_User_Idle_Check                                                    
  340. VxD_PAGEABLE_CODE_ENDS
  341. ;******************************************************************************
  342. ;                       R E A L   M O D E   C O D E
  343. ;******************************************************************************
  344. ;******************************************************************************
  345. ;
  346. ;       Real mode initialization code
  347. ;
  348. ;   DESCRIPTION:
  349. ;       This code is called when the system is still in real mode, and
  350. ;       the VxDs are being loaded.
  351. ;
  352. ;       This routine as coded shows how a VxD (with a defined VxD ID)
  353. ;       could check to see if it was being loaded twice, and abort the 
  354. ;       second without an error message. Note that this would require
  355. ;       that the VxD have an ID other than Undefined_Device_ID. See
  356. ;       the file VXDID.TXT more details.
  357. ;
  358. ;   ENTRY:
  359. ;       AX = VMM Version
  360. ;       BX = Flags
  361. ;               Bit 0: duplicate device ID already loaded 
  362. ;               Bit 1: duplicate ID was from the INT 2F device list
  363. ;               Bit 2: this device is from the INT 2F device list
  364. ;       EDX = Reference data from INT 2F response, or 0
  365. ;       SI = Environment segment, passed from MS-DOS
  366. ;
  367. ;   EXIT:
  368. ;       BX = ptr to list of pages to exclude (0, if none)
  369. ;       SI = ptr to list of instance data items (0, if none)
  370. ;       EDX = DWORD of reference data to be passed to protect mode init
  371. ;
  372. ;==============================================================================
  373. VxD_REAL_INIT_SEG
  374. BeginProc SAGE_Real_Init_Proc
  375.         test    bx, Duplicate_Device_ID ; check for already loaded
  376.         jnz     short duplicate         ; jump if so
  377.         xor     bx, bx                  ; no exclusion table
  378.         xor     si, si                  ; no instance data table
  379.         xor     edx, edx                ; no reference data
  380.         mov     ax, Device_Load_Ok
  381.         ret
  382. duplicate:
  383.         mov     ax, Abort_Device_Load + No_Fail_Message
  384.         ret
  385. EndProc SAGE_Real_Init_Proc
  386. VxD_REAL_INIT_ENDS
  387.         END