Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
gdsl-toolkit
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tanzeem Haque
gdsl-toolkit
Commits
3ed94b88
Commit
3ed94b88
authored
Feb 15, 2013
by
Julian Kranz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
X86 RREIL Translator
Runtime
parent
ad91c07c
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
144 additions
and
46 deletions
+144
-46
detail/codegen/c0/runtime.c
detail/codegen/c0/runtime.c
+94
-25
detail/codegen/c0/runtime.h
detail/codegen/c0/runtime.h
+10
-2
detail/cps/from-core.sml
detail/cps/from-core.sml
+12
-0
detail/semantic/primitives.sml
detail/semantic/primitives.sml
+5
-5
specifications/x86/c/Makefile
specifications/x86/c/Makefile
+1
-1
specifications/x86/c/asm-test.s
specifications/x86/c/asm-test.s
+10
-6
specifications/x86/c/sweep.c
specifications/x86/c/sweep.c
+10
-5
specifications/x86/x86-rreil-translator.ml
specifications/x86/x86-rreil-translator.ml
+2
-2
No files found.
detail/codegen/c0/runtime.c
View file @
3ed94b88
...
...
@@ -127,12 +127,18 @@ __obj __zx (__obj x) {
}
/* FIXME */
__obj
__ipget
(
__obj
x
)
{
__obj
__ipget
(
__obj
s
)
{
__LOCAL
(
blob
,
__RECORD_SELECT
(
s
,
___blob
));
__LOCAL0
(
y
);
__INT_BEGIN
(
y
);
__INT_INIT
(
42
);
__INT_INIT
(
blob
->
blob
.
idx
);
__INT_END
(
y
);
return
(
y
);
__LOCAL0
(
a
);
__RECORD_BEGIN
(
a
,
2
);
__RECORD_ADD
(
___1
,
y
);
__RECORD_ADD
(
___2
,
s
);
__RECORD_END
(
a
,
2
);
return
(
a
);
}
__obj
__concat
(
__obj
A
,
__obj
B
)
{
...
...
@@ -210,6 +216,7 @@ __obj __consume8 (__obj s) {
__LOCAL
(
blob
,
__RECORD_SELECT
(
s
,
___blob
));
__char
*
buf
=
blob
->
blob
.
blob
;
__word
sz
=
blob
->
blob
.
sz
;
__word
idx
=
blob
->
blob
.
idx
;
if
(
sz
==
0
)
__fatal
(
"end-of-blob"
);
__char
x
=
*
buf
;
...
...
@@ -219,7 +226,7 @@ __obj __consume8 (__obj s) {
__BV_END
(
v
,
8
);
__LOCAL0
(
blobb
);
__BLOB_BEGIN
(
blobb
);
__BLOB_INIT
(
buf
+
1
,
sz
-
1
);
__BLOB_INIT
(
buf
+
1
,
sz
-
1
,
idx
+
1
);
__BLOB_END
(
blobb
);
__LOCAL0
(
ss
);
__RECORD_BEGIN_UPDATE
(
ss
,
s
);
...
...
@@ -237,9 +244,10 @@ __obj __unconsume8 (__obj s) {
__LOCAL
(
blob
,
__RECORD_SELECT
(
s
,
___blob
));
__char
*
buf
=
blob
->
blob
.
blob
;
__word
sz
=
blob
->
blob
.
sz
;
__word
idx
=
blob
->
blob
.
idx
;
__LOCAL0
(
blobb
);
__BLOB_BEGIN
(
blobb
);
__BLOB_INIT
(
buf
-
1
,
sz
+
1
);
__BLOB_INIT
(
buf
-
1
,
sz
+
1
,
idx
-
1
);
__BLOB_END
(
blobb
);
__LOCAL0
(
ss
);
__RECORD_BEGIN_UPDATE
(
ss
,
s
);
...
...
@@ -257,6 +265,7 @@ __obj __consume16 (__obj s) {
__LOCAL
(
blob
,
__RECORD_SELECT
(
s
,
___blob
));
__char
*
buf
=
blob
->
blob
.
blob
;
__word
sz
=
blob
->
blob
.
sz
;
__word
idx
=
blob
->
blob
.
idx
;
if
(
sz
<
2
)
__fatal
(
"end-of-blob"
);
uint16_t
x1
=
buf
[
0
];
...
...
@@ -267,7 +276,7 @@ __obj __consume16 (__obj s) {
__BV_END
(
v
,
16
);
__LOCAL0
(
blobb
);
__BLOB_BEGIN
(
blobb
);
__BLOB_INIT
(
buf
+
2
,
sz
-
2
);
__BLOB_INIT
(
buf
+
2
,
sz
-
2
,
idx
+
2
);
__BLOB_END
(
blobb
);
__LOCAL0
(
ss
);
__RECORD_BEGIN_UPDATE
(
ss
,
s
);
...
...
@@ -285,9 +294,10 @@ __obj __unconsume16 (__obj s) {
__LOCAL
(
blob
,
__RECORD_SELECT
(
s
,
___blob
));
__char
*
buf
=
blob
->
blob
.
blob
;
__word
sz
=
blob
->
blob
.
sz
;
__word
idx
=
blob
->
blob
.
idx
;
__LOCAL0
(
blobb
);
__BLOB_BEGIN
(
blobb
);
__BLOB_INIT
(
buf
-
2
,
sz
+
2
);
__BLOB_INIT
(
buf
-
2
,
sz
+
2
,
idx
-
2
);
__BLOB_END
(
blobb
);
__LOCAL0
(
ss
);
__RECORD_BEGIN_UPDATE
(
ss
,
s
);
...
...
@@ -305,6 +315,7 @@ __obj __consume32 (__obj s) {
__LOCAL
(
blob
,
__RECORD_SELECT
(
s
,
___blob
));
__char
*
buf
=
blob
->
blob
.
blob
;
__word
sz
=
blob
->
blob
.
sz
;
__word
idx
=
blob
->
blob
.
idx
;
if
(
sz
<
4
)
__fatal
(
"end-of-blob"
);
uint32_t
x1
=
buf
[
0
];
...
...
@@ -317,7 +328,7 @@ __obj __consume32 (__obj s) {
__BV_END
(
v
,
32
);
__LOCAL0
(
blobb
);
__BLOB_BEGIN
(
blobb
);
__BLOB_INIT
(
buf
+
2
,
sz
-
2
);
__BLOB_INIT
(
buf
+
4
,
sz
-
4
,
idx
+
4
);
__BLOB_END
(
blobb
);
__LOCAL0
(
ss
);
__RECORD_BEGIN_UPDATE
(
ss
,
s
);
...
...
@@ -335,9 +346,10 @@ __obj __unconsume32 (__obj s) {
__LOCAL
(
blob
,
__RECORD_SELECT
(
s
,
___blob
));
__char
*
buf
=
blob
->
blob
.
blob
;
__word
sz
=
blob
->
blob
.
sz
;
__word
idx
=
blob
->
blob
.
idx
;
__LOCAL0
(
blobb
);
__BLOB_BEGIN
(
blobb
);
__BLOB_INIT
(
buf
-
4
,
sz
+
4
);
__BLOB_INIT
(
buf
-
4
,
sz
+
4
,
idx
-
4
);
__BLOB_END
(
blobb
);
__LOCAL0
(
ss
);
__RECORD_BEGIN_UPDATE
(
ss
,
s
);
...
...
@@ -367,6 +379,77 @@ __obj __halt (__obj env, __obj o) {
return
(
o
);
}
__obj
__cont
(
__obj
env
,
__obj
f
)
{
__LOCAL
(
s
,
__CLOSURE_REF
(
env
,
1
));
__LOCAL0
(
k
);
__LABEL_BEGIN
(
k
);
__LABEL_INIT
(
__halt
);
__LABEL_END
(
k
);
__LOCAL0
(
envK
);
__CLOSURE_BEGIN
(
envK
,
1
)
__CLOSURE_ADD
(
k
);
__CLOSURE_END
(
envK
,
1
);
__LOCAL
(
ff
,
__CLOSURE_REF
(
f
,
0
));
return
(
__INVOKE3
(
ff
,
f
,
envK
,
s
));
}
__obj
__createState
(
__char
*
blobb
,
__word
size
,
__word
index
,
__word
config
)
{
__LOCAL0
(
b
);
__BLOB_BEGIN
(
b
);
__BLOB_INIT
(
blobb
,
size
,
index
);
__BLOB_END
(
b
);
__LOCAL0
(
s
);
__RECORD_BEGIN
(
s
,
1
);
__RECORD_ADD
(
___blob
,
b
);
__RECORD_END
(
s
,
1
);
return
s
;
}
__word
__getBlobIndex
(
__obj
state
)
{
union
__wrapped_obj
*
o
=
__RECORD_SELECT
(
state
,
___blob
);
return
o
->
blob
.
idx
;
}
__obj
__runMonadicNoArg
(
__obj
(
*
f
)(
__obj
,
__obj
),
__obj
*
state
)
{
__LOCAL0
(
k
);
__LABEL_BEGIN
(
k
);
__LABEL_INIT
(
__halt
);
__LABEL_END
(
k
);
__LOCAL0
(
envK
);
__CLOSURE_BEGIN
(
envK
,
1
)
__CLOSURE_ADD
(
k
);
__CLOSURE_END
(
envK
,
1
);
__LOCAL
(
o
,
__FCALL
(
f
,
envK
,
*
state
));
if
(
___isNil
(
o
))
{
return
NULL
;
}
else
{
__obj
i
=
__RECORD_SELECT
(
o
,
___1
);
__obj
s
=
__RECORD_SELECT
(
o
,
___2
);
*
state
=
s
;
return
i
;
}
}
__obj
__runMonadicOneArg
(
__obj
(
*
f
)(
__obj
,
__obj
),
__obj
*
state
,
__obj
arg1
)
{
__LOCAL0
(
k
);
__LABEL_BEGIN
(
k
);
__LABEL_INIT
(
__cont
);
__LABEL_END
(
k
);
__LOCAL0
(
envK
);
__CLOSURE_BEGIN
(
envK
,
2
)
__CLOSURE_ADD
(
*
state
);
__CLOSURE_ADD
(
k
);
__CLOSURE_END
(
envK
,
2
);
__LOCAL
(
o
,
__FCALL
(
f
,
envK
,
arg1
));
if
(
___isNil
(
o
))
{
return
NULL
;
}
else
{
__obj
i
=
__RECORD_SELECT
(
o
,
___1
);
__obj
s
=
__RECORD_SELECT
(
o
,
___2
);
*
state
=
s
;
return
i
;
}
}
__obj
__runWithState
(
__obj
(
*
f
)(
__obj
,
__obj
),
__obj
s
)
{
__LOCAL0
(
k
);
__LABEL_BEGIN
(
k
);
...
...
@@ -382,7 +465,7 @@ __obj __runWithState (__obj (*f)(__obj,__obj), __obj s) {
__obj
__eval
(
__obj
(
*
f
)(
__obj
,
__obj
),
__char
*
blob
,
__word
sz
)
{
__LOCAL0
(
b
);
__BLOB_BEGIN
(
b
);
__BLOB_INIT
(
blob
,
sz
);
__BLOB_INIT
(
blob
,
sz
,
0
);
__BLOB_END
(
b
);
__LOCAL0
(
s
);
__RECORD_BEGIN
(
s
,
1
);
...
...
@@ -422,20 +505,6 @@ __word __decode (__obj (*f)(__obj,__obj), __char* blob, __word sz, __obj* insn)
}
}
__obj
__cont
(
__obj
env
,
__obj
f
)
{
__LOCAL
(
s
,
__CLOSURE_REF
(
env
,
1
));
__LOCAL0
(
k
);
__LABEL_BEGIN
(
k
);
__LABEL_INIT
(
__halt
);
__LABEL_END
(
k
);
__LOCAL0
(
envK
);
__CLOSURE_BEGIN
(
envK
,
1
)
__CLOSURE_ADD
(
k
);
__CLOSURE_END
(
envK
,
1
);
__LOCAL
(
ff
,
__CLOSURE_REF
(
f
,
0
));
return
(
__INVOKE3
(
ff
,
f
,
envK
,
s
));
}
__obj
__translate
(
__obj
(
*
f
)(
__obj
,
__obj
),
__obj
insn
)
{
__LOCAL0
(
s
);
__RECORD_BEGIN
(
s
,
0
);
...
...
@@ -545,7 +614,7 @@ __obj __print (__obj o) {
printf
(
"{tag=__LABEL,f=%p}"
,
o
->
label
.
f
);
break
;
case
__BLOB
:
printf
(
"{tag=__BLOB,sz=%lu,blob=%p
}"
,(
unsigned
long
)
o
->
blob
.
sz
,
o
->
blob
.
blob
);
printf
(
"{tag=__BLOB,sz=%lu,blob=%p
,idx=%lu}"
,(
unsigned
long
)
o
->
blob
.
sz
,
o
->
blob
.
blob
,
o
->
blob
.
idx
);
break
;
case
__BV
:
printf
(
"{tag=__BV,sz=%lu,vec=%zx}"
,(
unsigned
long
)
o
->
bv
.
sz
,(
unsigned
long
)
o
->
bv
.
vec
);
...
...
detail/codegen/c0/runtime.h
View file @
3ed94b88
...
...
@@ -181,11 +181,12 @@
#define __BLOB_BEGIN(Cname)\
__CHECK_HEAP(1)
#define __BLOB_INIT(buf, size)\
#define __BLOB_INIT(buf, size
, index
)\
{__objref o = __ALLOC1();\
o->blob.header.tag = __BLOB;\
o->blob.blob = buf;\
o->blob.sz = size;
o->blob.sz = size;\
o->blob.idx = index;
#define __BLOB_END(Cname)\
Cname = __WRAP(o);}
...
...
@@ -251,6 +252,7 @@ struct __s_unwrapped_blob {
__header
header
;
__char
*
blob
;
__word
sz
;
__word
idx
;
};
struct
__s_unwrapped_ropeleaf
{
__header
header
;
...
...
@@ -302,6 +304,7 @@ struct __s_label {
struct
__s_blob
{
__char
*
blob
;
__word
sz
;
__word
idx
;
};
struct
__s_ropeleaf
{
__char
*
blob
;
...
...
@@ -489,5 +492,10 @@ __word __decode(__obj(*)(__obj,__obj),__char*,__word,__obj*);
__obj
__pretty
(
__obj
(
*
)(
__obj
,
__obj
),
__obj
,
char
*
,
__word
);
__obj
__translate
(
__obj
(
*
)(
__obj
,
__obj
),
__obj
);
__obj
__createState
(
__char
*
blobb
,
__word
size
,
__word
index
,
__word
config
);
__word
__getBlobIndex
(
__obj
state
);
__obj
__runMonadicNoArg
(
__obj
(
*
f
)(
__obj
,
__obj
),
__obj
*
state
);
__obj
__runMonadicOneArg
(
__obj
(
*
f
)(
__obj
,
__obj
),
__obj
*
state
,
__obj
arg1
);
#endif
/* __RUNTIME_H */
detail/cps/from-core.sml
View file @
3ed94b88
...
...
@@ -47,6 +47,7 @@ end = struct
val
==
=
get
"=="
val
not
=
get
"not"
val
raisee
=
get
"raise"
val
ipget
=
get
"ipget"
val
return
=
get
"return"
val
add
=
get
"+"
val
eqi
=
get
"==="
...
...
@@ -266,6 +267,16 @@ end = struct
(
raisee
,
[
a
],
body
)
end
(*
val ipget s = %ipget(s) *)
val
ipget
=
let
val
s
=
fresh
"s"
val
primipget
=
get
"%ipget"
val
body
=
PRI
(
primipget
,
[
s
])
in
(
ipget
,
[
s
],
body
)
end
(*
val slice tok offs sz = return (%slice(tok,offs,sz) *)
val
slice
=
let
...
...
@@ -354,6 +365,7 @@ end = struct
==
,
concat
,
raisee
,
ipget
,
add
,
sx
,
zx
,
...
...
detail/semantic/primitives.sml
View file @
3ed94b88
...
...
@@ -41,8 +41,8 @@ structure Primitives = struct
val
stateK'
=
newFlow
stateK
val
stateL
=
freshVar
()
val
stateL'
=
newFlow
stateL
(*
val stateI
= freshVar ()
val state
I' = newFlow stateI*)
val
stateM
=
freshVar
()
val
state
M'
=
newFlow
stateM
val
a
=
freshVar
()
val
a
=
freshVar
()
val
a'
=
newFlow
a
...
...
@@ -121,8 +121,8 @@ structure Primitives = struct
flow
=
BD
.
meetVarImpliesVar
(
bvar
stateC'
,
bvar
stateC
)},
{
name
=
"raise"
,
ty
=
MONAD
(
freshVar
(),
stateD
,
stateD'
),
flow
=
noFlow
},
(*
{name="ipget", ty=MONAD (ZENO, stateI, stateI
'),
flow = BD.meetVarImpliesVar (bvar state
I', bvar stateI)},*)
{
name
=
"ipget"
,
ty
=
MONAD
(
ZENO
,
stateM
,
stateM
'
),
flow
=
BD
.
meetVarImpliesVar
(
bvar
state
M'
,
bvar
stateM
)},
{
name
=
"%raise"
,
ty
=
UNIT
,
flow
=
noFlow
},
{
name
=
"%and"
,
ty
=
UNIT
,
flow
=
noFlow
},
{
name
=
"%or"
,
ty
=
UNIT
,
flow
=
noFlow
},
...
...
@@ -239,7 +239,7 @@ structure Primitives = struct
flow
=
BD
.
meetVarImpliesVar
(
bvar
stateK'
,
bvar
stateK
)},
{
name
=
"%slice"
,
ty
=
MONAD
(
freshVar
(),
stateL
,
stateL'
),
flow
=
BD
.
meetVarImpliesVar
(
bvar
stateL'
,
bvar
stateL
)},
(*
{name="%ipget", ty=UNIT, flow = noFlow},*)
{
name
=
"%ipget"
,
ty
=
UNIT
,
flow
=
noFlow
},
{
name
=
"vcase"
,
ty
=
FUN
([
VEC
inp
,
content'
,
FUN
([
content''
,
VEC
out
],
content'''
)],
content''''
),
flow
=
BD
.
meetVarImpliesVar
(
bvar
content''''
,
bvar
content'
)
o
...
...
specifications/x86/c/Makefile
View file @
3ed94b88
...
...
@@ -14,7 +14,7 @@ clang-sweep:
clang
-pipe
-O3
-Wall
-static
-I
.
-I
../../..
-Wfatal-errors
sweep.c ../../../dis.o
-DRELAXEDFATAL
-o
clang-sweep
gcc-sweep
:
gcc
-pipe
-O3
-Wall
-static
-I
.
-I
../../..
-Wfatal-errors
sweep.c ../../../dis.o
-DRELAXEDFATAL
-o
gcc-sweep
gcc
-
g
-
pipe
-O3
-Wall
-static
-I
.
-I
../../..
-Wfatal-errors
sweep.c ../../../dis.o
-DRELAXEDFATAL
-o
gcc-sweep
cmusl-liveness
:
/usr/musl/bin/musl-gcc
-pipe
-O3
-Wall
-static
-I
.
-I
../../..
-Wfatal-errors
liveness.c ../../../dis.c
-DRELAXEDFATAL
-o
musl-live
...
...
specifications/x86/c/asm-test.s
View file @
3ed94b88
...
...
@@ -93,8 +93,12 @@ main:
#
cdqe
#
blah
:
#
call
blah
add
%
rax
,
%
rax
inc
%
rax
blah
:
call
blah
call
blah
#
bts
%
rax
,
(%
rbx
)
#
btr
%
rax
,
%
rbx
...
...
@@ -484,10 +488,10 @@ main:
#
vmaskmovps
%
xmm1
,
%
xmm2
,
(%
rax
)
#
vmaskmovps
(%
rax
),
%
xmm1
,
%
xmm2
vmaskmovpd
%
xmm1
,
%
xmm2
,
(%
rax
)
vmaskmovpd
(%
rax
),
%
xmm1
,
%
xmm2
vmaskmovpd
%
ymm1
,
%
ymm2
,
(%
rax
)
vmaskmovpd
(%
rax
),
%
ymm1
,
%
ymm2
#
vmaskmovpd
%
xmm1
,
%
xmm2
,
(%
rax
)
#
vmaskmovpd
(%
rax
),
%
xmm1
,
%
xmm2
#
vmaskmovpd
%
ymm1
,
%
ymm2
,
(%
rax
)
#
vmaskmovpd
(%
rax
),
%
ymm1
,
%
ymm2
#
vmovd
%
xmm5
,
%
ebx
...
...
specifications/x86/c/sweep.c
View file @
3ed94b88
...
...
@@ -51,11 +51,15 @@ int main (int argc, char** argv) {
unsigned
char
*
buffer
=
(
unsigned
char
*
)
malloc
(
buffer_size
);
size_t
buffer_length
=
fread
(
buffer
,
1
,
buffer_size
,
f
);
uint64_t
consumed
=
0
;
while
(
consumed
+
15
<
buffer_length
)
{
__obj
state
=
__createState
(
buffer
,
buffer_length
,
0
,
0
);
//uint64_t consumed = 0;
while
(
__getBlobIndex
(
state
)
+
15
<
buffer_length
)
{
printf
(
"++++++++++++ DECODING NEXT INSTRUCTION ++++++++++++
\n
"
);
consumed
+=
__decode
(
__decode__
,
buffer
+
consumed
,
buffer_length
-
consumed
,
&
insn
);
printf
(
"Consumed: %lu
\n
"
,
consumed
);
insn
=
__runMonadicNoArg
(
__decode__
,
&
state
);
//consumed += __decode(__decode__,buffer+consumed,buffer_length - consumed,&insn);
//printf("Consumed: %lu\n", consumed);
if
(
___isNil
(
insn
))
__fatal
(
"Decode failed"
);
else
{
...
...
@@ -64,7 +68,8 @@ int main (int argc, char** argv) {
printf
(
"---------------------------
\n
"
);
__obj
r
=
__translate
(
__translate__
,
insn
);
__obj
r
=
__runMonadicOneArg
(
__translate__
,
&
state
,
insn
);
//__obj r = __translate(__translate__,insn);
if
(
___isNil
(
r
))
__fatal
(
"Translate failed"
);
else
{
...
...
specifications/x86/x86-rreil-translator.ml
View file @
3ed94b88
...
...
@@ -12,8 +12,8 @@ val runtime-stack-address-size = do
end
val
ip
-
get
=
do
#
k
<-
ipget
;
return
(
imm
0
)
k
<-
ipget
;
return
(
imm
k
)
end
val
segment
-
register
?
x
=
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment