Commit 003d2bdf authored by Alyssa Rosenzweig's avatar Alyssa Rosenzweig 💜

Finish syncing

parent 85053e72
......@@ -18,6 +18,7 @@
#include <stdbool.h>
#include <stdarg.h>
#include <list.h>
#include <memory.h>
#include <mali-ioctl.h>
#include <panloader-util.h>
......@@ -80,19 +81,15 @@ char* pointer_as_memory_reference(mali_ptr ptr)
* all verbatim, as hex arrays, and memcpy them into the allocated memory
* spaces. The main issue is address fix up, which we also handle here. */
void replay_memory_specific(struct panwrap_mapped_memory *pos)
void replay_memory_specific(struct panwrap_mapped_memory *pos, int offset, int len)
{
/* Bail out */
if (!pos) {
panwrap_msg("Not replaying NULL memory?\n");
return;
}
/* If we don't have write access, no replay :) */
if (!(pos->flags & MALI_MEM_PROT_CPU_WR)) return;
if (pos->flags & MALI_MEM_PROT_GPU_EX) {
if (offset)
panwrap_msg("Shader sync not supported!\n");
/* Shader memory get dumped but not replayed, as the
* dis/assembler is setup in-tree as it is. */
......@@ -100,20 +97,24 @@ void replay_memory_specific(struct panwrap_mapped_memory *pos)
snprintf(filename, 128, "%s.bin", pos->name);
FILE *fp = fopen(filename, "wb");
fwrite(pos->addr, 1, pos->length, fp);
fwrite(pos->addr, 1, len, fp);
fclose(fp);
panwrap_log("// FILE *f_%s = fopen(\"%s\", \"rb\");\n", pos->name, filename);
panwrap_log("// fread(%s, 1, %d, f_%s);\n", pos->name, pos->length, pos->name);
panwrap_log("// fread(%s, 1, %d, f_%s);\n", pos->name, len, pos->name);
panwrap_log("// fclose(f_%s);\n", pos->name);
} else {
/* Fill it with dumped memory, skipping zeroes */
uint32_t *array = (uint32_t *) pos->addr;
for (uint32_t i = 0; i < pos->length / sizeof(uint32_t); ++i) {
for (uint32_t i = offset / sizeof(uint32_t); i < (offset + len) / sizeof(uint32_t); ++i) {
if (array[i])
panwrap_log("%s%s[%d] = %s;\n", pos->touched[i] ? "// " : "", pos->name, i, pointer_as_memory_reference(array[i]));
}
/* Touch what we have written */
/* TODO: Implement correctly */
// memset(pos->touched + (offset / sizeof(uint32_t)), 1, len / sizeof(uint32_t));
}
panwrap_log("\n");
......@@ -124,7 +125,7 @@ void replay_memory()
struct panwrap_mapped_memory *pos;
list_for_each_entry(pos, &mmaps, node) {
replay_memory_specific(pos);
replay_memory_specific(pos, 0, pos->length);
}
}
......
......@@ -70,7 +70,7 @@ struct panwrap_mapped_memory {
TOUCH_LEN(mem, addr, sizeof(typeof(obj)), ename, number, dyn)
void replay_memory();
void replay_memory_specific(struct panwrap_mapped_memory *pos);
void replay_memory_specific(struct panwrap_mapped_memory *pos, int offset, int len);
char *pointer_as_memory_reference(mali_ptr ptr);
void panwrap_track_allocation(mali_ptr gpu_va, int flags, int number, size_t length);
......
......@@ -1085,7 +1085,12 @@ int ioctl(int fd, int request, ...)
const struct mali_ioctl_sync *args = ptr;
if (args->type == MALI_SYNC_TO_DEVICE) {
replay_memory_specific(panwrap_find_mapped_mem(args->handle));
struct panwrap_mapped_memory *mem = panwrap_find_mapped_mem_containing(args->user_addr);
if (mem)
replay_memory_specific(mem, args->user_addr - mem->addr, args->size);
else
panwrap_msg("Bad synced memory\n");
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment