Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BAP 2.0 #960

Merged
merged 390 commits into from
Aug 14, 2019
Merged
Changes from 1 commit
Commits
Show all changes
390 commits
Select commit Hold shift + click to select a range
3870cce
new implementation of fsqrt
gitoleg Jan 22, 2019
ab7d86b
initial scrap of the bitvector, still wip
ivg Jan 18, 2019
10623e1
bap-elementary, initial commit
gitoleg Jan 29, 2019
c8afebb
new and efficient bitvector implementation
ivg Jan 29, 2019
65acae6
wrote docs
gitoleg Jan 29, 2019
fe01544
fixed a typo
gitoleg Jan 29, 2019
6fcc80e
finished the initial implementation
ivg Jan 29, 2019
5bf9524
renames bitvector to bitvec and adds auxiliary libraries
ivg Jan 30, 2019
3a488bb
makes bitvec-order compatible with newer versions of base
ivg Jan 31, 2019
d4fd98d
adds a couple of missing functions
ivg Jan 31, 2019
81c9717
merge with upstream/master
gitoleg Jan 31, 2019
7958b2a
Merge branch 'bap-new-semantics' into primus-2.0
ivg Jan 31, 2019
e8a127d
fixes some leftovers from the merge conflict
ivg Jan 31, 2019
72a6cdf
makes bap_build indepndent on core-kernel
ivg Jan 31, 2019
0cdbe43
makes the build system indepdent on core-kernel
ivg Jan 31, 2019
ee7454c
the core-theory no longer depends on BAP
ivg Jan 31, 2019
aa5de01
moves some of new primus-list stuff to the new bitvector
ivg Jan 31, 2019
2fd645c
wip
ivg Feb 1, 2019
ad3df28
updates value to reflec the new Bitvec interface
ivg Feb 5, 2019
d6684b7
finishes with the lib part
ivg Feb 5, 2019
55c7e50
switches to an unboxed modulus representation
ivg Feb 6, 2019
657e172
moves bitvector to the bitvec base
ivg Feb 6, 2019
9c1ba6f
updates oasis files to add bap dependency
ivg Feb 6, 2019
fab17a0
makes bitvec sublibraries standalone
ivg Feb 8, 2019
cc93604
Merge pull request #27 from gitoleg/bap-elementary
gitoleg Feb 14, 2019
0c1c4cd
The following code allows ymm registers to be cast to smaller registe…
turnersr Feb 18, 2019
c891622
prototype for sin function from double to double
turnersr Feb 18, 2019
64fcda3
initial example of using Core Theory's floating point support to hook…
turnersr Feb 18, 2019
d54055f
fix warnings regarding Type not being in scope for Imm and run signature
turnersr Feb 18, 2019
e5d5ce8
working merlin file
turnersr Feb 18, 2019
b8f302b
initial functions in core theory IR for inaccurate sine range reduction
turnersr Feb 19, 2019
0b75c17
intial sine and cosine implmentations using Remez's approximation.
turnersr Feb 19, 2019
c2e8de5
reverse coefficients order
turnersr Feb 19, 2019
cf292f1
fix fceil bug, but need an fround implmentation for this to work.
turnersr Feb 19, 2019
84cc56f
one more test
turnersr Feb 19, 2019
1ac279f
made refactoring recommendations to seperate polynomial evaluation fr…
turnersr Feb 20, 2019
df218c2
renaming
turnersr Feb 20, 2019
c4c318c
wip: refining the knowledge theory
ivg Feb 20, 2019
efa9fa8
added knowledge return operators to stop recomputing values
turnersr Feb 20, 2019
ab618b1
renaming and better comment
turnersr Feb 20, 2019
1d526f1
more refactoring
turnersr Feb 20, 2019
1c64480
new ceil! :)
turnersr Feb 20, 2019
f9f7d9c
multiply by constant instead of division in fmod. As well as better r…
turnersr Feb 20, 2019
99d92f3
one test passes sort of :Dgit add approximation.ml !
turnersr Feb 20, 2019
fc66de3
undo initial ABI changes
turnersr Feb 20, 2019
1f57485
Merge pull request #28 from turnersr/bap-new-semantics
ivg Feb 20, 2019
50738b3
fixes indentation
ivg Feb 20, 2019
59056b4
optimizes sin computation (10 times better now)
ivg Feb 20, 2019
ab1a739
nearly finished the implementation
ivg Feb 22, 2019
836823d
adds serialization of values
ivg Feb 25, 2019
96aa937
implements some domain functions
ivg Feb 25, 2019
af6e40f
drops the old modules, implements more sophisticated typing
ivg Feb 26, 2019
b6452ae
implementing different type classes for values and objects
ivg Feb 26, 2019
6e34583
implemented merge and join
ivg Feb 26, 2019
0656679
the knowledge module finally typechecks
ivg Feb 27, 2019
2c5e44d
started rewriting the Core Theory in terms of KB
ivg Feb 28, 2019
a47c144
at least the empty theory is ready
ivg Mar 1, 2019
c08119a
adds symbols to knowledge
ivg Mar 4, 2019
45be2af
finishes adding symbols to knowledge
ivg Mar 5, 2019
e1fc4ca
the theory manager now compiles
ivg Mar 5, 2019
8182d6a
vars are now using knowledge objects
ivg Mar 5, 2019
ac1d9e5
the parser also compiles
ivg Mar 5, 2019
a62ed6b
core theory compiles!
ivg Mar 5, 2019
9049978
implements symbols visibility
ivg Mar 6, 2019
5701de0
adds namespaces importing
ivg Mar 6, 2019
0130c7d
abstracts peristence, adds class order
ivg Mar 12, 2019
91866a5
adds support for knowledge data representation
ivg Mar 12, 2019
57e3f85
adds support for immediates
ivg Mar 13, 2019
038b7cb
primus 2.0 is nearly ready,
ivg Mar 20, 2019
c430a31
ok, Primus doesn't require any components
ivg Mar 20, 2019
c7b0b76
satisfied the signature
ivg Mar 21, 2019
0942db1
adds flat domains and made optional flat
ivg Mar 21, 2019
ba652fb
all promises are fullfiled when the knowledge monad is run
ivg Mar 21, 2019
c32abf0
bap.std finally compiles
ivg Mar 21, 2019
ad5086e
moves the new primus out of the bap_primus folder
ivg Mar 25, 2019
1d856c6
restores primus from the bap-new-semantics branch
ivg Mar 25, 2019
df8bc4c
fixes the print plugin
ivg Mar 25, 2019
3db77f5
adds a missing depedency to the core-theory
ivg Mar 25, 2019
53cd9e0
renames decide to fact
ivg Mar 26, 2019
950eed7
simplifies the class type
ivg Mar 26, 2019
91f3719
makes 'a cls,'a obj, and ('a,'p) slot covariant in 'a
ivg Mar 26, 2019
47597c5
revises the sort system
ivg Mar 29, 2019
c7b0c74
makes sort refinement more safe
ivg Apr 1, 2019
b1613f7
uses Theory.Var for vars, adds Unk branch to Bap.Std.typ
ivg Apr 1, 2019
8ebc25d
wip, nearly finished rewriting IR in new semantics
ivg Apr 2, 2019
d63917f
moves Ir_jmp to the new semantics
ivg Apr 3, 2019
e40bcee
moves the whole IR to the new semantics
ivg Apr 3, 2019
12c9c87
IR no longer uses BIL
ivg Apr 3, 2019
ac7397c
the Insn.t is now the Semantics.t
ivg Apr 3, 2019
dff38b3
renames links to labels
ivg Apr 4, 2019
ce9d08f
extends the derived interface of Objects
ivg Apr 4, 2019
fb15cf7
The Tid.t is now the Theory.label
ivg Apr 4, 2019
970a6c3
moves bap to the new runtime
ivg Apr 5, 2019
750940a
creates program abstraction in CT and refines label
ivg Apr 8, 2019
66031ba
updates major components to the new interface
ivg Apr 9, 2019
d44e3f4
reverts primus components to the old primus
ivg Apr 9, 2019
d9151da
fixes a bug in the bitvector representation
ivg Apr 9, 2019
3c56294
fixes the value merging function
ivg Apr 9, 2019
c5f9273
fixes IR generator
ivg Apr 9, 2019
a8d1776
changed the merging strategy of insn
ivg Apr 9, 2019
6616f3f
adds the runtime lock uses the runtime in bap functions
ivg Apr 10, 2019
ffd23f8
relaxes the lock
ivg Apr 11, 2019
3ee8080
makes bap_c_abi error printable
ivg Apr 11, 2019
e35d0c3
refines IR jmp representation
ivg Apr 11, 2019
3894429
prints negative numbers as subtractions of positives
ivg Apr 11, 2019
6b56b8c
the CFG is now more or less properly linked
ivg Apr 11, 2019
8a89f15
fixes call wiring
ivg Apr 12, 2019
2491ec0
fixes all bugs
ivg Apr 12, 2019
28e120a
Merge branch 'bap-new-semantics' into primus-2.0
ivg Apr 15, 2019
0e74a07
fixes a bug in variable susbtituter
ivg Apr 15, 2019
849d588
hardens bap_bitvector implementation
ivg Apr 16, 2019
73d02d5
prints argument types using the old bap types if possible
ivg Apr 16, 2019
fea1ec1
updates the elementary function
ivg Apr 16, 2019
fb2761f
fixes the signed comparison function
ivg Apr 16, 2019
30723b5
makes disasm failure in powerpc tests more verbose
ivg Apr 16, 2019
4a77346
fixes object string representation
ivg Apr 16, 2019
21670de
fixes representation of tids in piqi serializers
ivg Apr 16, 2019
15bf96c
fixes flat domains, unit tests are passing now
ivg Apr 17, 2019
7ca98c7
removes some debugging information
ivg Apr 17, 2019
eaa625a
Merge remote-tracking branch 'upstream/master' into primus-2.0
ivg Apr 17, 2019
b494287
refines reconstructor, symtab, and IR lifter to fit new semantics
ivg Apr 18, 2019
9c15d56
WIP: a complete rew of the recursive descent disassembler
ivg Apr 24, 2019
f87a293
makes the disassembler more robust
ivg Apr 25, 2019
233742a
prints the disasembly in the ascending order
ivg Apr 25, 2019
2be124e
cleans up the disassembler
ivg Apr 25, 2019
b20c30f
adds a new constrained superset disassembler
ivg May 3, 2019
b682ff3
embeds the constrained superset disassembler into the KB monad
ivg May 7, 2019
cc1c88a
fixes a bug in the ror x86 semantics
ivg May 9, 2019
a31812b
switches to the new superset disassembler
ivg May 9, 2019
1313464
fixes a couple of bugs
ivg May 10, 2019
de69956
prints disassembly in the increasing addresses order
ivg May 10, 2019
dfcca50
changes the scanning mode
ivg May 10, 2019
6260092
a memory footprint optimization
ivg May 13, 2019
4ff2acd
integrating the new disassembler into BAP
ivg May 17, 2019
e6b1fe5
few more renamings and refactorings
ivg May 17, 2019
3183aa6
changes the type of Insn.t
ivg May 22, 2019
c80b1d6
fixed a fixed point
ivg May 29, 2019
ec9eb93
adds an optional join method to the domain
ivg May 30, 2019
6bb9810
moving forward towards well-defined fixed point semantics
ivg May 31, 2019
257073b
wip: implementing the new agent based system
ivg Jun 3, 2019
6096933
moves more service on the knowledge runtime
ivg Jun 6, 2019
4608e65
renames Bap_state to Bap_toplevel
ivg Jun 6, 2019
0cc139a
adds aliases slot to the program label class
ivg Jun 6, 2019
950296a
fixes abi demangling and the usage of Tid.set_name
ivg Jun 6, 2019
a5e38f0
small renamings of the new symtab interface
ivg Jun 6, 2019
91259d3
makes Typeid in Bap.Std.Value abstract, fixes pretty printing
ivg Jun 6, 2019
386bc5b
unifies Bap.Std.Value with Knowledge
ivg Jun 6, 2019
da9c2ba
switches the project to the new engine
ivg Jun 10, 2019
e5db001
fixes insn delay computation
ivg Jun 14, 2019
d90affb
extracts IR directly from semantics, instead of reruning the lifter
ivg Jun 14, 2019
c3ce44d
adds the `join` parameter to domain definition functions
ivg Jun 14, 2019
8b26541
lifts each instruction only once
ivg Jun 14, 2019
299e6cc
some microoptimizations to the Exp/Bil/Bir domains
ivg Jun 14, 2019
d447ed7
a new implementation of universal maps
ivg Jun 18, 2019
f53cc70
finishes switching to the new maps
ivg Jun 19, 2019
2825947
optimizes tree representation even more,
ivg Jun 19, 2019
2c109f7
adds a few inlined attributes to the monads library
ivg Jun 20, 2019
269b3b8
revises the class/sort system
ivg Jun 24, 2019
07346ee
yet another pass on dictionary optimization
ivg Jun 26, 2019
d9afb58
continues working on the optimized trees
ivg Jun 28, 2019
19cfb23
an intermediate step in havl tree implementation
ivg Jul 2, 2019
d818d87
wip on trees
ivg Jul 3, 2019
0dd951c
rank balanced wavl style tree is mostly ready
ivg Jul 9, 2019
01e37e6
fixes a missing case in the rank_increases function
ivg Jul 9, 2019
21f7908
a more optimal lower level
ivg Jul 9, 2019
8ef8c33
a few final optimizations and the cleanup.
ivg Jul 10, 2019
38b0432
fixes the inline attribute (I keep confusing inline/inlined)
ivg Jul 10, 2019
10d83c0
adds caching to BIL lifter
ivg Jul 10, 2019
8302143
removes caching from the BIL lifter
ivg Jul 16, 2019
2a23110
updates the primus_machine to the new class representation
ivg Jul 16, 2019
6358922
switches to custom type keys
ivg Jul 16, 2019
b081574
adds GC setup code
ivg Jul 16, 2019
33fc4c2
optimizes some maps in monads
ivg Jul 16, 2019
a749ca7
Merge remote-tracking branch 'upstream/master' into bap-2.0
ivg Jul 17, 2019
b9c10e5
set the optimization level to 0 by default
ivg Jul 18, 2019
0642999
fixes the name of the external-reference ogre attribute
ivg Jul 18, 2019
4188965
restores the correct merge function
ivg Jul 18, 2019
0e86bb5
fixes opinions and ignores empty knowledge
ivg Jul 18, 2019
3a04bb7
ensures that the symtab symbolizer doesn't provide empty names
ivg Jul 18, 2019
cdf5d6e
enables image rooter and symbolizer when a projec is created
ivg Jul 18, 2019
f394d27
enhances IDA's plugin error messaging.
ivg Jul 18, 2019
d723b0c
revamps the objdump plugin
ivg Jul 19, 2019
7b267d4
adds the rooter capability to the objdump plugin
ivg Jul 19, 2019
fe142f5
stores interprocedural edges in the symtab
ivg Jul 19, 2019
f83e10f
publishes the barrier property
ivg Jul 19, 2019
8ac85e7
improves the Program IR lifting
ivg Jul 19, 2019
f6d227d
respects inter falls only if there are no jumps
ivg Jul 19, 2019
d42a42f
adds support for kernel-style relocation back again
ivg Jul 22, 2019
832c8a7
fixes the sexp printer in Bap.Std.Bitvector
ivg Jul 23, 2019
d2c14f7
fixes the label printer in Bap.Std.Jmp
ivg Jul 23, 2019
15663a9
fixes the asm printer in the insn
ivg Jul 23, 2019
382391a
updates BAP Lisp to the changes in the Core Theory interface
ivg Jul 23, 2019
88e6a41
better error messages in byteweight
ivg Jul 23, 2019
8941054
fixes the bitvector comparison function
ivg Jul 23, 2019
0e5bdab
makes the code start a function start if none provided
ivg Jul 23, 2019
a318911
prevents two subroutines to claim the same identifier
ivg Jul 24, 2019
f3a7704
tracks call targets as subroutines
ivg Jul 24, 2019
f98d999
removes debugging output
ivg Jul 25, 2019
cbfbeeb
fixes instruction properties
ivg Jul 25, 2019
7e8f30b
restores conditional edges in the old-style CFG
ivg Jul 25, 2019
df8d7ed
simplifies IR lifter, since barrier implies return
ivg Jul 25, 2019
2aa6c38
ensures that the lifter fills in the insn
ivg Jul 25, 2019
94d9911
the driver now respects barriers
ivg Jul 25, 2019
a187482
a small doc update
ivg Jul 25, 2019
0d23d29
ensures that speculative falls are taken after speculative slots
ivg Jul 25, 2019
1d3c1c1
updates the microcfg test
ivg Jul 25, 2019
f8f4812
restores proper to_string/of_string functions for bitvectors
ivg Jul 29, 2019
926ee5c
updates the mini-projects test
ivg Jul 29, 2019
2815f5a
hacks llvm to prevent linking errors during toplevel loading
ivg Jul 29, 2019
0ee2434
provides at least basic information if no BIL is avaiable
ivg Jul 29, 2019
31f97eb
updates the testsuite
ivg Jul 29, 2019
87588d8
downgrades code to the dialect understandable by older OCamls
ivg Jul 30, 2019
95f37b4
updates the CI opam file with the removes for newly added libs
ivg Jul 30, 2019
60afbf7
makes most of the important properties persistent
ivg Jul 30, 2019
e9fc5e3
makes knowledge state serializable
ivg Jul 30, 2019
074552d
removes the toplevel state from the project
ivg Jul 30, 2019
17a7853
simplifies the toplevel representation
ivg Jul 30, 2019
459fb5d
adds knowledge caching to the frontend
ivg Jul 30, 2019
eaee9af
implements caching of the project state
ivg Jul 30, 2019
30fcc12
adds serialization to the callgraph
ivg Jul 30, 2019
a6dd011
Merge branch 'master' into bap-2.0
ivg Jul 31, 2019
5997006
eta-expands a function to mitigate a bug in 4.06 compiler
ivg Jul 31, 2019
fbf752d
bumps version to 2.0.0-alpha
ivg Aug 1, 2019
29f40c1
wires calls to the toplevel via the library
ivg Aug 1, 2019
0da8080
updates the testsuite
ivg Aug 5, 2019
f8d206b
enables boolean operations in the bitvec context
ivg Aug 7, 2019
82ec6d8
uses Var.create along with Var.Ident.of_string in CT Parser
ivg Aug 7, 2019
5abd3e5
stop reflecting temps to lets in the BIL Lifter
ivg Aug 7, 2019
d9b9dba
disables BIL optimizations and normalizations
ivg Aug 7, 2019
8bb8519
Merge remote-tracking branch 'upstream/master' into bap-2.0
ivg Aug 7, 2019
ef4f62d
updates testsuite
gitoleg Aug 7, 2019
bb6f068
fixes scoped variables
ivg Aug 7, 2019
9c34dba
keeps signed/unsigned casts abstraction
ivg Aug 7, 2019
a9645b7
enables two optimizations of the cast expressions
ivg Aug 8, 2019
4549e2c
publishes Bil semantics in the Bil_semantics interface
ivg Aug 8, 2019
99488ef
enables back the optimization
ivg Aug 8, 2019
7d219fb
updates the testsuite
ivg Aug 8, 2019
ae06058
Merge remote-tracking branch 'origin/bap-2.0' into bap-2.0
ivg Aug 8, 2019
92bb14a
fixes a small bug in the optimizer
ivg Aug 8, 2019
7773e0e
fixes the semantics printer
ivg Aug 8, 2019
f6c18d3
deletes a stale file
ivg Aug 8, 2019
2f023cc
fixes (again) Bitvector sexp representation
ivg Aug 9, 2019
0bfe192
prettifies inspectors for a couple of domains
ivg Aug 9, 2019
5dc259f
adds --dump=knowledge option to `bap` that dumps the knowledge base
ivg Aug 9, 2019
43f4c74
implements the fair control flow in Primus
ivg Aug 13, 2019
0a42892
updated submodule with bap-veri
gitoleg Aug 13, 2019
db33122
Merge remote-tracking branch 'origin/bap-2.0' into bap-2.0
ivg Aug 13, 2019
8b7e2a6
Merge remote-tracking branch 'upstream/master' into bap-2.0
ivg Aug 13, 2019
4f1094a
fixes Bitvec.to_int[X] converters for negative numbers
ivg Aug 13, 2019
1ac0c1e
fixed minor bug in module naming
gitoleg Aug 13, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
The following code allows ymm registers to be cast to smaller registe…
…rs. This new casting operation is used to extract xmm registers from ymm registers in order to support monomorphic functions in sse. The SysV ABI is updated to recognize functions that read and write to xmm0.
turnersr committed Feb 18, 2019

