2

Having post-dated either, I came to understand the difference between paging and segmentation to be that the former refers to fixed blocks while the later can point anywhere. To do so, the segments are essentially a map from segment number to a (typically longer) base offset.

I'm reading an article on the Z8000 and they talk about the segment register (only one, or did I miss something?). However, it appears this 7-bit number is simply tacked onto the front of the 16-bit offset to produce a 23-bit address. So if my original understanding is correct, isn't this really paging? Is there a mapping going on that I'm missing, or is my original definition incorrect?

3

The term segmented mode in the Z8000 manuals is actually sort of a misnomer (or a mis-understanding when comparing to the same in Intel terminology)- The Z8001 actually supports linear 23-bit addressing.

The 23-bit addresses are stored in 32-bit register pairs or 32-bit immediate values (or 24 bits when stored on the stack). When used, only the lower 23 bits are significant.

There are some limitations, for example in the relative jumps, register-relative addressing modes, and the DJNZ instruction - thus, basically anything that calculates an address based on register + offset, which cannot cross segment boundaries (but rather wrap "within" the segment). Absolute addressing modes, however, target a 23-bit memory address held in an immediate or a register pair.

I'm afraid that misunderstanding invalidates the rest of your question.

  • "...anything that calculates an address based on register + offset, which cannot cross segment boundaries (but rather wrap "within" the segment)" - so as far as those instructions are concerned, it is segmented. That sucks. – Bruce Abbott Jun 6 at 6:16
  • @BruceAbbott Segmentation doesn't suck. It's just another way to think about memory than assuming a single flat address space. A rather clever one in fact, as it allows the same goal of virtual addressing with considerable less hardware (no address calculation involving multiple pages or paging interrupts in the midst of an instruction and alike). – Raffzahn Jun 6 at 6:43
  • According to the Z8000 user reference manual, "instructions and multiple byte data elements cannot cross segment boundaries". Even more sucky! – Bruce Abbott Jun 6 at 6:50
  • Especially if you look into the history of the Z8000-it’s architecture is more based on the intention to have a Z80 that has multiple 16-bit address spaces. Seen from there, it’s actually pretty logical-and if you didn’t like that, you could still use an MMU, which got segments out of the way. – tofro Jun 6 at 6:51
  • 1
    The point of segments is surely that there are segment boundaries -- separate address spaces -- so the "failure" of segmentation hardware to directly offer a linear address space really isn't much of a failure, it's F-A-D. – another-dave Jun 6 at 11:50
6

TL;DR

Pages are part of a larger address space, Segments are an address space.

And both are tools to organize a virtual address space which can be mapped onto real memory.


Preface:

It may be important to keep in mind that terms like Segment or Page aren't as hard defined as one may assume. Like next to any other term. Just take Byte. Today it's automatic assumed to be 8 bit, but that' not entirely true. It has been used for many different units of 5 to 10 Bits. Same for Segment or Page - just think the usage of Page in the context of a 6502 to denote a 256 byte region aligned at a 256 byte border.

Bottom line, we need to be careful when assuming about terms, as one term can carry various meaning.


The Long Read

I came to understand the difference between paging and segmentation to be that the former refers to fixed blocks while the later can point anywhere.

No, not really, as a Page can as well point anywhere in real memory (keep in mind, this is all about virtualization), as well as Segments can be of fixed size.

To do so, the segments are essentially a map from segment number to a (typically longer) base offset.

The same way as a Page is - or not. Both are about mapping virtual address (of a system or a process space) space to real memory or some pointer for retrieval of its region.

I'm reading an article on the Z8000 and they talk about the segment register (only one, or did I miss something?).

Erm, no, each and every address could use a different segment. Also, we're not talking Z8000 but Z8001.

However, it appears this 7-bit number is simply tacked onto the front of the 16-bit offset to produce a 23-bit address.

No, the segment number is separate from the address. The segment number is fixed and will never be calculated or manipulated by the CPU (*1,*2). Only the 16 bit address is calculated in address operations. Of course, from the point of view of a simple memory controller, just providing 8 MiB (*3) of memory addressd by 7+16 bits, yes. But then there is case of using a MMU, like the Z8010 - or a diskrete one as well. It uses the 7 bit segment number issued by the CPU to map it to some arbitrary real memory chunk. Maybe adding process IDs or issuening segment fault interrupts for unassigned (swaped out) pages or alike.

So if my original understanding is correct, isn't this really paging?

No. The basic difference between Paging and Segmentation is that Segments are closed address spaces. They carry no relation between each other. Each Segment is an address space of it's own. Pages on the other hand are parts of a common (single) address space.

