source: sbliveos2/trunk/drv32/startup.asm@ 175

Last change on this file since 175 was 148, checked in by sandervl, 25 years ago

beta 0.25 update

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 15.5 KB
Line 
1; $Id: startup.asm 148 2000-04-26 18:01:02Z sandervl $
2
3
4; 16 bits entrypoints for the PDD and thunks to call 32 bits code
5;
6; Copyright (C) 2000 Sander van Leeuwen
7;
8; Partly based on MWDD32 (32 bits OS/2 device driver and IFS support driver)
9; Copyright (C) 1995, 1996 Matthieu WILLM
10;
11; This program is free software; you can redistribute it and/or modify
12; it under the terms of the GNU General Public License as published by
13; the Free Software Foundation; either version 2 of the License, or
14; (at your option) any later version.
15;
16; This program is distributed in the hope that it will be useful,
17; but WITHOUT ANY WARRANTY; without even the implied warranty of
18; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19; GNU General Public License for more details.
20;
21; You should have received a copy of the GNU General Public License
22; along with this program; if not, write to the Free Software
23; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24
25 .386p
26
27
28 INCL_DOS equ 1
29 INCL_DOSERRORS equ 1
30 include os2.inc
31
32 include sbseg.inc
33
34DevHlp_VirtToLin EQU 5Bh
35DevHlp_VMLock EQU 55h
36
37; Status word masks
38STERR EQU 8000H ; Bit 15 - Error
39STINTER EQU 0400H ; Bit 10 - Interim character
40STBUI EQU 0200H ; Bit 9 - Busy
41STDON EQU 0100H ; Bit 8 - Done
42STECODE EQU 00FFH ; Error code
43
44; Definition of the request packet header.
45
46reqPacket struc
47reqLenght db ?
48reqUnit db ?
49reqCommand db ?
50reqStatus dw ?
51reqFlags db ?
52 db 3 dup (?) ; Reserved field
53reqLink dd ?
54reqPacket ends
55
56rpInitIn struc
57i_rph db size reqPacket dup (?)
58i_unit db ?
59i_devHelp dd ?
60i_initArgs dd ?
61i_driveNum db ?
62rpInitIn ends
63
64rpInitOut struc
65o_rph db size reqPacket dup (?)
66o_unit db ?
67o_codeend dw ?
68o_dataend dw ?
69o_bpbarray dd ?
70o_status dw ?
71rpInitOut ends
72
73BEGINCS16 EQU OFFSET CODE16:help_stub_strategy
74BEGINDS16 EQU OFFSET DATA16:help_header
75
76DATA16 segment
77 extrn DOS32FLATDS : abs ; ring 0 FLAT kernel data selector
78 public __OffFinalDS16
79 public help_header
80 public sblive_header
81 public _MSG_TABLE16
82 public DevHelpInit
83 public fOpen
84 public InitPktSeg
85 public InitPktOff
86 public _MESSAGE_STR
87 public pddname16
88 public FileName
89
90;*********************************************************************************************
91;************************* Device Driver Header **********************************************
92;*********************************************************************************************
93;DEZE MOET ALS EERSTE blijven staan!!!!
94help_header dw (OFFSET sblive_header - BEGINDS16)
95;dw OFFSET DATA16:sblive_header ; Pointer to next driver
96 dw SEG DATA16:sblive_header
97 dw 1000100110000000b ; Device attributes
98; ||||| +-+ ||||
99; ||||| | | |||+------------------ STDIN
100; ||||| | | ||+------------------- STDOUT
101; ||||| | | |+-------------------- NULL
102; ||||| | | +--------------------- CLOCK
103; ||||| | |
104; ||||| | +------------------------+ (001) OS/2
105; ||||| | | (010) DosDevIOCtl2 + SHUTDOWN
106; ||||| +--------------------------+ (011) Capability bit strip
107; |||||
108; ||||+----------------------------- OPEN/CLOSE (char) or Removable (blk)
109; |||+------------------------------ Sharing support
110; ||+------------------------------- IBM
111; |+-------------------------------- IDC entry point
112; +--------------------------------- char/block device driver
113
114; dw offset CODE16:help_stub_strategy ; Strategy routine entry point
115 dw (offset help_stub_strategy - BEGINCS16) ; Strategy routine entry point
116 dw 0 ; IDC routine entry point
117 db 'OSSHLP$ ' ; Device name
118 db 8 dup (0) ; Reserved
119 dw 0000000000010011b ; Level 3 device driver capabilities
120; |||||
121; ||||+------------------ DosDevIOCtl2 + Shutdown
122; |||+------------------- More than 16 MB support
123; ||+-------------------- Parallel port driver
124; |+--------------------- Adapter device driver
125; +---------------------- InitComplete
126 dw 0000000000000000b
127
128sblive_header dd -1
129 dw 1101100110000000b ; Device attributes
130; ||||| +-+ ||||
131; ||||| | | |||+------------------ STDIN
132; ||||| | | ||+------------------- STDOUT
133; ||||| | | |+-------------------- NULL
134; ||||| | | +--------------------- CLOCK
135; ||||| | |
136; ||||| | +------------------------+ (001) OS/2
137; ||||| | | (010) DosDevIOCtl2 + SHUTDOWN
138; ||||| +--------------------------+ (011) Capability bit strip
139; |||||
140; ||||+----------------------------- OPEN/CLOSE (char) or Removable (blk)
141; |||+------------------------------ Sharing support
142; ||+------------------------------- IBM
143; |+-------------------------------- IDC entry point
144; +--------------------------------- char/block device driver
145
146; dw offset CODE16:sblive_stub_strategy; Strategy routine entry point
147 dw (offset sblive_stub_strategy - BEGINCS16); Strategy routine entry point
148 dw (offset sblive_stub_idc - BEGINCS16) ; IDC routine entry point
149 db 'SBLIVE2$' ; Device name
150 db 8 dup (0) ; Reserved
151 dw 0000000000010011b ; Level 3 device driver capabilities
152; |||||
153; ||||+------------------ DosDevIOCtl2 + Shutdown
154; |||+------------------- More than 16 MB support
155; ||+-------------------- Parallel port driver
156; |+--------------------- Adapter device driver
157; +---------------------- InitComplete
158 dw 0000000000000000b
159
160DevHelpInit dd 0
161fOpen dd 0
162InitPktSeg dw 0
163InitPktOff dw 0
164;needed for rmcalls.lib
165_RM_Help0 dd 0
166_RM_Help1 dd 0
167_RM_Help3 dd 0
168_RMFlags dd 0
169_MESSAGE_STR db 1024 dup (0)
170_MSG_TABLE16 dw 0 ;message length
171 dw (OFFSET _MESSAGE_STR - BEGINDS16) ;message far pointer
172 dw SEG _MESSAGE_STR
173
174pddname16 db 'SBLIVE2$'
175FileName db "OSSHLP$", 0
176
177;last byte in 16 bits data segment
178__OffFinalDS16 label byte
179
180DATA16 ends
181
182CODE16 segment
183 assume cs:CODE16, ds:DATA16
184
185 public __OffFinalCS16
186
187 public help_stub_strategy
188 public sblive_stub_strategy
189 public sblive_stub_idc
190 public thunk3216_devhelp
191 public thunk3216_devhelp_modified_ds
192 extrn DOSOPEN : far
193 extrn DOSCLOSE : far
194 extrn DOSWRITE : far
195
196;DEZE MOET ALS EERSTE blijven staan!!!!
197help_stub_strategy proc far
198 pushad
199 push ds
200 push es
201 push fs
202 push gs
203
204 mov ax, DATA16
205 mov ds, ax
206
207 movzx eax, byte ptr es:[bx].reqCommand
208 cmp eax, 0 ; Init
209 je short @@help_init
210 cmp eax, 0Dh ; DosOpen
211 jne short @@help_error
212;DosOpen
213 cmp word ptr ds:(offset fOpen - BEGINDS16), 0
214 je short @@help_ret_ok ; not ours
215 push ebx ; later weer nodig
216 push es
217 mov word ptr ds:(offset fOpen - BEGINDS16), 0
218 mov ax, word ptr ds:(offset InitPktSeg-BEGINDS16)
219 mov fs, ax ; fs:ebx = req. packet
220 xor ebx, ebx
221 mov bx, word ptr ds:(offset InitPktOff - BEGINDS16)
222 call far ptr FLAT:STRATEGY_
223 pop es
224 pop ebx ; oude bx ptr
225@@help_ret:
226 mov word ptr es:[bx].reqStatus, ax
227@@help_ret_error:
228 pop gs
229 pop fs
230 pop es
231 pop ds
232 popad
233 ret
234
235@@help_init:
236 mov eax, dword ptr es:[bx].i_devHelp
237 mov dword ptr ds:(offset DevHelpInit - BEGINDS16), eax
238 mov word ptr es:[bx].o_codeend, (offset __OffFinalCS16 - BEGINCS16)
239 mov word ptr es:[bx].o_dataend, (offset __OffFinalDS16 - BEGINDS16)
240
241@@help_ret_ok:
242 mov ax, STDON
243 jmp short @@help_ret
244
245@@help_error:
246 mov ax, STDON + STERR + ERROR_I24_BAD_COMMAND
247 mov word ptr es:[bx].reqStatus, ax
248 jmp short @@help_ret_error
249
250help_stub_strategy endp
251
252
253sblive_stub_strategy proc far
254 pushad
255 push ds
256 push es
257 push fs
258 push gs
259
260 mov ax, DATA16
261 mov ds, ax
262
263 movzx eax, byte ptr es:[bx].reqCommand
264 cmp eax, 0
265 jz short @@init
266
267 push ebx
268 push es
269 mov ax, bx
270 xor ebx, ebx
271 mov bx, ax
272 mov ax, es
273 mov fs, ax ; fs:ebx = req. packet
274
275 call far ptr FLAT:STRATEGY_ ; 32 bits strategy entry point
276
277 pop es
278 pop ebx ; oude bx ptr
279 mov word ptr es:[bx].reqStatus, ax ; status code
280
281@@sblive_ret:
282
283 pop gs
284 pop fs
285 pop es
286 pop ds
287 popad
288 ret
289
290@@init:
291 ;
292 ; DEVICE= initialization
293 ;
294 mov word ptr ds:(InitPktSeg - BEGINDS16), es
295 mov word ptr ds:(InitPktOff - BEGINDS16), bx
296 inc word ptr ds:(fOpen - BEGINDS16)
297 call device_init
298
299 mov word ptr es:[bx].reqStatus, ax ; status code (ret by device_init)
300 mov word ptr es:[bx].o_codeend, (offset __OffFinalCS16 - BEGINCS16)
301 mov word ptr es:[bx].o_dataend, (offset __OffFinalDS16 - BEGINDS16)
302 jmp short @@sblive_ret
303
304init_err:
305 mov dword ptr es:[bx].i_devHelp, 0
306 jmp short @@sblive_ret
307
308sblive_stub_strategy endp
309
310;in: cx = cmd
311; bx = lower 16 bits of ULONG parameter
312; dx = upper 16 bits of ULONG parameter
313;return value in dx:ax
314sblive_stub_idc proc far
315 shl edx, 16
316 mov dx, bx
317 call far ptr FLAT:IDC_ ; 32 bits strategy entry point
318
319 mov dx, ax
320 shr eax, 16
321 xchg ax, dx
322
323 retf
324sblive_stub_idc endp
325
326device_init proc near
327 enter 24, 0
328 push ds
329 push es
330 push bx
331 push si
332 push di
333
334 ; bp -> old bp
335 ; bp - 2 -> FileHandle
336 ; bp - 4 -> ActionTaken
337 ; bp - 8 -> IOCTL parm (4 bytes) : union mwdd32_ioctl_init_device_parm
338 ; bp - 24 -> IOCTL data (16 bytes) : union mwdd32_ioctl_init_device_data
339
340 ;
341 ; Opens wathlp$
342 ;
343 push seg DATA16 ; seg FileName
344 push (offset FileName - BEGINDS16) ; ofs FileName
345 push ss ; seg &FileHandle
346 lea ax, [bp - 2]
347 push ax ; ofs &FileHandle
348 push ss ; seg &ActionTaken
349 lea ax, [bp - 4]
350 push ax ; ofs &ActionTaken
351 push dword ptr 0 ; file size
352 push 0 ; file attributes
353 push OPEN_ACTION_FAIL_IF_NEW + OPEN_ACTION_OPEN_IF_EXISTS
354 push OPEN_SHARE_DENYNONE + OPEN_ACCESS_READONLY
355 push dword ptr 0 ; reserved
356 call DOSOPEN
357 cmp ax, NO_ERROR
358 jnz short @@error
359
360
361 ;
362 ; Closes wathlp$
363 ;
364 push word ptr [bp - 2] ; FileHandle
365 call DOSCLOSE
366 cmp ax, NO_ERROR
367 jnz short @@error
368
369@@out:
370 push eax ;gemold door doswrite
371
372 push 0001H
373 push DATA16
374 push (offset _MESSAGE_STR - BEGINDS16)
375 push word ptr ds:(offset _MSG_TABLE16 - BEGINDS16)
376 push ss
377 lea dx, [bp - 2]
378 push dx
379 call DOSWRITE
380
381 pop eax
382
383 pop di
384 pop si
385 pop bx
386 pop es
387 pop ds
388 leave
389 ret
390@@error:
391 mov ax, STDON + STERR + ERROR_I24_GEN_FAILURE
392 jmp short @@out
393
394device_init endp
395
396 ALIGN 2
397;use devhlp pointer stored in 16 bits code segment
398thunk3216_devhelp:
399 push ds
400 push DATA16
401 pop ds
402 call dword ptr ds:(offset DevHelpInit - BEGINDS16)
403 pop ds
404
405 jmp far ptr FLAT:thunk1632_devhelp
406
407 ALIGN 2
408thunk3216_devhelp_modified_ds:
409 push gs
410 push DATA16
411 pop gs
412 call dword ptr gs:(offset DevHelpInit - BEGINDS16)
413 pop gs
414 jmp far ptr FLAT:thunk1632_devhelp_modified_ds
415
416;end of 16 bits code segment
417__OffFinalCS16 label byte
418
419CODE16 ends
420
421CODE32 segment
422ASSUME CS:FLAT, DS:FLAT, ES:FLAT
423
424 public __OffBeginCS32
425 public __GETDS
426 public thunk1632_devhelp
427 public thunk1632_devhelp_modified_ds
428 public DevHlp
429 public DevHlp_ModifiedDS
430 public STRATEGY_
431 public IDC_
432 extrn SBLIVE_STRATEGY : near
433 extrn SBLIVE_IDC : near
434IFDEF KEE
435 extrn KernThunkStackTo16 : near
436 extrn KernThunkStackTo32 : near
437ENDIF
438
439__OffBeginCS32:
440
441;Called by Watcom to set the DS
442__GETDS proc near
443 push eax
444 mov eax, DOS32FLATDS
445 mov ds, eax
446 pop eax
447 ret
448__GETDS endp
449
450__wcpp_2_pure_error__:
451__wcpp_2_undef_vfun__:
452__wcpp_2_undefed_cdtor__:
453__wcpp_2_dtor_array_store__:
454DevHelpDebug proc near
455 int 3
456 int 3
457 ret
458DevHelpDebug endp
459
460 ALIGN 4
461
462DevHlp proc near
463IFDEF KEE
464 push eax
465 call KernThunkStackTo16
466 pop eax ;trashed by KernThunkStackTo16
467ENDIF
468
469 jmp far ptr CODE16:thunk3216_devhelp
470 ALIGN 4
471thunk1632_devhelp:
472IFDEF KEE
473 push eax
474 push edx
475 call KernThunkStackTo32
476 pop edx ;trashed by KernThunkStackTo32
477 pop eax ;trashed by KernThunkStackTo32
478ENDIF
479 ret
480DevHlp endp
481
482 ALIGN 4
483DevHlp_ModifiedDS proc near
484IFDEF KEE
485 push eax
486 call KernThunkStackTo16
487 pop eax ;trashed by KernThunkStackTo16
488ENDIF
489 jmp far ptr CODE16:thunk3216_devhelp_modified_ds
490 ALIGN 4
491thunk1632_devhelp_modified_ds:
492IFDEF KEE
493 push eax
494 push edx
495 call KernThunkStackTo32
496 pop edx ;trashed by KernThunkStackTo32
497 pop eax ;trashed by KernThunkStackTo32
498ENDIF
499 ret
500DevHlp_ModifiedDS endp
501
502STRATEGY_ proc far
503 push ds
504 push es
505 push fs
506 push gs
507
508 mov eax, DOS32FLATDS
509 mov ds, eax
510 mov es, eax
511IFDEF KEE
512 push stacksel
513 push stackbase
514
515 push edx
516 mov edx, ss
517 mov stacksel, edx
518
519 call KernThunkStackTo32
520 mov stackbase, edx
521 pop edx ;trashed by KernThunkStackTo32
522 call SBLIVE_STRATEGY
523 push eax
524 call KernThunkStackTo16
525 pop eax ;trashed by KernThunkStackTo16
526
527 pop stackbase
528 pop stacksel
529ELSE
530 call SBLIVE_STRATEGY
531ENDIF
532
533 pop gs
534 pop fs
535 pop es
536 pop ds
537 retf
538STRATEGY_ endp
539
540;in: ecx = cmd
541; edx = ULONG parameter
542;return value in eax
543IDC_ proc far
544 push ds
545 push es
546 push fs
547 push gs
548 push ebx
549
550 mov eax, DOS32FLATDS
551 mov ds, eax
552 mov es, eax
553
554IFDEF KEE
555 push stacksel
556 push stackbase
557
558 push edx
559 mov edx, ss
560 mov stacksel, edx
561
562 call KernThunkStackTo32
563 mov stackbase, edx
564 pop edx ;trashed by KernThunkStackTo32
565
566 call SBLIVE_IDC
567
568 push eax
569 call KernThunkStackTo16
570 pop eax ;trashed by KernThunkStackTo16
571
572 pop stackbase
573 pop stacksel
574ELSE
575 call SBLIVE_IDC
576ENDIF
577 pop ebx
578 pop gs
579 pop fs
580 pop es
581 pop ds
582 retf
583IDC_ endp
584
585CODE32 ends
586
587DATA32 segment
588 public __OffsetFinalCS16
589 public __OffsetFinalDS16
590 public __wcpp_2_pure_error__
591 public __wcpp_2_undef_vfun__
592 public __wcpp_2_undefed_cdtor__
593 public __wcpp_2_dtor_array_store__
594 public PDDName
595 public _MSG_TABLE32
596 public __OffBeginDS32
597 public stackbase
598 public stacksel
599
600 __OffBeginDS32 dd 0
601
602 stacksel dd 0
603 stackbase dd 0
604
605 __OffsetFinalCS16 dw (OFFSET CODE16:__OffFinalCS16 - BEGINCS16)
606 __OffsetFinalDS16 dw (OFFSET DATA16:__OffFinalDS16 - BEGINDS16)
607
608 _MSG_TABLE32 dw (OFFSET DATA16:_MSG_TABLE16 - BEGINDS16)
609 dw SEG DATA16:_MSG_TABLE16
610
611;16:16 address of driver name
612 PDDName dw (OFFSET DATA16:pddname16 - BEGINDS16)
613 dw SEG DATA16:pddname16
614
615DATA32 ends
616
617end
618
Note: See TracBrowser for help on using the repository browser.