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>


git-svn-id: svn://coreboot.org/openbios/trunk/openbios-devel@706 f158a5a8-5612-0410-a976-696ce0be7e32
This commit is contained in:
Mark Cave-Ayland
2010-03-25 21:14:00 +00:00
committed by Mark Cave-Ayland
parent a288b3044b
commit 34d5a76f7e
5 changed files with 77 additions and 44 deletions

View File

@@ -129,6 +129,7 @@
<xsl:if test="$init!=''"> <xsl:if test="$init!=''">
<xsl:text> -d $(ODIR)/</xsl:text><xsl:value-of select="$init"/><xsl:text>.dict</xsl:text> <xsl:text> -d $(ODIR)/</xsl:text><xsl:value-of select="$init"/><xsl:text>.dict</xsl:text>
</xsl:if> </xsl:if>
<xsl:text> -c $@-console.log</xsl:text>
<xsl:text> $(</xsl:text> <xsl:text> $(</xsl:text>
<xsl:value-of select="@name"/> <xsl:value-of select="@name"/>
<xsl:text>-DICTIONARY)," GEN $(TARGET_DIR)$@")&#10;&#10;</xsl:text> <xsl:text>-DICTIONARY)," GEN $(TARGET_DIR)$@")&#10;&#10;</xsl:text>

View File

@@ -34,12 +34,13 @@ extern xt_t findword(const char *s1);
extern void modules_init( void ); extern void modules_init( void );
/* arch kernel hooks */ /* arch kernel hooks */
extern void (*exception)(cell no); extern void exception(cell no);
#ifdef FCOMPILER #ifdef FCOMPILER
extern void include_file( const char *str ); extern void include_file( const char *str );
extern void encode_file( const char *str ); extern void encode_file( const char *str );
extern int get_inputbyte( void ); extern int get_inputbyte( void );
extern void put_outputbyte( int c );
#endif #endif
#ifndef BOOTSTRAP #ifndef BOOTSTRAP

View File

@@ -54,6 +54,9 @@ static unsigned int cursrc = 0;
static char *srcbasedict; static char *srcbasedict;
/* console variables */
static FILE *console;
#ifdef NATIVE_BITWIDTH_SMALLER_THAN_HOST_BITWIDTH #ifdef NATIVE_BITWIDTH_SMALLER_THAN_HOST_BITWIDTH
unsigned long base_address; unsigned long base_address;
#endif #endif
@@ -487,15 +490,43 @@ static FILE *fopen_include(const char *fil)
/* /*
* 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) { 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: case -19:
printk("undefined word.\n"); printk("undefined word.\n");
break; 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: default:
printk("error %" FMT_CELL_d " occured.\n", no); printk("error %" FMT_CELL_d " occured.\n", no);
} }
@@ -503,30 +534,6 @@ static void exception_common(cell no)
} }
/*
* 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 * This is the C version of the forth interpreter
*/ */
@@ -548,9 +555,6 @@ static int interpret_source(char *fil)
exit(1); exit(1);
} }
/* Set up exception handler for this invocation (allows better error reporting) */
exception = exception_interpret_source;
/* FIXME: We should read this file at /* FIXME: We should read this file at
* once. No need to get it char by char * once. No need to get it char by char
*/ */
@@ -731,7 +735,7 @@ static int interpret_source(char *fil)
if (*test != 0) { if (*test != 0) {
/* what is it?? */ /* 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++; errors++;
#ifdef CONFIG_DEBUG_INTERPRETER #ifdef CONFIG_DEBUG_INTERPRETER
continue; continue;
@@ -844,14 +848,27 @@ int get_inputbyte( void )
} }
tmp = getc( srcfiles[cursrc-1] ); tmp = getc( srcfiles[cursrc-1] );
if (tmp != EOF)
/* Update current line number */
if (tmp == '\n') {
srclines[cursrc - 1]++;
}
if (tmp != EOF) {
return tmp; return tmp;
}
fclose(srcfiles[--cursrc]); fclose(srcfiles[--cursrc]);
return get_inputbyte(); return get_inputbyte();
} }
void put_outputbyte( int c )
{
if (console)
fputc(c, console);
}
/* /*
* segmentation fault handler. linux specific? * segmentation fault handler. linux specific?
*/ */
@@ -951,7 +968,7 @@ encode_file( const char *name )
} }
static void run_dictionary(char *basedict) static void run_dictionary(char *basedict, char *confile)
{ {
if(!basedict) if(!basedict)
return; return;
@@ -978,11 +995,17 @@ static void run_dictionary(char *basedict)
if (verbose) if (verbose)
printk("Jumping to dictionary %s...\n", basedict); printk("Jumping to dictionary %s...\n", basedict);
/* Set up exception handler for this invocation (allows better error reporting) */ /* If a console file has been specified, open it */
exception = exception_run_dictionary; if (confile)
console = fopen(confile, "w");
srcbasedict = basedict; srcbasedict = basedict;
enterforth((xt_t)PC); enterforth((xt_t)PC);
/* Close the console file */
if (console)
fclose(console);
} }
static void new_dictionary(const char *source) static void new_dictionary(const char *source)
@@ -1015,6 +1038,8 @@ static void new_dictionary(const char *source)
" use this dictionary as base\n" \ " use this dictionary as base\n" \
" -D|--target-dictionary output.dict\n" \ " -D|--target-dictionary output.dict\n" \
" write to 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" " -s|--segfault install segfault handler\n\n"
#else #else
#define USAGE "Usage: %s [options] [dictionary file|source file]\n\n" \ #define USAGE "Usage: %s [options] [dictionary file|source file]\n\n" \
@@ -1026,6 +1051,8 @@ static void new_dictionary(const char *source)
" use this dictionary as base\n" \ " use this dictionary as base\n" \
" -D output.dict\n" \ " -D output.dict\n" \
" write to 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" " -s install segfault handler\n\n"
#endif #endif
@@ -1037,11 +1064,12 @@ int main(int argc, char *argv[])
unsigned char *ressources=NULL; /* All memory used by us */ unsigned char *ressources=NULL; /* All memory used by us */
char *dictname = NULL; char *dictname = NULL;
char *basedict = NULL; char *basedict = NULL;
char *consolefile = NULL;
unsigned char *bootstrapdict[2]; unsigned char *bootstrapdict[2];
int c, cnt; int c, cnt;
const char *optstring = "VvhsI:d:D:?"; const char *optstring = "VvhsI:d:D:c:?";
while (1) { while (1) {
#ifdef __GLIBC__ #ifdef __GLIBC__
@@ -1054,6 +1082,7 @@ int main(int argc, char *argv[])
{"include", 1, NULL, 'I'}, {"include", 1, NULL, 'I'},
{"source-dictionary", 1, NULL, 'd'}, {"source-dictionary", 1, NULL, 'd'},
{"target-dictionary", 1, NULL, 'D'}, {"target-dictionary", 1, NULL, 'D'},
{"console", 1, NULL, 'c'},
}; };
/* /*
@@ -1093,11 +1122,17 @@ int main(int argc, char *argv[])
if (!basedict) { if (!basedict) {
basedict = optarg; basedict = optarg;
} }
break;
case 'D': case 'D':
if(!dictname) { if(!dictname) {
dictname = optarg; dictname = optarg;
} }
break; break;
case 'c':
if (!consolefile) {
consolefile = optarg;
}
break;
default: default:
return 1; return 1;
} }
@@ -1176,7 +1211,7 @@ int main(int argc, char *argv[])
for (c=argc-1; c>=optind; c--) for (c=argc-1; c>=optind; c--)
include_file(argv[c]); include_file(argv[c]);
run_dictionary(basedict); run_dictionary(basedict, consolefile);
} }
if(errors) if(errors)
break; break;

View File

@@ -860,11 +860,11 @@ static void herewrite(void)
static void emit(void) static void emit(void)
{ {
#ifndef FCOMPILER
cell tmp = POP(); cell tmp = POP();
#ifndef FCOMPILER
putchar(tmp); putchar(tmp);
#else #else
(void) POP(); put_outputbyte(tmp);
#endif #endif
} }

View File

@@ -25,10 +25,6 @@ static forth_word * const words[];
ucell PC; ucell PC;
volatile int interruptforth = 0; volatile int interruptforth = 0;
#ifdef FCOMPILER
void (*exception)(cell no) = NULL;
#endif
#define DEBUG_MODE_NONE 0 #define DEBUG_MODE_NONE 0
#define DEBUG_MODE_STEP 1 #define DEBUG_MODE_STEP 1
#define DEBUG_MODE_TRACE 2 #define DEBUG_MODE_TRACE 2