Ejemplo n.º 1
0
void
cexpFlashSymLoad(unsigned char bank)
{
unsigned char	*flashctrl=(unsigned char*)0xffeffe50;
unsigned char	*flash    =(unsigned char*)0xfff80000;
int				fd;
struct	stat	stbuf;
int				len,i,written;
char 			tmpfname[30]={
				        '/','t','m','p','/','m','o','d','X','X','X','X','X','X',
					        0};

	/* switch to desired bank */
	*flashctrl=(1<<7)|bank;

	if (stat("/tmp",&stbuf)) {
		mode_t old = umask(0);
		mkdir("/tmp",0777);
		umask(old);
	}
	if ( (fd=mkstemp(tmpfname)) < 0) {
		perror("creating scratch file");
		goto cleanup;
	}

	len=*(unsigned long*)flash;
	flash+=sizeof(unsigned long);

	printf("Copying %i bytes\n",len);
	for (i=written=0; i < len; i+=written ) {
		written=write(fd,flash+i,len-i);
		if (written<=0)
			break;
	}
	close(fd);
	if (written<0) {
		perror("writing to tempfile\n");
	} else {
		printf("OK, ready to load\n");
		cexpModuleLoad(tmpfname,0);
	}

cleanup:
	unlink(tmpfname);
}
Ejemplo n.º 2
0
int
cexp_main1(int argc, char **argv, void (*callback)(int argc, char **argv, CexpContext ctx))
{
CexpContextRec		context;	/* the public parts of this instance's context */
CexpContext			myContext;
char				*line=0, *prompt=0, *tmp;
char				*symfile=0, *script=0;
int					rval=CEXP_MAIN_INVAL_ARG, quiet=0;
MyGetOptCtxtRec		oc={0}; /* must be initialized */
int					opt;
#ifdef HAVE_TECLA
#define	rl_context  context.gl
#else
#define rl_context  0
#endif
char				optstr[]={
						'h',
						'v',
						's',':',
						'a',':',
						'p',':',
#ifdef YYDEBUG
						'd',
#endif
						'q',
						'\0'
					};

context.prompt = 0;
context.parser = 0;

while ((opt=mygetopt_r(argc, argv, optstr,&oc))>=0) {
	switch (opt) {
		default:  fprintf(stderr,"Unknown Option %c\n",opt);
		case 'h': usage(argv[0]);
		case 'v': version(argv[0]);
			return 0;

#ifdef YYDEBUG
		case 'd': cexpdebug=1;
			break;
#endif
		case 'q': quiet=1;
			break;
		case 's': symfile=oc.optarg;
			break;
		case 'a': cexpBuiltinCpuArch = oc.optarg;
			break;

		case 'p': free(context.prompt); context.prompt = strdup(oc.optarg);
			break;
	}
}

if (argc>oc.optind)
	script=argv[oc.optind];

/* make sure vital code is initialized */

{
	static int initialized=0;
	cexpContextRunOnce(&initialized, cexpInit);
}

if (!cexpSystemModule) {
	if (!symfile) {
		/* try to find a builtin table */
		if ( !cexpModuleLoad(0,0) )
			fprintf(stderr,"No builtin symbol table -- need a symbol file argument\n");
	} else if (!cexpModuleLoad(symfile,"SYSTEM"))
		fprintf(stderr,"Unable to load system symbol table\n");
	if (!cexpSystemModule) {
		usage(argv[0]);
		return CEXP_MAIN_NO_SYMS;
	}
}

#ifdef USE_MDBG
mdbgInit();
#endif

/* initialize the public context */
context.next=0;
#ifdef HAVE_BFD_DISASSEMBLER
{
	extern void cexpDisassemblerInit();
	cexpDisassemblerInit(&context.dinfo, stdout);
}
#endif

cexpContextGetCurrent(&myContext);

if (!myContext) {
	/* topmost frame */
#ifdef HAVE_TECLA
	context.gl = new_GetLine(200,2000);
	if (!context.gl) {
		fprintf(stderr,"Unable to create line editor\n");
		return CEXP_MAIN_NO_MEM;
	}
	/* mute warnings about being unable to 
	 * read ~/.teclarc
	 */
	gl_configure_getline(context.gl,0,0,0);
#endif
	/* register first instance running in this thread's context; */
	cexpContextRegister();
	if (!quiet)
		hello();
} else {
#ifdef HAVE_TECLA
	/* re-use caller's line editor */
	context.gl = myContext->gl;
#endif
}
/* push our frame to the top */
context.next = myContext;
myContext	 = &context;
cexpContextSetCurrent(myContext);

/* See if there is an ancestor with a local prompt
 * and inherit
 */
if ( !context.prompt && context.next && context.next->prompt )
	context.prompt = strdup(context.next->prompt);

do {
	if (!(context.parser=cexpCreateParserCtx(quiet ? 0 : stdout))) {
		fprintf(stderr,"Unable to create parser context\n");
		usage(argv[0]);
		rval = CEXP_MAIN_NO_MEM;
		goto cleanup;
	}

#ifdef HAVE_TECLA
	{
	CPL_MATCH_FN(cexpSymComplete);
	gl_customize_completion(context.gl, context.parser, cexpSymComplete);
	}
#endif

	if (cexpSigHandlerInstaller)
		cexpSigHandlerInstaller(sighandler);

	if (!(rval=setjmp(context.jbuf))) {
		/* call them back to pass the jmpbuf */
		if (callback)
			callback(argc, argv, &context);
	
		if (script) {
			if ( (rval = process_script(context.parser, script, quiet)) )
				goto cleanup;
		} else {

			while ( (line=readline_r(
							checkPrompt( &context, &prompt, argc > 0 ? argv[0] : "Cexp" ),
							rl_context)) ) {
				/* skip empty lines */
				if (*line) {
					if ( '<' == *(tmp=skipsp(line)) ) {
						process_script(context.parser,tmp+1,quiet);
					} else {
						/* interactively process this line */
						cexpResetParserCtx(context.parser,line);
						cexpparse((void*)context.parser);
						add_history(line);
					}
				}
				free(line); line=0;
			}
		}
		
	} else {
			fprintf(stderr,"\nOops, exception caught\n");
			/* setjmp passes 0: first time
			 *               1: longjmp(buf,0) or longjmp(buf,1)
			 *           other: longjmp(buf,other)
			 */
			rval = (rval<2 ? -1 : CEXP_MAIN_KILLED);
	}
	
cleanup:
		script=0;	/* become interactive if script is killed */
		free(line);   			line=0;
		free(prompt);           prompt=0;
		cexpFreeParserCtx(context.parser); context.parser=0;
	
} while (-1==rval);

free(context.prompt);

/* pop our stack context from the chained list anchored 
 * at the running thread
 */
myContext = myContext->next;
cexpContextSetCurrent(myContext);
if ( ! myContext ) {
	/* we'll exit the topmost instance */
#ifdef HAVE_TECLA
	del_GetLine(context.gl);
#endif
	cexpContextUnregister();
}

return rval;
}