From c138759ebf4194a73364a79a9acc87f54dcc73bc Mon Sep 17 00:00:00 2001 From: alekseiplusplus Date: Thu, 20 Apr 2023 12:51:50 +1000 Subject: callIT() FINALLY WORKS --- instruction-init.h | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'instruction-init.h') diff --git a/instruction-init.h b/instruction-init.h index c2f85ed..adb5047 100644 --- a/instruction-init.h +++ b/instruction-init.h @@ -4,17 +4,19 @@ //InstructionTable void* IT; - - +void (*func)(Addressing, address); void setIT(int i, uintptr_t p, Addressing r){ - uintptr_t* p1 = (IT + (i * sizeof(uintptr_t))); + uintptr_t* p1 = (IT + (sizeof(uintptr_t)*i)); *p1 = p; - Addressing* r1 = (IT + ((sizeof(uintptr_t)*256)) + (i * sizeof(Addressing))); + Addressing* r1 = (IT + (sizeof(uintptr_t)*256) + (sizeof(Addressing)*i)); *r1 = r; + + printf("DEBUG:\t%x\t%x -> %x\t%x -> %x\n", i, p1, *p1, r1, *r1); } +/* uintptr_t getITFunction(int i){ //Segmentation fault is occurring here, likely in next one too uintptr_t r = (IT + (sizeof(uintptr_t)*i)); return r; @@ -24,13 +26,14 @@ Addressing getITAddressing(int i){ Addressing r = (IT + (sizeof(uintptr_t)*256) + (sizeof(Addressing)*i)); return r; } +*/ void callIT(int i, address val){ - void (*func)(Addressing, address); - func = (IT + (sizeof(uintptr_t) * i)); - Addressing r = (IT + ((i * sizeof(Addressing)) + (sizeof(uintptr_t)*256))); - func(r, val); + uintptr_t a = ((uintptr_t)IT + (sizeof(uintptr_t) * i)); + memcpy(&func, a, sizeof(uintptr_t)); + Addressing* r = (IT + ((sizeof(uintptr_t)*256) + (sizeof(Addressing) * i))); + func(*r, val); } @@ -104,7 +107,8 @@ void fSEI(Addressing, address); void fNOP(Addressing, address); void fBRK(Addressing, address); -void initIT(){ +void initIT(){ //Change this to load a binary file which contains this same information. + //So will need to dump the contents of IT at some point. IT = malloc(256 * (sizeof(uintptr_t) + sizeof(Addressing))); // Load and Store Instructions -- cgit v1.2.3