|
|
1.1 root 1: #
2: # Operating System Interface to Berkeley VAX/UNIX
3: # for
4: # Macro SPITBOL V3.5
5: # -----------------------------------------------
6: #
7: # Copyright 1982
8: # Dewar Information Systems Corporation
9: # 221 West Lake Street
10: # Oak Park, Illinois 60302
11: #
12: # this operating system interface, commonly referred to as osint,
13: # provides the Macro SPITBOL compiler with a means to do all i/o
14: # and other OS dependent activities.
15: #
16: # osint is composed of one medium sized assembly module, with
17: # multiple entry points, and a collection of c functions. the
18: # entire interface is not in c due to the compiler's use of
19: # registers to pass parameters and other technicalities. all
20: # entries, except for sbchk, have five letter names starting
21: # with sys.
22: #
23: # when spitbol first starts execution, control passes to function
24: # main, just like in a normal c program. main processes any options
25: # and does other initialization chores. after completing
26: # initialization, main jumps to label sec04 to start
27: # the compiler itself. from that point, the compiler makes calls
28: # to sysxx routines to get service.
29: #
30: # the c functions are called from this module to do most of the
31: # hard and/or unix dependent work. an effort has been made to
32: # do all the system calls from c functions. this goal has not
33: # been entirely achieved.
34: #
35: #
36: # register masks
37: #
38: .set mr0,1
39: .set mr1,2
40: .set mr2,4
41: .set mr3,8
42: .set mr4,16
43: .set mr5,32
44: .set mr6,64
45: .set mr7,128
46: .set mr8,256
47: .set mr9,512
48: .set mr10,1024
49: .set mr11,2048
50: #
51: # c functions assume that r0 -> r5 are scratch. however, spitbol
52: # uses r2, r3, and r5. so, need to save these registers across
53: # function calls.
54: #
55: .set mr235,mr2+mr3+mr5
56: #
57: # mask for all registers used by compiler. necessary for dealing
58: # with load modules.
59: #
60: .set cmpreg,mr2+mr3+mr5+mr6+mr7+mr8+mr9+mr10
61: #
62: # miscellaneous equates
63: #
64: .set ch$lk,107 # upper case letter k
65: .set ch$mn,45 # dash (minus sign)
66: .set k,1024
67: .set kwords,k*4
68: #
69: # internal spitbol blocks
70: # -----------------------
71: #
72: # these equates describe compiler control blocks used by osint.
73: #
74: # chain of file control blocks
75: #
76: .set chtyp,0 # type word
77: .set chlen,4 # block length
78: .set chnxt,8 # -> next chblk
79: .set chfcb,12 # -> fcb
80: .set chsize,16 # size of chblk
81: #
82: # icblk - integer block
83: #
84: .set ictyp,0 # type word
85: .set icval,4 # integer value
86: #
87: # scblk - string block
88: #
89: .set sctyp,0 # type word
90: .set sclen,4 # string length
91: .set scstr,8 # start of string
92: #
93: # interface control blocks
94: # ------------------------
95: #
96: # these control blocks are built by the interface to handle i/o.
97: # for files other than standard input, standard output, and the
98: # terminal, these control blocks reside in the compiler's
99: # dynamic area. this requires appropriate setting of the type
100: # words to allow proper garbage collection.
101: #
102: # blocks with type b$xnt contain non-relocatable addresses - that
103: # is, no word may contain a pointer to another block in the
104: # dynamic area.
105: #
106: # blocks with type b$xrt contain relocatable addresses - that is
107: # words may contain a pointer to another block in the dynamic area.
108: #
109: # the basic structure is:
110: #
111: # for each input or output associated file there is:
112: #
113: # 1 ioblk containing all global information about
114: # the file: filename, buffer block pointer,
115: # file descriptor number, flags
116: #
117: # 1 bfblk containing the file buffer
118: #
119: # 1 or more fcblks containing the access mode (line or
120: # raw), the record length, and a pointer to
121: # the ioblk
122: #
123: # the first INPUT() or OUTPUT() call for a file creates one block
124: # of each type. subsequent calls to INPUT() or OUTPUT() for a
125: # previously associated file, may cause the creation of a new fcblk.
126: # allowing multiple fcblks provides the program with different
127: # ways of accessing the same file. for example, one type of access
128: # can be a character at a time and another entire records.
129: #
130: # the compiler keeps track of all active fcblks, and at times
131: # like end-of-job provides the inteface with a chain of all fcblks.
132: #
133: #
134: # bfblk - i/o buffer control block
135: #
136: .set bftyp,0 # type word - b$xnt
137: .set bflen,4 # block length
138: .set bfsiz,8 # buffer size in bytes
139: .set bfrem,12 # bytes remaining
140: .set bfoff,16 # offset to next remaining byte
141: .set bfsize,20 # end of fixed portion
142: #
143: # fcblk - file control block
144: #
145: .set fctyp,0 # type word - b$xrt
146: .set fclen,4 # block length
147: .set fcrsz,8 # record size ( >0 line mode / <0 raw mode)
148: .set fciob,12 # -> ioblk
149: .set fcsize,16 # size of fcblk
150: #
151: # ioblk - i/o control block
152: #
153: .set iotyp,0 # type word - b$xrt
154: .set iolen,4 # block length
155: .set iofnm,8 # -> filename scblk
156: .set iopid,12 # pid (if one end of pipe)
157: .set iobuf,16 # -> bfblk
158: .set iofdn,20 # file descriptor number
159: .set ioflg,24 # flags
160: .set iosize,28 # size of ioelt
161: #
162: # defines that match "spitio.h" for flags in ioflg
163: #
164: .set IO_INP,1 # input associated
165: .set IO_OUP,2 # output associated
166: .set IO_APP,4 # output open for append
167: .set IO_OPN,8 # file is open
168: .set IO_EOF,16 # eof on input file
169: .set IO_ERR,32 # i/o error
170: .set IO_SYS,64 # this is an osint file
171: .set IO_WRC,128 # don't do buffering
172: .set IO_PIP,256 # this is one end of a pipe
173: .set IO_DED,512 # other end of pipe died
174: .set IO_ILL,1024 # i/o illegal according to sysfc
175: #
176: # osint( argc,argv,environ ) is called just like the main
177: # function of a c program.
178: #
179: .globl _main
180: _main: .word 0
181: #
182: # normal start - process all command arguments.
183: #
184: movl 4(ap),r4 # get number of options
185: movl r4,argc # and save
186: movl 8(ap),r6 # -> option pointers
187: movl r6,argv # and save
188: #
189: # if this is a restart from an load module, go handle.
190: #
191: tstl lmodstk # if load module stack != 0 then
192: jnequ rstart # go handle
193: #
194: tstl (r6)+ # program name not interesting
195: brb gtcont # process other args
196: gtarg: movl (r6)+,r0 # -> option text
197: cmpb $ch$mn,(r0) # if no leading - then
198: bnequ gtinp # treat as input filename
199: incl r0 # bump over -
200: 1: movb (r0)+,curopt+1 # set option character in table
201: movl $opttbl,r1 # -> option table
202: 2: cmpl curopt,(r1) # if we have found it then
203: beqlu 3f # process it
204: addl2 $optsiz,r1 # -> next table entry
205: brb 2b # loop until found
206: 3: movl optrtn(r1),r11 # -> option routine
207: jsb (r11) # call option routine
208: 4: tstb (r0) # if char is binary zeros then
209: beqlu gtcont # done with this arg
210: cmpb $040,(r0) # if next char is blank then
211: bnequ 5f
212: incl r0 # ignore it
213: brb 4b # and check next char
214: 5: cmpb $ch$mn,(r0) # if next char is not - then
215: bnequ 1b # treat as option character
216: incl r0 # else skip over -
217: brb 1b # and treat next char as option
218: gtinp: jsb optinp # process input filename(s)
219: gtcont: sobgtr r4,gtarg # loop thru all options
220: #
221: # switch to proper input file
222: #
223: pushl inpptr
224: pushl inpcnt
225: calls $2,_swcinp
226: #
227: # call to do initial switch of output files.
228: #
229: pushl _outptr
230: calls $1,_swcoup
231: #
232: # see if standard output is tty or not.
233: #
234: pushl $1 # file descriptor 1
235: calls $1,_testty # call to check i/o chcaracteristics
236: tstl r0 # if r0 not 0 then
237: bnequ 0f # not a tty
238: clrl lnsppg # reset # lines per page
239: bisl2 $prtich,sptflg # else tell compiler
240: 0:
241: #
242: # set signals for execution
243: #
244: .globl _setsigs
245: calls $0,_setsigs # trap overflow signals
246: #
247: # allocate initial dynamic memory
248: #
249: mull3 meminc,$4,meminb# convert meminc to bytes
250: pushl meminb # memory request increment
251: calls $1,_sbrk # call to system call
252: movl r0,basmem # save base of memory
253: addl3 r0,meminb,topmem# computer top of memory
254: mull3 datwds,$4,r1 # convert max data words to bytes
255: addl3 r0,r1,maxmem # computer top of memory
256: 0: clrl (r0)+ # clear initial allocation
257: cmpl r0,topmem # loop until all cleared
258: blssu 0b
259: #
260: # set up lowest legal sp value, so that stack overflow can be detected,
261: #
262: mull3 $4,stksiz,r0 # convert words to bytes
263: subl3 r0,sp,lowsp # and compute lowest sp
264: movl sp,initsp # save initial sp
265: #
266: # clear registers, set dynamic area pointers, and jump off
267: # to compiler
268: #
269: clrl r2
270: clrl r3
271: clrl r4
272: clrl r5
273: clrl r6
274: clrl r7
275: clrl r8
276: movl basmem,r9
277: subl3 $4,topmem,r10
278: jmp sec04
279: #
280: # here to restart program after EXIT() call. this means we are now
281: # executing from an a.out file created by the interface.
282: #
283: rstart:
284: #
285: # before restoring stack, set up values for proper checking of
286: # stack overflow. (initial sp here will most probably differ
287: # from initial sp when compile was done.)
288: #
289: mull3 $4,stksiz,r0 # convert words to bytes
290: subl3 r0,sp,lowsp # and compute lowest sp
291: movl sp,initsp # save initial sp
292: jsb streloc # relocate pointers into stack
293: #
294: # restore stack from tscblk.
295: #
296: movl lmodstk,r0 # -> bottom word of stack
297: movab tscblk+scstr,r1 # -> top word of stack
298: 0: movl -(r0),-(sp) # relocate word of stack
299: cmpl r0,r1 # if not at end of relocation then
300: bgtru 0b # loop back
301: #
302: # if restarting, we can always access the command line arguments
303: #
304: movl $1,cmdcnt
305: #
306: # the system break will not be what it should, so reset it
307: #
308: pushl topmem
309: calls $1,_brk
310: #
311: # reset signals to what they should be.
312: #
313: calls $0,_setsigs
314: #
315: # forget about files open during compilation -
316: #
317: clrl inpptr # no input files
318: clrl inpcnt # so count is 0 too
319: clrl _outptr # no output file
320: clrl errfdn # no error file
321: #
322: # reset standard input buffer
323: #
324: clrl inpbf+bfrem # no remaining chars
325: clrl inpbf+bfoff # offset to next char
326: #
327: # restore compiler's registers and off we go.
328: #
329: popr $cmpreg # restore compiler's registers
330: addl2 $8,(sp)
331: rsb
332: #
333: # sbchk is called by the compiler to check for stack overflow.
334: #
335: .globl sbchk
336: sbchk: cmpl sp,lowsp # if sp is ok then
337: blssu 0f
338: rsb # return
339: 0: tstl (sp)+ # else pop stack
340: jmp sec05 # and go to stack overflow section
341: #
342: # sysef - eject file
343: #
344: .globl sysef
345: sysef:
346: pushr $mr235
347: pushl fciob(r6) # -> ioblk
348: calls $1,_osopen # call to do open
349: tstl r0 # if open error then
350: jnequ erxit1 # take error exit
351: pushl $ffscb # -> ff scblk
352: pushl fciob(r6) # -> ioblk
353: pushl ffscb+sclen # record length
354: mnegl fcrsz(r6),-(sp) # i/o mode - raw or line
355: calls $4,_oswrite # call to do write
356: tstl r0 # if output error then
357: jneq erxit3 # signal failure
358: popr $mr235
359: addl2 $12,(sp)
360: rsb
361: #
362: # sysej - end of job
363: #
364: .globl sysej
365: sysej:
366: movl r10,_rzfcb # copy head of fcb chain
367: beqlu 1f # if empty then nothing to close
368: 0: movl chfcb(r10),r1 # -> fcb
369: pushl fciob(r1) # -> ioblk
370: calls $1,_osclose # call to do close
371: movl chnxt(r10),r10 # -> next on chain
372: bnequ 0b # and loop back for more
373: 1: pushl r7 # return &code
374: calls $1,__exit
375: #
376: # sysen - endfile
377: #
378: .globl sysen
379: sysen:
380: pushr $mr235
381: pushl fciob(r6) # -> ioblk
382: calls $1,_osopen # call to do open
383: tstl r0 # if open error then
384: jnequ erxit1 # take error exit
385: movl r$fcb,_rzfcb # copy fcb chain head
386: pushl fciob(r6) # -> ioblk
387: calls $1,_osclose # call to do close
388: popr $mr235
389: addl2 $12,(sp)
390: rsb
391: #
392: # sysfc
393: #
394: .globl sysfc
395: sysfc:
396: movl (sp)+,(sp) # remove stacked scblk
397: pushr $mr235
398: tstl sclen(r10) # if null filearg1 then
399: jeqlu erxit1 # error
400: #
401: # get length of filename and scan off options.
402: #
403: movl r9,-(sp) # -> filename scblk
404: calls $1,_lenfnm # call to get filename length
405: movl r0,lenfname # save length for later use
406: jlss erxit1 # length must not be negative
407: movl r9,-(sp) # -> filename scblk
408: movl $tioblk,-(sp) # -> temporary ioblk
409: movl r7,-(sp) # input/output association flag
410: calls $3,_sioarg # call to scan i/o args
411: tstl r0 # if error in args then
412: jlss erxit1 # take error return
413: #
414: # check for consistency of calls. cannot have both input
415: # and output to same channel. if this happens, though,
416: # set flag and let sysio take proper error exit.
417: #
418: tstl r6 # if no previous fcblk then
419: beqlu 0f # skip
420: movl fciob(r6),r0 # -> ioblk
421: movl ioflg(r0),r0 # get previous flags
422: mcoml $IO_INP+IO_OUP,r1 # get mask for bicl
423: bicl2 r1,r0 # remove all bits but INP&OUP
424: bitl tioblk+ioflg,r0 # if bits are not same then
425: bnequ 0f
426: bisl2 $IO_ILL,tioblk+ioflg # then set error flag
427: 0:
428: #
429: # handle null filenames here - must either have a previous
430: # fcblk or specify -f arg.
431: #
432: tstl lenfname # if non-null filename then
433: bgtr fcfnam # go handle below
434: bitl $IO_OPN,tioblk+ioflg
435: bnequ fcfarf # if -f specified then merge w/non-null
436: tstl r6 # if no previous fcblk then
437: jeqlu erxit1 # error
438: clrl r6 # assume that no new fcblk needed
439: clrl ioblkptr # no ioblk ptr to stuff
440: tstl tioblk # if however i/o args indicate one
441: jeqlu fcxit
442: movl fciob(r6),ioblkptr
443: movl $fcsize,r6 # allocate one
444: jbr fcxit
445: #
446: # handle real filenames and null filenames with -f arg here.
447: # note that they're mutually exclusive.
448: #
449: fcfnam: bitl $IO_OPN,tioblk+ioflg
450: jnequ erxit1 # can't have -f arg too
451: fcfarf: tstl r6 # if previous fcblk passed then
452: jnequ erxit1 # error
453: clrl ioblkptr
454: addl3 $bfsize+3,tioblk+iopid,r6
455: bicl2 $3,r6
456: movl r6,bfblksiz
457: addl2 $fcsize+iosize,r6
458: movl $1,tioblk # set newfcb flag
459: #
460: fcxit: clrl r10 # no private fcblk
461: clrl r8 # xrblk please
462: popr $mr235
463: addl2 $4,(sp)
464: rsb
465: #
466: # syshs
467: #
468: .globl syshs
469: syshs:
470: pushr $mr235
471: cmpl $b$icl,(r6) # if arg1 not integer then
472: jnequ 9f # return host string
473: tstl icval(r6) # if integer 0 then
474: beqlu 1f # return -u argument
475: cmpl $1,icval(r6) # if integer 1 then
476: beqlu 2f # do system call
477: cmpl $2,icval(r6) # if integer 2 then
478: jeqlu 3f # return command arg
479: cmpl $3,icval(r6) # if integer 3 then
480: jeqlu 4f # return number of 1st #! arg
481: cmpl $4,icval(r6) # if integer 4 then
482: jeqlu 5f # return value of environment variable
483: jbr erxit1 # else arg error
484: #
485: 1: tstl uarg # if uarg is 0 then
486: jeqlu erxit4 # return null string
487: pushl tscblk # push scblk string length
488: pushl $tscblk # -> temp scblk
489: clrl -(sp) # ending character is 0
490: pushl uarg # -> -u argument
491: calls $4,_cpys2sc # copy string to scblk
492: movab tscblk,r10 # -> temp scblk
493: jbr erxit3 # return
494: #
495: 2: cmpl $b$scl,(r10) # if 2nd arg not string then
496: jnequ erxit1 # return error
497: tstl sclen(r10) # if null string then
498: jeqlu erxit4 # return null string
499: pushl r10 # -> command string
500: calls $1,_dosys # call to do system call
501: jbr erxit4 # return null string
502: #
503: 3: cmpl $b$icl,(r10) # if 2nd arg not integer then
504: jnequ erxit1 # return error
505: movl tscblk,tscblk+sclen # set max length of scblk
506: pushab tscblk # push -> tscblk
507: pushl argv # push -> pointers
508: pushl argc # push number of args
509: pushl icval(r10) # arg requested
510: calls $4,_arg2scb # call to do real move
511: tstl r0 # if out of range then
512: jlss erxit6 # fail
513: jeqlu erxit4 # (if 0) return null string
514: movab tscblk,r10 # -> tscblk
515: jbr erxit3 # return
516: #
517: 4: tstl cmdcnt # if not invoked by #! then
518: jeqlu erxit6 # fail
519: movab temp1,r9 # -> temp icblk
520: movl $b$icl,(r9) # set integer block
521: movl cmdcnt,icval(r9)# set value
522: jbr erxit5 # return result
523: #
524: 5: cmpl $b$scl,(r10) # if 2nd arg not string then
525: jnequ erxit1 # return error
526: tstl sclen(r10) # if null string then
527: jeqlu erxit1 # return error
528: movl tscblk,tscblk+sclen # set max length of scblk
529: pushab tscblk # push -> tscblk
530: pushl r10 # -> environment variable requested
531: calls $2,_rdenv # fetch the environment variable
532: tstl r0 # if it couldn't be found
533: jlss erxit6 # fail
534: movab tscblk,r10 # else return tscblk
535: jbr erxit3
536: #
537: 9: pushl hststr # push length of host string
538: pushab hststr # push -> host string scblk
539: calls $2,_gethost # call to get host string
540: tstl hststr+sclen # if null host string then
541: jeqlu erxit4 # return null string
542: movl $hststr,r10 # -> host string
543: jbr erxit3 # return
544: #
545: # sysid - return system id
546: #
547: .globl sysid
548: sysid:
549: movl $id1,r9
550: movl $id2,r10
551: rsb
552: #
553: # sysil - get input record length
554: #
555: .globl sysil
556: sysil:
557: movl fcrsz(r6),r6
558: bgtr 0f
559: mnegl r6,r6
560: 0:
561: rsb
562: #
563: # sysin - read input record
564: #
565: .globl sysin
566: sysin:
567: pushr $mr235
568: pushl fciob(r6) # -> ioblk
569: calls $1,_osopen # call to open file
570: tstl r0 # if open unsuccessful then
571: jnequ erxit3 # take error exit
572: pushl r9 # -> scblk
573: pushl fciob(r6) # -> ioblk
574: pushl fcrsz(r6) # push record length
575: bgtr 0f
576: mnegl (sp),(sp) # if negative then make it positive
577: 0: pushl fcrsz(r6) # i/o mode - raw or line
578: calls $4,_osread # call to do read
579: cmpl r0,$-1 # check for eof or input error
580: jeql erxit1 # take eof exit
581: jlss erxit2 # take error exit
582: movl r0,sclen(r9) # set record length
583: popr $mr235
584: addl2 $12,(sp)
585: rsb
586: #
587: # sysio
588: #
589: .globl sysio
590: sysio:
591: pushr $mr235
592: bitl $IO_ILL,tioblk+ioflg
593: jnequ erxit2 # if illegal then take error exit
594: movl r6,fcblkptr # copy fcblk pointer for exit
595: #
596: # fill in fcblk.
597: #
598: tstl tioblk+iotyp # if no new fcb to build then
599: jeqlu iodon # done
600: movl $fcsize,fclen(r6)
601: movl tioblk+iolen,fcrsz(r6)
602: movl ioblkptr,fciob(r6)
603: jnequ iodon
604: movab fcsize(r6),fciob(r6)
605: #
606: # fill in ioblk.
607: #
608: movab fcsize(r6),r6 # -> ioblk
609: movl $b$xrt,(r6)
610: movl $iosize,iolen(r6)
611: movl r9,iofnm(r6)
612: clrl iopid(r6)
613: movab iosize(r6),iobuf(r6)
614: movl tioblk+iofdn,iofdn(r6)
615: movl tioblk+ioflg,ioflg(r6)
616: #
617: # if -f0 or -f1 specified then
618: #
619: # for -f0 ensure that buffer is same as osint's
620: #
621: # for -f1 no buffering should be done
622: #
623: bitl $IO_SYS,ioflg(r6)
624: beqlu 9f
625: cmpl $1,iofdn(r6)
626: blssu 9f
627: beqlu 1f
628: movl $inpbf,iobuf(r6)
629: jbr 9f
630: 1: clrl iobuf(r6)
631: bisl2 $IO_WRC,ioflg(r6)
632: 9:
633: #
634: # fill in bfblk
635: #
636: movab iosize(r6),r6 # -> bfblk
637: movl $b$xnt,(r6)
638: movl bfblksiz,bflen(r6)
639: movl tioblk+iopid,bfsiz(r6)
640: clrl bfrem(r6)
641: clrl bfoff(r6)
642: #
643: iodon: movl fcblkptr,r10
644: clrl r8
645: popr $mr235
646: addl2 $8,(sp)
647: rsb
648: #
649: # sysmm - get more memory
650: #
651: .globl sysmm
652: sysmm:
653: cmpl topmem,maxmem # if already at top of memory then
654: blssu 0f
655: clrl r9 # no more to be had
656: rsb
657: 0: # else {alloc some more}
658: pushr $mr235
659: pushl meminb # size in bytes of memory request
660: calls $1,_sbrk # call to get memory
661: popr $mr235
662: tstl r0 # if memory obtained then
663: blss 1f
664: addl2 meminb,topmem # adjust current top
665: movl meminc,r9 # set number of words in block
666: rsb # return
667: 1: clrl r9 # else nothing to get
668: rsb
669: #
670: # sysmx - get maximum size of created objects
671: #
672: .globl sysmx
673: sysmx:
674: mull3 $4,maxsiz,r6
675: rsb
676: #
677: # syspi - print on interactive channel (terminal)
678: #
679: .globl syspi
680: syspi:
681: movl $ttyiob,r11
682: jbr piprt
683: #
684: # syspp - return print parameters
685: #
686: .globl syspp
687: syspp:
688: movl pagwid,r6
689: movl lnsppg,r7
690: movl sptflg,r8
691: movl defcas,kvcas
692: rsb
693: #
694: # syspr - print on standard output
695: #
696: .globl syspr
697: syspr:
698: movl $oupiob,r11
699: #
700: # handle both syspi and syspr here.
701: #
702: piprt:
703: pushr $mr235
704: bisl2 $IO_WRC,ioflg(r11) # briefly set no buffering
705: pushl r9 # -> scblk
706: pushl r11 # -> ioblk
707: pushl r6 # number characters
708: pushl $1 # line mode
709: calls $4,_oswrite # call to do write
710: bicl2 $IO_WRC,ioflg(r11) # back to buffering
711: tstl r0 # if output error then
712: jneq erxit1 # indicate error return
713: popr $mr235
714: addl2 $4,(sp)
715: rsb
716: #
717: # sysrd - read from standard input
718: #
719: .globl sysrd
720: sysrd:
721: pushr $mr235
722: movl $inpiob,ioblkptr
723: #
724: # handle both sysrd and sysri here.
725: #
726: rdmrg:
727: pushl r9 # -> scblk
728: pushl ioblkptr # -> ioblk
729: pushl r8 # read length
730: pushl r8 # line mode
731: calls $4,_osread # call to do read
732: cmpl r0,$-1 # check for eof or input error
733: jeql rdeof # take eof exit
734: jlss erxit1 # take error exit
735: movl r0,sclen(r9) # set read length
736: #
737: # check for 1st record of standard input coming from a file specified
738: # on the command line. if all of these conditions are true, allow
739: # the program to access any arguments following the file name.
740: #
741: tstl rdrec1 # if already ready record 1 then
742: bnequ rdskp # skip
743: cmpl $inpiob,ioblkptr
744: bnequ rdskp # if sysri entry then skip
745: incl rdrec1 # indicate read 1st record from std input
746: tstl inpptr # if not file from command line then
747: beqlu rdskp # skip
748: cmpb $'#,scstr(r9) # if 1st char not # then
749: bnequ rdskp # skip
750: cmpb $'!,scstr+1(r9) # if 2nd char not ! then
751: bnequ rdskp # skip
752: subl3 inpcnt,argc,cmdcnt
753: incl cmdcnt # compute # args after filename
754: movl $1,inpcnt # reset input count
755: brb rdmrg # ignore 1st record and try again
756: rdskp:
757: popr $mr235
758: addl2 $4,(sp)
759: rsb
760: #
761: # come here to handle eof for both sysrd and sysri. if eof
762: # is for sysrd, standard input, switch to next input file
763: # if one exists.
764: #
765: rdeof: movl ioblkptr,r4 # -> ioblk
766: tstl iofdn(r4) # if not file descriptor 0 then
767: jnequ erxit1 # real eof
768: pushl inpptr # push -> array of pointers
769: pushl inpcnt # push size of areray
770: calls $2,_swcinp # call to switch input files
771: tstl r0 # if more to read then
772: jeqlu rdmrg # read it
773: jmp erxit1 # else signal eof
774: #
775: # sysri - read from interactive channel (terminal)
776: #
777: .globl sysri
778: sysri:
779: pushr $mr235
780: movl $ttyiob,ioblkptr
781: jbr rdmrg
782: #
783: # sysst - set file pointer
784: #
785: .globl sysst
786: sysst:
787: pushr $mr235
788: pushl fciob(r6) # -> ioblk
789: calls $1,_osopen # call to do open
790: tstl r0 # if file open error then
791: jnequ erxit3 # return error
792: #
793: movl fciob(r6),r1 # -> ioblk
794: bitl $IO_PIP,ioflg(r1)
795: jnequ erxit4 # if pipe then set not allowed
796: cmpl iofdn(r1),$2 # if fd < 2 then
797: jlssu erxit4 # set not allowed
798: #
799: cmpl $b$icl,(r7) # if already integer then
800: bnequ 0f
801: movl icval(r7),temp1 # grab value
802: brb 1f
803: 0: cmpl $b$scl,(r7) # else if not a string then
804: jnequ erxit1 # error
805: clrl temp3 # clear scnint character count
806: pushl $temp3 # -> temp3
807: pushl sclen(r7) # string length
808: pushab scstr(r7) # -> string
809: calls $3,_scnint # call to scan integer
810: movl r0,temp1 # and save
811: 1:
812: #
813: cmpl $b$icl,(r8) # if already integer then
814: bnequ 0f
815: movl icval(r8),temp2 # grab value
816: brb 1f
817: 0: cmpl $b$scl,(r8) # else if not a string then
818: jnequ erxit1 # error
819: clrl temp3 # clear scnint character count
820: pushl $temp3 # -> temp3
821: pushl sclen(r8) # string length
822: pushab scstr(r8) # -> string
823: calls $3,_scnint # call to scan integer
824: movl r0,temp2 # and save
825: 1:
826: #
827: pushl temp2 # whence
828: pushl temp1 # offset
829: pushl fciob(r6) # -> ioblk
830: calls $3,_doset # call to do set
831: popr $mr235
832: addl2 $20,(sp)
833: rsb
834: #
835: # systm - get execution time so far
836: #
837: .globl systm
838: systm:
839: pushr $mr2+mr3
840: movl $tscblk+8,-(sp) # -> times buffer
841: calls $1,_times # call to do times
842: movl tscblk+8,r5 # get user time in 60ths
843: mull2 $100,r5 # mulitply by 100 to get 6000ths
844: divl2 $6,r5 # divide by 6 to get 1000ths
845: popr $mr2+mr3
846: rsb
847: #
848: # sysxi - exit from executing program
849: #
850: .globl sysxi
851: sysxi:
852: tstl r10 # if 0 instead of scblk then
853: jeqlu xilmod # try to write load module
854: pushr $mr235
855: cmpl $b$scl,(r10) # if not scblk then
856: jnequ erxit1 # error
857: pushl r10 # push scblk pointer
858: calls $1,_doexec # go do exit
859: jmp erxit2 # should never return
860: #
861: # write load module
862: #
863: xilmod: tstl r5 # if r5 <= 0 then
864: bgtr 0f
865: pushr $mr235 # save regs for error exits
866: jbr erxit1 # and take error exit
867: 0: pushr $cmpreg # else save all compiler regs
868: #
869: # need to save stack contents, so that when load module is
870: # invoked, stack can be recreated.
871: #
872: subl3 sp,initsp,r0 # compute depth of stack
873: cmpl r0,tscblk # if stack won't fit in tscblk then
874: jgtru xi2big # big trouble
875: movl sp,r0 # -> into real stack
876: movab tscblk+scstr,r1 # -> save stack area
877: 1: movl (r0)+,(r1)+ # copy word of stack ...
878: cmpl r0,initsp # until hit top word
879: blssu 1b
880: movl r1,lmodstk # set top of saved stack
881: #
882: # before creating the load module, we must relativize the
883: # compiler cells that point into the stack. We do this by
884: # temporarily negating initsp, calling streloc, and then
885: # restoring initsp. After the load module has been written,
886: # another call to streloc will restore the stack pointers.
887: #
888: mnegl initsp,initsp # negate initsp so streloc will subtract
889: jsb streloc # relativize the compiler cells
890: mnegl initsp,initsp # restore initsp to its previous value
891: #
892: # create a.out header in hststr scblk.
893: #
894: addl3 $1023,dnamp,r1 # round current memory in use
895: bicl3 $0x3ff,r1,-(sp) # to a multiple of the page size
896: movab hststr+scstr,r0 # -> a.out header block
897: pushl r0 # which will be the other argument
898: movl $0413,(r0)+ # set magic number
899: bicl3 $0x3ff,$_etext,r1 # get text size, rounded down
900: movl r1,(r0)+ # and place it in a.out header
901: subl3 r1,4(sp),(r0)+ # data size = total - text size
902: clrl (r0)+ # we will use no bss
903: clrl (r0)+
904: clrl (r0)+ # set starting address
905: clrl (r0)+
906: clrl (r0)+
907: #
908: # call a workhorse c routine to actually write a.out file.
909: # the amount of memory to write has already been pushed.
910: #
911: calls $2,_wrtaout # call to write a.out
912: #
913: # restore compiler cells to their previous values
914: #
915: jsb streloc # unrelativize stack pointers
916: #
917: tstl r0 # if error creating a.out then
918: blss xi2big # return error
919: #
920: # pop registers and set up call to sysej
921: #
922: popr $cmpreg # restore all registers
923: movl r7,r10 # -> chain of fcbs
924: clrl r7 # set &CODE = 0
925: jsb sysej # call to end run
926: #
927: # if stack too big
928: #
929: xi2big: popr $cmpreg # restore all regs
930: pushr $mr235 # push correct regs
931: jbr erxit2 # take error exit
932: #
933: # error/ppm exits - pick up n-th word following jsb and return
934: # to address contained in that word.
935: #
936: erxit1:
937: popr $mr235
938: movl (sp)+,r11
939: jmp *(r11)+
940: #
941: erxit2:
942: popr $mr235
943: addl3 $4,(sp)+,r11
944: jmp *(r11)+
945: #
946: erxit3:
947: popr $mr235
948: addl3 $8,(sp)+,r11
949: jmp *(r11)+
950: #
951: erxit4:
952: popr $mr235
953: addl3 $12,(sp)+,r11
954: jmp *(r11)+
955: #
956: erxit5:
957: popr $mr235
958: addl3 $16,(sp)+,r11
959: jmp *(r11)+
960: #
961: erxit6:
962: popr $mr235
963: addl3 $20,(sp)+,r11
964: jmp *(r11)+
965: #
966: # streloc - relocate stack pointers. this routine adds
967: # initsp to every cell whose address appears in strellst.
968: #
969: streloc:
970: pushr $mr0+mr1
971: moval strellst,r1 # start of list of thing to relocate
972: jbr strel1 # jump into the loop
973: strel0: addl2 initsp,(r0) # relocate a pointer
974: strel1: movl (r1)+,r0 # fetch a pointer to a cell
975: jneq strel0 # if zero, we're done
976: popr $mr0+mr1
977: rsb
978: #
979: # option routines
980: #
981: # optclr clears a flag
982: # opterr signals an error
983: # optfld sets defcas to 0 for no folding
984: # optnum get numeric value
985: # optset set option value
986: #
987: # optclr
988: #
989: optclr: bicl2 optflg(r1),sptflg
990: rsb
991: #
992: # opterr
993: #
994: opterr: pushr $mr0+mr1+mr2+mr3+mr4+mr5
995: pushl $6
996: pushl $curopt
997: pushl $2
998: calls $3,_write
999: popr $mr0+mr1+mr2+mr3+mr4+mr5
1000: rsb
1001: #
1002: # optinp
1003: #
1004: optinp: tstl inpptr # if already processed input filenames then
1005: bnequ opterr # error
1006: subl3 $4,r6,inpptr # -> first input filename
1007: movl r4,inpcnt # set number of filenames
1008: movl $1,r4 # done scanning options
1009: rsb # return
1010: #
1011: # optfld
1012: #
1013: optfld: clrl defcas
1014: rsb
1015: #
1016: # optnum
1017: #
1018: optnum: pushl r0 # -> number
1019: jsb getnum # get number
1020: movl (sp)+,r0 # -> byte past last digit
1021: movzbl (r0),r2 # get byte past last digit
1022: bisb2 $040,r2 # fold to lower case
1023: cmpb $ch$lk,r2 # if number followed by k then
1024: bnequ 0f
1025: mull2 $1024,r5 # mulitply by 1024
1026: incl r0 # skip over k
1027: 0: tstl r5 # if number zero or negative
1028: bleq opterr # treat as error
1029: movl r5,*optflg(r1) # store option
1030: rsb # return
1031: #
1032: # optoup
1033: #
1034: optoup: cmpl $2,r4 # if no option after -o then
1035: bgtru opterr # error
1036: movl (r6),r1 # -> output filename
1037: cmpb $ch$mn,(r1) # if filename starts with - then
1038: beqlu opterr # error
1039: movl (r6)+,_outptr # save pointer to output filename
1040: decl r4 # one less option to process
1041: rsb # return
1042: #
1043: # optset
1044: #
1045: optset: bisl2 optflg(r1),sptflg
1046: rsb
1047: #
1048: # optusr
1049: #
1050: optusr: cmpl $2,r4 # if fewer than 2 options then
1051: jgtru opterr # can't have argument
1052: movl (r6)+,uarg # save -> argument
1053: decl r4 # dec number of remaining options
1054: rsb
1055: #
1056: # getnum
1057: #
1058: # (sp) -> string to convert
1059: # jsb getnum
1060: # (sp) -> char after last digit
1061: # (r5) converted number
1062: #
1063: getnum:
1064: movl 4(sp),r7 # -> string
1065: clrl r5 # clear accumulator
1066: 0: cmpb $060,(r7) # if not a decimal digit then
1067: bgtru 1f # done with conversion
1068: cmpb $071,(r7) #
1069: blssu 1f
1070: movzbl (r7)+,r8 # load digit
1071: subl2 $060,r8 # remove unnecessary bits
1072: mull2 $10,r5 # accum * 10
1073: addl2 r8,r5 # add in this digit
1074: brb 0b
1075: 1: movl r7,4(sp) # return address of next byte
1076: rsb # return
1077: #
1078: # interface data area
1079: # -------------------
1080: #
1081: .data 1
1082: #
1083: # flags for compiler
1084: #
1085: .set errors,1 # send errors to terminal
1086: .set prtich,2 # standard printer is terminal
1087: .set nolist,4 # suppress compilation listing
1088: .set nocmps,8 # suppress compilation statistics
1089: .set noexcs,16 # suppress execution statistics
1090: .set lnglst,32 # generate page ejects
1091: .set noexec,64 # suppress program execution
1092: .set trmnal,128 # terminal i/o association
1093: .set stdlst,256 # standard listing (intermediate)
1094: .set nohedr,512 # suppress sysid header
1095: #
1096: .set deflag,errors+nolist+nocmps+noexcs+trmnal+nohedr
1097: #
1098: # option table
1099: #
1100: .set opttxt,0 # option characters
1101: .set optflg,4 # option flag - flags or address
1102: .set optrtn,8 # -> option processing routine
1103: .set optsiz,12 # size in bytes of entry
1104: #
1105: opttbl:
1106: .ascii "-f "
1107: .long 0,optfld
1108: #
1109: .ascii "-e "
1110: .long errors,optclr
1111: #
1112: .ascii "-l "
1113: .long nolist,optclr
1114: #
1115: .ascii "-c "
1116: .long nocmps,optclr
1117: #
1118: .ascii "-x "
1119: .long noexcs,optclr
1120: #
1121: .ascii "-a "
1122: .long nolist+nocmps+noexcs,optclr
1123: #
1124: .ascii "-p "
1125: .long lnglst,optset
1126: #
1127: .ascii "-z "
1128: .long stdlst,optset
1129: #
1130: .ascii "-h "
1131: .long nohedr,optclr
1132: #
1133: .ascii "-n "
1134: .long noexec,optset
1135: #
1136: .ascii "-m "
1137: .long maxsiz,optnum
1138: #
1139: .ascii "-s "
1140: .long stksiz,optnum
1141: #
1142: .ascii "-d "
1143: .long datwds,optnum
1144: #
1145: .ascii "-i "
1146: .long meminc,optnum
1147: #
1148: .ascii "-o "
1149: .long 0,optoup
1150: #
1151: .ascii "-u "
1152: .long 0,optusr
1153: #
1154: curopt: .ascii "- "
1155: .ascii "?\n "
1156: .long opterr
1157: .align 2
1158: #
1159: # standard input/output pointers
1160: #
1161: inpcnt: .long 0
1162: inpptr: .long 0
1163: .globl _outptr
1164: _outptr: .long 0
1165: #
1166: # pointer to -u arg
1167: #
1168: uarg: .long 0
1169: #
1170: # save argc and argv from initial call
1171: #
1172: argc: .long 0
1173: argv: .long 0
1174: #
1175: # #! data areas
1176: #
1177: cmdcnt: .long 0 # number of command args
1178: rdrec1: .long 0 # read record 1 from std in flag
1179: #
1180: # standard ioblks
1181: #
1182: inpiob: .space iobuf
1183: .long inpbf # -> input bfblk
1184: .long 0 # file descriptor
1185: .long IO_INP|IO_OPN|IO_SYS
1186: #
1187: inpbf: .space bfsiz
1188: .long 1024 # buffer size
1189: .long 0 # remaining chars to read
1190: .long 0 # offset to next character to read
1191: .space 1024 # buffer
1192: #
1193: #
1194: oupiob: .space iobuf
1195: .long 0 # no buffer
1196: .long 1 # file descriptor number
1197: .long IO_OUP|IO_OPN|IO_SYS
1198: #
1199: #
1200: ttyiob: .space iobuf
1201: .long ttybf # -> tty buffer input
1202: .long 2 # file descriptor number
1203: .long IO_INP|IO_OUP|IO_OPN|IO_SYS
1204: #
1205: ttybf: .space bfsiz
1206: .long 258 # buffer size
1207: .long 0 # remaining chars to read
1208: .long 0 # offset to next char to read
1209: .space 258 # buffer
1210: .align 2
1211: #
1212: .globl _rzfcb
1213: _rzfcb: .long 0
1214: #
1215: fildes: .long 0
1216: pr_len: .long 0
1217: rd_len: .long 0
1218: lenfname: .long 0
1219: ioblkptr: .long 0
1220: bfblkptr: .long 0
1221: bfblksiz: .long 0
1222: fcblkptr: .long 0
1223: tioblk: .space iosize
1224: #
1225: # memory allocation variables
1226: #
1227: meminc: .long 4*k # increment in words for sbrk
1228: meminb: .long 0 # meminc * 4 (to get bytes)
1229: datwds: .long 256*k # max size in words of dynamic area
1230: basmem: .long 0 # base of dynamic memory
1231: topmem: .long 0 # current top of dynamic memory
1232: maxmem: .long 0 # maximum top of dynamic memory
1233: maxsiz: .long 8*k # maximum object size in words
1234: stksiz: .long 2*k # stack size in words
1235: initsp: .long 0 # initial value of sp on entry to sec04
1236: lowsp: .long 0 # lowest legal sp value
1237: #
1238: # default value for &case
1239: #
1240: defcas: .long 1
1241: #
1242: # values given to syspp for print parameters
1243: #
1244: lnsppg: .long 60 # lines per page
1245: pagwid: .long 120 # page width
1246: sptflg: .long deflag # flags
1247: #
1248: # flag that indicates that this is a load module. also, serves
1249: # the dual purpose of indicating size of saved stack.
1250: #
1251: lmodstk: .long 0
1252: #
1253: temp1: .long 0
1254: temp2: .long 0
1255: temp3: .long 0
1256: #
1257: nulstr: .long 0,0
1258: #
1259: tscblk: .long 512,0
1260: .space 512
1261: #
1262: hststr: .long 128,0
1263: .space 128
1264: #
1265: id1: .long 0,id1l
1266: .ascii "(0.0)"
1267: id1e:
1268: .set id1l,id1e-id1-8
1269: .align 2
1270: #
1271: id2: .long 0,id2l
1272: .ascii "VAX/UNIX Version"
1273: id2e:
1274: .set id2l,id2e-id2-8
1275: .align 2
1276: #
1277: ffscb: .long 0,1
1278: ffstr: .byte 12
1279: #
1280: nlstr: .ascii "\n"
1281: .align 2
1282: #
1283: errfdn: .long 0
1284: #
1285: # The following pointers address those cells in the compiler
1286: # that point into the stack when a load module might be written,
1287: # and which must therefore be relocated.
1288: strellst:
1289: .long flptr
1290: .long stbas
1291: .long gtcef
1292: .long 0 # end of list marker
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.