Discussion:
[N8VEM: 18147] A fast z80 on a fpga
Tom Lafleur
2014-05-30 21:09:36 UTC
Permalink
http://www.gadgetfactory.net/2014/05/socz80-a-z80-retro-microcomputer-for-the-papilio-pro-fpga-board/

i~~ _/) ~~~~ _/) ~~~~ _/) ~~~~ _/) ~~i

Tom Lafleur
(858) 759-9692
>
Nikolay Dimitrov
2014-05-30 21:38:21 UTC
Permalink
Hi Tom,

I saw this article too, it looks like Will's FPGA computer is getting
famous quickly :).
This is a really nice project - if you have Papillio board at hand, I
definitely recommend playing with it, especially with the Unix-like OS.

Regards,
Nikolay
Alan Cox
2014-05-30 23:24:14 UTC
Permalink
It's also very useful for developing code for a real CP/M box when you need
to use the native CP/M tools



On Fri, May 30, 2014 at 10:38 PM, Nikolay Dimitrov <picmaster-***@public.gmane.org>
wrote:

> Hi Tom,
>
> I saw this article too, it looks like Will's FPGA computer is getting
> famous quickly :).
> This is a really nice project - if you have Papillio board at hand, I
> definitely recommend playing with it, especially with the Unix-like OS.
>
> Regards,
> Nikolay
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "N8VEM" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to n8vem+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
> To post to this group, send email to n8vem-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
> Visit this group at http://groups.google.com/group/n8vem.
> For more options, visit https://groups.google.com/d/optout.
>

--
You received this message because you are subscribed to the Google Groups "N8VEM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to n8vem+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To post to this group, send email to n8vem-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
Visit this group at http://groups.google.com/group/n8vem.
For more options, visit https://groups.google.com/d/optout.
Paul Birkel
2014-05-31 07:06:32 UTC
Permalink
Ref Kickstarter:
https://www.kickstarter.com/projects/13588168/papilio-duo-drag-and-drop-fpga-circuit-lab-for-mak

Best of two worlds :->.


On Fri, May 30, 2014 at 7:24 PM, Alan Cox <etchedpixels-***@public.gmane.org> wrote:

> It's also very useful for developing code for a real CP/M box when you
> need to use the native CP/M tools
>
>
>
> On Fri, May 30, 2014 at 10:38 PM, Nikolay Dimitrov <picmaster-***@public.gmane.org>
> wrote:
>
>> Hi Tom,
>>
>> I saw this article too, it looks like Will's FPGA computer is getting
>> famous quickly :).
>> This is a really nice project - if you have Papillio board at hand, I
>> definitely recommend playing with it, especially with the Unix-like OS.
>>
>> Regards,
>> Nikolay
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "N8VEM" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to n8vem+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
>> To post to this group, send email to n8vem-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
>> Visit this group at http://groups.google.com/group/n8vem.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "N8VEM" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to n8vem+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
> To post to this group, send email to n8vem-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
> Visit this group at http://groups.google.com/group/n8vem.
> For more options, visit https://groups.google.com/d/optout.
>

--
You received this message because you are subscribed to the Google Groups "N8VEM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to n8vem+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To post to this group, send email to n8vem-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
Visit this group at http://groups.google.com/group/n8vem.
For more options, visit https://groups.google.com/d/optout.
Edward Snider
2014-05-31 13:43:31 UTC
Permalink
Neat!

