diff vdisk.c @ 50:1430678cd4fb

use process structure's mmu
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 21 Jul 2018 22:44:02 +0900
parents 947cbecdd8d5
children 498b6fcaf270
line wrap: on
line diff
--- a/vdisk.c	Sat Jul 21 19:25:53 2018 +0900
+++ b/vdisk.c	Sat Jul 21 22:44:02 2018 +0900
@@ -19,16 +19,19 @@
 
 static int vdiskdebug = 1;  //   1 trace, 2 filename
 
+
+Byte pmmu[8];  // process dat mmu
+
 extern char *prog ;   // for disass
 #ifdef USE_MMU
 extern Byte * mem0(Byte *iphymem, Word adr, Byte *immu) ;
 //  smem physical address using system mmu
-//  umem physical address using caller's mmu
+//  pmem physical address using caller's mmu
 #define smem(a)  mem0(phymem,a,&mem[0x20+IOPAGE])
-#define umem(a)  (mem[0x42+IOPAGE]?mem0(phymem,a,&mem[0x28+IOPAGE]):mem0(phymem,a,&mem[0x20+IOPAGE]))
+#define pmem(a)  mem0(phymem,a,pmmu)
 #else
-#define umem(a)  (&mem[a])
 #define smem(a)  (&mem[a])
+#define pmem(a)  (&mem[a])
 #endif
 
 #define MAXPDV 256
@@ -162,20 +165,22 @@
     char *p = path;
     char *name = path;
     int maxlen = MAXPAHTLEN;
-if(vdiskdebug) { printf("checkf \""); putOs9str(name); printf("\"\n"); }
-    while(*p!=0 && (*p&0x80)==0 && (*p>0x1f) && maxlen-->0) p++;
+if(vdiskdebug&2) { printf("checkf \""); putOs9str(name); printf("\"\n"); }
+    while(*p!=0 && (*p&0x80)==0 && (*p&0x7f)>' ' && maxlen-->0) p++;
     if (maxlen==MAXPAHTLEN) return 0;
     if (*p!=0) {
         name = (char *)malloc(p-path+1); 
-        strncpy(name,path, MAXPAHTLEN-maxlen);
-        name[MAXPAHTLEN-maxlen-1] &= 0x7f;
+        int i;
+        for(int i=0;i<MAXPAHTLEN;i++) {
+            name[i] = path[i]&0x7f;
+        }
         name[MAXPAHTLEN-maxlen] = 0;
     }
     char *name1 = addCurdir(name,pd,curdir);
     if (name1!=name && name1!=path) free(name);
     if (name1==0) return 0;
     pd->name = name1;
