home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR41 / CTASK22D.ZIP / TSK.MAC < prev    next >
Text File  |  1993-06-08  |  18KB  |  1,053 lines

  1. ;
  2. ;    --- Version 2.2 93-06-08 10:16 ---
  3. ;
  4. ;    CTask - Definitions for assembler routines
  5. ;
  6. ;    Public Domain Software written by
  7. ;        Thomas Wagner
  8. ;        Ferrari electronic Gmbh
  9. ;        Beusselstrasse 27
  10. ;        D-1000 Berlin 21
  11. ;        Germany
  12. ;
  13. ;    The configuration definitions were moved to the combined
  14. ;    C/Assembler include file "tskconf.h" in version 2.1.
  15. ;
  16.      IFDEF BC_HUGE
  17. TC_HUGE = 1
  18.      ENDIF
  19. ;
  20.     include    tskconf.h
  21. ;
  22. ;-------------------------------------------------------------------
  23. ;
  24. TIMEOUT        =    -1
  25. WAKE        =    -2
  26. WATCH        =    -3
  27. ;
  28. ; Task states
  29. ;
  30. ST_KILLED    =    0
  31. ST_STOPPED    =    1
  32. ST_DELAYED    =    2
  33. ST_WAITING    =    3
  34. ST_ELIGIBLE    =    4
  35. ST_RUNNING    =    5
  36. ;
  37. ; Task flags
  38. ;
  39. F_TEMP         =    80h    ; Task is temporary
  40. F_STTEMP    =    40h    ; Task stack is temporary, free on kill
  41. F_PERM         =    20h    ; Task is a permanent system task
  42. F_USES_NDP    =    02h    ; Task uses NDP
  43. F_CRIT        =    01h    ; Task is critical, may not be preempted
  44. ;
  45. FL_SYSM        =    0f0h    ; Mask for system flags
  46. FL_USRM        =    00fh    ; Mask for user flags
  47. ;
  48. ; Timer queue element action kinds (upper nibble of elkind)
  49. ;
  50. TELEM_TIMER    =    10h    ; Timeout element
  51. TELEM_MEM    =    20h    ; Memory watch element
  52. TELEM_PORT    =    30h    ; Port watch element
  53. TELEM_HOTKEY    =    40h    ; Hotkey element
  54. ;
  55. ; Timer watch element comparison kinds (lower nibble of elkind)
  56. ;
  57. TCMP_EQ        =    1    ; Equal 
  58. TCMP_NE        =    2    ; Not Equal 
  59. TCMP_GE        =    3    ; Greater or Equal (unsigned) 
  60. TCMP_LE        =    4    ; Less or Equal (unsigned) 
  61. TCMP_GES    =    5    ; Greater or Equal (signed) 
  62. TCMP_LES    =    6    ; Less or Equal (signed) 
  63. TCMP_CHG    =    7    ; Change in value 
  64. ;
  65. ; Timer queue element control structure pointer kinds 
  66. ;
  67. TKIND_TASK    =    1    ; tcbptr, Wakeup associated task 
  68. TKIND_WAKE    =    2    ; tcbptr, but not same task 
  69. TKIND_PROC    =    3    ; call function 
  70. TKIND_FLAG    =    4    ; flagptr, set flag 
  71. TKIND_COUNTER    =    5    ; counterptr, increment counter 
  72. TKIND_COUNTDEC    =    6    ; counterptr, decrement counter 
  73. ;
  74. ; Timer queue element flags
  75. ;
  76. TFLAG_BUSY    =    01h    ; Timer task is busy processing element 
  77. TFLAG_ENQUEUE    =    02h    ; Enqueue after processing 
  78. TFLAG_UNQUEUE    =    04h    ; Don't enqueue after processing 
  79. TFLAG_REMOVE    =    08h    ; Free element after processing 
  80. TFLAG_REPEAT    =    40h    ; Bit set signals repeat processing 
  81. TFLAG_TEMP      =    80h    ; Bit set means temporary element
  82. ;
  83. ; Name link and queue head structure types 
  84. ;
  85. Q_HEAD        =    80h    ; Queue head flag 
  86. ;
  87. TYP_GROUP    =    0
  88. TYP_TCB        =    1
  89. TYP_FLAG    =    2
  90. TYP_RESOURCE    =    3
  91. TYP_COUNTER    =    4
  92. TYP_MAILBOX    =    5
  93. TYP_PIPE    =    6
  94. TYP_WPIPE    =    7
  95. TYP_BUFFER    =    8
  96. TYP_TIMER    =    9
  97. TYP_WATCH    =    10
  98. TYP_HOTKEY    =    11
  99. ;
  100. NAMELENGTH    =    9
  101. ;
  102. ; Installation flags 
  103. ;
  104. IFL_VIDEO    =    0001h    ; Install INT 10 access resource 
  105. IFL_DISK    =    0002h    ; Install INT 13 access resource 
  106. IFL_INT8_DIR    =    0004h    ; Call original INT 8 directly 
  107. IFL_PRINTER    =    0008h    ; Install INT 17 handler 
  108. IFL_INT15    =    0010h    ; Install IBM-AT INT 15 handler 
  109. IFL_NODOSVARS    =    0020h    ; Don't swap DOS variables 
  110. IFL_NOEXITCHECK    =    0040h    ; Don't check for premature exit 
  111. ;
  112. IFL_STD       =    (IFL_DISK OR IFL_PRINTER OR IFL_INT15)
  113. ;
  114. ; Size of the DOS variable swap area plus 8 bytes.
  115. ;
  116. DOSSWAPSIZE    =    30h
  117. ;
  118. ndp_rec        struc
  119. control87    dw    ?
  120. status87    dw    ?
  121. tag87        dw    ?
  122. iplo87        dw    ?
  123. iphi87_opcode87    dw    ?
  124. opaddrlo87    dw    ?
  125. opaddrhi87_null    dw    ?
  126. ndp_st0        dt    ?
  127. ndp_st1        dt    ?
  128. ndp_st2        dt    ?
  129. ndp_st3        dt    ?
  130. ndp_st4        dt    ?
  131. ndp_st5        dt    ?
  132. ndp_st6        dt    ?
  133. ndp_st7        dt    ?
  134. ndp_rec        ends
  135. ;
  136. callchain    struc
  137. cc_next        dd    ?
  138. cc_func        dd    ?
  139. cc_user_ptr    dd    ?
  140. cc_flags    db    ?
  141. callchain    ends
  142. ;
  143. qelem_pri    struc
  144. q_prior        dw    ?
  145. q_ini_prior    dw    ?
  146. qelem_pri    ends
  147. ;
  148. qelem_ticks    struc
  149. q_ticks        dd    ?
  150. qelem_ticks    ends
  151. ;
  152. queue_rec    struc
  153. q_next        dd    ?
  154. q_prev        dd    ?
  155. q_kind        db    ?
  156. q_el        db    TYPE qelem_pri dup(?)
  157. queue_rec    ends
  158. ;
  159. queue_head    struc
  160. q_first        dd    ?
  161. q_last        dd    ?
  162.         db    ?
  163. queue_head    ends
  164. ;
  165. ;
  166. namerec    struc
  167. ;
  168. nlist        db    TYPE queue_head dup(?)
  169. nstrucp        dd    ?
  170. nname        db    NAMELENGTH dup(?)
  171. ;
  172. namerec    ends
  173. ;
  174. ;
  175. tlink_rec    struc
  176. ;
  177. tlink        db    TYPE queue_rec dup(?)
  178. tlnext        dd    ?    ; timer task temp chain
  179. strucp        dd    ?    ; structure pointer
  180. tuserp        dd    ?    ; user parameter
  181.         IF    GROUPS
  182. tchain        db    TYPE queue_head dup(?)    ; timer element chain
  183.         ENDIF
  184. telem        db    8 dup(?) ; timeout element (union)
  185. elkind        db    ?    ; element kind
  186. struckind    db    ?    ; structure kind
  187. tflags        db    ?    ; timer flags
  188. ;
  189. tlink_rec    ends
  190. ;
  191. ;
  192. tcb    struc
  193. ;
  194. cqueue        db    TYPE queue_rec dup(?)
  195. qhead        dd    ?
  196. stkbot        dd    ?    ; stack bottom
  197. state        db    ?    ; task state
  198. flags        db    ?    ; task flags
  199. ;
  200. t_sp    dw    ?
  201. t_ss    dw    ?
  202. t_ax    dw    ?
  203. t_cx    dw    ?
  204. t_dx    dw    ?
  205. t_si    dw    ?
  206. t_di    dw    ?
  207. t_bp    dw    ?
  208. t_es    dw    ?
  209. t_ds    dw    ?
  210. ;
  211. timerq    db    TYPE tlink_rec dup(?)
  212. retptr    dd    ?    ; return value pointer
  213. retsize    dw    ?    ; return value size
  214. ;
  215. save_func    dd    ?
  216. rest_func    dd    ?
  217. user_ptr    dd    ?
  218. ;
  219.     IF    GROUPS
  220. tgroup        dd    ?    ; group control block pointer
  221. homegroup    dd    ?    ; group control block pointer
  222.     ENDIF
  223.     IF    DOS
  224. sched_ent_func    dd    ?
  225. t_indos        db    ?    ; in-dos flags
  226. t_new        db    ?    ; new task flag
  227. ;
  228. ;    caution: don't change the order of the following 3 items!
  229. base_psp    dw    ?    ; base PSP segment address
  230. psp_sssp    dd    ?    ; PSP ss:sp save area
  231. t_swap_area    db    DOSSWAPSIZE dup(?)    ; save area for DOS-vars & Int23/24
  232.     ENDIF
  233. ;
  234.     IF    TSK_NAMED
  235. tname    db    TYPE namerec dup(?)
  236.     ENDIF
  237.     IF    EMS
  238. t_ems_map    db    EMS_SAVE_SIZE dup(?)
  239.     ENDIF
  240.     IF    NDP
  241. ndpsave        db    TYPE ndp_rec dup(?)
  242.     ENDIF
  243. ;
  244. tcb    ends
  245. ;
  246. ;
  247. gcb    struc
  248. ;
  249. ghome        dd    ?
  250. glevel        dd    ?
  251. gbranch        dd    ?
  252. gcreator    dd    ?
  253. grp_exit_addr    dd    ?
  254. gcreate_psp    dw    ?
  255. gsave_psp    dw    ?
  256. gsave_sssp    dd    ?
  257. gnamelist    db    TYPE namerec dup(?)
  258. gmain_ptr    dd    ?
  259. gremove        dd    ?
  260.         IF    GROUPS
  261. gtelem_list    db    TYPE queue_head dup(?)
  262. gticker_list    db    TYPE queue_head dup(?)
  263.         ENDIF
  264. ;
  265.         IF    TSK_DYNAMIC
  266. gpalloc        dd    ?
  267. gpfree        dd    ?
  268.         ENDIF
  269. gcb    ends
  270. ;
  271. ;
  272. flag        struc
  273. ;
  274. fwait_set    db    TYPE queue_head dup(?)
  275. fwait_clear    db    TYPE queue_head dup(?)
  276. fstate        dw    ?
  277.  
  278.     IF    TSK_DYNAMIC
  279. flflags    db    ?
  280.     ENDIF
  281.     IF    TSK_NAMED
  282. fname    db    TYPE namerec dup(?)
  283.     ENDIF
  284. ;
  285. flag        ends
  286. ;
  287. ;
  288. counter        struc
  289. ;
  290. cwait_set    db    TYPE queue_head dup(?)
  291. cwait_clear    db    TYPE queue_head dup(?)
  292. cstate        dd    ?
  293. ;
  294.     IF    TSK_DYNAMIC
  295. ctflags    db    ?
  296.     ENDIF
  297.     IF    TSK_NAMED
  298. ctname    db    TYPE namerec dup(?)
  299.     ENDIF
  300. counter        ends
  301. ;
  302. ;
  303. resource    struc
  304. ;
  305. rwaiting    db    TYPE queue_head dup(?)
  306. rowner        dd    ?
  307. rcount        dw    ?
  308. ;
  309.     IF    TSK_DYNAMIC
  310. rsflags    db    ?
  311.     ENDIF
  312.     IF    TSK_NAMED
  313. rsname    db    TYPE namerec dup(?)
  314.     ENDIF
  315.  
  316. resource    ends
  317. ;
  318. ;
  319. mailbox        struc
  320. ;
  321. mwaiting    db    TYPE queue_head dup(?)
  322. mail_first    dd    ?
  323. mail_last    dd    ?
  324. ;
  325.     IF    TSK_DYNAMIC
  326. mbflags    db    ?
  327.     ENDIF
  328.     IF    TSK_NAMED
  329. mbname    db    TYPE namerec dup(?)
  330.     ENDIF
  331. mailbox        ends
  332. ;
  333. ;
  334. pipe        struc
  335. ;
  336. pwait_read    db    TYPE queue_head dup(?)
  337. pwait_write    db    TYPE queue_head dup(?)
  338. pwait_clear    db    TYPE queue_head dup(?)
  339. pbufsize    dw    ?
  340. pfilled        dw    ?
  341. pinptr        dw    ?
  342. poutptr        dw    ?
  343. pcontents    dd    ?
  344. ;
  345.     IF    TSK_DYNAMIC
  346. ppflags    db    ?
  347.     ENDIF
  348.     IF    TSK_NAMED
  349. ppname    db    TYPE namerec dup(?)
  350.     ENDIF
  351. pipe        ends
  352. ;
  353. ;
  354. wpipe        struc
  355. ;
  356. wwait_read    db    TYPE queue_head dup(?)
  357. wwait_write    db    TYPE queue_head dup(?)
  358. wwait_clear    db    TYPE queue_head dup(?)
  359. wbufsize    dw    ?
  360. wfilled        dw    ?
  361. winptr        dw    ?
  362. woutptr        dw    ?
  363. wcontents    dd    ?
  364. ;
  365.     IF    TSK_DYNAMIC
  366. wpflags    db    ?
  367.     ENDIF
  368.     IF    TSK_NAMED
  369. wpname    db    TYPE namerec dup(?)
  370.     ENDIF
  371. wpipe        ends
  372. ;
  373. ;
  374. glob_rec    struc
  375. ;
  376. glb_id        db    8 dup(?)
  377.  
  378. current_task    dd    ?
  379. eligible_queue    db    TYPE queue_head dup(?)
  380.  
  381. timer_queue    db    TYPE queue_head dup(?)
  382. watch_queue    db    TYPE queue_head dup(?)
  383.  
  384. preempt        db    ?
  385. pretick        db    ?
  386. var_prior    db    ?
  387.  
  388. in_sched    db    ?
  389.  
  390. tick_factor    dw    ?
  391. ticks_per_sec    dw    ?
  392. ticker_chain    dd    ?
  393. ;
  394. stub_table    dd    ?
  395. ;
  396.     IF    TSK_DYNAMIC
  397. pkill_queue    db    TYPE queue_head dup(?)
  398. pkill_task    dd    ?
  399.     ENDIF
  400.     IF    IBM
  401. hotkey_scan    db    TYPE queue_head dup(?)
  402. hotkey_noscan    db    TYPE queue_head dup(?)
  403.     ENDIF
  404.     IF    EMS
  405. ems_save    dd    ?
  406. ems_rest    dd    ?
  407. ems_savetsk    dd    ?
  408.     ENDIF
  409.     IF    DOS
  410. emergency_exit    dd    ?
  411. l_swap        dw    ?
  412. dos_vars    dd    ?
  413. dos_in_use    dd    ?        ; Adress of DOS in-use-flag
  414.     ENDIF
  415.     IF    GROUPS
  416. ggroup        db    TYPE gcb dup(?)
  417.     ELSE
  418. main_ptr    dd    ?
  419. glb_remove    dd    ?
  420.     IF    TSK_NAMED
  421. name_list    db    TYPE namerec dup(?)
  422.     ENDIF
  423.     ENDIF
  424.     IF    NDP
  425. ndp_present    db    ?
  426.     ENDIF
  427. ;
  428. glob_rec    ends
  429. ;
  430. ;
  431. tick_rec    struc
  432. ;
  433. ticknext    dd    ?
  434. ticklo        dw    ?
  435. tickhi        dw    ?
  436.     IF    GROUPS
  437. tickchain    db    TYPE queue_head dup(?)
  438.     ENDIF
  439.     IF    TSK_DYNAMIC
  440. tickflags    db    ?
  441.     ENDIF
  442. ;
  443. tick_rec    ends
  444. ;
  445. ;
  446. hotflags_rec    struc
  447. hf_mask        db    ?
  448. hf_value    db    ?
  449. hotflags_rec    ends
  450. ;
  451. hotkey_rec    struc
  452. kbflags1    db    TYPE hotflags_rec dup(?)
  453. kbflags2    db    TYPE hotflags_rec dup(?)
  454. kbflags3    db    TYPE hotflags_rec dup(?)
  455. scancode    db    ?
  456. hotkey_rec    ends
  457. ;
  458. ;
  459. ;    Stack setup relative to BP after switch_stack has been called
  460. ;
  461. saved_regs    struc
  462. ;
  463.         dd    ?    ; special return addr
  464. entry_flags    dw    ?    ; flags on entry to switch_stack
  465. caller_ip    dw    ?    ; IP from INT stack
  466. caller_cs    dw    ?    ; CS from INT stack
  467. caller_flags    dw    ?    ; flags from INT stack
  468. save_es        dw    ?
  469. save_ds        dw    ?
  470. save_bp        dw    ?
  471. save_di        dw    ?
  472. save_si        dw    ?
  473. save_dx        dw    ?
  474. save_ax        dw    ?
  475. slot_sp        dw    ?    ; stack slot sp
  476. slot_idx    dw    ?    ; stack slot index
  477. save_cx        dw    ?
  478. save_bx        dw    ?
  479. ;
  480. saved_regs    ends
  481. ;
  482. ;
  483. stc_saved    macro
  484.         or    byte ptr caller_flags[bp],1
  485.         endm
  486. ;
  487. clc_saved    macro
  488.         and    byte ptr caller_flags[bp],0feh
  489.         endm
  490. ;
  491. ;    Flags for the T_INDOS field in the TCB
  492. ;
  493. OWN_LOWER       =       1
  494. OWN_UPPER       =       2
  495. DOS_ENTERED    =    4
  496. ;
  497. ;---------------------------------------------------------------------
  498. ;
  499.     IFDEF    BC_HUGE
  500. TC_HUGE    =    1
  501.     ENDIF
  502. ;
  503. global_ext    macro
  504.         IF    SINGLE_DATA
  505.         extrn    tsk_glob_rec: byte
  506.         ELSE
  507.         extrn    tsk_global: dword
  508.         ENDIF
  509.         endm
  510. ;
  511.         IFDEF    TC_HUGE
  512. ;
  513. .tsk_data    macro
  514.         IFDEF    BC_HUGE
  515. CTASK_DATA    segment byte public 'FAR_DATA'
  516.         ELSE
  517. CTASK_DATA    segment byte public 'DATA'
  518.         ENDIF
  519.         assume    ds:CTASK_DATA,es:CTASK_DATA
  520. @CTASK_DATA    equ    <CTASK_DATA>
  521. @data        equ    <CTASK_DATA>
  522.         endm
  523. ;
  524.         ELSE
  525. ;
  526. .tsk_data    macro
  527.         .data
  528. @CTASK_DATA    equ    <DGROUP>
  529.         assume    ds:@data,es:@data
  530.         endm
  531. ;
  532.         ENDIF
  533. ;
  534.         IF    NEAR_CODE
  535. ;
  536. .tsk_code    macro
  537.         .code
  538.         endm
  539. ;
  540. Globext        macro    lab
  541.         IF    CALL_PASCAL
  542.         extrn    pascal lab: near
  543. _P_&lab        =    1
  544.         ELSE
  545.         extrn    C lab: near
  546.         ENDIF
  547.         endm
  548. ;
  549. CGlbext        macro    lab
  550.         extrn    C lab: near
  551.         endm
  552. ;
  553. PGlbext        macro    lab
  554.         extrn    pascal lab: near
  555. _P_&lab        =    1
  556.         endm
  557.         ELSE
  558. ;
  559. .tsk_code    macro
  560. CTASK_TEXT    segment word public 'CODE'
  561. @code        equ    <CTASK_TEXT>
  562.         assume    cs:CTASK_TEXT
  563.         endm
  564. ;
  565. Globext        macro    lab
  566.         IF    CALL_PASCAL
  567.         extrn    pascal lab: far
  568. _P_&lab        =    1
  569.         ELSE
  570.         extrn    C lab: far
  571.         ENDIF
  572.         endm
  573. ;
  574. CGlbext        macro    lab
  575.         extrn    C lab: far
  576.         endm
  577. ;
  578. PGlbext        macro    lab
  579.         extrn    pascal lab: far
  580. _P_&lab        =    1
  581.         endm
  582. ;
  583.         ENDIF
  584. ;
  585.         IF    LOCALS_FAR
  586. ;
  587. Locext        macro    lab
  588.         IF    CALL_PASCAL
  589.         extrn    pascal lab: far
  590. _P_&lab        =    1
  591.         ELSE
  592.         extrn    C lab: far
  593.         ENDIF
  594.         endm
  595. ;
  596. CLocext        macro    lab
  597.         extrn    C lab: far
  598.         endm
  599. ;
  600.         ELSE
  601. ;
  602. Locext        macro    lab
  603.         IF    CALL_PASCAL
  604.         extrn    pascal lab: near
  605. _P_&lab        =    1
  606.         ELSE
  607.         extrn    C lab: near
  608.         ENDIF
  609.         endm
  610. ;
  611. CLocext        macro    lab
  612.         extrn    C lab: near
  613.         endm
  614. ;
  615.         ENDIF
  616. ;
  617. .tsk_ecode    macro
  618.     IFDEF    @CurSeg
  619. @CurSeg        ends
  620.     ELSE
  621. @curseg        ends
  622.     ENDIF
  623.         endm
  624. ;
  625. .tsk_edata    macro
  626.     IFDEF    @CurSeg
  627. @CurSeg        ends
  628.     ELSE
  629. @curseg        ends
  630.     ENDIF
  631.         endm
  632. ;
  633. .tsk_model    macro
  634.         .model    small,c
  635.         IF    CHECKING
  636.         IFNDEF    fatal_pmd
  637.         extrn    C tsk_fatal_pmd: far
  638.         ENDIF
  639. @fnstring    catstr    <">,@filename,<">
  640.         ENDIF
  641.         endm
  642. ;
  643. Globalfunc    macro    name,pars
  644.         IF    NEAR_CODE
  645.         IF    CALL_PASCAL
  646.         IFDEF    ??Version
  647. name        proc    pascal near pars
  648.         ELSE
  649. name        proc    near pascal pars
  650.         ENDIF
  651.         ELSE
  652.         IFDEF    ??Version
  653. name        proc    C near pars
  654.         ELSE
  655. name        proc    near C pars
  656.         ENDIF
  657.         ENDIF
  658.         ELSE
  659.         IF    CALL_PASCAL
  660.         IFDEF    ??Version
  661. name        proc    pascal far pars
  662.         ELSE
  663. name        proc    pascal far pars
  664.         ENDIF
  665.         ELSE
  666.         IFDEF    ??Version
  667. name        proc    C far pars
  668.         ELSE
  669. name        proc    far C pars
  670.         ENDIF
  671.         ENDIF
  672.         ENDIF
  673.         endm
  674. ;    
  675. CGlobalfunc    macro    name,pars
  676.         IF    NEAR_CODE
  677. name        proc    near pars
  678.         ELSE
  679.         IFDEF    ??Version
  680. name        proc    C far pars
  681.         ELSE
  682. name        proc    far C pars
  683.         ENDIF
  684.         ENDIF
  685.         endm
  686. ;
  687. Localfunc    macro    name,pars
  688.         IF    LOCALS_FAR
  689.         IF    CALL_PASCAL
  690.         IFDEF    ??Version
  691. name        proc    pascal far pars
  692.         ELSE
  693. name        proc    far pascal pars
  694.         ENDIF
  695.         ELSE
  696.         IFDEF    ??Version
  697. name        proc    C far pars
  698.         ELSE
  699. name        proc    far C pars
  700.         ENDIF
  701.         ENDIF
  702.         ELSE
  703.         IF    CALL_PASCAL
  704.         IFDEF    ??Version
  705. name        proc    pascal near pars
  706.         ELSE
  707. name        proc    near pascal pars
  708.         ENDIF
  709.         ELSE
  710.         IFDEF    ??Version
  711. name        proc    C near pars
  712.         ELSE
  713. name        proc    near C pars
  714.         ENDIF
  715.         ENDIF
  716.         ENDIF
  717.         endm
  718. ;    
  719. CLocalfunc    macro    name,pars
  720.         IF    LOCALS_FAR
  721.         IFDEF    ??Version
  722. name        proc    C far pars
  723.         ELSE
  724. name        proc    far C pars
  725.         ENDIF
  726.         ELSE
  727.         IFDEF    ??Version
  728. name        proc    C near pars
  729.         ELSE
  730. name        proc    near C pars
  731.         ENDIF
  732.         ENDIF
  733.         endm
  734. ;
  735. Pubfunc        macro    name
  736.         IF    CALL_PASCAL
  737.         public    pascal name
  738.         ELSE
  739.         public    C name
  740.         ENDIF
  741.         endm
  742. ;
  743. CPubfnc        macro    name
  744.         public    C name
  745.         endm
  746. ;
  747. ;-------------------------------------------------------------------
  748. ;
  749. ;    The following is a set of macros that allow calling an
  750. ;    external routine without caring about the calling sequence
  751. ;    (C or Pascal) in use. Usage is
  752. ;
  753. ;        callp    procname,<parameter list>
  754. ;    as in
  755. ;        callp    request_resource,<<ds,offset dosupper>,0,0>
  756. ;
  757. ;    Doubleword and Segment/Offset pairs must be grouped with an
  758. ;    additional level of brackets.
  759. ;
  760. ;    The parameter list may contain the special character '#'
  761. ;    as a prefix to a label to identify an offset, so the above
  762. ;    example could be abbreviated to
  763. ;
  764. ;        callp    request_resource,<<ds,#dosupper>,0,0>
  765. ;
  766. ;    Also, the prefix '/' denotes an effective address, i.e. the
  767. ;    LEA instruction is used to load the parameter value.
  768. ;
  769. ;
  770. ;    The 'vpush' macro pushes a single value or a doubleword pair.
  771. ;    It checks the type of parameter (constant or variable), and
  772. ;    handles the offset shortcuts '#' and '/'. Note that AX is destroyed
  773. ;    when constants are pushed and the CPU is an 8086/88.
  774. ;
  775. vpush    macro    val,val2
  776.     local    vrest,hash,slash,strg,strgc,snext
  777. cc_parcnt    =    cc_parcnt + 2
  778. strg    instr    1,<val>,<">
  779. hash    instr    1,<val>,<#>
  780. slash    instr    1,<val>,</>
  781.     IF    hash EQ 1        ;; If hashmark prefix
  782. vrest    substr    <val>,2            ;; Get real parameter
  783.     IF    @Cpu AND 2
  784.     push    offset vrest
  785.     ELSE
  786.     mov    ax,offset vrest
  787.     push    ax
  788. ax_is_zero    =    0
  789.     ENDIF
  790.     ELSEIF    slash EQ 1
  791. vrest    substr    <val>,2            ;; Get real parameter
  792.     lea    ax,vrest
  793.     push    ax
  794. ax_is_zero    =    0
  795.     ELSEIF    strg EQ 1
  796.     jmp    short snext
  797. strgc    db    val,0
  798. snext:
  799.     push    cs
  800.     IF    @Cpu AND 2
  801.     push    offset strgc
  802.     ELSE
  803.     mov    ax,offset strgc
  804.     push    ax
  805. ax_is_zero    =    0
  806.     ENDIF
  807. cc_parcnt    =    cc_parcnt + 2
  808.     ELSEIF    (.TYPE val) AND 4    ;; If it's a constant
  809.     IF    @Cpu AND 2
  810.     push    val
  811.     ELSE
  812.     IF    val
  813.     mov    ax,val
  814. ax_is_zero    =    0
  815.     ELSEIFE    ax_is_zero        ;; Push 0 is handled special
  816.     xor    ax,ax
  817. ax_is_zero    =    TRUE
  818.     ENDIF
  819.     push    ax
  820.     ENDIF
  821.     ELSEIF    (.TYPE val) AND 10h    ;; If it's a register
  822.     push    val            ;; Push normal if register
  823.     ELSE
  824.     push    word ptr (val)        ;; Push word if variable
  825.     ENDIF
  826.     IFNB    <val2>
  827.     vpush    val2            ;; Do it again if second parameter
  828.     ENDIF
  829.     endm
  830. ;
  831. ;    The 'pushp' macro reverses the parameter list for the C calling
  832. ;    sequence by calling itself recursively.
  833. ;
  834. pushp    macro    p1,p2,p3,p4,p5,p6,p7,p8,p9,p10
  835.     IFNB    <p2>
  836.     pushp    <p2>,<p3>,<p4>,<p5>,<p6>,<p7>,<p8>,<p9>,<p10>
  837.     ENDIF
  838.     IFNB    <p1>
  839.     vpush    p1
  840.     ENDIF
  841.     endm
  842. ;
  843. ;    The 'callp' macro calls pushp or vpush depending on the 
  844. ;    calling sequence, and re-adjusts the stack after the call
  845. ;    for C.
  846. ;
  847. callp    macro    name,pars
  848. cc_parcnt    =    0
  849. ax_is_zero    =    FALSE
  850.     IFDEF    _P_&name
  851.     IRP    p,<pars>
  852.     vpush    p
  853.     ENDM
  854.     ELSE
  855.     pushp    pars
  856.     ENDIF
  857.     call    name
  858.     IFNDEF    _P_&name
  859.     IF    cc_parcnt
  860.     add    sp,cc_parcnt
  861.     ENDIF
  862.     ENDIF
  863.     ENDM
  864. ;
  865. ;--------------------------------------------------------------------------
  866. ;
  867. xjz    macro    where
  868.     local    nxt
  869.     IF    CHECKING
  870.     jnz    nxt
  871.     jmp    where
  872. nxt:
  873.     ELSE
  874.     jz    where
  875.     ENDIF
  876.     ENDM
  877. ;
  878. xjmp    macro    where
  879.     local    nxt
  880.     IF    CHECKING
  881.     jmp    where
  882.     ELSE
  883.     jmp    short where
  884.     ENDIF
  885.     ENDM
  886. ;
  887. ;
  888. ;    Checking mode support macros
  889. ;
  890. CHECK_PTR_R    macro    sreg,reg,txt
  891.     local    ok,nok,str
  892.     IF    CHECKING
  893.     push    ax
  894.     mov    ax,sreg
  895.     or    ax,reg
  896.     jnz    ok
  897.     jmp    short nok
  898. str    db    txt,' - Invalid pointer: %FP',0ah,0
  899. nok:
  900.     callp    tsk_fatal_pmd,<<cs,#str>,<sreg,reg>>
  901. ok:
  902.     pop    ax
  903.     ENDIF
  904.     ENDM
  905. ;
  906. ;
  907. CHECK_PTR    macro    pntr,txt
  908.     local    ok,nok,str
  909.     IF    CHECKING
  910.     push    ax
  911.     mov    ax,word ptr (pntr)
  912.     or    ax,word ptr (pntr+2)
  913.     jnz    ok
  914.     jmp    short nok
  915. str    db    txt,' - Invalid pointer: %FP',0ah,0
  916. nok:
  917.     callp    tsk_fatal_pmd,<<cs,#str>,<pntr+2,pntr>>
  918. ok:
  919.     pop    ax
  920.     ENDIF
  921.     ENDM
  922. ;
  923. ;
  924. CHECK_TCBPTR_R    macro    sreg,reg,txt
  925.     local    ok,nok,str
  926.     IF    CHECKING
  927.     push    ax
  928.     mov    ax,sreg
  929.     or    ax,reg
  930.     jz    nok
  931.     cmp    sreg:cqueue.q_kind[reg],TYP_TCB
  932.     jne    nok
  933.     IF    TSK_NAMED
  934.     cmp    sreg:tname.nlist.q_kind[reg],TYP_TCB
  935.     je    ok
  936.     ENDIF
  937.     jmp    short nok
  938. str    db    txt,' - Invalid pointer: %FP',0ah,0
  939. nok:
  940.     callp    tsk_fatal_pmd,<<cs,#str>,<sreg,reg>>
  941. ok:
  942.     pop    ax
  943.     ENDIF
  944.     ENDM
  945. ;
  946. ;
  947. CHECK_TCBPTR    macro    pntr,txt
  948.     IF    CHECKING
  949.     push    ds
  950.     push    si
  951.     lds    si,pntr
  952.     CHECK_TCBPTR_R    ds,si,txt
  953.     pop    si
  954.     pop    ds
  955.     ENDIF
  956.     ENDM
  957. ;
  958. ;
  959. CHECK_EVTPTR_R    macro    sreg,reg,kind,txt
  960.     local    ok,nok,str
  961.     IF    CHECKING
  962.     push    ax
  963.     mov    ax,sreg
  964.     or    ax,reg
  965.     jz    nok
  966.     mov    al,kind
  967.     or    al,Q_HEAD
  968.     cmp    al,sreg:cqueue.q_kind[reg]
  969.     je    ok
  970.     jmp    short nok
  971. str    db    txt,' - Invalid pointer: %FP',0ah,0
  972. nok:
  973.     callp    tsk_fatal_pmd,<<cs,#str>,<sreg,reg>>
  974. ok:
  975.     pop    ax
  976.     ENDIF
  977.     ENDM
  978. ;
  979. ;
  980. CHECK_EVTPTR    macro    pntr,kind,txt
  981.     IF    CHECKING
  982.     push    ds
  983.     push    si
  984.     lds    si,pntr
  985.     CHECK_EVTPTR_R    ds,si,kind,txt
  986.     pop    si
  987.     pop    ds
  988.     ENDIF
  989.     ENDM
  990. ;
  991. ;
  992. CHECK_QHEAD_R    macro    sreg,reg,txt
  993.     local    ok,nok,str
  994.     IF    CHECKING
  995.     push    ax
  996.     mov    ax,sreg
  997.     or    ax,reg
  998.     jz    nok
  999.     test    sreg:cqueue.q_kind[reg],Q_HEAD
  1000.     jnz    ok
  1001.     jmp    short nok
  1002. str    db    txt,' - Invalid pointer: %FP',0ah,0
  1003. nok:
  1004.     callp    tsk_fatal_pmd,<<cs,#str>,<sreg,reg>>
  1005. ok:
  1006.     pop    ax
  1007.     ENDIF
  1008.     ENDM
  1009. ;
  1010. ;
  1011. CHECK_QHEAD    macro    pntr,txt
  1012.     IF    CHECKING
  1013.     push    ds
  1014.     push    si
  1015.     lds    si,pntr
  1016.     CHECK_QHEAD_R    ds,si,txt
  1017.     pop    si
  1018.     pop    ds
  1019.     ENDIF
  1020.     ENDM
  1021. ;
  1022. FATAL    macro    txt,pars
  1023.     local    str,nok
  1024.     IF    CHECKING
  1025.     jmp    short nok
  1026. str    db    txt,0ah,0
  1027. nok:
  1028.     callp    tsk_fatal_pmd,<<cs,#str>,<pars>>
  1029.     ENDIF
  1030.     ENDM
  1031. ;
  1032. ASSERT    macro    arg1,opn,arg2,txt,pars
  1033.     local    str,nok,isok,fns
  1034.     IF    CHECKING
  1035.     cmp    arg1,arg2
  1036.     j&opn    isok
  1037.     jmp    short nok
  1038.     IFNB    <txt>
  1039. str    db    txt,0ah,0
  1040. nok:
  1041.     callp    tsk_fatal_pmd,<<cs,#str>,<pars>>
  1042.     ELSE
  1043. str    db    0ah,"Assertion failed <&arg1 &opn &arg2> - "
  1044.     db    @fnstring," - AX=%04X",0ah,0
  1045. nok:
  1046.     callp    tsk_fatal_pmd,<<cs,#str>,ax>
  1047.     ENDIF
  1048. isok:
  1049.     ENDIF
  1050.     ENDM
  1051. ;
  1052. ;
  1053.