*********************************************************************
*                                                                   *
*     AMICOM'S  A3000 MMU PATCH   VERSION 1.11 (1990-09-18)         *
*                                                                   *
*********************************************************************




      ChipCache V1.11  Description
---------------------------------------------------------------------

This is a small tool that can improve the performance of certain A3000
configurations by turning on Instruction Cache in Chip-Memory.
Furthermore, it allows you to make use of an additional 200kB of Fast
Memory when running under Kickstart 1.3.  It is rather hacky and will
probably not work on future releases of the A3000 Operating System.
To prevent crashes, a number of checks are done.


First version 1990-08-15
Updates:
 V1.09a (1990-09-17): 2nd issue of bad -RESET bug fixed by flushing
 data cache after every switch.
 Seems that 68030 can create shit entries in datacache.

 V1.10 (1990-09-18): AmigaDOS 2.x proper cache control implemented.
 Former versions were unable to change cache status in 2.x

 V1.11 (1990-09-19): Showmem routine built in.



      ChipCache V1.11  History and About
---------------------------------------------------------------------

Let me first explain how I came to the idea for this tool.  Of course
one of the first things I did with my new A3000 was to check out some
graphics software to see the speed-improvements.  Thereby I made an
interesting observation:  A demo that did not work on the A2620 unless
you turned-off Instruction Cache worked perfectly with the Instruction
Cache turned on!  I started to investigate on that until I finally
came across a line of text in the 68030 manual that says:  'The CI bit
will disable both caches in the corresponding pages'.

The problem is the following:  you MUST disable the Data Cache in all
locations where other devices than the CPU can alter memory.  Imagine
a word of data being read from memory by the CPU.  This word is stored
in the Data Cache.  The next time the program reads the same memory
location, the word is fetched from Data Cache instead from memory, to
increase speed.  However, if the same memory location has been written
to by disk DMA for example, then the value in the cache is not valid
and incorrect data is being used by the processor.  Treating of such
memory regions is done by means of either the MMU translation table
(which in the A3000 is also used to map the Kickstart into the correct
place), or by the memory controlling hardware.  Hardware Cache disable
is done on a cycle-by-cycle basis through a pin on the 68030.
Software Cache disable uses a special bit named Cache Inhibit in the
MMU tree structure.  On the 68020/68851, this would only disable Data
Cache.  On the 68030, this same bit also disables Instruction Cache.
Why this is, I cannot tell and I'm afraid there is no sense in it.
Under no circumstances, neither graphics DMA data, nor hardware
registers will ever be used as program (Assembler instructions).
[ There is one big exception to that:  Harddisk DMA.  BUT:  that
problem is resolved by a different means:  The Instruction Cache is
flushed after every harddisk DMA load.  So that point can be left out
in the discussion.  ]

With a standard A3000 using the disk-Kickstart you have about 300Kb of
FAST memory after boot-up.  Therefore you will very soon end up
without FAST mem and code gets loaded into CHIP memory, causing heavy
performane degradation.  This degradation results from two sources:
 
	- The Chip memory clock is only 7.16 MHz
	   compared to 25Mhz in FAST memory.

	- There is no Instruction Cache in Chip Memory

The latter can now be fixed using ChipCache at the cost of complete
renounce of the Data Cache.
Note that this is by no means a general improvement to the A3000.  It
does in fact REDUCE the performance of a well-equiped A3000 that has
lots of FAST memory, because it requires disabling the Data Cache.




      ChipCache V1.11  Instructions
---------------------------------------------------------------------

ChipCache lets you

 - help the no-Cache-in-Chipmemory problem
 - find out how much Kickstart-memory is unused and can
     be used otherwise
 - remove the write protection of that memory, allowing
     write access to the system MMU translation table

* The CHIPMEMORY CACHE FUNCTION is completely undangerous and so you
  may enter without risk:
  
  	ChipCache
  
  which will present you an overview of the former and the new
  system status.
  Two parameters are changed: The Chipmemory Cache is turned on and
  the Data Cache is turned off (see 'About').
  The Chipmemory Cache function is of equal usefulness in both
  Kickstart / AmigaDOS 1.3 and 2.0
  
* If you want to go BACK TO THE INITIAL STATE, just enter
  
  	ChipCache -RESET
  
  You need not use capital letters for options and you may take
  advantage of the abbreviations stated after the options names
  presented by
  
  	ChipCache ?
  
