static void show_fcode_def(fcode_env_t *env, char *type) { int i = env->last_token; if (get_interpreter_debug_level() & DEBUG_DUMP_TOKENS) { if (env->table[i].name) log_message(MSG_INFO, "%s: %s %03x %p\n", type, env->table[i].name, i, env->table[i].apf); else log_message(MSG_INFO, "%s: <noname> %03x %p\n", type, i, env->table[i].apf); } }
/* * Output debug message */ void debug_msg(int debug_level, char *fmt, ...) { va_list ap; char msg[LOG_LINESIZE]; if ((debug_level & get_interpreter_debug_level()) == 0) return; va_start(ap, fmt); vsprintf(msg, fmt, ap); log_message(MSG_DEBUG, msg); }
void byte_load(fcode_env_t *env) { uchar_t *fcode_buffer; uchar_t *fcode_ptr; int fcode_incr; int offset_incr; int fcode_xt; int interpretting; int depth; int length; int past_eob = 0; int db; /* save any existing interpret state */ fcode_buffer = env->fcode_buffer; fcode_ptr = env->fcode_ptr; fcode_incr = env->fcode_incr; offset_incr = env->offset_incr; interpretting = env->interpretting; depth = DEPTH-2; /* Now init them */ CHECK_DEPTH(env, 2, "byte-load"); fcode_xt = POP(DS); env->fcode_ptr = env->fcode_buffer = (uchar_t *)POP(DS); if (fcode_xt != 1) { log_message(MSG_WARN, "byte-load: ignoring xt\n"); } length = (env->fcode_buffer[4] << 24) | (env->fcode_buffer[5] << 16) | (env->fcode_buffer[6] << 8) | env->fcode_buffer[7]; if (!check_fcode_header("byte-load", env->fcode_ptr, length)) log_message(MSG_WARN, "byte-load: header NOT OK\n"); env->fcode_incr = 1; env->offset_incr = 1; env->interpretting = 1; env->level = 0; db = get_interpreter_debug_level() & (DEBUG_BYTELOAD_DS|DEBUG_BYTELOAD_RS|DEBUG_BYTELOAD_TOKENS); debug_msg(db, "byte_load: %p, %d\n", env->fcode_buffer, fcode_xt); debug_msg(db, " header: %x, %x\n", env->fcode_buffer[0], env->fcode_buffer[1]); debug_msg(db, " crc: %x\n", (env->fcode_buffer[2]<<8)|(env->fcode_buffer[3])); debug_msg(db, " length: %x\n", length); env->fcode_ptr += 8; debug_msg(db, "Interpretting: %d\n", env->interpretting); while (env->interpretting) { int token; fcode_token *entry; acf_t apf; if (!past_eob && env->fcode_ptr >= env->fcode_buffer + length) { log_message(MSG_WARN, "byte-load: past EOB\n"); past_eob = 1; } env->last_fcode_ptr = env->fcode_ptr; token = get_next_token(env); entry = &env->table[token]; apf = entry->apf; DEBUGF(BYTELOAD_DS, output_data_stack(env, MSG_FC_DEBUG)); DEBUGF(BYTELOAD_RS, output_return_stack(env, 1, MSG_FC_DEBUG)); DEBUGF(BYTELOAD_TOKENS, log_message(MSG_FC_DEBUG, "%s: %04x %03x %s (%x)", ((env->state && (entry->flags & IMMEDIATE) == 0)) ? "Compile" : "Execute", env->last_fcode_ptr - env->fcode_buffer, token, entry->name ? entry->name : "???", entry->flags)); if (db) log_message(MSG_FC_DEBUG, "\n"); if (apf) { DEBUGF(TOKEN_USAGE, entry->usage++); PUSH(DS, (fstack_t)apf); if ((env->state) && ((entry->flags & IMMEDIATE) == 0)) { /* Compile in references */ compile_comma(env); } else { execute(env); } } } if (DEPTH != depth) { log_message(MSG_ERROR, "FCODE has net stack change of %d\n", DEPTH-depth); } /* restore old state */ env->fcode_ptr = fcode_ptr; env->fcode_buffer = fcode_buffer; env->fcode_incr = fcode_incr; env->offset_incr = offset_incr; env->interpretting = interpretting; }