Valgrindで見つかったメモリー周辺の問題点を修正
[YACASL2.git] / src / exec.c
index 7034e19..feb735c 100644 (file)
@@ -9,7 +9,6 @@
  * 実行エラーの定義
  */
 static CERR cerr_exec[] = {
-    { 201, "Loading - full of COMET II memory" },
     { 202, "SVC input - out of Input memory" },
     { 203, "SVC output - out of COMET II memory" },
     { 204, "Program Register (PR) - out of COMET II memory" },
@@ -17,6 +16,15 @@ static CERR cerr_exec[] = {
     { 206, "Address - out of COMET II memory" },
     { 207, "Stack Pointer (SP) - out of COMET II memory" },
     { 209, "not GR in operand x" },
+    { 210, "not command code of COMET II" },
+};
+
+/**
+ * アセンブル結果読み込みエラーの定義
+ */
+static CERR cerr_load[] = {
+    { 201, "Loading - full of COMET II memory" },
+    { 208, "object file is not specified" },
 };
 
 /**
@@ -25,13 +33,20 @@ static CERR cerr_exec[] = {
 EXECMODE execmode = {false, false, false};
 
 /**
- * 実行エラーをエラーリストに追加
+ * アセンブル結果読み込みエラーをエラーリストに追加
  */
-bool addcerrlist_exec()
+void addcerrlist_load()
 {
-    return addcerrlist(ARRAYSIZE(cerr_exec), cerr_exec);
+    addcerrlist(ARRAYSIZE(cerr_load), cerr_load);
 }
 
+/**
+ * 実行エラーをエラーリストに追加
+ */
+void addcerrlist_exec()
+{
+    addcerrlist(ARRAYSIZE(cerr_exec), cerr_exec);
+}
 /**
  * 指定されたファイルからアセンブル結果を読み込む
  */
@@ -80,7 +95,7 @@ static void svcin()
         sys->memory[sys->cpu->gr[1]+i] = *(buffer + i);
     }
     sys->memory[sys->cpu->gr[2]] = i + 1;
-    free_chk(buffer, "buffer");
+    FREE(buffer);
 }
 
 /**
@@ -380,7 +395,9 @@ bool exec()
         /* 命令の取り出し */
         op = sys->memory[sys->cpu->pr] & 0xFF00;
         /* 命令の解読 */
-        cmdtype = getcmdtype(op);
+        if((cmdtype = getcmdtype(op)) == NOTCMD) {
+            setcerr(210, pr2str(sys->cpu->pr));          /* not command code of COMET II */
+        }
         r_r1 = (sys->memory[sys->cpu->pr] >> 4) & 0xF;
         x_r2 = sys->memory[sys->cpu->pr] & 0xF;
         /* traceオプション指定時、レジスタを出力 */