Browse Source

Adding support for another POSIX-MODE Primitive

Jeremiah Orians 4 years ago
parent
commit
44745cf994
4 changed files with 32 additions and 0 deletions
  1. 5 0
      High_level_prototypes/disasm.c
  2. 1 0
      vm.h
  3. 11 0
      vm_decode.c
  4. 15 0
      vm_instructions.c

+ 5 - 0
High_level_prototypes/disasm.c

@@ -1393,6 +1393,11 @@ void decode_HALCODE(struct Instruction* c)
 			strncpy(Name, "UNAME", 19);
 			break;
 		}
+		case 0x00004F: /* GETCWD */
+		{
+			strncpy(Name, "GETCWD", 19);
+			break;
+		}
 		case 0x000050: /* CHDIR */
 		{
 			strncpy(Name, "CHDIR", 19);

+ 1 - 0
vm.h

@@ -102,6 +102,7 @@ struct Instruction
 void vm_EXIT(struct lilith* vm, uint64_t performance_counter);
 void vm_CHMOD(struct lilith* vm);
 void vm_UNAME(struct lilith* vm);
+void vm_GETCWD(struct lilith* vm);
 void vm_CHDIR(struct lilith* vm);
 void vm_FCHDIR(struct lilith* vm);
 void vm_ACCESS(struct lilith* vm);

+ 11 - 0
vm_decode.c

@@ -302,6 +302,17 @@ bool eval_HALCODE(struct lilith* vm, struct Instruction* c)
 				vm_UNAME(vm);
 				break;
 			}
+			case 0x00004F: /* GETCWD */
+			{
+				#ifdef DEBUG
+				strncpy(Name, "GETCWD", 19);
+				#elif TRACE
+				record_trace("GETCWD");
+				#endif
+
+				vm_GETCWD(vm);
+				break;
+			}
 			case 0x000050: /* CHDIR */
 			{
 				#ifdef DEBUG

+ 15 - 0
vm_instructions.c

@@ -173,6 +173,21 @@ void vm_UNAME(struct lilith* vm)
 	writeout_string(vm, arch_name, vm->reg[0] + 260);
 }
 
+void vm_GETCWD(struct lilith* vm)
+{
+	char* s = malloc(vm->reg[1]);
+	s = getcwd(s, vm->reg[1]);
+	if(NULL == s)
+	{
+		vm->reg[0] = 0;
+	}
+	else
+	{
+		writeout_string(vm, s, vm->reg[0]);
+	}
+	free(s);
+}
+
 void vm_CHDIR(struct lilith* vm)
 {
 	char* s = string_copy(vm, vm->reg[0]);