{"id":207,"date":"2011-12-01T18:16:55","date_gmt":"2011-12-02T00:16:55","guid":{"rendered":"http:\/\/tommysprinkle.com\/txxos\/?p=207"},"modified":"2021-04-17T18:26:31","modified_gmt":"2021-04-17T23:26:31","slug":"disk-io-subroutine","status":"publish","type":"post","link":"https:\/\/tommysprinkle.com\/txxos\/?p=207","title":{"rendered":"DISK I\/O Subroutine"},"content":{"rendered":"<p>Now that we have successfully managed to read from a DASD device we can build a general purpose subroutine to perform I\/O. \u00a0We will create a control block to communicate with the I\/O routine. \u00a0The control block will be called I\/O Request (IOR).<\/p>\n<pre>IOR      DSECT ,\r\nIORCCW   DS    A             ADDRESS OF CCW\r\nIORUNIT  DS    XL2           DEVICE ADDRESS\r\nIORSIOCC DS    X             SIO CONDITION CODE\r\n         DS    X\r\nIORCSW   DS    XL8           CHANNEL STATUS WORD\r\nIORSENS0 DS    X             SENSE BYTE 0\r\nIORSENS1 DS    X             SENSE BYTE 1\r\n*\r\nIORLEN   EQU   *-IOR<\/pre>\n<p>The first two fields are input to the I\/O routine and the remainder are output. \u00a0The IORCC field points to the CCW chain to execute. \u00a0The IORUNIT field contains the device address. \u00a0IORSIOCC returns the\u00a0condition\u00a0code returned form the SIO instruction. \u00a0IORCSW contains a copy of the CSW after the I\/O request is complete. \u00a0If the I\/O operation resulted in a Unit Check condition the I\/O subroutine will perform a sense command and save the first two bytes into IORSENS0 and IORSENS1.<\/p>\n<p>The I\/O subroutine returns a completion code in Register 15 to indicate the completion status of the I\/O request.<\/p>\n<ul>\n<li>RC = 0 &#8211; The I\/O Completed Normally<\/li>\n<li>RC = 4 &#8211; Exceptional Condition Encountered<\/li>\n<li>RC = 8 &#8211; I\/O Not Initiated (SIO CC Stored)<\/li>\n<li>RC = 16 &#8211; TIO Error<\/li>\n<\/ul>\n<pre>**********************************************************************\r\n* XIO - PERFORM I\/O SUBROUTINE\r\n*       R1 = A(IOR) I\/O REQUEST BLOCK\r\n*       ON EXIT R15 CONTAINS A RETURN CODE\r\n**********************************************************************\r\n*\r\nXIO      DS    0H\r\n         STM   R14,R12,12(R13)    SAVE CALLER'S REGISTERS\r\n         LA    R14,XIOSAVE        POINT TO OUR SAVE ADDRESS\r\n         ST    R14,8(,R13)\r\n         ST    R13,4(,R14)\r\n         LR    R13,R14\r\n*\r\n         LR    R10,R1             IOR BLOCK ADDRESS\r\n         USING IOR,R10\r\n*<\/pre>\n<p>We begin by saving the callers registers and then establishing a new save area. \u00a0The IOR address is copied into Register 10 and mapped against the IOR DSECT.<\/p>\n<pre>         XC    IORSIOCC,IORSIOCC\r\n         XC    IORSENS0(2),IORSENS0\r\n         XC    IORCSW,IORCSW<\/pre>\n<p>First the output fields in the IOR are cleared.<\/p>\n<pre>         L     R1,IORCCW          POINT TO CCW  CHAIN\r\n         ST    R1,72              SAVE INTO CAW\r\n         SLR   R2,R2\r\n         ICM   R2,B'0011',IORUNIT DEVICE ADDRESS\r\n         SIO   0(R2)              START I\/O\r\n         BC    4,SIOCC4           BRANCH IF SIO NOT ACCEPTED\r\n         BC    2,SIOCC2           BRANCH IF SIO NOT ACCEPTED\r\n         BC    1,SIOCC1           BRANCH IF SIO NOT ACCEPTED<\/pre>\n<p>The CCW address is saved into the CAW and a SIO is issued against the device. \u00a0If the SIO did not complete with CC=8 a SIO CC code is stored in the IOR and the return code is set to 8.<\/p>\n<pre>WAITIO   TIO   0(R2)              WAIT FOR I\/O COMPLETION\r\n         BC    1,TIOCC1           BRANCH IF ERROR\r\n         BC    7,WAITIO           KEEP WAITING...\r\n*\r\n         MVC    IORCSW,64         SAVE CSW\r\n         CLC    =X'0C00',ORCSW+4  CHANNEL END\/DEVICE END\r\n         BE     WAITIO20          YES - GOOD COMPLETION\r\n         TM     IORCSW+4,X'02'    UNIT CHECK?\r\n         BNO    WAITIO15          NO - DON'T NEED TO SO SENSE<\/pre>\n<p>A TIO loop is executed to wait for the I\/O request to complete. \u00a0Once the I\/O has completed the CSW copied into the IOR. \u00a0If any status bits except Channel End and Device End are set it is considered to be an exceptional condition.<\/p>\n<p>If Unit Check was set we fall through to issue a sense command.<\/p>\n<pre>         LA    R1,CCWSENSE\r\n         ST    R1,72              SAVE INTO CAW\r\n         SIO   0(R2)              START I\/O\r\n         BC    7,WAITIO99         ERROR\r\n*\r\nWAITIO10 TIO   0(R2)              WAIT FOR I\/O COMPLETION\r\n         BC    1,WAITIO99         BRANCH IF ERROR\r\n         BC    7,WAITIO10         KEEP WAITING...\r\n*\r\n         MVC   IORSENS0(2),SENSE  SAVE SENSE BYTES 0 &amp; 1\r\nWAITIO15 DS    0H                 WAIT FOR I\/O COMPLETION\r\n         LA    R15,4              SET RC=4\r\n         B     XIOXT<\/pre>\n<p>The address of the SENSE CCW is stored into the CAW and a SIO is issued to the device. \u00a0A TIO loop is used to wait for the Sense I\/O to complete. \u00a0The first two bytes of the sense data is stored into the IOR. \u00a0We can now exit with a return code of 4.<\/p>\n<pre>SIOCC1   DS    0H\r\n         MVI   IORSIOCC,X'01'\r\n         LA    R15,8\r\n         B     XIOXT\r\n*\r\n*\r\nSIOCC2   DS    0H\r\n         MVI   IORSIOCC,X'02'\r\n         LA    R15,8\r\n         B     XIOXT\r\n*\r\n*\r\nSIOCC4   DS    0H\r\n         MVI   IORSIOCC,X'04'\r\n         LA    R15,8\r\n         B     XIOXT\r\n*\r\n*\r\nWAITIO99 DS    0H\r\nTIOCC1   DS    0H\r\n         LA    R15,16\r\n         B     XIOXT\r\n*\r\n*\r\nXIOXT    DS    0H\r\n         L     R1,4(,R13)\r\n         ST    R15,16(,R1)\r\n*\r\n         @PRINT '-------- IOR --------'\r\n         @DUMP IORB,IORLEN\r\n         @PRINT ' '\r\n         @PRINT ' '\r\n*\r\n         L     R13,4(,R13)\r\n         LM    R14,R12,12(R13)    RESTORE CALLER'S REGS\r\n         BR    R14                RETURN TO CALLER<\/pre>\n<p>We finally end up at XIOXT with a return code set in Register 15. \u00a0Here I save the RC into the callers save area so it will be restored into Register 15 before returning to the caller. \u00a0For debugging purposes I have included a dump of the IOR Block. (This is why saving the value in Register 15 was necessary)<\/p>\n<p><a title=\"Searching The VTOC\" href=\"http:\/\/tommysprinkle.com\/txxos\/?p=233\">[Next &#8211; Searching The VTOC]<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Now that we have successfully managed to read from a DASD device we can build a general purpose subroutine to perform I\/O. \u00a0We will create a control block to communicate with the I\/O routine. \u00a0The control block will be called &hellip; <a href=\"https:\/\/tommysprinkle.com\/txxos\/?p=207\">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-207","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p1CPQT-3l","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/tommysprinkle.com\/txxos\/index.php?rest_route=\/wp\/v2\/posts\/207","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=207"}],"version-history":[{"count":5,"href":"https:\/\/tommysprinkle.com\/txxos\/index.php?rest_route=\/wp\/v2\/posts\/207\/revisions"}],"predecessor-version":[{"id":502,"href":"https:\/\/tommysprinkle.com\/txxos\/index.php?rest_route=\/wp\/v2\/posts\/207\/revisions\/502"}],"wp:attachment":[{"href":"https:\/\/tommysprinkle.com\/txxos\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=207"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tommysprinkle.com\/txxos\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=207"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tommysprinkle.com\/txxos\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=207"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}