home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DP Tool Club 19
/
CD_ASCQ_19_010295.iso
/
dos
/
prg
/
noyau
/
dispatch.asm
< prev
next >
Wrap
Assembly Source File
|
1994-05-25
|
4KB
|
182 lines
;
;
; DISPATCHER / ELIGIBLE / P / V
;
;
; ART OF CODE 1994
;
;
; Dispatch.asm
;
PAGE 60,132
TITLE TP ASSEMBLEUR / SE N°2
.MODEL SMALL,OS_DOS
.286
INCLUDE gestlist.inc ; importe les fonctions de gestion de liste
INCLUDE descript.inc ; définition du type DESCRIPTEUR
INCLUDE queue.inc ; définition du type QUEUE
INCLUDE etats.inc
INCLUDE types.inc
INCLUDE semphor.inc
INCLUDE process.inc
INCLUDE donnees.inc
INCLUDE code.inc
.CODE
;
; PROCEDURE DISPATCHER
;
;
DISPATCHER PROC NEAR
assume ds:@data
pushf
cli ; masquage des interruptions
push es
push ds
pusha
mov ax,@data ; au cas où ....
mov ds,ax
cmp NonPreemptif,0 ; test si noyau non preemptif
jne fin_dispatch ; si oui on demasque et on quitte
mov bx,[EnCours]
mov si,[QueueExp]
cmp (DESCRIPTEUR PTR [bx]).etat,ACTIF
jne Change_EnCours ; si EnCours pas actif -> on rend le processus le plus prioritaire actif
; sinon
mov di,si ; di pointe sur la cellule de garde
mov di,(DESCRIPTEUR PTR [di]).suivant ; di pointe sur le descripteur le plus prioritaire
mov al,(DESCRIPTEUR PTR [bx]).priorite
cmp al,(DESCRIPTEUR PTR [di]).priorite
jbe fin_dispatch ; si Encours est le plus prioritaire on ne fait rien
; sinon on réalise la transition ACTIF - > PRET
call ELIGIBLE ; On place EnCours dans la queue d'exploitation
; Puis, le premier de la queue d'exploitation devient
; le processus EnCours
Change_EnCours:
mov (PROCESSUS PTR [bx]).Reg_SS,ss ; on sauvegarde la pile privée
mov (PROCESSUS PTR [bx]).Reg_SP,sp ; du programme EnCours
call PremierDeListe ; DS:BX= ptr sur l'EnCours nouveau
mov [EnCours],bx
mov ss,(PROCESSUS PTR [bx]).Reg_SS ; on retablit la pile privée
mov sp,(PROCESSUS PTR [bx]).Reg_SP ; du programme EnCours
mov (DESCRIPTEUR PTR [bx]).etat,ACTIF ; on le rend ACTIF
mov (PROCESSUS PTR [bx]).file,0
fin_dispatch:
popa
pop ds
pop es
popf
ret
DISPATCHER ENDP
;
; PROCEDURE ELIGIBLE
;
; Réalise la transition ??? -> PRET
;
; Entrée : DS:BX pointe sur le DdP à inserer
;
ELIGIBLE PROC NEAR
assume ds:@data
push si
mov si,[QueueExp]
mov (DESCRIPTEUR PTR [bx]).etat,PRET
mov (PROCESSUS PTR [bx]).file,si
CALL INSERE ; On insere le DdP à sa place.
pop si
ret
ELIGIBLE ENDP
;
; PROCEDURE P - Wait ( sémaphore s )
;
; Entrée : (DS:SI) = pointeur sur le sémaphore s
;
P PROC NEAR
assume ds:@data
pushf
cli
push bx
push ds
mov bx,@data
mov ds,bx
cmp (SEMAPHORE PTR[si]).Compteur,0 ; compteur nul ?
je Extraction ; oui, on bloque
dec (SEMAPHORE PTR [si]).Compteur ; sinon, cpt = cpt - 1
jmp Fin_Wait
Extraction:
mov bx,[EnCours]
mov (DESCRIPTEUR PTR [bx]).Etat,BLOQUE
call empiler
mov (PROCESSUS PTR [bx]).file,si
Fin_Wait:
pop ds
pop bx
popf ; rétablit l'ancien registre d'état ( voire les interruptions )
call DISPATCHER
ret
P ENDP
;
; PROCEDURE V - Signal( sémaphore s )
;
; Entrée : (DS:SI) = pointeur sur le sémaphore s
;
V PROC NEAR
assume ds:@data
pushf
cli
push si
push bx
push ds
mov bx,@data
mov ds,bx
call FileVide ; La file d'attente du sémaphore est elle vide ?
jne Sema_non_vide
; oui ! On augmente la valeur du sémaphore
inc (SEMAPHORE PTR [si]).Compteur
jmp Fin_Signal
Sema_non_vide:
call DernierDeListe ; on extrait un DdP de la file d'attente
call Eligible ; dans la queue d'exploitation
Fin_Signal:
pop ds
pop bx
pop si
popf
Call Dispatcher
ret
V ENDP
END