-if(vdiskdebug) {
+if(vdiskdebug&2) {
     printf(" remain = \"");
     char *p1 = p;
     while(*p1 && (*p1&0x80)==0 ) { if (*p1<0x20)  printf("(0x%02x)",*p1); else  putchar(*p1); p1++; }
@@ -355,6 +360,15 @@
     return 0;
 }
 
+void
+getDAT() {
+    Word ps = getword(smem(0x50));      // process structure
+    Byte *dat = smem(ps+0x40);  // process dat (dynamic address translation)
+    for(int i=0; i<8; i++) {
+        pmmu[i] = dat[i*2+1];
+    }
+}
+
 /*
  *   each command should have preallocated os9 path descriptor on Y
  *
@@ -376,6 +390,8 @@
     Byte mode = 0;
     Byte *os9pd = smem(getword(&mem[0x47+IOPAGE]));
     PathDesc *pd = pdv+*os9pd;
+
+    getDAT();
     pd->num = *os9pd;
     pd->drv = mem[0x41+IOPAGE];
     char *path,*next,*buf;
@@ -398,7 +414,7 @@
         case 0xd1:
             mode = *areg;
             attr = *breg;
-            path = (char *)umem(xreg);
+            path = (char *)pmem(xreg);
             next = pd->name  = checkFileName(path,pd,curdir);
             pd->dir = 0;
             pd->fp = fopen(pd->name, os9toUnixAttr(attr));
@@ -429,7 +445,7 @@
             mode = *areg;
             attr = *breg;
             pd->fp = 0;
-            path = (char*)umem(xreg);
+            path = (char*)pmem(xreg);
             next = checkFileName(path,pd,curdir);
             *breg = 0xff;
             if (next!=0) {
@@ -469,7 +485,7 @@
 
         case 0xd3:
             *breg = 0xff;
-            path = (char*)umem(xreg);
+            path = (char*)pmem(xreg);
             next =  checkFileName(path,pd,curdir);
             if (next!=0 &&  mkdir(pd->name,0)!= 0 ) {
                 xreg += ( next - path );
@@ -503,7 +519,7 @@
         * we keep track a cwd and a cxd for a process using 8bit id
         */
         case 0xd4:
-            path = (char*)umem(xreg);
+            path = (char*)pmem(xreg);
             next = checkFileName(path,pd,curdir);
             if (next!=0) { 
                 struct stat buf;
@@ -534,7 +550,7 @@
             *breg = 0xff;
             if (pd==0) break;
             struct stat st;
-            path = (char*)umem(xreg);
+            path = (char*)pmem(xreg);
             next = checkFileName(path,pd,curdir);
             pd->use = 0;
             if (next!=0 && stat(pd->name,&st)!=0) break;
@@ -585,7 +601,7 @@
         */
         case 0xd7:
             *breg = 0xff;
-            buf = (char*)umem(xreg);
+            buf = (char*)pmem(xreg);
             char *b;
             if ((b=fgets(buf,yreg,pd->fp))) {
                 if (b==0) {
@@ -616,7 +632,7 @@
         */
         case 0xd8:
             *breg = 0xff;
-            buf = (char*)umem(xreg);
+            buf = (char*)pmem(xreg);
             int i =  fread(buf,1,yreg,pd->fp);
             // set y 
             setword(smem(u+6),i);
@@ -643,7 +659,7 @@
             if (pd->dir) break;
             int len = yreg;
             int i = 0;
-            Byte *buf = umem(xreg);
+            Byte *buf = pmem(xreg);
             while(len>0 && *buf !='\r') {
                 fputc(buf[i++],pd->fp);
                 len--;
@@ -671,7 +687,7 @@
         case 0xda :
             *breg = 0xff;
             if (!pd->dir) {
-                Byte *buf = umem(xreg);
+                Byte *buf = pmem(xreg);
                 int len = yreg;
                 int err = fwrite(buf,1,len,pd->fp);
                 *breg = err?0:0xff;
@@ -743,7 +759,7 @@
                  */
                     *breg = 0xff;
                     if (pd==0) break;
-                    *breg = filedescriptor(umem(xreg), yreg,pd) ;
+                    *breg = filedescriptor(pmem(xreg), yreg,pd) ;
                     break;
                 case 0x20: // Pos.FDInf    mandatry for dir command
                 /*         SS.FDInf ($20) - Directly reads a file descriptor from anywhere
@@ -758,7 +774,7 @@
                     *breg = 0xff;
                     if (pd==0) break;
                     ureg = getword(smem(u+8));
-                    *breg  = fdinfo(umem(xreg),yreg,xreg*0x10000+ureg,pd);
+                    *breg  = fdinfo(pmem(xreg),yreg,xreg*0x10000+ureg,pd);
                     break;
                 default:
                 *breg = 0xff;
@@ -810,7 +826,7 @@
     yreg  = getword(frame+6);
     ureg  = getword(frame+8);
     pcreg  = getword(frame+10)-3;
-    prog = (char*)(umem(pcreg) - pcreg);
+    prog = (char*)(pmem(pcreg) - pcreg);
     do_trace(fp);
 }