Re: mmu for 65c02

From: fachat (afachat_at_gmx.de)
Date: 2005-04-20 22:22:42

On Wed, Apr 20, 2005 at 08:17:47PM +0200, Gabor Lenart wrote:
> On Wed, Apr 20, 2005 at 04:28:26PM +0200, A. Fachat wrote:
> > So a "full size" process contains
> > threads as "lightweight processes" without own memory mapping. In fact 
> 
> Yes. But in this way you can't have private stack for threads within a
> process, right? I mean threads within a process should use eg different
> part of the stack for example. This reduces the maximal usable stack size
> within the thread. And if you want to create 16 threads there is only

Yes, that is what I do. I have limited the number of threads to, IIRC, 
five or so.
> 
> Errrrrrrrrrr ... you're right, thanks ;-) But my problem is: if I have
> a process and creating a thread, than maybe I will use the same zero page
> locations (eg it's a cc65 compiled software using zero pages) so they
> will disturb each other, doesn't it?

If both threads are running the same code, yes. In general the zeropage
must be considered as "static global" process variables, and are thus
shared and accessible by all threads similar to such variables in C.
If you want thread-local variables, they must be created "on the heap",
i.e. local variables in C. So you cannot use zeropage adressing there,
only indirect indexed. If cc65 handles this I don't know, Uz?

IIRC I have in OS/A65 a "thread context pointer" of 
two bytes that are in the zeropage and that are swapped together with
the thread, and not the process. I.e. when there is a context switch between
two threads in the same process, those two bytes are swapped. 
I think I used this to implement the 
lib6502 in a threadsafe way (the lib6502 implementation handles a 
thread-specific context and uses the "thread context pointer" to address 
the data in the context. 

So all threads use the same code and still the code is thread safe :-)

> > The advantage of your scheme is that you could have a common mapping of 
> > the zeropage for all
> > threads in a processes, but each thread could have its own stack 
> 
> You can do it as well, if you have another mapper just for stack (addresses
> between $100 and $1ff). So in your project you have 4K length pages but with

Well yes, but I would still have to solder that stuff together - which is
complicated if you don't use programmable logic.

André




       Message was sent through the cbm-hackers mailing list

Archive generated by hypermail pre-2.1.8.