home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 330_02 / tsk.mac < prev    next >
Text File  |  1990-10-12  |  16KB  |  908 lines

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