* Extensive experimenting showed me that despite the considerations
  about Data Cache in Chip Memory, the machine may actually work ok.
  THIS DOES NOT MEAN THAT I GUARANTEE THAT IT WORKS!
  To allow you to experiment for yourself, I built-in option DATA.
  USE IT AT YOUR OWN RISK! System crashs can cause 'Key already set'
  problems!
  It is quite safe to use it with low-level (non-multitasking)
  software like Starglider and other games. Here, a speed increase
  can be stated. To enable both Chipmemory and Data Cache enter
  
  	ChipCache -DATA
  
* Since the Kickstart 1.3 uses only about 270kB of the 512kB that
  are allocated for it, and we are very short of Fast Memory on the
  standard A3000, I came to the idea to use the free space as system
  memory. Unfortunately, this region is write protected by MMU code
  that is set-up by the boot-rom.
  Therefore, I built a tool that removes this write protection and
  fitted it into ChipCache, too.
  To take advantage of this also, you need first to find out where
  exactly that usable memory is located.
  To do so, enter
  
  	ChipCache -SHOWMEM
  
  This will most probably give you the answer:
  
	  Addable memory from $07FC5000 to $07FFFFFF.
  
  Note that this inquiry cannot be repeated after you used that
  memory as system memory. It works only as long as this memory
  has never been touched.
  Then, you need to remove the writeprotection by entering
  
  	ChipCache -NOWPRO
  
  As you can see now, the status of the write protection has changed
  to inactive. Now you may add that memory to the system using
  the AddMem tool. Enter
  
  	AddMem $7fc5000 $7ffffff
  
  CAUTION: -	Attempting to AddMem to a region that does not contain
  		usable memory will instantly result in a crash.
  	   -	From now on, you must pay attention to NOT use option
  		RESET since this would reinstall the writeprotection
  		and therefore crash the machine.
  
  Note: To overcome the problem that option RESET may not be used
  while the additional memory is being used, option NOCHIPCACHE lets
  you remove just the Chipmemory Cache, without touching the
  writeprotection.
  
  
* The memory part that is usually write-protected contains
	- the new libraries, devices and resources the A3000
          Kick '1.3' needs
  	- the system MMU translation table
  Be careful not to overwrite any of these!
  
  If you want to look at the translation table, use CINFO (by me!)
  to locate it.
  If know what you're doing, you can change the translation table
  after removing the write-protection!
  Note also that the translation table is reset-proof, so you end up
  in a reboot-crash-loop if you trash it!
  
  Have Fun!





      ChipCache V1.11  Options
---------------------------------------------------------------------

Usage: ChipCache [-DATA=D] [-NOWPRO=NP] [-RESET=R] [-NOCHIPCACHE=NC]
                 [-SHOWMEM=S]

-DATA = D
This option causes the Data Cache not to be turned off.
The state your machine goes into using this option is not guaranteed
to be stable. Use this option AT YOUR OWN RISK and be careful!
The best thing is to start a low-level application immediately
after activating ChipCache with Data Cache.

-RESET = R
This option resets the chipmemory Cache (inhibts it) to normal mode.
It will also turn on the Data Cache and set the write protection
of the translation table memory.
CAUTION: You must not use RESET when you have added memory because
 this memory will then be write-protected!

-NOWPRO = NP
This option causes the write protection of the top 256kb of FAST RAM
(from $07fc0000 to $08000000) to be removed.
You are able then to alter the translation table, or use some free
memory for your own purposes.

-SHOWMEM = S
This option will tell you the address range (if any) in the top FAST
memory region that is unused and can be gained using AddMem.
NOTE: This option will only work if you did not use the extra memory
 region before, because it simply scans for the beginning of the
 region containing only zeros.

-NOCHIPCACHE = NC
This option reverts the chipcache function. Chipmemory Cache will
be turned off.
  
  
  
  
      ChipCache V1.11  Error messages
---------------------------------------------------------------------
If ChipCache fails because either
 - you gave invalid options / parameters
 - there was an internal problem (e.g. incompatible OS version)
 - you used it on a system it does not apply to
then it returns an error code of 20.
You may use this for script files like the Add200k tool supplied with
ChipCache.


Here is a list of all ChipCache error messages:

*** This is not an A3000!

*** Cannot recognize the A3000 translation table!
    Either you have a different A3000 Boot-ROM than I, or
    you are cheating, using ChipCache on a GVP-Board or so.

*** The translation table is somehow strange.
    Hmmm... strange!

*** Translation table outside of expected memory page!
    ROM OS version conflict. Please contact me.

*** Sorry, unable to handle the 68040!
    I have not yet had the pleasure to try it out.

*** Input line too long!

*** Got unexpected argument.
    Check for '-' before options.

*** Option RESET must be used alone!

