mirror of https://github.com/Nonannet/copapy.git
R_ARM_THM_MOV* support added
This commit is contained in:
parent
8fcf0dedac
commit
c7c8db6332
|
|
@ -393,14 +393,14 @@ def compile_to_dag(node_list: Iterable[Node], sdb: stencil_database) -> tuple[bi
|
||||||
# assemble stencils to main program and patch stencils
|
# assemble stencils to main program and patch stencils
|
||||||
data = sdb.get_function_code('entry_function_shell', 'start')
|
data = sdb.get_function_code('entry_function_shell', 'start')
|
||||||
data_list.append(data)
|
data_list.append(data)
|
||||||
print(f"* entry_function_shell (0) " + ' '.join(f'{d:02X}' for d in data))
|
#print(f"* entry_function_shell (0) " + ' '.join(f'{d:02X}' for d in data))
|
||||||
offset = aux_func_len + len(data)
|
offset = aux_func_len + len(data)
|
||||||
|
|
||||||
for associated_net, node in extended_output_ops:
|
for associated_net, node in extended_output_ops:
|
||||||
assert node.name in sdb.stencil_definitions, f"- Warning: {node.name} stencil not found"
|
assert node.name in sdb.stencil_definitions, f"- Warning: {node.name} stencil not found"
|
||||||
data = sdb.get_stencil_code(node.name)
|
data = sdb.get_stencil_code(node.name)
|
||||||
data_list.append(data)
|
data_list.append(data)
|
||||||
print(f"* {node.name} ({offset}) " + ' '.join(f'{d:02X}' for d in data))
|
#print(f"* {node.name} ({offset}) " + ' '.join(f'{d:02X}' for d in data))
|
||||||
|
|
||||||
for reloc in sdb.get_relocations(node.name, stencil=True):
|
for reloc in sdb.get_relocations(node.name, stencil=True):
|
||||||
if reloc.target_symbol_info in ('STT_OBJECT', 'STT_NOTYPE', 'STT_SECTION'):
|
if reloc.target_symbol_info in ('STT_OBJECT', 'STT_NOTYPE', 'STT_SECTION'):
|
||||||
|
|
@ -453,7 +453,7 @@ def compile_to_dag(node_list: Iterable[Node], sdb: stencil_database) -> tuple[bi
|
||||||
for reloc in sdb.get_relocations(name):
|
for reloc in sdb.get_relocations(name):
|
||||||
|
|
||||||
if not reloc.target_section_index:
|
if not reloc.target_section_index:
|
||||||
assert reloc.pelfy_reloc.type == 'R_ARM_V4BX', (reloc.pelfy_reloc.type, name)
|
assert reloc.pelfy_reloc.type == 'R_ARM_V4BX', (reloc.pelfy_reloc.type, name, reloc.pelfy_reloc.symbol.name)
|
||||||
|
|
||||||
elif reloc.target_symbol_info in {'STT_OBJECT', 'STT_NOTYPE', 'STT_SECTION'}:
|
elif reloc.target_symbol_info in {'STT_OBJECT', 'STT_NOTYPE', 'STT_SECTION'}:
|
||||||
# Patch constants/variable addresses on heap
|
# Patch constants/variable addresses on heap
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ from dataclasses import dataclass
|
||||||
from typing import Generator, Literal, Iterable, TYPE_CHECKING
|
from typing import Generator, Literal, Iterable, TYPE_CHECKING
|
||||||
import struct
|
import struct
|
||||||
import platform
|
import platform
|
||||||
|
import os
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
import pelfy
|
import pelfy
|
||||||
|
|
@ -46,6 +47,10 @@ class patch_entry:
|
||||||
|
|
||||||
|
|
||||||
def detect_process_arch() -> str:
|
def detect_process_arch() -> str:
|
||||||
|
cp_target_arch = os.environ.get("CP_TARGET_ARCH")
|
||||||
|
if cp_target_arch:
|
||||||
|
return cp_target_arch
|
||||||
|
|
||||||
bits = struct.calcsize("P") * 8
|
bits = struct.calcsize("P") * 8
|
||||||
arch = platform.machine().lower()
|
arch = platform.machine().lower()
|
||||||
|
|
||||||
|
|
@ -305,21 +310,20 @@ class stencil_database():
|
||||||
scale = 8
|
scale = 8
|
||||||
#print(f" *> {patch_value=} {symbol_address=} {pr.fields['r_addend']=}, {function_offset=}")
|
#print(f" *> {patch_value=} {symbol_address=} {pr.fields['r_addend']=}, {function_offset=}")
|
||||||
|
|
||||||
elif pr.type.endswith('_MOVW_ABS_NC'):
|
elif pr.type == 'R_ARM_MOVW_ABS_NC':
|
||||||
# R_ARM_MOVW_ABS_NC
|
|
||||||
# (S + A) & 0xFFFF
|
# (S + A) & 0xFFFF
|
||||||
mask = 0xFFFF
|
mask = 0xFFFF
|
||||||
patch_value = symbol_address + pr.fields['r_addend']
|
patch_value = symbol_address + pr.fields['r_addend']
|
||||||
symbol_type = symbol_type + 0x04 # Absolut value
|
symbol_type = symbol_type + 0x04 # Absolut value
|
||||||
#print(f" *> {pr.type} {patch_value=} {symbol_address=}, {function_offset=}")
|
#print(f" *> {pr.type} {patch_value=} {symbol_address=}, {function_offset=}")
|
||||||
|
|
||||||
elif pr.type.endswith('_MOVT_ABS'):
|
elif pr.type =='R_ARM_MOVT_ABS':
|
||||||
# R_ARM_MOVT_ABS
|
|
||||||
# (S + A) & 0xFFFF0000
|
# (S + A) & 0xFFFF0000
|
||||||
mask = 0xFFFF0000
|
mask = 0xFFFF0000
|
||||||
patch_value = symbol_address + pr.fields['r_addend']
|
patch_value = symbol_address + pr.fields['r_addend']
|
||||||
symbol_type = symbol_type + 0x04 # Absolut value
|
symbol_type = symbol_type + 0x04 # Absolut value
|
||||||
scale = 0x10000
|
scale = 0x10000
|
||||||
|
#print(f" *> {pr.type} {patch_value=} {symbol_address=}, {function_offset=}, {pr.fields['r_addend']=}")
|
||||||
|
|
||||||
elif pr.type.endswith('_ABS32'):
|
elif pr.type.endswith('_ABS32'):
|
||||||
# R_ARM_ABS32
|
# R_ARM_ABS32
|
||||||
|
|
@ -330,9 +334,24 @@ class stencil_database():
|
||||||
elif pr.type.endswith('_THM_JUMP24') or pr.type.endswith('_THM_CALL'):
|
elif pr.type.endswith('_THM_JUMP24') or pr.type.endswith('_THM_CALL'):
|
||||||
# R_ARM_THM_JUMP24
|
# R_ARM_THM_JUMP24
|
||||||
# S + A - P
|
# S + A - P
|
||||||
#assert pr.fields['r_addend'] == 0, pr.fields['r_addend']
|
patch_value = symbol_address - patch_offset + pr.fields['r_addend']
|
||||||
patch_value = symbol_address - (patch_offset + 4) #+ pr.fields['r_addend']
|
|
||||||
symbol_type = symbol_type + 0x05 # PATCH_FUNC_ARM32_THM
|
symbol_type = symbol_type + 0x05 # PATCH_FUNC_ARM32_THM
|
||||||
|
#print(f" *> {pr.type} {patch_value=} {symbol_address=} {pr.fields['r_addend']=} {pr.bits=}, {function_offset=} {patch_offset=}")
|
||||||
|
|
||||||
|
elif pr.type == 'R_ARM_THM_MOVW_ABS_NC':
|
||||||
|
# (S + A) & 0xFFFF
|
||||||
|
mask = 0xFFFF
|
||||||
|
patch_value = symbol_address + pr.fields['r_addend']
|
||||||
|
symbol_type = symbol_type + 0x06 # PATCH_OBJECT_ARM32_ABS_THM
|
||||||
|
#print(f" *> {pr.type} {patch_value=} {symbol_address=}, {function_offset=}, {pr.fields['r_addend']=}")
|
||||||
|
|
||||||
|
elif pr.type == 'R_ARM_THM_MOVT_ABS':
|
||||||
|
# (S + A) & 0xFFFF0000
|
||||||
|
mask = 0xFFFF0000
|
||||||
|
patch_value = symbol_address + pr.fields['r_addend']
|
||||||
|
symbol_type = symbol_type + 0x06 # PATCH_OBJECT_ARM32_ABS_THM
|
||||||
|
scale = 0x10000
|
||||||
|
#print(f" *> {pr.type} {patch_value=} {symbol_address=}, {function_offset=}, {pr.fields['r_addend']=}")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError(f"Relocation type {pr.type} in {relocation.pelfy_reloc.target_section.name} pointing to {relocation.pelfy_reloc.symbol.name} not implemented")
|
raise NotImplementedError(f"Relocation type {pr.type} in {relocation.pelfy_reloc.target_section.name} pointing to {relocation.pelfy_reloc.symbol.name} not implemented")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue