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

Last change on this file since 144 was 142, checked in by ktk, 25 years ago

Import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 15.8 KB
Line 
1; $Id: startup.asm 142 2000-04-23 14:55:46Z ktk $
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 public iodelay_
193 extrn DOSOPEN : far
194 extrn DOSWRITE : far
195 extrn DOSCLOSE : far
196 EXTRN DOSIODELAYCNT : ABS
197
198;DEZE MOET ALS EERSTE blijven staan!!!!
199help_stub_strategy proc far
200 pushad
201 push ds
202 push es
203 push fs
204 push gs
205
206 mov ax, DATA16
207 mov ds, ax
208
209 movzx eax, byte ptr es:[bx].reqCommand
210 cmp eax, 0 ; Init
211 je short @@help_init
212 cmp eax, 0Dh ; DosOpen
213 jne short @@help_error
214;DosOpen
215 cmp word ptr ds:(offset fOpen - BEGINDS16), 0
216 je short @@help_ret_ok ; not ours
217 push ebx ; later weer nodig
218 push es
219 mov word ptr ds:(offset fOpen - BEGINDS16), 0
220 mov ax, word ptr ds:(offset InitPktSeg-BEGINDS16)
221 mov fs, ax ; fs:ebx = req. packet
222 xor ebx, ebx
223 mov bx, word ptr ds:(offset InitPktOff - BEGINDS16)
224 call far ptr FLAT:STRATEGY_
225 pop es
226 pop ebx ; oude bx ptr
227@@help_ret:
228 mov word ptr es:[bx].reqStatus, ax
229@@help_ret_error:
230 pop gs
231 pop fs
232 pop es
233 pop ds
234 popad
235 ret
236
237@@help_init:
238 mov eax, dword ptr es:[bx].i_devHelp
239 mov dword ptr ds:(offset DevHelpInit - BEGINDS16), eax
240 mov word ptr es:[bx].o_codeend, (offset __OffFinalCS16 - BEGINCS16)
241 mov word ptr es:[bx].o_dataend, (offset __OffFinalDS16 - BEGINDS16)
242
243@@help_ret_ok:
244 mov ax, STDON
245 jmp short @@help_ret
246
247@@help_error:
248 mov ax, STDON + STERR + ERROR_I24_BAD_COMMAND
249 mov word ptr es:[bx].reqStatus, ax
250 jmp short @@help_ret_error
251
252help_stub_strategy endp
253
254
255sblive_stub_strategy proc far
256 pushad
257 push ds
258 push es
259 push fs
260 push gs
261
262 mov ax, DATA16
263 mov ds, ax
264
265 movzx eax, byte ptr es:[bx].reqCommand
266 cmp eax, 0
267 jz short @@init
268
269 push ebx
270 push es
271 mov ax, bx
272 xor ebx, ebx
273 mov bx, ax
274 mov ax, es
275 mov fs, ax ; fs:ebx = req. packet
276
277 call far ptr FLAT:STRATEGY_ ; 32 bits strategy entry point
278
279 pop es
280 pop ebx ; oude bx ptr
281 mov word ptr es:[bx].reqStatus, ax ; status code
282
283@@sblive_ret:
284
285 pop gs
286 pop fs
287 pop es
288 pop ds
289 popad
290 ret
291
292@@init:
293 ;
294 ; DEVICE= initialization
295 ;
296 mov word ptr ds:(InitPktSeg - BEGINDS16), es
297 mov word ptr ds:(InitPktOff - BEGINDS16), bx
298 inc word ptr ds:(fOpen - BEGINDS16)
299 call device_init
300
301 mov word ptr es:[bx].reqStatus, ax ; status code (ret by device_init)
302 mov word ptr es:[bx].o_codeend, (offset __OffFinalCS16 - BEGINCS16)
303 mov word ptr es:[bx].o_dataend, (offset __OffFinalDS16 - BEGINDS16)
304 jmp short @@sblive_ret
305
306init_err:
307 mov dword ptr es:[bx].i_devHelp, 0
308 jmp short @@sblive_ret
309
310sblive_stub_strategy endp
311
312;in: cx = cmd
313; bx = lower 16 bits of ULONG parameter
314; dx = upper 16 bits of ULONG parameter
315;return value in dx:ax
316sblive_stub_idc proc far
317 shl edx, 16
318 mov dx, bx
319 call far ptr FLAT:IDC_ ; 32 bits strategy entry point
320
321 mov dx, ax
322 shr eax, 16
323 xchg ax, dx
324
325 retf
326sblive_stub_idc endp
327
328device_init proc near
329 enter 24, 0
330 push ds
331 push es
332 push bx
333 push si
334 push di
335
336 ; bp -> old bp
337 ; bp - 2 -> FileHandle
338 ; bp - 4 -> ActionTaken
339 ; bp - 8 -> IOCTL parm (4 bytes) : union mwdd32_ioctl_init_device_parm
340 ; bp - 24 -> IOCTL data (16 bytes) : union mwdd32_ioctl_init_device_data
341
342 ;
343 ; Opens wathlp$
344 ;
345 push seg DATA16 ; seg FileName
346 push (offset FileName - BEGINDS16) ; ofs FileName
347 push ss ; seg &FileHandle
348 lea ax, [bp - 2]
349 push ax ; ofs &FileHandle
350 push ss ; seg &ActionTaken
351 lea ax, [bp - 4]
352 push ax ; ofs &ActionTaken
353 push dword ptr 0 ; file size
354 push 0 ; file attributes
355 push OPEN_ACTION_FAIL_IF_NEW + OPEN_ACTION_OPEN_IF_EXISTS
356 push OPEN_SHARE_DENYNONE + OPEN_ACCESS_READONLY
357 push dword ptr 0 ; reserved
358 call DOSOPEN
359 cmp ax, NO_ERROR
360 jnz short @@error
361
362
363 ;
364 ; Closes wathlp$
365 ;
366 push word ptr [bp - 2] ; FileHandle
367 call DOSCLOSE
368 cmp ax, NO_ERROR
369 jnz short @@error
370
371@@out:
372 push eax ;gemold door doswrite
373
374 push 0001H
375 push DATA16
376 push (offset _MESSAGE_STR - BEGINDS16)
377 push word ptr ds:(offset _MSG_TABLE16 - BEGINDS16)
378 push ss
379 lea dx, [bp - 2]
380 push dx
381 call far ptr DOSWRITE
382
383 pop eax
384
385 pop di
386 pop si
387 pop bx
388 pop es
389 pop ds
390 leave
391 ret
392@@error:
393 mov ax, STDON + STERR + ERROR_I24_GEN_FAILURE
394 jmp short @@out
395
396device_init endp
397
398 ALIGN 2
399;use devhlp pointer stored in 16 bits code segment
400thunk3216_devhelp:
401 push ds
402 push DATA16
403 pop ds
404 call dword ptr ds:(offset DevHelpInit - BEGINDS16)
405 pop ds
406
407 jmp far ptr FLAT:thunk1632_devhelp
408
409 ALIGN 2
410thunk3216_devhelp_modified_ds:
411 push gs
412 push DATA16
413 pop gs
414 call dword ptr gs:(offset DevHelpInit - BEGINDS16)
415 pop gs
416 jmp far ptr FLAT:thunk1632_devhelp_modified_ds
417
418iodelay_:
419 db 0B8h
420 dw DOSIODELAYCNT
421 align 4
422@@: dec eax
423 jnz @b
424 loop iodelay_
425 jmp far ptr FLAT:thunk1632_iodelay32_
426
427;end of 16 bits code segment
428__OffFinalCS16 label byte
429
430CODE16 ends
431
432CODE32 segment
433ASSUME CS:FLAT, DS:FLAT, ES:FLAT
434
435 public __OffBeginCS32
436 public __GETDS
437 public thunk1632_devhelp
438 public thunk1632_devhelp_modified_ds
439 public DevHlp
440 public DevHlp_ModifiedDS
441 public STRATEGY_
442 public IDC_
443 public iodelay32_
444 public thunk1632_iodelay32_
445 extrn SBLIVE_STRATEGY : near
446 extrn SBLIVE_IDC : near
447 extrn KernThunkStackTo16 : near
448 extrn KernThunkStackTo32 : near
449
450__OffBeginCS32:
451
452;Called by Watcom to set the DS
453__GETDS proc near
454 push eax
455 mov eax, DOS32FLATDS
456 mov ds, eax
457 pop eax
458 ret
459__GETDS endp
460
461__wcpp_2_pure_error__:
462__wcpp_2_undef_vfun__:
463__wcpp_2_undefed_cdtor__:
464__wcpp_2_dtor_array_store__:
465DevHelpDebug proc near
466 int 3
467 int 3
468 ret
469DevHelpDebug endp
470
471 ALIGN 4
472
473DevHlp proc near
474IFDEF KEE
475 push eax
476 call KernThunkStackTo16
477 pop eax ;trashed by KernThunkStackTo16
478ENDIF
479
480 jmp far ptr CODE16:thunk3216_devhelp
481 ALIGN 4
482thunk1632_devhelp:
483IFDEF KEE
484 push eax
485 push edx
486 call KernThunkStackTo32
487 pop edx ;trashed by KernThunkStackTo32
488 pop eax ;trashed by KernThunkStackTo32
489ENDIF
490 ret
491DevHlp endp
492
493 ALIGN 4
494DevHlp_ModifiedDS proc near
495IFDEF KEE
496 push eax
497 call KernThunkStackTo16
498 pop eax ;trashed by KernThunkStackTo16
499ENDIF
500 jmp far ptr CODE16:thunk3216_devhelp_modified_ds
501 ALIGN 4
502thunk1632_devhelp_modified_ds:
503IFDEF KEE
504 push eax
505 push edx
506 call KernThunkStackTo32
507 pop edx ;trashed by KernThunkStackTo32
508 pop eax ;trashed by KernThunkStackTo32
509ENDIF
510 ret
511DevHlp_ModifiedDS endp
512
513iodelay32_ proc near
514 jmp far ptr CODE16:iodelay_
515 ALIGN 4
516thunk1632_iodelay32_:
517 ret
518iodelay32_ endp
519
520STRATEGY_ proc far
521 push ds
522 push es
523 push fs
524 push gs
525
526 mov eax, DOS32FLATDS
527 mov ds, eax
528 mov es, eax
529IFDEF KEE
530 push stacksel
531 push stackbase
532
533 push edx
534 mov edx, ss
535 mov stacksel, edx
536
537 call KernThunkStackTo32
538 mov stackbase, edx
539 pop edx ;trashed by KernThunkStackTo32
540 call SBLIVE_STRATEGY
541 push eax
542 call KernThunkStackTo16
543 pop eax ;trashed by KernThunkStackTo16
544
545 pop stackbase
546 pop stacksel
547ELSE
548 call SBLIVE_STRATEGY
549ENDIF
550
551 pop gs
552 pop fs
553 pop es
554 pop ds
555 retf
556STRATEGY_ endp
557
558;in: ecx = cmd
559; edx = ULONG parameter
560;return value in eax
561IDC_ proc far
562 push ds
563 push es
564 push fs
565 push gs
566 push ebx
567
568 mov eax, DOS32FLATDS
569 mov ds, eax
570 mov es, eax
571
572IFDEF KEE
573 push stacksel
574 push stackbase
575
576 push edx
577 mov edx, ss
578 mov stacksel, edx
579
580 call KernThunkStackTo32
581 mov stackbase, edx
582 pop edx ;trashed by KernThunkStackTo32
583
584 call SBLIVE_IDC
585
586 push eax
587 call KernThunkStackTo16
588 pop eax ;trashed by KernThunkStackTo16
589
590 pop stackbase
591 pop stacksel
592ELSE
593 call SBLIVE_IDC
594ENDIF
595 pop ebx
596 pop gs
597 pop fs
598 pop es
599 pop ds
600 retf
601IDC_ endp
602
603CODE32 ends
604
605DATA32 segment
606 public __OffsetFinalCS16
607 public __OffsetFinalDS16
608 public __wcpp_2_pure_error__
609 public __wcpp_2_undef_vfun__
610 public __wcpp_2_undefed_cdtor__
611 public __wcpp_2_dtor_array_store__
612 public PDDName
613 public _MSG_TABLE32
614 public __OffBeginDS32
615 public stackbase
616 public stacksel
617
618 __OffBeginDS32 dd 0
619
620 stacksel dd 0
621 stackbase dd 0
622
623 __OffsetFinalCS16 dw (OFFSET CODE16:__OffFinalCS16 - BEGINCS16)
624 __OffsetFinalDS16 dw (OFFSET DATA16:__OffFinalDS16 - BEGINDS16)
625
626 _MSG_TABLE32 dw (OFFSET DATA16:_MSG_TABLE16 - BEGINDS16)
627 dw SEG DATA16:_MSG_TABLE16
628
629;16:16 address of driver name
630 PDDName dw (OFFSET DATA16:pddname16 - BEGINDS16)
631 dw SEG DATA16:pddname16
632
633DATA32 ends
634
635end
636
Note: See TracBrowser for help on using the repository browser.