OSDN Git Service

VisualStudioでの警告抑制とコメント付加
authorttwilb <ttwilb@users.sourceforge.jp>
Mon, 10 Mar 2014 01:08:07 +0000 (10:08 +0900)
committerttwilb <ttwilb@users.sourceforge.jp>
Mon, 10 Mar 2014 01:08:07 +0000 (10:08 +0900)
jitc.c
main.c
osecpu.h
switch.h

diff --git a/jitc.c b/jitc.c
index 3192437..98c4ec8 100644 (file)
--- a/jitc.c
+++ b/jitc.c
@@ -1412,7 +1412,10 @@ unsigned char *jitCompCallFunc(unsigned char *dst, void *func)
        jitCompPutByte1(w.dst, 0x55);   /* PUSH(EBP); */
        jitCompPutByte1(w.dst, 0xe8);   /* CALL(func); */
        int j = ((unsigned char *)func) - (w.dst + 4);
+
+       //この関数の中では結局w->dstしか参照していない
        jitCompPutImm32(&w, j);
+
        jitCompPutByte1(w.dst, 0x58);   /* POP(EAX); */         /* (win32では不要なのだけど、MacOSには必要らしい) */
        jitCompPutByte1(w.dst, 0x58);   /* POP(EAX); */
        jitCompPutByte1(w.dst, 0x61);   /* POPAD(); */
@@ -1543,6 +1546,15 @@ void errHndl(struct Regs *r)
        // ここに帰ってきてはいけない.
 }
 
+/*
+ * qq : 出力バイナリの書き込み位置のアドレスへの参照(書き込み位置を呼び出しに反映させるため参照渡しにする)
+ * q1 : 出力バイナリの書き込み位置のアドレスの最大値
+ * p0 : (*.ose)バイナリの読み込み位置のアドレス(ヘッダ部除去済)
+ * p1 : (*.ose)バイナリの読み込み位置の取りうる最大値
+ *      (ただし、「確保したメモリ」の最大値なのでこれより手前にゴミデータが入っているかもしれない)
+ * ret=1 : ヘッダのエラー
+ * ret=2 : jitコンパイルエラー
+ */
 int jitc0(unsigned char **qq, unsigned char *q1, const unsigned char *p0, const unsigned char *p1, int level, struct LabelTable *label)
 {
        unsigned char *q = *qq;
diff --git a/main.c b/main.c
index dbf7bc1..20869ed 100644 (file)
--- a/main.c
+++ b/main.c
@@ -14,7 +14,14 @@ int osecpuMain(int argc, char **argv)
 {
        unsigned char *appbin = malloc(APPSIZ1), *up;
        unsigned char *jitbuf = mallocRWE(1024 * 1024); /* とりあえず1MBで */
-       unsigned char *sysjit0 = mallocRWE(SJITSIZ1), *sysjit1 = sysjit0, *sysjit00 = sysjit0;
+       //unsigned char *sysjit0 = mallocRWE(SJITSIZ1), *sysjit1 = sysjit0, *sysjit00 = sysjit0;
+
+       // syslib.oseのjitc結果を格納する領域を確保。
+       unsigned char *sysjit00 = mallocRWE(SJITSIZ1);
+
+       // 現在の、jitc結果を格納するメモリへの書き込み位置のアドレス
+       unsigned char *sysjit = sysjit00;
+
        unsigned char *systmp0 = malloc(SYSTMP0SIZ);
        unsigned char *systmp1 = malloc(SYSTMP1SIZ);
        unsigned char *systmp2 = malloc(1024 * 1024), *opTbl = malloc(256);
@@ -58,19 +65,32 @@ int osecpuMain(int argc, char **argv)
                return 1;
        }
        if (syslib[0] == 0x05 && syslib[1] == 0xc1) {
+               
+               // 一体この部分ではなにをやっているのだろう?
+               // OSECPUに0x05, 0x1bという命令はないが... ヘッダ?
+               // どうせ初めからの32バイトは無視されるのだろうに...
+
                memcpy(systmp0, syslib, appsiz0);
                ComLib_main(systmp0 + 2, syslib + 2);
                syslib[0] = 0x05;
                syslib[1] = 0x1b;
        }
 
-       sysjit1 = jitCompInit(sysjit1);
-       sysjit0 = sysjit1;
-       i = jitc0(&sysjit1, sysjit00 + SJITSIZ1, syslib + 32, syslib + SYSLIBSIZ1, JITC_LV_SLOWEST + 9, label);
+       // jutc.cのerrHndl()をCALLするネィティブコードを挿入。
+       // sysjitの値は次の書き込み位置へずらされる。
+       // 元々のsysjitはsysjit00へ保存されている。
+       sysjit = jitCompInit(sysjit);
+
+       // sysjit (アドレス変数)は下の関数の実行で変更される(だから参照渡し)
+       // もちろんsysjitの値は次の書き込み位置へずらされる。
+       // labelはjitc0()内で初期化される。
+       i = jitc0(&sysjit, sysjit00 + SJITSIZ1, syslib + 32, syslib + SYSLIBSIZ1, JITC_LV_FASTEST, label);
        if (i != 0) {
                fputs("syslib-file JITC error.¥n", stderr);
                return 1;
        }
+
+       // エラー時にデバッグ用に表示する変数を加算
        di1_serial++;
 
        /* アプリバイナリの読み込み */
@@ -138,7 +158,7 @@ int osecpuMain(int argc, char **argv)
                regs.preg[0x0b].p = (void *)pxxFlag;
                regs.preg[0x0c].p = (void *)typLabel;
                regs.preg[0x0d].p = opTbl;
-               jitfunc = (void *)sysjit0;
+               jitfunc = (void *)sysjit;
                (*jitfunc)(((char *)&regs) + 128); /* サイズを節約するためにEBPを128バイトずらす */
                if (regs.ireg[0] != 0) {
                        jp = regs.preg[2].p - 1;
index ee99d53..a38c77f 100644 (file)
--- a/osecpu.h
+++ b/osecpu.h
@@ -3,6 +3,10 @@
 
 // プロジェクトのすべてのファイルで読み込むヘッダ
 
+
+/* Visual Studio で fopen()やsprintf() などの古い関数を使用する時に出る警告を抑止する*/
+#define _CRT_SECURE_NO_WARNINGS 1
+
 #include <stdio.h>
 #include <string.h>
 #include <limits.h>
@@ -69,6 +73,8 @@ struct Regs {
 
 static int *keybuf, keybuf_r, keybuf_w, keybuf_c;
 static int *vram = NULL, v_xsiz, v_ysiz;
+
+//デバッグ用。プログラム中の随所で加算される変数
 static int di1_serial = 0;
 
 // main.c
index 0977438..51abed1 100644 (file)
--- a/switch.h
+++ b/switch.h
@@ -5,7 +5,6 @@
  * このファイルを編集することでコンパイルの仕方を変更できます
  */
 
-
 /*
  * CPUのアーキテクチャ
  * 1 : i386