file names adjusted

This commit is contained in:
Nicolas 2025-10-08 22:59:51 +02:00
parent 5723fc0085
commit 45c7fa5b3b
13 changed files with 373 additions and 85 deletions

View File

@ -22,7 +22,7 @@ jobs:
gcc-12-riscv64-linux-gnu
- name: Build object files
run: bash src/copapy/obj/crosscompile.sh
run: bash tools/crosscompile.sh
- uses: actions/upload-artifact@v4
with:

View File

@ -13,7 +13,7 @@ jobs:
- uses: actions/checkout@v4
- name: Build object files
run: bash src/copapy/obj/nativecompile.sh
run: bash tools/nativecompile.sh
- uses: actions/upload-artifact@v4
with:

2
.gitignore vendored
View File

@ -10,7 +10,6 @@ __pycache__
.pytest_cache
/tests/autogenerated_*.py
*test*.o
/bin/*
token.txt
/src/copapy/obj/*.o
/src/copapy/obj/old/*.o
@ -20,5 +19,4 @@ bin/*
build/*
/*.obj
/src/*.pyd
src/copapy/stencils.c
vc140.pdb

View File

@ -1,6 +0,0 @@
#!/bin/bash
source build.sh
python tests/test_compile_div.py
python tools/extract_code.py
objdump -D -b binary -m i386:x86-64 --adjust-vma=0x1000 bin/test_code.bin > bin/test_code.bin.txt

291
src/copapy/stencils.c Normal file
View File

@ -0,0 +1,291 @@
// Auto-generated stencils for copapy
// Do not edit manually
volatile int dummy_int = 1337;
volatile float dummy_float = 1337;
void result_int(int arg1);
void result_float(float arg1);
void result_int_int(int arg1, int arg2);
void result_int_float(int arg1, float arg2);
void result_float_int(float arg1, int arg2);
void result_float_float(float arg1, float arg2);
void add_int_int(int arg1, int arg2) {
asm volatile (".long 0xE1401F0F");
result_int_int(arg1 + arg2, arg2);
asm volatile (".long 0xE2401F0F");
}
void add_int_float(int arg1, float arg2) {
asm volatile (".long 0xE1401F0F");
result_float_float(arg1 + arg2, arg2);
asm volatile (".long 0xE2401F0F");
}
void add_float_int(float arg1, int arg2) {
asm volatile (".long 0xE1401F0F");
result_float_int(arg1 + arg2, arg2);
asm volatile (".long 0xE2401F0F");
}
void add_float_float(float arg1, float arg2) {
asm volatile (".long 0xE1401F0F");
result_float_float(arg1 + arg2, arg2);
asm volatile (".long 0xE2401F0F");
}
void sub_int_int(int arg1, int arg2) {
asm volatile (".long 0xE1401F0F");
result_int_int(arg1 - arg2, arg2);
asm volatile (".long 0xE2401F0F");
}
void sub_int_float(int arg1, float arg2) {
asm volatile (".long 0xE1401F0F");
result_float_float(arg1 - arg2, arg2);
asm volatile (".long 0xE2401F0F");
}
void sub_float_int(float arg1, int arg2) {
asm volatile (".long 0xE1401F0F");
result_float_int(arg1 - arg2, arg2);
asm volatile (".long 0xE2401F0F");
}
void sub_float_float(float arg1, float arg2) {
asm volatile (".long 0xE1401F0F");
result_float_float(arg1 - arg2, arg2);
asm volatile (".long 0xE2401F0F");
}
void mul_int_int(int arg1, int arg2) {
asm volatile (".long 0xE1401F0F");
result_int_int(arg1 * arg2, arg2);
asm volatile (".long 0xE2401F0F");
}
void mul_int_float(int arg1, float arg2) {
asm volatile (".long 0xE1401F0F");
result_float_float(arg1 * arg2, arg2);
asm volatile (".long 0xE2401F0F");
}
void mul_float_int(float arg1, int arg2) {
asm volatile (".long 0xE1401F0F");
result_float_int(arg1 * arg2, arg2);
asm volatile (".long 0xE2401F0F");
}
void mul_float_float(float arg1, float arg2) {
asm volatile (".long 0xE1401F0F");
result_float_float(arg1 * arg2, arg2);
asm volatile (".long 0xE2401F0F");
}
void div_int_int(int arg1, int arg2) {
asm volatile (".long 0xE1401F0F");
result_float_int((float)arg1 / arg2, arg2);
asm volatile (".long 0xE2401F0F");
}
void div_int_float(int arg1, float arg2) {
asm volatile (".long 0xE1401F0F");
result_float_float((float)arg1 / arg2, arg2);
asm volatile (".long 0xE2401F0F");
}
void div_float_int(float arg1, int arg2) {
asm volatile (".long 0xE1401F0F");
result_float_int(arg1 / arg2, arg2);
asm volatile (".long 0xE2401F0F");
}
void div_float_float(float arg1, float arg2) {
asm volatile (".long 0xE1401F0F");
result_float_float(arg1 / arg2, arg2);
asm volatile (".long 0xE2401F0F");
}
void gt_int_int(int arg1, int arg2) {
asm volatile (".long 0xE1401F0F");
result_int_int(arg1 > arg2, arg2);
asm volatile (".long 0xE2401F0F");
}
void gt_int_float(int arg1, float arg2) {
asm volatile (".long 0xE1401F0F");
result_float_float(arg1 > arg2, arg2);
asm volatile (".long 0xE2401F0F");
}
void gt_float_int(float arg1, int arg2) {
asm volatile (".long 0xE1401F0F");
result_float_int(arg1 > arg2, arg2);
asm volatile (".long 0xE2401F0F");
}
void gt_float_float(float arg1, float arg2) {
asm volatile (".long 0xE1401F0F");
result_float_float(arg1 > arg2, arg2);
asm volatile (".long 0xE2401F0F");
}
void eq_int_int(int arg1, int arg2) {
asm volatile (".long 0xE1401F0F");
result_int_int(arg1 == arg2, arg2);
asm volatile (".long 0xE2401F0F");
}
void eq_int_float(int arg1, float arg2) {
asm volatile (".long 0xE1401F0F");
result_float_float(arg1 == arg2, arg2);
asm volatile (".long 0xE2401F0F");
}
void eq_float_int(float arg1, int arg2) {
asm volatile (".long 0xE1401F0F");
result_float_int(arg1 == arg2, arg2);
asm volatile (".long 0xE2401F0F");
}
void eq_float_float(float arg1, float arg2) {
asm volatile (".long 0xE1401F0F");
result_float_float(arg1 == arg2, arg2);
asm volatile (".long 0xE2401F0F");
}
void mod_int_int(int arg1, int arg2) {
asm volatile (".long 0xE1401F0F");
result_int_int(arg1 % arg2, arg2);
asm volatile (".long 0xE2401F0F");
}
void read_int_reg0_int_int(int arg1, int arg2) {
asm volatile (".long 0xE1401F0F");
result_int_int(dummy_int, arg2);
asm volatile (".long 0xE2401F0F");
}
void read_int_reg1_int_int(int arg1, int arg2) {
asm volatile (".long 0xE1401F0F");
result_int_int(arg1, dummy_int);
asm volatile (".long 0xE2401F0F");
}
void read_float_reg0_int_int(int arg1, int arg2) {
asm volatile (".long 0xE1401F0F");
result_float_int(dummy_float, arg2);
asm volatile (".long 0xE2401F0F");
}
void read_float_reg1_int_int(int arg1, int arg2) {
asm volatile (".long 0xE1401F0F");
result_int_float(arg1, dummy_float);
asm volatile (".long 0xE2401F0F");
}
void read_int_reg0_int_float(int arg1, float arg2) {
asm volatile (".long 0xE1401F0F");
result_int_float(dummy_int, arg2);
asm volatile (".long 0xE2401F0F");
}
void read_int_reg1_int_float(int arg1, float arg2) {
asm volatile (".long 0xE1401F0F");
result_int_int(arg1, dummy_int);
asm volatile (".long 0xE2401F0F");
}
void read_float_reg0_int_float(int arg1, float arg2) {
asm volatile (".long 0xE1401F0F");
result_float_float(dummy_float, arg2);
asm volatile (".long 0xE2401F0F");
}
void read_float_reg1_int_float(int arg1, float arg2) {
asm volatile (".long 0xE1401F0F");
result_int_float(arg1, dummy_float);
asm volatile (".long 0xE2401F0F");
}
void read_int_reg0_float_int(float arg1, int arg2) {
asm volatile (".long 0xE1401F0F");
result_int_int(dummy_int, arg2);
asm volatile (".long 0xE2401F0F");
}
void read_int_reg1_float_int(float arg1, int arg2) {
asm volatile (".long 0xE1401F0F");
result_float_int(arg1, dummy_int);
asm volatile (".long 0xE2401F0F");
}
void read_float_reg0_float_int(float arg1, int arg2) {
asm volatile (".long 0xE1401F0F");
result_float_int(dummy_float, arg2);
asm volatile (".long 0xE2401F0F");
}
void read_float_reg1_float_int(float arg1, int arg2) {
asm volatile (".long 0xE1401F0F");
result_float_float(arg1, dummy_float);
asm volatile (".long 0xE2401F0F");
}
void read_int_reg0_float_float(float arg1, float arg2) {
asm volatile (".long 0xE1401F0F");
result_int_float(dummy_int, arg2);
asm volatile (".long 0xE2401F0F");
}
void read_int_reg1_float_float(float arg1, float arg2) {
asm volatile (".long 0xE1401F0F");
result_float_int(arg1, dummy_int);
asm volatile (".long 0xE2401F0F");
}
void read_float_reg0_float_float(float arg1, float arg2) {
asm volatile (".long 0xE1401F0F");
result_float_float(dummy_float, arg2);
asm volatile (".long 0xE2401F0F");
}
void read_float_reg1_float_float(float arg1, float arg2) {
asm volatile (".long 0xE1401F0F");
result_float_float(arg1, dummy_float);
asm volatile (".long 0xE2401F0F");
}
void write_int(int arg1) {
asm volatile (".long 0xE1401F0F");
dummy_int = arg1;
result_int(arg1);
asm volatile (".long 0xE2401F0F");
}
void write_float(float arg1) {
asm volatile (".long 0xE1401F0F");
dummy_float = arg1;
result_float(arg1);
asm volatile (".long 0xE2401F0F");
}
int function_start(){
result_int(0); // dummy call instruction before marker gets striped
asm volatile (".long 0xE2401F0F");
return 1;
}
int function_end(){
result_int(0);
asm volatile (".long 0xE1401F0F");
return 1;
}

View File

@ -1,7 +0,0 @@
#!/bin/bash
set -e
echo "Compile..."
python tests/test_compile.py
echo "Run..."
echo "-----------------------------------"
bin/coparun bin/test.copapy

View File

@ -1,9 +1,9 @@
#!/bin/bash
set -e
set -v
SRC=src/copapy/stencils.c
SRC=bin/stencils.c
DEST=src/copapy/obj
python src/copapy/generate_stencils.py $SRC
python tools/generate_stencils.py $SRC
mkdir -p $DEST
gcc -c $SRC -O0 -o $DEST/stencils_x86_64_O0.o
gcc -c $SRC -O1 -o $DEST/stencils_x86_64_O1.o

View File

@ -13,18 +13,18 @@
set -e
set -v
SRC=src/copapy/stencils.c
SRC=bin/stencils.c
DEST=src/copapy/obj
OPT=O3
mkdir -p $DEST
# Windows x86_64 (ARM64)
python src/copapy/generate_stencils.py --abi ms $SRC
python tools/generate_stencils.py --abi ms $SRC
gcc-12 -$OPT -c $SRC -o $DEST/stencils_AMD64_$OPT.o
# Native x86_64
python src/copapy/generate_stencils.py $SRC
python tools/generate_stencils.py $SRC
gcc-12 -$OPT -c $SRC -o $DEST/stencils_x86_64_$OPT.o
# ARM64

View File

@ -1,22 +1,28 @@
from copapy.binwrite import data_reader, Command, ByteOrder
from copapy.stencil_db import RelocationType
import argparse
input_file = "bin/test.copapy"
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("input_file", type=str, help="Input file path with copapy commands")
parser.add_argument("output_file", type=str, help="Output file with patched code")
parser.add_argument("--data_section_offset", type=int, default=0x2000, help="Offset for data relative to code section")
parser.add_argument("--byteorder", type=str, choices=['little', 'big'], default='little', help="Select byteorder")
args = parser.parse_args()
output_file = "bin/test_code.bin"
input_file: str = args.input_file
output_file: str = args.output_file
data_section_offset: int = args.data_section_offset
byteorder: ByteOrder = args.byteorder
data_section_offset = 0x2000
byteorder: ByteOrder = 'little'
with open(input_file, mode='rb') as f:
with open(input_file, mode='rb') as f:
dr = data_reader(f.read(), byteorder)
buffer_index: int = 0
end_flag: int = 0
program_data: bytearray = bytearray([])
buffer_index: int = 0
end_flag: int = 0
program_data: bytearray = bytearray([])
while (end_flag == 0):
while (end_flag == 0):
com = dr.read_com()
if com == Command.ALLOCATE_DATA:
@ -64,7 +70,7 @@ while (end_flag == 0):
else:
assert False, f"Unknown command: {com}"
with open(output_file, mode='wb') as f:
with open(output_file, mode='wb') as f:
f.write(program_data)
print('OK')
print(f"Code written to {output_file}.")

6
tools/inspect.sh Normal file
View File

@ -0,0 +1,6 @@
#!/bin/bash
source tools/build.sh
python tests/test_compile_div.py
python tools/extract_code.py "bin/test.copapy" "bin/test.copapy.bin"
objdump -D -b binary -m i386:x86-64 --adjust-vma=0x1000 bin/test.copapy.bin > bin/test.copapy.asm

View File

@ -2,10 +2,10 @@
set -e
set -v
SRC=src/copapy/stencils.c
SRC=bin/stencils.c
DEST=src/copapy/obj
python src/copapy/generate_stencils.py $SRC
python tools/generate_stencils.py $SRC
mkdir -p $DEST
gcc-12 -c $SRC -O0 -o $DEST/stencils_x86_64_O0.o
@ -13,7 +13,7 @@ gcc-12 -c $SRC -O1 -o $DEST/stencils_x86_64_O1.o
gcc-12 -c $SRC -O2 -o $DEST/stencils_x86_64_O2.o
gcc-12 -c $SRC -O3 -o $DEST/stencils_x86_64_O3.o
python src/copapy/generate_stencils.py --abi ms $SRC
python tools/generate_stencils.py --abi ms $SRC
gcc-12 -c $SRC -O0 -o $DEST/stencils_AMD64_O0.o
gcc-12 -c $SRC -O1 -o $DEST/stencils_AMD64_O1.o