plsintr.asm

来自「开放源码的编译器open watcom 1.6.0版的源代码」· 汇编 代码 · 共 563 行 · 第 1/2 页

ASM
563
字号
                iretd                           ; return to bkpt instruction
fakebreak       endp                            ; double whew!

public          GrabPrtScrn_
GrabPrtScrn_    proc    near
                push    ecx                     ; save registers
                push    ebx                     ; ...
                push    edx                     ; ...
                push    es                      ; ...
                push    ds                      ; ...

                mov     dataseg,ds              ; stash ds for addressability

                saveintr 05H                    ; save protected mode int 5

                mov     ax,2503h                ; save old int5 real mode
                mov     cl,5                    ; ...
                int     21h                     ; ...
                mov     int5real,ebx            ; ...

                setintr 05H,both

                pop     ds                      ; restore registers
                pop     es                      ; ...
                pop     edx                     ; ...
                pop     ebx                     ; ...
                pop     ecx                     ; ...
                ret
GrabPrtScrn_    endp

public          RelePrtScrn_
RelePrtScrn_    proc    near
                push    ecx                     ; save registers
                push    ebx                     ; ...
                push    edx                     ; ...
                push    es                      ; ...
                push    ds                      ; ...

                mov     ebx,int5real            ; restore real mode int 5
                mov     cl,5                    ; ...
                mov     ax,2505h                ; ...
                int     21h                     ; ...

                restintr 05H                    ; restore protected int 5

                pop     ds                      ; restore registers
                pop     es                      ; ...
                pop     edx                     ; ...
                pop     ebx                     ; ...
                pop     ecx                     ; ...
                ret
RelePrtScrn_    endp


public          GrabVects_
GrabVects_      proc near
                push    ecx                     ; save registers
                push    ebx                     ; ...
                push    edx                     ; ...
                push    es                      ; ...
                push    ds                      ; ...

                mov     ax,250cH                ; get hw interrupt vectors
                int     21H                     ; ...
                add     al,1                    ; this is keyboard interrupt
                cmp     _XVersion,3             ; if version >= 3
                jl      grab_idt                ; - then
                push    eax                     ; - remember kb interrupt num
                saveintr KB,al                  ; - save the keyboard handler
                pop     eax                     ; - set new keyboard handler
                setintr KB,al                   ; - ...
                jmp     done_idt                ; else
grab_idt:       movzx   ebx,al                  ; - point to IDT entry
                shl     ebx,3                   ; - ...
                mov     ax,50h                  ; - ...
                mov     es,ax                   ; - ...
                cli                             ; - interrupts off
                mov     ax,es:[ebx].hoffs       ; - save IDT entry
                mov     kbhoffs,ax              ; - ...
                mov     ax,es:[ebx].loffs       ; - ...
                mov     kbloffs,ax              ; - ...
                mov     ax,es:[ebx].select      ; - ...
                mov     kbselect,ax             ; - ...
                mov     al,es:[ebx].arights     ; - ...
                mov     kbarights,al            ; - ...
                lea     eax,intKB               ; - set new keyboard handler
                mov     es:[ebx].loffs,ax       ; - ...
                shr     eax,16                  ; - ...
                mov     es:[ebx].hoffs,ax       ; - ...
                mov     es:[ebx].select,cs      ; - ...
                mov     es:[ebx].arights,08EH   ; - ...
                sti                             ; - interrupts back on
done_idt:                                       ; endif

                saveintr 20H
                setintr 20H
                saveintr 21H
                setintr 21H
                saveintr 27H
                setintr 27H

                mov     eax,1                   ; return true
                jmp     epi                     ; ...
false:          xor     eax,eax                 ; return false
epi:            pop     ds                      ; restore registers
                pop     es                      ; ...
                pop     edx                     ; ...
                pop     ebx                     ; ...
                pop     ecx                     ; ...
                ret                             ; return to caller
GrabVects_      endp

public          ReleVects_
ReleVects_      proc near
                push    ecx                     ; save registers
                push    edx                     ; ...
                push    ds                      ; ...
                push    es                      ; ...

                cmp     _XVersion,3             ; if version >= 3
                jl      fix_idt                 ; - then
                mov     ax,250cH                ; - get hw interrupt vectors
                int     21H                     ; - ...
                add     al,1                    ; - this is keyboard interrupt
                restintr KB,al                  ; - restore it
                jmp     fixed_idt               ; else
