Author: mcayland Date: Thu Mar 25 22:14:00 2010 New Revision: 706 URL: http://tracker.coreboot.org/trac/openbios/changeset/706
Log: Revert the parts of the last commit which changed the exception function to use an exception pointer as it isn't really required. Update forthstrap to add a new -c option that when specified will direct the Forth kernel console output to a file and integrate this into the build system. By default, when a dictionary is built using a base dictionary then a new log file called <dict>-console.log will be generated to help debugging if the build fails.
Also update the exception handler in kernel/bootstrap.c so that it matches the entire range of error codes in forth/bootstrap/interpreter.fs.
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@siriusit.co.uk
Modified: trunk/openbios-devel/config/xml/dictionary.xsl trunk/openbios-devel/include/kernel/kernel.h trunk/openbios-devel/kernel/bootstrap.c trunk/openbios-devel/kernel/forth.c trunk/openbios-devel/kernel/internal.c
Modified: trunk/openbios-devel/config/xml/dictionary.xsl ============================================================================== --- trunk/openbios-devel/config/xml/dictionary.xsl Wed Mar 24 12:49:41 2010 (r705) +++ trunk/openbios-devel/config/xml/dictionary.xsl Thu Mar 25 22:14:00 2010 (r706) @@ -129,6 +129,7 @@ <xsl:if test="$init!=''"> xsl:text -d $(ODIR)/</xsl:text><xsl:value-of select="$init"/>xsl:text.dict</xsl:text> </xsl:if> + xsl:text -c $@-console.log</xsl:text> xsl:text $(</xsl:text> <xsl:value-of select="@name"/> xsl:text-DICTIONARY)," GEN $(TARGET_DIR)$@") </xsl:text>
Modified: trunk/openbios-devel/include/kernel/kernel.h ============================================================================== --- trunk/openbios-devel/include/kernel/kernel.h Wed Mar 24 12:49:41 2010 (r705) +++ trunk/openbios-devel/include/kernel/kernel.h Thu Mar 25 22:14:00 2010 (r706) @@ -34,12 +34,13 @@ extern void modules_init( void );
/* arch kernel hooks */ -extern void (*exception)(cell no); +extern void exception(cell no);
#ifdef FCOMPILER extern void include_file( const char *str ); extern void encode_file( const char *str ); extern int get_inputbyte( void ); +extern void put_outputbyte( int c ); #endif
#ifndef BOOTSTRAP
Modified: trunk/openbios-devel/kernel/bootstrap.c ============================================================================== --- trunk/openbios-devel/kernel/bootstrap.c Wed Mar 24 12:49:41 2010 (r705) +++ trunk/openbios-devel/kernel/bootstrap.c Thu Mar 25 22:14:00 2010 (r706) @@ -54,6 +54,9 @@
static char *srcbasedict;
+/* console variables */ +static FILE *console; + #ifdef NATIVE_BITWIDTH_SMALLER_THAN_HOST_BITWIDTH unsigned long base_address; #endif @@ -487,14 +490,42 @@
/* - * Common Forth exception handler + * Forth exception handler */
-static void exception_common(cell no) +void exception(cell no) { + printk("%s:%d: ", srcfilenames[cursrc - 1], srclines[cursrc - 1]); + + /* See also forth/bootstrap/interpreter.fs */ switch (no) { + case -1: + case -2: + printk("Aborted.\n"); + break; + case -3: + printk("Stack Overflow.\n"); + break; + case -4: + printk("Stack Underflow.\n"); + break; + case -5: + printk("Return Stack Overflow.\n"); + break; + case -6: + printk("Return Stack Underflow.\n"); + break; case -19: - printk(" undefined word.\n"); + printk("undefined word.\n"); + break; + case -21: + printk("out of memory.\n"); + break; + case -33: + printk("undefined method.\n"); + break; + case -34: + printk("no such device.\n"); break; default: printk("error %" FMT_CELL_d " occured.\n", no); @@ -504,30 +535,6 @@
/* - * Exception handler for run_dictionary() - */ - -static void exception_run_dictionary(cell no) -{ - printk("Error executing base dictionary %s: ", srcbasedict); - - exception_common(no); -} - - -/* - * Exception handler for interpret_source() - */ - -static void exception_interpret_source(cell no) -{ - printk("%s:%d: ", srcfilenames[cursrc - 1], srclines[cursrc - 1]); - - exception_common(no); -} - - -/* * This is the C version of the forth interpreter */
@@ -548,9 +555,6 @@ exit(1); }
- /* Set up exception handler for this invocation (allows better error reporting) */ - exception = exception_interpret_source; - /* FIXME: We should read this file at * once. No need to get it char by char */ @@ -731,7 +735,7 @@
if (*test != 0) { /* what is it?? */ - printk("%s:%d - %s is not defined.\n\n", srcfilenames[cursrc - 1], srclines[cursrc - 1], tib); + printk("%s:%d: %s is not defined.\n\n", srcfilenames[cursrc - 1], srclines[cursrc - 1], tib); errors++; #ifdef CONFIG_DEBUG_INTERPRETER continue; @@ -844,14 +848,27 @@ }
tmp = getc( srcfiles[cursrc-1] ); - if (tmp != EOF) + + /* Update current line number */ + if (tmp == '\n') { + srclines[cursrc - 1]++; + } + + if (tmp != EOF) { return tmp; + }
fclose(srcfiles[--cursrc]);
return get_inputbyte(); }
+void put_outputbyte( int c ) +{ + if (console) + fputc(c, console); +} + /* * segmentation fault handler. linux specific? */ @@ -951,7 +968,7 @@ }
-static void run_dictionary(char *basedict) +static void run_dictionary(char *basedict, char *confile) { if(!basedict) return; @@ -978,11 +995,17 @@ if (verbose) printk("Jumping to dictionary %s...\n", basedict);
- /* Set up exception handler for this invocation (allows better error reporting) */ - exception = exception_run_dictionary; + /* If a console file has been specified, open it */ + if (confile) + console = fopen(confile, "w"); + srcbasedict = basedict;
enterforth((xt_t)PC); + + /* Close the console file */ + if (console) + fclose(console); }
static void new_dictionary(const char *source) @@ -1015,6 +1038,8 @@ " use this dictionary as base\n" \ " -D|--target-dictionary output.dict\n" \ " write to output.dict\n" \ + " -c|--console output.log\n" \ + " write kernel console output to log file\n" \ " -s|--segfault install segfault handler\n\n" #else #define USAGE "Usage: %s [options] [dictionary file|source file]\n\n" \ @@ -1026,6 +1051,8 @@ " use this dictionary as base\n" \ " -D output.dict\n" \ " write to output.dict\n" \ + " -c output.log\n" \ + " write kernel console output to log file\n" \ " -s install segfault handler\n\n"
#endif @@ -1037,11 +1064,12 @@ unsigned char *ressources=NULL; /* All memory used by us */ char *dictname = NULL; char *basedict = NULL; + char *consolefile = NULL;
unsigned char *bootstrapdict[2]; int c, cnt;
- const char *optstring = "VvhsI:d:D:?"; + const char *optstring = "VvhsI:d:D:c:?";
while (1) { #ifdef __GLIBC__ @@ -1054,6 +1082,7 @@ {"include", 1, NULL, 'I'}, {"source-dictionary", 1, NULL, 'd'}, {"target-dictionary", 1, NULL, 'D'}, + {"console", 1, NULL, 'c'}, };
/* @@ -1093,11 +1122,17 @@ if (!basedict) { basedict = optarg; } + break; case 'D': if(!dictname) { dictname = optarg; } break; + case 'c': + if (!consolefile) { + consolefile = optarg; + } + break; default: return 1; } @@ -1176,7 +1211,7 @@ for (c=argc-1; c>=optind; c--) include_file(argv[c]);
- run_dictionary(basedict); + run_dictionary(basedict, consolefile); } if(errors) break;
Modified: trunk/openbios-devel/kernel/forth.c ============================================================================== --- trunk/openbios-devel/kernel/forth.c Wed Mar 24 12:49:41 2010 (r705) +++ trunk/openbios-devel/kernel/forth.c Thu Mar 25 22:14:00 2010 (r706) @@ -860,11 +860,11 @@
static void emit(void) { -#ifndef FCOMPILER cell tmp = POP(); +#ifndef FCOMPILER putchar(tmp); #else - (void) POP(); + put_outputbyte(tmp); #endif }
Modified: trunk/openbios-devel/kernel/internal.c ============================================================================== --- trunk/openbios-devel/kernel/internal.c Wed Mar 24 12:49:41 2010 (r705) +++ trunk/openbios-devel/kernel/internal.c Thu Mar 25 22:14:00 2010 (r706) @@ -25,10 +25,6 @@ ucell PC; volatile int interruptforth = 0;
-#ifdef FCOMPILER -void (*exception)(cell no) = NULL; -#endif - #define DEBUG_MODE_NONE 0 #define DEBUG_MODE_STEP 1 #define DEBUG_MODE_TRACE 2