home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / c / kernel.zip / TELE.MAC < prev   
Text File  |  1986-11-25  |  9KB  |  253 lines

  1. ;Listing 2-     System Definitions
  2. ;(C) Copyright 1986 Ken Berry.
  3. ;All rights reserved.
  4. ;Copies may be made for non-commercial, private use only.
  5.  
  6.  
  7. sys_parm  struc          ;; register storage block
  8. rax       dw ?           ;; ax (general register A)
  9. rbx       dw ?           ;; bx (general register B)
  10. rcx       dw ?           ;; cx (general register C)
  11. rdx       dw ?           ;; dx (general register D)
  12. rbp       dw ?           ;; bp (base pointer)
  13. rsi       dw ?           ;; si (source index)
  14. rdi       dw ?           ;; di (destination index)
  15. rsp       dw ?           ;; sp (stack pointer)
  16. rcs       dw ?           ;; cs (code segment)
  17. rds       dw ?           ;; ds (data segment)
  18. rss       dw ?           ;; ss (stack segment)
  19. res       dw ?           ;; es (extra segment)
  20. rpf       dw ?           ;; pf (processor flags)
  21. rsw       dw ?           ;; sw (status word)
  22. rip       dw ?           ;; ip (instruction pointer)
  23. rres      dw ?           ;; unused
  24. sys_parm  ends
  25.  
  26. t_task    struc          ;; task control table
  27. t_type    db ?           ;; task type
  28. t_wttk    dw ?           ;; wait tick count
  29. t_cls     dw ?           ;; priority queue index
  30. t_pqtsk   dw ?           ;; prior t_task pointer
  31. t_nqtsk   dw ?           ;; next t_task pointer
  32. t_ratsk   dw ?           ;; ancestor t_task pointer
  33. t_pstsk   dw ?           ;; prior sibling t_task pointer
  34. t_nstsk   dw ?           ;; next sibling t_task pointer
  35. t_fdtsk   dw ?           ;; first desendant t_task pointer
  36. t_ldtsk   dw ?           ;; last desendant t_task pointer
  37. t_ps      db type sys_parm dup (?) ;; processor status
  38. t_xtm0    dw ?           ;; *  execution time accumulator
  39. t_xtm1    dw ?           ;; *
  40. t_xtm2    dw ?           ;; *
  41. t_axstk   dw ?           ;; application stack pointer
  42. t_task    ends
  43.  
  44. T_ATSK    equ 01h        ;; abreviated task
  45. T_X       equ 80h        ;; execute wueue
  46. T_W       equ 40h        ;; wait queue
  47. T_P       equ 20h        ;; priority queue
  48. t_SW      equ 10h        ;; secondary wait queue
  49.  
  50. t_scls    struc          ;; scheduling class queue
  51. t_sfrq    dw ?           ;; scheduling frequency
  52. t_sct     dw ?           ;; queue length
  53. t_fqtsk   dw ?           ;; first task in queue
  54. t_lqtsk   dw ?           ;; last task in queue
  55. t_scls    ends
  56.  
  57. t_schd    struc          ;; scheduling control table
  58. t_xct     dw ?           ;; execution queue length
  59. t_fxtsk   dw ?           ;; first task in execution queue
  60. t_lxtsk   dw ?           ;; last task in execution queue
  61. t_wct     dw ?           ;; wait queue length
  62. t_fwtsk   dw ?           ;; first task in wait queue
  63. t_lwtsk   dw ?           ;; last task in wait queue
  64. t_swct    dw ?           ;; secondary wait queue length
  65. t_fswtsk  dw ?           ;; first task in secondary wait queue
  66. t_lswtsk  dw ?           ;; last task in secondary wait queue
  67. t_sclsl   dw ?           ;; scheduling class index limit
  68. t_sclsp   dw ?           ;; scheduling class array pointer
  69. t_schd    ends
  70.  
  71. t_calln   struc          ;; near function call
  72. t_nbp     dw ?           ;; base pointer storage
  73. t_nret    dw ?           ;; return address
  74. t_np0     dw ?           ;; parameter 0
  75. t_np1     dw ?           ;; parameter 1
  76. t_np2     dw ?           ;; parameter 2
  77. t_np3     dw ?           ;; parameter 3
  78. t_np4     dw ?           ;; parameter 4
  79. t_np5     dw ?           ;; parameter 5
  80. t_np6     dw ?           ;; parameter 6
  81. t_np7     dw ?           ;; parameter 7
  82. t_calln   ends
  83.  
  84. t_xtsk    struc          ;; execution stack
  85. t_xbase   dw ?           ;; _base (for stack overflow detection)
  86. t_xes     dw ?           ;; es
  87. t_xbp     dw ?           ;; bp
  88. t_xdi     dw ?           ;; di
  89. t_xsi     dw ?           ;; si
  90. t_xdx     dw ?           ;; dx
  91. t_xcx     dw ?           ;; cx
  92. t_xbx     dw ?           ;; bx
  93. t_xax     dw ?           ;; ax
  94. t_xds     dw ?           ;; ds
  95. t_xip     dw ?           ;; ip
  96. t_xcs     dw ?           ;; cs
  97. t_xpf     dw ?           ;; pf
  98. t_retip   dw ?           ;; return ip
  99. t_xtsk    ends
  100.  
  101. retn      macro s        ;; near return
  102.   ifnb <s>
  103.           db 0C2h        ;; pop ip & adjust sp
  104.           db high s      ;; *  adjustment value
  105.           db low s       ;; *
  106.   else
  107.           db 0C3h        ;; pop ip only
  108.   endif
  109.           endm
  110.  
  111. retf      macro s        ;; far return
  112.   ifnb <s>
  113.           db 0CCh        ;; pop ip, cs & adjust sp
  114.           db high s      ;; *  adjustment value
  115.           db low s       ;; *
  116.   else
  117.           db 0CBh        ;; pop ip, cs only
  118.   endif
  119.           endm
  120.  
  121. ilck      macro reg,flag
  122.           xchg reg,flag  ;; capture token
  123.           endm
  124.  
  125. iowait    macro
  126.           nop            ;; I/O delay
  127.           endm
  128.  
  129. sys_entr  macro flag     ;; enter system function
  130.   ifndef sys_ilck
  131.           extrn sys_ilck:byte
  132.   endif
  133.           mov al,0FFh    ;; ** system task interlock
  134.           ilck al,sys_ilck ;; **
  135.           mov flag,al    ;; save asynchronous status
  136.           endm
  137.  
  138. sys_exit  macro flag     ;; exit from system function
  139.           local exit1,exit2
  140.   ifndef sys_ilck
  141.           extrn sys_ilck:byte
  142.   endif
  143.   ifndef t_astrm
  144.           extrn t_astrm:byte
  145.   endif
  146.   ifndef t_term
  147.           extrn t_term:near
  148.   endif
  149.           test byte ptr t_astrm,0FFh ;; *  test for application terminated
  150.           jnz exit1      ;; *
  151.           mov byte ptr sys_ilck,0 ;; exit system state
  152.           jmp short exit2 ;; continue application task
  153. exit1:    test flag,0FFH ;; ** test for more stacked system tasks
  154.           jnz exit2      ;; **
  155.           call t_term    ;; terminate application task
  156. exit2:                   ;; macro exit
  157.           endm
  158.  
  159. sys_sync  macro flag     ;; synchronize system resource
  160.   ifndef t_sync
  161.           extrn t_sync:near
  162.   endif
  163.           lea bx,flag    ;; set flag offset
  164.           call t_sync    ;; suspend task until token obtained
  165.           endm
  166.  
  167. sys_sstk  macro          ;; conditionally establish system stack
  168.           local sstk1
  169.   ifndef t__sstk
  170.           extrn t__sstk:near
  171.   endif
  172.           or al,al       ;; *  test for system task interrupted
  173.           jnz sstk1      ;; *
  174.           call t__sstk   ;; establish system stack
  175. sstk1:    push ds        ;; ** set es = ds
  176.           pop es         ;; **
  177.           endm
  178.  
  179. sys_sctx  macro          ;; save processor context
  180.           push bx        ;; protect bx
  181.           push cx        ;; protect cx
  182.           push dx        ;; protect dx
  183.           push si        ;; protect si
  184.           push di        ;; protect di
  185.           push bp        ;; protect bp
  186.           push es        ;; protect es
  187.           cld            ;; clear direction flag
  188.           sys_sstk       ;; conditionally establish system stack
  189.           endm
  190.  
  191. sys__rctx macro          ;; restore processor context (except ds)
  192.           pop es         ;; restore es
  193.           pop bp         ;; restore bp
  194.           pop di         ;; restore di
  195.           pop si         ;; restore si
  196.           pop dx         ;; restore dx
  197.           pop cx         ;; restore cx
  198.           pop bx         ;; restore bx
  199.           pop ax         ;; restore ax
  200.           endm
  201.  
  202. sys_rctx  macro          ;; restore processor context
  203.           sys__rctx      ;; restore context (except ds)
  204.           pop ds         ;; restore ds
  205.           endm
  206.  
  207. sys_ient  macro flag
  208.           push ds        ;; protect ds
  209.           push ax        ;; protect ax
  210.           mov ax,dgroup  ;; *  establish data addressability
  211.           mov ds,ax      ;; *
  212.           sys_entr flag  ;; enter system state
  213.           sti            ;; interrupts on
  214.           sys_sctx       ;; save processor context
  215.           endm
  216.  
  217. sys_iret  macro flag
  218.           local iret1
  219.   ifndef t_astrm
  220.           extrn t_astrm:byte
  221.   endif
  222.           cli            ;; interrupts off
  223.           test byte ptr t_astrm,0FFh ;; *  test for application not terminated
  224.           jz iret1       ;; *
  225.           test flag,0FFh ;; ** test for system state interrupted
  226.           jnz iret1      ;; **
  227.           sti            ;; interrupts on
  228.           retn           ;; return to task management
  229. iret1:    sys_rctx       ;; restore processor context
  230.           iret           ;; resume interrupted task
  231.           endm
  232.  
  233. dseg      macro
  234. dgroup    group data
  235. data      segment word public 'data'
  236.           assume ds:dgroup,es:dgroup,ss:dgroup
  237.           endm
  238.  
  239. endds     macro
  240. data      ends
  241.           endm
  242.  
  243. pseg      macro
  244. pgroup    group prog
  245. prog      segment byte public 'prog'
  246.           assume cs:pgroup
  247.           endm
  248.  
  249. endps     macro
  250. prog      ends
  251.           endm
  252.  
  253.