Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 12 additions & 4 deletions chb/api/AppFunctionSignature.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# ------------------------------------------------------------------------------
# The MIT License (MIT)
#
# Copyright (c) 2023 Aarno Labs LLC
# Copyright (c) 2023-2024 Aarno Labs LLC
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -54,7 +54,9 @@ class AppFunctionSignature(InterfaceDictionaryRecord):
args[6..]: indices of registers preserved (not normally preserved)
"""

def __init__(self, ixd: "InterfaceDictionary", ixval: IndexedTableValue) -> None:
def __init__(
self, ixd: "InterfaceDictionary", ixval: IndexedTableValue
) -> None:
InterfaceDictionaryRecord.__init__(self, ixd, ixval)

@property
Expand All @@ -69,16 +71,22 @@ def parameter_list(self) -> List["FtsParameter"]:
def returntype(self) -> "BCTyp":
return self.bcd.typ(self.args[3])

def index_of_register_parameter_location(self, r: "Register") -> Optional[int]:
def index_of_register_parameter_location(
self, r: "Register") -> Optional[int]:
for p in self.parameter_list:
if p.is_register_parameter_location(r):
return p.argindex
return None

def index_of_stack_parameter_location(self, offset: int) -> Optional[int]:
for p in self.parameter_list:
if p.is_stack_parameter_location(offset):
return p.argindex
return None

def __str__(self) -> str:
return (
str(self.returntype)
+ " ("
+ ", ".join(str(p) for p in self.parameter_list)
+ ")")

7 changes: 6 additions & 1 deletion chb/api/FtsParameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# ------------------------------------------------------------------------------
# The MIT License (MIT)
#
# Copyright (c) 2023 Aarno Labs LLC
# Copyright (c) 2023-2024 Aarno Labs LLC
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -80,5 +80,10 @@ def is_register_parameter_location(self, r: "Register") -> bool:
return self.parameter_location_list[0].is_register_parameter_location_of(r)
return False

def is_stack_parameter_location(self, offset: int) -> bool:
if len(self.parameter_location_list) == 1:
return self.parameter_location_list[0].is_stack_parameter_location_of(offset)
return False

def __str__(self) -> str:
return str(self.typ) + " " + str(self.name)
10 changes: 8 additions & 2 deletions chb/api/FtsParameterLocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# ------------------------------------------------------------------------------
# The MIT License (MIT)
#
# Copyright (c) 2023 Aarno Labs LLC
# Copyright (c) 2023-2024 Aarno Labs LLC
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -81,6 +81,9 @@ def is_unknown_location(self) -> bool:
def is_register_parameter_location_of(self, r: "Register") -> bool:
return False

def is_stack_parameter_location_of(self, offset: int) -> bool:
return False


@apiregistry.register_tag("s", FtsParameterLocation)
class FtsStackParameter(FtsParameterLocation):
Expand All @@ -98,9 +101,12 @@ def is_stack_parameter(self) -> bool:
return True

@property
def index(self) -> int:
def offset(self) -> int:
return self.args[0]

def is_stack_parameter_location_of(self, offset: int) -> bool:
return offset == self.offset

def __str__(self) -> str:
return "stack-parameter " + str(self.index)

Expand Down
12 changes: 12 additions & 0 deletions chb/app/AppAccess.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
from chb.app.Function import Function
from chb.app.FunctionInfo import FunctionInfo
from chb.app.FunctionsData import FunctionsData
from chb.app.GlobalMemoryMap import GlobalMemoryMap
from chb.app.JumpTables import JumpTables
from chb.app.SystemInfo import SystemInfo
from chb.app.StringXRefs import StringsXRefs
Expand Down Expand Up @@ -128,6 +129,7 @@ def __init__(
self._bcfiles: Optional[BCFiles] = None

self._typeconstraints = TypeConstraintStore(self)
self._globalmemorymap: Optional[GlobalMemoryMap] = None
self._systeminfo: Optional[SystemInfo] = None

@property
Expand Down Expand Up @@ -190,6 +192,16 @@ def tcdictionary(self) -> TypeConstraintDictionary:
self._tcdictionary = TypeConstraintDictionary(self, None)
return self._tcdictionary

@property
def globalmemorymap(self) -> GlobalMemoryMap:
if self._globalmemorymap is None:
if UF.has_global_locations_file(self.path, self.filename):
x = UF.get_global_locations_xnode(self.path, self.filename)
self._globalmemorymap = GlobalMemoryMap(self, x)
else:
self._globalmemorymap = GlobalMemoryMap(self, None)
return self._globalmemorymap

@property
def bdictionary(self) -> BDictionary:
if self._bdictionary is None:
Expand Down
2 changes: 1 addition & 1 deletion chb/app/CHVersion.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
chbversion: str = "0.3.0-20241111"
chbversion: str = "0.3.0-20250203"
50 changes: 50 additions & 0 deletions chb/app/Function.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
from chb.app.FnProofObligations import FnProofObligations
from chb.app.FnXPODictionary import FnXPODictionary
from chb.app.FunctionInfo import FunctionInfo
from chb.app.GlobalMemoryMap import (
GlobalLoad, GlobalStore, GlobalAddressArgument)
from chb.app.Instruction import Instruction
from chb.app.JumpTables import JumpTable
from chb.app.StackLayout import StackLayout
Expand All @@ -84,9 +86,14 @@

import chb.util.fileutil as UF
from chb.util.graphutil import coalesce_lists
from chb.util.loggingutil import chklogger


if TYPE_CHECKING:
from chb.app.AppAccess import AppAccess
from chb.app.FnStackFrame import FnStackFrame
from chb.app.GlobalMemoryMap import (
GlobalMemoryMap, GlobalLocation, GlobalReference)
from chb.bctypes.BCTyp import BCTyp


Expand Down Expand Up @@ -119,6 +126,7 @@ def __init__(
self._invariants: Dict[str, List[InvariantFact]] = {}
self._varinvariants: Dict[str, List[VarInvariantFact]] = {}
self._stacklayout: Optional[StackLayout] = None
self._globalrefs: Optional[Dict[str, List["GlobalReference"]]] = None
self._proofobligations: Optional[FnProofObligations] = None

@property
Expand All @@ -129,6 +137,10 @@ def path(self) -> str:
def filename(self) -> str:
return self._filename

@property
def app(self) -> "AppAccess":
return self.ixd.app

@property
def bd(self) -> BDictionary:
return self._bd
Expand Down Expand Up @@ -544,6 +556,44 @@ def stacklayout(self) -> StackLayout:
self._stacklayout = stacklayout
return self._stacklayout

def globalrefs(self) -> Dict[str, List["GlobalReference"]]:
if self._globalrefs is None:
self._globalrefs = {}
gnode = self.xnode.find("global-references")
if gnode is not None:
glnode = gnode.find("location-references")
if glnode is not None:
for rnode in glnode.findall("gref"):
gaddr = rnode.get("g")
if gaddr is None:
chklogger.logger.error(
"Global address is missing in xml gref")
continue
gloc = self.app.globalmemorymap.get_location(gaddr)
if gloc is None:
chklogger.logger.error(
"Global location is missing for %s", gaddr)
continue
gt = rnode.get("t")
if gt is None:
chklogger.logger.error(
"Global reference type is missing for %s", gaddr)
continue
if gt == "L":
gref: "GlobalReference" = GlobalLoad(self, gloc, rnode)
elif gt == "S":
gref = GlobalStore(self, gloc, rnode)
elif gt == "CA":
gref = GlobalAddressArgument(self, gloc, rnode)
else:
chklogger.logger.error(
"Global reference type %s not recognized for %s",
gt, gaddr)
continue
self._globalrefs.setdefault(gaddr, [])
self._globalrefs[gaddr].append(gref)
return self._globalrefs

@abstractmethod
def to_string(
self,
Expand Down
Loading