Browse Source

Making disassembler more M2-Planet friendly

Jeremiah Orians 5 years ago
parent
commit
a4d2742e3e
4 changed files with 57 additions and 17 deletions
  1. 35 2
      High_level_prototypes/disasm.c
  2. 21 7
      ISA_HEX_Map.org
  3. 1 1
      vm_decode.c
  4. 0 7
      vm_instructions.c

+ 35 - 2
High_level_prototypes/disasm.c

@@ -123,6 +123,14 @@ void string_values(struct Instruction *c, bool first)
 	}
 }
 
+void print_address(struct Instruction* c)
+{
+	read_instruction(c);
+	address = address + 4;
+	fprintf(stdout,"%08X\t", address);
+	fprintf(stdout, "%s\t # M2 Large const\n", c->operation);
+}
+
 void decode_Integer_4OP(struct Instruction* c)
 {
 	/* Parse Raw Data */
@@ -1342,8 +1350,8 @@ void decode_0OPI(struct Instruction* c)
 		}
 	}
 
-	fprintf(stdout, "%s %d\t", Name, c->raw_Immediate);
-	fprintf(stdout, "# %s\n", c->operation);
+	fprintf(stdout, "%s %d\t# %s\n", Name, c->raw_Immediate, c->operation);
+	if(4 == c->raw_Immediate) print_address(c);
 }
 
 void decode_HALCODE(struct Instruction* c)
@@ -1356,6 +1364,31 @@ void decode_HALCODE(struct Instruction* c)
 	/* Convert to Human readable form */
 	switch(c->HAL_CODE)
 	{
+		case 0x000002: /* fopen */
+		{
+			strncpy(Name, "FOPEN", 19);
+			break;
+		}
+		case 0x000003: /* fclose */
+		{
+			strncpy(Name, "FCLOSE", 19);
+			break;
+		}
+		case 0x000008: /* fseek */
+		{
+			strncpy(Name, "FSEEK", 19);
+			break;
+		}
+		case 0x00003C: /* EXIT */
+		{
+			strncpy(Name, "EXIT", 19);
+			break;
+		}
+		case 0x00005A: /* CHMOD */
+		{
+			strncpy(Name, "CHMOD", 19);
+			break;
+		}
 		case 0x100000: /* FOPEN_READ */
 		{
 			strncpy(Name, "FOPEN_READ", 19);

+ 21 - 7
ISA_HEX_Map.org

@@ -887,16 +887,30 @@ This is a very rare and special group as each entry consumes a piece of the prec
 
 ** Exotic behavior
 *** Illegal instructions
-To ensure consistent behavior, all undefined opcodes are to be treated like illegal instructions and for hardware/operating system combinations that lack an illegal instruction handler, the result is that of HALT.
-Should an illegal instruction handler be implemented, the implementor should if possible emulate the instruction via software and jump to instruction that follows.
+To ensure consistent behavior, all undefined opcodes are to be treated like illegal
+instructions and for hardware/operating system combinations that lack an illegal
+instruction handler, the result is that of HALT.
+
+Should an illegal instruction handler be implemented, the implementor should if
+possible emulate the instruction via software and jump to instruction that follows.
 
 *** Illegal encoding
-Assemblers should throw an exception in the event that a register is compared to itself.
-As such code is likely wrong and such sequences are reserved for future opcode harvesting in the event of opcode starvation.
+Assemblers should throw an exception in the event that a register is compared to
+itself. As such code is likely wrong and such sequences are reserved for future
+opcode harvesting in the event of opcode starvation.
 
 *** compare and skip instructions
-All compare and skip instructions lookup the first byte following themselves to determine the number of bytes to skip to allow the correct behavior to occur with shorter and longer instruction formats.
+All compare and skip instructions lookup the first byte following themselves to
+determine the number of bytes to skip to allow the correct behavior to occur with
+shorter and longer instruction formats.
+This will result in a page fault if the next byte is in the next page and the
+instruction will have to be restarted
 
 *** HALCODE
-On systems that support an IOMMU and Kernel mode, all HALCODES can be modified or replaced by the kernel. Those listed in this document are those that must be supported on bootup.
-Systems supporting more HALCODES than those listed in this document must implement HALCODE 0x42FFFFFF which must provide a DEVICE LIST and HALCODE 0x42000000 which must provide a HALCODE LIST
+On systems that support an IOMMU and Kernel mode, all HALCODES can be modified or
+replaced by the kernel. Those listed in this document are those that must be
+supported on bootup.
+
+Systems supporting more HALCODES than those listed in this document must implement
+HALCODE 0x42FFFFFF which must provide a DEVICE LIST and HALCODE 0x42000000 which
+must provide a HALCODE LIST

+ 1 - 1
vm_decode.c

@@ -280,7 +280,7 @@ bool eval_HALCODE(struct lilith* vm, struct Instruction* c)
 				vm_EXIT(vm, performance_counter);
 				break;
 			}
-			case 0x00005A: /* EXIT */
+			case 0x00005A: /* CHMOD */
 			{
 				#ifdef DEBUG
 				strncpy(Name, "CHMOD", 19);

+ 0 - 7
vm_instructions.c

@@ -156,14 +156,7 @@ void vm_CHMOD(struct lilith* vm)
 
 void vm_FOPEN(struct lilith* vm)
 {
-	struct stat sb;
-
 	char* s = string_copy(vm, vm->reg[0]);
-	if(-1 == stat(s, &sb))
-	{
-		fprintf(stderr, "File named %s does not exist\n", s);
-		exit(EXIT_FAILURE);
-	}
 	vm->reg[0] = open(s, vm->reg[1], vm->reg[2]);
 	free(s);
 }