EuroAssembler Index Manual Download Source Macros


Sitemap Links Forum Tests Projects

kblock.htm

KeyBoard Lock is an example of DOS character device driver. Its only function is to temporarily disable (lock) keyboard during DOS start, which should prevent the computer user from breaking the boot process and launching applications not approved by administrator.
Keyboard is locked by sending command-code 0xF5 to its microcontroller at IO port 0x60.

It can be unlocked with command-code 0xF4 sent to the same port, which should be done by the desired application, placed in AUTOEXEC.BAT. Sample Keyboard Unlock is an example of such application.

Format
DOS driver
Platform
DOS
Documented
[DosDriver]
Build
euroasm.exe kblock.htm
Run
Add line DEVICE=kblock.sys to configuration file CONFIG.SYS , which is stored in the root directory of DOS boot disk.
See also
kbunlock
Program prologue
DOS driver begins with a structure DRIVER_HEADER which defines its name, attributes and addresses of two main routines.
        EUROASM AutoAlign=Off,DumpAll=Yes,DumpWidth=20,CPU=186,Priv=Enabled
kblock  PROGRAM Format=BIN,Model=Small,Width=16,ListMap=Off,ListGlobals=Off,OutFile=kblock.sys
         INCLUDE doss.htm ; Definition of DOS structures and symbols.

Driver:: DS DRIVER_HEADER, .Device="KBLOCK", .Attributes=drvCharDevice, \
                            .Strategy=Strategy, .Interrupt=Interrupt
Strategy routine
The only function of Strategy procedure is to save the address of the request prepared by the caller of our driver. Pointer to the request is delivered in ES:BX.
Strategy: PROC DIST=FAR
           MOV [CS:Driver.RequestOfs],BX
           MOV [CS:Driver.RequestSeg],ES
           RET
          ENDPROC Strategy:

Interrupt routine

Procedure Interrupt is invoked by DOS when some service needs to access the device served by this driver.
It should read the request and perform the desired Request.Command with the device. Result is returned in Request.Status.

The first requested action is Request.Command=0 (initialization) invoked during installation, which makes the driver resident in memory. This simple driver doesn't understand any other command than initialization.

Sample driver KBLOCK occupies 96 bytes of memory, as can be seen with MEM /D.
Interrupt:PROC DIST=FAR
           PUSHAW
            PUSH DS
             LDS BX,[CS:Driver.Request] ; Get address of the request into DS:BX, which was saved in Strategy routine.
             MOV [DS:BX+DRIVER_REQUEST.Status],dstDone ; Tell the caller that the command was done.
             MOV AL,[DS:BX+DRIVER_REQUEST.Command]
             CMP AL,0     ; The only accepted command is initialization (.Command=0)
             JNE .Ignore: ; Ignore all other commands.
             MOV AL,0xF5  ; Perform the driver function.
             OUT 0x60,AL  ; Disable the keyboard by sending code 0xF5 to its port.
             MOV [DS:BX+DRIVER_REQUEST.Status],dstError+dstGeneralFailure
             MOV DX,Message$ ; End of Interrupt routine.
             MOV [DS:BX+DRIVER_REQUEST.TermOfs],DX
             MOV [DS:BX+DRIVER_REQUEST.TermSeg],CS
             PUSH CS
             POP DS
             MOV AH,9
             INT 0x21 ; Display Message$ addressed by DS:DX.
   .Ignore: POP DS
           POPAW
           RET
          ENDPROC Interrupt
Message$  DB 13,10,"Keyboard is temporarily disabled by KBLOCK.",13,10,'$'
      ENDPROGRAM kblock

▲Back to the top▲