Discussion:
[Simh] pdp11 i/o addressing
Mike Stramba
2018-02-16 15:05:06 UTC
Permalink
Greetings,

I'm trying to figure out how console I/O works with the PD11.

Or more generally I/O addressing

E.g.
A "sh TTO" gives :

TTO, address=17777564-17777567, vector=64, 7p

And 17777564 (octal) is 4,194,164 dec, which is obviously out of range
of the 64K addressable by any MOV instruction.

But various diagnostic routines, e.g. below, are using
movb rX,@#177566 ; output to console

https://www.ak6dn.com/PDP-11/M9312/23-248F1/23-248F1.mac

Are I/O devices always at the "top 64k" of memory ?

If so, why doesn't SH DEV display :

xxx xxx-177 777 ?

Mike
Paul Koning
2018-02-16 15:15:28 UTC
Permalink
Mike,

You should get yourself a good intro to the PDP-11, for example one of the PDP-11 Processor Handbook copies you can find on Bitsavers. It answers that question and many others.

The key point is that you have to distinguish virtual addresses from physical ones. The I/O device addresses are physical addresses. The program uses virtual addresses. Physical addresses can be 16, 18, or 22 bits depending on the model; virtual addresses are always 16 bits.

The power on default mapping is that physical addresses 0-157777 map to physical addresses with leading zeroes; virtual addresses 160000 and up map to physical adddresses with leading ones. So, for example,

mov #101, @#177566

moves the value 0101 (decimal 65, the ASCII code for "A") to physical address 17 777 566 which should result in A appearing on the console output.

On machines with an MMU (which is most of them) the mapping from virtual to physical can be changed, and for example the "I/O page" (top 4kW of physical memory) might not be accessible. But by universal software convention, in kernel mode 160000 and up (MMU page 7) are always mapped to the physical I/O page address range.

paul
Post by Mike Stramba
Greetings,
I'm trying to figure out how console I/O works with the PD11.
Or more generally I/O addressing
E.g.
TTO, address=17777564-17777567, vector=64, 7p
And 17777564 (octal) is 4,194,164 dec, which is obviously out of range
of the 64K addressable by any MOV instruction.
But various diagnostic routines, e.g. below, are using
https://www.ak6dn.com/PDP-11/M9312/23-248F1/23-248F1.mac
Are I/O devices always at the "top 64k" of memory ?
xxx xxx-177 777 ?
Mike
_______________________________________________
Simh mailing list
http://mailman.trailing-edge.com/mailman/listinfo/simh
Clem Cole
2018-02-16 15:34:32 UTC
Permalink
+1 Paul's comments

some resources - cut and pasted from a message to a young
engineer/mentee/student I have at the moment ;-)

PDP11 Processor Handbook 1979
<http://bitsavers.trailing-edge.com/pdf/dec/pdp11/handbooks/PDP11_Handbook1979.pdf>

AA-5075A-TC PDP-11 MACRO-11 Language Reference Manual (RT-11)
<http://www.bitsavers.org/www.computer.museum.uq.edu.au/RT-11/AA-5075A-TC%20PDP-11%20MACRO-11%20Language%20Reference%20Manual.pdf>

$5 used on Amazon: https://www.amazon.com/Introduction-Assembly-
Language-Prentice-Hall-software/dp/0134917049



