home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 19 / CD_ASCQ_19_010295.iso / dos / prg / noyau / dispatch.asm < prev    next >
Assembly Source File  |  1994-05-25  |  4KB  |  182 lines

  1. ;
  2. ;
  3. ;        DISPATCHER / ELIGIBLE / P / V
  4. ;
  5. ;
  6. ; ART OF CODE 1994
  7. ;
  8. ;
  9. ; Dispatch.asm
  10. ;
  11.  
  12. PAGE 60,132
  13. TITLE TP ASSEMBLEUR / SE N°2
  14.  
  15. .MODEL SMALL,OS_DOS
  16. .286
  17.  
  18. INCLUDE gestlist.inc    ; importe les fonctions de gestion de liste
  19. INCLUDE descript.inc    ; définition du type DESCRIPTEUR
  20. INCLUDE queue.inc       ; définition du type QUEUE
  21. INCLUDE etats.inc
  22. INCLUDE types.inc
  23. INCLUDE semphor.inc
  24. INCLUDE process.inc
  25. INCLUDE donnees.inc
  26. INCLUDE code.inc
  27.  
  28.  
  29.  
  30. .CODE
  31.  
  32.  
  33. ;
  34. ;           PROCEDURE DISPATCHER
  35. ;
  36. ;
  37.  
  38. DISPATCHER PROC NEAR
  39.     assume ds:@data
  40.     pushf
  41.     cli                     ; masquage des interruptions
  42.     push es
  43.     push ds
  44.     pusha
  45.  
  46.     mov ax,@data      ; au cas où ....
  47.     mov ds,ax
  48.  
  49.     cmp NonPreemptif,0    ; test si noyau non preemptif
  50.     jne fin_dispatch        ; si oui on demasque et on quitte
  51.  
  52.     mov bx,[EnCours]
  53.     mov si,[QueueExp]
  54.     cmp (DESCRIPTEUR PTR [bx]).etat,ACTIF
  55.     jne Change_EnCours    ; si EnCours pas actif -> on rend le processus le plus prioritaire actif
  56.  
  57.     ; sinon
  58.  
  59.     mov di,si                  ; di pointe sur la cellule de garde
  60.     mov di,(DESCRIPTEUR PTR [di]).suivant ; di pointe sur le descripteur le plus prioritaire
  61.     mov al,(DESCRIPTEUR PTR [bx]).priorite
  62.     cmp al,(DESCRIPTEUR PTR [di]).priorite
  63.     jbe fin_dispatch     ; si Encours est le plus prioritaire on ne fait rien
  64.  
  65.     ; sinon on réalise la transition ACTIF - > PRET
  66.     call ELIGIBLE ; On place EnCours dans la queue d'exploitation
  67.           ; Puis, le premier de la queue d'exploitation devient
  68.           ; le processus EnCours
  69. Change_EnCours:
  70.  
  71.  
  72.     mov (PROCESSUS PTR [bx]).Reg_SS,ss ; on sauvegarde la pile privée
  73.     mov (PROCESSUS PTR [bx]).Reg_SP,sp ; du programme EnCours
  74.     
  75.     call PremierDeListe ; DS:BX= ptr sur l'EnCours nouveau
  76.     mov  [EnCours],bx
  77.     mov ss,(PROCESSUS PTR [bx]).Reg_SS ; on retablit la pile privée
  78.     mov sp,(PROCESSUS PTR [bx]).Reg_SP ; du programme EnCours
  79.     mov (DESCRIPTEUR PTR [bx]).etat,ACTIF   ; on le rend ACTIF
  80.     mov (PROCESSUS PTR [bx]).file,0
  81.  
  82. fin_dispatch:
  83.     popa
  84.     pop ds
  85.     pop es
  86.     popf
  87.     ret
  88. DISPATCHER ENDP
  89.  
  90.  
  91. ;
  92. ;              PROCEDURE ELIGIBLE
  93. ;
  94. ;           Réalise la transition ??? -> PRET
  95. ;
  96. ;       Entrée : DS:BX pointe sur le DdP à inserer
  97. ;
  98.  
  99. ELIGIBLE PROC NEAR
  100.     assume ds:@data
  101.     push si
  102.     mov si,[QueueExp]
  103.     mov (DESCRIPTEUR PTR [bx]).etat,PRET
  104.     mov (PROCESSUS PTR [bx]).file,si
  105.     CALL INSERE         ; On insere le DdP à sa place.
  106.     pop si
  107.     ret
  108. ELIGIBLE ENDP
  109.  
  110.  
  111. ;
  112. ;         PROCEDURE P - Wait ( sémaphore s )
  113. ;
  114. ;   Entrée : (DS:SI) = pointeur sur le sémaphore s
  115. ;
  116.  
  117. P PROC NEAR
  118.     assume ds:@data
  119.  
  120.     pushf
  121.     cli
  122.     push bx
  123.     push ds
  124.  
  125.     mov bx,@data
  126.     mov ds,bx
  127.  
  128.     cmp (SEMAPHORE PTR[si]).Compteur,0    ; compteur nul ?
  129.     je    Extraction            ; oui, on bloque
  130.     dec (SEMAPHORE PTR [si]).Compteur    ; sinon, cpt = cpt - 1
  131.     jmp Fin_Wait
  132. Extraction:
  133.     mov bx,[EnCours]
  134.     mov (DESCRIPTEUR PTR [bx]).Etat,BLOQUE
  135.     call empiler
  136.     mov (PROCESSUS PTR [bx]).file,si
  137. Fin_Wait:
  138.     pop ds
  139.     pop bx
  140.     popf    ; rétablit l'ancien registre d'état ( voire les interruptions )
  141.     call DISPATCHER
  142.     ret
  143. P ENDP
  144.  
  145.  
  146. ;
  147. ;         PROCEDURE V - Signal( sémaphore s )
  148. ;
  149. ;   Entrée : (DS:SI) = pointeur sur le sémaphore s
  150. ;
  151.  
  152. V PROC NEAR
  153.     assume ds:@data
  154.  
  155.     pushf
  156.     cli
  157.     push si
  158.     push bx
  159.     push ds
  160.  
  161.     mov bx,@data
  162.     mov ds,bx
  163.     call FileVide   ; La file d'attente du sémaphore est elle vide ?
  164.     jne  Sema_non_vide
  165.             ; oui ! On augmente la valeur du sémaphore
  166.     inc (SEMAPHORE PTR [si]).Compteur
  167.     jmp Fin_Signal
  168. Sema_non_vide:
  169.     call DernierDeListe    ; on extrait un DdP de la file d'attente
  170.     call Eligible    ; dans la queue d'exploitation
  171.  
  172. Fin_Signal:
  173.     pop ds
  174.     pop bx
  175.     pop si
  176.     popf
  177.     Call Dispatcher
  178.     ret
  179. V ENDP
  180.  
  181. END
  182.