1*5824Srrh /* 2*5824Srrh * Copyright (c) 1982 Regents of the University of California 3*5824Srrh */ 4*5824Srrh #ifndef lint 5*5824Srrh static char sccsid[] = "@(#)asio.c 4.4 02/14/82"; 6*5824Srrh #endif not lint 7*5824Srrh 8594Sbill #include <stdio.h> 9594Sbill #include "as.h" 10594Sbill /* 11594Sbill * Block I/O routines for logical I/O concurrently in 12594Sbill * more than one place in the same file. 13594Sbill */ 14594Sbill int biofd; /* file descriptor for block I/O file */ 15594Sbill off_t boffset; /* physical position in logical file */ 16594Sbill BFILE *biobufs; /* the block I/O buffers */ 17594Sbill 18594Sbill #define error(severity, message) \ 19594Sbill {yyerror(message); if (severity) delexit();} 20594Sbill 21594Sbill Flushfield(n) 22594Sbill register int n; 23594Sbill { 24594Sbill while (n>0) { 25594Sbill outb(bitfield); 26594Sbill bitfield >>= 8; 27594Sbill n -= 8; 28594Sbill } 29594Sbill bitoff=0; 30594Sbill bitfield=0; 31594Sbill } 32594Sbill 33594Sbill /* 34648Shenry * Block I/O Routines 35594Sbill */ 36594Sbill bopen(bp, off) 37594Sbill struct biobuf *bp; 38594Sbill off_t off; 39594Sbill { 40594Sbill 41594Sbill bp->b_ptr = bp->b_buf; 42594Sbill bp->b_nleft = BUFSIZ - off % BUFSIZ; 43594Sbill bp->b_off = off; 44594Sbill bp->b_link = biobufs; 45594Sbill biobufs = bp; 46594Sbill } 47594Sbill 48594Sbill int bwrerror; 49594Sbill 50594Sbill bwrite(p, cnt, bp) 51594Sbill register char *p; 52594Sbill register int cnt; 53594Sbill register struct biobuf *bp; 54594Sbill { 55594Sbill register int put; 56594Sbill register char *to; 57594Sbill 58594Sbill top: 59594Sbill if (cnt == 0) 60594Sbill return; 61594Sbill if (bp->b_nleft) { 62594Sbill put = bp->b_nleft; 63594Sbill if (put > cnt) 64594Sbill put = cnt; 65594Sbill bp->b_nleft -= put; 66594Sbill to = bp->b_ptr; 67*5824Srrh #ifdef lint 68*5824Srrh *to = *to; 69*5824Srrh #endif lint 70594Sbill asm("movc3 r8,(r11),(r7)"); 71594Sbill bp->b_ptr += put; 72594Sbill p += put; 73594Sbill cnt -= put; 74594Sbill goto top; 75594Sbill } 76594Sbill if (cnt >= BUFSIZ) { 77594Sbill if (bp->b_ptr != bp->b_buf) 78594Sbill bflush1(bp); 79594Sbill put = cnt - cnt % BUFSIZ; 80594Sbill if (boffset != bp->b_off) 81*5824Srrh (void)lseek(biofd, (long)bp->b_off, 0); 82594Sbill if (write(biofd, p, put) != put) { 83594Sbill bwrerror = 1; 84594Sbill error(1, "Output write error"); 85594Sbill } 86594Sbill bp->b_off += put; 87594Sbill boffset = bp->b_off; 88594Sbill p += put; 89594Sbill cnt -= put; 90594Sbill goto top; 91594Sbill } 92594Sbill bflush1(bp); 93594Sbill goto top; 94594Sbill } 95594Sbill 96594Sbill bflush() 97594Sbill { 98594Sbill register struct biobuf *bp; 99594Sbill 100594Sbill if (bwrerror) 101594Sbill return; 102594Sbill for (bp = biobufs; bp; bp = bp->b_link) 103594Sbill bflush1(bp); 104594Sbill } 105594Sbill 106594Sbill bflush1(bp) 107594Sbill register struct biobuf *bp; 108594Sbill { 109594Sbill register int cnt = bp->b_ptr - bp->b_buf; 110594Sbill 111594Sbill if (cnt == 0) 112594Sbill return; 113594Sbill if (boffset != bp->b_off) 114*5824Srrh (void)lseek(biofd, (long)bp->b_off, 0); 115594Sbill if (write(biofd, bp->b_buf, cnt) != cnt) { 116594Sbill bwrerror = 1; 117594Sbill error(1, "Output write error"); 118594Sbill } 119594Sbill bp->b_off += cnt; 120594Sbill boffset = bp->b_off; 121594Sbill bp->b_ptr = bp->b_buf; 122594Sbill bp->b_nleft = BUFSIZ; 123594Sbill } 124594Sbill 125594Sbill bflushc(bp, c) 126594Sbill register struct biobuf *bp; 127594Sbill char c; 128594Sbill { 129594Sbill bflush1(bp); 130594Sbill bputc(c, bp); 131594Sbill } 132