From e58abb8fb84431ef5aea1659b008abe0a46f120a Mon Sep 17 00:00:00 2001 From: Jeremiah Orians Date: Sat, 11 Jun 2016 11:43:01 -0400 Subject: [PATCH] Added indexed load/store instructions to vm, assembler and disassembler --- ISA_HEX_Map.org | 44 +++++-- asm.c | 18 ++- disasm.c | 88 ++++++++++---- vm.c | 300 ++++++++++++++++++++++++++++++++++++++---------- vm.h | 59 +++++++++- 5 files changed, 412 insertions(+), 97 deletions(-) diff --git a/ISA_HEX_Map.org b/ISA_HEX_Map.org index 7855d55..01e703d 100644 --- a/ISA_HEX_Map.org +++ b/ISA_HEX_Map.org @@ -23,13 +23,13 @@ 01 0A ab cd # SUBU.BO a b c d :: a = b - c; d = BORROW? [unsigned] 01 0B ab cd # SUBU.BIO a b c d :: a = b - c - BORROW? d; d = BORROW? [unsigned] -**** long math +**** long math subgroup 01 0C ab cd # MULTIPLY a b c d :: a = MUL c d; b = MULH c d [signed] 01 0D ab cd # MULTIPLYU a b c d :: a = MUL c d; b = MULH c d [unsigned] 01 0E ab cd # DIVIDE a b c d :: a = DIV c d; b = MOD c d [signed] 01 0F ab cd # DIVIDEU a b c d :: a = DIV c d; b = MOD c d [unsigned] -**** Logic +**** Logic subgroup 01 10 ab cd # MUX a b c d :: a = (c & ~b) | (d & b) 01 11 ab cd # NMUX a b c d :: a = (c & b) | (d & ~b) 01 12 ab cd # SORT a b c d :: a = MAX(c, d); b = MIN(c, d) [signed] @@ -116,8 +116,36 @@ 05 03 6a bc # ROL a b c :: a = ROL(b, c) [Circular rotate left] 05 03 7a bc # ROR a b c :: a = ROR(b, c) [Circular rotate right] +**** Load group +05 03 8a bc # LOADX a b c :: a = MEM[b+c] +05 03 9a bc # LOADX8 a b c :: a = MEM[b+c] [signed 8bits] +05 03 Aa bc # LOADXU8 a b c :: a = MEM[b+c] [unsigned 8bits] +05 03 Ba bc # LOADX16 a b c :: a = MEM[b+c] [signed 16bits] +05 03 Ca bc # LOADXU16 a b c :: a = MEM[b+c] [unsigned 16bits] +05 03 Da bc # LOADX32 a b c :: a = MEM[b+c] [signed 32bits] +05 03 Ea bc # LOADXU32 a b c :: a = MEM[b+c] [unsigned 32bits] +05 03 Fx xx # Reserved +05 04 0x xx # Reserved +05 04 1x xx # Reserved +05 04 2x xx # Reserved +05 04 3x xx # Reserved +05 04 4x xx # Reserved +05 04 5x xx # Reserved +05 04 6x xx # Reserved +05 04 7x xx # Reserved + +**** Store group +05 04 8a bc # STOREX a b c :: MEM[b+c] = a +05 04 9a bc # STOREX8 a b c :: MEM[b+c] = a [8bits] +05 04 Aa bc # STOREX16 a b c :: MEM[b+c] = a [16bits] +05 04 Ba bc # STOREX32 a b c :: MEM[b+c] = a [32bits] +05 04 Cx xx # Reserved +05 04 Dx xx # Reserved +05 04 Ex xx # Reserved +05 04 Fx xx # Reserved + **** Reserved group 2 -05 03 8x xx # Reserved +05 05 0x xx # Reserved ... 05 FF Fx xx # Reserved @@ -221,11 +249,11 @@ *** 2OPI Integer store 20 ab ii ii # STORE a b ii :: MEM[b + ii ii] = a 21 ab ii ii # STORE8 a b ii :: MEM[b + ii ii] = a [signed 8bits] -22 ab ii ii # STOREU8 a b ii :: MEM[b + ii ii] = a [unsigned 8bits] -23 ab ii ii # STORE16 a b ii :: MEM[b + ii ii] = a [signed 16bits] -24 ab ii ii # STOREU16 a b ii :: MEM[b + ii ii] = a [unsigned 16bits] -25 ab ii ii # STORE32 a b ii :: MEM[b + ii ii] = a [signed 32bits] -26 ab ii ii # STOREU32 a b ii :: MEM[b + ii ii] = a [unsigned 32bits] +22 ab ii ii # STORE16 a b ii :: MEM[b + ii ii] = a [signed 16bits] +23 ab ii ii # STORE32 a b ii :: MEM[b + ii ii] = a [signed 32bits] +24 ab ii ii # Reserved +25 ab ii ii # Reserved +26 ab ii ii # Reserved 27 ab ii ii # Reserved 28 ab ii ii # Reserved 29 ab ii ii # Reserved diff --git a/asm.c b/asm.c index 4cf15fb..03a2cfa 100644 --- a/asm.c +++ b/asm.c @@ -232,6 +232,17 @@ void assemble(struct Token* p) setExpression(p, "SR1", "05035", 4); setExpression(p, "ROL", "05036", 4); setExpression(p, "ROR", "05037", 4); + setExpression(p, "LOADX", "05038", 4); + setExpression(p, "LOADX8", "05039", 4); + setExpression(p, "LOADXU8", "0503A", 4); + setExpression(p, "LOADX16", "0503B", 4); + setExpression(p, "LOADXU16", "0503C", 4); + setExpression(p, "LOADX32", "0503D", 4); + setExpression(p, "LOADXU32", "0503E", 4); + setExpression(p, "STOREX", "05048", 4); + setExpression(p, "STOREX8", "05049", 4); + setExpression(p, "STOREX16", "0504A", 4); + setExpression(p, "STOREX32", "0504B", 4); /* 2OP Integer Group */ setExpression(p, "NEG", "090000", 4); @@ -269,11 +280,8 @@ void assemble(struct Token* p) setExpression(p, "CMPUI", "1F", 4); setExpression(p, "STORE", "20", 4); setExpression(p, "STORE8", "21", 4); - setExpression(p, "STOREU8", "22", 4); - setExpression(p, "STORE16", "23", 4); - setExpression(p, "STOREU16", "24", 4); - setExpression(p, "STORE32", "25", 4); - setExpression(p, "STOREU32", "26", 4); + setExpression(p, "STORE16", "22", 4); + setExpression(p, "STORE32", "23", 4); /* 1OPI Group */ setExpression(p, "JUMP.C", "2C0", 4); diff --git a/disasm.c b/disasm.c index d0aac1c..28f76e0 100644 --- a/disasm.c +++ b/disasm.c @@ -189,7 +189,7 @@ void decode_Integer_4OP(struct Instruction* c) break; } } - fprintf(stdout, "%s reg%o reg%o reg%o reg%o\t", Name, c->reg0, c->reg1, c->reg2, c->reg3); + fprintf(stdout, "%s reg%u reg%u reg%u reg%u\t", Name, c->reg0, c->reg1, c->reg2, c->reg3); fprintf(stdout, "# %s\n", c->operation); } @@ -430,13 +430,68 @@ void decode_Integer_3OP(struct Instruction* c) strncpy(Name, "ROR", 19); break; } + case 0x038: /* LOADX */ + { + strncpy(Name, "LOADX", 19); + break; + } + case 0x039: /* LOADX8 */ + { + strncpy(Name, "LOADX8", 19); + break; + } + case 0x03A: /* LOADXU8 */ + { + strncpy(Name, "LOADXU8", 19); + break; + } + case 0x03B: /* LOADX16 */ + { + strncpy(Name, "LOADX16", 19); + break; + } + case 0x03C: /* LOADXU16 */ + { + strncpy(Name, "LOADXU16", 19); + break; + } + case 0x03D: /* LOADX32 */ + { + strncpy(Name, "LOADX32", 19); + break; + } + case 0x03E: /* LOADXU32 */ + { + strncpy(Name, "LOADXU32", 19); + break; + } + case 0x048: /* STOREX */ + { + strncpy(Name, "STOREX", 19); + break; + } + case 0x049: /* STOREX8 */ + { + strncpy(Name, "STOREX8", 19); + break; + } + case 0x04A: /* STOREX16 */ + { + strncpy(Name, "STOREX16", 19); + break; + } + case 0x04B: /* STOREX32 */ + { + strncpy(Name, "STOREX32", 19); + break; + } default: /* Unknown 3OP*/ { break; } } - fprintf(stdout, "%s reg%o reg%o reg%o\t", Name, c->reg0, c->reg1, c->reg2); + fprintf(stdout, "%s reg%u reg%u reg%u\t", Name, c->reg0, c->reg1, c->reg2); fprintf(stdout, "# %s\n", c->operation); } @@ -503,7 +558,7 @@ void decode_Integer_2OP(struct Instruction* c) } } - fprintf(stdout, "%s reg%o reg%o\t", Name, c->reg0, c->reg1); + fprintf(stdout, "%s reg%u reg%u\t", Name, c->reg0, c->reg1); fprintf(stdout, "# %s\n", c->operation); } @@ -570,7 +625,7 @@ void decode_1OP(struct Instruction* c) } } - fprintf(stdout, "%s reg%o\t", Name, c->reg0); + fprintf(stdout, "%s reg%u\t", Name, c->reg0); fprintf(stdout, "# %s\n", c->operation); } @@ -706,38 +761,23 @@ void decode_Integer_2OPI(struct Instruction* c) strncpy(Name, "STORE8", 19); break; } - case 0x22: /* STOREU8 */ - { - strncpy(Name, "STOREU8", 19); - break; - } - case 0x23: /* STORE16 */ + case 0x22: /* STORE16 */ { strncpy(Name, "STORE16", 19); break; } - case 0x24: /* STOREU16 */ - { - strncpy(Name, "STOREU16", 19); - break; - } - case 0x25: /* STORE32 */ + case 0x23: /* STORE32 */ { strncpy(Name, "STORE32", 19); break; } - case 0x26: /* STOREU32 */ - { - strncpy(Name, "STOREU32", 19); - break; - } default: /* Unknown 2OPI*/ { break; } } - fprintf(stdout, "%s reg%o reg%o 0x%x\t", Name, c->reg0, c->reg1, c->raw_Immediate); + fprintf(stdout, "%s reg%u reg%u 0x%x\t", Name, c->reg0, c->reg1, c->raw_Immediate); fprintf(stdout, "# %s\n", c->operation); } @@ -820,7 +860,7 @@ void decode_1OPI(struct Instruction* c) } } - fprintf(stdout, "%s reg%o %d\t", Name, c->reg0, c->raw_Immediate); + fprintf(stdout, "%s reg%u %d\t", Name, c->reg0, c->raw_Immediate); fprintf(stdout, "# %s\n", c->operation); } @@ -893,7 +933,7 @@ void decode_Branch_1OPI(struct Instruction* c) } } - fprintf(stdout, "%s reg%o %d\t", Name, c->reg0, c->raw_Immediate); + fprintf(stdout, "%s reg%u %d\t", Name, c->reg0, c->raw_Immediate); fprintf(stdout, "# %s\n", c->operation); } diff --git a/vm.c b/vm.c index ba90a5c..cb43a35 100644 --- a/vm.c +++ b/vm.c @@ -1,8 +1,9 @@ #include "vm.h" -#define DEBUG true; +#define DEBUG true FILE* tape_01; FILE* tape_02; +uint32_t performance_counter; /* Load program tape into Memory */ void load_program(struct lilith* vm, char **argv) @@ -43,10 +44,13 @@ void read_instruction(struct lilith* vm, struct Instruction *current) /* Process HALCODE instructions */ bool eval_HALCODE(struct lilith* vm, struct Instruction* c) { + char Name[20] = "ILLEGAL_HALCODE"; switch(c->HAL_CODE) { case 0x100000: /* fopen */ { + strncpy(Name, "FOPEN", 19); + if(0x00001100 == vm->reg[0]) { tape_01 = fopen("tape_01", "r"); @@ -60,6 +64,8 @@ bool eval_HALCODE(struct lilith* vm, struct Instruction* c) } case 0x100001: /* fclose */ { + strncpy(Name, "FCLOSE", 19); + if(0x00001100 == vm->reg[0]) { fclose(tape_01); @@ -73,6 +79,8 @@ bool eval_HALCODE(struct lilith* vm, struct Instruction* c) } case 0x100002: /* fseek */ { + strncpy(Name, "FSEEK", 19); + if(0x00001100 == vm->reg[0]) { fseek(tape_01, vm->reg[1], SEEK_CUR); @@ -86,6 +94,8 @@ bool eval_HALCODE(struct lilith* vm, struct Instruction* c) } case 0x100003: /* rewind */ { + strncpy(Name, "REWIND", 19); + if(0x00001100 == vm->reg[0]) { rewind(tape_01); @@ -99,6 +109,7 @@ bool eval_HALCODE(struct lilith* vm, struct Instruction* c) } case 0x100100: /* fgetc */ { + strncpy(Name, "FGETC", 19); int32_t byte = -1; if (0x00000000 == vm->reg[1]) @@ -122,6 +133,7 @@ bool eval_HALCODE(struct lilith* vm, struct Instruction* c) } case 0x100200: /* fputc */ { + strncpy(Name, "FPUTC", 19); int32_t byte = vm->reg[0]; if (0x00000000 == vm->reg[1]) @@ -143,6 +155,8 @@ bool eval_HALCODE(struct lilith* vm, struct Instruction* c) } default: return true; } + + if(DEBUG) {fprintf(stdout, "# %s\n", Name);} return false; } @@ -153,8 +167,8 @@ bool eval_4OP_Int(struct lilith* vm, struct Instruction* c) uint32_t utmp1, utmp2; int64_t btmp1; uint64_t ubtmp1; - bool C, B; + char Name[20] = "ILLEGAL_4OP"; utmp1 = vm->reg[c->reg3]; @@ -165,6 +179,7 @@ bool eval_4OP_Int(struct lilith* vm, struct Instruction* c) { case 0x00: /* ADD.CI */ { + strncpy(Name, "ADD.CI", 19); tmp1 = vm->reg[c->reg1]; tmp2 = vm->reg[c->reg2]; @@ -181,6 +196,7 @@ bool eval_4OP_Int(struct lilith* vm, struct Instruction* c) } case 0x01: /* ADD.CO */ { + strncpy(Name, "ADD.CO", 19); tmp1 = (int32_t)(vm->reg[c->reg1]); tmp2 = (int32_t)(vm->reg[c->reg2]); btmp1 = ((int64_t)tmp1) + ((int64_t)tmp2); @@ -201,6 +217,7 @@ bool eval_4OP_Int(struct lilith* vm, struct Instruction* c) } case 0x02: /* ADD.CIO */ { + strncpy(Name, "ADD.CIO", 19); tmp1 = (int32_t)(vm->reg[c->reg1]); tmp2 = (int32_t)(vm->reg[c->reg2]); btmp1 = ((int64_t)tmp1) + ((int64_t)tmp2); @@ -228,6 +245,7 @@ bool eval_4OP_Int(struct lilith* vm, struct Instruction* c) } case 0x03: /* ADDU.CI */ { + strncpy(Name, "ADDU.CI", 19); utmp1 = vm->reg[c->reg1]; utmp2 = vm->reg[c->reg2]; @@ -244,6 +262,7 @@ bool eval_4OP_Int(struct lilith* vm, struct Instruction* c) } case 0x04: /* ADDU.CO */ { + strncpy(Name, "ADDU.CO", 19); utmp1 = vm->reg[c->reg1]; utmp2 = vm->reg[c->reg2]; ubtmp1 = ((uint64_t)utmp1) + ((uint64_t)utmp2); @@ -264,6 +283,7 @@ bool eval_4OP_Int(struct lilith* vm, struct Instruction* c) } case 0x05: /* ADDU.CIO */ { + strncpy(Name, "ADDU.CIO", 19); utmp1 = vm->reg[c->reg1]; utmp2 = vm->reg[c->reg2]; ubtmp1 = ((uint64_t)utmp1) + ((uint64_t)utmp2); @@ -291,6 +311,7 @@ bool eval_4OP_Int(struct lilith* vm, struct Instruction* c) } case 0x06: /* SUB.BI */ { + strncpy(Name, "SUB.BI", 19); tmp1 = (int32_t)(vm->reg[c->reg1]); tmp2 = (int32_t)(vm->reg[c->reg2]); @@ -307,6 +328,7 @@ bool eval_4OP_Int(struct lilith* vm, struct Instruction* c) } case 0x07: /* SUB.BO */ { + strncpy(Name, "SUB.BO", 19); btmp1 = (int64_t)(vm->reg[c->reg1]); tmp1 = (int32_t)(vm->reg[c->reg2]); tmp2 = (int32_t)(btmp1 - tmp1); @@ -327,6 +349,7 @@ bool eval_4OP_Int(struct lilith* vm, struct Instruction* c) } case 0x08: /* SUB.BIO */ { + strncpy(Name, "SUB.BIO", 19); btmp1 = (int64_t)(vm->reg[c->reg1]); tmp1 = (int32_t)(vm->reg[c->reg2]); tmp2 = (int32_t)(btmp1 - tmp1); @@ -354,6 +377,7 @@ bool eval_4OP_Int(struct lilith* vm, struct Instruction* c) } case 0x09: /* SUBU.BI */ { + strncpy(Name, "SUBU.BI", 19); utmp1 = vm->reg[c->reg1]; utmp2 = vm->reg[c->reg2]; @@ -370,6 +394,7 @@ bool eval_4OP_Int(struct lilith* vm, struct Instruction* c) } case 0x0A: /* SUBU.BO */ { + strncpy(Name, "SUBU.BO", 19); utmp1 = vm->reg[c->reg1]; utmp2 = vm->reg[c->reg2]; ubtmp1 = (uint64_t)(utmp1 - utmp2); @@ -390,6 +415,7 @@ bool eval_4OP_Int(struct lilith* vm, struct Instruction* c) } case 0x0B: /* SUBU.BIO */ { + strncpy(Name, "SUBU.BIO", 19); utmp1 = vm->reg[c->reg1]; utmp2 = vm->reg[c->reg2]; ubtmp1 = (uint64_t)(utmp1 - utmp2); @@ -417,6 +443,7 @@ bool eval_4OP_Int(struct lilith* vm, struct Instruction* c) } case 0x0C: /* MULTIPLY */ { + strncpy(Name, "MULTIPLY", 19); tmp1 = (int32_t)(vm->reg[c->reg2]); tmp2 = (int32_t)( vm->reg[c->reg3]); btmp1 = ((int64_t)tmp1) * ((int64_t)tmp2); @@ -426,6 +453,7 @@ bool eval_4OP_Int(struct lilith* vm, struct Instruction* c) } case 0x0D: /* MULTIPLYU */ { + strncpy(Name, "MULTIPLYU", 19); ubtmp1 = (uint64_t)(vm->reg[c->reg2]) * (uint64_t)(vm->reg[c->reg3]); vm->reg[c->reg0] = ubtmp1 % 0x100000000; vm->reg[c->reg1] = ubtmp1 / 0x100000000; @@ -433,6 +461,7 @@ bool eval_4OP_Int(struct lilith* vm, struct Instruction* c) } case 0x0E: /* DIVIDE */ { + strncpy(Name, "DIVIDE", 19); tmp1 = (int32_t)(vm->reg[c->reg2]); tmp2 = (int32_t)(vm->reg[c->reg3]); vm->reg[c->reg0] = tmp1 / tmp2; @@ -441,6 +470,7 @@ bool eval_4OP_Int(struct lilith* vm, struct Instruction* c) } case 0x0F: /* DIVIDEU */ { + strncpy(Name, "DIVIDEU", 19); utmp1 = vm->reg[c->reg2]; utmp2 = vm->reg[c->reg3]; vm->reg[c->reg0] = utmp1 / utmp2; @@ -449,18 +479,21 @@ bool eval_4OP_Int(struct lilith* vm, struct Instruction* c) } case 0x10: /* MUX */ { + strncpy(Name, "MUX", 19); vm->reg[c->reg0] = ((vm->reg[c->reg2] & ~(vm->reg[c->reg1])) | (vm->reg[c->reg3] & vm->reg[c->reg1])); break; } case 0x11: /* NMUX */ { + strncpy(Name, "NMUX", 19); vm->reg[c->reg0] = ((vm->reg[c->reg2] & vm->reg[c->reg1]) | (vm->reg[c->reg3] & ~(vm->reg[c->reg1]))); break; } case 0x12: /* SORT */ { + strncpy(Name, "SORT", 19); tmp1 = (int32_t)(vm->reg[c->reg2]); tmp2 = (int32_t)(vm->reg[c->reg3]); @@ -478,6 +511,7 @@ bool eval_4OP_Int(struct lilith* vm, struct Instruction* c) } case 0x13: /* SORTU */ { + strncpy(Name, "SORTU", 19); utmp1 = vm->reg[c->reg2]; utmp2 = vm->reg[c->reg3]; @@ -495,6 +529,7 @@ bool eval_4OP_Int(struct lilith* vm, struct Instruction* c) } default: return true; } + if(DEBUG) {fprintf(stdout, "# %s reg%u reg%u reg%u reg%u\n", Name, c->reg0, c->reg1, c->reg2, c->reg3);} return false; } @@ -503,6 +538,7 @@ bool eval_3OP_Int(struct lilith* vm, struct Instruction* c) { int32_t tmp1, tmp2; uint32_t utmp1, utmp2; + char Name[20] = "ILLEGAL_3OP"; tmp1 = (int32_t)(vm->reg[c->reg1]); tmp2 = (int32_t)(vm->reg[c->reg2]); @@ -513,26 +549,31 @@ bool eval_3OP_Int(struct lilith* vm, struct Instruction* c) { case 0x000: /* ADD */ { + strncpy(Name, "ADD", 19); vm->reg[c->reg0] = (int32_t)(tmp1 + tmp2); break; } case 0x001: /* ADDU */ { + strncpy(Name, "ADDU", 19); vm->reg[c->reg0] = utmp1 + utmp2; break; } case 0x002: /* SUB */ { + strncpy(Name, "SUB", 19); vm->reg[c->reg0] = (int32_t)(tmp1 - tmp2); break; } case 0x003: /* SUBU */ { + strncpy(Name, "SUBU", 19); vm->reg[c->reg0] = utmp1 - utmp2; break; } case 0x004: /* CMP */ { + strncpy(Name, "CMP", 19); /* Clear bottom 3 bits of condition register */ vm->reg[c->reg0] = vm->reg[c->reg0] & 0xFFFFFFF8; if(tmp1 > tmp2) @@ -551,6 +592,7 @@ bool eval_3OP_Int(struct lilith* vm, struct Instruction* c) } case 0x005: /* CMPU */ { + strncpy(Name, "CMPU", 19); /* Clear bottom 3 bits of condition register */ vm->reg[c->reg0] = vm->reg[c->reg0] & 0xFFFFFFF8; if(utmp1 > utmp2) @@ -569,6 +611,7 @@ bool eval_3OP_Int(struct lilith* vm, struct Instruction* c) } case 0x006: /* MUL */ { + strncpy(Name, "MUL", 19); int64_t sum = tmp1 * tmp2; /* We only want the bottom 32bits */ vm->reg[c->reg0] = sum % 0x100000000; @@ -576,6 +619,7 @@ bool eval_3OP_Int(struct lilith* vm, struct Instruction* c) } case 0x007: /* MULH */ { + strncpy(Name, "MULH", 19); int64_t sum = tmp1 * tmp2; /* We only want the top 32bits */ vm->reg[c->reg0] = sum / 0x100000000; @@ -583,6 +627,7 @@ bool eval_3OP_Int(struct lilith* vm, struct Instruction* c) } case 0x008: /* MULU */ { + strncpy(Name, "MULU", 19); uint64_t sum = tmp1 * tmp2; /* We only want the bottom 32bits */ vm->reg[c->reg0] = sum % 0x100000000; @@ -590,6 +635,7 @@ bool eval_3OP_Int(struct lilith* vm, struct Instruction* c) } case 0x009: /* MULUH */ { + strncpy(Name, "MULUH", 19); uint64_t sum = tmp1 * tmp2; /* We only want the top 32bits */ vm->reg[c->reg0] = sum / 0x100000000; @@ -597,26 +643,31 @@ bool eval_3OP_Int(struct lilith* vm, struct Instruction* c) } case 0x00A: /* DIV */ { + strncpy(Name, "DIV", 19); vm->reg[c->reg0] = tmp1 / tmp2; break; } case 0x00B: /* MOD */ { + strncpy(Name, "MOD", 19); vm->reg[c->reg0] = tmp1 % tmp2; break; } case 0x00C: /* DIVU */ { + strncpy(Name, "DIVU", 19); vm->reg[c->reg0] = utmp1 / utmp2; break; } case 0x00D: /* MODU */ { + strncpy(Name, "MODU", 19); vm->reg[c->reg0] = utmp1 % utmp2; break; } case 0x010: /* MAX */ { + strncpy(Name, "MAX", 19); if(tmp1 > tmp2) { vm->reg[c->reg0] = tmp1; @@ -629,6 +680,7 @@ bool eval_3OP_Int(struct lilith* vm, struct Instruction* c) } case 0x011: /* MAXU */ { + strncpy(Name, "MAXU", 19); if(utmp1 > utmp2) { vm->reg[c->reg0] = utmp1; @@ -641,6 +693,7 @@ bool eval_3OP_Int(struct lilith* vm, struct Instruction* c) } case 0x012: /* MIN */ { + strncpy(Name, "MIN", 19); if(tmp1 < tmp2) { vm->reg[c->reg0] = tmp1; @@ -653,6 +706,7 @@ bool eval_3OP_Int(struct lilith* vm, struct Instruction* c) } case 0x013: /* MINU */ { + strncpy(Name, "MINU", 19); if(utmp1 < utmp2) { vm->reg[c->reg0] = utmp1; @@ -665,126 +719,219 @@ bool eval_3OP_Int(struct lilith* vm, struct Instruction* c) } case 0x014: /* PACK */ { + strncpy(Name, "PACK", 19); break; } case 0x015: /* UNPACK */ { + strncpy(Name, "UNPACK", 19); break; } case 0x016: /* PACK8.CO */ { + strncpy(Name, "PACK8.CO", 19); break; } case 0x017: /* PACK8U.CO */ { + strncpy(Name, "PACK8U.CO", 19); break; } case 0x018: /* PACK16.CO */ { + strncpy(Name, "PACK16.CO", 19); break; } case 0x019: /* PACK16U.CO */ { + strncpy(Name, "PACK16U.CO", 19); break; } case 0x01A: /* PACK32.CO */ { + strncpy(Name, "PACK32.CO", 19); break; } case 0x01B: /* PACK32U.CO */ { + strncpy(Name, "PACK32U.CO", 19); break; } case 0x020: /* AND */ { + strncpy(Name, "AND", 19); vm->reg[c->reg0] = utmp1 & utmp2; break; } case 0x021: /* OR */ { + strncpy(Name, "OR", 19); vm->reg[c->reg0] = utmp1 | utmp2; break; } case 0x022: /* XOR */ { + strncpy(Name, "XOR", 19); vm->reg[c->reg0] = utmp1 ^ utmp2; break; } case 0x023: /* NAND */ { + strncpy(Name, "NAND", 19); vm->reg[c->reg0] = ~(utmp1 & utmp2); break; } case 0x024: /* NOR */ { + strncpy(Name, "NOR", 19); vm->reg[c->reg0] = ~(utmp1 | utmp2); break; } case 0x025: /* XNOR */ { + strncpy(Name, "XNOR", 19); vm->reg[c->reg0] = ~(utmp1 ^ utmp2); break; } case 0x026: /* MPQ */ { + strncpy(Name, "MPQ", 19); vm->reg[c->reg0] = (~utmp1) & utmp2; break; } case 0x027: /* LPQ */ { + strncpy(Name, "LPQ", 19); vm->reg[c->reg0] = utmp1 & (~utmp2); break; } case 0x028: /* CPQ */ { + strncpy(Name, "CPQ", 19); vm->reg[c->reg0] = (~utmp1) | utmp2; break; } case 0x029: /* BPQ */ { + strncpy(Name, "BPQ", 19); vm->reg[c->reg0] = utmp1 | (~utmp2); break; } case 0x030: /* SAL */ { + strncpy(Name, "SAL", 19); vm->reg[c->reg0] = vm->reg[c->reg1] << vm->reg[c->reg2]; break; } case 0x031: /* SAR */ { + strncpy(Name, "SAR", 19); vm->reg[c->reg0] = vm->reg[c->reg1] >> vm->reg[c->reg2]; break; } case 0x032: /* SL0 */ { + strncpy(Name, "SL0", 19); vm->reg[c->reg0] = shift_register(vm->reg[c->reg1], vm->reg[c->reg2], true, true); break; } case 0x033: /* SR0 */ { + strncpy(Name, "SR0", 19); vm->reg[c->reg0] = shift_register(vm->reg[c->reg1], vm->reg[c->reg2], false, true); break; } case 0x034: /* SL1 */ { + strncpy(Name, "SL1", 19); vm->reg[c->reg0] = shift_register(vm->reg[c->reg1], vm->reg[c->reg2], true, false); break; } case 0x035: /* SR1 */ { + strncpy(Name, "SR1", 19); vm->reg[c->reg0] = shift_register(vm->reg[c->reg1], vm->reg[c->reg2], false, false); break; } case 0x036: /* ROL */ { + strncpy(Name, "ROL", 19); break; } case 0x037: /* ROR */ { + strncpy(Name, "ROR", 19); + break; + } + case 0x038: /* LOADX */ + { + strncpy(Name, "LOADX", 19); + vm->reg[c->reg0] = readin_Reg(vm, vm->reg[c->reg1] + vm->reg[c->reg2]); + break; + } + case 0x039: /* LOADX8 */ + { + strncpy(Name, "LOADX8", 19); + vm->reg[c->reg0] = readin_byte(vm, vm->reg[c->reg1] + vm->reg[c->reg2], true); + break; + } + case 0x03A: /* LOADXU8 */ + { + strncpy(Name, "LOADXU8", 19); + vm->reg[c->reg0] = readin_byte(vm, vm->reg[c->reg1] + vm->reg[c->reg2], false); + break; + } + case 0x03B: /* LOADX16 */ + { + strncpy(Name, "LOADX16", 19); + vm->reg[c->reg0] = readin_doublebyte(vm, vm->reg[c->reg1] + vm->reg[c->reg2], true); + break; + } + case 0x03C: /* LOADXU16 */ + { + strncpy(Name, "LOADXU16", 19); + vm->reg[c->reg0] = readin_doublebyte(vm, vm->reg[c->reg1] + vm->reg[c->reg2], false); + break; + } + case 0x03D: /* LOADX32 */ + { + strncpy(Name, "LOADX32", 19); + vm->reg[c->reg0] = readin_Reg(vm, vm->reg[c->reg1] + vm->reg[c->reg2]); + break; + } + case 0x03E: /* LOADXU32 */ + { + strncpy(Name, "LOADXU32", 19); + vm->reg[c->reg0] = readin_Reg(vm, vm->reg[c->reg1] + vm->reg[c->reg2]); + break; + } + case 0x048: /* STOREX */ + { + strncpy(Name, "STOREX", 19); + writeout_Reg(vm, vm->reg[c->reg1] + vm->reg[c->reg2] , vm->reg[c->reg0]); + break; + } + case 0x049: /* STOREX8 */ + { + strncpy(Name, "STOREX8", 19); + writeout_byte(vm, vm->reg[c->reg1] + vm->reg[c->reg2] , vm->reg[c->reg0]); + break; + } + case 0x04A: /* STOREX16 */ + { + strncpy(Name, "STOREX16", 19); + writeout_doublebyte(vm, vm->reg[c->reg1] + vm->reg[c->reg2] , vm->reg[c->reg0]); + break; + } + case 0x04B: /* STOREX32 */ + { + strncpy(Name, "STOREX32", 19); + writeout_Reg(vm, vm->reg[c->reg1] + vm->reg[c->reg2] , vm->reg[c->reg0]); break; } default: return true; } + if(DEBUG) {fprintf(stdout, "# %s reg%u reg%u reg%u\n", Name, c->reg0, c->reg1, c->reg2);} return false; } @@ -793,16 +940,19 @@ bool eval_2OP_Int(struct lilith* vm, struct Instruction* c) { int32_t tmp1 = (int32_t)(vm->reg[c->reg1]); uint32_t utmp1 = vm->reg[c->reg1]; + char Name[20] = "ILLEGAL_2OP"; switch(c->raw_XOP) { case 0x0000: /* NEG */ { + strncpy(Name, "NEG", 19); vm->reg[c->reg0] = tmp1*-1; break; } case 0x0001: /* ABS */ { + strncpy(Name, "ABS", 19); if(0 <= tmp1) { vm->reg[c->reg0] = tmp1; @@ -815,6 +965,7 @@ bool eval_2OP_Int(struct lilith* vm, struct Instruction* c) } case 0x0002: /* NABS */ { + strncpy(Name, "NABS", 19); if(0 > tmp1) { vm->reg[c->reg0] = tmp1; @@ -827,23 +978,27 @@ bool eval_2OP_Int(struct lilith* vm, struct Instruction* c) } case 0x0003: /* SWAP */ { + strncpy(Name, "SWAP", 19); vm->reg[c->reg1] = vm->reg[c->reg0]; vm->reg[c->reg0] = utmp1; break; } case 0x0004: /* COPY */ { + strncpy(Name, "COPY", 19); vm->reg[c->reg0] = utmp1; break; } case 0x0005: /* MOVE */ { + strncpy(Name, "MOVE", 19); vm->reg[c->reg0] = utmp1; vm->reg[c->reg1] = 0; break; } case 0x0100: /* BRANCH */ { + strncpy(Name, "BRANCH", 19); /* Write out the PC */ writeout_Reg(vm, vm->reg[c->reg1], vm->ip); @@ -853,6 +1008,7 @@ bool eval_2OP_Int(struct lilith* vm, struct Instruction* c) } case 0x0101: /* CALL */ { + strncpy(Name, "CALL", 19); /* Write out the PC */ writeout_Reg(vm, vm->reg[c->reg1], vm->ip); @@ -865,51 +1021,63 @@ bool eval_2OP_Int(struct lilith* vm, struct Instruction* c) } default: return true; } + if(DEBUG) {fprintf(stdout, "# %s reg%u reg%u\n", Name, c->reg0, c->reg1);} return false; } /* Process 1OP Integer instructions */ bool eval_1OP_Int(struct lilith* vm, struct Instruction* c) { + char Name[20] = "ILLEGAL_1OP"; switch(c->raw_XOP) { case 0x00000: /* READPC */ { + strncpy(Name, "READPC", 19); vm->reg[c->reg0] = vm->ip; break; } case 0x00001: /* READSCID */ { + strncpy(Name, "READSCID", 19); /* We only support Base 8,16 and 32*/ vm->reg[c->reg0] = 0x00000007; break; } case 0x00002: /* FALSE */ { + strncpy(Name, "FALSE", 19); vm->reg[c->reg0] = 0; break; } case 0x00003: /* TRUE */ { + strncpy(Name, "TRUE", 19); vm->reg[c->reg0] = 0xFFFFFFFF; break; } case 0x01000: /* JSR_COROUTINE */ { + strncpy(Name, "JSR_COROUTINE", 19); vm->ip = vm->reg[c->reg0]; break; } case 0x01001: /* RET */ { + strncpy(Name, "RET", 19); + /* Update our index */ + vm->reg[c->reg0] = vm->reg[c->reg0] - 4; + /* Read in the new PC */ vm->ip = readin_Reg(vm, vm->reg[c->reg0]); - /* Update our index */ - vm->reg[c->reg0] = vm->reg[c->reg0] - 4; + /* Clear Stack Values */ + writeout_Reg(vm, vm->reg[c->reg0], 0); break; } case 0x02000: /* PUSHPC */ { + strncpy(Name, "PUSHPC", 19); /* Write out the PC */ writeout_Reg(vm, vm->reg[c->reg0], vm->ip); @@ -919,6 +1087,7 @@ bool eval_1OP_Int(struct lilith* vm, struct Instruction* c) } case 0x02001: /* POPPC */ { + strncpy(Name, "POPPC", 19); /* Read in the new PC */ vm->ip = readin_Reg(vm, vm->reg[c->reg0]); @@ -928,6 +1097,7 @@ bool eval_1OP_Int(struct lilith* vm, struct Instruction* c) } default: return true; } + if(DEBUG) {fprintf(stdout, "# %s reg%u\n", Name, c->reg0);} return false; } @@ -937,6 +1107,7 @@ bool eval_2OPI_Int(struct lilith* vm, struct Instruction* c) int32_t tmp1; uint32_t utmp1; uint8_t raw0, raw1; + char Name[20] = "ILLEGAL_2OPI"; tmp1 = (int32_t)(vm->reg[c->reg1]); utmp1 = vm->reg[c->reg1]; @@ -946,26 +1117,31 @@ bool eval_2OPI_Int(struct lilith* vm, struct Instruction* c) { case 0x0E: /* ADDI */ { + strncpy(Name, "ADDI", 19); vm->reg[c->reg0] = (int32_t)(tmp1 + c->raw_Immediate); break; } case 0x0F: /* ADDUI */ { + strncpy(Name, "ADDUI", 19); vm->reg[c->reg0] = utmp1 + c->raw_Immediate; break; } case 0x10: /* SUBI */ { + strncpy(Name, "SUBI", 19); vm->reg[c->reg0] = (int32_t)(tmp1 - c->raw_Immediate); break; } case 0x11: /* SUBUI */ { + strncpy(Name, "SUBUI", 19); vm->reg[c->reg0] = utmp1 + c->raw_Immediate; break; } case 0x12: /* CMPI */ { + strncpy(Name, "CMPI", 19); /* Clear bottom 3 bits of condition register */ vm->reg[c->reg0] = vm->reg[c->reg0] & 0xFFFFFFF8; if(tmp1 > c->raw_Immediate) @@ -984,55 +1160,49 @@ bool eval_2OPI_Int(struct lilith* vm, struct Instruction* c) } case 0x13: /* LOAD */ { + strncpy(Name, "LOAD", 19); vm->reg[c->reg0] = readin_Reg(vm, (utmp1 + c->raw_Immediate)); break; } case 0x14: /* LOAD8 */ { - raw0 = vm->memory[utmp1 + c->raw_Immediate]; - int32_t tmp = raw0; - - /* Sign extend Register */ - tmp = tmp << 24; - tmp = tmp >> 24; - - vm->reg[c->reg0] = tmp; + strncpy(Name, "LOAD8", 19); + vm->reg[c->reg0] = readin_byte(vm, utmp1 + c->raw_Immediate, true); break; } case 0x15: /* LOADU8 */ { - vm->reg[c->reg0] = (uint8_t)(vm->memory[utmp1 + c->raw_Immediate]); + strncpy(Name, "LOADU8", 19); + vm->reg[c->reg0] = readin_byte(vm, utmp1 + c->raw_Immediate, false); break; } case 0x16: /* LOAD16 */ { - raw0 = vm->memory[utmp1 + c->raw_Immediate]; - raw1 = vm->memory[utmp1 + c->raw_Immediate + 1]; - - int32_t tmp = raw0*0x100 + raw1; - - /* Sign extend Register */ - tmp = tmp << 16; - tmp = tmp >> 16; - vm->reg[c->reg0] = tmp; + strncpy(Name, "LOAD16", 19); + vm->reg[c->reg0] = readin_doublebyte(vm, utmp1 + c->raw_Immediate, true); break; } case 0x17: /* LOADU16 */ { - raw0 = vm->memory[utmp1 + c->raw_Immediate]; - raw1 = vm->memory[utmp1 + c->raw_Immediate + 1]; - - vm->reg[c->reg0] = raw0*0x1000000 + raw1; + strncpy(Name, "LOADU16", 19); + vm->reg[c->reg0] = readin_doublebyte(vm, utmp1 + c->raw_Immediate, false); break; } case 0x18: /* LOAD32 */ + { + strncpy(Name, "LOAD32", 19); + vm->reg[c->reg0] = readin_Reg(vm, (utmp1 + c->raw_Immediate)); + break; + } case 0x19: /* LOADU32 */ { + strncpy(Name, "LOADU32", 19); vm->reg[c->reg0] = readin_Reg(vm, (utmp1 + c->raw_Immediate)); break; } case 0x1F: /* CMPUI */ { + strncpy(Name, "CMPUI", 19); /* Clear bottom 3 bits of condition register */ vm->reg[c->reg0] = vm->reg[c->reg0] & 0xFFFFFFF8; if(utmp1 > (uint32_t)c->raw_Immediate) @@ -1051,55 +1221,31 @@ bool eval_2OPI_Int(struct lilith* vm, struct Instruction* c) } case 0x20: /* STORE */ { + strncpy(Name, "STORE", 19); writeout_Reg(vm, (utmp1 + c->raw_Immediate), vm->reg[c->reg0]); break; } case 0x21: /* STORE8 */ { - int32_t tmp = (int8_t)(vm->reg[c->reg0]); - raw0 = tmp%0x100; - - vm->memory[utmp1 + c->raw_Immediate] = raw0; + strncpy(Name, "STORE8", 19); + writeout_byte(vm, utmp1 + c->raw_Immediate, vm->reg[c->reg0]); break; } - case 0x22: /* STOREU8 */ + case 0x22: /* STORE16 */ { - uint32_t tmp = vm->reg[c->reg0]; - raw0 = tmp%0x100; - - vm->memory[utmp1 + c->raw_Immediate] = raw0; + strncpy(Name, "STORE16", 19); + writeout_doublebyte(vm, utmp1 + c->raw_Immediate, vm->reg[c->reg0]); break; } - case 0x23: /* STORE16 */ - { - int32_t tmp = (int16_t)(vm->reg[c->reg0]); - raw1 = tmp%0x100; - tmp = tmp/0x100; - raw0 = tmp%0x100; - - vm->memory[utmp1 + c->raw_Immediate] = raw0; - vm->memory[utmp1 + c->raw_Immediate + 1] = raw1; - break; - } - case 0x24: /* STOREU16 */ - { - uint32_t tmp = vm->reg[c->reg0]; - raw1 = tmp%0x100; - tmp = tmp/0x100; - raw0 = tmp%0x100; - - vm->memory[utmp1 + c->raw_Immediate] = raw0; - vm->memory[utmp1 + c->raw_Immediate + 1] = raw1; - break; - } - case 0x25: /* STORE32 */ - case 0x26: /* STOREU32 */ + case 0x23: /* STORE32 */ { + strncpy(Name, "STORE32", 19); writeout_Reg(vm, (utmp1 + c->raw_Immediate), vm->reg[c->reg0]); break; } default: return true; } + if(DEBUG) {fprintf(stdout, "# %s reg%u reg%u %i\n", Name, c->reg0, c->reg1, c->raw_Immediate);} return false; } @@ -1108,6 +1254,7 @@ bool eval_Integer_1OPI(struct lilith* vm, struct Instruction* c) { bool C, B, O, GT, EQ, LT; uint32_t tmp; + char Name[20] = "ILLEGAL_1OPI"; tmp = vm->reg[c->reg0]; @@ -1123,6 +1270,7 @@ bool eval_Integer_1OPI(struct lilith* vm, struct Instruction* c) { case 0x0: /* JUMP.C */ { + strncpy(Name, "JUMP.C", 19); if(1 == C) { /* Adust the IP relative the the start of this instruction*/ @@ -1132,6 +1280,7 @@ bool eval_Integer_1OPI(struct lilith* vm, struct Instruction* c) } case 0x1: /* JUMP.B */ { + strncpy(Name, "JUMP.B", 19); if(1 == B) { /* Adust the IP relative the the start of this instruction*/ @@ -1141,6 +1290,7 @@ bool eval_Integer_1OPI(struct lilith* vm, struct Instruction* c) } case 0x2: /* JUMP.O */ { + strncpy(Name, "JUMP.O", 19); if(1 == O) { /* Adust the IP relative the the start of this instruction*/ @@ -1150,6 +1300,7 @@ bool eval_Integer_1OPI(struct lilith* vm, struct Instruction* c) } case 0x3: /* JUMP.G */ { + strncpy(Name, "JUMP.G", 19); if(1 == GT) { /* Adust the IP relative the the start of this instruction*/ @@ -1159,6 +1310,7 @@ bool eval_Integer_1OPI(struct lilith* vm, struct Instruction* c) } case 0x4: /* JUMP.GE */ { + strncpy(Name, "JUMP.GE", 19); if((1 == GT) || (1 == EQ)) { /* Adust the IP relative the the start of this instruction*/ @@ -1168,6 +1320,7 @@ bool eval_Integer_1OPI(struct lilith* vm, struct Instruction* c) } case 0x5: /* JUMP.E */ { + strncpy(Name, "JUMP.E", 19); if(1 == EQ) { /* Adust the IP relative the the start of this instruction*/ @@ -1177,6 +1330,7 @@ bool eval_Integer_1OPI(struct lilith* vm, struct Instruction* c) } case 0x6: /* JUMP.NE */ { + strncpy(Name, "JUMP.NE", 19); if(1 != EQ) { /* Adust the IP relative the the start of this instruction*/ @@ -1186,6 +1340,7 @@ bool eval_Integer_1OPI(struct lilith* vm, struct Instruction* c) } case 0x7: /* JUMP.LE */ { + strncpy(Name, "JUMP.LE", 19); if((1 == EQ) || (1 == LT)) { /* Adust the IP relative the the start of this instruction*/ @@ -1195,6 +1350,7 @@ bool eval_Integer_1OPI(struct lilith* vm, struct Instruction* c) } case 0x8: /* JUMP.L */ { + strncpy(Name, "JUMP.L", 19); if(1 == LT) { /* Adust the IP relative the the start of this instruction*/ @@ -1204,6 +1360,7 @@ bool eval_Integer_1OPI(struct lilith* vm, struct Instruction* c) } case 0x9: /* JUMP.Z */ { + strncpy(Name, "JUMP.Z", 19); if(0 == tmp) { /* Adust the IP relative the the start of this instruction*/ @@ -1213,6 +1370,7 @@ bool eval_Integer_1OPI(struct lilith* vm, struct Instruction* c) } case 0xA: /* JUMP.NZ */ { + strncpy(Name, "JUMP.NZ", 19); if(0 != tmp) { /* Adust the IP relative the the start of this instruction*/ @@ -1222,15 +1380,18 @@ bool eval_Integer_1OPI(struct lilith* vm, struct Instruction* c) } default: return true; } + if(DEBUG) {fprintf(stdout, "# %s reg%u %d\n", Name, c->reg0, c->raw_Immediate);} return false; } bool eval_branch_1OPI(struct lilith* vm, struct Instruction* c) { + char Name[20] = "ILLEGAL_1OPI"; switch(c->raw_XOP) { case 0x0: /* CALLI */ { + strncpy(Name, "CALLI", 19); /* Write out the PC */ writeout_Reg(vm, vm->reg[c->reg0], vm->ip); @@ -1244,61 +1405,73 @@ bool eval_branch_1OPI(struct lilith* vm, struct Instruction* c) } case 0x1: /* LOADI */ { + strncpy(Name, "LOADI", 19); vm->reg[c->reg0] = (int16_t)c->raw_Immediate; break; } case 0x2: /* LOADUI*/ { + strncpy(Name, "LOADU", 19); vm->reg[c->reg0] = c->raw_Immediate; break; } case 0x3: /* SALI */ { + strncpy(Name, "SALI", 19); vm->reg[c->reg0] = vm->reg[c->reg0] << c->raw_Immediate; break; } case 0x4: /* SARI */ { + strncpy(Name, "SARI", 19); vm->reg[c->reg0] = vm->reg[c->reg0] >> c->raw_Immediate; break; } case 0x5: /* SL0I */ { + strncpy(Name, "SL0I", 19); vm->reg[c->reg0] = shift_register(vm->reg[c->reg0], c->raw_Immediate, true, true); break; } case 0x6: /* SR0I */ { + strncpy(Name, "SR0I", 19); vm->reg[c->reg0] = shift_register(vm->reg[c->reg0], c->raw_Immediate, false, true); break; } case 0x7: /* SL1I */ { + strncpy(Name, "SL1I", 19); vm->reg[c->reg0] = shift_register(vm->reg[c->reg0], c->raw_Immediate, true, false); break; } case 0x8: /* SR1I */ { + strncpy(Name, "SR1I", 19); vm->reg[c->reg0] = shift_register(vm->reg[c->reg0], c->raw_Immediate, false, false); break; } default: return true; } + if(DEBUG) {fprintf(stdout, "# %s reg%u %d\n", Name, c->reg0, c->raw_Immediate);} return false; } /* Process 0OPI Integer instructions */ bool eval_Integer_0OPI(struct lilith* vm, struct Instruction* c) { + char Name[20] = "ILLEGAL_0OPI"; switch(c->raw_XOP) { case 0x00: /* JUMP */ { + strncpy(Name, "JUMP", 19); vm->ip = vm->ip + c->raw_Immediate - 4; break; } default: return true; } + if(DEBUG) {fprintf(stdout, "# %s %d\n", Name, c->raw_Immediate);} return false; } @@ -1306,6 +1479,14 @@ bool eval_Integer_0OPI(struct lilith* vm, struct Instruction* c) void eval_instruction(struct lilith* vm, struct Instruction* current) { bool invalid = false; + fprintf(stdout, "Executing: %s\n", current->operation); + //usleep(1000); + performance_counter = performance_counter + 1; + + if(1000000 == performance_counter) + { + current->raw0 = 0xFF; + } switch(current->raw0) { @@ -1426,6 +1607,7 @@ int main(int argc, char **argv) struct lilith* vm; vm = create_vm(1 << 20); load_program(vm, argv); + performance_counter = 0; execute_vm(vm); destroy_vm(vm); diff --git a/vm.h b/vm.h index 3cace27..4091fe8 100644 --- a/vm.h +++ b/vm.h @@ -200,7 +200,8 @@ void writeout_Reg(struct lilith* vm, uint32_t p, uint32_t value) /* Allow the use of native data format for Register operations */ uint32_t readin_Reg(struct lilith* vm, uint32_t p) { - uint8_t raw0, raw1, raw2, raw3, sum; + uint8_t raw0, raw1, raw2, raw3; + uint32_t sum; raw0 = vm->memory[p]; raw1 = vm->memory[p + 1]; raw2 = vm->memory[p + 2]; @@ -214,6 +215,62 @@ uint32_t readin_Reg(struct lilith* vm, uint32_t p) return sum; } +/* Unify byte write functionality */ +void writeout_byte(struct lilith* vm, uint32_t p, uint32_t value) +{ + vm->memory[p] = (uint8_t)(value%0x100); +} + +/* Unify byte read functionality*/ +uint32_t readin_byte(struct lilith* vm, uint32_t p, bool Signed) +{ + if(Signed) + { + int32_t raw0; + raw0 = (int8_t)(vm->memory[p]); + return (uint32_t)(raw0); + } + + return (uint32_t)(vm->memory[p]); +} + +/* Unify doublebyte write functionality */ +void writeout_doublebyte(struct lilith* vm, uint32_t p, uint32_t value) +{ + uint8_t uraw0, uraw1; + uint32_t utmp = value; + utmp = utmp/0x10000; + uraw1 = utmp%0x100; + utmp = utmp/0x100; + uraw0 = utmp%0x100; + + vm->memory[p] = uraw0; + vm->memory[p + 1] = uraw1; +} + +/* Unify doublebyte read functionality*/ +uint32_t readin_doublebyte(struct lilith* vm, uint32_t p, bool Signed) +{ + if(Signed) + { + int8_t raw0, raw1; + int32_t sum; + raw0 = vm->memory[p]; + raw1 = vm->memory[p + 1]; + + sum = raw0*0x100 + raw1; + return (uint32_t)(sum); + } + + uint8_t uraw0, uraw1; + uint32_t usum; + uraw0 = vm->memory[p]; + uraw1 = vm->memory[p + 1]; + + usum = uraw0*0x100 + uraw1; + return usum; +} + /* Determine the result of bit shifting */ uint32_t shift_register(uint32_t source, uint32_t amount, bool left, bool zero) {