Unverified

The committer email address is not verified.
commit 0c1c4cd9f4122e29a4d0a69a70ba87cdeea145fc
23 changes: 12 additions & 11 deletions lib/bap_primus/bap_primus_lisp.ml
Original file line number Diff line number Diff line change
@@ -498,21 +498,23 @@ module Make(Machine : Machine) = struct
(fun msg -> fun () -> Machine.raise (Runtime_error msg)) ppf

let eval_args = Machine.List.map bs ~f:(fun (var,arg) ->
let open Bil.Types in
match Arg.rhs arg with
| Var v -> Eval.get v >>| fun w -> (var,w)
| Load (_,BinOp(op, Var sp, Int off),e,s) ->
Eval.get sp >>= fun sp ->
Eval.const off >>= fun off ->
Eval.binop op sp off >>= fun addr ->
Eval.load addr e s >>| fun w -> (var,w)
| _ -> failf "unsupported argument passing semantics" ())
Eval.exp (Arg.rhs arg) >>| fun w -> (var ,w))

let size_of_reg r = match Var.typ r with
| Imm x -> x
| _ -> assert false

let eval_ret r = match ret with
| None -> Machine.return ()
| Some v -> match Arg.rhs v with
| Bil.Var reg -> Eval.set reg r
| e -> failf "unknown return semantics: %a" Exp.pps e ()
| Bil.(Cast (LOW, rsize, Var reg)) ->
let vsize = size_of_reg reg in
Eval.get reg >>= fun lhs ->
Eval.extract ~hi:(vsize-1) ~lo:rsize lhs >>= fun high ->
Eval.concat high r >>= fun r ->
Eval.set reg r
| e -> failf "unknown return semantics: %a" Exp.pps e ()

