{"id":336,"date":"2012-01-03T22:54:04","date_gmt":"2012-01-04T04:54:04","guid":{"rendered":"http:\/\/tommysprinkle.com\/txxos\/?p=336"},"modified":"2021-04-17T18:23:21","modified_gmt":"2021-04-17T23:23:21","slug":"dispatcher-2","status":"publish","type":"post","link":"https:\/\/tommysprinkle.com\/txxos\/?p=336","title":{"rendered":"TXXDISP &#8211; Dispatcher Routine"},"content":{"rendered":"<p>The Dispatcher looks at the list of TCB&#8217;s on the work queue and selects one to become the active task. \u00a0If there are no TCB&#8217;s ready to dispatch an enabled wait will be entered.<\/p>\n<pre>000000                                6 TXXDISP  CSECT ,\r\n000000 18CF                           7          LR    R12,R15            ESTABLISH\r\n                            00000     8          USING TXXDISP,R12                 BASE REG\r\n                                      9 *\r\n000002 1F11                          10          SLR   R1,R1              CLEAR TIME EXPIRED SWITCH\r\n                                     11 *\r\n000004 58B0 0010      00010          12          L     R11,16             GET CVT ADDRESS\r\n                            00000    13          USING @CVT,R11\r\n                                     14 *\r\n000008 5840 B004      00004          15          L     R4,CVTTASKQ        START AT TOP OF TASK QUEUE\r\n                                     16 *\r\n                            00000    17          USING @TCB,R4\r\n                                     18 *\r\n00000C                               19 DISP010  DS    0H\r\n00000C 91D0 4004      00004          20          TM    TCBFLGS,TCBFWAIT+TCBFNDSP+TCBFETS  DISPATCHABLE?\r\n000010 4780 C05C      0005C          21          BZ    DISP050             YES - GO RUN IT\r\n                                     22 *\r\n000014 9110 4004      00004          23          TM    TCBFLGS,TCBFETS    TIME EXPIRED FOR THIS TASK?\r\n000018 47E0 C020      00020          24          BNO   DISP020            NO - BRANCH\r\n                                     25 *\r\n00001C 4110 0001      00001          26          LA    R1,1               SET EXPIRED SWITCH\r\n000020                               27 DISP020  DS    0H\r\n000020 5840 4000      00000          28          L     R4,TCBNEXT         POINT TO NEXT TCB\r\n000024 1244                          29          LTR   R4,R4              END OF CHAIN\r\n000026 4770 C00C      0000C          30          BNZ   DISP010            LOOP BACK\r\n                                     31 *\r\n00002A 1211                          32          LTR   R1,R1              ANY TIME EXPIRED TASKS\r\n00002C 4780 C06A      0006A          33          BZ    DISP060              NO - GO INTO WAIT<\/pre>\n<p>The Dispatcher starts at the top of the TCB queue. \u00a0It looks for a TCB that is\u00a0eligible\u00a0to be dispatched. \u00a0If a TCB is found it becomes the current TCB and control is passed to that task. \u00a0While scanning the queue a switch is set if any TCB on the queue is not dispatchable because it was interrupted by the timer task. \u00a0If no any TCB&#8217;s were found that were not dispatched because of the time exceeded flag, the dispatcher will clear these bits and allows the TCB&#8217;s to be dispatched.<\/p>\n<pre>000030 5840 B004      00004          35          L     R4,CVTTASKQ        LOAD TOP OF TASK QUEUE\r\n000034                               36 DISP030  DS    0H\r\n000034 94FE 4004      00004          37          NI    TCBFLGS,X'FF'-TCBFLONG  CLEAR LONG RUNNING FLAG\r\n                                     38 *\r\n000038 9110 4004      00004          39          TM    TCBFLGS,TCBFETS    TIME EXPIRED FOR THIS TASK?\r\n00003C 47E0 C048      00048          40          BNO   DISP040            NO - BRANCH\r\n                                     41 *\r\n000040 94EF 4004      00004          42          NI    TCBFLGS,X'FF'-TCBFETS    CLEAR FLAG\r\n000044 9601 4004      00004          43          OI    TCBFLGS,TCBFLONG         SET LONG RUNNING FLAG\r\n                                     44 *\r\n000048                               45 DISP040  DS    0H\r\n000048 5840 4000      00000          46          L     R4,TCBNEXT               NEXT TCB ON CHAIN\r\n00004C 1244                          47          LTR   R4,R4                    END OF CHAIN\r\n00004E 4770 C034      00034          48          BNZ   DISP030                   NO - LOOP BACK\r\n                                     49 *\r\n000052 5840 B004      00004          50          L     R4,CVTTASKQ              POINT TO TOP OF QUEUE\r\n000056 1F11                          51          SLR   R1,R1                    CLEAR SWITCH\r\n000058 47F0 C020      00020          52          B     DISP020                  LOOK AGAIN FOR WORK<\/pre>\n<p>Here the Dispatcher loops through the TCB queue resetting time exceeded bit. \u00a0If the TCBFETS flag is reset in a TCB, the TCBFLONG bit is set. \u00a0This bit will not make the task non-dispatchable. \u00a0It only indicates the TCB had previously been prohibited from dispatch. \u00a0Once the entire queue has been scanned the main dispatcher loop is once again entered to select a task for dispatch.<\/p>\n<pre>00005C                               58 DISP050  DS    0H\r\n00005C 5040 B000      00000          59          ST    R4,CVTCTCB\r\n000060 58F0 0014      00014          60          L     R15,20                   MVT ADDRESS\r\n000064 58F0 F008      00008          61          L     R15,MVTLLDSP-@MVT(,R15)  LLDISP ROUTINE\r\n000068 07FF                          62          BR    R15<\/pre>\n<p>Once a TCB is selected for dispatch the address of the TCB is stored in the CVT at CVTCTCB \u00a0(current TCB). \u00a0Control is then passed the the Low Core Dispatch routine in low memory to restore the registers and PSW from the TCB.<\/p>\n<pre>00006A                               68 DISP060  DS    0H\r\n00006A 5840 B004      00004          69          L     R4,CVTTASKQ              WAIT TASK\r\n00006E 5040 B000      00000          70          ST    R4,CVTCTCB                 MAKE IT CURRENT TASK\r\n000072 8200 C078      00078          71          LPSW  DISPWPSW           ENABLED WAIT\r\n000078                               75          DS    0D\r\n000078 FF0200000000FEAD              76 DISPWPSW DC    AL1(255,2,0,0),A(X'FEAD')  ENABLED WAIT PSW<\/pre>\n<p>If no TCB is\u00a0available\u00a0for dispatch the dummy Wait Task TCB is made the current TCB and an enabled wait is entered. \u00a0The dummy Wait Task TCB is needed so that when an interruption occurs while in the disabled wait there will be a TCB for the interrupt handler to store registers and the PSW. \u00a0Although this information is saved at the interrupt, it is never used since the Wait Task is always associated with the enabled wait PSW.<\/p>\n<p>[Next &#8211; <a title=\"TXXDINIT \u2013 Dispatcher Initialization\" href=\"http:\/\/tommysprinkle.com\/txxos\/?p=339\">TXXDINIT &#8211; Dispatcher Initialization<\/a>\u00a0]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Dispatcher looks at the list of TCB&#8217;s on the work queue and selects one to become the active task. \u00a0If there are no TCB&#8217;s ready to dispatch an enabled wait will be entered. 000000 6 TXXDISP CSECT , 000000 &hellip; <a href=\"https:\/\/tommysprinkle.com\/txxos\/?p=336\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"template-page-builder-no-sidebar.php","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1],"tags":[],"class_list":["post-336","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p1CPQT-5q","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/tommysprinkle.com\/txxos\/index.php?rest_route=\/wp\/v2\/posts\/336","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tommysprinkle.com\/txxos\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tommysprinkle.com\/txxos\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tommysprinkle.com\/txxos\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tommysprinkle.com\/txxos\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=336"}],"version-history":[{"count":5,"href":"https:\/\/tommysprinkle.com\/txxos\/index.php?rest_route=\/wp\/v2\/posts\/336\/revisions"}],"predecessor-version":[{"id":483,"href":"https:\/\/tommysprinkle.com\/txxos\/index.php?rest_route=\/wp\/v2\/posts\/336\/revisions\/483"}],"wp:attachment":[{"href":"https:\/\/tommysprinkle.com\/txxos\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=336"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tommysprinkle.com\/txxos\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=336"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tommysprinkle.com\/txxos\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=336"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}