# A simple Makefile, to build run: make all
TARGET = test-chacha20
-CROSS ?= powerpc64le-linux-gnu-
-AS = $(CROSS)as
-CC = $(CROSS)gcc
-LD = $(CROSS)ld
+AS = powerpc64le-linux-gnu-as
+CC = gcc
+LD = ld
+CROSSOBJCOPY = powerpc64le-linux-gnu-objcopy
+CROSSLD = powerpc64le-linux-gnu-ld
#compiler flags here
-CFLAGS = -g3 -O -Wall -Wextra -mno-vsx -mno-altivec -I../../media/pypowersim_wrapper -I/usr/include/python3.7m
+CFLAGS = -g3 -O -Wall -Wextra -I../../media/pypowersim_wrapper -I/usr/include/python3.7m
# assembler flags here
ASFLAGS= -mlibresoc -mregnames -Isrc
LDFLAGS = -Wall -pthread -lpython3.7m
SRCDIR = src
+BINDIR = bin
CFILES := $(SRCDIR)/xchacha20.c $(SRCDIR)/test.c $(SRCDIR)/xchacha20_wrapper.c
ASFILES := $(SRCDIR)/xchacha_hchacha20_svp64.s $(SRCDIR)/xchacha_encrypt_bytes_svp64.s
INCLUDES := $(wildcard $(SRCDIR)/*.h))
-OBJECTS := $(CFILES:$(SRCDIR)/%.c=$(SRCDIR)/%.o) $(ASFILES:$(SRCDIR)/%.s=$(SRCDIR)/%.o)
+SVP64OBJECTS := $(ASFILES:$(SRCDIR)/%.s=$(SRCDIR)/%.o)
+OBJECTS := $(CFILES:$(SRCDIR)/%.c=$(SRCDIR)/%.o)
+BINFILES := $(BINDIR)/xchacha_hchacha20_svp64.bin $(BINDIR)/xchacha_encrypt_bytes_svp64.bin
+
+
+$(BINDIR)/%.elf: $(SRCDIR)/%.o
+ $(CROSSLD) -EL -o $@ -T memmap $^
+
+$(BINDIR)/%.bin: $(BINDIR)/%.elf
+ $(CROSSOBJCOPY) -I elf64-little -O binary $< $@
.PHONY: all clean remove
all: ${TARGET}
-$(TARGET): $(OBJECTS)
+$(TARGET): $(OBJECTS) $(SVP64OBJECTS) $(BINFILES)
$(CC) -o $@ $(OBJECTS) $(LDFLAGS)
clean:
- $ rm -f $(OBJECTS)
+ $ rm -f $(OBJECTS) $(SVP64OBJECTS)
remove: clean
$ rm -f $(TARGET)
#include "xchacha20_wrapper.h"
#include "xchacha20.h"
+const char *xchacha_hchacha_svp64_filename = "./bin/xchacha_hchacha20_svp64.bin";
+const char *xchacha_encrypt_bytes_svp64_filename = "./bin/xchacha_encrypt_bytes_svp64.bin";
+
void xchacha_hchacha20_svp64(uint8_t *out, const uint8_t *in, const uint8_t *k) {
// These cannot be the same pointer as the original function, as it is really a separate CPU/RAM
pypowersim_state_t *state = pypowersim_prepare();
// Change the relevant elements, mandatory: body
- state->binary = PyBytes_FromStringAndSize((const char *)&xchacha_hchacha20_svp64_real, 10000);
+ state->binary = PyBytes_FromStringAndSize(xchacha_hchacha_svp64_filename, strlen(xchacha_hchacha_svp64_filename));
// Set GPR #3 to the output pointer
PyObject *out_address = PyLong_FromUnsignedLongLong(outptr_svp64);
PyList_SetItem(state->initial_regs, 3, out_address);
pypowersim_state_t *state = pypowersim_prepare();
// Change the relevant elements
- state->binary = PyBytes_FromStringAndSize((const char *)&xchacha_encrypt_bytes_svp64_real, 10000);
+ state->binary = PyBytes_FromStringAndSize(xchacha_encrypt_bytes_svp64_filename, strlen(xchacha_encrypt_bytes_svp64_filename));
// Set GPR #3 to the output pointer
PyObject *ctxptr_address = PyLong_FromUnsignedLongLong(ctxptr_svp64);