ᐧ
Post by Paul Koning
Mike,
You should get yourself a good intro to the PDP-11, for example one of the
PDP-11 Processor Handbook copies you can find on Bitsavers. It answers
that question and many others.
The key point is that you have to distinguish virtual addresses from
physical ones. The I/O device addresses are physical addresses. The
program uses virtual addresses. Physical addresses can be 16, 18, or 22
bits depending on the model; virtual addresses are always 16 bits.
The power on default mapping is that physical addresses 0-157777 map to
physical addresses with leading zeroes; virtual addresses 160000 and up map
to physical adddresses with leading ones. So, for example,
moves the value 0101 (decimal 65, the ASCII code for "A") to physical
address 17 777 566 which should result in A appearing on the console output.
On machines with an MMU (which is most of them) the mapping from virtual
to physical can be changed, and for example the "I/O page" (top 4kW of
physical memory) might not be accessible. But by universal software
convention, in kernel mode 160000 and up (MMU page 7) are always mapped to
the physical I/O page address range.
paul
Post by Mike Stramba
Greetings,
I'm trying to figure out how console I/O works with the PD11.
Or more generally I/O addressing
E.g.
TTO, address=17777564-17777567, vector=64, 7p
And 17777564 (octal) is 4,194,164 dec, which is obviously out of range
of the 64K addressable by any MOV instruction.
But various diagnostic routines, e.g. below, are using
https://www.ak6dn.com/PDP-11/M9312/23-248F1/23-248F1.mac
Are I/O devices always at the "top 64k" of memory ?
xxx xxx-177 777 ?
Mike
_______________________________________________
Simh mailing list
http://mailman.trailing-edge.com/mailman/listinfo/simh
_______________________________________________
Simh mailing list
http://mailman.trailing-edge.com/mailman/listinfo/simh
Mike Stramba
2018-02-16 15:44:45 UTC
Permalink
Thanks Guys.

I *had* downloaded a handbook... but it was the *oldest* one (1969)
;), hence no mention of virtual memory in it ;)

Mike
Post by Clem Cole
+1 Paul's comments
some resources - cut and pasted from a message to a young
engineer/mentee/student I have at the moment ;-)
PDP11 Processor Handbook 1979
<http://bitsavers.trailing-edge.com/pdf/dec/pdp11/handbooks/PDP11_Handbook1979.pdf>
AA-5075A-TC PDP-11 MACRO-11 Language Reference Manual (RT-11)
<http://www.bitsavers.org/www.computer.museum.uq.edu.au/RT-11/AA-5075A-TC%20PDP-11%20MACRO-11%20Language%20Reference%20Manual.pdf>
$5 used on Amazon: https://www.amazon.com/Introduction-Assembly-
Language-Prentice-Hall-software/dp/0134917049

Post by Paul Koning
Mike,
You should get yourself a good intro to the PDP-11, for example one of the
PDP-11 Processor Handbook copies you can find on Bitsavers. It answers
that question and many others.
The key point is that you have to distinguish virtual addresses from
physical ones. The I/O device addresses are physical addresses. The
program uses virtual addresses. Physical addresses can be 16, 18, or 22
bits depending on the model; virtual addresses are always 16 bits.
The power on default mapping is that physical addresses 0-157777 map to
physical addresses with leading zeroes; virtual addresses 160000 and up map
to physical adddresses with leading ones. So, for example,
moves the value 0101 (decimal 65, the ASCII code for "A") to physical
address 17 777 566 which should result in A appearing on the console output.
On machines with an MMU (which is most of them) the mapping from virtual
to physical can be changed, and for example the "I/O page" (top 4kW of
physical memory) might not be accessible. But by universal software
convention, in kernel mode 160000 and up (MMU page 7) are always mapped to
the physical I/O page address range.
paul
Post by Mike Stramba
Greetings,
I'm trying to figure out how console I/O works with the PD11.
Or more generally I/O addressing
E.g.
TTO, address=17777564-17777567, vector=64, 7p
And 17777564 (octal) is 4,194,164 dec, which is obviously out of range
of the 64K addressable by any MOV instruction.
But various diagnostic routines, e.g. below, are using
https://www.ak6dn.com/PDP-11/M9312/23-248F1/23-248F1.mac
Are I/O devices always at the "top 64k" of memory ?
xxx xxx-177 777 ?
Mike
_______________________________________________
Simh mailing list
http://mailman.trailing-edge.com/mailman/listinfo/simh
_______________________________________________
Simh mailing list
http://mailman.trailing-edge.com/mailman/listinfo/simh
Ethan Dicks
2018-02-16 16:06:03 UTC
Permalink
Post by Mike Stramba
Thanks Guys.
I *had* downloaded a handbook... but it was the *oldest* one (1969)
;), hence no mention of virtual memory in it ;)
Yeah, Once you get to anything with an 18-bit Unibus, there's a distinction.

