home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 13 / 13.iso / s / s001 / 1.ddi / TS / ASM / SLICER.ASM < prev    next >
Encoding:
Assembly Source File  |  1991-03-14  |  8.3 KB  |  339 lines

  1. ;                 **************
  2. ;                 * SLICER.asm *
  3. ;               *******************************************
  4. ;               * Copyright TimeSlice, Inc. 1985, 86, 87. *
  5. ;               *******************************************
  6. ;
  7. .8087                ;enable fpc code
  8. ;
  9. include ts.inc
  10. ;
  11. start_data
  12. ;
  13. _fsw   dw  0FFFFh       ;used to check if fpc is there
  14.  
  15. extern_data    _tsfpc,word    ;FPC presence flag
  16. extern_data    _tckrst,word    ;timer tick reset counter
  17. extern_data    _tckcnt,word    ;timer tick counter
  18. extern_data    _ts_trace,word    ;trace Slicer
  19.  
  20. extern_ptr    _idleproc,d    ;pointer to TSIDLE, runs when all other task are blocked
  21. extern_ptr    _DosFlag,d    ;Is DOS interrupted
  22. extern_data    _idle,word    ;current level of critstar/critend nesting
  23. extern_data    _i13Flag,word    ;FileIO interrupted
  24. ;
  25. end_data
  26. ;
  27. extern_code    ts_main        ;to force ts_main to be present, or give error.
  28. extern_code    prout        ;to trace curproc
  29. extern_code    critstart    ;to handle critical task
  30. extern_code    critend     ;to handle critical task
  31. ;
  32. start_code
  33. ;
  34. ;*******
  35. ;* INITFPC( PTR )
  36. ;* Initialize the area pointed by PTR with current 87 regs.
  37. ;*******
  38. ;
  39. start_struct
  40. mbr    inFPCbp    d_int
  41. mbr    inFPCret    d_ret
  42. mbr    inFPCptr    d_ptr
  43. ;
  44. routine initfpc
  45.     push    bp
  46.     mov    bp,sp
  47.     push_sdi
  48.     ldptr    es,di,[bp].inFPCptr
  49.     fnsave    es:[di]
  50.     pop_sdi
  51.     pop    bp
  52. return    initfpc
  53. ;
  54. ;*******
  55. ;* SLICER()
  56. ;* Slicer() is responsible for the context switching which occurs whenever
  57. ;* the current process has expired its time slice. (A time slice is defined
  58. ;* as the number of time quantum units assigned to that process.)
  59. ;* It saves the current proc's registers (except for the SS and SP) using
  60. ;* a PUSHA instruction. The SS and SP are then copied in the process's PCB.
  61. ;* The next ready-to-run process's state is then restored by first
  62. ;* activating that process' SS and SP and then executing a POPA instruction
  63. ;* which then restores all other registers.
  64. ;* A jump to the original timer service routine is done so that nothing is
  65. ;* disturbed.
  66. ;*******
  67. public    slicer
  68. public    __gus
  69. public    __jaddr
  70. ;
  71. slicer    proc    far
  72. __gus    proc    far
  73.     pusha                ;push all registers
  74.     mov    ax,dgroup        ;activate local data segment
  75.     mov    ds,ax
  76.     mov    ah,_volguc        ;voluntary give up control???
  77.     test    ah,ah
  78.     jnz    cntxsw            ;yes, always context switch
  79.     mov    ax,_sslev        ;slicer asleep???
  80.     test    ax,ax
  81.     jz    s2
  82.     jmp    slxit            ;yes, skip context switching
  83. s2:    dec    _timcnt            ;check if switch context needed
  84.     jz    cntxsw
  85.     jmp    slxit            ;No context swich needed
  86.  
  87. cntxsw:    ldptr    es,di,curproc,d        ;set ES:DI to *curproc
  88.     mov    ax,es:[di].status
  89.  
  90.     mov    _idle,di        ;mark offset of the interrupted task
  91.  
  92.     test    ax,DOSCRIT        ;was this a Critical Task
  93.     jz    FPCtst
  94.  
  95.     ldptr    es,di,_DosFlag,d    ;Interrupt TASK in DOS ??
  96.     mov    bx, es:[di]        ;
  97.     or    bx, _i13Flag        ;or in Disk service ??
  98.     cmp    bl, 0            ;
  99.     jz    noDOS            ;No, do context switch freely
  100.  
  101.     test    ax, INDOS        ;DOS already critical
  102.     jnz    iDOS
  103.  
  104.     sub    ax, ax            ;DOS is interrupted,
  105.     push    ax            ;so do a late critstart for DOS
  106.     call    critstart
  107.     pop    ax
  108.  
  109. iDOS:    ldptr    es,di,curproc,d     ;set ES:DI to *curproc
  110.     mov    ax,es:[di].status    ;hold this special case in status
  111.     or    ax, INDOS        ;say we are in DOS
  112.     mov    es:[di].status, ax
  113.     jmp    FPCtst
  114.  
  115. noDOS:    ldptr    es,di,curproc,d     ;set ES:DI to *curproc
  116.     mov    ax,es:[di].status
  117.     test    ax, INDOS        ;Last slice left in DOS ?
  118.     jz    FPCtst
  119.     xor    ax, INDOS        ;clear the in DOS status
  120.     mov    es:[di].status, ax
  121.  
  122.     xor    ax,ax
  123.     push    ax
  124.     call    critend
  125.     pop    ax
  126.  
  127.     ldptr    es,di,curproc,d     ;set ES:DI to *curproc
  128.     mov    ax,es:[di].status
  129.  
  130. FPCtst: test    ax,SAVEFPC        ;save fpc context???
  131.     jz    noFPCsv
  132.     fnsave    es:[di].regsFPC        ;save iAPXFPC registers
  133. noFPCsv:mov    ax,ss            ;save current process stack seg
  134.     mov    es:[di].pss,ax
  135.     mov    ax,sp                  ;"    "       "       stack pointer
  136.     mov    es:[di].psp,ax
  137. s3:    mov    ax,es:[di].nxt.off    ;load curproc with curproc->nxt
  138. if ldata
  139.     mov    bx,es:[di].nxt.sgt
  140.     mov    curproc.sgt,bx
  141.     mov    es,bx
  142. endif
  143. ifndef stkset
  144.      mov    bx,ax                   ;bx will compute stk_base
  145.     add    bx,process
  146. endif
  147.     mov    curproc.off,ax
  148.     mov    di,ax            ;set ES:DI to *curproc
  149.     mov    ax,es:[di].status    ;process blocked??
  150.  
  151.     test    ax,BLOCKED
  152.     jz    rstFPC            ;Not blocked, restore FPC
  153.  
  154.     mov    ax,[_idle]
  155.     cmp    ax,di            ;Process is blocked
  156.     jnz    s3            ;if this is the process last running
  157.                     ;   then we have some idle time
  158.     ldptr    es,di,_idleproc,d    ;
  159. if ldata
  160.     mov    bx,es
  161.     mov    curproc.sgt,bx
  162. endif
  163. ifndef stkset
  164.     mov    bx,di            ;bx will compute stk_base
  165.     add    bx,process
  166. endif
  167.     mov    curproc.off,di
  168.     mov    ax,es:[di].status    ;process status
  169.  
  170. rstFPC: test    ax,SAVEFPC        ;now test process->status for 87 processing
  171.     jz    noFPCrs
  172.     frstor    es:[di].regsFPC        ;yes, restore fpc registers
  173. ifndef stkset
  174.     add    bx,94            ;add 94 byte for FPC save area to stack base
  175. endif
  176. noFPCrs:
  177. ifndef stkset
  178.         mov    stk_base, bx        ;update stack overflow marker
  179. endif
  180.     mov    ax,es:[di].pss        ;no,load ss & sp w/new curproc values
  181.     mov    ss,ax
  182.     mov    ax,es:[di].psp
  183.     mov    sp,ax
  184.  
  185.     mov    ax, _ts_trace        ;Trace slicer ?
  186.     cmp    ax, 0
  187.     je    notrac
  188.  
  189.     push    es
  190.     push    di
  191.  
  192.     mov    ax,es:[di].pname.sgt    ;
  193.     push    ax
  194.     mov    ax,es:[di].pname.off    ;
  195.     push    ax
  196.     mov    ax, 7
  197.     push    ax
  198.     sub    ax, ax
  199.     push    ax            ;prout(0,0,NORMVID, curproc->pname)
  200.     push    ax
  201.     call    prout
  202.     add    sp, 10
  203.  
  204.     pop    di
  205.     pop    es
  206.  
  207. notrac: mov    ax,es:[di].tunits    ;reload _timcnt
  208.     mov    bh,_volguc        ;load voluntary give-up-control flag
  209.     test    bh,bh            ;last process did guc() ???
  210.     je    s4            ;no
  211.     inc    ax            ;yes, add one time unit to curproc
  212.     xor    bh,bh            ;reset _volguc
  213.     mov    _volguc,bh        ;clear volguc...
  214.     mov    _timcnt,ax
  215.  
  216.     popa                ;restore all registers...
  217.     iret                ;exec nxt process
  218. ;
  219. s4:    mov    _timcnt,ax        ;set number of time units for curproc
  220. ;
  221. ;    Take care of timer ticks counter, and exiting from the slicer
  222. ;    when a regular timer interrupt occurred
  223. ;
  224. slxit:    dec    _tckcnt            ;regular timer tick???
  225.     jnz    s5            ;no: special accelerated tick
  226.     mov    ax,_tckrst        ;yes: reset tick counter to reset value
  227.     mov    _tckcnt,ax
  228.     popa                ;restore all registers
  229.     ;
  230.     db    JMPFAR            ;jump to original timer interrupt routine
  231. __jaddr:dw    0
  232.     dw    0
  233. ;
  234. ;    Take care of special accelerated timer tick
  235. ;
  236. s5:    mov    al,20h            ;issue EOI
  237.     out    20h,al
  238.     popa                ;restore all registers...
  239.     iret                ;exec nxt process
  240. __gus    endp
  241. slicer    endp
  242. ;
  243. ;
  244. ;
  245. ;*******
  246. ;* _TS_BOOT() 
  247. ;* 1) Installs the initial PCB at _base, initializes it, and reset _base.
  248. ;* 2) Copies the 4 byte interupt vector from location 0:_SLINT to CS:JADDR
  249. ;*    prior to installing the slicer.
  250. ;*******
  251. start_struct
  252. mbr    bootbp    d_int
  253. mbr    bootret    d_ret
  254. mbr    bootpp    d_ptr
  255. ;
  256. routine    _ts_boot
  257.     push    bp
  258.     mov    bp,sp
  259.     push_sdi
  260.     mov    ax,ds            ;init _datseg
  261.     mov    _datseg,ax
  262.     mov    ax,ss            ;init _stkseg
  263.     mov    _stkseg,ax
  264.     mov    ax,cs            ;init _codseg (small code only)
  265.     mov    _codseg,ax
  266. ;
  267. ;    Check for presence of fpc
  268. ;
  269.     fninit                ;initialize fpc
  270.     fnstsw    _fsw            ;get its status word
  271.     mov    cx,100h            ;delay while 87 works on its own
  272. delay:    loop    delay            
  273.     mov    ax,_fsw
  274.     and    ax,0B8BFh        ;if fpc, these are reset
  275.     jnz    noFPC
  276.     inc    byte ptr _tsfpc        ;mark that fpc is here
  277. noFPC:
  278. ;
  279. ;    set initial PCB at STK_BASE
  280. ;
  281.     ldptr    es,ax,[bp].bootpp,d    ;base of regular stack
  282.     mov    di,ax            ;init boot process to itself
  283.     mov    es:[di].nxt.off,ax    ;point to itself (only proc at start)
  284.     mov    ax,es
  285.     mov    es:[di].nxt.sgt,ax
  286.     xor    ax,ax
  287.     stptrr    es:[di].crnxt,ax,ax    ;not on critical list
  288.     ldint    es:[di].tunits,1
  289.     ldint    es:[di].status,READY
  290.     mov    curproc.off,di
  291. if ldata
  292.     mov    bx,es
  293.     mov    curproc.sgt,bx
  294. endif
  295. ;
  296. ;    attach slicer to interrupt # _slint
  297. ;
  298.     cli                ;set timer interrupt to slicer
  299.     mov    ax,_slint        ;ax <-- interrupt of slicer
  300.     mov    cl,2
  301.     shl    ax,cl            ;ax <-- offset of slicer's IntVector
  302.     mov    si,ax            ;si <-- slicer's Int Vector
  303.     push    ds            ;save local data segment
  304.     xor    ax,ax            ;so that we can address the interrupt
  305.     mov    ds,ax            ;table located at 0:0
  306.     mov    ax,[si]            ;ax <-- slicer's Intrpt original offset
  307.     mov    bx,offset __jaddr
  308.     mov    cx,seg __jaddr
  309.     mov    es,cx
  310.     mov    es:[bx],ax        ;save original routine's offset...
  311.     mov    ax,[si+2]        ;ax <-- slicer's Intrpt original segment
  312.     add    bx,2
  313.     mov    es:[bx],ax        ;and code segment so that we can jmp to it
  314. ;
  315. ;
  316.     mov    ax,offset slicer    ;install slicer in interrupt table
  317.     mov    [si],ax
  318.     mov    ax,seg slicer
  319.     mov    [si+2],ax
  320.     pop    ds            ;restore local data segment
  321.     mov    ax,ds
  322.     mov    es,ax
  323.     sti
  324.     pop_sdi
  325.     pop    bp
  326. return    _ts_boot
  327. ;
  328. ;
  329. public _inDos_ptr
  330. _inDos_ptr proc far
  331.        mov    ah, 34h
  332.        int    21h
  333.        mov    ax, bx
  334.        mov    dx, es
  335.        ret
  336. _inDos_ptr endp
  337.  
  338. end_code
  339.