let exec =
eval_args >>= fun bs ->
@@ -691,7 +693,6 @@ module Doc = struct
else sprintf "%s\nOR\n%s" x y) |>
Map.to_alist


let describe prog item =
Lisp.Program.get prog item |> List.map ~f:(fun x ->
Lisp.Def.name x, Lisp.Def.docs x) |> normalize
41 changes: 27 additions & 14 deletions plugins/x86/x86_abi.ml
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ module type abi = sig
val arch : Arch.x86
val name : string
val size : C.Size.base
val arg : pos -> exp
val arg : C.Type.t -> pos -> exp
val demangle : string -> string
val autodetect : project -> bool
end
@@ -29,7 +29,16 @@ module SysV = struct
let name = "sysv"
let arch = `x86_64
let stack n = Stack.create arch n
let arg = function


let xmm r = Bil.(cast low 64 (var ymms.(r)))

let flt = function
| Ret_0 -> xmm 0
| Ret_1 -> xmm 1
| Arg n -> xmm n

let int = function
| Ret_0 -> var rax
| Ret_1 -> var rdx
| Arg 0 -> var rdi
@@ -40,6 +49,10 @@ module SysV = struct
| Arg 5 -> var r.(1)
| Arg n -> stack Int.(n-6)

let arg = function
| `Basic {C.Type.Spec.t=`double} -> flt
| _ -> int

let size = object
inherit C.Size.base `LP64
end
@@ -53,7 +66,7 @@ module CDECL = struct
let name = "cdecl"
let arch = `x86
let stack n = Stack.create arch n
let arg = function
let arg _ = function
| Ret_0 -> var rax
| Ret_1 -> var rdx
| Arg n -> stack Int.(n+1)
@@ -90,7 +103,7 @@ end
module MS_64 = struct
include SysV
let name = "ms"
let arg = function
let arg _ = function
| Ret_0 -> var rax
| Ret_1 -> var rdx
| Arg 0 -> var rcx
@@ -111,10 +124,10 @@ end
module FASTCALL = struct
include CDECL
let name = "fastcall"
let arg = function
let arg t = function
| Arg 0 -> var rcx
| Arg 1 -> var rdx
| other -> arg other
| other -> arg t other
end

module WATCOM_STACK = struct
@@ -129,13 +142,13 @@ end
module WATCOM_REGS = struct
include WATCOM_STACK
let name = "watcom-regs"
let arg = function
let arg t = function
| Arg 0 -> var rax
| Arg 1 -> var rdx
| Arg 2 -> var rbx
| Arg 3 -> var rcx
| Arg n -> stack Int.(n-4)
| ret -> arg ret
| ret -> arg t ret
end

exception Unsupported
@@ -148,23 +161,23 @@ let supported_api (module Abi : abi) {C.Type.Proto.return; args} =
| None ->
warning "size of return object doesn't fit into word sizes";
raise Unsupported
| Some sz ->
| Some _ ->
let data = C.Abi.data Abi.size return in
if width > word && width <= word * 2
then Some (data, Bil.(Abi.arg Ret_0 ^ Abi.arg Ret_1))
then Some (data, Bil.(Abi.arg return Ret_0 ^ Abi.arg return Ret_1))
else if width <= word
then Some (data, Abi.arg Ret_0)
then Some (data, Abi.arg return Ret_0)
else
(warning "size of return object doesn't fit into double word\n";
raise Unsupported) in
let params = List.mapi args ~f:(fun i (n,t) ->
let params = List.mapi args ~f:(fun i (_,t) ->
match Abi.size#bits t with
| None ->
warning "size of %a parameter is unknown" C.Type.pp t;
raise Unsupported
| Some size -> match Size.of_int_opt size with
| Some sz when size <= word ->
C.Abi.data Abi.size t, Abi.arg (Arg i)
| Some _ when size <= word ->
C.Abi.data Abi.size t, Abi.arg t (Arg i)
| _ ->
warning "argument %d doesn't fit into word" i;
raise Unsupported) in