home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / lxapi32.zip / SKELETON / Dev32 / startup.asm < prev    next >
Assembly Source File  |  2002-04-26  |  11KB  |  479 lines

  1. ; $Id: startup.asm,v 1.2 2002/04/26 23:09:39 smilcke Exp $
  2.  
  3. ;
  4. ; statup.asm
  5. ; Autor:               Stefan Milcke
  6. ; Erstellt am:         08.12.2001
  7. ; Letzte Aenderung am: 28.03.2002
  8. ;
  9.        .386p
  10.  
  11.  
  12.        INCL_DOS        equ 1
  13.        INCL_DOSERRORS  equ 1
  14.        include os2.inc
  15.        include seg32.inc
  16.     include r0thunk.inc
  17.        include rp.inc
  18.        include devhlp.inc
  19.  
  20. ;        EXTERNDEF DOS32FLATDS:ABS
  21.  
  22. MAX_MESSAGESIZE        EQU     2048
  23.  
  24. ; Status word masks
  25. STERR    EQU    8000H        ; Bit 15 - Error
  26. STINTER EQU    0400H        ; Bit 10 - Interim character
  27. STBUI    EQU    0200H        ; Bit  9 - Busy
  28. STDON    EQU    0100H        ; Bit  8 - Done
  29. STECODE EQU    00FFH        ; Error code
  30.  
  31. DATA16 segment
  32.                extrn  DOS32FLATDS : abs                ; ring 0 FLAT kernel data selector
  33.                extrn  __OffFinalDS16 : byte
  34.         public _MSG_TABLE16
  35.         public DevHelpInit
  36.                public DeviceHelp
  37.         public fOpen    
  38.         public InitPktSeg
  39.         public InitPktOff
  40.         public _MESSAGE_STR
  41.         public FileName
  42.  
  43. DeviceHelp     label byte
  44. DevHelpInit    dd 0
  45. fOpen        dd 0
  46. InitPktSeg    dw 0
  47. InitPktOff    dw 0
  48.  
  49. ;needed for rmcalls.lib
  50. _RM_Help0      dd 0
  51. _RM_Help1      dd 0
  52. _RM_Help3      dd 0
  53. _RMFlags       dd 0
  54. _MESSAGE_STR   db MAX_MESSAGESIZE dup (0)
  55. _MSG_TABLE16   dw 0    ;message length
  56.                dw (OFFSET _MESSAGE_STR)
  57.         dw SEG    _MESSAGE_STR
  58. FileName     db "SK32HLP$", 0
  59. DATA16 ends
  60.  
  61. CODE16 segment
  62.        assume cs:CODE16, ds:DATA16
  63.        public help_stub_strategy
  64.        public device_stub_strategy
  65.        public device_stub_idc
  66.        public thunk3216_devhelp
  67.        public thunk3216_devhelp_modified_ds
  68.        extrn DOSOPEN       : far
  69.        extrn DOSWRITE      : far
  70.        extrn DOSCLOSE      : far
  71.        extrn DOSCREATETHREAD : far
  72.        extrn __OffFinalCS16 : byte
  73.  
  74. ;DEZE MOET ALS EERSTE blijven staan!!!!
  75. help_stub_strategy proc far
  76.     pushad
  77.     push    ds
  78.     push    es
  79.     push    fs
  80.     push    gs
  81.  
  82.     mov    ax, DATA16
  83.     mov    ds, ax
  84.  
  85.        movzx     eax, byte ptr es:[bx].reqCommand
  86.     cmp    eax, 0                ; Init
  87.     je    short @@help_init
  88.        cmp     eax, 0Dh            ; DosOpen
  89.        jne     short @@help_error
  90. ;DosOpen
  91.        cmp     word ptr ds:(offset fOpen),0
  92.     je    short @@help_ret_ok        ; not ours
  93.     push    ebx                ; later weer nodig
  94.     push    es
  95.        mov     word ptr ds:(offset fOpen),0
  96.        mov     ax, word ptr ds:(offset InitPktSeg)
  97.     mov    fs, ax                ; fs:ebx = req. packet
  98.     xor    ebx, ebx
  99.        mov     bx, word ptr ds:(offset InitPktOff)
  100.     call    far ptr FLAT:STRATEGY_
  101.     pop    es
  102.     pop    ebx                ; oude bx ptr
  103. @@help_ret:
  104.        mov     word ptr es:[bx].reqStatus, ax
  105. @@help_ret_error:
  106.     pop    gs
  107.     pop    fs
  108.     pop    es
  109.     pop    ds
  110.     popad
  111.     ret
  112.         
  113. @@help_init:
  114.     mov    eax, dword ptr es:[bx].i_devHelp
  115.        mov     dword ptr ds:offset DevHelpInit, eax
  116.        mov     word ptr es:[bx].o_codeend,(offset __OffFinalCS16)
  117.        mov     word ptr es:[bx].o_dataend,(offset __OffFinalDS16)
  118. @@help_ret_ok:
  119.     mov    ax, STDON
  120.     jmp    short @@help_ret
  121.  
  122. @@help_error:
  123.     mov    ax, STDON + STERR + ERROR_I24_BAD_COMMAND
  124.        mov     word ptr es:[bx].reqStatus, ax
  125.     jmp    short @@help_ret_error
  126. help_stub_strategy endp
  127.  
  128. device_stub_strategy proc far
  129.     pushad
  130.     push    ds
  131.     push    es
  132.     push    fs
  133.     push    gs
  134.  
  135.     mov    ax, DATA16
  136.     mov    ds, ax
  137.  
  138.        movzx     eax, byte ptr es:[bx].reqCommand
  139.        cmp     eax, 0
  140.        jz     short @@init
  141.  
  142.     push    ebx
  143.     push    es
  144.     mov    ax, bx
  145.     xor    ebx, ebx            
  146.     mov    bx, ax
  147.     mov    ax, es
  148.     mov    fs, ax                ; fs:ebx = req. packet
  149.        call     far ptr FLAT:STRATEGY_          ; 32 bits strategy entry point
  150.  
  151.     pop    es
  152.     pop    ebx                ; oude bx ptr
  153.        mov     word ptr es:[bx].reqStatus, ax  ; status code
  154.  
  155. @@device_ret:
  156.  
  157.     pop    gs
  158.     pop    fs
  159.     pop    es
  160.     pop    ds
  161.     popad
  162.        ret
  163.  
  164. @@init:
  165.         ;
  166.         ; DEVICE= initialization
  167.         ;
  168.        mov     word ptr ds:(InitPktSeg), es
  169.        mov     word ptr ds:(InitPktOff), bx
  170.        inc     word ptr ds:(fOpen)
  171.  
  172.     call     device_init
  173.  
  174.        mov     word ptr es:[bx].reqStatus, ax  ; status code (ret by device_init)
  175.        mov     word ptr es:[bx].o_codeend,(offset __OffFinalCS16)
  176.        mov     word ptr es:[bx].o_dataend,(offset __OffFinalDS16)
  177.     jmp     short @@device_ret
  178.  
  179. init_err:
  180.     mov     dword ptr es:[bx].i_devHelp, 0
  181.     jmp     short @@device_ret
  182.  
  183. device_stub_strategy endp
  184.  
  185. ;in: cx = cmd
  186. ;    bx = lower 16 bits of ULONG parameter
  187. ;    dx = upper 16 bits of ULONG parameter
  188. ;return value in dx:ax
  189. device_stub_idc proc far
  190.        enter   0,0
  191.        and     sp, 0fffch
  192.        shl     edx,16
  193.        mov     dx,bx
  194.        call    far ptr FLAT:IDC_
  195.        mov     dx,ax
  196.        shr     eax,16
  197.        xchg    ax,dx
  198.        leave
  199.        retf
  200. device_stub_idc endp
  201.  
  202. thread_fn proc far
  203.        push    ds
  204.        pop     ds
  205.        retf
  206. thread_fn endp
  207.  
  208. device_init proc near
  209.     enter     24, 0
  210.     push     ds
  211.     push     es
  212.     push     bx
  213.     push     si
  214.     push     di
  215.  
  216.        ; bp      ->  old bp
  217.        ; bp - 2  -> FileHandle
  218.        ; bp - 4  -> ActionTaken
  219.        ; bp - 8  -> IOCTL parm (4 bytes)  : union mwdd32_ioctl_init_device_parm
  220.        ; bp - 24 -> IOCTL data (16 bytes) : union mwdd32_ioctl_init_device_data
  221.  
  222.        ;
  223.        ; Opens wathlp$
  224.        ;
  225.        push     seg DATA16                 ; seg  FileName
  226.        push    (offset FileName)
  227.        push     ss                         ; seg &FileHandle
  228.        lea     ax, [bp - 2]
  229.        push     ax                         ; ofs &FileHandle
  230.        push     ss                         ; seg &ActionTaken
  231.        lea     ax, [bp - 4]
  232.        push     ax                         ; ofs &ActionTaken
  233.        push     dword ptr 0                ; file size
  234.        push     0                          ; file attributes
  235.        push     OPEN_ACTION_FAIL_IF_NEW + OPEN_ACTION_OPEN_IF_EXISTS
  236.        push     OPEN_SHARE_DENYNONE + OPEN_ACCESS_READONLY
  237.        push     dword ptr 0                ; reserved
  238.        call     DOSOPEN
  239.        cmp     ax, NO_ERROR
  240.        jnz     short @@error
  241.  
  242.  
  243.        ;
  244.        ; Closes wathlp$
  245.        ;
  246.        push     word ptr [bp - 2]                   ; FileHandle
  247.        call     DOSCLOSE
  248.        cmp     ax, NO_ERROR
  249.        jnz     short @@error
  250.  
  251. @@out:
  252.        push    eax
  253.  
  254.        push    0001H
  255.        push    DATA16
  256.        push    (offset _MESSAGE_STR)
  257.        push    word ptr ds:(offset _MSG_TABLE16)
  258.        push    ss
  259.        lea     dx,[bp - 2]
  260.        push    dx
  261.        call    far ptr DOSWRITE
  262.  
  263.        pop     eax
  264.  
  265.     pop     di
  266.     pop     si
  267.     pop     bx
  268.     pop     es
  269.     pop     ds
  270.     leave
  271.     ret
  272. @@error:
  273.     mov     ax, STDON + STERR + ERROR_I24_GEN_FAILURE
  274.     jmp     short @@out
  275.  
  276. device_init endp
  277.  
  278.     ALIGN   2
  279. ;use devhlp pointer stored in 16 bits code segment
  280. thunk3216_devhelp:
  281.     push    ds
  282.     push    DATA16
  283.     pop    ds
  284.        call    dword ptr ds:(offset DevHelpInit)
  285.     pop    ds
  286.  
  287.        jmp     far ptr FLAT:thunk1632_devhelp
  288.  
  289.     ALIGN     2
  290. thunk3216_devhelp_modified_ds:
  291.     push    gs
  292.     push    DATA16
  293.     pop    gs
  294.        call    dword ptr gs:(offset DevHelpInit)
  295.     pop    gs
  296.        jmp     far ptr FLAT:thunk1632_devhelp_modified_ds
  297.  
  298.        ALIGN   2
  299. CODE16 ends
  300.  
  301. CODE32 segment
  302. ASSUME CS:FLAT, DS:FLAT, ES:FLAT
  303.  
  304.        public __OffBeginCS32
  305.        public __GETDS
  306.        public thunk1632_devhelp
  307.     public thunk1632_devhelp_modified_ds
  308.        public DevHlp
  309.        public DevHlp_ModifiedDS
  310.        public STRATEGY_
  311.        public IDC_
  312. IFDEF KEE
  313.     extrn  KernThunkStackTo16 : near
  314.     extrn  KernThunkStackTo32 : near
  315. ENDIF
  316.        extrn   STRATEGY_ENTRY : far
  317.        extrn   IDC_ENTRY : far
  318.  
  319. __OffBeginCS32:
  320.  
  321. ;Called by Watcom to set the DS
  322. __GETDS proc near
  323.     push    eax
  324.        mov     eax, DOS32FLATDS
  325.     mov    ds, eax
  326.     pop    eax
  327.     ret
  328. __GETDS endp
  329.  
  330. __wcpp_2_pure_error__:
  331. __wcpp_2_undef_vfun__:
  332. __wcpp_2_undefed_cdtor__:
  333. __wcpp_2_dtor_array_store__:
  334. DevHelpDebug  proc near
  335.        int 3
  336.        int 3
  337.        ret
  338. DevHelpDebug  endp
  339.  
  340.     ALIGN     4
  341.  
  342. DevHlp proc near
  343. IFDEF  KEE
  344.        push    eax
  345.        call    KernThunkStackTo16
  346.        pop     eax
  347. ENDIF
  348.     jmp    far ptr CODE16:thunk3216_devhelp
  349.     ALIGN 4
  350. thunk1632_devhelp:
  351. IFDEF  KEE
  352.        push    eax
  353.        push    edx
  354.        call    KernThunkStackTo32
  355.        pop     edx     ; trashed by KernThunkStackTo32
  356.        pop     eax     ; trashed by KernThunkStackTo32
  357. ENDIF
  358.     ret
  359. DevHlp endp
  360.  
  361.     ALIGN     4
  362. DevHlp_ModifiedDS proc near
  363. IFDEF  KEE
  364.        push    eax
  365.        call    KernThunkStackTo16
  366.        pop     eax
  367. ENDIF
  368.     jmp    far ptr CODE16:thunk3216_devhelp_modified_ds
  369.     ALIGN 4
  370. thunk1632_devhelp_modified_ds:
  371. IFDEF  KEE
  372.        push    eax
  373.        push    edx
  374.        call    KernThunkStackTo32
  375.        pop     edx     ; trashed by KernThunkStackTo32
  376.        pop     eax     ; trashed by KernThunkStackTo32
  377. ENDIF
  378.     ret
  379. DevHlp_ModifiedDS endp
  380.  
  381. STRATEGY_ proc far
  382.        push    ds
  383.        push    es
  384.        push    fs
  385.        push    gs
  386.        mov     eax,DOS32FLATDS
  387.        mov     ds,eax
  388.        mov     es,eax
  389. IFDEF  KEE
  390.        push    stacksel
  391.        push    stackbase
  392.        push    edx
  393.        mov     edx,ss
  394.        mov     stacksel,edx
  395.        call    KernThunkStackTo32
  396.        mov     stackbase,edx
  397.        pop     edx
  398.        call    STRATEGY_ENTRY
  399.        push    eax
  400.        call    KernThunkStackTo16
  401.        pop     eax
  402.        pop     stackbase
  403.        pop     stacksel
  404. ELSE
  405.        call    STRATEGY_ENTRY
  406. ENDIF
  407.        pop     gs
  408.        pop     fs
  409.        pop     es
  410.        pop     ds
  411.        retf
  412. STRATEGY_ endp
  413.  
  414. ;in: ecx = cmd
  415. ;    edx = ULONG parameter
  416. ;return value in eax
  417. IDC_ proc far
  418.        push    ds
  419.        push    es
  420.        push    fs
  421.        push    gs
  422.        push    ebx
  423.        mov     eax,DOS32FLATDS
  424.        mov     ds,eax
  425.        mov     es,eax
  426. IFDEF  KEE
  427.        push    stacksel
  428.        push    stackbase
  429.        push    edx
  430.        mov     edx,ss
  431.        mov     stacksel,edx
  432.        call    KernThunkStackTo32
  433.        mov     stackbase,edx
  434.        pop     edx
  435.        call    IDC_ENTRY
  436.        push    eax
  437.        call    KernThunkStackTo16
  438.        pop     eax
  439.        pop     stackbase
  440.        pop     stacksel
  441. ELSE
  442.        call    IDC_ENTRY
  443. ENDIF
  444.        pop     ebx
  445.        pop     gs
  446.        pop     fs
  447.        pop     es
  448.        pop     ds
  449.        retf
  450. IDC_ endp
  451.  
  452. CODE32 ends
  453.  
  454. DATA32 segment
  455.        public  __OffsetFinalCS16
  456.        public  __OffsetFinalDS16
  457.        public  __wcpp_2_pure_error__
  458.        public  __wcpp_2_undef_vfun__
  459.        public  __wcpp_2_undefed_cdtor__
  460.        public  __wcpp_2_dtor_array_store__
  461.        public  _MSG_TABLE32
  462.        public  __OffBeginDS32
  463.        public stackbase
  464.        public stacksel
  465.  
  466. __OffBeginDS32         dd 0
  467. stacksel               dd 0
  468. stackbase              dd 0
  469.  
  470. __OffsetFinalCS16  dw (OFFSET CODE16:__OffFinalCS16)
  471. __OffsetFinalDS16  dw (OFFSET DATA16:__OffFinalDS16)
  472.  
  473. _MSG_TABLE32       dw (OFFSET  DATA16:_MSG_TABLE16)
  474.                    dw SEG     DATA16:_MSG_TABLE16
  475. DATA32 ends
  476.  
  477. end
  478.  
  479.