/* Copyright (c) 1979 Regents of the University of California */
* variables to manage the assembly input
char *dotsname
; /*the current file name; managed by the parser*/
int lineno
; /*current line number; managed by the parser*/
int silent
; /*don't complain about any errors*/
int savelabels
; /*write the labels to the a.out file*/
char *endcore
; /*where to get more symbol space*/
0410, 0, 0, 0, 0, 0, 0, 0,
struct {short hiword
; short loword
;}; /* stupid fp-11 */
#define writel(p,n,f) fwrite( (long) p, sizeof (long), n, f)
struct exp usedot
[NLOC
+NLOC
];
FILE *usefile
[NLOC
+NLOC
];
FILE *rusefile
[NLOC
+NLOC
];
char sibuf
[TOKBUFLG
]; /*buffer used for all input*/
char sobuf
[TOKBUFLG
]; /*buffer used for all output*/
/*except stdout and relfil*/
char stdoutbuf
[BUFSIZ
]; /*stdout buffer*/
extern int njxxx
; /*number of jumpxxx instructs*/
extern int d124
; /*allocate 1,2 or 4 bytes for unknowns*/
char *innames
[32]; /*names of the files being assembled*/
int ninfiles
; /*how many interesting files there are*/
setbuf(stdout
, stdoutbuf
);
* Give the error processor something to complain about
* if there is an error processing an argument
dotsname
= "<argv error>";
* We can throw away single minus signs, so
* that make scripts for the PDP 11 assembler work
yyerror("Unknown flag: %c", *--cp
);
if ( (d124
!= 1) && (d124
!= 2) &&
while (*cp
&& ('0' <= *cp
) && (*cp
<= '7'))
hdr
.magic
= hdr
.magic
<<3 + *cp
++ - '0';
case 'C': outcounters
= 1;
case 'L': savelabels
= 1;
} /*end of pulling out all arguments*/
} /*end of a flag argument*/
yyerror("More than 32 file names");
innames
[ninfiles
++] = argv
[1];
} /*end of looking at all of the arguments*/
endcore
= (char *)sbrk(0);
* Install symbols in the table
* mark usedot: first NLOC slots for named text segments,
* the next for named data segments.
for (locindex
=0; locindex
<NLOC
; locindex
++) {
usedot
[locindex
].xtype
= XTEXT
;
usedot
[locindex
+NLOC
].xtype
= XDATA
;
if (signal(SIGINT
, SIG_IGN
) != SIG_IGN
)
tmpn1
= (char *)mktemp("/tmp/asXXXXX");
tmpfil
= fopen(tmpn1
, "w");
yyerror("Bad pass 1 temporary file for writing %s", tmpn1
);
buildtokensets(); /*sets to implement expression lookahead*/
if (ninfiles
== 0){ /*take the input from stdin directly*/
} else { /*we have the names tanked*/
for (filestep
= 0; filestep
< ninfiles
; filestep
++){
new_dot_s(innames
[filestep
]);
if (freopen(innames
[filestep
], "r", stdin
) == NULL
) {
yyerror( "Can't open source file %s\n",
closetmpfile(); /*kick out the last buffered intermediate text*/
lgtmpfile
= ftell(tmpfil
);
tmpfil
= fopen(tmpn1
, "r");
yyerror("Bad pass 2 temporary file for reading %s", tmpn1
);
* round and assign text segment origins
for (locindex
=0; locindex
<NLOC
; locindex
++) {
v
= round(usedot
[locindex
].xvalue
, FW
);
usedot
[locindex
].xvalue
= tsize
;
* round and assign data segment origins
datbase
= round(tsize
, PAGRND
);
for (locindex
=0; locindex
<NLOC
; locindex
++) {
v
= round(usedot
[NLOC
+locindex
].xvalue
, FW
);
usedot
[NLOC
+locindex
].xvalue
= datbase
+dsize
;
* Assign final values to symbols
txtfil
= fopen(outfile
, "w");
yyerror("Cannot create %s", outfile
);
tmpn2
= (char *)mktemp("/tmp/aaatXXXXX");
tmpn3
= (char *)mktemp("/tmp/abatXXXXX");
relfil
= fopen(tmpn3
, "w");
yyerror("Bad temp file for writing extra text segments %s", tmpn3
);
hdr
.ssize
= sizesymtab();
* hdr.trsize, hdr.drsize set by outrel
/* *************** PASS 2 **************** */
printf("\n\n\n\t\tPASS 2\n\n\n\n");
for (locindex
=0; locindex
<NLOC
; locindex
++) {
txtfil
=usefile
[locindex
];
while (usedot
[locindex
].xvalue
& FW
)
fclose(usefile
[locindex
]);
fclose(rusefile
[locindex
]);
if (usefile
[NLOC
+locindex
]) {
txtfil
= usefile
[NLOC
+locindex
];
dotp
= &usedot
[locindex
+NLOC
];
relfil
= rusefile
[NLOC
+locindex
];
while (usedot
[locindex
+NLOC
].xvalue
& FW
)
* append csect text onto text for csect 0
for (locindex
=1; locindex
<NLOC
+NLOC
; locindex
++) {
tmpn2
[TMPC
] = locindex
+'a';
relfil
= fopen(tmpn2
, "r");
yyerror("cannot reopen temp");
fread(buffer
, 1, BUFSIZ
, relfil
),
* append relocation info onto text
for (locindex
=0; locindex
<NLOC
+NLOC
; locindex
++) {
if (rusefile
[locindex
]) {
tmpn3
[TMPC
] = locindex
+'a';
relfil
= fopen(tmpn3
, "r");
yyerror("cannot reopen temp");
fread(buffer
, 1, BUFSIZ
, relfil
),
* Go back and patch up rsize
if (anyerrs
==0 && orgwarn
)
yyerror("Caution: absolute origins.\n");
fread(buffer
, 1, BUFSIZ
, stdin
);
exit(1); /*although the previous pass will also exit non zero*/
for (locindex
=0; locindex
<NLOC
+NLOC
; locindex
++) {
tmpn2
[TMPC
] = locindex
+'a';
tmpn3
[TMPC
] = locindex
+'a';
if (!outcounters
) return;
printf("Assembly of files: ");
printf("<Standard Input.>\n");
for (i
= 0; i
<ninfiles
; i
++)
printf("%s ", innames
[i
]);
printf("Virtual Memory for the interpass temporary file.\n");
printf("%d hashing collsions\n", nhcollisions
);
printf("%d hash table accesses\n", nhashed
);
printf("%d values entered in the hash table\n", nentered
);
printf("%d byte length of the temporary file\n", lgtmpfile
);
printf("%d symbols in the symbol table\n", nsyms
);
printf("%d labels in the symbol table\n", nlabels
);
printf("%d forgotten symbols\n", nforgotten
);
printf("%d iterations through all symbols to remove jxxxes\n",
printf("%d jumps resolved via tunnelling\n", jxxxtunnel
);
printf("%d DEADLOCKED JXXXentries: Resolved by %s jumping\n",
jxdeadlock
, nbadjxsegs
== 0 ? "short" : "long");
printf("%d Segments with jxxx over aligns.\n",
((float)tbuffer
.p_user
)/60.0,
((float)tbuffer
.p_sys
)/60.0);