Skip to content

Commit

Permalink
scan tool doesn't crash any more (probably wrong though)
Browse files Browse the repository at this point in the history
  • Loading branch information
chzchzchz committed Sep 26, 2010
1 parent ce247a1 commit 56042dd
Show file tree
Hide file tree
Showing 14 changed files with 307 additions and 55 deletions.
2 changes: 1 addition & 1 deletion fs/vfat.fsl
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
49 changes: 49 additions & 0 deletions src/runtime/debug.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#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");
}
49 changes: 49 additions & 0 deletions src/runtime/debug.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#ifndef FSL_RT_DEBUG_H
#define FSL_RT_DEBUG_H

#include <stdarg.h>

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
13 changes: 9 additions & 4 deletions src/runtime/dyn.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
#include <assert.h>
#include <string.h>
#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;

Expand All @@ -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 */
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
}
}
25 changes: 25 additions & 0 deletions src/runtime/dyn.h
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion src/runtime/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <stdio.h>
#include <assert.h>
#include <string.h>

#include "debug.h"
#include "runtime.h"

typedef uint64_t logaddr_t;
Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 7 additions & 1 deletion src/runtime/runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include "debug.h"
#include "runtime.h"

extern uint64_t fsl_num_types;
Expand Down Expand Up @@ -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++) {
Expand Down Expand Up @@ -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);
Expand Down
15 changes: 4 additions & 11 deletions src/runtime/runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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) \
Expand All @@ -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)
Expand Down Expand Up @@ -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[]);

Expand Down
Loading

0 comments on commit 56042dd

Please sign in to comment.