home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 575.lha / Personal040DevelopSoft / mmu.c < prev    next >
C/C++ Source or Header  |  1991-11-05  |  6KB  |  210 lines

  1. /*
  2.     MMU040 V1.0 for the Progressive Peripipherals & Software 040/A3000
  3.         by Greg Tibbs; some code from  SetCPU V1.4 by Dave Haynie
  4.  
  5.     MAIN PROGRAM
  6.  
  7.         Assumptions: The PPS 040 for the A3000 only works under 2.0+, so 
  8.                      assumptions that exec knows about an 040, that ROMsize
  9.                      is 512K. The PPS 040 has no onboard memory, so the
  10.                      area mapped from 0x0100000 on to the base of the A3000
  11.                      motherboard Ram is made invalid in the Address translation
  12.                      cache and accesses there will yield an address error
  13.                      exception. Zorro III memory area is made data &
  14.                      instruciton cachable, with ZorroII I/o space not
  15.                      cachable at all (040 limitation in that there is no
  16.                      ddistinction in the ATC between data accesses and 
  17.                      instruction accesses. The only way around this is
  18.                       with the mTTX registers which will be used primarily
  19.                      in fast ram. 
  20.     
  21. */
  22.  
  23. #define PROGRAM_VERSION    "V1.0"
  24.  
  25. #include <exec/types.h>
  26. #include <exec/execbase.h>
  27. #include <exec/nodes.h>
  28. #include <exec/interrupts.h>
  29. #include <stdio.h>
  30.  
  31. /* ====================================================================== */
  32.  
  33. /* Define all bit components used for manipulation of the Cache Control
  34.    Register. */
  35.  
  36. #define CACR_INST    (1L<<15)
  37. #define CACR_DATA    (1L<<31)
  38.  
  39.  
  40. /* ====================================================================== */
  41.  
  42. /* Define important bits used in various MMU registers. */
  43. /* Here are the TC definitions.  The TC register is 32 bits long. */
  44.  
  45. #define    TC_ENB        ((1L<<15)+(1L<<14))      /* Enable the MMU with 8K pages*/
  46.  
  47. /* Here are the page descriptor definitions, for short desctriptors only,
  48.    since that's all I'm using at this point. */
  49.    
  50. /* ====================================================================== */
  51.  
  52. /* Some external declarations. */
  53.  
  54. void SetCACR(), DumpCache(), SetCRP(), SetTC(), SetVBR();
  55. void SetITT0(), SetITT1(), SetDTT0(), SetDTT1();
  56. ULONG GetCACR(), GetTC(), GetCPUType(), GetCRP(), GetSRP();
  57. ULONG GetDTT0(), GetDTT1(), GetITT0(), GetITT1(), GetVBR(), GetMMUStatus();
  58.  
  59. /* ====================================================================== */
  60.  
  61. /* This replaces the Lattice "stricmp()" function, plus it's a better form
  62.    for my needs here. */
  63.    
  64. static BOOL striequ(s1,s2)
  65. char *s1,*s2;
  66. {
  67.    BOOL aok;
  68.    
  69.    while (*s1 && *s2 && (aok = (*s1++ & 0xdf) == (*s2++ & 0xdf)));
  70.    return (BOOL) (!*s1 && aok);
  71. }
  72.  
  73. void pdata(itt0)
  74. ULONG itt0;
  75. {
  76. UBYTE *enabled, *cmmode, *affects;
  77. ULONG temp;
  78.  
  79.   temp=(itt0&0x60)>>5;
  80.   switch(temp)
  81.   {
  82.     case 0: cmmode = "WT";
  83.             break;
  84.     case 1: cmmode = "CB";
  85.          break;
  86.     case 2: cmmode = "NS";
  87.             break;
  88.     case 3: cmmode = "NN";
  89.             break;
  90.   }
  91.   temp=(itt0&0x6000)>>13;
  92.   switch(temp)
  93.   {
  94.     case 0: affects = "User Space";
  95.             break;
  96.     case 1: affects = "Supervisor Space";
  97.          break;
  98.     case 2:
  99.     case 3: affects = "Both U & S Space";
  100.             break;
  101.   }
  102.   if (itt0&0x8000)  
  103.     enabled="YES";
  104.   else
  105.   {
  106.     enabled="NO ";
  107.   }
  108.   printf("%s       %s     %s\n",cmmode, enabled, affects);
  109. }
  110.  
  111. /* This be the main program. */
  112.  
  113. int main(argc,argv)
  114. int argc;
  115. char *argv[];
  116. {
  117.    ULONG myTC,cpu,crp,srp,cacr,itt0,itt1,dtt0,dtt1,vbr,status;
  118.  
  119.    /* If they're just asking for help */
  120.  
  121.    if (argc >= 2 && argv[1][0] == '?') {
  122.       printf("\2337mMMU040 %s\2330m\n",PROGRAM_VERSION);
  123.       exit(0);
  124.    }
  125.  
  126.   /* Let's find out what we have, and perform the ROM translation, if it's
  127.      requested and hasn't been done already. */
  128.  
  129.    printf("\n\2337mMMU040 %s\2330m\n\n",PROGRAM_VERSION);
  130.  
  131.    cpu = GetCPUType();
  132.    if(cpu != 68040) 
  133.    {
  134.       printf("040 Not Present!!!\n");
  135.       exit(5L);
  136.    }
  137.    else
  138.    {
  139.       printf("68040 MMU is set up as follows:\n");
  140.    }
  141.  
  142.    status=GetMMUStatus();
  143.    vbr = GetVBR();   
  144.    myTC=GetTC();
  145.    cacr=GetCACR();
  146.    crp=GetCRP();
  147.    srp=GetSRP();
  148.    dtt0=GetDTT0();
  149.    dtt1=GetDTT1();
  150.    itt0=GetITT0();
  151.    itt1=GetITT1();
  152.  
  153.    printf("Vector Base Register: 0x%0lx\n",vbr);
  154.    printf("Translation Control Register (TC): ");
  155.    if(!(myTC & 0x8000)) 
  156.      printf("Disabled");
  157.    else
  158.      printf("Enabled ");
  159.  
  160.    if(myTC & 0x4000)
  161.      printf("  Page Size = 8K\n");
  162.    else
  163.      printf("  Page Size = 4K\n");
  164.    printf("Supervisor Space Root Pointer (SRP) = 0x%08x\n",srp);
  165.    printf("User Space Root Pointer (URP) = 0x%08x\n",crp);
  166.    if(cacr & 0x8000) 
  167.      printf("Instruction Cache (IC): Enabled  ");
  168.    else
  169.      printf("Instruction Cache (IC): Disabled ");  
  170.   if(cacr & 0x80000000) 
  171.      printf("   Data Cache (DC): Enabled  \n");
  172.    else
  173.      printf("   Data Cache (DC): Disabled \n");
  174.   printf("MMU Status Register = 0x%08x\n",status); 
  175.  
  176.   printf("\nTransparent Translation Registers (mTTx): \n");
  177.  
  178.   printf("ITT0: Address         Mask    CMMode  Enabled     Affects\n");
  179.   printf("      0x%02xXXXXXX   0x%02xXXXXXX  ",
  180.      (itt0&0xff000000)>>24, (itt0&0x00ff0000)>>16);
  181.   pdata(itt0);
  182.  
  183.   printf("ITT1: Address         Mask    CMMode  Enabled     Affects\n");
  184.   printf("      0x%02xXXXXXX   0x%02xXXXXXX  ",
  185.      (itt1&0xff000000)>>24, (itt1&0x00ff0000)>>16);
  186.   pdata(itt1);
  187.  
  188.   printf("DTT0: Address         Mask    CMMode  Enabled     Affects\n");
  189.   printf("      0x%02xXXXXXX   0x%02xXXXXXX  ",
  190.      (dtt0&0xff000000)>>24, (dtt0&0x00ff0000)>>16);
  191.   pdata(dtt0);
  192.  
  193.   printf("DTT1: Address         Mask    CMMode  Enabled     Affects\n");
  194.   printf("      0x%02xXXXXXX   0x%02xXXXXXX  ",
  195.      (dtt1&0xff000000)>>24, (dtt1&0x00ff0000)>>16);
  196.   pdata(dtt1);
  197.     
  198.    printf("\nBinary Equivalent (Hex):\n\n");
  199.    printf("TC =   %04x        CACR = %08x   SRP = %08x\n",myTC,cacr,srp);
  200.    printf("ITT0 = %08x    DTT0 = %08x   URP = %08x\n",itt0,dtt0, crp);
  201.    printf("ITT1 = %08x    DTT1 = %08x\n\n",itt1,dtt1);
  202.  
  203.    /* For safety's sake, or personal paranoia, or whatever, I dump the
  204.       data cache before I go away. */
  205.  
  206.    DumpCache();
  207.    exit(0L);
  208. }
  209.  
  210.