Or as practical example, incrementing an address pointer, pointing to the last byte of a segment, by one will make it point to the first byte of the same segment. While incrementing a pointer pointing to the last byte of a page by one will let it point to the first byte of the next page - unless it was the last page in the address space. In this case it will be pointing to the first byte of page 0

Is there a mapping going on that I'm missing, or is my original definition incorrect?

I think you just mixed in the idea how the 8086 implemented segmentation with the fact that some segmented systems can have segments of varying size. Both are implementation details and not basic differences (*4).


*1 - And will be presented on the bus right away, even before the effective 16 bit address is calculated.

*2 - Of course user code may manipulate segment numbers as part of a 32 bit operation. How useful this is may be is up to each user - or better how far the OS can tolerate it (*5).

*3 - Or 48 MiB if address space information is used as well.

*4 - After all, pages can as well have different sizes :)

*5 - Here the fixed 64 KiB segment size does allow to view consecutive segments (by number) to be seen as continuous memory - but no CPU instruction will support this, meaning that all pointer operations have to be done in user code.

  • Re: byte: it has been used for many different units of 5 to 10 Bits. Or even 1 to 36 bits -- PDP-10 ;-) – another-dave Jun 5 at 21:57
  • 1
    This: The basic difference between Paging and Segmentation is that Segments are closed address spaces precisely captures the distinction in a single sentence. Nice! – another-dave Jun 5 at 22:00
  • "Also, we're not talking Z8000 but Z8001." - "Of course, from the point of view of a simple memory controller, just providing 8 MiB (*3) of memory addressed by 7+16 bits, yes." - this is the case I am talking about, the base CPU without the MMU. Perhaps I don't understand how this was actually used, but could two processes access the same physical memory by the correct combination of – Maury Markowitz Jun 6 at 11:42
  • @MauryMarkowitz There is not Z8000. Only Z8001 and Z8002. Z8001 is the segmented, Z8002 the non segmented. The Z8002 can only address 64 KiB (384 KiB if using separate address spaces according to transaction type). The MMU for a Z8001 would be Z8010. Your question about accessing the same physical space doesn't make sense without looking at the memory system design. The whole idea of segmentation as part of programming logic is to enable easy design of memory systems. For example a simple latch plus a 6264 RAM (and a few glue gates) would already make a veritable MMU for 64 processes. – Raffzahn Jun 6 at 15:21
  • @MauryMarkowitz Now, if a memory system just attaches 8 MiB by using S0..6 and A0..15 as a 23 bit address, then yes, every process using the same combination of segment and address would access the same location. This would effectively degrade segmentation to a banking like system. Not helpful, as the whole point of segmentation is to allow virtual memory, while at the same time reducing the effort to do so by eliminating pitfalls a paged system has. – Raffzahn Jun 6 at 15:24
1

As a programmer, I'd say the (original) distinction is this: a 'segment' is supposed to be a mapping from an object in the program to the address space of the processor, i.e., a segment is one 'thing' as far as the program is concerned. It quite naturally needs to be of variable length.

Overlapping segments, in the manner of x86, are to my mind a misfeature.

A 'page', however, is a slice of the address space, typically fixed size, the point of which is management of the memory resources of the system. The relationship of pages to program objects is arbitrary.

Though I'm unfamiliar with the Z8000, the description in Wikipedia seems more like segmentation. If you add 1 to the offset ffff, then you're addressing 0000 in the same segment, not 0000 in the 'next' segment (which would require updating the segment-number register). And that's the crucial thing: programs in a paged address space are not expected to do special things when addresses cross page boundaries, whereas programs in a segmented address space may well do.

  • 2
    A good segmented architecture should avoid requiring that heap objects be consolidated into chunks. Either one segment should be large enough to hold everything, or segments should be cheap enough to give every object its own segment. The 8088 design opted to make segments cheap. I wouldn't describe the fact that segments overlap as being a "feature" or "misfeature" beyond the fact that it minimizes the cost of managing segments whose used portions do not overlap. – supercat Jun 5 at 22:04
  • 1
    I wouldn't call the 8086 segmentation (not x86, as the 286 replaced it) a misfeature. From a system design view I'd say it's pure genius. It allows to write code as if there is a fully featured segmentation system (like the 286 added) without spending the transistors - the 286 is more than 4 times the TC of the 8086, and next to all accounts for adding 'real' segmentation. The problem here wasn't Intel, but 'brillint' programmer coming up with pointer arithmetic, screwing any transition. – Raffzahn Jun 5 at 22:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.