home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / g / gtak212.zip / OS2-DD / lowlevel.asm < prev    next >
Assembly Source File  |  1993-01-16  |  17KB  |  767 lines

  1. ;##############################################################################
  2. ; $Id: lowlevel.asm,v 1.5 1992/07/24 11:36:30 ak Exp $
  3. ;##############################################################################
  4. ; $Log: lowlevel.asm,v $
  5. ; Revision 1.5  1992/07/24  11:36:30  ak
  6. ; OS/2 2.0
  7. ; BASEDEV drivers
  8. ; VGA debugging
  9. ;
  10. ; Revision 1.4  1992/01/06  22:49:28  ak
  11. ; *** empty log message ***
  12. ;
  13. ; Revision 1.3  1992/01/06  22:48:17  ak
  14. ; int_on/off() for != ZTC.
  15. ;
  16. ; Revision 1.2  1992/01/06  20:10:00  ak
  17. ; *** empty log message ***
  18. ;
  19. ; Revision 1.1.1.1  1992/01/06  19:54:55  ak
  20. ; Alpha version.
  21. ;
  22. ; Revision 1.1  1992/01/06  19:54:53  ak
  23. ; Initial revision
  24. ;
  25. ;##############################################################################
  26.  
  27.     .386p
  28.  
  29.     public    __acrtused
  30.     public    _devhlp
  31.     public    _ctors
  32.  
  33.     public    _AllocGDTSelector 
  34.     public    _AllocPhys        
  35.     public    _AllocReqPacket      
  36.     public    _AttachDD
  37.     public    _Block            
  38.     public    _DevDone          
  39.     public    _EOI              
  40.     public    _FreePhys         
  41.     public    _FreeReqPacket    
  42.     public    _GetDOSVar        
  43.     public    _InternalError    
  44.     public    _Lock             
  45.     public    _PhysToGDTSelector
  46.     public    _PhysToUVirt 
  47.     public    _ProtToReal       
  48.     public    _PullParticular   
  49.     public    _PullReqPacket    
  50.     public    _PushReqPacket    
  51.     public    _QueueFlush       
  52.     public    _QueueInit        
  53.     public    _QueueRead        
  54.     public    _QueueWrite       
  55.     public    _RealToProt       
  56.     public    _RegisterStackUsage
  57.     public    _ResetTimer       
  58.     public    _Run              
  59.     public    _SemClear         
  60.     public    _SemHandle        
  61.     public    _SemRequest       
  62.     public    _SendEvent        
  63.     public    _SetIRQ           
  64.     public    _SetROMVector     
  65.     public    _SetTimer         
  66.     public    _SortReqPacket    
  67.     public    _TCYield          
  68.     public    _TickCount        
  69.     public    _Unlock           
  70.     public    _VerifyAccess     
  71.     public    _VirtToPhys       
  72.     public    _Yield
  73.  
  74.     public    _PhysToVirt
  75.     public    _UnPhysToVirt
  76.  
  77.     public    _inProtMode
  78.     public    _inInitPhase
  79.     public    _int_on
  80.     public    _int_off
  81.  
  82.     include    macros.inc
  83.     include    dd-segs.inc
  84.  
  85.     assume    cs:CGROUP, ds:DGROUP, es:nothing, ss:nothing
  86.  
  87. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  88. BegData    _DATA
  89.  
  90. __acrtused    dw    0    ;C .OBJ files want one.  They never
  91.                 ;use it.
  92.  
  93. _devhlp        dd    0    ;devhlp vector
  94.  
  95. EndData    _DATA
  96. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  97. BegCode    _TEXT
  98.  
  99. ;
  100. ; Helper functions
  101. ;
  102.  
  103. DevHlp_SchedClock    =  0    ;  0    Called each timer tick
  104. DevHlp_DevDone        =  1    ;  1    Device I/O complete
  105. DevHlp_Yield        =  2    ;  2    yield CPU if resched set
  106. DevHlp_TCYield        =  3    ;  3    yield to time critical task
  107.  
  108. DevHlp_Block        =  4    ;  4    Block on event
  109. DevHlp_Run        =  5    ;  5    Unblock process
  110.  
  111. DevHlp_SemRequest    =  6    ;  6    claim a semaphore
  112. DevHlp_SemClear     =  7    ;  7    release a semaphore
  113. DevHlp_SemHandle    =  8    ;  8    obtain a semaphore handle
  114.  
  115. DevHlp_PushRequest    =  9    ;  9    Push the request
  116. DevHlp_PullRequest    = 10    ;  A    Pull next request from Q
  117. DevHlp_PullParticular    = 11    ;  B    Pull a specific request
  118. DevHlp_SortRequest    = 12    ;  C    Push request in sorted order
  119.  
  120. DevHlp_AllocReqPacket    = 13    ;  D    allocate request packet
  121. DevHlp_FreeReqPacket    = 14    ;  E    free request packet
  122.  
  123. DevHlp_QueueInit    = 15    ;  F    Init/Clear char queue
  124. DevHlp_QueueFlush    = 16    ; 10    flush queue
  125. DevHlp_QueueWrite    = 17    ; 11    Put a char in the queue
  126. DevHlp_QueueRead    = 18    ; 12    Get a char from the queue
  127.  
  128. DevHlp_Lock        = 19    ; 13    Lock segment
  129. DevHlp_Unlock        = 20    ; 14    Unlock segment
  130.  
  131. DevHlp_PhysToVirt    = 21    ; 15    convert physical address to virtual
  132. DevHlp_VirtToPhys    = 22    ; 16    convert virtual address to physical
  133. DevHlp_PhysToUVirt    = 23    ; 17    convert physical to LDT
  134.  
  135. DevHlp_AllocPhys    = 24    ; 18    allocate physical memory
  136. DevHlp_FreePhys     = 25    ; 19    free physical memory
  137.  
  138. DevHlp_SetROMVector    = 26    ; 1A    set a ROM service routine vector
  139. DevHlp_SetIRQ        = 27    ; 1B    set an IRQ interrupt
  140. DevHlp_UnSetIRQ     = 28    ; 1C    unset an IRQ interrupt
  141.  
  142. DevHlp_SetTimer     = 29    ; 1D    set timer request handler
  143. DevHlp_ResetTimer    = 30    ; 1E    unset timer request handler
  144.  
  145. DevHlp_MonitorCreate    = 31    ; 1F    create a monitor
  146. DevHlp_Register     = 32    ; 20    install a monitor
  147. DevHlp_DeRegister    = 33    ; 21    remove a monitor
  148. DevHlp_MonWrite     = 34    ; 22    pass data records to monitor
  149. DevHlp_MonFlush     = 35    ; 23    remove all data from stream
  150.  
  151. DevHlp_GetDOSVar    = 36    ; 24    Return pointer to DOS variable
  152. DevHlp_SendEvent    = 37    ; 25    an event occurred
  153. DevHlp_ROMCritSection    = 38    ; 26    ROM Critical Section
  154. DevHlp_VerifyAccess    = 39    ; 27    Verify access to memory
  155. DevHlp_RAS        = 40    ; 28    Put info in RAS trace buffer
  156.  
  157. DevHlp_AttachDD        = 42    ; 2A    Attach a device driver
  158.  
  159. DevHlp_InternalError    = 43    ; 2B    Panic
  160.  
  161. DevHlp_AllocGDTSel    = 45    ; 2D    Allocate GDT Selectors
  162. DevHlp_PhysToGDTSel    = 46    ; 2E    Convert phys addr to GDT sel
  163. DevHlp_RealToProt    = 47    ; 2F    Change from real to protected mode
  164. DevHlp_ProtToReal    = 48    ; 30    Change from protected to real mode
  165.  
  166. DevHlp_EOI        = 49    ; 31    Send EOI to PIC
  167. DevHlp_UnPhysToVirt    = 50    ; 32    mark completion of PhysToVirt
  168. DevHlp_TickCount    = 51    ; 33    modify timer
  169.  
  170. DevHlp_GetLIDEntry    = 34h
  171. DevHlp_FreeLIDEntry    = 35h
  172. DevHlp_ABIOSCall    = 36h
  173. DevHlp_ABIOSCommonEntry    = 37h
  174.  
  175. DevHlp_RegisterStackUse = 38h
  176.  
  177. DevHlp_VideoPause    = 3Ch
  178. DevHlp_DispMsg        = 3Dh
  179.  
  180. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  181. ; OS/2 2.0
  182.  
  183. DevHlp_SegRealloc    = 62    ; 3E    Realloc DD protect mode segment
  184. DevHlp_PutWaitingQueue    = 63    ; 3F    Put I/O request on waiting queue
  185. DevHlp_GetWaitingQueue    = 64    ; 40    Get I/O request from waiting queue
  186. ;DevHlp_PhysToSys    = 65    ; 41    Address conversion for the AOX
  187. ;DevHlp_PhysToSysHook    = 66    ; 42    Address conversion for the AOX
  188. DevHlp_RegisterDeviceClass = 67    ; 43    Register DC entry point
  189.  
  190. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  191. ; OS/2 2.0 32-bit
  192.  
  193. DevHlp_RegisterPDD    = 80    ; 50    Register PDD entry point with
  194.                 ;       VDM manager for later PDD-VDD
  195.                 ;    communication
  196. DevHlp_RegisterBeep    = 81    ; 51    register PTD beep service
  197.                 ;    entry point with kernel
  198. DevHlp_Beep        = 82    ; 52    preempt beep service via PTD
  199.  
  200. DevHlp_FreeGDTSelector    = 83    ; 53    Free allocated GDT selector
  201.  
  202. DevHlp_PhysToGDTSel    = 84    ; 54    Convert Phys Addr to GDT sel
  203.                 ;    with given access
  204.                 ;   BUGBUG: TEMPORARY!!!
  205.  
  206. DevHlp_VMLock        = 85    ; 55    Lock linear address range
  207.  
  208. DevHlp_VMUnlock     = 86    ; 56    Unlock address range
  209.  
  210. DevHlp_VMAlloc        = 87    ; 56    Allocate memory
  211.  
  212. DevHlp_VMFree        = 88    ; 58    Free memory or mapping
  213.  
  214. DevHlp_VMProcessToGlobal = 89    ; 59    Create global mapping to process
  215.                 ;    memory
  216.  
  217. DevHlp_VMGlobalToProcess = 90    ; 5A    Create process mapping to global
  218.                 ;    memory
  219.  
  220. DevHlp_VirtToLin    = 91    ; 5B Convert virtual address to linear
  221.  
  222. DevHlp_LinToGDTSelector = 92    ; 5C Convert linear address to virtual
  223.  
  224. DevHlp_GetDescInfo    = 93    ; 5D Return descriptor information
  225.  
  226. DevHlp_LinToPageList    = 94    ; 5E build pagelist array from lin addr
  227.  
  228. DevHlp_PageListToLin    = 95    ; 5F map page list array to lin addr
  229.  
  230. DevHlp_PageListToGDTSelector = 96 ; 60 map page list array to GDT sel.
  231.  
  232. DevHlp_RegisterTmrDD    = 97    ; 61 Register TMR Device Driver.
  233.  
  234. DevHlp_RegisterPerfCtrs = 98    ; 62 Register device driver perf. ctrs (PVW).
  235.  
  236. DevHlp_AllocateCtxHook    = 99    ; 63 Allocate a context hook
  237.  
  238. DevHlp_FreeCtxHook    = 100    ; 64 Free a context hook
  239.  
  240. DevHlp_ArmCtxHook    = 101    ; 65 Arm a context hook
  241.  
  242. DevHlp_VMSetMem     = 102    ; 66H commit/decommit memory
  243.  
  244. DevHlp_OpenEventSem    = 103    ; 67H open an event semaphore
  245.  
  246. DevHlp_CloseEventSem    = 104    ; 68H close an event semaphore
  247.  
  248. DevHlp_PostEventSem    = 105    ; 69H post an event semaphore
  249.  
  250. DevHlp_ResetEventSem    = 106    ; 6AH reset an event semaphore
  251.  
  252. DevHlp_RegisterFreq    = 107    ; 6BH    register PTD freq service
  253.                 ;    entry point with kernel
  254.  
  255. DevHlp_DynamicAPI    = 108    ; 6CH add a dynamic API
  256. ;
  257. ; Request bit definitions used in DevHlp_DynamicAPI
  258. DHDYNAM_16B_CALLGATE    = 1    ; 1 = 16 bit callgate, 0 = 32 bit
  259. DHDYNAM_16B_APIRTN    = 2    ; 1 = 16 bit API rtn,  0 = 32 rtn
  260.  
  261. DevHlp_ProcRun2     = 109    ; 6DH  Unblock process via procrun2
  262. ;
  263. DevHlp_CreateInt13VDM    = 110    ; 6EH Create Int13 VDM (Internal Only) OEMINT13
  264.  
  265.  
  266. p    equ    [bp+4]
  267.  
  268. ; (word *address, word nselectors) -> word 0 if ok, errcode if not
  269. _AllocGDTSelector proc near
  270.     .enter    <es,di>
  271.     les    di, p+0
  272.     mov    cx, p+4
  273.     .devhlp    AllocGDTSel
  274.     .rzero
  275.     .return    <es,di>
  276. _AllocGDTSelector endp
  277.  
  278. ; (dword size) -> physaddr if ok, 0 if not
  279. _AllocPhys proc near
  280.     .enter    <>
  281.     mov    ax, p+2
  282.     mov    bx, p+0
  283.     .devhlp    AllocPhys
  284.     .rnull    ax, bx
  285.     .return    <>
  286. _AllocPhys endp
  287.  
  288. ; (word waitflag) -> farptr if ok, 0 if not
  289. _AllocReqPacket proc near
  290.     .enter    <es>
  291.     mov    dh, p+0
  292.     .devhlp    AllocReqPacket
  293.     .rnull    es, bx
  294.     .return    <es>
  295. _AllocReqPacket endp
  296.  
  297. ; (nearptr name, nearptr area) -> error
  298. _AttachDD proc near
  299.     .enter    <di>
  300.     mov    bx, p+0
  301.     mov    di, p+2
  302.     .devhlp    AttachDD
  303.     .rflag
  304.     .return    <di>
  305. _AttachDD endp
  306.  
  307. ; (dword id, dword time, word interruptible)
  308. ;    -> 0 if normal, -1 if timeout, awake-code > 0 if unusual wakeup
  309. _Block proc near
  310.     .enter    <di>
  311.     mov    bx, p+0
  312.     mov    ax, p+2
  313.     mov    cx, p+4
  314.     mov    di, p+6
  315.     mov    dh, p+8
  316.     .devhlp    Block
  317.     jnc    short bl_evt
  318.     jz    short bl_tim
  319.     mov    ah, 0
  320.     jmp    short bl_ret
  321. bl_tim:    mov    ax, -1
  322.     jmp    short bl_ret
  323. bl_evt:    sub    ax, ax
  324. bl_ret:    .return    <di>
  325. _Block endp
  326.  
  327. ; (farptr reqpkt)
  328. _DevDone proc near
  329.     .enter    <es>
  330.     les    bx, p+0
  331.     .devhlp    DevDone
  332.     .return    <es>
  333. _DevDone endp
  334.  
  335. ; (farptr msgtable)
  336. _DispMsg proc near
  337.     .enter    <es,di>
  338.     les    di, p+0
  339.     sub    bx, bx
  340.     .devhlp    DispMsg
  341.     .return    <es,di>
  342. _DispMsg endp
  343.  
  344. ; (word irqnum)
  345. _EOI proc near
  346.     .enter    <>
  347.     mov    al, p+0
  348.     .devhlp    EOI
  349.     .return    <>
  350. _EOI endp
  351.  
  352. ; (physaddr address) -> error
  353. _FreePhys proc near
  354.     .enter    <>
  355.     mov    bx, p+0
  356.     mov    ax, p+2
  357.     .devhlp    FreePhys
  358.     .rflag
  359.     .return    <>
  360. _FreePhys endp
  361.  
  362. ; (farptr reqpkt)
  363. _FreeReqPacket proc near
  364.     .enter    <es>
  365.     les    bx, p
  366.     .devhlp    FreeReqPacket
  367.     .return    <es>
  368. _FreeReqPacket endp
  369.  
  370. ; (word varnum, word cx) -> farptr or 0
  371. _GetDOSVar proc near
  372.     .enter    <>
  373.     mov    al, p
  374.     mov    cx, p+2
  375.     .devhlp    GetDOSVar
  376.     .rnull    ax, bx
  377.     .return    <>
  378. _GetDOSVar endp
  379.  
  380. ; (farptr msg, word msglen)
  381. _InternalError proc near
  382.     lds    si, p
  383.     mov    di, p+4
  384.     mov    ax, ds
  385.     mov    es, ax
  386.     mov    dl, DevHlp_InternalError
  387.     call    es:_devhlp
  388. _InternalError endp
  389.  
  390. ; (word seg, word flags) -> dword handle or 0
  391. _Lock proc near
  392.     .enter    <>
  393.     mov    ax, p+0
  394.     mov    bx, p+2
  395.     .devhlp    Lock
  396.     .rnull    ax, bx
  397.     .return    <>
  398. _Lock endp
  399.  
  400. ; (physaddr address, word length, word selector) -> 0 or errcode
  401. _PhysToGDTSelector proc near
  402.     .enter    <si>
  403.     mov    bx, p+0
  404.     mov    ax, p+2
  405.     mov    cx, p+4
  406.     mov    si, p+6
  407.     .devhlp    PhysToGDTSel
  408.     .rzero
  409.     .return    <si>
  410. _PhysToGDTSelector endp
  411.  
  412. ; (physaddr address, word length, word type, word tag) -> farptr or 0
  413. _PhysToUVirt proc near
  414.     .enter    <es, si>
  415.     mov    bx, p+0
  416.     mov    ax, p+2
  417.     mov    cx, p+4
  418.     mov    dh, p+6
  419.     mov    si, p+8
  420.     .devhlp    PhysToUVirt
  421.     .rnull    es, bx
  422.     .return    <es, si>
  423. _PhysToUVirt endp
  424.  
  425. ; () -> 0 or errcode
  426. _ProtToReal proc near
  427.     .devhlp    ProtToReal
  428.     .rzero
  429.     ret
  430. _ProtToReal endp
  431.  
  432. ; (nearptr queue, farptr reqpkt) -> error
  433. _PullParticular proc near
  434.     .enter    <es,si>
  435.     mov    si, p+0
  436.     les    bx, p+2
  437.     .devhlp    PullParticular
  438.     .rflag
  439.     .return    <es,si>
  440. _PullParticular endp
  441.  
  442. ; (nearptr queue) -> farptr reqpkt or 0
  443. _PullReqPacket proc near
  444.     .enter    <es,si>
  445.     mov    si, p+0
  446.     .devhlp    PullRequest
  447.     .rnull    es, bx
  448.     .return    <es,si>
  449. _PullReqPacket  endp
  450.  
  451. ; (nearptr queue, farptr reqpkt)
  452. _PushReqPacket proc near
  453.     .enter    <es,si>
  454.     mov    si, p+0
  455.     les    bx, p+2
  456.     .devhlp    PushRequest
  457.     .return    <es,si>
  458. _PushReqPacket  endp
  459.  
  460. ; (nearptr queue)
  461. _QueueFlush proc near
  462.     .enter    <si>
  463.     mov    si, p+0
  464.     .devhlp    QueueFlush
  465.     .return    <si>
  466. _QueueFlush endp
  467.  
  468. ; (nearptr queue)
  469. _QueueInit proc near
  470.     .enter    <si>
  471.     mov    si, p+0
  472.     .devhlp    QueueInit
  473.     .return    <si>
  474. _QueueInit endp
  475.  
  476. ; (nearptr queue) -> word char or -1
  477. _QueueRead proc near
  478.     .enter    <>
  479.     mov    bx, p+0
  480.     .devhlp    QueueRead
  481.     .rminus
  482.     .return    <>
  483. _QueueRead endp
  484.  
  485. ; (nearptr queue, word char) -> error
  486. _QueueWrite proc near
  487.     .enter    <>
  488.     mov    bx, p+0
  489.     mov    al, p+2
  490.     .devhlp    QueueWrite
  491.     .rflag
  492.     .return    <>
  493. _QueueWrite endp
  494.  
  495. ; () -> error
  496. _RealToProt proc near
  497.     .devhlp    RealToProt
  498.     .rflag
  499.     ret
  500. _RealToProt endp
  501.  
  502. ; (nearptr data) -> error
  503. _RegisterStackUsage proc near
  504.     .enter    <>
  505.     mov    bx, p+0
  506.     .devhlp    RegisterStackUse
  507.     .rflag
  508.     .return    <>
  509. _RegisterStackUsage endp
  510.  
  511. ; (farfcn handler) -> error
  512. _ResetTimer proc near
  513.     .enter    <>
  514.     mov    ax, p+0
  515.     .devhlp    ResetTimer
  516.     .rflag
  517.     .return    <>
  518. _ResetTimer endp
  519.  
  520. ; (dword id) -> word count_awakened
  521. _Run proc near
  522.     .enter    <>
  523.     mov    bx, p+0
  524.     mov    ax, p+2
  525.     .devhlp    Run
  526.     .return    <>
  527. _Run endp
  528.  
  529. ; (dword handle) -> 0 or errcode
  530. _SemClear proc near
  531.     .enter    <>
  532.     mov    bx, p+0
  533.     mov    ax, p+2
  534.     .devhlp    SemClear
  535.     .rzero
  536.     .return    <>
  537. _SemClear endp
  538.  
  539. ; (dword semid, word inuse) -> dword handle or 0
  540. _SemHandle proc near
  541.     .enter    <>
  542.     mov    bx, p+0
  543.     mov    ax, p+2
  544.     mov    dh, p+4
  545.     .devhlp    SemHandle
  546.     .rnull    ax, bx
  547.     .return    <>
  548. _SemHandle endp
  549.  
  550. ; (dword handle, dword time) -> 0 or errcode
  551. _SemRequest proc near
  552.     .enter    <di>
  553.     mov    bx, p+0
  554.     mov    ax, p+2
  555.     mov    cx, p+4
  556.     mov    di, p+6
  557.     .devhlp    SemRequest
  558.     .rzero
  559.     .return    <di>
  560. _SemRequest endp
  561.  
  562. ; (word event, word arg) -> error
  563. _SendEvent proc near
  564.     .enter    <>
  565.     mov    al, p+0
  566.     mov    bx, p+2
  567.     .devhlp    SendEvent
  568.     .rflag
  569.     .return    <>
  570. _SendEvent endp
  571.  
  572. ; (farfcn handler, word irqnum, word shared) -> error
  573. _SetIRQ proc near
  574.     .enter    <>
  575.     mov    ax, p+0
  576.     mov    bx, p+4
  577.     mov    dh, p+6
  578.     .devhlp    SetIRQ
  579.     .rflag
  580.     .return    <>
  581. _SetIRQ endp
  582.  
  583. ; (farfcn handler, word intnum, nearCSptr saveDS) -> dword previous
  584. _SetROMVector proc near
  585.     .enter    <si>
  586.     mov    ax, p+0
  587.     mov    bx, p+4
  588.     mov    si, p+6
  589.     .devhlp    SetROMVector
  590.     .rnull    ax, dx
  591.     .return    <si>
  592. _SetROMVector endp
  593.  
  594. ; (farfcn handler) -> error
  595. _SetTimer proc near
  596.     .enter    <>
  597.     mov    ax, p+0
  598.     .devhlp    SetTimer
  599.     .rflag
  600.     .return    <>
  601. _SetTimer endp
  602.  
  603. ; (nearptr queue, farptr reqpkt)
  604. _SortReqPacket proc near
  605.     .enter    <es,si>
  606.     mov    si, p+0
  607.     les    bx, p+2
  608.     .devhlp    SortRequest
  609.     .return    <es,si>
  610. _SortReqPacket endp
  611.  
  612. ; ()
  613. _TCYield proc near
  614.     .devhlp    TCYield
  615.     ret
  616. _TCYield endp
  617.  
  618. ; (farfcn handler, word tick_count) -> error
  619. _TickCount proc near
  620.     .enter    <>
  621.     mov    ax, p+0
  622.     mov    bx, p+4
  623.     .devhlp    TickCount
  624.     .rflag
  625.     .return    <>
  626. _TickCount endp
  627.  
  628. ; (dword handle) -> error
  629. _Unlock proc near
  630.     .enter    <>
  631.     mov    bx, p+0
  632.     mov    ax, p+2
  633.     .devhlp    Unlock
  634.     .rflag
  635.     .return    <>
  636. _Unlock endp
  637.  
  638. ; (farptr address, word length, word type) -> error
  639. _VerifyAccess proc near
  640.     .enter    <di>
  641.     mov    ax, p+2
  642.     mov    cx, p+4
  643.     mov    di, p+0
  644.     mov    dh, p+6
  645.     .devhlp    VerifyAccess
  646.     .rflag
  647.     .return    <di>
  648. _VerifyAccess endp
  649.  
  650. ; (farptr address) -> physaddr
  651. _VirtToPhys proc near
  652.     .enter    <es,ds,si>
  653.     mov    ax, ds
  654.     mov    es, ax
  655.     lds    si, p+0
  656.     mov    dl, DevHlp_VirtToPhys
  657.     call    es:_devhlp
  658.     .rnull    ax, bx
  659.     .return    <es,ds,si>
  660. _VirtToPhys endp
  661.  
  662. ; ()
  663. _Yield proc near
  664.     .devhlp    Yield
  665.     ret
  666. _Yield endp
  667.  
  668.  
  669. ; (farptr paddr, word len) -> farptr
  670. _PhysToVirt proc near
  671.     .enter    <es,di>
  672.     mov    ax, p+2
  673.     mov    bx, p+0
  674.     mov    cx, p+4
  675.     mov    dh, 1
  676.     .devhlp    PhysToVirt
  677.     .rnull    es, di
  678.     .return    <es,di>
  679. _PhysToVirt endp
  680.  
  681. ; ()
  682. _UnPhysToVirt proc near
  683.     mov    dh, 1
  684.     .devhlp    UnPhysToVirt
  685.     ret
  686. _UnPhysToVirt endp
  687.  
  688. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  689.  
  690. _inProtMode proc near
  691.     smsw    ax
  692.     and    ax, 1
  693.     ret
  694. _inProtMode endp
  695.  
  696. _inInitPhase proc near
  697.     smsw    ax
  698.     and    ax, 1
  699.     jz    short in1
  700.     mov    ax, cs
  701.     and    ax, 3
  702. in1:    ret
  703. _inInitPhase endp
  704.  
  705. _int_on proc near
  706.     sti
  707. _int_on endp
  708.  
  709. _int_off proc near
  710.     sti
  711. _int_off endp
  712.  
  713. EndCode    _TEXT
  714. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  715. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  716. BegCode    ITEXT
  717.  
  718. ; Clear BSS & c_common segments
  719. ; Perform static constructors
  720. ; Go backwards through the list so we do what was linked in last, first.
  721. ; Return length of data segment
  722.  
  723. _ctors    proc near
  724.     push    di
  725.     ;Clear BSS segment
  726.     mov    di, offset DGROUP:UDATA    ;start of _BSS
  727.     mov    ax, ds            ;end of _BSS = end of data segment
  728.     lsl    cx, ax
  729.     inc    cx
  730.     push    cx
  731.     sub    cx, di
  732.     jcxz    short ct0
  733.     mov    ax, ds
  734.     mov    es, ax
  735.     sub    al, al
  736.     cld
  737.     rep    stosb
  738.  
  739.     ;Call far ctors
  740. ct0:    mov    di, offset DGROUP:XIFE
  741. ctfar:    cmp    di, offset DGROUP:XIFB
  742.     jbe    short ct2
  743.     sub    di, 4
  744.     cmp    dword ptr [di], 0
  745.     jz    short ctfar
  746.     call    dword ptr [di]
  747.     jmp    short ctfar
  748.  
  749.     ;Call near ctors
  750. ct2:    mov    di, offset DGROUP:XIE
  751. ctnear:    cmp    di, offset DGROUP:XIB
  752.     jbe    short ct3
  753.     sub    di, 2
  754.     mov    cx, [di]
  755.     jcxz    short ctnear
  756.     call    cx
  757.     jmp    short ctnear
  758.  
  759. ct3:    pop    ax        ;length of data segment
  760.     pop    di
  761.     ret
  762. _ctors    endp
  763.  
  764. EndCode    ITEXT
  765.  
  766.     end
  767.