This is Cache-problem-Code-on-the-fly in view mode; [Up]
Date: Sun 30-Nov-1991 22:51:22 From: bkr@drdhh.hanse.de (Bjoern Kriews) Subject: Cache problem / Code on the fly I've got a problem with a somewhat unconventional application: A thread installs its own exception port with the goal of catching software exceptions. Now some code is created on the fly in an allocated buffer. (I know I should crawl into the next corner - but this is necessary for my purpose) The problem is that I can't execute this code via a function pointer because the processor seems to hold parts of it into its instruction cache. I created programs that worked, did nothing, crashed, all with the same binary. I also tried to vm_allocate my buffer, vm_protect it to 0, then prepare the code, vm_protect it to ALL, then copy the prepared code into the vm area and start it - all the same. Any help greatly appreciated, thanks in advance, Bjoern
Date: Sun 02-Dec-1991 04:38:55 From: melling@cs.psu.edu (Michael D Mellinger) Subject: Re: Cache problem / Code on the fly NeXT Answer: Hardware.656 --------------------------------------------------------------------------- execute it. This worked fine on the 68030, but now that I try it on the 68040 it doesn't work. What am I doing wrong? to generate opcodes at run-time and execute them. This worked as expected on the 68030, but on the 68040 architecture, it is necessary to flush the instruction cache to insure that your code is executed properly. To do this, you need to call a hardware trap (trap number 2). You can use the "asm" C function to place this assembly language call inline in your C code: asm("trap #2"); This call will flush the 4K of memory allocated to the Data and Instruction caches. There currently is no call on our system that selectively flushes part (or one) of these two caches. This call will not do anything harmful on 68030 machines, so it is not necessary to check which architecture you are running on. QA 656 Valid for 2.0 on the '040, does nothing harmful on the '030
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Marcel Waldvogel and Netfuture.ch.