From 56042dd6863d860c18fb5ef6d5bb1834492353ff Mon Sep 17 00:00:00 2001 From: chz Date: Sat, 25 Sep 2010 21:58:25 -0700 Subject: [PATCH] scan tool doesn't crash any more (probably wrong though) --- fs/vfat.fsl | 2 +- src/Makefile | 3 +- src/runtime/debug.c | 49 +++++++++++++++++++++++++++ src/runtime/debug.h | 49 +++++++++++++++++++++++++++ src/runtime/dyn.c | 13 ++++--- src/runtime/dyn.h | 25 ++++++++++++++ src/runtime/io.c | 3 +- src/runtime/runtime.c | 8 ++++- src/runtime/runtime.h | 15 +++------ src/runtime/scantool.c | 75 +++++++++++++++++++++++++++++++---------- src/runtime/type_info.c | 46 ++++++++++++++++++++----- src/runtime/virt.c | 67 +++++++++++++++++++++++++++++++----- src/tool/Makefile | 3 +- tests/do_all_tests.sh | 4 ++- 14 files changed, 307 insertions(+), 55 deletions(-) create mode 100644 src/runtime/debug.c create mode 100644 src/runtime/debug.h create mode 100644 src/runtime/dyn.h diff --git a/fs/vfat.fsl b/fs/vfat.fsl index 0253c9e..2ba1f96 100644 --- a/fs/vfat.fsl +++ b/fs/vfat.fsl @@ -95,7 +95,7 @@ virtual_if( ? file_size != 0xffffffff, cluster, i, 1, (file_size / bytes_per_cluster())+1, get_nth(i)) as vfile virtual_if( - ? file_size != 0xffffffff && (ATTR_DIRECTORY & attr) != 0, + ? file_size > 0 && file_size != 0xffffffff && (ATTR_DIRECTORY & attr) != 0, fat_de, i, 1, (file_size / bytes_per_cluster())+1, get_nth(i)) as vdir points_if( diff --git a/src/Makefile b/src/Makefile index b22fd66..2ae52eb 100644 --- a/src/Makefile +++ b/src/Makefile @@ -35,7 +35,8 @@ RTOBJS= runtime/runtime.o \ runtime/virt.o \ runtime/dyn.o \ runtime/io.o \ - runtime/max.o + runtime/max.o \ + runtime/debug.o TOOLOBJS= runtime/scantool.o runtime/browser.o runtime/modify.o diff --git a/src/runtime/debug.c b/src/runtime/debug.c new file mode 100644 index 0000000..e68a8bb --- /dev/null +++ b/src/runtime/debug.c @@ -0,0 +1,49 @@ +#include +#include +#include +#include "debug.h" + +unsigned int fsl_debug_depth = 0; + +static void fsl_debug_indent(void); + +void fsl_debug_enter(const char *func_name) +{ + fsl_debug_indent(); + printf("%s: entering\n", func_name); + fsl_debug_indent(); + printf("{\n"); + fsl_debug_depth++; +} + +void fsl_debug_leave(const char *func_name) +{ + fsl_debug_indent(); + printf("%s: leaving\n", func_name); + fsl_debug_depth--; + fsl_debug_indent(); + printf("}\n"); +} + +void fsl_debug_write(const char* fmt, ...) +{ + va_list vl; + + va_start(vl, fmt); + fsl_debug_vwrite(fmt, vl); + va_end(vl); +} + +static void fsl_debug_indent(void) +{ + unsigned int i; + for (i = 0; i < fsl_debug_depth; i++) + printf(" "); +} + +void fsl_debug_vwrite(const char* fmt, va_list vl) +{ + fsl_debug_indent(); + vprintf(fmt, vl); + printf("\n"); +} \ No newline at end of file diff --git a/src/runtime/debug.h b/src/runtime/debug.h new file mode 100644 index 0000000..dbf9245 --- /dev/null +++ b/src/runtime/debug.h @@ -0,0 +1,49 @@ +#ifndef FSL_RT_DEBUG_H +#define FSL_RT_DEBUG_H + +#include + +extern unsigned int fsl_debug_depth; + +#define DEBUG_ENTER() fsl_debug_enter(__FUNCTION__) +#define DEBUG_LEAVE() fsl_debug_leave(__FUNCTION__) +#define DEBUG_WRITE fsl_debug_write + +#ifdef DEBUG_TOOL +#define DEBUG_TOOL_ENTER() fsl_debug_enter(__FUNCTION__) +#define DEBUG_TOOL_LEAVE() fsl_debug_leave(__FUNCTION__) +#define DEBUG_TOOL_WRITE fsl_debug_write +#else +#define DEBUG_TOOL_ENTER() do {} while (0) +#define DEBUG_TOOL_LEAVE() do {} while (0) +#define DEBUG_TOOL_WRITE +#endif + +#ifdef DEBUG_TYPEINFO +#define DEBUG_TYPEINFO_ENTER() fsl_debug_enter(__FUNCTION__) +#define DEBUG_TYPEINFO_LEAVE() fsl_debug_leave(__FUNCTION__) +#define DEBUG_TYPEINFO_WRITE fsl_debug_write +#else +#define DEBUG_TYPEINFO_ENTER() do {} while (0) +#define DEBUG_TYPEINFO_LEAVE() do {} while (0) +#define DEBUG_TYPEINFO_WRITE +#endif + +#ifdef DEBUG_VIRT +#define DEBUG_VIRT_ENTER() fsl_debug_enter(__FUNCTION__) +#define DEBUG_VIRT_LEAVE() fsl_debug_leave(__FUNCTION__) +#define DEBUG_VIRT_WRITE fsl_debug_write +#else +#define DEBUG_VIRT_ENTER() do {} while (0) +#define DEBUG_VIRT_LEAVE() do {} while (0) +#define DEBUG_VIRT_WRITE +#endif + + + +void fsl_debug_enter(const char *func_name); +void fsl_debug_leave(const char *func_name); +void fsl_debug_write(const char* fmt, ...); +void fsl_debug_vwrite(const char* fmt, va_list vl); + +#endif diff --git a/src/runtime/dyn.c b/src/runtime/dyn.c index 1618cdf..795e212 100644 --- a/src/runtime/dyn.c +++ b/src/runtime/dyn.c @@ -4,9 +4,8 @@ #include #include #include "runtime.h" +#include "debug.h" -#define DYN_INVALID_TYPE (~((uint64_t)0)) -#define env_get_dyn_clo(x) (&(fsl_env->fctx_dyn_closures[(x)])) extern struct fsl_rt_ctx *fsl_env; extern uint64_t fsl_num_types; @@ -15,6 +14,8 @@ struct fsl_rt_closure* fsl_dyn_alloc(void) struct fsl_rt_closure *dyns; unsigned int i; + if (fsl_env) fsl_env->fctx_stat.s_dyn_alloc_c++; + dyns = malloc(sizeof(struct fsl_rt_closure)*fsl_num_types); /* initialize all dynamic closures */ @@ -71,6 +72,8 @@ struct fsl_rt_closure* fsl_dyn_copy(const struct fsl_rt_closure* src) tt_by_num(i)->tt_param_c*sizeof(uint64_t)); } + fsl_env->fctx_stat.s_dyn_copy_c++; + return ret; } @@ -142,10 +145,12 @@ void fsl_dyn_dump(void) unsigned int i; assert (fsl_env != NULL); + DEBUG_WRITE("dumping dyns."); for (i = 0; i < fsl_env->fctx_num_types; i++) { - printf("type %2d (%s): %"PRIu64"\n", + DEBUG_WRITE("type %2d (%s): %"PRIu64" (%p)", i, tt_by_num(i)->tt_name, - env_get_dyn_clo(i)->clo_offset); + env_get_dyn_clo(i)->clo_offset, + env_get_dyn_clo(i)->clo_xlate); } } diff --git a/src/runtime/dyn.h b/src/runtime/dyn.h new file mode 100644 index 0000000..19de004 --- /dev/null +++ b/src/runtime/dyn.h @@ -0,0 +1,25 @@ +#ifndef DYN_H +#define DYN_H + +#define DYN_INVALID_TYPE (~((uint64_t)0)) +#define env_get_dyn_clo(x) (&(fsl_env->fctx_dyn_closures[(x)])) + +#define FSL_DYN_SAVE(x) struct fsl_rt_closure* x; \ + x = fsl_dyn_copy(fsl_env->fctx_dyn_closures) +#define FSL_DYN_LOAD(x) fsl_dyn_free( \ + fsl_rt_dyn_swap( \ + fsl_dyn_copy(x))) + +#define FSL_DYN_RESTORE(x) do { \ + \ + fsl_dyn_free(fsl_rt_dyn_swap(x)); \ + x = NULL; \ + } while (0) + +struct fsl_rt_closure* fsl_rt_dyn_swap(struct fsl_rt_closure* dyns); +void fsl_dyn_dump(void); +struct fsl_rt_closure* fsl_dyn_alloc(void); +void fsl_dyn_free(struct fsl_rt_closure*); +struct fsl_rt_closure* fsl_dyn_copy(const struct fsl_rt_closure* src); + +#endif diff --git a/src/runtime/io.c b/src/runtime/io.c index 929ec77..9808302 100644 --- a/src/runtime/io.c +++ b/src/runtime/io.c @@ -3,6 +3,8 @@ #include #include #include + +#include "debug.h" #include "runtime.h" typedef uint64_t logaddr_t; @@ -40,7 +42,6 @@ uint64_t __getLocal( assert ((bit_off + (num_bits-1)) == (bit_off_last) && "Discontiguous getLocal not permitted"); } - /* common path */ if (fseeko(fsl_get_io()->io_backing, bit_off / 8, SEEK_SET) != 0) { diff --git a/src/runtime/runtime.c b/src/runtime/runtime.c index 1968029..b8de4c6 100644 --- a/src/runtime/runtime.c +++ b/src/runtime/runtime.c @@ -4,6 +4,7 @@ #include #include #include +#include "debug.h" #include "runtime.h" extern uint64_t fsl_num_types; @@ -43,8 +44,9 @@ typesize_t __computeArrayBits( assert (elem_type < fsl_rt_table_entries); total_bits = 0; - cur_off = clo->clo_offset;; + cur_off = clo->clo_offset; tt = tt_by_num(elem_type); + /* save old dyn closure value */ __getDynClosure(elem_type, &old_dyn); for (i = 0; i < num_elems; i++) { @@ -114,6 +116,10 @@ static void fsl_rt_dump_stats(struct fsl_rt_ctx* fctx) fctx->fctx_stat.s_get_closure_c); fprintf(out_file, "get_offset %"PRIu64"\n", fctx->fctx_stat.s_get_offset_c); + fprintf(out_file, "dyn_copy %"PRIu64"\n", + fctx->fctx_stat.s_dyn_copy_c); + fprintf(out_file, "dyn_alloc %"PRIu64"\n", + fctx->fctx_stat.s_dyn_alloc_c); if (stat_fname != NULL) fclose(out_file); diff --git a/src/runtime/runtime.h b/src/runtime/runtime.h index c0aea3e..a20ed53 100644 --- a/src/runtime/runtime.h +++ b/src/runtime/runtime.h @@ -35,6 +35,8 @@ struct fsl_rt_stat uint64_t s_get_param_c; uint64_t s_get_closure_c; uint64_t s_get_offset_c; + uint64_t s_dyn_copy_c; + uint64_t s_dyn_alloc_c; }; #include "io.h" @@ -57,8 +59,6 @@ struct fsl_rt_closure }; -#include "virt.h" - #define NEW_CLO(x,y,z) NEW_VCLO(x,y,z,NULL) #define NEW_VCLO(x,y,z,t) \ @@ -70,6 +70,8 @@ struct fsl_rt_closure struct fsl_rt_closure x; \ uint64_t x##_params[tt_by_num(y)->tt_param_c]; +#include "dyn.h" +#include "virt.h" #define TYPENUM_INVALID (~0) #define OFFSET_INVALID (~0) @@ -194,17 +196,8 @@ uint64_t fsl_fail(void); /* not exposed to llvm */ struct fsl_rt_ctx* fsl_rt_init(const char* fsl_rt); -struct fsl_rt_closure* fsl_rt_dyn_swap(struct fsl_rt_closure* dyns); void fsl_rt_uninit(struct fsl_rt_ctx* ctx); -void fsl_dyn_dump(void); -struct fsl_rt_closure* fsl_dyn_alloc(void); -void fsl_dyn_free(struct fsl_rt_closure*); -struct fsl_rt_closure* fsl_dyn_copy(const struct fsl_rt_closure* src); - -/* virt functions */ - - /* implemented by tool: */ int tool_entry(int argc, char* argv[]); diff --git a/src/runtime/scantool.c b/src/runtime/scantool.c index 66fdc92..3e8ea31 100644 --- a/src/runtime/scantool.c +++ b/src/runtime/scantool.c @@ -4,6 +4,7 @@ #include #include "runtime.h" +#include "debug.h" #include "type_info.h" @@ -38,6 +39,9 @@ static void scan_type_pointsto( uint64_t min_idx, max_idx; TI_INTO_CLO (ti); + DEBUG_TOOL_ENTER(); + FSL_DYN_SAVE(dyn_saved); + pt = pt_from_idx(ti, pt_idx); assert (pt->pt_range != NULL); @@ -45,17 +49,24 @@ static void scan_type_pointsto( min_idx = pt->pt_min(clo); max_idx = pt->pt_max(clo); - if (min_idx > max_idx) return; + if (min_idx > max_idx) { + FSL_DYN_RESTORE(dyn_saved); + DEBUG_TOOL_LEAVE(); + return; + } - INDENT(ti); - printf("points_to %s [%"PRIu64", %"PRIu64"]\n", - (pt->pt_name) ? pt->pt_name : "", min_idx, max_idx); + DEBUG_TOOL_WRITE( + "points_to %s %s [%"PRIu64", %"PRIu64"]", + (pt->pt_name) ? pt->pt_name : "", + tt->tt_name, + min_idx, max_idx); for (k = min_idx; k <= max_idx; k++) { struct type_info *new_ti; struct type_desc next_td; uint64_t params[tt->tt_param_c]; + DEBUG_TOOL_WRITE("allocating pt[%d]", k); next_td.td_typenum = pt->pt_type_dst; td_init(&next_td, @@ -63,14 +74,22 @@ static void scan_type_pointsto( pt->pt_range(clo, k, params), params); + FSL_DYN_LOAD(dyn_saved); new_ti = typeinfo_alloc_pointsto(&next_td, pt_idx, k, ti); - if (new_ti == NULL) + if (new_ti == NULL) { + DEBUG_TOOL_WRITE("skipped"); continue; + }else { + DEBUG_TOOL_WRITE("found pointsto"); + } scan_type(new_ti); typeinfo_free(new_ti); } + + FSL_DYN_RESTORE(dyn_saved); + DEBUG_TOOL_LEAVE(); } static void scan_type_pointsto_all(const struct type_info* ti) @@ -86,9 +105,12 @@ static void scan_type_pointsto_all(const struct type_info* ti) static void dump_field( const struct fsl_rt_table_field* field, - diskoff_t bitoff) + diskoff_t bitoff, + int idx) { - printf("%s::", field->tf_fieldname); + if (idx < 0) printf("%s::", field->tf_fieldname); + else printf("%s[%d]::", field->tf_fieldname, idx); + printf("%s", (field->tf_typenum != TYPENUM_INVALID) ? tt_by_num(field->tf_typenum)->tt_name : @@ -129,7 +151,9 @@ static void handle_field( /* dump data */ INDENT(ti); - dump_field(field, td_offset(&next_td)); + if (num_elems == 1) dump_field(field, td_offset(&next_td), -1); + else dump_field(field, td_offset(&next_td), i); + if (next_td.td_typenum == TYPENUM_INVALID) return; @@ -147,8 +171,7 @@ static void handle_field( continue; } - INDENT(ti); - printf("following field %s\n", field->tf_fieldname); + DEBUG_TOOL_WRITE("following field %s", field->tf_fieldname); scan_type(new_ti); @@ -162,42 +185,55 @@ static void handle_virt(struct type_info* ti, struct fsl_rt_table_virt* vt) unsigned int i; int err_code; + DEBUG_TOOL_ENTER(); + + FSL_DYN_SAVE(dyn_saved); err_code = TI_ERR_OK; i = 0; - while (err_code == TI_ERR_OK || err_code == TI_ERR_BADIDX) { + while (err_code == TI_ERR_OK || err_code == TI_ERR_BADVERIFY) { struct type_info *ti_cur; + DEBUG_TOOL_WRITE("alloc virt[%d] %s", i, vt->vt_name); + FSL_DYN_LOAD(dyn_saved);; ti_cur = typeinfo_alloc_virt_idx(vt, ti, i, &err_code); if (ti_cur == NULL) { + DEBUG_TOOL_WRITE( + "(skipping %s %d err=%d)", + vt->vt_name, i, err_code); i++; - printf("next\n"); continue; } - INDENT(ti); - if (vt->vt_name != NULL) printf("virt %s (%d)\n", vt->vt_name, i); - else printf("virt (%d)\n", i); + if (vt->vt_name != NULL) DEBUG_TOOL_WRITE("virt initialized! %s (%d)", vt->vt_name, i); + else DEBUG_TOOL_WRITE("virt initialized! (%d)", i); + DEBUG_TOOL_WRITE("voff=%"PRIu64, ti_cur->ti_td.td_clo.clo_offset); assert (ti_cur->ti_td.td_clo.clo_xlate != NULL); scan_type(ti_cur); + DEBUG_TOOL_WRITE("virt done"); typeinfo_free(ti_cur); + DEBUG_TOOL_WRITE("virt[%d] freed", i); i++; } -} + FSL_DYN_RESTORE(dyn_saved); + DEBUG_TOOL_LEAVE(); +} static void scan_type_virt(struct type_info* ti) { struct fsl_rt_table_type *tt; unsigned int i; + DEBUG_TOOL_ENTER(); tt = tt_by_ti(ti); for (i = 0; i < tt->tt_virt_c; i++) { handle_virt(ti, &tt->tt_virt[i]); } + DEBUG_TOOL_LEAVE(); } /* dump all data for strong usertypes that are aggregate to the given type */ @@ -216,16 +252,19 @@ static void scan_type(struct type_info* ti) { unsigned int i; - INDENT(ti); - printf("scanning: %s (%d usertypes) voff=%"PRIu64" bits. poff=%"PRIu64" bits. xlate=%p\n", + DEBUG_TOOL_ENTER(); + DEBUG_TOOL_WRITE("scanning: %s (%d usertypes) voff=%"PRIu64" bits. poff=%"PRIu64" bits. xlate=%p", tt_by_ti(ti)->tt_name, tt_by_ti(ti)->tt_field_c, ti_offset(ti), ti_phys_offset(ti), ti_xlate(ti)); scan_type_strongtypes(ti); + DEBUG_TOOL_WRITE("do pointsto_all."); scan_type_pointsto_all(ti); + DEBUG_TOOL_WRITE("do scan virts."); scan_type_virt(ti); + DEBUG_TOOL_LEAVE(); } int tool_entry(int argc, char* argv[]) diff --git a/src/runtime/type_info.c b/src/runtime/type_info.c index 7f1438e..814c58b 100644 --- a/src/runtime/type_info.c +++ b/src/runtime/type_info.c @@ -5,6 +5,7 @@ #include #include +#include "debug.h" #include "type_info.h" static char hexmap[] = {"0123456789abcdef"}; @@ -322,9 +323,11 @@ static bool ti_has_loop(const struct type_info* chain) if (cur->ti_prev == NULL) return false; + DEBUG_TYPEINFO_WRITE("COMPUTING PHYSOFF %p", ti_xlate(cur)); top_poff = ti_phys_offset(cur); top_typenum = ti_typenum(cur); cur = cur->ti_prev; + DEBUG_TYPEINFO_WRITE("TI_HAS_LOOP: LOOP"); for (; cur != NULL; cur = cur->ti_prev) { /* TODO: cache physical offsets? */ @@ -375,20 +378,26 @@ static struct type_info* typeinfo_alloc_generic( static bool typeinfo_verify(const struct type_info* ti) { + DEBUG_TYPEINFO_ENTER(); + DEBUG_TYPEINFO_WRITE("check loop %p", ti_xlate(ti)); if (ti_has_loop(ti) == true) { - printf("XXX addr already in chain! voff=%"PRIu64 - " poff=%"PRIu64" (%s). xlate=%p\n", + DEBUG_TYPEINFO_WRITE("XXX addr already in chain! voff=%"PRIu64 + " poff=%"PRIu64" (%s). xlate=%p", ti_offset(ti), ti_phys_offset(ti), ti_type_name(ti), ti->ti_td.td_clo.clo_xlate); + DEBUG_TYPEINFO_LEAVE(); return false; } - - if (verify_asserts(ti) == false) + DEBUG_TYPEINFO_WRITE("verify: check asserts %p", ti_xlate(ti)); + if (verify_asserts(ti) == false) { + DEBUG_TYPEINFO_LEAVE(); return false; + } + DEBUG_TYPEINFO_LEAVE(); return true; } @@ -454,11 +463,14 @@ struct type_info* typeinfo_alloc_virt_idx( struct type_info* ret; typesize_t array_bit_off; + DEBUG_TYPEINFO_ENTER(); + assert (tt_by_num(virt->vt_type_virttype)->tt_param_c == 0 && "Parameterized virtual types not yet supported"); set_err_code(err_code, TI_ERR_OK); + DEBUG_TYPEINFO_WRITE("td_vinit"); td_vinit(&td, virt->vt_type_virttype, 0, NULL, fsl_virt_alloc(&ti_to_td(ti_prev)->td_clo, virt)); @@ -466,25 +478,33 @@ struct type_info* typeinfo_alloc_virt_idx( if (td_xlate(&td) == NULL) { /* could not allocate virt */ set_err_code(err_code, TI_ERR_BADVIRT); - return NULL; + ret = NULL; + goto done; } if (idx != 0) { + DEBUG_TYPEINFO_WRITE("idx = %d", idx); + array_bit_off = fsl_virt_get_nth(td_xlate(&td), idx); + assert (array_bit_off != 0 && "Type must be at non-zero voff"); if (array_bit_off == OFFSET_INVALID) { fsl_virt_free(td_xlate(&td)); set_err_code(err_code, TI_ERR_BADIDX); - return NULL; + ret = NULL; + goto done; } td_offset(&td) = array_bit_off; + DEBUG_TYPEINFO_WRITE("idx = %d. Done. voff=%"PRIu64, idx, array_bit_off); } + DEBUG_TYPEINFO_WRITE("alloc_gen"); assert (td_xlate(&td) != NULL); ret = typeinfo_alloc_generic(&td, ti_prev); if (ret == NULL) { set_err_code(err_code, TI_ERR_BADALLOC); - return NULL; + ret = NULL; + goto done; } assert (ti_xlate(ret) != NULL); @@ -493,13 +513,20 @@ struct type_info* typeinfo_alloc_virt_idx( ret->ti_pointsto = false; ret->ti_virttype_c = 0; /* XXX */ + DEBUG_TYPEINFO_WRITE("now set_dyns"); typeinfo_set_dyn(ret); + DEBUG_TYPEINFO_WRITE("virt_alloc_idx: typeinfo_verify"); if (typeinfo_verify(ret) == false) { + DEBUG_TYPEINFO_WRITE("virt_alloc_idx: typeinfo_verify BAD!\n"); typeinfo_free(ret); set_err_code(err_code, TI_ERR_BADVERIFY); - return NULL; + ret = NULL; + goto done; } + DEBUG_TYPEINFO_WRITE("virt_alloc_idx: typeinfo_verify OK!"); +done: + DEBUG_TYPEINFO_LEAVE(); return ret; } @@ -565,6 +592,9 @@ diskoff_t ti_phys_offset(const struct type_info* ti) return voff; } + DEBUG_TYPEINFO_WRITE("enter xlate %p", ti_xlate(ti)); off = fsl_virt_xlate(&ti->ti_td.td_clo, voff); + DEBUG_TYPEINFO_WRITE("leave xlate %p", ti_xlate(ti)); + return off; } diff --git a/src/runtime/virt.c b/src/runtime/virt.c index 1a104fa..14500c8 100644 --- a/src/runtime/virt.c +++ b/src/runtime/virt.c @@ -3,6 +3,8 @@ #include #include #include "runtime.h" +#include "virt.h" +#include "debug.h" static bool fsl_virt_load_cache(struct fsl_rt_mapping* rtm); @@ -13,20 +15,36 @@ uint64_t fsl_virt_xlate(const struct fsl_rt_closure* clo, uint64_t bit_off) uint64_t idx, off; diskoff_t base; + DEBUG_VIRT_ENTER(); + + DEBUG_VIRT_WRITE("xlating!!!"); + + assert (clo != NULL); + rtm = clo->clo_xlate; assert (rtm != NULL); assert (bit_off < fsl_virt_total_bits(rtm)); + DEBUG_VIRT_WRITE("rtm->rtm_cached_min = %"PRIu64, rtm->rtm_cached_minidx); + DEBUG_VIRT_WRITE("rtm->rtm_cached_max = %"PRIu64, rtm->rtm_cached_maxidx); idx = bit_off / rtm->rtm_cached_srcsz; - idx += rtm->rtm_cached_minidx; /* rebase. */ + idx += rtm->rtm_cached_minidx; /* base. */ off = bit_off % rtm->rtm_cached_srcsz; uint64_t params[tt_by_num(rtm->rtm_virt->vt_type_src)->tt_param_c]; + /* use dyn vars set on allocation of xlate */ old_clo = fsl_rt_dyn_swap(rtm->rtm_dyn); + DEBUG_VIRT_WRITE("rtm_clo->clo_offset: %"PRIu64" bits (%"PRIu64" bytes)", + rtm->rtm_clo->clo_offset, + rtm->rtm_clo->clo_offset / 8); base = rtm->rtm_virt->vt_range(rtm->rtm_clo, idx, params); + DEBUG_VIRT_WRITE("BASE FOUND: %"PRIu64, base); + DEBUG_VIRT_WRITE("WANTED BITOFF: %"PRIu64, bit_off); + + /* swap back to old dyn vars */ fsl_rt_dyn_swap(old_clo); assert (bit_off != base+off && "Identity xlate. Probably wrong."); @@ -34,6 +52,8 @@ uint64_t fsl_virt_xlate(const struct fsl_rt_closure* clo, uint64_t bit_off) fsl_env->fctx_stat.s_xlate_call_c++; fsl_env->fctx_stat.s_xlate_alloc_c++; + DEBUG_VIRT_LEAVE(); + return base + off; } @@ -53,17 +73,24 @@ struct fsl_rt_mapping* fsl_virt_alloc( assert (parent != NULL); assert (vt != NULL); + DEBUG_VIRT_ENTER(); + DEBUG_VIRT_WRITE("COPYING FOR VIRT_ALLOC"); + rtm = malloc(sizeof(*rtm)); rtm->rtm_virt = vt; rtm->rtm_clo = parent; rtm->rtm_dyn = fsl_dyn_copy(fsl_env->fctx_dyn_closures); + DEBUG_VIRT_WRITE("COPY DONE"); + if (fsl_virt_load_cache(rtm) == false) { /* empty type */ fsl_virt_free(rtm); rtm = NULL; } + DEBUG_VIRT_WRITE("resh new RTM %p", rtm); + DEBUG_VIRT_LEAVE(); return rtm; } @@ -76,29 +103,46 @@ static bool fsl_virt_load_cache(struct fsl_rt_mapping* rtm) vt = rtm->rtm_virt; + DEBUG_VIRT_ENTER(); + + DEBUG_VIRT_WRITE("BEFORE FINDING IDXS"); + /* XXX these should be invalidated when underlying changes.. need * to use logging facility */ rtm->rtm_cached_minidx = rtm->rtm_virt->vt_min(rtm->rtm_clo); rtm->rtm_cached_maxidx = rtm->rtm_virt->vt_max(rtm->rtm_clo); + DEBUG_VIRT_WRITE("MINIDX=%"PRIu64" / MAXIDX=%"PRIu64, + rtm->rtm_cached_minidx, + rtm->rtm_cached_maxidx); + /* no data associated with this virt type-- don't allocate */ if (rtm->rtm_cached_minidx > rtm->rtm_cached_maxidx) { + DEBUG_VIRT_LEAVE(); return false; } tt_vsrc = tt_by_num(vt->vt_type_src); uint64_t params[tt_vsrc->tt_param_c]; + + DEBUG_VIRT_WRITE("1st RANGE. %s. param_c=%d", + tt_vsrc->tt_name, + tt_vsrc->tt_param_c); first_type_off = vt->vt_range( rtm->rtm_clo, rtm->rtm_cached_minidx, params); + DEBUG_VIRT_WRITE("NEW_VCLO"); NEW_VCLO(vsrc_clo, first_type_off, params, rtm->rtm_clo->clo_xlate); + DEBUG_VIRT_WRITE("Get SIZE"); rtm->rtm_cached_srcsz = tt_vsrc->tt_size(&vsrc_clo); assert (rtm->rtm_cached_srcsz > 0); + + DEBUG_VIRT_WRITE("LOOOOoOP"); /* verify that srcsz is constant-- if not we need to do some other * tricks */ @@ -116,7 +160,7 @@ static bool fsl_virt_load_cache(struct fsl_rt_mapping* rtm) } /* XXX TODO: verify virtualtype fits in given source data */ - + DEBUG_VIRT_LEAVE(); return true; } @@ -138,23 +182,30 @@ diskoff_t fsl_virt_get_nth( cur_off = 0; virt_typenum = rtm->rtm_virt->vt_type_virttype; tt = tt_by_num(virt_typenum); + DEBUG_VIRT_WRITE("nth of type: %s", tt->tt_name); /* save old dyn closure value */ NEW_EMPTY_CLO (old_dyn, virt_typenum); __getDynClosure(virt_typenum, &old_dyn); for (i = 0; i < target_idx; i++) { typesize_t cur_size; - NEW_CLO (new_clo, cur_off, NULL); - - if (total_bits >= fsl_virt_total_bits(rtm)) { - __setDyn(virt_typenum, &old_dyn); - return OFFSET_INVALID; - } + NEW_VCLO (new_clo, cur_off, NULL, rtm); __setDyn(virt_typenum, &new_clo); cur_size = tt->tt_size(&new_clo); + DEBUG_VIRT_WRITE("new_clo->voffset = %"PRIu64, new_clo.clo_offset); + DEBUG_VIRT_WRITE("fsl_total_bits= %"PRIu64, fsl_virt_total_bits(rtm)); + DEBUG_VIRT_WRITE("cur_size = %"PRIu64, cur_size); total_bits += cur_size; cur_off += cur_size; + + DEBUG_VIRT_WRITE("%"PRIu64" >= %"PRIu64"???", + total_bits, + fsl_virt_total_bits(rtm)); + if (total_bits >= fsl_virt_total_bits(rtm)) { + __setDyn(virt_typenum, &old_dyn); + return OFFSET_INVALID; + } } /* reset to original */ diff --git a/src/tool/Makefile b/src/tool/Makefile index ba07c24..043ecb5 100644 --- a/src/tool/Makefile +++ b/src/tool/Makefile @@ -9,7 +9,8 @@ RT_OBJS=../runtime/runtime.o \ ../runtime/virt.o \ ../runtime/dyn.o \ ../runtime/io.o \ - ../runtime/max.o + ../runtime/max.o \ + ../runtime/debug.o SCANTOOL_OBJS=../runtime/scantool.o $(RT_OBJS) BROWSER_OBJS=../runtime/browser.o $(RT_OBJS) diff --git a/tests/do_all_tests.sh b/tests/do_all_tests.sh index d1980ba..63fca15 100755 --- a/tests/do_all_tests.sh +++ b/tests/do_all_tests.sh @@ -6,6 +6,7 @@ function browser_startup echo "Testing browser-$fs startup." cmd="${src_root}/src/tool/browser-$fs ${src_root}/img/$fs.img <<>tests.log + echo "$cmd" >failed_test_cmd outstr=`eval $cmd` retval=$? if [ $retval -ne 0 ]; then @@ -19,8 +20,9 @@ function scan_startup { fs=$1 echo "Testing scantool-$fs startup." - cmd="${src_root}/src/tool/scantool-$fs ${src_root}/img/$fs.img <<>tests.log + echo "$cmd" >failed_test_cmd outstr=`eval $cmd` retval=$? if [ $retval -ne 0 ]; then