Browse Source

Added SET instructions

Jeremiah Orians 3 years ago
parent
commit
1582f2eef4
6 changed files with 129 additions and 2 deletions
  1. 6 0
      High_level_prototypes/defs
  2. 13 0
      Knight Reference/ISA_HEX_Map.org
  3. 2 2
      makefile
  4. 6 0
      vm.h
  5. 66 0
      vm_decode.c
  6. 36 0
      vm_instructions.c

+ 6 - 0
High_level_prototypes/defs

@@ -156,6 +156,12 @@ DEFINE PUSHPC 0D02000
 DEFINE POPPC 0D02001
 
 # 2OPI Group
+DEFINE SET.G E10000
+DEFINE SET.GE E10001
+DEFINE SET.E E10002
+DEFINE SET.NE E10003
+DEFINE SET.LE E10004
+DEFINE SET.L E10005
 DEFINE ADDI E1000E
 DEFINE ADDUI E1000F
 DEFINE SUBI E10010

+ 13 - 0
Knight Reference/ISA_HEX_Map.org

@@ -609,6 +609,19 @@ This block specified for instructions that require immediates
 *** 2OPI Groups
 2OPI ii ii is the Immediate, a = b OP ii ii
 
+**** 2OPI Set group
+| Hex               | Name             | Comment                         |
+|-------------------+------------------+---------------------------------|
+| E1 00 00 ab ii ii | SET.G a b ii ii  | gbitset(a) ? b = ii ii : b = 0  |
+| E1 00 01 ab ii ii | SET.GE a b ii ii | gebitset(a) ? b = ii ii : b = 0 |
+| E1 00 02 ab ii ii | SET.E a b ii ii  | ebitset(a) ? b = ii ii : b = 0  |
+| E1 00 03 ab ii ii | SET.NE a b ii ii | nebitset(a) ? b = ii ii : b = 0 |
+| E1 00 04 ab ii ii | SET.LE a b ii ii | lebitset(a) ? b = ii ii : b = 0 |
+| E1 00 05 ab ii ii | SET.L a b ii ii  | lbitset(a) ? b = ii ii : b = 0  |
+| E1 00 06 xx xx xx | Reserved         |                                 |
+| ...               |                  |                                 |
+| E1 00 0D xx xx xx | Reserved         |                                 |
+
 **** 2OPI Integer
 | Hex               | Name            | Comment                  |
 |-------------------+-----------------+--------------------------|

+ 2 - 2
makefile

@@ -112,10 +112,10 @@ xeh: Linux\ Bootstrap/Legacy_pieces/xeh.c | bin
 
 # libVM Builds for Development tools
 libvm.so: wrapper.c vm_instructions.c vm_decode.c vm.h tty.c
-	$(CC) -ggdb -DVM32=true -Dtty_lib=true -shared -Wl,-soname,libvm.so -o libvm.so -fPIC wrapper.c vm_instructions.c vm_decode.c tty.c functions/require.c functions/file_print.c
+	$(CC) -ggdb -DVM32=true -Dtty_lib=true -shared -Wl,-soname,libvm.so -o libvm.so -fPIC wrapper.c vm_globals.c vm_instructions.c vm_decode.c tty.c functions/require.c functions/file_print.c
 
 libvm-production.so: wrapper.c vm_instructions.c vm_decode.c vm.h
-	$(CC) -DVM32=true -shared -Wl,-soname,libvm.so -o libvm-production.so -fPIC wrapper.c vm_instructions.c vm_decode.c functions/require.c functions/file_print.c
+	$(CC) -DVM32=true -shared -Wl,-soname,libvm.so -o libvm-production.so -fPIC wrapper.c vm_globals.c vm_instructions.c vm_decode.c functions/require.c functions/file_print.c
 
 # Tests
 Generate-rom-test: ALL-ROMS

+ 6 - 0
vm.h

@@ -228,6 +228,12 @@ extern void CMPJUMPU_G(struct lilith* vm, struct Instruction* c);
 extern void CMPJUMPU_GE(struct lilith* vm, struct Instruction* c);
 extern void CMPJUMPU_LE(struct lilith* vm, struct Instruction* c);
 extern void CMPJUMPU_L(struct lilith* vm, struct Instruction* c);
