Merge branch 'vendor/OPENSSH'
[dragonfly.git] / usr.bin / doscmd / emsdriv.S
1 ! Copyright (c) 1997 Helmut Wirth <hfwirth@ping.at>
2 ! All rights reserved.
3 !
4 ! Redistribution and use in source and binary forms, with or without
5 ! modification, are permitted provided that the following conditions
6 ! are met:
7 ! 1. Redistributions of source code must retain the above copyright
8 !    notice immediately at the beginning of the file, witout modification,
9 !    this list of conditions, and the following disclaimer.
10 ! 2. Redistributions in binary form must reproduce the above copyright
11 !    notice, this list of conditions and the following disclaimer in the
12 !    documentation and/or other materials provided with the distribution.
13 ! 3. The name of the author may not be used to endorse or promote products
14 !    derived from this software without specific prior written permission.
15 !
16 ! THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 ! IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 ! OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 ! IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 ! INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 ! NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 ! DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 ! THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
24 ! (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 ! THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 !
27 ! $FreeBSD: src/usr.bin/doscmd/emsdriv.S,v 1.2 1999/08/28 01:00:14 peter Exp $
28 ! $DragonFly: src/usr.bin/doscmd/emsdriv.S,v 1.2 2003/06/17 04:29:26 dillon Exp $
29
30
31 !
32 ! This driver is needed for Expanded Memory emulation (EMS). A driver
33 ! is needed here, because EMS drivers are installed as DOS devices
34 ! with the name "EMMXXXX0" and programs look for such a device while
35 ! checking the existence of EMS. 
36 ! The driver is installed by CONFIG.SYS, it has no options. It uses
37 ! the emulator callback interrupt 0xff to initialize the EMS subsystem.
38 ! If EMS is not configured or if there is an error inside the emulator
39 ! the driver reports failure and does not install itself.
40 ! If all works, the driver changes the interrupt vector for int 0x67 to
41 ! point at itself. The resident part of the drivers simlpy routes calls
42 ! to int 0x67 to the correct subfunction of the emulator callback interrupt.
43
44 use16
45
46 .text
47 .bss
48 .data
49 .align 0
50
51         .org    0
52
53 NumFunc =       15
54
55 ! Emulator interrupt entry
56 EmulatorINT = 0xFF
57
58 ! Emulator EMS callback function
59 EMU_EMS         = 0x2
60 EMU_EMS_CTL     = 0
61 EMU_EMS_CALL    = 1
62
63 ! DOS print message
64 DOSMesg     = 0x9
65
66 cr      =       0xd
67 lf      =       0xa
68 eom     =       '$'             ! DOS end of string
69
70 EMSintnum = 0x67
71 Intoffset   =   (EMSintnum * 4)
72
73 .globl _main
74 _main:
75
76 driverhead:
77         .long   -1              ! link to next device driver
78         .word   0xC000          ! attribute word for driver 
79         .word   Strategy        ! ptr to strategy routine
80         .word   Interrupt       ! ptr to interrupt service routine
81         .ascii  "EMMXXXX0"      ! logical device name
82
83 reqhead:
84         .long   0
85
86 vectordone: 
87         .word   0               ! != 0 , if vector installed
88
89 FuncTable:
90         .word   InitDrv         ! initialize driver
91         .word   Noop            ! media Check 
92         .word   Noop            ! build BPB
93         .word   Noop            ! Ioctl
94         .word   Noop            ! read
95         .word   Noop            ! non destructive read
96         .word   Noop            ! input status
97         .word   Noop            ! flush input
98         .word   Noop            ! write
99         .word   Noop            ! write with verify
100         .word   Noop            ! output status
101         .word   Noop            ! flush output
102         .word   Noop            ! ioctl output
103         .word   Noop            ! open device
104         .word   Noop            ! close device
105         .word   Noop            ! removeable media check
106
107 Strategy:
108         seg cs
109         mov     [reqhead], bx
110         seg cs
111         mov     [reqhead+2],es
112         retf
113
114 Interrupt:
115         push    ax
116         push    bx
117         push    cx
118         push    dx
119         push    ds
120         push    es
121         push    di
122         push    si
123         push    bp
124         
125         push    cs
126         pop     ds
127
128         les     di,[reqhead]            ! load pointer to request header
129
130         seg es
131         movb    bl,[di+2]
132         xorb    bh,bh
133         cmp     bx, #NumFunc
134         jle     dointr
135         call    errorhandler
136         jmp     intrend
137
138 dointr: 
139         shl     bx,#1
140         call    [bx+FuncTable]
141         les     di,[reqhead]            ! load pointer to request header
142
143 intrend:
144         or      ax,#0x100               ! done bit
145         seg es
146         mov     [di+3],ax
147
148         pop     bp
149         pop     si
150         pop     di
151         pop     es
152         pop     ds
153         pop     dx
154         pop     cx
155         pop     bx
156         pop     ax
157         retf
158
159 errorhandler:
160         mov     ax,#0x8003              ! report error to caller
161         ret
162
163
164 ! This is done for all functions except init. It supports the different
165 ! methods for an EMS installation check described in the LIM EMS 4.0 spec
166 Noop:
167         call    installvector
168         xor     ax,ax
169         ret
170
171 ! The interrupt vector installed for int 0x67 points to this routine
172 intr67:
173         push    ax                      ! Save original AX
174         mov     ah, #EMU_EMS            ! Emuint function
175         mov     al, #EMU_EMS_CALL       ! Emuint subfunction
176         int     EmulatorINT             ! Call emulator for EMS
177         iret
178
179 installvector:
180         push cs
181         pop ds                  ! load DS to use local data
182         mov ax,[vectordone]
183         cmp ax,#0
184         jne isinstalled         ! already installed
185
186         push    di              ! save request header pointer
187         push    es
188
189         mov     ax, #0          ! write the new interrupt vector
190         mov     es, ax
191         mov     di, #Intoffset
192         seg     es
193         mov     [di], #intr67
194         seg     es
195         mov     [di+2], cs
196
197         pop     es
198         pop     di
199
200         mov ax,#1
201         mov [vectordone],ax
202
203 isinstalled:
204         ret
205
206 InitDrv:
207         push    cs
208         pop     ds
209         push    ax
210         mov     ah, #EMU_EMS            ! Emuint function
211         mov     al, #EMU_EMS_CTL        ! Emuint subfunction
212         int     EmulatorINT
213         cmp     ax,#0                   ! check if successful
214         je      Fail
215         
216         call    installvector
217
218         push    cs
219         pop     ds
220
221         mov     ah, #DOSMesg
222         mov     dx, #Success
223         int     0x21
224
225         seg es
226         mov     [di+14], #InitDrv       ! address break for driver
227         seg es
228         mov     [di+16], cs
229
230         xor ax,ax
231         ret
232
233 Fail:
234         push cs
235         pop ds
236         mov     ah,  #DOSMesg
237         mov     dx,  #Failure
238         int     0x21
239
240         seg es 
241         movb    [di+13],#0
242         seg es
243         mov     [di+20],cs
244         seg es
245         mov     [di+14],#0              ! address break == 0, no driver
246         seg es
247         mov     [di+16],cs
248         ret
249
250
251 Success:        
252         .ascii  "Doscmd EMS 4.0 driver installed"
253         .byte   cr,lf,eom
254
255 Failure:
256         .byte   cr,lf,lf
257         .ascii  "EMS emulation is disabled"
258         .byte   cr,lf
259         .ascii  "Driver not installed"
260         .byte   cr,lf,lf,eom
261
262         end