fix_idt:        cmp     byte ptr kbarights,0    ; - if we have taken it over
                je      fixed_idt               ; - - then

                mov     ax,250cH                ; - - get hw interrupt vectors
                int     21H                     ; - - ...
                add     al,1                    ; - - this is keyboard interrupt
                movzx   ebx,al                  ; - - ...
                shl     ebx,3                   ; - - ...
                mov     ax,50h                  ; - - point to IDT
                mov     es,ax                   ; - - ...

                cli                             ; - ...
                mov     ax,kbhoffs              ; - ...
                mov     es:[ebx].hoffs,ax       ; - ...
                mov     ax,kbloffs              ; - ...
                mov     es:[ebx].loffs,ax       ; - save offset
                mov     ax,kbselect             ; - ...
                mov     es:[ebx].select,ax      ; - save offset
                mov     al,kbarights            ; - ...
                mov     es:[ebx].arights,al     ; - ...
                sti                             ; - ...
                                                ; - endif
fixed_idt:                                      ; endif
                restintr 20H
                restintr 21H
                restintr 27H

                pop     es                      ; restore registers
                pop     ds                      ; ...
                pop     edx                     ; ...
                pop     ecx                     ; ...
                ret                             ; return to caller
ReleVects_      endp

public          GetDosLong_
GetDosLong_     proc near
                push    fs
                mov     fs,_Meg1
                mov     eax,dword ptr fs:[eax]
                pop     fs
                ret
GetDosLong_     endp

public          GetDosByte_
GetDosByte_     proc near
                push    fs
                mov     fs,_Meg1
                movzx   eax,byte ptr fs:[eax]
                pop     fs
                ret
GetDosByte_     endp

public          PutDosByte_
PutDosByte_     proc near
                push    fs
                mov     fs,_Meg1
                mov     byte ptr fs:[eax],dl
                pop     fs
                ret
PutDosByte_     endp

public          PutDosLong_
PutDosLong_     proc near
                push    fs
                mov     fs,_Meg1
                mov     fs:[eax],edx
                pop     fs
                ret
PutDosLong_     endp

public          CallRealMode_
CallRealMode_   proc near
                push    ebx
                push    ecx
                push    edx
                push    esi
                push    edi
                push    ebp
                mov     ebx,eax
                xor     ecx,ecx
                mov     ax,250eH
                int     21H
                pop     ebp
                pop     edi
                pop     esi
                pop     edx
                pop     ecx
                pop     ebx
                ret
CallRealMode_   endp

public          SetPSP_
SetPSP_         proc near
                push    ebx
                mov     bx,ax
                mov     ah,50H
                int     21H
                pop     ebx
                ret
SetPSP_         endp


public          GetDS_
GetDS_          proc    near
                xor     eax,eax
                mov     ax,ds
                ret
GetDS_          endp


public          GetCS_
GetCS_          proc    near
                xor     eax,eax
                mov     ax,cs
                ret
GetCS_          endp


public          SetMSW_
SetMSW_         proc near
                push    edx             ; save regs
                push    ecx             ; ...
                push    ebx             ; ...
                mov     ecx,eax         ; save new CR0 value
                and     ecx, 6          ; isolate EM, MP bits
                mov     ax,cs           ; get CPL
                and     ax,3            ; ...
                je      ring_0          ; if ring_0, do the stuff ourselves
                sub     esp,48          ; allocate buffer space
                mov     edx,esp         ; point at buffer
                xor     ebx,ebx         ; read system regs
                mov     ax,2535H        ; ...
                int     21H             ; ...
                and     byte ptr [edx], 0f9h; turn off EM, MP bits
                or      [edx],ecx       ; set new CR0 value (EM, MP bits)
                inc     ebx             ; write system regs
                int     21H             ; ...
                add     esp,48          ; dealloc buffer space
done:
                pop     ebx
                pop     ecx
                pop     edx
                ret
ring_0:
                mov     eax,cr0         ; get current
                and     eax,NOT 6       ; turn off EM, MP bits
                or      ecx,eax         ; merge two CR0's together
                mov     cr0,ecx         ; retore EM, MP bits to original
                jmp     short done
SetMSW_         endp

_text           ends

                end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?