vax.c
来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· C语言 代码 · 共 1,097 行 · 第 1/2 页
C
1,097 行
#ifndef lintstatic char *sccsid = " @(#)vax.c 1.3 (ULTRIX) 1/15/86";#endif lint/************************************************************************ * * * Copyright (c) 1986 by * * Digital Equipment Corporation, Maynard, MA * * All rights reserved. * * * * This software is furnished under a license and may be used and * * copied only in accordance with the terms of such license and * * with the inclusion of the above copyright notice. This * * software or any other copies thereof may not be provided or * * otherwise made available to any other person. No title to and * * ownership of the software is hereby transferred. * * * * This software is derived from software received from the * * University of California, Berkeley, and from Bell * * Laboratories. Use, duplication, or disclosure is subject to * * restrictions under license agreements with University of * * California and with AT&T. * * * * The information in this software is subject to change without * * notice and should not be construed as a commitment by Digital * * Equipment Corporation. * * * * Digital assumes no responsibility for the use or reliability * * of its software on equipment which is not supplied by Digital. * * * ************************************************************************//************************************************************************** Modification History** David Metsky 14-Jan-86** 001 Replaced old version with BSD 4.3 version as part of upgrade.** Based on: vax.c 5.2 8/29/85**************************************************************************//* * vax.c * * VAX specific routines for the F77 compiler, pass 1 * * University of Utah CS Dept modification history: * * $Log: vax.c,v $ * Revision 5.2 85/08/10 05:06:30 donn * Deleted intcon[] and realcon[], since they are now made redundant by * changes in intr.c. From Jerry Berkman. * * Revision 5.1 85/08/10 03:50:38 donn * 4.3 alpha * * Revision 3.1 85/02/27 19:14:58 donn * Changed to use pcc.h instead of pccdefs.h. * * Revision 2.3 85/02/22 01:09:22 donn * memname() didn't know about intrinsic functions... * * Revision 2.2 85/02/12 17:56:44 donn * Put the argument to the profiling routine in data space instead of * constant space. From Jerry Berkman. * * Revision 2.1 84/07/19 12:05:08 donn * Changed comment headers for UofU. * * Revision 1.2 84/02/26 06:41:04 donn * Added Berkeley changes to move data around to produce shorter offsets. * */#include "defs.h"#ifdef SDB# include <a.out.h>extern int types2[];# ifndef N_SO# include <stab.h># endif#endif#include <pcc.h>int maxregvar = MAXREGVAR;int regnum[] = { 10, 9, 8, 7, 6 } ;static int regmask[] = { 0x800, 0xc00, 0xe00, 0xf00, 0xf80, 0xfc0 };/* * The VAX assembler has a serious and not easily fixable problem * with generating instructions that contain expressions of the form * label1-label2 where there are .align's in-between the labels. * Therefore, the compiler must keep track of the offsets and output * .space where needed. */LOCAL int i_offset; /* initfile offset */LOCAL int a_offset; /* asmfile offset */prsave(proflab)int proflab;{if(profileflag) { pruse(asmfile, USEINIT); /* This is not a constant */ fprintf(asmfile, "L%d:\t.space\t4\n", proflab); pruse(asmfile, USECONST); p2pi("\tmovab\tL%d,r0", proflab); p2pass("\tjsb\tmcount"); }p2pi("\tsubl2\t$LF%d,sp", procno);}goret(type)int type;{p2pass("\tret");}/* * move argument slot arg1 (relative to ap) * to slot arg2 (relative to ARGREG) */mvarg(type, arg1, arg2)int type, arg1, arg2;{p2pij("\tmovl\t%d(ap),%d(fp)", arg1+ARGOFFSET, arg2+argloc);}prlabel(fp, k)FILEP fp;int k;{fprintf(fp, "L%d:\n", k);}prconi(fp, type, n)FILEP fp;int type;ftnint n;{register int i;if(type == TYSHORT) { fprintf(fp, "\t.word\t%ld\n", n); i = SZSHORT; }else { fprintf(fp, "\t.long\t%ld\n", n); i = SZLONG; }if(fp == initfile) i_offset += i;else a_offset += i;}prcona(fp, a)FILEP fp;ftnint a;{fprintf(fp, "\t.long\tL%ld\n", a);if(fp == initfile) i_offset += SZLONG;else a_offset += SZLONG;}#ifndef vaxprconr(fp, type, x)FILEP fp;int type;float x;{fprintf(fp, "\t%s\t0f%e\n", (type==TYREAL ? ".float" : ".double"), x);}#endif#ifdef vaxprconr(fp, type, x)FILEP fp;int type;double x;{/* non-portable cheat to preserve bit patterns */union { double xd; long int xl[2]; } cheat;register int i;cheat.xd = x;if(type == TYREAL) { float y = x; fprintf(fp, "\t.long\t0x%X\n", *(long *) &y); i = SZFLOAT; }else { fprintf(fp, "\t.long\t0x%X,0x%X\n", cheat.xl[0], cheat.xl[1]); i = SZDOUBLE; }if(fp == initfile) i_offset += i;else a_offset += i;}#endifpraddr(fp, stg, varno, offset)FILE *fp;int stg, varno;ftnint offset;{char *memname();if(stg == STGNULL) fprintf(fp, "\t.long\t0\n");else { fprintf(fp, "\t.long\t%s", memname(stg,varno)); if(offset) fprintf(fp, "+%ld", offset); fprintf(fp, "\n"); }if(fp == initfile) i_offset += SZADDR;else a_offset += SZADDR;}pralign(k)int k;{register int lg = 0;if(k > 4) { if(i_offset & 7) lg = 8 - (i_offset & 7); }else if(k > 2) { if(i_offset & 3) lg = 4 - (i_offset & 3); }else if(k > 1) { if(i_offset & 1) lg = 1; }else return;if(lg > 0) { fprintf(initfile, "\t.space\t%d\n", lg); i_offset += lg; }}prspace(n)int n;{fprintf(initfile, "\t.space\t%d\n", n);i_offset += n;}preven(k)int k;{register int lg = 0;if(k > 4) { if(a_offset & 7) lg = 8 - (a_offset & 7); }else if(k > 2) { if(a_offset & 3) lg = 4 - (a_offset & 3); }else if(k > 1) { if(a_offset & 1) lg = 1; }else return;if(lg > 0) { fprintf(asmfile, "\t.space\t%d\n", lg); a_offset += lg; }}praspace(n)int n;{fprintf(asmfile, "\t.space\t%d\n", n);a_offset += n;}vaxgoto(index, nlab, labs)expptr index;register int nlab;struct Labelblock *labs[];{register int i;register int arrlab;putforce(TYINT, index);p2pi("\tcasel\tr0,$1,$%d", nlab-1);p2pi("L%d:", arrlab = newlabel() );for(i = 0; i< nlab ; ++i) if( labs[i] ) p2pij("\t.word\tL%d-L%d", labs[i]->labelno, arrlab);}prarif(p, neg, zer, pos)expptr p;int neg, zer, pos;{int type;type = p->headblock.vtype;putforce(type, p);if(type == TYLONG) p2pass("\ttstl\tr0");else if (type == TYSHORT) p2pass("\ttstw\tr0");else p2pass("\ttstd\tr0");p2pi("\tjlss\tL%d", neg);p2pi("\tjeql\tL%d", zer);p2pi("\tjbr\tL%d", pos);}char *memname(stg, mem)int stg, mem;{static char s[20];switch(stg) { case STGCOMMON: case STGEXT: case STGINTR: sprintf(s, "_%s", varstr(XL, extsymtab[mem].extname) ); break; case STGBSS: case STGINIT: sprintf(s, "v.%d", mem); break; case STGCONST: sprintf(s, "L%d", mem); break; case STGEQUIV: sprintf(s, "q.%d", mem+eqvstart); break; default: badstg("memname", stg); }return(s);}prlocvar(s, len)char *s;ftnint len;{fprintf(asmfile, "\t.lcomm\t%s,%ld\n", s, len);}char *packbytes(cp)register Constp cp;{ static char shrt[2]; static char lng[4]; static char quad[8]; static char oct[16]; register int type; register int *ip, *jp; switch (cp->vtype) { case TYSHORT: *((short *) shrt) = (short) cp->const.ci; return (shrt); case TYLONG: case TYLOGICAL: case TYREAL: *((int *) lng) = cp->const.ci; return (lng); case TYDREAL: ip = (int *) quad; jp = (int *) &(cp->const.cd[0]); ip[0] = jp[0]; ip[1] = jp[1]; return (quad); case TYCOMPLEX: ip = (int *) quad; jp = (int *) &(cp->const.cd[0]); ip[0] = jp[0]; ip[1] = jp[2]; return (quad); case TYDCOMPLEX: ip = (int *) oct; jp = (int *) &(cp->const.cd[0]); *ip++ = *jp++; *ip++ = *jp++; *ip++ = *jp++; *ip = *jp; return (oct); default: badtype("packbytes", cp->vtype); }}prsdata(s, len)register char *s;register int len;{ static char *longfmt = "\t.long\t0x%x\n"; static char *wordfmt = "\t.word\t0x%x\n"; static char *bytefmt = "\t.byte\t0x%x\n"; register int i; i = 0; if ((len - i) >= 4) { fprintf(initfile, longfmt, *((int *) s)); i += 4; } if ((len - i) >= 2) { fprintf(initfile, wordfmt, 0xffff & (*((short *) (s + i)))); i += 2; } if ((len - i) > 0) fprintf(initfile,bytefmt, 0xff & s[i]); i_offset += len; return;}prquad(s)char *s;{ static char *quadfmt1 = "\t.quad\t0x%x\n"; static char *quadfmt2 = "\t.quad\t0x%x%08x\n"; if ( *((int *) (s + 4)) == 0 ) fprintf(initfile, quadfmt1, *((int *) s)); else fprintf(initfile, quadfmt2, *((int *) (s + 4)), *((int *) s)); i_offset += 8; return;}#ifdef NOTDEF/* The code for generating .fill directives has been *//* ifdefed out because of bugs in the UCB VAX assembler. *//* If those bugs are ever fixed (and it seems unlikely), *//* the NOTDEF's should be replaced by UCBVAXASM. */prfill(n, s)int n;register char *s;{ static char *fillfmt1 = "\t.fill\t%d,8,0x%x\n"; static char *fillfmt2 = "\t.fill\t%d,8,0x%x%08x\n"; if (*((int *) (s + 4)) == 0) fprintf(initfile, fillfmt1, n, *((int *) s)); else fprintf(initfile, fillfmt2, n, *((int *) (s + 4)), *((int *) s)); return;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?