home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.whtech.com
/
ftp.whtech.com.tar
/
ftp.whtech.com
/
Geneve
/
9640news
/
CAT24
/
MMRY9640.ARK
< prev
next >
Wrap
Text File
|
2006-10-19
|
14KB
|
405 lines
?
THE FOLLOWING DOCUMENT (C) Copyright 1988, Paul Charlton, ALL RIGHTS RESERVED
================================================================================
= memory management:
================================================================================
definitions:
page: 8k bytes of memory, addressed by the 13 least significant address bits
execution page: these are numbered 0 to 7, indexed solely by the
3 most significant bits of the cpu's address
physical page: these are numbered from 0 to 255
function of the mapper: to translate an execution page into a physical page
example:
EXECUTION ADDRESS: eee iiiii iiiiiiii 64 Kbyte range
/ |
v |
mapper |
| |
v v
PHYSICAL ADDRESS: p pppp ppp iiiii iiiiiiii 2 Mbyte range
"eee" is the execution page
"pppppppp" is the physical page
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
in our case:
local page = virtual page
virtual addressing: a method of allowing a task to access more memory than
is directly accessible through the address bits
of the CPU. allowing a task to own more physical pages
than the 8 execution pages which are directly accessible
through the mapper
in the mapping of MDOS, the execution pages for a task are a subset of the
virtual pages belonging to the task.
for each task, MDOS maintains a list of physical pages which can be used
by the task. If the pages in this list are numbered, beginning with 0, the
number assigned to each position in the list is the same as the virtual
page number within the task. The list is allowed to have holes it, which
correspond to no physical page.
An example of the virtual page list maintained by MDOS for a task
with 128k of memory:
physical page numbers:
>3f >3e >3d >b8 >b8 >b8 >b8 >3c >3b >3a >39 >38 >37 >36 >35 >34
virtual (local) page numbers:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
<--- HOLE ----> (physical page >b8 does not correspond
to any device which can be located in the
PE BOX )
the virtual address is:
>2000 * (virtual page number) + ( index into page <13 bits> )
note: the virtual page list is limited to 256 bytes in length. therefore,
no task may have more than 2 Mbyte of virtual memory
since this task has a hole containing 4 pages, it really only uses 96k
of physical memory, even though it has 128k of virtual memory.
*** this example is the basis of the examples which follow ***
memory mangement opcodes:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#0 this returns the number of unassigned physical pages in the system
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#1 this routines allows you to fill holes in your virtual
page list, it will also create a new hole if the first page
you are allocating has a higher virtual page number than
any which have been previously assigned.
in the above example, if this routine were passed the arguments:
r1=2 # of pages to get
r2=4 Virtual page #
r3=don't care
then the routine would take unassigned physical pages
(if available) and assign them to virtual pages #4 & #5
creating a virtual page map like:
physical page numbers:
>3f >3e >3d >b8 >33 >32 >b8 >3c >3b >3a >39 >38 >37 >36 >35 >34
virtual (local) page numbers:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| |
<hole> <hole>
the routine could create a new hole if you gave it arguments like:
r1=1
r2=17
r3=don't care
results:
physical page numbers:
>3f >3e >3d >b8 >b8 >b8 >b8 >3c >3b >3a >39 >38 >37 >36 >35 >34 >b8 >33
virtual (local) page numbers:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
<---- hole ------> <hole>
notice that this routine only _fills_ holes, it does not assign
a new physical page to a virtual page which is already assigned
example:
r1=5
r2=1
r3=don't care
results:
physical page numbers:
>3f >3e >3d >33 >32 >31 >b8 >3c >3b >3a >39 >38 >37 >36 >35 >34
virtual (local) page numbers:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
<--- 5 pages ---> |
<had><new pages ><hole>
notice that the arguments asked for 5 pages, but only 3 were actually
assigned, since two of the target pages had already been assigned
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#2 this routine releases pages which have been assigned to the
virtual address space of a task, thus creating holes in the list
it also ensures that there is no hole at the end of the list which
is not followed by an assigned page
note: you can not release page #0 (it isn't really owned by the task,
it belongs to MDOS and is also the "header" page for the task)
arguments:
r1=9
r2=2
results:
physical page numbers:
>3f >3e >b8 >b8 >b8 >b8 >b8 >b8 >b8 >b8 >b8 >38 >37 >36 >35 >34
virtual (local) page numbers:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
note that some of the pages released were already unassigned, this is
quite ok...
arguments:
r1=10
r2=12
physical page numbers:
>3f >3e >3d >b8 >b8 >b8 >b8 >3c >3b >3a >39 >38
virtual (local) page numbers:
0 1 2 3 4 5 6 7 8 9 10 11
the list was truncated, since all of the pages at the tail of the list
were unassigned. Also note that we really told it to release
pages 12 to 21, but we only had pages up to 15 to begin with...this is
ok.
arguments:
r1=12
r2=2
physical page numbers:
>3f >3e >b8 >b8 >b8 >b8 >b8 >b8 >b8 >b8 >b8 >b8 >b8 >b8 >35 >34
virtual (local) page numbers:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
<--- giant hole ------------------------------>
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#3 map a virtual page into the execution (cpu visible) address space
arguments:
r1=virtual page number (index into list of physical pages)
r2=execution page number (index into the mapper)
physical page numbers:
>3f >3e >3d >b8 >b8 >b8 >b8 >3c >3b >3a >39 >38 >37 >36 >35 >34
virtual (local) page numbers:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
mapper:
>3f >b8 >b8 >b8 >b8 >b8 >b8 >b8
example arguments:
r1=14
r2=2
result---new contents of mapper:
>3f >b8 >35 >b8 >b8 >b8 >b8 >b8
|
virtual page # 14 is now located at >4000 (cpu address)
another way to see this is to say that data at a virtual address of
>0001_c000 is addressable at >4000
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#4 return a list of virtual pages
r1= execution address at which to place the list
r2= length reserved for list
you'll get an error code if the list is longer than the reserved area
returns ( *R2 ), physical pages numbers:
>3f >3e >3d >b8 >b8 >b8 >b8 >3c >3b >3a >39 >38 >37 >36 >35 >34
getting such a list is useful if your application does
_lots_ of paging around to get at the data it needs to use.
it is quite useful if your application also needs to use
pointers longer than 16 bits to maintain some complex data
structure, if you are maintaining 32 bit pointers, here is
how to get at the data addressed by the pointer:
assume: r1,r2 = 32 bit pointer, @paglst are bytes from opcode #4
movb r2,r1 ok, since only low 5 bits of r1 are used
andi r1,>e01f keep 8 bits, zap the others
src r1,13 rotate them to make an index into the page list
andi r2,>1fff mask off the high three bits, they're now
* in R1 ...
*
movb @paglst(r1),@mapper+4 put it at >8000
movb @paglst+1(r1),@mapper+5 put next page at >a000
*
* it is not necessary to place two pages into the mapper if you
* know for certain that the record accessed by the pointer does not
* cross page boundaries, the above code is just a method of playing it
* safe
*
mov @>8000+field_offset(r2),r3
*
* this of course assumes that there is some record addressed by the
* initial pointer, and that the record contains fields of some
* data structure. fields are easy to set up with a DORG statement
* for each record type in use by an application
*
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#5 declare shared pages
any task may declare a subset of its virtual address space to be
"shared"
each set of shared pages is given a "type" so that other applications
can later assign a certain "type" of shared pages into their
virtual address spage without knowlege of which physical pages
belong to a "shared" group
it is recommended that "types" be assigned by the distributor of MDOS,
so that incompatible applications do not try to use the same "type"
if you decide to use a "type" please correspond with the distributor
of MDOS to coordinate your development efforts with others.
a "shared" type may only be declared once, and always resides in a group
of consecutive virtual pages. If all applications using a "shared"
group of pages release those pages, the "type" may be redeclared
(MDOS keeps a count of the number of applications using a shared group,
and if the count ever becomes zero, the type is made free for re-use)
*** it is not possible to declare page 0 to be part of a shared group
*** page 0 is _always_ private, since it contains the information
*** which MDOS uses to distinguish between tasks.
arguments:
r1=5 number of pages to be shared in this "type" ( 40 Kbytes)
r2=8 beginning virtual page number
r3=1 type
results:
physical page numbers:
>3f >3e >3d >b8 >b8 >b8 >b8 >3c >3b >3a >39 >38 >37 >36 >35 >34
virtual (local) page numbers:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
<-- shared pages ->
<-- type #1 ->
let us call the above page list "task #1", for the next few examples
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#7 get "shared" pages (we'll come back to opcode #6 later)
1) the "type" must have be declared by a previous call to #5
by another task
2) if shared type has 5 pages, there must be a hole of at least
5 pages in the virtual page list for the shared type to map into
it is not possible to overlay shared and non-shared pages, nor
is it possible to overlap different "types" of shared pages
task #2, initially 24k
vp: 1 2 3 4 5 6 7 8 9
pp: >20 >21 >22 >b8 >b8 >b8 >b8 >b8 >23
task #2 calls opcode #7
arguments:
r1=1
r2=3
results, task #2
vp: 1 2 3 4 5 6 7 8 9
pp: >20 >21 >22 >3b >3a >39 >38 >37 >23
<-- shared pages -->
note that arguments of: r1=1, r2=4 would generate an error,
since page #9 has already been assigned
also note that it is ok to have the shared group at
>1 0000 in task #1, but at
>0 6000 in task #2
also note that physical pages >37 to >3b can now be accessed
by both tasks.
also: a task may use more than one "shared type" simultaneously
shared pages can be a good way to communicate between tasks,
it is also a good way to reduce memory usage for
an application which is used by more than one user at a time,
since you could "share" the object code of the application
between the users, and have more memory available for
each users' data.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#6 release shared pages
only the "type" argument is needed, since MDOS keeps track of
the number of pages in each "type", and its location within the
virtual address space of the tasks which are using the "type"
if task #2 were to call opcode #6 with
r1=1
the following would result:
vp: 1 2 3 4 5 6 7 8 9
pp: >20 >21 >22 >b8 >b8 >b8 >b8 >b8 >23
<- the shared pages are no longer here ->
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#8 get size of shared group
if any task were to call this, they can obtain the number of pages
used by each active type
example: task #3
argument:
r1=1
return:
r0=0 (assuming task #1, above, still had shared pages)
r1=5 size of shared type #1 in above example
Download complete. Turn off Capture File.