Re: Swapping

Gábor Lénárt
2004-05-28T07:52:44Z

Re,

On Thu, May 27, 2004 at 07:45:07PM +0100, Alan Cox wrote:
> Firstly older processors could not restart a faulting instruction
> perfectly. Eg if you did
>
> "move block of 32 bytes from x to y"
>
> you didn't know how much was copied when it faulted. Worse still
> instructions that did the post increment/decrement might or might
> not have changed the values. The 8086 is in this category, the 80286
> is [with sufficient care] not.

I don't understand this.

mov cx,32
push ds
pop es
mov si,0x100
mov di,0x200
rep movsb

This code (in intel asm syntax) copies 32 bytes from offset 0x100 to
0x200 withing the data segment. If you interrupt rep prefixed movsb
register cx should inform you the state of the prefixed movsb.

Or simply I've ignored something :)

> The other difference is by fixed v variable size). Paging traditionally
> means fixed size blocks and not loading all the program into memory at
> once. Works a treat on a 386, not useful on a 286. In the 286 world
> instead you have to work with variable sized segments being written to
> or from disk, but you could in 286PM but not on 8086 load only some
> segments into memory and load others on the fault.

Also it's important to declare here than on 386, paging and segmenting
works in parallel (if you enable paging of course). On 286 you have got
only segmenting but you have got special meaning of segment registers in
protected mode ie conatining selectors which are "only" indices inside a
desciptor table. Segmenting is similar in 386 protected mode but there
you have the possibility to use page granulity instead of bytes, so instead
of maximum of 64K segment size, you can use maximum segment size 4G. Since
paging and segmenting can works in parallel most modern OSes (like Linux)
uses "flat" addressing mode, ie setting segment sizes to 4G, and let paging
do the hw level protecting and other related stuffs on per page basis.

And another interesting things for 386 is the so called 'flat real
addressing mode). It's an ugly trick and only works in real mode so not
in virtual 8086 mode. You can change into 32 bit protected mode on 386,
and you can build a descriptor table with using 4G wide segment limits.
Now you can load selectors into the segment registers. And NOW. If you
switch back into real mode, size of the segments are 4G (!) instead of 64K,
though meaning of segment IDs reamins the "real mode" constructs, so
segid*16=real_addr. This addressing mode is used by some old scene demos.
However I don't know exactly if it's a bug or feature :) as far as I can
remember it's because CPU has got a "cache" for eg segment limits to avoid
to load from descriptor table each time, and since 4G limit is loaded,
this limit is used in real mode too after switching back into real mode.

However, Alan, please correct me if I'm wrong somewhere.

- Gábor (larta'H)