home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume1 / 8707 / 10 < prev    next >
Encoding:
Text File  |  1993-09-02  |  4.3 KB  |  145 lines

  1. Article 96 of comp.sources.misc:
  2. Relay-Version: version B 2.10.3 alpha 5/22/85; site osu-eddie.UUCP
  3. Path: osu-eddie!cbosgd!cwruecmp!hal!ncoast!allbery
  4. From: mouse@mcgill-vision.UUCP (der Mouse )
  5. Newsgroups: comp.sources.misc
  6. Subject: memdisk (silicon disk driver) patch 2
  7. Message-ID: <2805@ncoast.UUCP>
  8. Date: 7 Jul 87 01:44:47 GMT
  9. Date-Received: 8 Jul 87 01:15:38 GMT
  10. Sender: allbery@ncoast.UUCP
  11. Lines: 128
  12. Approved: allbery@ncoast.UUCP
  13. X-Archive: comp.sources.misc/8707/10
  14.  
  15. A while back I posted a silicon disk driver here.  Recently I posted a
  16. patch to it.  Well, 'tis time for another patch.
  17. This one allows you to execute binaries residing on the silicon disk.
  18. Unfortunately, it works this way only on VAXen.  I would have fixed it
  19. for Suns too, except that I don't know the Sun memory management well
  20. enough to wing it and SunOS doesn't come with source, unlike civilized
  21. operating systems (even *VMS* had it on microfiche, mutter grumble...).
  22.  
  23. The reason you couldn't execute off the silicon disk in the first place
  24. is that Berserkeley did something that stunningly violates the
  25. principle of least astonishment: user text space is readonly to the
  26. kernel as well as user!  Worse, when paging it in from disk, the page
  27. table entry is not marked valid until *after* the disk I/O is complete,
  28. meaning it doesn't work to just settprot(RW) before and settprot(RO)
  29. after!!  Sigh.  This way is a hack, but it does work.
  30.  
  31. *** /sys/local/memdisk.c-    Fri Jun 19 19:12:54 1987
  32. --- memdisk.c    Sun Jul  5 04:23:07 1987
  33. ***************
  34. *** 34,42 ****
  35.   #include "../h/ioctl.h"
  36.   #include "../h/buf.h"
  37.   #include "../h/conf.h"
  38. - #include "../h/time.h"
  39. - #include "../h/kernel.h"
  40.   #include "../h/errno.h"
  41.   #ifdef UFS_UFSMOUNT
  42.   #include "../ufs/ufsmount.h"
  43.   #define MOUNTTABLE mounttab
  44. --- 34,49 ----
  45.   #include "../h/ioctl.h"
  46.   #include "../h/buf.h"
  47.   #include "../h/conf.h"
  48.   #include "../h/errno.h"
  49. + #include "../h/dir.h"
  50. + #include "../h/user.h"
  51. + #include "../h/proc.h"
  52. + #include "../h/kernel.h"
  53. + #include "../h/seg.h"
  54. + #include "../h/vmmac.h"
  55. + #ifdef vax
  56. + #include "../vax/mtpr.h"
  57. + #endif
  58.   #ifdef UFS_UFSMOUNT
  59.   #include "../ufs/ufsmount.h"
  60.   #define MOUNTTABLE mounttab
  61. ***************
  62. *** 50,55 ****
  63. --- 57,64 ----
  64.   #define MOUNTTABLE mounttab
  65.   #endif
  66.   
  67. + #include "../machine/pte.h"
  68.   int max_md_size = (2048+512) * 1024; /* 2.5Mb */
  69.   
  70.   static struct memdiskinfo {
  71. ***************
  72. *** 124,130 ****
  73.       return;
  74.     }
  75.    if (bp->b_flags & B_READ)
  76. !   { bcopy(mdi->data+off,bp->b_un.b_addr,bp->b_bcount);
  77.     }
  78.    else
  79.     { bcopy(bp->b_un.b_addr,mdi->data+off,bp->b_bcount);
  80. --- 133,189 ----
  81.       return;
  82.     }
  83.    if (bp->b_flags & B_READ)
  84. !   {
  85. ! /* Berserkeley did something really stunning here.  User text is     */
  86. ! /*  read-only to the kernel, which means we can't just bcopy(), or you     */
  87. ! /*  can't run a binary residing on the silicon disk.  We double-map the     */
  88. ! /*  physical memory to a known r/w page to do the copy.  Unfortunately,     */
  89. ! /*  I don't know enough about Sun memory management to fix this for     */
  90. ! /*  Suns as well.                             */
  91. ! #ifdef vax
  92. !     if ( !(0x80000000&(int)bp->b_un.b_addr) &&
  93. !      isatsv(u.u_procp,btop(bp->b_un.b_addr)) )
  94. !      { static char kbuf[1024];
  95. !        static caddr_t kptr = 0;
  96. !        int nb;
  97. !        int bwp;
  98. !        int tocopy;
  99. !        caddr_t uva;
  100. !        struct pte *upte;
  101. !        struct pte *kpte;
  102. !        int kpfn;
  103. !        caddr_t daddr;
  104. !        if (kptr == 0)
  105. !     { kptr = (caddr_t) (((int)&kbuf[511])&~511);
  106. !     }
  107. !        kpte = (struct pte *) (0x80000000+mfpr(SBR)+(((0x7fffffff&(int)kptr)>>9)<<2));
  108. !        kpfn = kpte->pg_pfnum;
  109. !        nb = bp->b_bcount;
  110. !        uva = (caddr_t) bp->b_un.b_addr;
  111. !        daddr = mdi->data + off;
  112. !        while (nb > 0)
  113. !     { bwp = 511 & (int)uva;
  114. !       tocopy = 512 - bwp;
  115. !       if (tocopy > nb)
  116. !        { tocopy = nb;
  117. !        }
  118. !       upte = tptopte(u.u_procp,btop(uva));
  119. !       kpte->pg_pfnum = upte->pg_pfnum;
  120. !       mtpr(TBIS,(int)kptr);
  121. !       bcopy(daddr,kptr+bwp,tocopy);
  122. !       uva += tocopy;
  123. !       daddr += tocopy;
  124. !       nb -= tocopy;
  125. !     }
  126. !        kpte->pg_pfnum = kpfn;
  127. !        mtpr(TBIS,(int)kptr);
  128. !      }
  129. !     else
  130. !      { bcopy(mdi->data+off,bp->b_un.b_addr,bp->b_bcount);
  131. !      }
  132. ! #else
  133. !     bcopy(mdi->data+off,bp->b_un.b_addr,bp->b_bcount);
  134. ! #endif
  135.     }
  136.    else
  137.     { bcopy(bp->b_un.b_addr,mdi->data+off,bp->b_bcount);
  138.  
  139.                     der Mouse
  140.  
  141.                 (mouse@mcgill-vision.uucp)
  142.  
  143.  
  144.