On Saturday, May 31, 2014 2:06:33 AM UTC-5, pbirkel wrote:
>
> Ref Kickstarter:
> https://www.kickstarter.com/projects/13588168/papilio-duo-drag-and-drop-fpga-circuit-lab-for-mak
>
> Best of two worlds :->.
>
>
> On Fri, May 30, 2014 at 7:24 PM, Alan Cox <etched...-***@public.gmane.org
> <javascript:>> wrote:
>
>> It's also very useful for developing code for a real CP/M box when you
>> need to use the native CP/M tools
>>
>>
>>
>> On Fri, May 30, 2014 at 10:38 PM, Nikolay Dimitrov <picm...-***@public.gmane.org
>> <javascript:>> wrote:
>>
>>> Hi Tom,
>>>
>>> I saw this article too, it looks like Will's FPGA computer is getting
>>> famous quickly :).
>>> This is a really nice project - if you have Papillio board at hand, I
>>> definitely recommend playing with it, especially with the Unix-like OS.
>>>
>>> Regards,
>>> Nikolay
>>>
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "N8VEM" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to n8vem+un...-/***@public.gmane.org <javascript:>.
>>> To post to this group, send email to n8...-/***@public.gmane.org
>>> <javascript:>.
>>> Visit this group at http://groups.google.com/group/n8vem.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "N8VEM" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to n8vem+un...-/***@public.gmane.org <javascript:>.
>> To post to this group, send email to n8...-/***@public.gmane.org <javascript:>
>> .
>> Visit this group at http://groups.google.com/group/n8vem.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

--
You received this message because you are subscribed to the Google Groups "N8VEM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to n8vem+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To post to this group, send email to n8vem-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
Visit this group at http://groups.google.com/group/n8vem.
For more options, visit https://groups.google.com/d/optout.
Alan Cox
2014-07-01 22:33:49 UTC
Permalink
I've uploaded a couple of new SocZ80 things here

http://zeniv.linux.org.uk/~alan/SocZ80/

They are
- support for the Papilio Pro 'LogicStart' board including VGA output (in
the form of 80 x 30 text and also teletext modes)
- CP/M 3 BIOS and set up instructions to build and run banked CP/M 3 on it.

The VHDL is short the font rom at this point as I'm verifying the
licensing/copyright on it before I either release it or use a different
font set.

Next items on the hit list are SD card, ps/2 keyboard, rtc and ethernet but
not necessarily in that order.

Also fiddling with external "protected mode" circuitry. This allows the CPU
to do an out instruction to disable access to I/O devices which is only
undone by NMI or the processor on the first instruction fetch after
fetching an instruction with the bitpattern 11XXX111 (RST instructions).

NMI is needed as its hard to stop the user being irritating with DI, IM
1/2/3, but using NMI for all interrupts stops that mattering. I'm also
trying to make sure I do it in a way that could be done with real ICs.

--
You received this message because you are subscribed to the Google Groups "N8VEM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to n8vem+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To post to this group, send email to n8vem-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
Visit this group at http://groups.google.com/group/n8vem.
For more options, visit https://groups.google.com/d/optout.
Nikolay Dimitrov
2014-07-02 08:47:57 UTC
Permalink
Hi Alan,

On 7/2/2014 1:33 AM, Alan Cox wrote:
> Also fiddling with external "protected mode" circuitry. This allows
> the CPU to do an out instruction to disable access to I/O devices
> which is only undone by NMI or the processor on the first instruction
> fetch after fetching an instruction with the bitpattern 11XXX111 (RST
> instructions).
I also thought on a similar idea for protection circuitry. But if you
disable the access to MMU registers in userspace, then the userspace
application won't be able to map/unmap additional memory blocks, and the
app size would be limited to less then 64K?

Also in my opinion the stack too should be switched between these
supervisor/user states. I was thinking for something like "task id" or
"process id" which can uniquely identify the OS and userspace contexts
and their corresponding memory mappings (stack/code/data/io) and
protection bits. Hmm, is it possible to have only partially mapped user
address space and to generate page faults when accessing the unmapped
areas? I have a gut feeling that such implementation will overshadow
8086 for ugliest memory organization ever :).

Regards,
Nikolay
William R Sowerbutts
2014-07-02 09:26:25 UTC
Permalink
>>Also fiddling with external "protected mode" circuitry. This allows the CPU
>>to do an out instruction to disable access to I/O devices which is only
>>undone by NMI or the processor on the first instruction fetch after
>>fetching an instruction with the bitpattern 11XXX111 (RST instructions).
>I also thought on a similar idea for protection circuitry. But if you disable
>the access to MMU registers in userspace, then the userspace application
>won't be able to map/unmap additional memory blocks, and the app size would
>be limited to less then 64K?

The application code (running in "protected mode") would make a system call
when it wants to change the memory mapping. The privileged supervisor code
would then validate the requested mapping before applying it.

Will

_________________________________________________________________________
William R Sowerbutts will-***@public.gmane.org
"Carpe post meridiem" http://sowerbutts.com
main(){char*s=">#=0> ^#X@#@^7=",c=0,m;for(;c<15;c++)for
(m=-1;m<7;putchar(m++/6&c%3/2?10:s[c]-31&1<<m?42:32));}
Alan Cox
2014-07-02 09:55:45 UTC
Permalink
I'm interested in exploring what is possible with a Z80 and hardware of
the period - so minimal numbers of gates, believable technology and
implementable in hardware (and eventually I may try just that).

That as far as I can tell means you pretty much have to do the stack switch
in the RST handler. Bank switching is a bit easier - you could use the bit
only to gate some sections of the I/O logic. However that gets really
complicated really fast because you have to validate the MMU access is
allowed by the task. Easier to let the OS do it.

Page faulting recovery is also very very hard on the Z80 because you've not
got restartable instructions. If you fault in the middle of LDI exactly
what state are you in ?

I don't actually think you need page faulting and VM anyway. It's a 16bit
machine with >= 128K of RAM so it's not got an address space in excess of
memory size.

The big problem which would be useful to deal with but isn't really fixable
without modifying the CPU core (and thus cheating) would be split I/D - so
you get a different 64K bank mapping for code and for data access. While
the Z80 tells you the first cycle of an instruction fetch it doesn't tell
you any more than that.

A fully protected UZI or similar environment just needs the I/O protection,
IRQ via NMI and a way to get back into supervisor mode as far as I can
tell. Things like VM are just surplus to requirements.

Beyond that the only thing its valuable to have is a bit of granularity in
your memory mapping registers so that you can lock down a relatively small
chunk of low memory holding the RST handlers and the per process kernel
state that is not usually needed via another task. That avoids having to
keep all the task stacks mapped and makes a huge difference to memory space.

I'm sort of torn there between something clever and simply trying to
software work around a "classic" 4 x 16K bank model.

Alan

--
You received this message because you are subscribed to the Google Groups "N8VEM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to n8vem+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To post to this group, send email to n8vem-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
Visit this group at http://groups.google.com/group/n8vem.
For more options, visit https://groups.google.com/d/optout.
Nikolay Dimitrov
2014-07-02 10:31:34 UTC
Permalink
Hi Alan,

On 7/2/2014 12:55 PM, Alan Cox wrote:
> I'm interested in exploring what is possible with a Z80 and hardware
> of the period - so minimal numbers of gates, believable technology and
> implementable in hardware (and eventually I may try just that).
Sure.

> That as far as I can tell means you pretty much have to do the stack
> switch in the RST handler. Bank switching is a bit easier - you could
> use the bit only to gate some sections of the I/O logic. However that
> gets really complicated really fast because you have to validate the
> MMU access is allowed by the task. Easier to let the OS do it.
I would rather avoid disturbing the OS constantly for each and every
memory access. Would be better if the MMU contains a primitive policy to
control memory accesses.

> Page faulting recovery is also very very hard on the Z80 because
> you've not got restartable instructions. If you fault in the middle of
> LDI exactly what state are you in ?
Hmm, you're right. Haven't thought about restarting instructions... But
from another perspective, we can do it "almost the right way":
1. Allow partial address space mappings for the userspace.
2. Return 0x00 (NOP) for all non-mapped regions, so we trigger NMI and
still complete the current instruction execution.
3. Inform the OS that a non-mapped access occurred, with detailed info
about the misbehaving task. It's totally possible to just kill or
restart the task in such circumstance, what do you think?

> I don't actually think you need page faulting and VM anyway. It's a
> 16bit machine with >= 128K of RAM so it's not got an address space in
> excess of memory size.
Still, would be great to have some flexibility and handle 512KiB as the
current boards.

> The big problem which would be useful to deal with but isn't really
> fixable without modifying the CPU core (and thus cheating) would be
> split I/D - so you get a different 64K bank mapping for code and for
> data access. While the Z80 tells you the first cycle of an instruction
> fetch it doesn't tell you any more than that.
What will you achieve when splitting the instruction and data? Usually
(in Von-Neumann) I & D paths are split only because the 2 streams have
different access patterns and need different caches in the memory
hierarchy. If you provide 2 totally separate address spaces, that's
totally different topic, but I think this will be even more than a hack :D.

> A fully protected UZI or similar environment just needs the I/O
> protection, IRQ via NMI and a way to get back into supervisor mode as
> far as I can tell. Things like VM are just surplus to requirements.
But if you add memory address space protection between supervisor and
user modes, it will gain the same complexity, imho.

> Beyond that the only thing its valuable to have is a bit of
> granularity in your memory mapping registers so that you can lock down
> a relatively small chunk of low memory holding the RST handlers and
> the per process kernel state that is not usually needed via another
> task. That avoids having to keep all the task stacks mapped and makes
> a huge difference to memory space.
Yep. But this is a classic choice between "who has to handle the job" -
the kernel or the MMU. The cheapest approach is to have just 2 contexts,
kernel and user, which fully maps the logical address space to the
physical one. Then each time when the kernel decides to switch to
another task, it will have to load the new mapping in the MMU-user-part.
If the MMU supports enough SRAM for multiple mappings, the switching
between mappings can be only a write to a "task id" register, which is
connected to the MSB address lines to the MMU SRAM. But in general I'm
OK with either approach, as long as it works :).

> I'm sort of torn there between something clever and simply trying to
> software work around a "classic" 4 x 16K bank model.
Can you guys explain me why noone likes the idea of having smaller pages
for Z80, like 4KiB or 1KiB?

Regards,
Nikolay
Alan Cox
2014-07-02 11:18:52 UTC
Permalink
On Wed, Jul 2, 2014 at 11:31 AM, Nikolay Dimitrov <picmaster-***@public.gmane.org> wrote:

>
> .
>>
> I would rather avoid disturbing the OS constantly for each and every
> memory access. Would be better if the MMU contains a primitive policy to
> control memory accesses.
>
> You disturb it only when you switch banks - which shouldn't be often.


>
> Page faulting recovery is also very very hard on the Z80 because you've
>> not got restartable instructions. If you fault in the middle of LDI exactly
>> what state are you in ?
>>
> Hmm, you're right. Haven't thought about restarting instructions... But
> from another perspective, we can do it "almost the right way":
> 1. Allow partial address space mappings for the userspace.
>

Easy enough but you could also just map the same block repeatedly in all
the "banks" that are empty so a program only wees on itself.

3. Inform the OS that a non-mapped access occurred, with detailed info
> about the misbehaving task. It's totally possible to just kill or restart
> the task in such circumstance, what do you think?


Will's MMU can already generate an error on a forbidden access and you can
wire it to NMI although it isn't connected in the current SocZ80.


> What will you achieve when splitting the instruction and data? Usually (in
> Von-Neumann) I & D paths are split only because the 2 streams have


64K code + 64K data without having to bank switch.


> A fully protected UZI or similar environment just needs the I/O
>> protection, IRQ via NMI and a way to get back into supervisor mode as far
>> as I can tell. Things like VM are just surplus to requirements.
>>
> But if you add memory address space protection between supervisor and user
> modes, it will gain the same complexity, imho.


I don't think so, nothing of the same order.

>
>
> Yep. But this is a classic choice between "who has to handle the job" -
> the kernel or the MMU. The cheapest approach is to have just 2 contexts,
> kernel and user, which fully maps the logical address space to the physical
> one. Then each time when the kernel decides to switch to another task, it
> will have to load the new mapping in the MMU-user-part. If the MMU supports
> enough SRAM for multiple mappings, the switching between mappings can be
> only a write to a "task id" register, which is connected to the MSB address
> lines to the MMU SRAM. But in general I'm OK with either approach, as long
> as it works :).
>
>
> I'm sort of torn there between something clever and simply trying to
>> software work around a "classic" 4 x 16K bank model.
>>
> Can you guys explain me why noone likes the idea of having smaller pages
> for Z80, like 4KiB or 1KiB?
>

These two are closely related. On SocZ80 the CPU executes a lot of
instructions to do a bank switch. At 128MHz nobody notices. On a "classic"
4MHz CP/M Z80 board you execute something like 10 instructions with 4 16K
banks.

Four banks means four I/O writes to switch completely (3 for CP/M where the
top 16K is fixed). It requires a 2 input mux and four registers holding the
bank numbers, plus the relevant CPU glue to update them.

4K pages means you need a four input mux, 16 bank registers and it's a lot
more glue logic, especially before PAL, CPLD and ULA type devices were
available.

In some cases having a small number of banks also saved a lot of logic
because you could do dirty tricks with spare I/O device pins. For example
Grant Searle's Z80 'DIY' system has a pair of free lines on the Z80 SIO
which with a tiny bit more logic would be sufficient to implement bank
switching and using more of the RAM without having to implement all the
register setting but instead (ab)using the SIO to do the hard work. In fact
there were real systems that did exactly that. Something as simple as
A16 <= (A14 and A15 and SIOsparepin1) or SIOsparepin2 ought to do the trick.


"cost" is relative. With an FPGA gates are cheap (although as I keep
finding out the hard way - not in long chains at high speed), on a real
board, especially a historic one gates were expensive.


Alan

--
You received this message because you are subscribed to the Google Groups "N8VEM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to n8vem+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To post to this group, send email to n8vem-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
Visit this group at http://groups.google.com/group/n8vem.
For more options, visit https://groups.google.com/d/optout.
Nikolay Dimitrov
2014-07-02 11:31:15 UTC
Permalink
Hi Alan,

Thanks for the explanation, I appreciate it.

>
> On 7/2/2014 2:18 PM, Alan Cox wrote:
> On Wed, Jul 2, 2014 at 11:31 AM, Nikolay Dimitrov <picmaster-***@public.gmane.org
> <mailto:picmaster-***@public.gmane.org>> wrote:
>
> What will you achieve when splitting the instruction and data?
> Usually (in Von-Neumann) I & D paths are split only because the 2
> streams have
>
>
> 64K code + 64K data without having to bank switch.
>
Can you please elaborate on this? Do you mean converting the Z80 to
Harvard architecture with 2 entirely separate address spaces? I'm trying
to understand your idea.

Regards,
Nikolay

--
You received this message because you are subscribed to the Google Groups "N8VEM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to n8vem+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To post to this group, send email to n8vem-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
Visit this group at http://groups.google.com/group/n8vem.
For more options, visit https://groups.google.com/d/optout.
Alan Cox
2014-07-02 12:33:20 UTC
Permalink
It's what Digital did for the PDP-11. Basically instructions and constants
are fetched from one address space, but indirect accesses from another.
Effectively you have a 128K address space 64K of which is code, 64K of
which is data accessed by things like LD A, (44) or LD (HL), E

On the subject of MMUs the one mainstream 8bit processor which got a real
MMU product was the 6809 which could be connected to a 6829 MMU. It has one
must peculiar feature when you told the MMU to switch task you programmed
a "fuse" register with the number of cycles before the change occurred,
this meant you could for example synchronize an MMU change with a jump
instruction.

I did today learn about a design for a homebrew MMU for the 6502 that uses
4K pages and a 74160

http://www.6502.org/users/andre/icapos/mmu65.html

so perhaps 4K pages could have been done more easily than I thought - but
then - when was the 74LS160 released ?

Alan

--
You received this message because you are subscribed to the Google Groups "N8VEM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to n8vem+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To post to this group, send email to n8vem-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
Visit this group at http://groups.google.com/group/n8vem.
For more options, visit https://groups.google.com/d/optout.
Nikolay Dimitrov
2014-07-02 13:02:57 UTC
Permalink
Hi Alan,

Offtopic: Thanks for the link, I'll take a look at it. Btw, C64 was
released in 1982, and it actually used a PLA inside for glue logic.
That's around 6 years after 1976 (Z80 release year), so I think PLAs
were already known as a technology, albeit not cheap enough for mass
production before 1980-1982.

Regards,
Nikolay
Nikolay Dimitrov
2014-07-02 10:04:10 UTC
Permalink
Hi Will,

On 7/2/2014 12:26 PM, William R Sowerbutts wrote:
>>> Also fiddling with external "protected mode" circuitry. This allows the CPU
>>> to do an out instruction to disable access to I/O devices which is only
>>> undone by NMI or the processor on the first instruction fetch after
>>> fetching an instruction with the bitpattern 11XXX111 (RST instructions).
>> I also thought on a similar idea for protection circuitry. But if you disable
>> the access to MMU registers in userspace, then the userspace application
>> won't be able to map/unmap additional memory blocks, and the app size would
>> be limited to less then 64K?
> The application code (running in "protected mode") would make a system call
> when it wants to change the memory mapping. The privileged supervisor code
> would then validate the requested mapping before applying it.
Let me think about it for a second... The syscall can pass 8-bit ID to
the kernel to identify the system function to be called, but what about
the function arguments? Z80 registers won't be enough for any
non-trivial argument passing.
Maybe if the syscall-specific arguments are pushed on the user stack,
and the syscall function stores the stack top address (an userspace
address) into one of the 16-bit registers, and perform something like
NMI. The hardware circuitry should catch the interrupt, switch MMU
mappings, and provide to the OS information about the task which caused
the context switch, especially about the page where the stack is
located. Then syscall arguments can be read "somehow" from the userspace
stack (like the mechanism you implemented for reading/writing non-mapped
memory) and then the syscall can be validated/executed. So, I can only
agree with your idea :).

Gee, this circuitry starts to look like a MIPS coprocessor :).

Regards,
Nikolay
Alan Cox
2014-07-02 10:46:00 UTC
Permalink
Actually if you look at the classic Unix syscalls you need no more than 3
arguments for almost all of them and two registers for the returned
information. This is not co-incidence. Where blocks of data are transferred
an address is passed instead. The same is true of CP/M calls - they pass
very little information directly.

Again for simplicity I don't believe the hardware needs to tell the OS what
task was running. That's just a lot of extra gates (real or virtual) when
the OS already *knows* what task was running.

--
You received this message because you are subscribed to the Google Groups "N8VEM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to n8vem+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To post to this group, send email to n8vem-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
Visit this group at http://groups.google.com/group/n8vem.
For more options, visit https://groups.google.com/d/optout.
Nikolay Dimitrov
2014-07-02 11:09:52 UTC
Permalink
Hi Alan,

On 7/2/2014 1:46 PM, Alan Cox wrote:
> Actually if you look at the classic Unix syscalls you need no more
> than 3 arguments for almost all of them and two registers for the
> returned information. This is not co-incidence. Where blocks of data
> are transferred an address is passed instead. The same is true of CP/M
> calls - they pass very little information directly.
I don't have any experience with UNIX systems. Just checked for NetBSD
syscalls
here:http://ftp.netbsd.org/pub/NetBSD/NetBSD-current/src/sys/kern/syscalls.master
...and found at least several syscalls with 4-6 arguments (wait4, mount,
ptrace, recvfrom).

The situation is similar on Linux kernel, as seen here:
http://syscalls.kernelgrok.com/
...like sys_execve, sys_mount, sys_ptrace and others with more than 3
arguments. I'm not sure whether these would be essential for
Z80-specific OS, just mentioning it.

> Again for simplicity I don't believe the hardware needs to tell the OS
> what task was running. That's just a lot of extra gates (real or
> virtual) when the OS already *knows* what task was running.
Sure. But if you look from another perspective, you can consider a
register the 1 bit for switching between supervisor and user mappings.
It's just a matter of having a bigger register to refer to more tasks
(if needed, of course), that's what I meant. Btw, regarding simplicity -
I think that unless the MMU "RAM" (be it FFs or SRAM) is dual-ported,
we'll have hard times to update mappings without addressing/activating them.

Regards,
Nikolay
James Moxham
2014-07-02 10:27:32 UTC
Permalink
Is there a way of doing this in C?

Thinking back to say, the early to mid 1980s as memory went past 64k, were
there changes to the C language that allowed larger programs?

Is there something by any chance in z88dk eg, you write a little assembly
routine to handle mmu calls, and in return, it allows >64k programs to be
written without having to think about memory management.

I know something similar was discussed at length on the propeller forums
(the propeller has 32k) and there are all sorts of memory models now
available to use external parallel ram, serial ram, and even flash cards
or an sd card to write large programs.

And yes, I agree it would be better if this were a system call.

btw Will, I tried running your post nominal program on the fpga board - it
compiles and runs fine but it just prints out a series of **** symbols. Or
are these obfuscated too?!





On Wed, 02 Jul 2014 18:56:25 +0930, William R Sowerbutts
<will-***@public.gmane.org> wrote:

>>> Also fiddling with external "protected mode" circuitry. This allows
>>> the CPU
>>> to do an out instruction to disable access to I/O devices which is
>>> only
>>> undone by NMI or the processor on the first instruction fetch after
>>> fetching an instruction with the bitpattern 11XXX111 (RST
>>> instructions).
>> I also thought on a similar idea for protection circuitry. But if you
>> disable
>> the access to MMU registers in userspace, then the userspace application
>> won't be able to map/unmap additional memory blocks, and the app size
>> would
>> be limited to less then 64K?
>
> The application code (running in "protected mode") would make a system
> call
> when it wants to change the memory mapping. The privileged supervisor
> code
> would then validate the requested mapping before applying it.
>
> Will
>
> _________________________________________________________________________
> William R Sowerbutts will-***@public.gmane.org
> "Carpe post meridiem" http://sowerbutts.com
> main(){char*s=">#=0> ^#X@#@^7=",c=0,m;for(;c<15;c++)for
> (m=-1;m<7;putchar(m++/6&c%3/2?10:s[c]-31&1<<m?42:32));}
Nikolay Dimitrov
2014-07-02 10:38:48 UTC
Permalink
Hi James,

On 7/2/2014 1:27 PM, James Moxham wrote:
> Is there a way of doing this in C?
>
> Thinking back to say, the early to mid 1980s as memory went past 64k,
> were there changes to the C language that allowed larger programs?
As far as I know, there was a mechanism called "overlays". The following
explanation is far better than I could do:

http://en.wikipedia.org/wiki/Overlay_%28programming%29

Regards,
Nikolay
Alan Cox
2014-07-02 10:57:51 UTC
Permalink
Three things happened

1. Sensible people designed proper 32bit processors (eg DEC VAX, Motorola
68K etc)

2. Overlays as has been mentioned

3. "Smart" C compilers. In particular for code some of the smarter C
compilers for Z180 could be told to put functions into blocks and do calls
between them differently. Some compilers would do this automatically (which
has a performance cost) others by hand guidance. Sometimes the linker would
fix it up.

A typical arrangement was to make all the C functions expect the arguments
to start one word further one. When making a call the compiler would push
an additional dummy value and then call the function.

The linker would fix up calls between blocks by replacing the

CALL function

with

CALL _far_function_0 ; generated stub to call "function" and return
to bank 0

which in turn would manipulate the stack by putting the real return address
into the dummy slot, switching bank, calling the function, switching back,
recovering the correct return address, and returning

Much slower but it worked.

There were a collection of different schemes of this type and several of
the proprietary Z180 compilers supported them for embedded use.

Data is much harder to handle but some compilers (including SDCC) have
extensions that allow you to specify what bank some data lives in and how
to access the bank. The compiler makes an effort to do minimal switching of
banks.

For efficiency overlays are usually the winner, and most portable. Some of
the compilers could also generate a lot of the overlay hooks for you and
the pieces to make sure the right overlay was loaded when you made a call.
It was however up to you to get the correct functions together in the same
overlay so your program didn't spend all day copying bits off disk.

--
You received this message because you are subscribed to the Google Groups "N8VEM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to n8vem+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To post to this group, send email to n8vem-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
Visit this group at http://groups.google.com/group/n8vem.
For more options, visit https://groups.google.com/d/optout.
Loading...