Skip to content

Commit fb6e54d

Browse files
committed
CHB:ARM: updates for result types
1 parent 71e8a9e commit fb6e54d

File tree

6 files changed

+85
-17
lines changed

6 files changed

+85
-17
lines changed

CodeHawk/CHB/bchlib/bCHFloc.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1271,7 +1271,8 @@ object (self)
12711271
let maxC = largest_constant_term x in
12721272
let maxCdw = TR.tvalue (numerical_to_doubleword maxC) ~default:wordzero in
12731273
(* if maxC#gt system_info#get_image_base#to_numerical then *)
1274-
if system_info#is_code_address maxCdw then
1274+
if system_info#is_code_address maxCdw
1275+
|| memmap#is_global_data_address maxCdw then
12751276
(* global base *)
12761277
let memref_r = Ok self#env#mk_global_memory_reference in
12771278
let offset = simplify_xpr (XOp (XMinus, [x; num_constant_expr maxC])) in

CodeHawk/CHB/bchlib/bCHGlobalMemoryMap.ml

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,8 @@ object (self)
341341
&& Option.is_none tgtbtype ->
342342
Ok (ArrayIndexOffset (indexxpr, NoOffset))
343343
| Some (indexxpr, rem) ->
344-
if is_struct_type eltty then
344+
if (TR.tfold_default is_struct_type false (resolve_type eltty)) then
345+
let eltty = TR.tvalue (resolve_type eltty) ~default:t_unknown in
345346
tbind
346347
(fun suboff -> Ok (ArrayIndexOffset (indexxpr, suboff)))
347348
(self#structvar_memory_offset ~tgtsize ~tgtbtype eltty rem)
@@ -356,7 +357,8 @@ object (self)
356357
else
357358
Error[__FILE__ ^ ":" ^ (string_of_int __LINE__) ^ ":"
358359
^ "xoffset: " ^ (x2s xoffset)
359-
^ "; btype: " ^ (btype_to_string btype)])
360+
^ "; btype: " ^ (btype_to_string btype)
361+
^ "; elementtype: " ^ (btype_to_string eltty)])
360362
(size_of_btype eltty)
361363
else
362364
Error [__FILE__ ^ ":" ^ (string_of_int __LINE__) ^ ":"
@@ -382,11 +384,14 @@ object (self)
382384
| XConst (IntConst n) when not self#is_typed ->
383385
Ok (ConstantOffset (n, NoOffset))
384386
| _ ->
385-
let tgtbtype = if is_unknown_type tgtbtype then None else Some tgtbtype in
387+
let tgtbtype =
388+
if is_unknown_type tgtbtype then None else Some tgtbtype in
386389
if self#is_struct then
387-
self#structvar_memory_offset ~tgtsize ~tgtbtype self#btype xoffset
390+
let btype = TR.tvalue (resolve_type self#btype) ~default:t_unknown in
391+
self#structvar_memory_offset ~tgtsize ~tgtbtype btype xoffset
388392
else if self#is_array then
389-
self#arrayvar_memory_offset ~tgtsize ~tgtbtype self#btype xoffset
393+
let btype = TR.tvalue (resolve_type self#btype) ~default:t_unknown in
394+
self#arrayvar_memory_offset ~tgtsize ~tgtbtype self#btype xoffset
390395
else
391396
Error [__FILE__ ^ ":" ^ (string_of_int __LINE__) ^ ":"
392397
^ (btype_to_string self#btype)
@@ -429,6 +434,16 @@ object (self)
429434
(name: string)
430435
(addr: doubleword_int)
431436
(size: doubleword_int) =
437+
let _ =
438+
chlog#add
439+
"globalmemorymap:set_section"
440+
(LBLOCK [
441+
STR name;
442+
STR ": @";
443+
addr#toPretty;
444+
STR " (";
445+
size#toPretty;
446+
STR " bytes)"]) in
432447
H.add sections addr#value (name, size#value, readonly, initialized)
433448

434449
method private is_initialized (addr: doubleword_int): bool =

CodeHawk/CHB/bchlibarm32/bCHARMJumptable.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ let is_ldrls_jumptable
528528
let indexreg = indexregop#get_register in
529529
let cmptestf = cmp_reg_imm_test indexreg in
530530
let addr = ldrinstr#get_address in
531-
let optcmpinstr = find_instr cmptestf [(-4)] addr in
531+
let optcmpinstr = find_instr cmptestf [(-4); (-16)] addr in
532532
(match optcmpinstr with
533533
| Some cmpinstr ->
534534
let branchtestf instr =

CodeHawk/CHB/bchlibarm32/bCHARMOperand.ml

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
------------------------------------------------------------------------------
55
The MIT License (MIT)
66
7-
Copyright (c) 2021-2024 Aarno Labs, LLC
7+
Copyright (c) 2021-2025 Aarno Labs, LLC
88
99
Permission is hereby granted, free of charge, to any person obtaining a copy
1010
of this software and associated documentation files (the "Software"), to deal
@@ -475,12 +475,31 @@ object (self:'a)
475475
floc#get_memory_variable_numoffset ~size ~align rvar memoff)
476476
numoffset_r
477477

478+
| ARMIndexOffset (ri, i) ->
479+
let rvar = env#mk_arm_register_variable r in
480+
let ivar = env#mk_arm_register_variable ri in
481+
if isadd then
482+
let rx = floc#inv#rewrite_expr (XVar rvar) in
483+
let ivax = floc#inv#rewrite_expr (XVar ivar) in
484+
let xoffset = simplify_xpr (XOp (XPlus, [rx; ivax])) in
485+
(match (xoffset, i) with
486+
| (XConst (IntConst n), 0) ->
487+
floc#env#mk_global_variable ~size n
488+
| _ ->
489+
floc#get_memory_variable_varoffset
490+
~size rvar ivar (mkNumerical i))
491+
else
492+
Error [__FILE__ ^ ":" ^ (string_of_int __LINE__) ^ ": "
493+
^ "Index offset with is_add false not yet supported: "
494+
^ (p2s self#toPretty)]
495+
478496
| ARMShiftedIndexOffset _ ->
479497
let rvar = env#mk_arm_register_variable r in
480498
(match (offset, isadd) with
481499
| (ARMShiftedIndexOffset (ivar, srt, i), true) ->
482500
let optscale =
483501
match srt with
502+
| ARMImmSRT (SRType LSL, 3) -> Some 8
484503
| ARMImmSRT (SRType_LSL, 2) -> Some 4
485504
| ARMImmSRT (SRType_LSL, 0) -> Some 1
486505
| _ -> None in
@@ -491,8 +510,8 @@ object (self:'a)
491510
let rx = floc#inv#rewrite_expr (XVar rvar) in
492511
let ivax = floc#inv#rewrite_expr (XVar ivar) in
493512
let xoffset = simplify_xpr (XOp (XPlus, [rx; ivax])) in
494-
(match xoffset with
495-
| XConst (IntConst n) ->
513+
(match (xoffset, i) with
514+
| (XConst (IntConst n), 0) ->
496515
floc#env#mk_global_variable ~size n
497516
| _ ->
498517
floc#get_memory_variable_varoffset
@@ -509,12 +528,7 @@ object (self:'a)
509528
Error [__FILE__ ^ ":" ^ (string_of_int __LINE__) ^ ": "
510529
^ "Shifted Index Offset with isadd: false: "
511530
^ (p2s self#toPretty)
512-
^ " not yet supported"])
513-
514-
| _ ->
515-
Error [__FILE__ ^ ":" ^ (string_of_int __LINE__) ^ ": "
516-
^ "Index Offset address: " ^ (p2s self#toPretty)
517-
^ " not yet supported"])
531+
^ " not yet supported"]))
518532

519533
| ARMShiftedReg (r, ARMImmSRT (SRType_LSL, 0)) ->
520534
Ok (env#mk_arm_register_variable r)

CodeHawk/CHB/bchlibarm32/bCHFnARMDictionary.ml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,12 @@ object (self)
536536
let rdefcount = List.length rdefs in
537537
let tagstring = tagstring ^ (string_repeat "x" xprcount) in
538538
let tagstring = tagstring ^ (string_repeat "r" rdefcount) in
539-
let args = args @ (List.map index_xpr xprs_r) @ rdefs in
539+
(* move the call target index (into the interface dictionary) to the
540+
end of args list, so it is not interpreted as an expression *)
541+
let args_calltgt_ix = List.hd (List.rev args) in
542+
let args_proper = List.rev (List.tl (List.rev args)) in
543+
let args = args_proper @ (List.map index_xpr xprs_r) @ rdefs in
544+
let args = args @ [args_calltgt_ix] in
540545
let tags = (tagstring :: (List.tl tags)) @ ["bx-call"] in
541546
(tags, args) in
542547

@@ -601,6 +606,7 @@ object (self)
601606
^ "Parameter type not recognized in call instruction"] in
602607
let ptype = get_parameter_type p in
603608
let xx = rewrite_expr ?restrict:(Some 4) x in
609+
(*
604610
let xx =
605611
if is_pointer ptype then
606612
let _ = floc#memrecorder#record_argument xx index in
@@ -616,6 +622,7 @@ object (self)
616622
(floc#get_var_at_address ~btype:ptype xx)
617623
else
618624
xx in
625+
*)
619626
let rdef = get_rdef_r xvar_r in
620627
(xx :: xprs, xvar_r :: xvars, rdef :: rdefs, index + 1))
621628
([], [], [], 1) callargs in

CodeHawk/CHB/bchlibarm32/bCHFnARMTypeConstraints.ml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,37 @@ object (self)
927927
(* no type information gained *)
928928
()
929929

930+
| SignedMultiplyLong (_, _, rdlo, rdhi, rn, rm) ->
931+
let rdloreg = rdlo#to_register in
932+
let lhslotypevar = mk_reglhs_typevar rdloreg faddr iaddr in
933+
let rdhireg = rdhi#to_register in
934+
let lhshitypevar = mk_reglhs_typevar rdhireg faddr iaddr in
935+
let rnreg = rn#to_register in
936+
let rndefs = get_variable_rdefs_r (rn#to_variable floc) in
937+
let rmreg = rm#to_register in
938+
let rmdefs = get_variable_rdefs_r (rm#to_variable floc) in
939+
940+
let tc = mk_int_type_constant Signed 32 in
941+
let tctypeterm = mk_cty_term tc in
942+
let lhslotypeterm = mk_vty_term lhslotypevar in
943+
let lhshitypeterm = mk_vty_term lhshitypevar in
944+
begin
945+
store#add_subtype_constraint tctypeterm lhslotypeterm;
946+
store#add_subtype_constraint tctypeterm lhshitypeterm;
947+
948+
(List.iter (fun rnrdef ->
949+
let rnaddr = rnrdef#getBaseName in
950+
let rntypevar = mk_reglhs_typevar rnreg faddr rnaddr in
951+
let rntypeterm = mk_vty_term rntypevar in
952+
store#add_subtype_constraint tctypeterm rntypeterm) rndefs);
953+
954+
(List.iter (fun rmrdef ->
955+
let rmaddr = rmrdef#getBaseName in
956+
let rmtypevar = mk_reglhs_typevar rmreg faddr rmaddr in
957+
let rmtypeterm = mk_vty_term rmtypevar in
958+
store#add_subtype_constraint tctypeterm rmtypeterm) rmdefs)
959+
end
960+
930961
(* Store x in y --- *y := x --- X <: Y.store *)
931962
| StoreRegister (_, rt, _rn, rm, memvarop, _) when rm#is_immediate ->
932963
let xaddr_r = memvarop#to_address floc in

0 commit comments

Comments
 (0)