+extern void SET_G(struct lilith* vm, struct Instruction* c);
+extern void SET_GE(struct lilith* vm, struct Instruction* c);
+extern void SET_E(struct lilith* vm, struct Instruction* c);
+extern void SET_NE(struct lilith* vm, struct Instruction* c);
+extern void SET_LE(struct lilith* vm, struct Instruction* c);
+extern void SET_L(struct lilith* vm, struct Instruction* c);
 
 /* Prototypes for functions in vm_decode.c*/
 extern struct lilith* create_vm(size_t size);

+ 66 - 0
vm_decode.c

@@ -1855,6 +1855,72 @@ bool eval_2OPI_Int(struct lilith* vm, struct Instruction* c)
 	/* 0xB0 ... 0xDF */
 	switch(c->raw2)
 	{
+		case 0x0: /* SET.G */
+		{
+			#ifdef DEBUG
+			strncpy(Name, "SET.G", 19);
+			#elif TRACE
+			record_trace("SET.G");
+			#endif
+
+			SET_G(vm, c);
+			break;
+		}
+		case 0x1: /* SET.GE */
+		{
+			#ifdef DEBUG
+			strncpy(Name, "SET.GE", 19);
+			#elif TRACE
+			record_trace("SET.GE");
+			#endif
+
+			SET_GE(vm, c);
+			break;
+		}
+		case 0x2: /* SET.E */
+		{
+			#ifdef DEBUG
+			strncpy(Name, "SET.E", 19);
+			#elif TRACE
+			record_trace("SET.E");
+			#endif
+
+			SET_E(vm, c);
+			break;
+		}
+		case 0x3: /* SET.NE */
+		{
+			#ifdef DEBUG
+			strncpy(Name, "SET.NE", 19);
+			#elif TRACE
+			record_trace("SET.NE");
+			#endif
+
+			SET_NE(vm, c);
+			break;
+		}
+		case 0x4: /* SET.LE */
+		{
+			#ifdef DEBUG
+			strncpy(Name, "SET.LE", 19);
+			#elif TRACE
+			record_trace("SET.LE");
+			#endif
+
+			SET_LE(vm, c);
+			break;
+		}
+		case 0x5: /* SET.L */
+		{
+			#ifdef DEBUG
+			strncpy(Name, "SET.L", 19);
+			#elif TRACE
+			record_trace("SET.L");
+			#endif
+
+			SET_L(vm, c);
+			break;
+		}
 		case 0x0E: /* ADDI */
 		{
 			#ifdef DEBUG

+ 36 - 0
vm_instructions.c

@@ -1393,6 +1393,42 @@ void POPPC(struct lilith* vm, struct Instruction* c)
 	writeout_bytes(vm, vm->reg[c->reg0], 0, reg_size);
 }
 
+void SET_G(struct lilith* vm, struct Instruction* c)
+{
+	if(GreaterThan_bit_set(vm->reg[c->reg0])) vm->reg[c->reg1] = c->raw_Immediate;
+	else vm->reg[c->reg1] = 0;
+}
+
+void SET_GE(struct lilith* vm, struct Instruction* c)
+{
+	if(GreaterThan_bit_set(vm->reg[c->reg0]) || EQual_bit_set(vm->reg[c->reg0])) vm->reg[c->reg1] = c->raw_Immediate;
+	else vm->reg[c->reg1] = 0;
+}
+
+void SET_E(struct lilith* vm, struct Instruction* c)
+{
+	if(EQual_bit_set(vm->reg[c->reg0])) vm->reg[c->reg1] = c->raw_Immediate;
+	else vm->reg[c->reg1] = 0;
+}
+
+void SET_NE(struct lilith* vm, struct Instruction* c)
+{
+	if(!EQual_bit_set(vm->reg[c->reg0])) vm->reg[c->reg1] = c->raw_Immediate;
+	else vm->reg[c->reg1] = 0;
+}
+
+void SET_LE(struct lilith* vm, struct Instruction* c)
+{
+	if(LessThan_bit_set(vm->reg[c->reg0]) || EQual_bit_set(vm->reg[c->reg0])) vm->reg[c->reg1] = c->raw_Immediate;
+	else vm->reg[c->reg1] = 0;
+}
+
+void SET_L(struct lilith* vm, struct Instruction* c)
+{
+	if(LessThan_bit_set(vm->reg[c->reg0])) vm->reg[c->reg1] = c->raw_Immediate;
+	else vm->reg[c->reg1] = 0;
+}
+
 void ADDI(struct lilith* vm, struct Instruction* c)
 {
 	signed_vm_register tmp1;