What's sometimes hard to get used to is for the PDP-11, virtual space
is *smaller* than physical space. Virtual space is 64K. Physical
space can be up to 4MB depending on the model.

I started on a VAX with 2MB of physical memory in a 16MB physical
address space but with 4GB virtual addresses. Switching over to the
PDP-11 was odd from that.

-ethan
Clem Cole
2018-02-16 19:51:27 UTC
Permalink
curmudgeon warning below.....
Post by Ethan Dicks
I started on a VAX with 2MB of physical memory in a 16MB physical
address space but with 4GB virtual addresses. Switching over to the
PDP-11 was odd from that.
​Sigh... I fear that is a fault of your education.

If you ask many (younger) programmers what VM was designed to solve
(particularly those that never memory constrained systems such as you get
in 8, 12, 16 or 18 bit processors), they will tell you 'So can have more
addressable memory.'​ The problem is said programmers never experienced or
learned about overlays. Conceptually, a PDP-11 can allow a lot more than
the 64Ks physical limit by 'swapping out' and 'overlaying parts' and
calling subroutines through 'thunks' [which to quote my old friend Paul
Hilfinger from page 427 of his book: *"an onomatopoetic reference to the
sound made by a pointer as it moves instantaneously up and down the stack"*].
A process has be allowed to be larger that 64K, but only 64K (128K on
seperate I/D systems) in the set up memory maps at a time. If you need
to call a subroutine to (optionally) bring in the routines and its data
into memory if it is not already there, and then set up the map to point
the routine in question.

BTW: If you play with BSD 2.11 or the like, it uses overlays to allow
programs to grow in size. This was needed as people started to try to
move features from 4BSD and later back to the PDP-11. At this point, I
believe you must have what was sometimes referred too as '17th address bit
- i.e. I/D space which gives you 128K bytes of mapped in memory at a time.
But you can (with care) let you programs grow.

The point is that VM is a mechanism* to automatically manage overlays*.
The implementation of this management gets easier if there are more
address bits than physical address bit, but that is the key item that is
happening.

Sadly, since people stopped learning about overlay management, the context
of what it was doing under the covers was lost.

Clem


ᐧ
Bob Eager
2018-02-16 20:23:05 UTC
Permalink
On Fri, 16 Feb 2018 14:51:27 -0500
Post by Clem Cole
curmudgeon warning below.....
Post by Ethan Dicks
I started on a VAX with 2MB of physical memory in a 16MB physical
address space but with 4GB virtual addresses. Switching over to the
PDP-11 was odd from that.
?Sigh... I fear that is a fault of your education.
If you ask many (younger) programmers what VM was designed to solve
(particularly those that never memory constrained systems such as you
get in 8, 12, 16 or 18 bit processors), they will tell you 'So can
have more addressable memory.'? The problem is said programmers
never experienced or learned about overlays. Conceptually, a PDP-11
can allow a lot more than the 64Ks physical limit by 'swapping out'
and 'overlaying parts' and calling subroutines through
'thunks' [which to quote my old friend Paul Hilfinger from page 427
of his book: *"an onomatopoetic reference to the sound made by a
pointer as it moves instantaneously up and down the stack"*]. A
process has be allowed to be larger that 64K, but only 64K (128K on
seperate I/D systems) in the set up memory maps at a time. If you
need to call a subroutine to (optionally) bring in the routines and
its data into memory if it is not already there, and then set up the
map to point the routine in question.
BTW: If you play with BSD 2.11 or the like, it uses overlays to allow
programs to grow in size. This was needed as people started to try
to move features from 4BSD and later back to the PDP-11. At this
point, I believe you must have what was sometimes referred too as
'17th address bit
- i.e. I/D space which gives you 128K bytes of mapped in memory at a
time. But you can (with care) let you programs grow.
The point is that VM is a mechanism* to automatically manage
overlays*. The implementation of this management gets easier if there
are more address bits than physical address bit, but that is the key
item that is happening.
Sadly, since people stopped learning about overlay management, the
context of what it was doing under the covers was lost.
When I teach virtual memory, I start by talking about the 'old days'
and overlays. I remember Overlay Description Language on the PDP-11!
Timothe Litt
2018-02-16 21:15:28 UTC
Permalink
Post by Clem Cole
curmudgeon warning below.....
I started on a VAX with 2MB of physical memory in a 16MB physical
address space but with 4GB virtual addresses.  Switching over to the
PDP-11 was odd from that.
​Sigh... I fear that is a fault of your education.  
If you ask many (younger) programmers what VM was designed to solve
(particularly those that never memory constrained systems such as you
get in 8, 12, 16 or 18 bit processors), they will tell you 'So can
have more addressable memory.'​  The problem is said programmers never
experienced or learned about overlays.   Conceptually, a PDP-11 can
allow a lot more than the 64Ks physical limit by 'swapping out' and
'overlaying parts' and calling subroutines through 'thunks' [which to
quote my old friend Paul Hilfinger from page 427 of his book:  /"an
onomatopoetic reference to the sound made by a pointer as it moves
instantaneously up and down the stack"/].  A process has be allowed to
be larger that 64K, but only 64K (128K on seperate I/D systems) in the
set up memory maps at a time.    If you need to call a subroutine to
(optionally) bring in the routines and its data into memory if it is
not already there, and then set up the map to point the routine in
question.
BTW: If you play with BSD 2.11 or the like, it uses overlays to allow
programs to grow in size.   This was needed as people started to try
to move features from 4BSD and later back to the PDP-11.   At this
point, I believe you must have what was sometimes referred too as
'17th address bit - i.e. I/D space which gives you 128K bytes of
mapped in memory at a time.    But you can (with care) let you
programs grow.   
The point is that VM is a mechanism/to automatically manage
overlays/.   The implementation of this management gets easier if
there are more address bits than physical address bit, but that is the
key item that is happening.
You have to pick a frame of reference.  There were overlays before VM. 
But people may have experience VM before overlays, or vice-versa.  It is
true that overlays aren't well known or understood by the younger crowds.

But, your observation that "VM is a mechanism/to automatically manage
overlays/" is an over-simplification.

Overlays were used to compensate for limited virtual address space.  VM
expands the limit.  But, more than that, it does it more efficiently
than overlays.  Overlays generally are implemented in user mode by a
linker (task builder).  They are not visible to the OS, so limit
sharing.  In addition, they force code (in the overlay areas) to be
writable.  And the overlay loader (invoked by thunks) makes
cross-overlay calls considerably more expensive than an ordinary call -
even when the target call is frequent.  They work better for code than
for data; identifying & swapping out writable data in user mode for an
overlay is non-trivial.  (Sane overly systems didn't encourage this.) 
Although there were some attempts to automate generating an overlay
structure, getting reasonable performance requires a lot of analysis and
programmer effort.  This grows (at least) exponentially as the size and
complexity of a program grows and the overlay structure moves from a
partition or two to a tree structure.  And worse with writable overlays.

VM expands the address space *more efficiently*.  The OS knows about it;
sharing is more efficient; code can be read-only.  Physical memory can
be used for caching recently used pages, reducing I/O.  And a programmer
can do less (not to be confused with no) work.

Overlays had a place - but VM does a lot more than automatically manage
them.   It provides much finer granularity than is practical for
overlays, does so more efficiently (at both the application and system
level), and used thoughtfully saves programmer effort.  Overlays are, in
many respects, a "poor man's VM".  When you don't have paging hardware,
overlays can do a  lot.  But at a steep price.  Initially, paging
hardware wasn't cheap, neither was the OS complexity to implement it
well.  And it took a long time to figure out how to do it well.  (Er,
well enough.  We're still learning.)

That said, VM used carelessly can perform much, much worse than an
overlay structure.  An early version of an operating that I won't name
decided that "everything is a page fault".  Including disk I/O.  So to
run a program, you associated it with an address space, and - well. Page
fault reading the start address.  PF reading the instruction at the
start address.  PF reading the operand of the instruction at the start
address.... It was academically beautiful - but hopelessly
non-performant.  As were programs that figured that since memory is
free, might as well allocate GB sparse arrays.

I remember when VAX's 32-bit VM was supposed to be "infinite" and
overlays "obsolete"; divided into 4 segments, it didn't take long before
1GB was "too small", and thoughts of overlays had a brief resurgence. 

Still, I miss telling Link-10 to provide a plot (on a drum pen plotter)
of the overlay structure of a really big program, like SPSS.  It could
tell you a lot about how the developer thought it worked.

I don't miss the RSX-11/TKB overlays, even though they did force
programmers to think about their code.

And I cede curmudgeon points and status to no one :-)

("Thunk" is also used for the code used in call by name - which has
another hollow sound.)
Post by Clem Cole
Sadly, since people stopped learning about overlay management, the
context of what it was doing under the covers was lost.
Clem
Paul Koning
2018-02-16 22:09:20 UTC
Permalink
Date: Fri, 16 Feb 2018 16:15:28 -0500
Overlays were used to compensate for limited virtual address space.
ITYM "Overlays were used to compensate for limited address space."
I first encountered the notion of overlays in IBM 1401 and System/360 programs.
Neither computer had any notion of virtual memory, virtual addressing, memory
mapping, or any such hoohah. You had the memory you were given, and that was
most decidedly that.
There was virtual addressing in early systems without hardware help. The famous THE operating system (mid 1960s) uses virtual addressing, with 27 bit virtual addresses which are mapped by a page table to 16 bit physical addresses. Addressing of virtually addressed object is done by way of subroutines, which works because the compiler makes it so. And as in many other VM systems, virtual memory is used for buffering I/O, for shared libraries, for user code and data, and so on. There's a bunch of nice analysis in the design to deal with deadlock concerns and resource starvation problems; the papers are in the "EWD archives", the collected archives of Dijkstra.

paul
Johnny Billquist
2018-02-17 13:15:00 UTC
Permalink
And an even stronger curmudgeon warning here then.

If people today claim that VM was designed to solve the problem of
having more addressable memory, they are utterly confused, as VM don't
give you any more addressable memory. Addressable memory is limited by
the size of an address in the CPU, and that does not change with or
without virtual memory. Now, physical address space on a machine in the
end is usually different than the size of an address in the CPU, but
that is handled by external hardware, such as MMUs, and does not change
how much addressable memory you have. And with MMUs, or other hardware
devices, you can change how much physical memory is on a machine, but it
don't change how much memory you can address in your virtual memory.

Furthermore, if you think that VMs purpose is to automatically manage
overlays, you are also totally confused about what VM is.

To all your defenses, this is not an uncommon confusion, but really is a
conflation of two different mechanisms and concepts.

First of all we have VM, which is virtual memory (we're not talking
about virtual machines here...). The idea is that this gives your
process the appearance that you have the full memory range, and it is
private to you. That is, you have address 0 (or whatever address), and
that appears to be a memory location where you can store data. Another
process can also refer to address 0, but it will not be the same address
0 as your process has. Each process has its own (full) memory space, and
it is unique and private. Unix, or RSX, or RSTS/E, or whatever on a
PDP-11 have virtual memory. The MMU is the device that then translates
your virtual address to a physical address, and from there you get some
actual storage for your virtual memory. Of course, your virtual address
might also not translate to any physical storage at all, at a given
time. On machines with a rather small virtual address space, but a large
physical address space, it usually makes enough sense to either have all
your memory mapped, or none of it. And when it is not mapped, it might
not be in memory at all, that is, it is swapped out. Swapping in and out
is reasonably cheap on these systems, so that you don't have much need
to implement anything more advanced. And with reasonably cheap I mean
that reading or writing the whole virtual memory to and from disk can be
done in a reasonable time, and having the full virtual memory of a
process mapped to physical memory will not allocate too much physical
memory on the machine.

Now, if the virtual memory space is large, and/or the physical memory is
small(ish) compared to virtual memory, then swapping becomes
impractical, or not even feasible. This is where then second concept
most people think about comes in: demand paging. Demand paging solves
both the problem with not having enough physical memory to back up the
full virtual address space, and having large enough virtual memory that
reading and writing the full virtual memory space would take
unreasonable amounts of time. With demand paging, only the actual memory
pages that you refer to, or need, will be read from disk into memory
when the process is running. Note that this is commonly used in
combination with virtual memory. So that each process still has its own
full, private address space. However, not all of the virtual memory is
necessarily backed by physical memory at a given point in time. Only
some select parts are. All other parts of your virtual memory is flagged
as not having a mapping to physical memory, and any reference to
unmapped addresses will cause a page fault, which will make the OS read
in the required page of memory from disk into some part of physical
memory, and set up the MMU to map those virtual addresses to physical
addresses at that point. Other parts will still be unmapped, and this
page could potentially also be dropped again without the rest of the
process being wiped out from physical memory. But the virtual memory
still exists.

Which then leads me to overlays. Where does overlays fit into this?
Well, if you look at it, what overlays is is a mechanism for reading in
only parts of memory when it actually is needed, and having it reside in
the same virtual address space as other parts of the code (if we have a
machine totally without virtual memory, overlays can of course also be
used directly on the physical address space, works the same way). And
other parts of the code might be wiped out because of demand for some
other code, which uses the same memory. But if you look at what this
implies, it should be obvious that overlays really are a user level
implementation doing the same thing as demand paging does. It has
nothing really to do with virtual memory. Demand paging does it to
reduce the amount of physical memory needed, while overlays does it to
reduce the amount of virtual memory needed (if you have virtual memory)
or the amount of physical memory (if you don't have virtual memory). But
overlays as such have nothing to do with virtual memory as such. Virtual
memory is just the memory your process has. Overlays just make use of
your virtual memory, without even being aware that it is virtual.

Johnny
Post by Clem Cole
curmudgeon warning below.....
I started on a VAX with 2MB of physical memory in a 16MB physical
address space but with 4GB virtual addresses.  Switching over to the
PDP-11 was odd from that.
​Sigh... I fear that is a fault of your education.
If you ask many (younger) programmers what VM was designed to solve
(particularly those that never memory constrained systems such as you
get in 8, 12, 16 or 18 bit processors), they will tell you 'So can have
more addressable memory.'​  The problem is said programmers never
experienced or learned about overlays.   Conceptually, a PDP-11 can
allow a lot more than the 64Ks physical limit by 'swapping out' and
'overlaying parts' and calling subroutines through 'thunks' [which to
quote my old friend Paul Hilfinger from page 427 of his book: /"an
onomatopoetic reference to the sound made by a pointer as it moves
instantaneously up and down the stack"/].  A process has be allowed to
be larger that 64K, but only 64K (128K on seperate I/D systems) in the
set up memory maps at a time.    If you need to call a subroutine to
(optionally) bring in the routines and its data into memory if it is not
already there, and then set up the map to point the routine in question.
BTW: If you play with BSD 2.11 or the like, it uses overlays to allow
programs to grow in size.   This was needed as people started to try to
move features from 4BSD and later back to the PDP-11.   At this point, I
believe you must have what was sometimes referred too as '17th address
bit - i.e. I/D space which gives you 128K bytes of mapped in memory at a
time.    But you can (with care) let you programs grow.
The point is that VM is a mechanism/to automatically manage overlays/.
 The implementation of this management gets easier if there are more
address bits than physical address bit, but that is the key item that is
happening.
Sadly, since people stopped learning about overlay management, the
context of what it was doing under the covers was lost.
Clem

_______________________________________________
Simh mailing list
http://mailman.trailing-edge.com/mailman/listinfo/simh
--
Johnny Billquist || "I'm on a bus
|| on a psychedelic trip
email: ***@softjar.se || Reading murder books
pdp is alive! || tryin' to stay hip" - B. Idol
Loading...