
111/119 06 Nov 91 01:11:19
From:   John Lobraico
To:     All
Subj:   multitasking O.S.
Attr:   
------------------------------------------------
Hello Everyone,

 I've noticed your interest in Jon Guthries 'SIRIUS' and thought I'd share some 
of my O.S. with you. I've recently changed my 'CALL DISPATCHER to an INT 28H so 
the task saves its CS,IP & flags on the call followed by DISPATCHER saving 
everything else.
 I made Job 0 do a TSR call after ten seconds and set the timer int to check 
for DOS running (Job 0) and do an int 28h on DOS's behalf. So now my O.S. can 
run all it's tasks and run/suspend a DOS job at the same time.
 The system is set up for non-preemptive execution (except DOS) where the 
running task calls int 28h whenever it's in a wait for event loop or any other 
time the programmer wants to break temporarily to the O.S.
 I've used the system for a fire alarm system running 12 riser controller 
jobs,2 tty_tx jobs,2 tty_rx jobs, 2 talk_trm jobs,a spooler and a talk_central 
job. I've also done a central control job that talks to n buildings and gets 
the picture and provides a link to each buildings talk_terminal routine. 
 I had a good debugging trick where the processor would put itself into trap 
mode and then print every IP address that it executed. 
 Anyway here's a piece and I'll look forward to hearing any questions,comments 
or commercial enquiries.

    John L
;-----------------------------------------------------------------------------
DISPATCHER2 PROC FAR
; INT 28h to invoke DISPATCHER
; saves flags + CS + IP
  PUSH AX  ;push jobs state to stack frame
  PUSH BX
  PUSH CX
  PUSH DX
  PUSH DI
  PUSH SI
  PUSH BP
  PUSH DS
  PUSH ES
;
  MOV AX,DATA
  MOV DS,AX  ;make sure DS is correct
  INC IN_DISPATCH 
  STI  ;allow new ints
  MOV BX,CURRENT_JOB
  ADD BX,BX  ;*2 for word table
  MOV [JOB_SP+BX],SP ;save jobs SP
;
  MOV AX,SS
  MOV [JOB_SS+BX],AX ;save jobs SS
;
;Check from CURRENT_JOB on and run those JOBS at 0 priority
DISPATCH_JOB: MOV BX,CURRENT_JOB
  INC BX  ;current job includes 0 
DISPATCH_INI: LEA DI,JOB_PRIORITY
DISPATCH_INI_1: CMP BX,NUMJOBS ;if = start with Job 0 again
  JNE CHECK_SUSPEND ;clr BX for new run through list
  SUB BX,BX  ;set to JOB 0
CHECK_SUSPEND: TEST [JOB_STATUS+BX],00000001B
  JNE SUSPENDED
CHECK_RUN: CMP BYTE PTR [BX+DI],0 ;is next job scheduled to run now?
  JE RUN_JOB_BX
  DEC BYTE PTR [BX+DI] ;age the job that didn't run
  INC  BX ;else check next job for 0 priority to run
  JMP DISPATCH_INI_1
ASLEEP:  DEC WORD PTR [BX+JOB_SLEEP] ;age sleeping job
  SHR BX,1
  INC  BX ;else check next job for 0 priority to run
  JMP DISPATCH_INI_1
SUSPENDED: INC  BX ;else check next job for 0 priority to run
  JMP DISPATCH_INI_1
RUN_JOB_BX: SHL BX,1 ;address word table
  CMP WORD PTR [BX+JOB_SLEEP],0 ;is job sleeping?
  JNE ASLEEP
  SHR BX,1
  MOV CURRENT_JOB,BX ;Save current job # before running
  MOV AL,[BX+JOB_INI_PRIORITY] ;get jobs initial priority
  MOV [BX+JOB_PRIORITY],AL ;put it in the changing priority
  SHL BX,1  ;*2 for word table
  MOV AX,[BX+JOB_SS]  ;restore SS
  CLI
  MOV SS,AX
  MOV SP,[BX+JOB_SP] ;get jobs stack pointer value
  DEC IN_DISPATCH
  POP ES
  POP DS
  POP BP
  POP SI
  POP DI
  POP DX
  POP CX
  POP BX
  POP AX
  IRET  ;RETURN to next TASK 
DISPATCHER2 ENDP
;-----------------------------------------------------------------------------

--- Maximus-CBCS v1.02
 * Origin: SHERIDAN College BBS (1:259/303)

