Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!cbmvax!jesup From: jesup@cbmvax.commodore.com (Randell Jesup) Newsgroups: comp.sys.amiga.programmer Subject: Re: Self modifying code Message-ID: <21988@cbmvax.commodore.com> Date: 29 May 91 02:44:32 GMT References: <5005@orbit.cts.com> <1991May28.120630.10150@cs.umu.se> <1991May28.171342.31105@kuhub.cc.ukans.edu> Reply-To: jesup@cbmvax.commodore.com (Randell Jesup) Organization: Commodore, West Chester, PA Lines: 45 In article <1991May28.171342.31105@kuhub.cc.ukans.edu> markv@kuhub.cc.ukans.edu writes: >> Consider for instance that I would like to write a fast completely >> unwinded linedrawing routine and wrote code for drawing one pixel. >> Then when the program start, I would allocate memory for 320 such routines >> and putting 320 copies of my routine there. Would this be considered as >> selfmodifying code, and therefore forbidden? > >Yes, for two reasons. In practice on the current Amiga it would >probably work assuming you wrote the code before any was executed. In most cases you'll get lucky on an '030 since the internal cache is small (256 bytes). Note that is NOT the last ~128 instructions - caches aren't like fifo's. So you can execute thousands of cycles across several hundred instructions and still get unlucky, at least theoretically. >However, in future OSs, where the MMU has pages flagged as CODE or >DATA, or future hardware that plays cache control games with a large >external cache (using the FCx and CIN lines), you could still barf. Yup. The A3000 has provision on the 200-pin connector for large external caches, and in addition CPUs in that (or other) CPU-slots could have external caches. And of course the '040 has a monster internal cache, and can bite you far easier than you think, particularily in copy-back mode. >Under 2.0 the legal way to do this is write you routines and then call >CacheFlush(). (Not very friendly to the OS to do it too often, but >okay for a one shot deal). Future OSes that use the MMU actively will >likely have the calls to play with the attributes of memory, whether >its a code page or data page, whether its cachable or not, etc. Actually, some of the calls exist already. CacheClearU and CacheClearE, CacheControl, CachePreDMA and CachePostDMA. Under 2.0, for example, Dos uses CacheClearE in LoadSeg and Create{New}Proc, and the A3000 scsi driver uses the Cache{Pre,Post}DMA calls. Some parts of these are hooks for the future, as well - for example, CachePreDMA is designed so it could handle memory translation and locking in a mapped system. -- Randell Jesup, Jack-of-quite-a-few-trades, Commodore Engineering. {uunet|rutgers}!cbmvax!jesup, jesup@cbmvax.cbm.commodore.com BIX: rjesup Disclaimer: Nothing I say is anything other than my personal opinion. "No matter where you go, there you are." - Buckaroo Banzai