Hacker News new | ask | show | jobs
by amiga386 6 hours ago
> It's not all that different from the memory pages we have today

An MMU gives you a flat addressing model. There is no comparison. 8086 segments are rigidly locked to a 64KB window that goes forward in memory 16 bytes for every segment (so segmented address 1234:5678 is linear address $12340 + $5678 = $179B8)

It didn't do this to offer a useful feature like an MMU. It did this to allow code that doesn't know segment registers exist to think they're still running on an 8-bit Z80. What a waste of potential. The 68000 didn't pretend to be a 6502.

The 80286 introduced protected mode with "segment descriptors", but this is well after MMUs existed on other CPUs, it didn't invent virtual memory. Only the 80386 offered a 32-bit flat memory model.

If you want to see something to make you weep, look at the MS-DOS version of unzip. It has to do all kinds of crazy, just to allocate 64KB of RAM and get all 64KB, not 8 bytes less. And it's still locked into a memory access model that will not let it ever address more than 64KB of any one object. It's why MS-DOS was viewed as a toy OS for a toy computer.

    #if defined(__TURBOC__) && !defined(OS2)
    #include <alloc.h>
    /* Turbo C malloc() does not allow dynamic allocation of 64K bytes
     * and farmalloc(64K) returns a pointer with an offset of 8, so we
     * must fix the pointer. Warning: the pointer must be put back to its
     * original form in order to free it, use zcfree().
     */

    ...

    static ptr_table table[MAX_PTR];
    /* This table is used to remember the original form of pointers
     * to large buffers (64K). Such pointers are normalized with a zero offset.
     * Since MSDOS is not a preemptive multitasking OS, this table is not
     * protected from concurrent access. This hack doesn't work anyway on
     * a protected system like OS/2. Use Microsoft C instead.
     */
1 comments

That's a limitation of the Turbo C library, as the comment says. DOS memory allocation functions take the size in 16-byte "paragraphs", and return a segment, with the allocated memory starting at offset zero in that segment.