⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mips.c

📁 mips架构的bootloader,99左右的版本 但源代码现在没人更新了
💻 C
字号:
/************************************************************* * File: tools/mips.c * Purpose: Compiler driver for MIPS compiler. This module is * 	    used to generate the pmcc command. See the pmcc man *	    page for a full description of the options. * Author: Phil Bunce (pjb@carmel.com) * Revision History: *	970313	Added -ssyms option (separate symbols) *	970314	Removed $LSIPKG refs in crtn pathnames *	970417	Added check for nfiles==0 *	970902	Removed -ice option */#include <stdio.h>#include <malloc.h>#include <string.h>#include "../include/defines.h"#include "misc.h"#define FILSZ 1000#define FLGSZ 1000/* set various defaults */int vflag = 0;int ssyms_flag = 0;char INC[100],LIBM[100];int fast = 1;char *driver = "";int crt0,msim;char *prom = "";char *syms = "-s";char *chksum = "";char *ofile = "a";char CC[40];Str files,LIBS,flags,Lflags;Str *strlst[] = {&files,&LIBS,&flags,&Lflags,0};char tmp[LNMAX],tmp2[LNMAX],objfile[40];char LIBC[100],HPATH[100];char tstart[10];char dstart[40];char stoppoint;char *Gnum = "o";char *LSIPKG,*ENDIAN,*COMP_HOST_ROOT;char *SZ;/**************************************************************  main(argc,argv)*/main(argc,argv)int argc;char *argv[];{int i,nfiles,status,sz;char *p,*vtmp,*fmt;strcpy(CC,"cc");strcpy(dstart,"");if (! (LSIPKG=getenv("LSIPKG"))) {	fprintf(stderr,"pmcc: LSIPKG not set\n");	exit(1);	}sprintf(INC,"%s/include",LSIPKG);Strcpy(&LIBS,"");Strcpy(&Lflags,"");addarg(&flags,"-DPMCC -DMIPSTOOLS");#ifdef SRECfast = 0;#endif#ifdef CLIENTPCsprintf(tmp,"%08x",CLIENTPC);strcpy(tstart,tmp);#elsestrcpy(tstart,"80020000");#endif/* Select default Endianess. */#ifdef LENDEFENDIAN = "l";#elseENDIAN = "b";#endifstrcpy(LIBM,"/usr/lib/cmplrs/cc");#ifdef MSIMmsim = 1;crt0 = 1;addarg(&files,"$LSIPKG/lib/bo/crt2.o");strcpy(tstart,"9fc00000");fast = 0;#endif/* This while loop does several jobs:# 	1. strips off any pmcc defined options# 	2. some options, if specified, must preceed path specs# 	   so extract them from here, and add them to flags.# 	3. find the output filename, if specified*/nfiles = 0;for (i=1;i < argc;i++) {	if (strequ(argv[i],"-fast")) {		fast = 1;		}	else if (strequ(argv[i],"-syms")) {		syms = "";		}	else if (strequ(argv[i],"-ssyms")) {		ssyms_flag = 1;		syms = "";		}	else if (strequ(argv[i],"-driver")) {		driver = "-D";		crt0 = 1;		syms = "";		sprintf(tmp,"%s/lib/%sg/crt3.o",LSIPKG,ENDIAN);		addarg(&files,tmp);		nfiles++;		}#if 0 /* 970902 */	else if (strequ(argv[i],"-ice")) {		crt0 = 1;		sprintf(tmp,"%s/lib/%so/crt4.o",LSIPKG,ENDIAN);		addarg(&files,tmp);		nfiles++;		}#endif	else if (strequ(argv[i],"-mips2")) {		addarg(&flags,argv[i]);		}	else if (strequ(argv[i],"-prom")) {		prom = "-p";		fast = 0;		}	else if (strequ(argv[i],"-crt0")) {		crt0 = 1;		}	else if (strequ(argv[i],"-msim")) {		if (!msim) addarg(&files,"$LSIPKG/lib/bo/crt2.o");		msim = 1;		crt0 = 1;		strcpy(tstart,"9fc00000");		fast = 0;		}	else if (strequ(argv[i],"-T")) {		i++;		strcpy(tstart,argv[i]);		}	else if (strequ(argv[i],"-D")) {		i++;		sprintf(dstart,"-Wl,-D -Wl,%s",argv[i]);		}	else if (strequ(argv[i],"-target")) {		i++;		}	else if (strequ(argv[i],"-L")) {		addarg(&Lflags,argv[i]);		}	else if (!strncmp(argv[i],"-L",2)) {		addarg(&Lflags,argv[i]);		}	else if (!strncmp(argv[i],"-l",2)) {		addarg(&LIBS,argv[i]);		}	else if (!strncmp(argv[i],"-D",2)) {		addarg(&flags,argv[i]);		}	else if (!strncmp(argv[i],"-y",2)) {		addarg(&flags,argv[i]);		}	else if (strequ(argv[i],"-fp")) {		addarg(&flags,argv[i]);		}	else if (strequ(argv[i],"-G")) {		i++;		addarg(&flags,"-G");		addarg(&flags,argv[i]);		if (strequ(argv[i],"0")) Gnum = "g";		}	else if (strequ(argv[i],"-I")) {		addarg(&flags,argv[i]);		}	else if (!strncmp(argv[i],"-I",2)) {		addarg(&flags,argv[i]);		}	else if (strequ(argv[i],"-g")) {		addarg(&flags,argv[i]);		}	else if (strequ(argv[i],"-j")) {		addarg(&flags,argv[i]);		stoppoint = 'c';		}	else if (strequ(argv[i],"-v")) {		vflag = 1;		addarg(&flags,argv[i]);		}	else if (strequ(argv[i],"-srec")) {		fast = 0;		}	else if (strequ(argv[i],"-chksum")) {		chksum = "-c";		}	else if (!strncmp(argv[i],"-O",2)) {		addarg(&flags,argv[i]);		}	else if (strequ(argv[i],"-float")) {		addarg(&flags,argv[i]);		addarg(&flags,"-DFLOAT");		SZ = "FLOAT";		}	else if (strequ(argv[i],"-double")) {		SZ = "DOUBLE";		}	else if (strequ(argv[i],"-EB")) {		ENDIAN = "b";		}	else if (strequ(argv[i],"-EL")) {		ENDIAN = "l";		}	else if (strequ(argv[i],"-o")) {		addarg(&flags,argv[i]);		i++;		addarg(&flags,argv[i]);		ofile = argv[i];		}	else if (strequ(argv[i],"-c")) {		addarg(&flags,argv[i]);		stoppoint = 'c';		}	else if (strequ(argv[i],"-S")) {		addarg(&flags,argv[i]);		stoppoint = 'S';		}	else if (!strncmp(argv[i],"-W",2)) {		addarg(&flags,argv[i]);		}	else if (argv[i][0] == '-') {		fprintf(stderr,"%s: bad arg\n",argv[i]);		exit(1);		}	else {		addarg(&files,argv[i]);		nfiles++;		}	}if (strequ(ENDIAN,"b")) addarg(&flags,"-EB");else addarg(&flags,"-EL");/* see if it is the MIPS cross toolset */if (COMP_HOST_ROOT=getenv("COMP_HOST_ROOT")) {	sprintf(tmp,"%s/usr/bin/ccx",COMP_HOST_ROOT);	if (fileExists(tmp)) strcpy(CC,"ccx");	else strcpy(CC,"ccr3000");	sprintf(LIBM,"%s/usr/lib",COMP_HOST_ROOT);	}#ifdef NO_CHKSUMchksum = "-c";#endif/* Select math library */if (SZ) {	sprintf(tmp,"%s/libm/%s/%s%s",LSIPKG,SZ,ENDIAN,Gnum);	if (fileExists(tmp)) strcpy(LIBM,tmp);	}/* Select C library */sprintf(LIBC,"%s/lib/%s%s",LSIPKG,ENDIAN,Gnum);/* for O3 opt we need to set systype */#if defined(RISC5) || defined(DECRISC)strcat(CC," -systype lsipkg");#elseif (strequ(CC,"ccx") || strequ(CC,"ccr3000")) strcat(CC," -systype lsipkg");#endif#ifdef RISC45sprintf(tmp," -systype lsipkg%s%s",ENDIAN,Gnum);strcat(CC,tmp);#endif#ifdef DECRISCstrcat(CC," -unsigned");#endif#ifdef SGIRISCstrcat(CC," -non_shared");#endifif (crt0 || *driver) sprintf(HPATH,"%s/libsa/%s%s",LSIPKG,ENDIAN,Gnum);else sprintf(HPATH,"%s",LIBC);if (nfiles == 0) {	printf("Fatal error: no files specified\n");	exit(1);	}/* now invoke the compiler */fmt = "%s -N -T %s %s %s -tr -h%s -L -L%s -L%s %s -I -I%s -B %s %s";sz = strlen(CC)+strlen(tstart)+strlen(dstart)+strlen(flags.str)+strlen(HPATH)+     strlen(LIBC)+strlen(LIBM)+strlen(Lflags.str)+strlen(INC)+     strlen(files.str)+strlen(LIBS.str)+strlen(fmt);vtmp = malloc(sz);sprintf(vtmp,fmt,CC,tstart,dstart,flags.str,HPATH,LIBC,LIBM,Lflags.str,	     INC,files.str,LIBS.str);if (vflag) fprintf(stderr,"%s\n",vtmp);if (status=system(vtmp)) Exit(status);Free(vtmp);if (stoppoint != 0) Exit(0);strcpy(objfile,ofile);if (strequ(ofile,"a")) strcpy(objfile,"a.out");/* now make the appropriate download records */if (fast) sprintf(tmp,"genfrec %s %s %s %s > %s.rec",driver,syms,chksum,objfile,ofile);else sprintf(tmp,"gensrec %s %s %s %s > %s.rec",driver,prom,syms,objfile,ofile);if (vflag) fprintf(stderr,"%s\n",tmp);if (status=system(tmp)) Exit(status);sprintf(tmp,"gensrec -B %s > %s.map",objfile,ofile);if (vflag) fprintf(stderr,"%s\n",tmp);if (status=system(tmp)) Exit(status);if (!ssyms_flag) Exit(0);/* do -ssyms option */if (fast) sprintf(tmp,"genfrec -e %s > %s.sym",objfile,ofile);else sprintf(tmp,"gensrec -e %s > %s.sym",objfile,ofile);if (vflag) fprintf(stderr,"%s\n",tmp);if (status=system(tmp)) Exit(status);Exit(0);}/**************************************************************  char *strstr(p,q) *	returns a ptr to q in p, else 0 if not found *	strstr provided with compilers 2.20 doesn't work*/char *strstr(p,q)char *p,*q;{char *s,*t;if (!p || !q) return(0);if (! *q) return(p);for (;*p;p++) {	if (*p == *q) {		t = p; s = q;		for (;*t;s++,t++) {			if (*t != *s) break;			}		if (! *s) return(p);		}	}return(0);}/**************************************************************  Exit(x)*/Exit(x)int x;{int i;for (i=0;strlst[i];i++) {	if (strlst[i]->str) free(strlst[i]->str);	}exit(((x)>127)?1:(x));}/**************************************************************/getargs(ac,av)int ac;char *av[];{/* stub */}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -