Change the sysdebug exception() callback so that it is now a function pointer, rather than a function. This enables us to setup an appropriate exception handler

for the task in hand; in particular it allows us to distinguish between an error that occurs when attempting to execute a base dictionary, and an error that 
occurs when interpreting source.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@siriusit.co.uk>


git-svn-id: svn://coreboot.org/openbios/trunk/openbios-devel@705 f158a5a8-5612-0410-a976-696ce0be7e32
This commit is contained in:
Mark Cave-Ayland
2010-03-24 11:49:41 +00:00
committed by Mark Cave-Ayland
parent 5c73290696
commit a288b3044b
3 changed files with 61 additions and 17 deletions

View File

@@ -34,7 +34,7 @@ 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 );

View File

@@ -52,6 +52,8 @@ static char *srcfilenames[MAX_SRC_FILES];
static int srclines[MAX_SRC_FILES]; static int srclines[MAX_SRC_FILES];
static unsigned int cursrc = 0; static unsigned int cursrc = 0;
static char *srcbasedict;
#ifdef NATIVE_BITWIDTH_SMALLER_THAN_HOST_BITWIDTH #ifdef NATIVE_BITWIDTH_SMALLER_THAN_HOST_BITWIDTH
unsigned long base_address; unsigned long base_address;
#endif #endif
@@ -484,6 +486,47 @@ static FILE *fopen_include(const char *fil)
} }
/*
* Common Forth exception handler
*/
static void exception_common(cell no)
{
switch (no) {
case -19:
printk(" undefined word.\n");
break;
default:
printk("error %" FMT_CELL_d " occured.\n", no);
}
exit(1);
}
/*
* 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
*/ */
@@ -505,6 +548,9 @@ 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
*/ */
@@ -862,20 +908,6 @@ static void init_memory(void)
PUSH(pointer2cell(memory) + MEMORY_SIZE-1); PUSH(pointer2cell(memory) + MEMORY_SIZE-1);
} }
void exception(cell no)
{
printk("%s:%d: ", srcfilenames[cursrc - 1], srclines[cursrc - 1]);
switch (no) {
case -19:
printk(" undefined word.\n");
break;
default:
printk("error %" FMT_CELL_d " occured.\n", no);
}
exit(1);
}
void void
include_file( const char *name ) include_file( const char *name )
@@ -927,8 +959,12 @@ static void run_dictionary(char *basedict)
read_dictionary(basedict); read_dictionary(basedict);
PC = (ucell)findword("initialize"); PC = (ucell)findword("initialize");
if (!PC) if (!PC) {
if (verbose) {
printk("Unable to find initialize word in dictionary %s; ignoring\n", basedict);
}
return; return;
}
if(!srcfiles[0]) { if(!srcfiles[0]) {
cursrc = 1; cursrc = 1;
@@ -940,7 +976,11 @@ static void run_dictionary(char *basedict)
init_memory(); init_memory();
if (verbose) if (verbose)
printk("Jumping to dictionary..."); printk("Jumping to dictionary %s...\n", basedict);
/* Set up exception handler for this invocation (allows better error reporting) */
exception = exception_run_dictionary;
srcbasedict = basedict;
enterforth((xt_t)PC); enterforth((xt_t)PC);
} }

View File

@@ -25,6 +25,10 @@ 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