home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 5 / ctrom5b.zip / ctrom5b / PROGRAM / DIVERSEN / DOS32V3B / EXAMPLES / EG5.ASM < prev    next >
Assembly Source File  |  1995-02-14  |  4KB  |  134 lines

  1. ;**************************************************************************
  2. ;  EG5.ASM
  3. ;
  4. ; This program hooks IRQ 0 and loads and executes COMMAND.COM
  5. ;
  6. ; By Adam Seychell
  7. ;**************************************************************************
  8. .386
  9. .model  flat
  10. .stack 400h
  11. .code
  12.  
  13.  
  14.  
  15. align 4
  16.  
  17. saved_INT8              DF 0
  18. comspec_ptr             dd 0
  19. dummy_cmd_tail      db 1,' '
  20. meag_v86            db ' Exiting protected mode ',10,13,36
  21. mesg_pmode          db 'Got into 32bit protected mode ',10,13
  22.                     db  10,'Press any key to load and execute COMMAND.COM$'
  23.  
  24.  
  25.  
  26. start32:                ; 32 bit code entry point.
  27.  
  28.  
  29.  
  30.       ; *****************  print a message *****************
  31.  
  32.         mov edx,offset mesg_pmode
  33.         mov ah,9
  34.         int 21h                     ; print string
  35.  
  36.  
  37.  
  38.  
  39.  
  40.     ;********** Hook Timer inerrupt ( IRQ 0 ) just for fun ****************
  41.  
  42.         mov     bl,8                        ;Save IRQ 0 interrupt vector
  43.         mov     ax,204h
  44.         int     31h
  45.         mov     dword ptr saved_INT8 , edx
  46.         mov     word ptr saved_INT8+4 , cx
  47.  
  48.         mov     bl,8                      ; Set the new IRQ 0 vector
  49.         mov     edx,offset  timer_int     ; See below
  50.         mov     cx,cs                     ; CS:EDX = selector:offset
  51.         mov     ax,205h
  52.         int     31h
  53.  
  54.  
  55.         mov     ah,0                    ; wait for key
  56.         int     16h
  57.  
  58.  
  59. ;************** LOAD AND EXECUTE A PROGRAM ( command.com ) *****************
  60.  
  61. ;
  62. ; search for the "COMSPEC=" environemnt varibles
  63. ;
  64.  
  65.         mov     ax,0EE02h            ; Get DOS32 address information
  66.         int     31h                  ; Returns EDI -> environment address
  67. get_str_loop:
  68.         cmp     dword ptr [edi],'SMOC'          ; cmp the string "COMSPEC="
  69.         jne not_string
  70.         cmp     dword ptr [edi+4],'=CEP'
  71.         je got_string                           ; if equal exit loop
  72. not_string:
  73.         mov     al,0                            ; Scan environment for a zero
  74.         mov     ecx,20000                       ; and get next varible
  75.         repne   scasb
  76.         jmp  get_str_loop                       ; loop around again
  77.  
  78. got_string:
  79.         add     edi,8
  80.         mov     comspec_ptr,edi                 ; save address of the envir
  81.  
  82.  
  83. ;
  84. ; Call the 32bit version of the "load and execute" DOS service
  85. ;
  86.         mov     ah,4Bh
  87.         mov     al,0
  88.         mov     edi,00000                       ; DS:EDI -> envrironment
  89.         mov     esi,Offset dummy_cmd_tail       ; DS:ESI -> command tail
  90.         mov     edx,comspec_ptr             ; DS:EDX -> ASCIIZ string
  91.         Int     21h
  92.  
  93. ;******* restore origonal interrupt vector ********************
  94.  
  95.         mov     edx,dword ptr saved_INT8 
  96.         mov     cx,word ptr saved_INT8+4 
  97.         mov     bl,8                      ; Set the new IRQ 0 vector
  98.         mov     ax,205h
  99.         int     31h
  100.  
  101.  
  102.  
  103. ; *****************  print another message *****************
  104.         mov edx,offset meag_v86
  105.         mov ah,9
  106.         int 21h
  107.  
  108. exit:
  109.         mov   ax,4c00h            ; Terminate program
  110.         int   21h
  111.  
  112.  
  113. ;
  114. ; *****************  IRQ 0  interrupt  handler *****************
  115. ;
  116. timer_int:
  117.         push  ds                        ; must save all registers used
  118.         pushad
  119.         mov   ax,_TEXT
  120.         mov   ds,ax                    ; Load DS with data selector
  121.         mov   ax,0EE02h                 ; Get DOS32 Address information
  122.         int   31h
  123.         neg   ebx                       ; EBX = program address
  124.         add   ebx,0b8000h               ; Convert EBX to video memory
  125.         inc word ptr [ebx]              ; increment character on the screen
  126.                                         ; just to show it's doing something
  127.         popad
  128.         pop   ds
  129.         jmp   cs:saved_INT8             ; continue on interrupt chain.
  130.                                         ; must use CS because DS is unknown
  131.  
  132.  
  133. END Start32
  134.