Commit fb5d0472 authored by Julian Kranz's avatar Julian Kranz

Base address in state

"translateBlock": Now stops at specified address
parent 6dced205
......@@ -15,7 +15,8 @@ struct state {
char* heap; /* current top of the heap */
@state_type@
; /* the current monadic state */
char* ip_base; /* beginning of code buffer */
char* ip_start; /* beginning of code buffer */
size_t ip_base; /* base address of code */
char* ip_limit; /* first byte beyond the code buffer */
char* ip; /* current pointer into the buffer */
char* err_str; /* a string describing the fatal error that occurred */
......@@ -278,25 +279,27 @@ state_t
void
@set_code@
(state_t s, char* buf, size_t buf_len, uint64_t base) {
(state_t s, char* buf, size_t buf_len, size_t base) {
s->ip = buf;
s->ip_limit = buf+buf_len;
s->ip_base = buf-base;
s->ip_start = buf;
s->ip_base = base;
}
uint64_t
size_t
@get_ip_offset@
(state_t s) {
return s->ip - s->ip_base;
return s->ip_base + (s->ip - s->ip_start);
}
int_t
@seek@
(state_t s, size_t i) {
size_t size = (size_t)(s->ip_limit - s->ip_base);
if(i >= size)
size_t size = (size_t)(s->ip_limit - s->ip_start);
size_t start_offset = i - s->ip_base;
if(start_offset >= size)
return 1;
s->ip = s->ip_base + i;
s->ip = s->ip_start + start_offset;
return 0;
}
......
......@@ -38,10 +38,10 @@ state_t
in GDSL returns when no bytes have been consumed. */
void
@set_code@
(state_t s, char* buf, size_t buf_len, uint64_t base);
(state_t s, char* buf, size_t buf_len, size_t base);
/* Query the offset of the current IP relative to base. */
uint64_t
size_t
@get_ip_offset@
(state_t s);
......
......@@ -47,7 +47,7 @@ char gdwrap_translate_block(obj_t state, obj_t *rreil) {
if(setjmp(*gdsl_err_tgt(state)))
return 1;
else {
*rreil = gdsl_translateBlock(state, gdsl_config_default(state));
*rreil = gdsl_translateBlock(state, gdsl_config_default(state), gdsl_int_max(state));
return 0;
}
}
# Standard definitions.
export = rope-length rope-print rope-to-string
export = rope-length rope-print rope-to-string int-max
type rope = RopeLeaf of { rope-size : int, rope-string: string }
| RopeInner of { rope-size : int, rope-left : rope, rope-right : rope }
......@@ -78,3 +78,5 @@ val io-binop binop a b =
end
| IO_NONE: IO_NONE
end
val int-max = 0x7fffffffffffffff
......@@ -2132,22 +2132,21 @@ val transInstr config = do
semantics insn
end
val transBlock config = do
val transBlock config limit = do
transInstr config;
jmp <- query $foundJump;
#ic <- query $ins_count;
#if jmp or ic>1000 then query $stack else transBlock config
if jmp then query $stack else transBlock config
idx <- idxget;
if jmp or (idx >= limit) then query $stack else transBlock config limit
end
val translateBlock config = do
val translateBlock config limit = do
update @{ins_count=0};
update@{stack=SEM_NIL,foundJump='0'};
# the type checker is does not instanitate types of decoders; what seemed to be
# a fine specialization turns out to be a bad idea since records need to be
# newly instantiated
update @{ptrsz=0, reg/opcode='000', rm='000', mod='00', vexm='00001', vexv='0000', vexl='0', vexw='0'};
stmts <- transBlock config;
stmts <- transBlock config limit;
return (rreil-stmts-rev stmts)
end
......@@ -2219,13 +2218,13 @@ type stmts_option =
type translate-result = {insns:int, succ_a:int, succ_b:int}
val translateSuperBlock config = let
val translateSuperBlock config limit = let
val translate-block-at idx = do
current <- idxget;
#error <- rseek idx;
error <- seek (current + idx);
result <- if error === 0 then do
stmts <- translateBlock config;
stmts <- translateBlock config int-max;
seek current;
return (SO_SOME stmts)
end else
......@@ -2246,7 +2245,7 @@ in do
# the type checker is seriously broken when it comes to infinite recursion,
# I cannot as of yet reproduce this bug
update @{ptrsz=0, reg/opcode='000', rm='000', mod='00', vexm='00001', vexv='0000', vexl='0', vexw='0'};
stmts <- transBlock config;
stmts <- transBlock config limit;
ic <- query $ins_count;
......
......@@ -176,14 +176,14 @@ obj_t translate_single(state_t state) {
obj_t translate(state_t state) {
if(setjmp(*gdsl_err_tgt(state)))
return NULL;
obj_t rreil_insns = gdsl_translateBlock(state, gdsl_config_default(state));
obj_t rreil_insns = gdsl_translateBlock(state, gdsl_config_default(state), gdsl_int_max(state));
return rreil_insns;
}
translate_result_t translate_super(state_t state, obj_t *rreil_insns) {
if(setjmp(*gdsl_err_tgt(state)))
return NULL;
translate_result_t rreil_insns_succs = gdsl_translateSuperBlock(state, gdsl_config_default(state));
translate_result_t rreil_insns_succs = gdsl_translateSuperBlock(state, gdsl_config_default(state), gdsl_int_max(state));
*rreil_insns = rreil_insns_succs->insns;
return rreil_insns_succs;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment