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

Last change on this file since 198 was 182, checked in by sandervl, 24 years ago

stack alignment fix

  • 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 182 2001-05-13 19:50:33Z 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 enter 0, 0
316 and sp, 0fffch
317
318 shl edx, 16
319 mov dx, bx
320 call far ptr FLAT:IDC_ ; 32 bits strategy entry point
321
322 mov dx, ax
323 shr eax, 16
324 xchg ax, dx
325
326 leave
327 retf
328sblive_stub_idc endp
329
330device_init proc near
331 enter 24, 0
332 push ds
333 push es
334 push bx
335 push si
336 push di
337
338 ; bp -> old bp
339 ; bp - 2 -> FileHandle
340 ; bp - 4 -> ActionTaken
341 ; bp - 8 -> IOCTL parm (4 bytes) : union mwdd32_ioctl_init_device_parm
342 ; bp - 24 -> IOCTL data (16 bytes) : union mwdd32_ioctl_init_device_data
343
344 ;
345 ; Opens wathlp$
346 ;
347 push seg DATA16 ; seg FileName
348 push (offset FileName - BEGINDS16) ; ofs FileName
349 push ss ; seg &FileHandle
350 lea ax, [bp - 2]
351 push ax ; ofs &FileHandle
352 push ss ; seg &ActionTaken
353 lea ax, [bp - 4]
354 push ax ; ofs &ActionTaken
355 push dword ptr 0 ; file size
356 push 0 ; file attributes
357 push OPEN_ACTION_FAIL_IF_NEW + OPEN_ACTION_OPEN_IF_EXISTS
358 push OPEN_SHARE_DENYNONE + OPEN_ACCESS_READONLY
359 push dword ptr 0 ; reserved
360 call DOSOPEN
361 cmp ax, NO_ERROR
362 jnz short @@error
363
364
365 ;
366 ; Closes wathlp$
367 ;
368 push word ptr [bp - 2] ; FileHandle
369 call DOSCLOSE
370 cmp ax, NO_ERROR
371 jnz short @@error
372
373@@out:
374 push eax ;gemold door doswrite
375
376 push 0001H
377 push DATA16
378 push (offset _MESSAGE_STR - BEGINDS16)
379 push word ptr ds:(offset _MSG_TABLE16 - BEGINDS16)
380 push ss
381 lea dx, [bp - 2]
382 push dx
383 call DOSWRITE
384
385 pop eax
386
387 pop di
388 pop si
389 pop bx
390 pop es
391 pop ds
392 leave
393 ret
394@@error:
395 mov ax, STDON + STERR + ERROR_I24_GEN_FAILURE
396 jmp short @@out
397
398device_init endp
399
400 ALIGN 2
401;use devhlp pointer stored in 16 bits code segment
402thunk3216_devhelp:
403 push ds
404 push DATA16
405 pop ds
406 call dword ptr ds:(offset DevHelpInit - BEGINDS16)
407 pop ds
408
409 jmp far ptr FLAT:thunk1632_devhelp
410
411 ALIGN 2
412thunk3216_devhelp_modified_ds:
413 push gs
414 push DATA16
415 pop gs
416 call dword ptr gs:(offset DevHelpInit - BEGINDS16)
417 pop gs
418 jmp far ptr FLAT:thunk1632_devhelp_modified_ds
419
420;end of 16 bits code segment
421__OffFinalCS16 label byte
422
423CODE16 ends
424
425CODE32 segment
426ASSUME CS:FLAT, DS:FLAT, ES:FLAT
427
428 public __OffBeginCS32
429 public __GETDS
430 public thunk1632_devhelp
431 public thunk1632_devhelp_modified_ds
432 public DevHlp
433 public DevHlp_ModifiedDS
434 public STRATEGY_
435 public IDC_
436 extrn SBLIVE_STRATEGY : near
437 extrn SBLIVE_IDC : near
438IFDEF KEE
439 extrn KernThunkStackTo16 : near
440 extrn KernThunkStackTo32 : near
441ENDIF
442
443__OffBeginCS32:
444
445;Called by Watcom to set the DS
446__GETDS proc near
447 push eax
448 mov eax, DOS32FLATDS
449 mov ds, eax
450 pop eax
451 ret
452__GETDS endp
453
454__wcpp_2_pure_error__:
455__wcpp_2_undef_vfun__:
456__wcpp_2_undefed_cdtor__:
457__wcpp_2_dtor_array_store__:
458DevHelpDebug proc near
459 int 3
460 int 3
461 ret
462DevHelpDebug endp
463
464 ALIGN 4
465
466DevHlp proc near
467IFDEF KEE
468 push eax
469 call KernThunkStackTo16
470 pop eax ;trashed by KernThunkStackTo16
471ENDIF
472
473 jmp far ptr CODE16:thunk3216_devhelp
474 ALIGN 4
475thunk1632_devhelp:
476IFDEF KEE
477 push eax
478 push edx
479 call KernThunkStackTo32
480 pop edx ;trashed by KernThunkStackTo32
481 pop eax ;trashed by KernThunkStackTo32
482ENDIF
483 ret
484DevHlp endp
485
486 ALIGN 4
487DevHlp_ModifiedDS proc near
488IFDEF KEE
489 push eax
490 call KernThunkStackTo16
491 pop eax ;trashed by KernThunkStackTo16
492ENDIF
493 jmp far ptr CODE16:thunk3216_devhelp_modified_ds
494 ALIGN 4
495thunk1632_devhelp_modified_ds:
496IFDEF KEE
497 push eax
498 push edx
499 call KernThunkStackTo32
500 pop edx ;trashed by KernThunkStackTo32
501 pop eax ;trashed by KernThunkStackTo32
502ENDIF
503 ret
504DevHlp_ModifiedDS endp
505
506STRATEGY_ proc far
507 push ds
508 push es
509 push fs
510 push gs
511
512 mov eax, DOS32FLATDS
513 mov ds, eax
514 mov es, eax
515IFDEF KEE
516 push stacksel
517 push stackbase
518
519 push edx
520 mov edx, ss
521 mov stacksel, edx
522
523 call KernThunkStackTo32
524 mov stackbase, edx
525 pop edx ;trashed by KernThunkStackTo32
526 call SBLIVE_STRATEGY
527 push eax
528 call KernThunkStackTo16
529 pop eax ;trashed by KernThunkStackTo16
530
531 pop stackbase
532 pop stacksel
533ELSE
534 call SBLIVE_STRATEGY
535ENDIF
536
537 pop gs
538 pop fs
539 pop es
540 pop ds
541 retf
542STRATEGY_ endp
543
544;in: ecx = cmd
545; edx = ULONG parameter
546;return value in eax
547IDC_ proc far
548 push ds
549 push es
550 push fs
551 push gs
552 push ebx
553
554 mov eax, DOS32FLATDS
555 mov ds, eax
556 mov es, eax
557
558IFDEF KEE
559 push stacksel
560 push stackbase
561
562 push edx
563 mov edx, ss
564 mov stacksel, edx
565
566 call KernThunkStackTo32
567 mov stackbase, edx
568 pop edx ;trashed by KernThunkStackTo32
569
570 call SBLIVE_IDC
571
572 push eax
573 call KernThunkStackTo16
574 pop eax ;trashed by KernThunkStackTo16
575
576 pop stackbase
577 pop stacksel
578ELSE
579 call SBLIVE_IDC
580ENDIF
581 pop ebx
582 pop gs
583 pop fs
584 pop es
585 pop ds
586 retf
587IDC_ endp
588
589CODE32 ends
590
591DATA32 segment
592 public __OffsetFinalCS16
593 public __OffsetFinalDS16
594 public __wcpp_2_pure_error__
595 public __wcpp_2_undef_vfun__
596 public __wcpp_2_undefed_cdtor__
597 public __wcpp_2_dtor_array_store__
598 public PDDName
599 public _MSG_TABLE32
600 public __OffBeginDS32
601 public stackbase
602 public stacksel
603
604 __OffBeginDS32 dd 0
605
606 stacksel dd 0
607 stackbase dd 0
608
609 __OffsetFinalCS16 dw (OFFSET CODE16:__OffFinalCS16 - BEGINCS16)
610 __OffsetFinalDS16 dw (OFFSET DATA16:__OffFinalDS16 - BEGINDS16)
611
612 _MSG_TABLE32 dw (OFFSET DATA16:_MSG_TABLE16 - BEGINDS16)
613 dw SEG DATA16:_MSG_TABLE16
614
615;16:16 address of driver name
616 PDDName dw (OFFSET DATA16:pddname16 - BEGINDS16)
617 dw SEG DATA16:pddname16
618
619DATA32 ends
620
621end
622
Note: See TracBrowser for help on using the repository browser.