home *** CD-ROM | disk | FTP | other *** search
- TITLE METHOD2
- ; Purpose: demonstrates interfacing between
- ; protected mode program and real mode program
- ; by shelling from protected mode to real mode.
-
- codeseg segment ;
- assume cs:codeseg ;
- ;
- rds dw (?) ;
- res dw (?) ;
- rss dw (?) ;
- rsp dw (?) ;
- rbp dw (?) ;
- rdi dw (?) ;
- rsi dw (?) ;
- rax dw (?) ;
- rbx dw (?) ;
- rcx dw (?) ;
- rdx dw (?) ;
- rfl dw (?) ;
- rseg dw (?) ;
- roff dw (?) ;
- psp dw (?) ;
- pss dw (?) ;
- ;
- ; ------ install ---------------------- ;
- ;
- ; install is passed two arguments. One is the address of
- ; the real mode buffer, passed through BASIC from the
- ; protected mode program. The other is the BASIC array,
- ; which will serve as a data transfer area.
- ;
- ; The real mode buffer is loaded with the address of the
- ; data transfer area and the address of a return
- ; instruction.
- ; NOTE => It is important to observe the following two
- ; rules:
- ; 1. install MUST be called from the main program area
- ; 2. install MUST NOT be called more than once.
- ;
- ; -------------------------------------
- ;
- ;
- install proc far ;
- public install ;
- ;
- ; start by saving the state of the processor into RAM.
- ;
- mov cs:rax,ax ; save ax
- mov cs:rbx,bx ; save bx
- mov cs:rcx,cx ; save cx
- mov cs:rdx,dx ; save dx
- mov cs:rdi,di ; save di
- mov cs:rsi,si ; save si
- lahf ;
- mov cs:rfl,ax ; save flags
- mov ax,ds ;
- mov cs:rds,ax ; save ds
- mov ax,es ;
- mov cs:res,ax ; save es
- mov ax,ss ;
- mov cs:rss,ax ; save ss
- mov ax,sp ;
- mov cs:rsp,ax ; save sp
- mov ax,bp ;
- mov cs:rbp,ax ; save bp
- push bp ;
- mov bp,sp ;
- mov ax,[bp+4] ; save portion of
- mov cs:rseg,ax ; stack
- mov ax,[bp+2] ;
- mov cs:roff,ax ;
- mov ax,cs:rds ;
- mov es,ax ;
- ;
- ; Put address of return instruction into the buffer passed
- ; through BASIC from the protected mode program.
- ;
- mov di,[bp+8] ; address of 2nd arg
- mov ax,es:[di] ; ds now defined
- mov ds,ax ; by calling routine
- mov ax,cs ; this code segment
- mov ds:[2],ax ;
- mov ax,offset retinst ; return instruction
- mov ds:[0],ax ;
- ;
- ; Put the address of the data transfer array into the
- ; same buffer.
- ;
- mov ax,cs:rds ;
- mov ds:[6],ax ;
- mov ax,[bp+6] ;
- mov ds:[4],ax ;
- mov ah,31h ; request to terminate
- int 21h ; and stay resident
- ;
- ; All future calls to the BASIC program start here.
- ;
- retinst: ;
- push cs ;
- pop ds ;
- ;
- ; Save the stack so we can recover it and return to
- ; protected mode.
- ;
- mov ax,sp ;
- mov psp,ax ; save sp
- mov ax,ss ;
- mov pss,ax ; save ss
- mov ax,rss ;
- ;
- ; Restore the processor, and part of the stack, as it was
- ; defined by BASIC.
- ;
- mov ss,ax ; restore BASIC
- mov ax,rsp ; stack segment
- mov sp,ax ; restore BASIC
- add sp,4 ; stack pointer
- push cs:rseg ; and portion of stack
- ;
- push cs:roff ;
- mov ax,rbp ; restore BASIC
- mov bp,ax ; base pointer
- mov ax,res ; restore BASIC
- mov es,ax ; extra segment
- mov ax,rds ; must be last restore
- mov ds,ax ; restore BASIC
- mov ax,cs:rfl ; data segment
- sahf ; restore flags
- mov ax,cs:rax ; restore ax
- mov bx,cs:rbx ; restore bx
- mov cx,cs:rcx ; restore cx
- mov dx,cs:rdx ; restore dx
- mov di,cs:rdi ; restore di
- mov si,cs:rsi ; restore si
- ;
- ; At this point, the return instruction delivers us to the
- ; main BASIC program, at the instruction following the call
- ; to install.
- ;
- ret 4 ; ss:sp points at
- ; BASIC code
- install endp ;
- ;
- ; ------ goback ------------------------
- ; goback returns to the calling protected mode program
- ; after the BASIC program has provided a service. It
- ; can be called from any level of the BASIC program.
- ;
- ; --------------------------------------
- ;
- ;
- goback proc far ;
- public goback ;
- mov ax,psp ; restore stack to
- mov sp,ax ; what it was when
- mov ax,pss ; protected mode
- mov ss,ax ; program called.
- ret ; return
- goback endp ;
- codeseg ends ;
- end ;
-
-