summaryrefslogtreecommitdiffstats
path: root/usr.bin/doscmd/emsdriv.S
blob: 40c7affd00b703ff591e59881b1aaec9550ec4ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
! Copyright (c) 1997 Helmut Wirth <hfwirth@ping.at>
! All rights reserved.
!
! Redistribution and use in source and binary forms, with or without
! modification, are permitted provided that the following conditions
! are met:
! 1. Redistributions of source code must retain the above copyright
!    notice immediately at the beginning of the file, witout modification,
!    this list of conditions, and the following disclaimer.
! 2. Redistributions in binary form must reproduce the above copyright
!    notice, this list of conditions and the following disclaimer in the
!    documentation and/or other materials provided with the distribution.
! 3. The name of the author may not be used to endorse or promote products
!    derived from this software without specific prior written permission.
!
! THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
! IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
! OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
! IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
! INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
! NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
! DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
! THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
! (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
! THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
!
! $FreeBSD$


!
! This driver is needed for Expanded Memory emulation (EMS). A driver
! is needed here, because EMS drivers are installed as DOS devices
! with the name "EMMXXXX0" and programs look for such a device while
! checking the existence of EMS. 
! The driver is installed by CONFIG.SYS, it has no options. It uses
! the emulator callback interrupt 0xff to initialize the EMS subsystem.
! If EMS is not configured or if there is an error inside the emulator
! the driver reports failure and does not install itself.
! If all works, the driver changes the interrupt vector for int 0x67 to
! point at itself. The resident part of the drivers simlpy routes calls
! to int 0x67 to the correct subfunction of the emulator callback interrupt.

use16

.text
.bss
.data
.align 0

	.org	0

NumFunc	=	15

! Emulator interrupt entry
EmulatorINT = 0xFF

! Emulator EMS callback function
EMU_EMS 	= 0x2
EMU_EMS_CTL 	= 0
EMU_EMS_CALL 	= 1

! DOS print message
DOSMesg     = 0x9

cr      =       0xd
lf      =       0xa
eom     =       '$'             ! DOS end of string

EMSintnum = 0x67
Intoffset   = 	(EMSintnum * 4)

.globl _main
_main:

driverhead:
	.long	-1		! link to next device driver
	.word	0xC000		! attribute word for driver 
	.word	Strategy	! ptr to strategy routine
	.word	Interrupt	! ptr to interrupt service routine
	.ascii	"EMMXXXX0"	! logical device name

reqhead:
	.long	0

vectordone: 
	.word 	0		! != 0 , if vector installed

FuncTable:
	.word	InitDrv		! initialize driver
	.word	Noop		! media Check 
	.word	Noop		! build BPB
	.word	Noop		! Ioctl
	.word	Noop		! read
	.word	Noop  		! non destructive read
	.word	Noop		! input status
	.word	Noop		! flush input
	.word	Noop		! write
	.word	Noop		! write with verify
	.word	Noop		! output status
	.word	Noop		! flush output
	.word	Noop		! ioctl output
	.word	Noop		! open device
	.word	Noop		! close device
	.word	Noop		! removeable media check

Strategy:
	seg cs
	mov	[reqhead], bx
	seg cs
	mov	[reqhead+2],es
	retf

Interrupt:
	push	ax
	push	bx
	push	cx
	push	dx
	push	ds
	push	es
	push	di
	push	si
	push	bp
	
	push	cs
	pop	ds

	les	di,[reqhead]		! load pointer to request header

	seg es
	movb	bl,[di+2]
	xorb	bh,bh
	cmp	bx, #NumFunc
	jle	dointr
	call	errorhandler
	jmp	intrend

dointr:	
	shl	bx,#1
	call	[bx+FuncTable]
	les	di,[reqhead]		! load pointer to request header

intrend:
	or	ax,#0x100		! done bit
	seg es
	mov	[di+3],ax

	pop	bp
	pop	si
	pop	di
	pop	es
	pop	ds
	pop	dx
	pop	cx
	pop	bx
	pop	ax
	retf

errorhandler:
	mov	ax,#0x8003		! report error to caller
	ret


! This is done for all functions except init. It supports the different
! methods for an EMS installation check described in the LIM EMS 4.0 spec
Noop:
	call 	installvector
	xor	ax,ax
	ret

! The interrupt vector installed for int 0x67 points to this routine
intr67:
	push	ax			! Save original AX
	mov	ah, #EMU_EMS		! Emuint function
	mov	al, #EMU_EMS_CALL	! Emuint subfunction
	int	EmulatorINT		! Call emulator for EMS
	iret

installvector:
	push cs
	pop ds			! load DS to use local data
	mov ax,[vectordone]
	cmp ax,#0
	jne isinstalled		! already installed

	push	di		! save request header pointer
	push	es

	mov	ax, #0		! write the new interrupt vector
	mov	es, ax
	mov	di, #Intoffset
	seg	es
	mov	[di], #intr67
	seg	es
	mov	[di+2], cs

	pop	es
	pop	di

	mov ax,#1
	mov [vectordone],ax

isinstalled:
	ret

InitDrv:
	push	cs
	pop	ds
	push	ax
	mov	ah, #EMU_EMS            ! Emuint function
	mov	al, #EMU_EMS_CTL        ! Emuint subfunction
	int	EmulatorINT
	cmp	ax,#0			! check if successful
	je	Fail
	
	call	installvector

	push	cs
	pop	ds

	mov	ah, #DOSMesg
	mov	dx, #Success
	int	0x21

	seg es
	mov	[di+14], #InitDrv	! address break for driver
	seg es
	mov	[di+16], cs

	xor ax,ax
	ret

Fail:
	push cs
	pop ds
	mov	ah,  #DOSMesg
	mov	dx,  #Failure
	int	0x21

	seg es 
	movb	[di+13],#0
	seg es
	mov	[di+20],cs
	seg es
	mov	[di+14],#0		! address break == 0, no driver
	seg es
	mov	[di+16],cs
	ret


Success:	
	.ascii	"Doscmd EMS 4.0 driver installed"
	.byte	cr,lf,eom

Failure:
	.byte	cr,lf,lf
	.ascii	"EMS emulation is disabled"
	.byte	cr,lf
	.ascii	"Driver not installed"
	.byte	cr,lf,lf,eom

	end
OpenPOWER on IntegriCloud