{"id":344,"date":"2012-01-07T10:16:55","date_gmt":"2012-01-07T16:16:55","guid":{"rendered":"http:\/\/tommysprinkle.com\/txxos\/?p=344"},"modified":"2021-04-17T18:22:47","modified_gmt":"2021-04-17T23:22:47","slug":"exit-routine","status":"publish","type":"post","link":"https:\/\/tommysprinkle.com\/txxos\/?p=344","title":{"rendered":"TXXEXIT &#8211; Exit Routine"},"content":{"rendered":"<p>The Exit Routine terminates the top level RB and makes the next RB on the stack active. \u00a0If there are no more RB&#8217;s on the stack then the TCB is terminated.<\/p>\n<pre>000000                                9 TXXEXIT  CSECT ,\r\n000000 18CF                          10          LR    R12,R15\r\n                            00000    11          USING TXXEXIT,R12\r\n                                     12 *\r\n000002 8000 C0C8      000C8          13          SSM   =X'00'             DISABLE INTERRUPTS\r\n                                     14 *\r\n000006 5840 0010      00010          15          L     R4,16              CVT ADDRESS\r\n00000A 5840 4000      00000          16          L     R4,CVTCTCB-@CVT(,R4)  GET TCB ADDRESS\r\n00000E 5850 4008      00008          17          L     R5,TCBRB-@TCB(,R4)    GET RB  ADDRESS\r\n                                     18 *\r\n                            00000    19          USING @TCB,R4\r\n                            00000    20          USING @RB,R5\r\n                                     21 *\r\n000012 1255                          22          LTR   R5,R5              ANY RB\r\n000014 4780 C068      00068          23          BZ    XTCB                NO - TERMINATE TCB<\/pre>\n<p>Interrupts are disabled before any additional processing is done. \u00a0Since we will be modifying RB and TCB chains we don&#8217;t want the Dispatcher trying to dispatch a TCB we are modifying. \u00a0By disabling interrupts we know the Dispatcher will not gain control through an interrupt caused by the Interval Timer or and I\/O interrupt. \u00a0We next get the current TCB address and the top level RB address. \u00a0If for some reason there is no RB we terminate the TCB.<\/p>\n<pre>000018 D23F 4020 5010 00020 00010    25          MVC   TCBREGS(64),RBREGS  COPY RB REGS TO TCB\r\n00001E D207 4018 5008 00018 00008    26          MVC   TCBPSW(8),RBPSW     COPY RB PSW  TO TCB\r\n000024 5810 5000      00000          27          L     R1,RBNEXT           NEXT RB ON CHAIN\r\n000028 5010 4008      00008          28          ST    R1,TCBRB            UNCHAIN RB\r\n                                     29 *\r\n00002C 4110 0050      00050          30          LA    R1,RBLEN            LENGTH OF RB\r\n000030 BF18 C0C9      000C9          31          ICM   R1,B'1000',=AL1(128)   SP=128\r\n000034 1805                          32          LR    R0,R5                  RB ADDRESS TO FREE\r\n                                     33          @CALL FREEMAIN               FREE STORAGE\r\n000036 58F0 0014      00014          34+         L     R15,20             MVT ADDRESS\r\n00003A 58F0 F01C      0001C          35+         L     R15,MVTFMAIN-@MVT(,R15) ROUTINE ADDRESS\r\n00003E 05EF                          36+         BALR  R14,R15<\/pre>\n<p>We unchain the top level RB by taking the forward pointer in the RB and storing it in the TCB. \u00a0Now that the RB is off the chain we can free the storage associated with it.<\/p>\n<pre>000040 5850 4008      00008          38          L     R5,TCBRB            GET NEW CURRENT RB ADDRESS\r\n000044 1255                          39          LTR   R5,R5               ANY RB\r\n000046 4780 C068      00068          40          BZ    XTCB                NO - TERMINATE TCB\r\n                                     41 *\r\n00004A 9500 5004      00004          42          CLI   RBWTCNT,0           IS RB WAITING\r\n00004E 4780 C05A      0005A          43          BE    EXIT010              NO - BRANCH\r\n                                     44 *\r\n000052 9680 4004      00004          45          OI    TCBFLGS,TCBFWAIT    SET WAIT BIT\r\n000056 47F0 C05E      0005E          46          B     EXIT020\r\n                                     48 *\r\n00005A                               49 EXIT010  DS    0H\r\n00005A 947F 4004      00004          50          NI    TCBFLGS,X'FF'-TCBFWAIT  CLEAR WAIT BIT\r\n00005E                               51 EXIT020  DS    0H\r\n00005E 58F0 0014      00014          52          L     R15,20              MVT ADDRESS\r\n000062 58F0 F004      00004          53          L     R15,MVTDISP-@MVT(,R15)   DISPATCHER ENTRY\r\n000066 07FF                          54          BR    R15                 GO TO DISPATCHER<\/pre>\n<p>Next we get the new top level RB address. \u00a0If we just removed the last RB for the TCB this pointer will be null and we need to terminate the TCB. \u00a0If there is a top level RB we propagate the wait status of the RB to the TCB. \u00a0If the RB wait count is not zero the TCB wait flag is set. \u00a0If the RB wait count is zero the TCB wait flag is cleared. \u00a0Control is then\u00a0transferred\u00a0to the Dispatcher to select the next task to dispatch.<\/p>\n<pre>000068                               57 XTCB     DS    0H\r\n000068 5810 0010      00010          58          L     R1,16              CVT ADDRESS\r\n00006C 5810 1004      00004          59          L     R1,CVTTASKQ-@CVT(,R1)   TOP OF TASK QUEUE\r\n                                     60 *\r\n000070                               61 XTCB010  DS    0H\r\n000070 5820 1000      00000          62          L     R2,0(,R1)          POINT TO NEXT TCB\r\n000074 1222                          63          LTR   R2,R2              END OF CHAIN ?\r\n000076 4780 C0B8      000B8          64          BZ    XTCB900            SHOULD NOT HAPPEN - CAN'T FIND TCB\r\n                                     65 *\r\n00007A 1924                          66          CR    R2,R4              IS THIS OUR TCB\r\n00007C 4780 C086      00086          67          BE    XTCB020              YES - BRANCH\r\n                                     68 *\r\n000080 1812                          69          LR    R1,R2              CHECK NEXT\r\n000082 47F0 C070      00070          70          B     XTCB010                      TCB<\/pre>\n<p>This routine terminates the TCB when no RB&#8217;s are left. \u00a0First the the TCB chain is searched to locate the TCB that points to the TCB we are terminating. \u00a0We need this TCB address so we can unchain the terminating TCB.<\/p>\n<pre>000086                               73 XTCB020  DS    0H\r\n000086 5830 2000      00000          74          L     R3,0(,R2)          UNCHAIN THIS\r\n00008A 5030 1000      00000          75          ST    R3,0(,R1)                     TCB FROM QUEUE\r\n                                     76 *\r\n00008E 58B0 0010      00010          77          L     R11,16             CVT\r\n000092 5810 B004      00004          78          L     R1,CVTTASKQ-@CVT(,R11)   TOP OF QUEUE (WAIT TASK)\r\n000096 5010 B000      00000          79          ST    R1,CVTCTCB-@CVT(,R11)    MAKE CURRENT TASK\r\n                                     80 *\r\n00009A 4110 0060      00060          81          LA    R1,TCBLEN          LENGTH OF TCB\r\n00009E BF18 C0C9      000C9          82          ICM   R1,B'1000',=AL1(128)   SP=128\r\n0000A2 1804                          83          LR    R0,R4                  ADDRESS OF TCB TO FREE\r\n                                     84          @CALL FREEMAIN\r\n0000A4 58F0 0014      00014          85+         L     R15,20             MVT ADDRESS\r\n0000A8 58F0 F01C      0001C          86+         L     R15,MVTFMAIN-@MVT(,R15) ROUTINE ADDRESS\r\n0000AC 05EF                          87+         BALR  R14,R15\r\n                                     88 *\r\n0000AE 58F0 0014      00014          89          L     R15,20             MVT ADDRESS\r\n0000B2 58F0 F004      00004          90          L     R15,MVTDISP-@MVT(,R15)   DISPATCHER\r\n0000B6 07FF                          91          BR    R15<\/pre>\n<p>The TCB is removed from the chain and the Wait Task is made the current task. \u00a0This is necessary so the current task pointer will point to a valid TCB. \u00a0Now the TCB storage is freed and control is passed to the Dispatcher.<\/p>\n<pre>0000B8                               95 XTCB900  DS    0H\r\n0000B8 8200 C0C0      000C0          96          LPSW  XTCBPSW\r\n                                     97 *\r\n0000C0                               98          DS    0D\r\n0000C0 0002000000EE0005              99 XTCBPSW  DC    AL1(0,2,0,0),A(@E@EXIT)<\/pre>\n<p>If the terminating TCB is not found on the TCB chain an \u00a0unrecoverable error has\u00a0occurred\u00a0and a wait state PSW is loaded.<\/p>\n<p>[Next &#8211; <a title=\"SVC 3 \u2013 Exit\" href=\"http:\/\/tommysprinkle.com\/txxos\/?p=346\">SVC 3 &#8211; Exit<\/a>]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Exit Routine terminates the top level RB and makes the next RB on the stack active. \u00a0If there are no more RB&#8217;s on the stack then the TCB is terminated. 000000 9 TXXEXIT CSECT , 000000 18CF 10 LR &hellip; <a href=\"https:\/\/tommysprinkle.com\/txxos\/?p=344\">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-344","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p1CPQT-5y","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/tommysprinkle.com\/txxos\/index.php?rest_route=\/wp\/v2\/posts\/344","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=344"}],"version-history":[{"count":4,"href":"https:\/\/tommysprinkle.com\/txxos\/index.php?rest_route=\/wp\/v2\/posts\/344\/revisions"}],"predecessor-version":[{"id":480,"href":"https:\/\/tommysprinkle.com\/txxos\/index.php?rest_route=\/wp\/v2\/posts\/344\/revisions\/480"}],"wp:attachment":[{"href":"https:\/\/tommysprinkle.com\/txxos\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=344"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tommysprinkle.com\/txxos\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=344"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tommysprinkle.com\/txxos\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=344"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}