20 November 2021, 04:08 | #1 |
Registered User
Join Date: Sep 2019
Location: Sydney
Posts: 357
|
CPU Caches
The other day, Ross had pointed out a problem in my cache flushing code which I fixed, and I was hopeful it could fix some compatibility issues some systems had. But then dlfrsilver reported some problems with my game on his A1200 with an A1230. Setting nocache on the CLI fixed it.
I load chunks of code from disk, both from the bootblock, and for each level (and dlfrsilver was only getting a problem on the 3rd level). After loading the code I do some relocation work on it, then I flush the cache using the below code (originally from SolidGold I believe), before jumping into it. Code:
Supervisor equ -30 move.l EXECBASE,a6 btst #AFB_68020,AttnFlags+1(a6) beq .skipFlushCache lea flushCaches(pc),a5 jsr Supervisor(a6) .skipFlushCache: flushCaches: mc68020 movec cacr,d0 tst.w d0 bmi .1 ; 68040/68060 I-Cache enabled? ; clear 68020/68030 caches or.w #$808,d0 movec d0,cacr rte mc68040 ; clear 68040/68060 caches .1: nop cpusha bc rte Any experience with common cache gotchas would be appreciated as I'm not sure where to start looking currently. Thanks |
20 November 2021, 09:25 | #2 |
Registered User
Join Date: Jan 2019
Location: Germany
Posts: 3,292
|
No. To clear the caches, call "CacheClearU()", an exec function, which takes care of all processors and cache types. You only need to do this if you modify code, or load data as code. The typical candidates such as starting a process or creating a task perform this already for you, thus it is unnecessary in many situations.
|
20 November 2021, 09:45 | #3 | |
Defendit numerus
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 54
Posts: 4,483
|
Quote:
Full deactivating the caches completely changes the cards! Hence a different previously hidden problem (a race condition) may not happen. I would also investigate elsewhere. EDIT: However if exec is valid and usable calling CacheClearU() is the right way, so you can get rid of any doubts on your code. I would use direct control of the caches registers only after a complete system takeover. Last edited by ross; 20 November 2021 at 10:06. |
|
20 November 2021, 10:06 | #4 |
Registered User
Join Date: Sep 2019
Location: Sydney
Posts: 357
|
I wasn’t clear but yes this is all after a system takeover.
|
20 November 2021, 14:21 | #5 |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,525
|
Maybe you cannot even call Supervisor() after a complete system takeover. At least it is not advisable. Or did you leave the OS structure intact?
BTW, CacheClearU() doesn't help when you intend to support Kickstart 1.x. |
20 November 2021, 16:25 | #6 |
Registered User
Join Date: Jan 2019
Location: Germany
Posts: 3,292
|
Kick 1.x will not work with any processor with caches that are "worth mentioning", i.e 68040 and up.
|
20 November 2021, 16:51 | #7 |
Registered User
Join Date: Jun 2016
Location: europe
Posts: 1,050
|
Code looks OK to me, I use a similar setup and it's been fine. Probably a problem elsewhere.
If you are killing the system (well, depends... are you also trashing it or just disabling via Disable()/$dff09a?), for utliity functions that need supervisor instructions you could consider using trap vectors. If calling Supervisor() is safe then calling CacheClearU() is also safe, and should be a preferred option (2.0+), but as mentioned, you'd still have to handle 1.3 and 040+ manually. |
20 November 2021, 17:39 | #8 |
Registered User
Join Date: Jul 2015
Location: The Netherlands
Posts: 3,430
|
I'd wager this question is for Muzza's excellent Turrican 2 AGA project, in which case Kickstart 1.3 is not really a problem to worry about.
|
20 November 2021, 21:21 | #9 |
Registered User
Join Date: Jan 2008
Location: Warsaw/Poland
Age: 56
Posts: 2,024
|
If this is AGA version, then no kick 1.3. This is logical, only kick 3.0 or higher.
|
21 November 2021, 06:00 | #10 |
Registered User
Join Date: Sep 2019
Location: Sydney
Posts: 357
|
Thanks for the replies, I do a system takeover but keep the system intact. And given that this is for OS2.0+, it seems sensible to change to use CacheClearU.
I agree it is probably just revealing a problem elsewhere, so I'll continue to look into that. |
22 November 2021, 07:11 | #11 |
Registered User
Join Date: Mar 2018
Location: Hastings, New Zealand
Posts: 2,698
|
|
22 November 2021, 10:56 | #12 |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,525
|
He mentioned that he has taken over the system. Probably he even uses some trackloader for the code. So you have to do relocation yourself to support different Fast RAM expansions. At least this is what I do in my games...
|
22 November 2021, 11:02 | #13 |
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,351
|
IF the game does not make use of extra computing power that accelerated machines have (i.e. pure 68000 speed is always enough) then you might be better off by turning caches off at startup, before the takeover.
|
22 November 2021, 22:19 | #14 | |
Registered User
Join Date: Sep 2019
Location: Sydney
Posts: 357
|
Quote:
Yes, three code modules with internal references and which make calls to other modules. They are loaded into dynamically allocated memory, so all the internal and external references need relocating to point to the correct locations depending on where they are in RAM and where the other modules are. |
|
22 November 2021, 22:28 | #15 | |
Registered User
Join Date: Sep 2019
Location: Sydney
Posts: 357
|
Quote:
It targets 68020, so I'm assuming turning off cache would have negative affects there too. I implemented the CacheClearU change, and spent a lot of time making some copper code robust (because transitioning between copper lists in between game levels was my number one suspect for a possible race condition). Unfortunately the reports I've had back from some testers who were good enough to try it for me are that it now crashes on level 2. Next possible culprit is the music. It uses the TFMX player, and given that I didn't write that code myself, but had to interface with it, and that it is interrupt heavy, maybe there is a some timing issue there. But I'm just guessing really. |
|
22 November 2021, 23:49 | #16 |
Registered User
Join Date: Jan 2008
Location: Warsaw/Poland
Age: 56
Posts: 2,024
|
For testing TFMX Pro player, you can disable music. But from my memory TFMX Pro player has no problem to works on fastest CPU's on Amiga. Only TFMX 7V player (Turrican 2 intro/outro) uses SMC in mixing routine.
|
23 November 2021, 04:20 | #17 | |
Registered User
Join Date: Sep 2019
Location: Sydney
Posts: 357
|
Quote:
Useful to know thanks. I use both players in my code, but the 7V one is not activated in the current build, because like you say, it's only for the intro. |
|
24 November 2021, 23:14 | #18 |
Registered User
Join Date: Sep 2019
Location: Sydney
Posts: 357
|
Disabling all audio makes no difference. I've tried various WinUAE settings to make it run faster trying to reproduce a race condition, but nothing. Very frustrating.
|
24 November 2021, 23:58 | #19 |
Registered User
Join Date: Jan 2008
Location: Warsaw/Poland
Age: 56
Posts: 2,024
|
Maybe this is simply code bug? Reading random value from Amiga memory or writing data in bad place?
|
25 November 2021, 00:07 | #20 | |
Registered User
Join Date: Sep 2019
Location: Sydney
Posts: 357
|
Quote:
It is quite possible. I already do things like putting guards around all memory allocations in debug mode (to check for write overflows). Plus the code runs on PC too which would detect many common trashing bugs (apart from any in Amiga specific code of course). Last edited by Muzza; 25 November 2021 at 00:14. |
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Killing caches: fool-proof method? | Keir | Coders. Asm / Hardware | 41 | 17 January 2023 18:43 |
A1200 Early Startup Control vs CPU to disable caches! | BarryB | support.Games | 25 | 20 May 2020 22:28 |
Selling A3660 CPU card, including Rev 5 CPU - NEW - professionally built | tbtorro | MarketPlace | 1 | 17 June 2018 19:14 |
How to disable caches using MOVEC => CACR | jotd | Coders. Asm / Hardware | 12 | 07 November 2017 20:45 |
How not to flush caches. | Toni Wilen | Coders. General | 18 | 28 October 2011 10:05 |
|
|